1   /*
2    * Copyright 2005-2010 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 org.junit.Assert;
22  import org.junit.Before;
23  import org.junit.Test;
24  
25  public class QNameEditorTest {
26  
27      private QNameEditor editor;
28  
29      @Before
30      public void setUp() throws Exception {
31          editor = new QNameEditor();
32      }
33  
34      @Test
35      public void testNamespaceLocalPartPrefix() throws Exception {
36          QName qname = new QName("namespace", "localpart", "prefix");
37          doTest(qname);
38      }
39  
40      @Test
41      public void testNamespaceLocalPart() throws Exception {
42          QName qname = new QName("namespace", "localpart");
43          doTest(qname);
44      }
45  
46      @Test
47      public void testLocalPart() throws Exception {
48          QName qname = new QName("localpart");
49          doTest(qname);
50      }
51  
52      private void doTest(QName qname) {
53          editor.setValue(qname);
54          String text = editor.getAsText();
55          Assert.assertNotNull("getAsText returns null", text);
56          editor.setAsText(text);
57          QName result = (QName) editor.getValue();
58          Assert.assertNotNull("getValue returns null", result);
59          Assert.assertEquals("Parsed QName local part is not equal to original", qname.getLocalPart(), result.getLocalPart());
60          Assert.assertEquals("Parsed QName prefix is not equal to original", qname.getPrefix(), result.getPrefix());
61          Assert.assertEquals("Parsed QName namespace is not equal to original", qname.getNamespaceURI(),
62                  result.getNamespaceURI());
63      }
64  }