1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.jxpath.ri.model;
19
20 import static org.junit.jupiter.api.Assertions.assertEquals;
21
22 import org.apache.commons.jxpath.AbstractJXPathTest;
23 import org.apache.commons.jxpath.JXPathContext;
24 import org.apache.commons.jxpath.xml.DocumentContainer;
25 import org.junit.jupiter.api.Test;
26
27
28
29
30 public class XMLSpaceTest extends AbstractJXPathTest {
31
32 protected JXPathContext context;
33
34 protected JXPathContext createContext(final String model) {
35 final JXPathContext context = JXPathContext.newContext(createDocumentContainer(model));
36 return context;
37 }
38
39 protected DocumentContainer createDocumentContainer(final String model) {
40 return new DocumentContainer(AbstractJXPathTest.class.getResource("XmlSpace.xml"), model);
41 }
42
43 protected void doTest(final String id, final String model, final String expectedValue) {
44 final JXPathContext context = JXPathContext.newContext(createDocumentContainer(model));
45 assertEquals(expectedValue, context.getValue("test/text[@id='" + id + "']"));
46 }
47
48 @Test
49 public void testDefaultDOM() {
50 doTest("default", DocumentContainer.MODEL_DOM, "foo");
51 }
52
53 @Test
54 public void testDefaultJDOM() {
55 doTest("default", DocumentContainer.MODEL_JDOM, "foo");
56 }
57
58 @Test
59 public void testNestedDOM() {
60 doTest("nested", DocumentContainer.MODEL_DOM, "foo;bar; baz ");
61 }
62
63 @Test
64 public void testNestedJDOM() {
65 doTest("nested", DocumentContainer.MODEL_JDOM, "foo;bar; baz ");
66 }
67
68 @Test
69 public void testNestedWithCommentsDOM() {
70 doTest("nested-with-comments", DocumentContainer.MODEL_DOM, "foo;bar; baz ");
71 }
72
73 @Test
74 public void testNestedWithCommentsJDOM() {
75 doTest("nested-with-comments", DocumentContainer.MODEL_JDOM, "foo;bar; baz ");
76 }
77
78 @Test
79 public void testPreserveDOM() {
80 doTest("preserve", DocumentContainer.MODEL_DOM, " foo ");
81 }
82
83 @Test
84 public void testPreserveJDOM() {
85 doTest("preserve", DocumentContainer.MODEL_JDOM, " foo ");
86 }
87
88 @Test
89 public void testUnspecifiedDOM() {
90 doTest("unspecified", DocumentContainer.MODEL_DOM, "foo");
91 }
92
93 @Test
94 public void testUnspecifiedJDOM() {
95 doTest("unspecified", DocumentContainer.MODEL_JDOM, "foo");
96 }
97 }