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;
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.junit.Test;
14  
15  import static org.junit.Assert.assertEquals;
16  import static org.junit.Assert.assertNotNull;
17  import static org.junit.Assert.assertNull;
18  
19  public class PersistentVMQueueTestCase extends FunctionalTestCase
20  {
21  
22      private static final int RECEIVE_TIMEOUT = 5000;
23  
24      @Override
25      protected String getConfigResources()
26      {
27          return "vm/persistent-vmqueue-test.xml";
28      }
29  
30      @Test
31      public void testAsynchronousDispatching() throws Exception
32      {
33          String input = "Test message";
34          String[] output = {"Test", "message"};
35          MuleClient client = new MuleClient(muleContext);
36          client.dispatch("vm://receiver", input, null);
37          MuleMessage result = client.request("vm://out", RECEIVE_TIMEOUT);
38          assertNotNull(result);
39          assertNotNull(result.getPayload());
40          assertNull(result.getExceptionPayload());
41          String[] payload = (String[]) result.getPayload();
42          assertEquals(output.length, payload.length);
43          for (int i = 0; i < output.length; i++)
44          {
45              assertEquals(output[i], payload[i]);
46          }
47      }
48  
49      @Test
50      public void testAsynchronousDispatchingInFlow() throws Exception
51      {
52          String input = "Test message";
53          String[] output = {"Test", "message"};
54          MuleClient client = new MuleClient(muleContext);
55          client.dispatch("vm://flowReceiver", input, null);
56          MuleMessage result = client.request("vm://flowOut", RECEIVE_TIMEOUT);
57          assertNotNull(result);
58          assertNotNull(result.getPayload());
59          assertNull(result.getExceptionPayload());
60          String[] payload = (String[]) result.getPayload();
61          assertEquals(output.length, payload.length);
62          for (int i = 0; i < output.length; i++)
63          {
64              assertEquals(output[i], payload[i]);
65          }
66      }
67  
68  }