View Javadoc

1   /*
2    * $Id: PersistentVMQueueTestCase.java 22505 2011-07-21 15:34:24Z 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  
11  package org.mule.transport.vm;
12  
13  import static org.junit.Assert.assertEquals;
14  import static org.junit.Assert.assertNotNull;
15  import static org.junit.Assert.assertNull;
16  
17  import java.util.Arrays;
18  import java.util.Collection;
19  
20  import org.junit.Test;
21  import org.junit.runners.Parameterized.Parameters;
22  import org.mule.api.MuleMessage;
23  import org.mule.module.client.MuleClient;
24  import org.mule.tck.AbstractServiceAndFlowTestCase;
25  
26  public class PersistentVMQueueTestCase extends AbstractServiceAndFlowTestCase
27  {
28  
29      private static final int RECEIVE_TIMEOUT = 5000;
30  
31      public PersistentVMQueueTestCase(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/persistent-vmqueue-test-service.xml"},
41              {ConfigVariant.FLOW, "vm/persistent-vmqueue-test-flow.xml"}});
42      }
43  
44      @Test
45      public void testAsynchronousDispatching() throws Exception
46      {
47          String input = "Test message";
48          String[] output = {"Test", "message"};
49          MuleClient client = new MuleClient(muleContext);
50          client.dispatch("vm://receiver", input, null);
51          MuleMessage result = client.request("vm://out", RECEIVE_TIMEOUT);
52          assertNotNull(result);
53          assertNotNull(result.getPayload());
54          assertNull(result.getExceptionPayload());
55          String[] payload = (String[]) result.getPayload();
56          assertEquals(output.length, payload.length);
57          for (int i = 0; i < output.length; i++)
58          {
59              assertEquals(output[i], payload[i]);
60          }
61      }
62  
63      @Test
64      public void testAsynchronousDispatchingInFlow() throws Exception
65      {
66          String input = "Test message";
67          String[] output = {"Test", "message"};
68          MuleClient client = new MuleClient(muleContext);
69          client.dispatch("vm://flowReceiver", input, null);
70          MuleMessage result = client.request("vm://flowOut", RECEIVE_TIMEOUT);
71          assertNotNull(result);
72          assertNotNull(result.getPayload());
73          assertNull(result.getExceptionPayload());
74          String[] payload = (String[]) result.getPayload();
75          assertEquals(output.length, payload.length);
76          for (int i = 0; i < output.length; i++)
77          {
78              assertEquals(output[i], payload[i]);
79          }
80      }
81  
82  }