View Javadoc

1   /*
2    * $Id: ExpressionSplitterXPathTestCase.java 20321 2010-11-24 15:21:24Z dfeist $
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.test.integration.routing.outbound;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.api.MuleMessageCollection;
15  import org.mule.module.client.MuleClient;
16  import org.mule.tck.FunctionalTestCase;
17  
18  import java.util.List;
19  
20  import org.custommonkey.xmlunit.XMLUnit;
21  
22  public class ExpressionSplitterXPathTestCase extends FunctionalTestCase
23  {
24      private final String MESSAGE = "<Batch xmlns=\"http://acme.com\">\n" +
25              "    <Trade>\n" +
26              "        <Type>CASH</Type>\n" +
27              "        <Amount>40000</Amount>\n" +
28              "        <Currency>USD</Currency>\n" +
29              "        <Date>28102008</Date>\n" +
30              "    </Trade>    \n" +
31              "    <Trade>\n" +
32              "        <Type>CASH</Type>\n" +
33              "        <Amount>2000</Amount>\n" +
34              "        <Currency>GBP</Currency>\n" +
35              "        <Date>28102008</Date>\n" +
36              "    </Trade>    \n" +
37              "</Batch>";
38  
39      private final String EXPECTED_MESSAGE_1 = "<Trade xmlns=\"http://acme.com\">\n" +
40              "        <Type>CASH</Type>\n" +
41              "        <Amount>40000</Amount>\n" +
42              "        <Currency>USD</Currency>\n" +
43              "        <Date>28102008</Date>\n" +
44              "        <Received>ServiceOne</Received>\n" +
45              "    </Trade>";
46  
47      private final String EXPECTED_MESSAGE_2 = "<Trade xmlns=\"http://acme.com\">\n" +
48              "        <Type>CASH</Type>\n" +
49              "        <Amount>2000</Amount>\n" +
50              "        <Currency>GBP</Currency>\n" +
51              "        <Date>28102008</Date>\n" +
52              "        <Received>ServiceTwo</Received>\n" +
53              "    </Trade>";
54  
55  
56      public ExpressionSplitterXPathTestCase()
57      {
58          XMLUnit.setIgnoreWhitespace(true);
59      }
60  
61      @Override
62      protected String getConfigResources()
63      {
64          return "org/mule/test/integration/routing/outbound/expression-splitter-xpath-test.xml";
65      }
66  
67      public void testRecipientList() throws Exception
68      {
69  
70  
71          MuleClient client = new MuleClient(muleContext);
72          MuleMessage result = client.send("vm://distributor.queue", MESSAGE, null);
73  
74          assertNotNull(result);
75          assertTrue(result instanceof MuleMessageCollection);
76          MuleMessageCollection coll = (MuleMessageCollection) result;
77          assertEquals(2, coll.size());
78          List<?> results = (List<?>) coll.getPayload();
79  
80          XMLUnit.compareXML(EXPECTED_MESSAGE_1, results.get(0).toString());
81          XMLUnit.compareXML(EXPECTED_MESSAGE_2, results.get(1).toString());
82      }
83  }