1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.jxpath.ri.model;
18
19 import org.apache.commons.jxpath.JXPathContext;
20 import org.apache.commons.jxpath.JXPathTestCase;
21 import org.apache.commons.jxpath.xml.DocumentContainer;
22
23
24
25
26
27
28
29 public class ExternalXMLNamespaceTest extends JXPathTestCase {
30 protected JXPathContext context;
31
32 protected DocumentContainer createDocumentContainer(String model) {
33 DocumentContainer result = new DocumentContainer(JXPathTestCase.class
34 .getResource("ExternalNS.xml"), model);
35
36 result.setNamespaceAware(false);
37 return result;
38 }
39
40 protected JXPathContext createContext(String model) {
41 JXPathContext context = JXPathContext
42 .newContext(createDocumentContainer(model));
43 context.registerNamespace("A", "foo");
44 context.registerNamespace("B", "bar");
45 return context;
46 }
47
48 protected void doTest(String xpath, String model, String expected) {
49 assertXPathValue(createContext(model), xpath, expected);
50 }
51
52 protected void doTestAttribute(String model) {
53 doTest("/ElementA/@A:myAttr", model, "Mytype");
54 }
55
56 protected void doTestElement(String model) {
57 doTest("/ElementA/B:ElementB", model, "MY VALUE");
58 }
59
60 protected void doTestCreateAndSetAttribute(String model) {
61 assertXPathCreatePathAndSetValue(createContext(model),
62 "/ElementA/@A:newAttr", "newValue", "/ElementA[1]/@A:newAttr");
63 }
64
65 public void testAttributeDOM() {
66 doTestAttribute(DocumentContainer.MODEL_DOM);
67 }
68
69 public void testElementDOM() {
70 doTestElement(DocumentContainer.MODEL_DOM);
71 }
72
73 public void testCreateAndSetAttributeDOM() {
74 doTestCreateAndSetAttribute(DocumentContainer.MODEL_DOM);
75 }
76
77 }