1
2
3
4
5
6
7 package org.mule.module.xml.functional;
8
9 import org.mule.api.MuleException;
10 import org.mule.api.MuleMessage;
11 import org.mule.module.client.MuleClient;
12 import org.mule.tck.junit4.FunctionalTestCase;
13
14 import org.junit.Test;
15
16 import static org.junit.Assert.assertEquals;
17 import static org.junit.Assert.assertNotNull;
18
19 public class JXPathTestCase extends FunctionalTestCase
20 {
21
22 @Override
23 protected String getConfigResources()
24 {
25 return "jxpath-config.xml";
26 }
27
28 @Test
29 public void testSetMessagePropertyFromXmlWithNamespacesDefinedWithSamePrefix() throws Exception
30 {
31 String xml = "<root " +
32 "xmlns:h=\"http://www.w3.org/TR/html4/\" " +
33 "xmlns:f=\"http://www.w3schools.com/furniture\">" +
34
35 "<h:table>" +
36 "<h:tr>" +
37 "<h:td>Apples</h:td>" +
38 "<h:td>Bananas</h:td>" +
39 "</h:tr>" +
40 "</h:table>" +
41
42 "<f:table>" +
43 "<f:name>African Coffee Table</f:name>" +
44 "<f:width>80</f:width>" +
45 "<f:length>120</f:length>" +
46 "</f:table>" +
47
48 "</root>";
49
50 doTest(xml);
51 }
52
53 @Test
54 public void testSetMessagePropertyFromXmlWithNamespacesDefinedWithDifferentPrefix() throws Exception
55 {
56 String xml = "<root " +
57 "xmlns:h=\"http://www.w3.org/TR/html4/\" " +
58 "xmlns:z=\"http://www.w3schools.com/furniture\">" +
59
60 "<h:table>" +
61 "<h:tr>" +
62 "<h:td>Apples</h:td>" +
63 "<h:td>Bananas</h:td>" +
64 "</h:tr>" +
65 "</h:table>" +
66
67 "<z:table>" +
68 "<z:name>African Coffee Table</z:name>" +
69 "<z:width>80</z:width>" +
70 "<z:length>120</z:length>" +
71 "</z:table>" +
72
73 "</root>";
74
75 doTest(xml);
76 }
77
78 private void doTest(String xml) throws MuleException
79 {
80 MuleClient client = new MuleClient(muleContext);
81 MuleMessage response = client.send("vm://in", xml, null);
82 assertNotNull(response);
83 assertNotNull(response.getInboundProperty("nameProperty"));
84 assertEquals("African Coffee Table", response.getInboundProperty("nameProperty"));
85 }
86 }
87