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.module.client.MuleClient;
11  import org.mule.tck.junit4.FunctionalTestCase;
12  
13  import org.custommonkey.xmlunit.XMLUnit;
14  import org.junit.Test;
15  
16  import static org.junit.Assert.assertNotNull;
17  import static org.junit.Assert.assertNull;
18  
19  public class ExpressionSplitterXPathWithFiltersTestCase extends FunctionalTestCase
20  {
21      private static final String MESSAGE = "<Foo>\n" +
22              "    <Bar>\n" +
23              "        <One>One</One>\n" +
24              "        <Three>Three</Three>\n" +
25              "        <Two>Two</Two>\n" +
26              "        <Three>Three</Three>\n" +
27              "        <Three>Three</Three>\n" +
28              "        <One>One</One>\n" +
29              "    </Bar>    \n" +
30              "</Foo>";
31  
32      private MuleClient client;
33  
34      public ExpressionSplitterXPathWithFiltersTestCase()
35      {
36          XMLUnit.setIgnoreWhitespace(true);
37      }
38  
39      @Override
40      protected String getConfigResources()
41      {
42          return "org/mule/test/integration/routing/outbound/expression-splitter-xpath-with-filters-test.xml";
43      }
44  
45      @Test
46      public void testRecipientList() throws Exception
47      {
48          client = new MuleClient(muleContext);
49          client.dispatch("vm://distributor.queue", MESSAGE, null);
50  
51          readFromQueue("vm://service1.out", 2, "One");
52          readFromQueue("vm://service2.out", 1, "Two");
53          readFromQueue("vm://service3.out", 3, "Three");
54      }
55  
56      public void readFromQueue(String name, int expectedNumber, String number) throws Exception
57      {
58          MuleMessage message;
59          for (int i = 0; i < expectedNumber; i++)
60          {
61              message = client.request(name, 2000L);
62              assertNotNull(message);
63              XMLUnit.compareXML("<" + number + ">" + number + "</" + number + ">", message.getPayloadAsString());
64          }
65  
66          assertNull(client.request(name, 1000L));
67      }
68  }