View Javadoc

1   /*
2    * $Id: ExpressionRecipientListAsyncTestCase.java 22422 2011-07-15 08:22:16Z 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.test.integration.routing.outbound;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.module.client.MuleClient;
15  import org.mule.tck.AbstractServiceAndFlowTestCase;
16  
17  import java.util.ArrayList;
18  import java.util.Arrays;
19  import java.util.Collection;
20  import java.util.HashMap;
21  import java.util.List;
22  import java.util.Map;
23  
24  import org.junit.Test;
25  import org.junit.runners.Parameterized.Parameters;
26  
27  import static org.junit.Assert.assertNotNull;
28  import static org.junit.Assert.assertTrue;
29  
30  public class ExpressionRecipientListAsyncTestCase extends AbstractServiceAndFlowTestCase
31  {
32      @Parameters
33      public static Collection<Object[]> parameters()
34      {
35          return Arrays.asList(new Object[][]{
36              {ConfigVariant.SERVICE,
37                  "org/mule/test/integration/routing/outbound/expression-recipient-list-async-test-service.xml"},
38              {ConfigVariant.FLOW,
39                  "org/mule/test/integration/routing/outbound/expression-recipient-list-async-test-flow.xml"}});
40      }
41  
42      public ExpressionRecipientListAsyncTestCase(ConfigVariant variant, String configResources)
43      {
44          super(variant, configResources);
45      }
46  
47      @Test
48      public void testRecipientList() throws Exception
49      {
50          String message = "test";
51          MuleClient client = new MuleClient(muleContext);
52          Map<String, Object> props = new HashMap<String, Object>(3);
53          props.put("recipient1", "vm://service1.queue");
54          props.put("recipient2", "vm://service2.queue");
55          props.put("recipient3", "vm://service3.queue");
56          client.dispatch("vm://distributor.queue", message, props);
57  
58          List<Object> results = new ArrayList<Object>(3);
59  
60          MuleMessage result = client.request("vm://collector.queue", 5000);
61          assertNotNull(result);
62          results.add(result.getPayload());
63  
64          result = client.request("vm://collector.queue", 3000);
65          assertNotNull(result);
66          results.add(result.getPayload());
67  
68          result = client.request("vm://collector.queue", 3000);
69          assertNotNull(result);
70          results.add(result.getPayload());
71  
72          assertTrue(results.contains("test 1 Received"));
73          assertTrue(results.contains("test 2 Received"));
74          assertTrue(results.contains("test 3 Received"));
75      }
76  }