1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 package org.jaxen.test;
50
51 import javax.xml.parsers.DocumentBuilder;
52 import javax.xml.parsers.DocumentBuilderFactory;
53
54 import org.jaxen.Navigator;
55 import org.jaxen.dom.DocumentNavigator;
56 import org.w3c.dom.Attr;
57 import org.w3c.dom.Document;
58 import org.w3c.dom.Element;
59
60 public class DOMNavigatorTest extends XPathTestBase
61 {
62
63 private DocumentBuilder builder;
64
65
66 public DOMNavigatorTest(String name)
67 {
68 super( name );
69 }
70
71 public Navigator getNavigator()
72 {
73 return new DocumentNavigator();
74 }
75
76 protected void setUp() throws Exception {
77 super.setUp();
78 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
79 factory.setNamespaceAware(true);
80 builder = factory.newDocumentBuilder();
81 }
82
83 public Object getDocument(String url) throws Exception
84 {
85 return builder.parse( url );
86 }
87
88 public void testGetAttributeQNameOnElement() {
89 Navigator nav = getNavigator();
90 Document doc = builder.newDocument();
91 Element a = doc.createElement("a");
92 String qname = nav.getAttributeQName(a);
93 assertNull(qname);
94 }
95
96 public void testGetElementQNameOnAttr() {
97 Navigator nav = getNavigator();
98 Document doc = builder.newDocument();
99 Attr a = doc.createAttribute("a");
100 String qname = nav.getElementQName(a);
101 assertNull(qname);
102 }
103
104 public void testGetAttributeLocalNameOnElement() {
105 Navigator nav = getNavigator();
106 Document doc = builder.newDocument();
107 Element a = doc.createElementNS("http://www.ex.com", "pre:a");
108 String name = nav.getAttributeName(a);
109 assertNull(name);
110 }
111
112 public void testGetElementLocalNameOnAttr() {
113 Navigator nav = getNavigator();
114 Document doc = builder.newDocument();
115 Attr a = doc.createAttributeNS("http://www.ex.com", "a");
116 String name = nav.getElementName(a);
117 assertNull(name);
118 }
119
120 public void testGetAttributeNamespaceURIOnElement() {
121 Navigator nav = getNavigator();
122 Document doc = builder.newDocument();
123 Element a = doc.createElementNS("http://www.example.org/", "a");
124 String qname = nav.getAttributeNamespaceUri(a);
125 assertNull(qname);
126 }
127
128 public void testGetElementNamespaceURIOnAttr() {
129 Navigator nav = getNavigator();
130 Document doc = builder.newDocument();
131 Attr a = doc.createAttributeNS("http://www.element.org/", "a");
132 String qname = nav.getElementNamespaceUri(a);
133 assertNull(qname);
134 }
135
136 public void testGetTargetOfNonPI() {
137 Navigator nav = getNavigator();
138 Document doc = builder.newDocument();
139 Attr a = doc.createAttributeNS("http://www.element.org/", "a");
140 try {
141 nav.getProcessingInstructionTarget(a);
142 fail("got target of non processing instruction");
143 }
144 catch (ClassCastException ex) {
145 assertNotNull(ex.getMessage());
146 }
147 }
148
149 public void testGetDataOfNonPI() {
150 Navigator nav = getNavigator();
151 Document doc = builder.newDocument();
152 Attr a = doc.createAttributeNS("http://www.element.org/", "a");
153 try {
154 nav.getProcessingInstructionData(a);
155 fail("got data of non processing instruction");
156 }
157 catch (ClassCastException ex) {
158 assertNotNull(ex.getMessage());
159 }
160 }
161
162
163 }