View Javadoc

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