1
2
3
4
5
6
7
8
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.AbstractServiceAndFlowTestCase;
17
18 import java.util.Arrays;
19 import java.util.Collection;
20 import java.util.List;
21
22 import org.custommonkey.xmlunit.XMLUnit;
23 import org.junit.Test;
24 import org.junit.runners.Parameterized.Parameters;
25
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertTrue;
29
30 public class ExpressionSplitterXPathTestCase extends AbstractServiceAndFlowTestCase
31 {
32 private final String MESSAGE = "<Batch xmlns=\"http://acme.com\">\n" +
33 " <Trade>\n" +
34 " <Type>CASH</Type>\n" +
35 " <Amount>40000</Amount>\n" +
36 " <Currency>USD</Currency>\n" +
37 " <Date>28102008</Date>\n" +
38 " </Trade> \n" +
39 " <Trade>\n" +
40 " <Type>CASH</Type>\n" +
41 " <Amount>2000</Amount>\n" +
42 " <Currency>GBP</Currency>\n" +
43 " <Date>28102008</Date>\n" +
44 " </Trade> \n" +
45 "</Batch>";
46
47 private final String EXPECTED_MESSAGE_1 = "<Trade xmlns=\"http://acme.com\">\n" +
48 " <Type>CASH</Type>\n" +
49 " <Amount>40000</Amount>\n" +
50 " <Currency>USD</Currency>\n" +
51 " <Date>28102008</Date>\n" +
52 " <Received>ServiceOne</Received>\n" +
53 " </Trade>";
54
55 private final String EXPECTED_MESSAGE_2 = "<Trade xmlns=\"http://acme.com\">\n" +
56 " <Type>CASH</Type>\n" +
57 " <Amount>2000</Amount>\n" +
58 " <Currency>GBP</Currency>\n" +
59 " <Date>28102008</Date>\n" +
60 " <Received>ServiceTwo</Received>\n" +
61 " </Trade>";
62
63
64 @Parameters
65 public static Collection<Object[]> parameters()
66 {
67 return Arrays.asList(new Object[][]{
68 {ConfigVariant.SERVICE, "org/mule/test/integration/routing/outbound/expression-splitter-xpath-test-service.xml"},
69 {ConfigVariant.FLOW, "org/mule/test/integration/routing/outbound/expression-splitter-xpath-test-flow.xml"}
70 });
71 }
72
73 public ExpressionSplitterXPathTestCase(ConfigVariant variant, String configResources)
74 {
75 super(variant, configResources);
76 XMLUnit.setIgnoreWhitespace(true);
77 }
78
79 @Test
80 public void testRecipientList() throws Exception
81 {
82 MuleClient client = new MuleClient(muleContext);
83 MuleMessage result = client.send("vm://distributor.queue", MESSAGE, null);
84
85 assertNotNull(result);
86 assertTrue(result instanceof MuleMessageCollection);
87 MuleMessageCollection coll = (MuleMessageCollection) result;
88 assertEquals(2, coll.size());
89 List<?> results = (List<?>) coll.getPayload();
90
91 XMLUnit.compareXML(EXPECTED_MESSAGE_1, results.get(0).toString());
92 XMLUnit.compareXML(EXPECTED_MESSAGE_2, results.get(1).toString());
93 }
94 }