View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.test.integration.routing.outbound;
8   
9   import org.mule.api.MuleMessage;
10  import org.mule.api.MuleMessageCollection;
11  import org.mule.module.client.MuleClient;
12  import org.mule.tck.junit4.FunctionalTestCase;
13  
14  import java.util.List;
15  
16  import org.custommonkey.xmlunit.XMLUnit;
17  import org.junit.Test;
18  
19  import static org.junit.Assert.assertEquals;
20  import static org.junit.Assert.assertNotNull;
21  import static org.junit.Assert.assertTrue;
22  
23  public class ExpressionSplitterXPathTestCase extends FunctionalTestCase
24  {
25      private final String MESSAGE = "<Batch xmlns=\"http://acme.com\">\n" +
26              "    <Trade>\n" +
27              "        <Type>CASH</Type>\n" +
28              "        <Amount>40000</Amount>\n" +
29              "        <Currency>USD</Currency>\n" +
30              "        <Date>28102008</Date>\n" +
31              "    </Trade>    \n" +
32              "    <Trade>\n" +
33              "        <Type>CASH</Type>\n" +
34              "        <Amount>2000</Amount>\n" +
35              "        <Currency>GBP</Currency>\n" +
36              "        <Date>28102008</Date>\n" +
37              "    </Trade>    \n" +
38              "</Batch>";
39  
40      private final String EXPECTED_MESSAGE_1 = "<Trade xmlns=\"http://acme.com\">\n" +
41              "        <Type>CASH</Type>\n" +
42              "        <Amount>40000</Amount>\n" +
43              "        <Currency>USD</Currency>\n" +
44              "        <Date>28102008</Date>\n" +
45              "        <Received>ServiceOne</Received>\n" +
46              "    </Trade>";
47  
48      private final String EXPECTED_MESSAGE_2 = "<Trade xmlns=\"http://acme.com\">\n" +
49              "        <Type>CASH</Type>\n" +
50              "        <Amount>2000</Amount>\n" +
51              "        <Currency>GBP</Currency>\n" +
52              "        <Date>28102008</Date>\n" +
53              "        <Received>ServiceTwo</Received>\n" +
54              "    </Trade>";
55  
56  
57      public ExpressionSplitterXPathTestCase()
58      {
59          XMLUnit.setIgnoreWhitespace(true);
60      }
61  
62      @Override
63      protected String getConfigResources()
64      {
65          return "org/mule/test/integration/routing/outbound/expression-splitter-xpath-test.xml";
66      }
67  
68      @Test
69      public void testRecipientList() throws Exception
70      {
71  
72  
73          MuleClient client = new MuleClient(muleContext);
74          MuleMessage result = client.send("vm://distributor.queue", MESSAGE, null);
75  
76          assertNotNull(result);
77          assertTrue(result instanceof MuleMessageCollection);
78          MuleMessageCollection coll = (MuleMessageCollection) result;
79          assertEquals(2, coll.size());
80          List<?> results = (List<?>) coll.getPayload();
81  
82          XMLUnit.compareXML(EXPECTED_MESSAGE_1, results.get(0).toString());
83          XMLUnit.compareXML(EXPECTED_MESSAGE_2, results.get(1).toString());
84      }
85  }