1   /*
2    * Copyright 2005 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springframework.xml.namespace;
18  
19  import javax.xml.namespace.QName;
20  
21  import junit.framework.TestCase;
22  
23  public class QNameEditorTest extends TestCase {
24  
25      private QNameEditor editor;
26  
27      protected void setUp() throws Exception {
28          editor = new QNameEditor();
29      }
30  
31      public void testNamespaceLocalPartPrefix() throws Exception {
32          QName qname = new QName("namespace", "localpart", "prefix");
33          doTest(qname);
34      }
35  
36      public void testNamespaceLocalPart() throws Exception {
37          QName qname = new QName("namespace", "localpart");
38          doTest(qname);
39      }
40  
41      public void testLocalPart() throws Exception {
42          QName qname = new QName("localpart");
43          doTest(qname);
44      }
45  
46      private void doTest(QName qname) {
47          editor.setValue(qname);
48          String text = editor.getAsText();
49          assertNotNull("getAsText returns null", text);
50          editor.setAsText(text);
51          QName result = (QName) editor.getValue();
52          assertNotNull("getValue returns null", result);
53          assertEquals("Parsed QName local part is not equal to original", qname.getLocalPart(), result.getLocalPart());
54          assertEquals("Parsed QName prefix is not equal to original", qname.getPrefix(), result.getPrefix());
55          assertEquals("Parsed QName namespace is not equal to original", qname.getNamespaceURI(),
56                  result.getNamespaceURI());
57      }
58  }