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 VMFunctionalTestCase extends FunctionalTestCase
20  {
21  
22      public VMFunctionalTestCase()
23      {
24          setDisposeContextPerClass(true);
25      }
26  
27      @Override
28      protected String getConfigResources()
29      {
30          return "vm/vm-functional-test.xml";
31      }
32  
33      @Test
34      public void testSingleMessage() throws Exception
35      {
36          MuleClient client = new MuleClient(muleContext);
37          client.dispatch("vm://in", "Marco", null);
38          MuleMessage response = client.request("vm://out", RECEIVE_TIMEOUT);
39          assertNotNull("Response is null", response);
40          assertEquals("Polo", response.getPayload());
41      }
42  
43      @Test
44      public void testRequest() throws Exception
45      {
46          MuleClient client = new MuleClient(muleContext);
47          client.dispatch("vm://in", "Marco", null);
48          MuleMessage response = client.request("vm://out", RECEIVE_TIMEOUT);
49          assertNotNull("Response is null", response);
50          assertEquals("Polo", response.getPayload());
51      }
52  
53      @Test
54      public void testMultipleMessages() throws Exception
55      {
56          MuleClient client = new MuleClient(muleContext);
57          client.dispatch("vm://in", "Marco", null);
58          client.dispatch("vm://in", "Marco", null);
59          client.dispatch("vm://in", "Marco", null);
60          MuleMessage response;
61          for (int i = 0; i < 3; ++i)
62          {
63              response = client.request("vm://out", RECEIVE_TIMEOUT);
64              assertNotNull("Response is null", response);
65              assertEquals("Polo", response.getPayload());
66          }
67  
68          MuleMessage secondMessage = client.request("vm://out", RECEIVE_TIMEOUT);
69          assertNull(secondMessage);
70      }
71  
72      @Test
73      public void testOneWayChain() throws Exception
74      {
75          MuleClient client = new MuleClient(muleContext);
76          client.dispatch("vm://in1", "Marco", null);
77          MuleMessage response = client.request("vm://out1", RECEIVE_TIMEOUT);
78          assertNotNull("Response is null", response);
79          assertEquals("Polo", response.getPayload());
80      }
81  
82      @Test
83      public void testRequestResponseChain() throws Exception
84      {
85          MuleClient client = new MuleClient(muleContext);
86          MuleMessage response = client.send("vm://in2", "Marco", null);
87          assertNotNull("Response is null", response);
88          assertEquals("Polo", response.getPayload());
89      }
90      
91      @Test
92      public void testNoMessageDuplication() throws Exception
93      {
94          MuleClient client = new MuleClient(muleContext);
95          client.dispatch("vm://in", "Marco", null);
96          MuleMessage response = client.request("vm://out", RECEIVE_TIMEOUT);
97          assertNotNull("Response is null", response);
98          assertEquals("Polo", response.getPayload());
99          MuleMessage secondMessage = client.request("vm://out", RECEIVE_TIMEOUT);
100         assertNull(secondMessage);
101     }
102 }