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 XMLSpaceTest extends JXPathTestCase {
30 protected JXPathContext context;
31
32 protected DocumentContainer createDocumentContainer(String model) {
33 return new DocumentContainer(JXPathTestCase.class
34 .getResource("XmlSpace.xml"), model);
35 }
36
37 protected JXPathContext createContext(String model) {
38 JXPathContext context = JXPathContext
39 .newContext(createDocumentContainer(model));
40 return context;
41 }
42
43 protected void doTest(String id, String model, String expectedValue) {
44 JXPathContext context = JXPathContext
45 .newContext(createDocumentContainer(model));
46 assertEquals(context.getValue("test/text[@id='" + id + "']"), expectedValue);
47 }
48
49 public void testUnspecifiedDOM() {
50 doTest("unspecified", DocumentContainer.MODEL_DOM, "foo");
51 }
52
53 public void testDefaultDOM() {
54 doTest("default", DocumentContainer.MODEL_DOM, "foo");
55 }
56
57 public void testPreserveDOM() {
58 doTest("preserve", DocumentContainer.MODEL_DOM, " foo ");
59 }
60
61 public void testNestedDOM() {
62 doTest("nested", DocumentContainer.MODEL_DOM, "foo;bar; baz ");
63 }
64
65 public void testNestedWithCommentsDOM() {
66 doTest("nested-with-comments", DocumentContainer.MODEL_DOM, "foo;bar; baz ");
67 }
68
69 public void testUnspecifiedJDOM() {
70 doTest("unspecified", DocumentContainer.MODEL_JDOM, "foo");
71 }
72
73 public void testDefaultJDOM() {
74 doTest("default", DocumentContainer.MODEL_JDOM, "foo");
75 }
76
77 public void testPreserveJDOM() {
78 doTest("preserve", DocumentContainer.MODEL_JDOM, " foo ");
79 }
80
81 public void testNestedJDOM() {
82 doTest("nested", DocumentContainer.MODEL_JDOM, "foo;bar; baz ");
83 }
84
85 public void testNestedWithCommentsJDOM() {
86 doTest("nested-with-comments", DocumentContainer.MODEL_JDOM, "foo;bar; baz ");
87 }
88 }