1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 }