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 package org.jaxen.test;
49
50 import javax.xml.parsers.DocumentBuilder;
51 import javax.xml.parsers.DocumentBuilderFactory;
52 import javax.xml.parsers.ParserConfigurationException;
53
54 import junit.framework.TestCase;
55
56 import org.jaxen.BaseXPath;
57 import org.jaxen.FunctionCallException;
58 import org.jaxen.JaxenException;
59 import org.jaxen.XPath;
60 import org.jaxen.dom.DOMXPath;
61 import org.w3c.dom.Document;
62
63 /***
64 * @author Elliotte Rusty Harold
65 *
66 */
67 public class NormalizeSpaceTest extends TestCase {
68
69 private Document doc;
70
71 public void setUp() throws ParserConfigurationException
72 {
73 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
74 factory.setNamespaceAware(true);
75 DocumentBuilder builder = factory.newDocumentBuilder();
76 doc = builder.newDocument();
77 doc.appendChild(doc.createElement("root"));
78 }
79
80
81 public NormalizeSpaceTest(String name) {
82 super(name);
83 }
84
85 public void testNormalizeSpaceUsesXMLSpaceRulesNotJavaRules() throws JaxenException
86 {
87
88 String data = "\u2003X\u2003";
89 XPath xpath = new DOMXPath( "normalize-space('" + data + "')" );
90 String result = (String) xpath.evaluate( doc );
91 assertEquals(data, result);
92 }
93
94 public void testNormalizeSpaceUsesXMLSpaceRulesNotJavaRules2() throws JaxenException
95 {
96
97 String data = "\u2003X\u2003";
98 XPath xpath = new DOMXPath( "normalize-space(' " + data + " ')" );
99 String result = (String) xpath.evaluate( doc );
100 assertEquals(data, result);
101 }
102
103 public void testNormalizeSpaceInContextNode() throws JaxenException
104 {
105 XPath xpath = new DOMXPath( "normalize-space()" );
106 String result = (String) xpath.evaluate( doc );
107 assertEquals("", result);
108 }
109
110 public void testNormalizeSpaceRequiresAtMostOneArguments()
111 throws JaxenException {
112
113 BaseXPath xpath = new DOMXPath("normalize-space('a', 'a')");
114
115 try {
116 xpath.selectNodes(doc);
117 fail("Allowed normalize-space function with two arguments");
118 }
119 catch (FunctionCallException ex) {
120 assertNotNull(ex.getMessage());
121 }
122
123 }
124
125 }