View Javadoc

1   /*
2    * $Id: JXPathTestCase.java 19386 2010-09-06 21:57:44Z mike.schilling $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.module.xml.functional;
12  
13  import org.mule.api.MuleException;
14  import org.mule.api.MuleMessage;
15  import org.mule.module.client.MuleClient;
16  import org.mule.tck.FunctionalTestCase;
17  
18  public class JXPathTestCase extends FunctionalTestCase
19  {
20  
21      @Override
22      protected String getConfigResources()
23      {
24          return "jxpath-config.xml";
25      }
26  
27      public void testSetMessagePropertyFromXmlWithNamespacesDefinedWithSamePrefix() throws Exception
28      {
29          String xml = "<root " +
30                       "xmlns:h=\"http://www.w3.org/TR/html4/\" " +
31                       "xmlns:f=\"http://www.w3schools.com/furniture\">" +
32  
33                       "<h:table>" +
34                       "<h:tr>" +
35                       "<h:td>Apples</h:td>" +
36                       "<h:td>Bananas</h:td>" +
37                       "</h:tr>" +
38                       "</h:table>" +
39  
40                       "<f:table>" +
41                       "<f:name>African Coffee Table</f:name>" +
42                       "<f:width>80</f:width>" +
43                       "<f:length>120</f:length>" +
44                       "</f:table>" +
45  
46                       "</root>";
47  
48          doTest(xml);
49      }
50  
51      public void testSetMessagePropertyFromXmlWithNamespacesDefinedWithDifferentPrefix() throws Exception
52      {
53          String xml = "<root " +
54                       "xmlns:h=\"http://www.w3.org/TR/html4/\" " +
55                       "xmlns:z=\"http://www.w3schools.com/furniture\">" +
56  
57                       "<h:table>" +
58                       "<h:tr>" +
59                       "<h:td>Apples</h:td>" +
60                       "<h:td>Bananas</h:td>" +
61                       "</h:tr>" +
62                       "</h:table>" +
63  
64                       "<z:table>" +
65                       "<z:name>African Coffee Table</z:name>" +
66                       "<z:width>80</z:width>" +
67                       "<z:length>120</z:length>" +
68                       "</z:table>" +
69  
70                       "</root>";
71  
72          doTest(xml);
73      }
74  
75      private void doTest(String xml) throws MuleException
76      {
77          MuleClient client = new MuleClient(muleContext);
78          MuleMessage response = client.send("vm://in", xml, null);
79          assertNotNull(response);
80          assertNotNull(response.getInboundProperty("nameProperty"));
81          assertEquals("African Coffee Table", response.getInboundProperty("nameProperty"));
82      }
83  }
84