View Javadoc

1   /*
2    * $Id: JXPathTestCase.java 22421 2011-07-15 05:05:06Z dirk.olmes $
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.AbstractServiceAndFlowTestCase;
17  
18  import java.util.Arrays;
19  import java.util.Collection;
20  
21  import org.junit.Test;
22  import org.junit.runners.Parameterized.Parameters;
23  
24  import static org.junit.Assert.assertEquals;
25  import static org.junit.Assert.assertNotNull;
26  
27  public class JXPathTestCase extends AbstractServiceAndFlowTestCase
28  {
29      @Parameters
30      public static Collection<Object[]> parameters()
31      {
32          return Arrays.asList(new Object[][]{{ConfigVariant.SERVICE, "jxpath-config-service.xml"},
33              {ConfigVariant.FLOW, "jxpath-config-flow.xml"}});
34      }
35  
36      public JXPathTestCase(ConfigVariant variant, String configResources)
37      {
38          super(variant, configResources);
39      }
40  
41      @Test
42      public void testSetMessagePropertyFromXmlWithNamespacesDefinedWithSamePrefix() throws Exception
43      {
44          String xml = "<root " + "xmlns:h=\"http://www.w3.org/TR/html4/\" "
45                       + "xmlns:f=\"http://www.w3schools.com/furniture\">" +
46  
47                       "<h:table>" + "<h:tr>" + "<h:td>Apples</h:td>" + "<h:td>Bananas</h:td>" + "</h:tr>"
48                       + "</h:table>" +
49  
50                       "<f:table>" + "<f:name>African Coffee Table</f:name>" + "<f:width>80</f:width>"
51                       + "<f:length>120</f:length>" + "</f:table>" +
52  
53                       "</root>";
54  
55          doTest(xml);
56      }
57  
58      @Test
59      public void testSetMessagePropertyFromXmlWithNamespacesDefinedWithDifferentPrefix() throws Exception
60      {
61          String xml = "<root " + "xmlns:h=\"http://www.w3.org/TR/html4/\" "
62                       + "xmlns:z=\"http://www.w3schools.com/furniture\">" +
63  
64                       "<h:table>" + "<h:tr>" + "<h:td>Apples</h:td>" + "<h:td>Bananas</h:td>" + "</h:tr>"
65                       + "</h:table>" +
66  
67                       "<z:table>" + "<z:name>African Coffee Table</z:name>" + "<z:width>80</z:width>"
68                       + "<z:length>120</z:length>" + "</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  }