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.transport.vm.functional;
8   
9   import org.mule.api.MuleException;
10  import org.mule.api.MuleMessage;
11  import org.mule.module.client.MuleClient;
12  import org.mule.tck.junit4.FunctionalTestCase;
13  
14  import java.util.ArrayList;
15  import java.util.List;
16  
17  import org.junit.Test;
18  
19  import static org.junit.Assert.assertEquals;
20  import static org.junit.Assert.assertNotNull;
21  import static org.junit.Assert.fail;
22  
23  public class VMRequestorTestCase extends FunctionalTestCase
24  {
25  
26      @Override
27      protected String getConfigResources()
28      {
29          return "vm/vm-functional-test.xml";
30      }
31  
32      @Test
33      public void testRequestorWithUpdateonMessage() throws Exception
34      {
35  
36          for (int i = 0; i < 10; i++)
37          {
38              makeClientRequest("test" + i);
39          }
40  
41          MuleClient client = new MuleClient(muleContext);
42          List results = new ArrayList();
43          MuleMessage result = null;
44          for (int i = 0; i < 10; i++)
45          {
46              result = client.request("vm://out", 3000L);
47              assertNotNull(result);
48              results.add(result.getPayloadAsString());
49          }
50  
51          assertEquals(10, results.size());
52  
53          //This would fail if the owner thread info was not updated
54          result.setOutboundProperty("foo", "bar");
55      }
56  
57      protected void makeClientRequest(final String message) throws MuleException
58      {
59          final MuleClient client = new MuleClient(muleContext);
60          Thread t = new Thread(new Runnable()
61          {
62              public void run()
63              {
64                  try
65                  {
66                      client.send("vm://in", message, null);
67                  }
68                  catch (MuleException e)
69                  {
70                      fail("failed to dispatch event: " + e);
71                      e.printStackTrace();
72                  }
73              }
74          }, "test-thread");
75          t.start();
76      }
77      
78  }