View Javadoc

1   /*
2    * $Id: VMRequestorTestCase.java 22449 2011-07-19 07:40:43Z justin.calleja $
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  package org.mule.transport.vm.functional;
11  
12  import static org.junit.Assert.assertEquals;
13  import static org.junit.Assert.assertNotNull;
14  import static org.junit.Assert.fail;
15  
16  import java.util.ArrayList;
17  import java.util.Arrays;
18  import java.util.Collection;
19  import java.util.List;
20  
21  import org.junit.Test;
22  import org.junit.runners.Parameterized.Parameters;
23  import org.mule.api.MuleException;
24  import org.mule.api.MuleMessage;
25  import org.mule.module.client.MuleClient;
26  import org.mule.tck.AbstractServiceAndFlowTestCase;
27  
28  public class VMRequestorTestCase extends AbstractServiceAndFlowTestCase
29  {
30  
31      public VMRequestorTestCase(ConfigVariant variant, String configResources)
32      {
33          super(variant, configResources);
34      }
35      
36      @Parameters
37      public static Collection<Object[]> parameters()
38      {
39          return Arrays.asList(new Object[][]{
40              {ConfigVariant.SERVICE, "vm/vm-functional-test-service.xml"},
41              {ConfigVariant.FLOW, "vm/vm-functional-test-flow.xml"}
42          });
43      }
44  
45      @Test
46      public void testRequestorWithUpdateonMessage() throws Exception
47      {
48  
49          for (int i = 0; i < 10; i++)
50          {
51              makeClientRequest("test" + i);
52          }
53  
54          MuleClient client = new MuleClient(muleContext);
55          List results = new ArrayList();
56          MuleMessage result = null;
57          for (int i = 0; i < 10; i++)
58          {
59              result = client.request("vm://out", 3000L);
60              assertNotNull(result);
61              results.add(result.getPayloadAsString());
62          }
63  
64          assertEquals(10, results.size());
65  
66          //This would fail if the owner thread info was not updated
67          result.setOutboundProperty("foo", "bar");
68      }
69  
70      protected void makeClientRequest(final String message) throws MuleException
71      {
72          final MuleClient client = new MuleClient(muleContext);
73          Thread t = new Thread(new Runnable()
74          {
75              public void run()
76              {
77                  try
78                  {
79                      client.send("vm://in", message, null);
80                  }
81                  catch (MuleException e)
82                  {
83                      fail("failed to dispatch event: " + e);
84                      e.printStackTrace();
85                  }
86              }
87          }, "test-thread");
88          t.start();
89      }
90      
91  }