1
2
3
4
5
6
7
8
9
10
11
12 package com.eviware.soapui.support.xml;
13
14 import junit.framework.TestCase;
15
16 public class XPathDataTestCase extends TestCase
17 {
18 public void test1() throws Exception
19 {
20 XPathData data = new XPathData("//in/name", false);
21 assertEquals("//in/name", data.getFullPath());
22 }
23
24 public void testText() throws Exception
25 {
26 XPathData data = new XPathData("//in/name/text()", false);
27 assertEquals("//in/name/text()", data.getFullPath());
28 }
29
30 public void testCount() throws Exception
31 {
32 XPathData data = new XPathData("count(//in/name)", false);
33 assertEquals("count(//in/name)", data.getFullPath());
34 assertEquals("count", data.getFunction());
35 }
36
37 public void testCountWithNamespace() throws Exception
38 {
39 String namespace = "declare namespace tes='http://www.example.org/TestService/';\n";
40 XPathData data = new XPathData(namespace + "count(//in/name)", false);
41 assertEquals(namespace + "count(//in/name)", data.getFullPath());
42 assertEquals("count", data.getFunction());
43 }
44
45 public void testStripXPath() throws Exception
46 {
47 checkStripXPath("//abc", "//abc");
48 checkStripXPath("//abc", "//abc[1]");
49 checkStripXPath("//abc", "//abc[a > 3]");
50 checkStripXPath("//abc", "//abc/text()");
51 checkStripXPath("//abc", "count(//abc)");
52 checkStripXPath("//abc", "count( //abc)");
53 checkStripXPath("//abc", "exists(//abc)");
54 checkStripXPath("//abc", "exists( //abc)");
55
56 String ns = "declare namespace ns1='http://abc.com';\n";
57 checkStripXPath(ns + "//abc", ns + "//abc[1]");
58 checkStripXPath(ns + "//abc", ns + "//abc/text()");
59 checkStripXPath(ns + "//abc", ns + "exists(//abc)");
60 }
61
62 private void checkStripXPath(String expected, String org)
63 {
64 XPathData xpath = new XPathData(org, true);
65 xpath.strip();
66 assertEquals(expected, xpath.getXPath());
67 }
68
69 public void testReplaceNameInPathOrQuery() throws Exception
70 {
71 String exp = "//test:test/bil[@name='test ']/@test > 0 and count(//test[bil/text()='test'] = 5";
72
73 assertEquals( "//test:test/bila[@name='test ']/@test > 0 and count(//test[bila/text()='test'] = 5",
74 XmlUtils.replaceNameInPathOrQuery( exp, "bil", "bila" ));
75 }
76 }