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.test.integration.endpoints;
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  import static org.junit.Assert.assertTrue;
19  
20  public class EndpointMessageProcessorsTestCase extends FunctionalTestCase
21  {
22  
23      private static final int TIMEOUT = 5000;
24  
25      @Override
26      protected String getConfigResources()
27      {
28          return "org/mule/test/integration/endpoints/endpoint-message-processors.xml";
29      }
30  
31      @Test
32      public void testSynchronousOutbound() throws Exception
33      {
34          MuleClient client = new MuleClient(muleContext);
35          
36          MuleMessage response = client.send("vm://in1", "input", null);
37          assertNotNull(response);
38          assertEquals("input:A:B:service1:E:F:service2:G:H:C:D", response.getPayload());
39      }
40  
41      @Test
42      public void testAsynchronousOutbound() throws Exception
43      {
44          MuleClient client = new MuleClient(muleContext);
45          
46          MuleMessage response = client.send("vm://in2", "input", null);
47          assertNotNull(response);
48          assertEquals("input:A:B:service1:C:D", response.getPayload());
49  
50          response = client.request("vm://out2", TIMEOUT);
51          assertNotNull(response);
52          assertEquals("input:A:B:service1:E:F", response.getPayload());
53      }
54  
55      @Test
56      public void testLegacyAttributes() throws Exception
57      {
58          MuleClient client = new MuleClient(muleContext);
59          
60          MuleMessage response = client.send("vm://in3", "input", null);
61          assertNotNull(response);
62          assertEquals("input:A:B:service1:E:F:service2:G:H:C:D", response.getPayload());
63      }
64  
65      @Test
66      public void testRouters() throws Exception
67      {
68          MuleClient client = new MuleClient(muleContext);
69          
70          client.dispatch("vm://in4", "input1,input2,input3", null);
71  
72          MuleMessage response = client.request("vm://wiretap1", TIMEOUT);
73          assertNotNull(response);
74          assertEquals("input1,input2,input3 (tapped)", response.getPayload());
75  
76          response = client.request("vm://wiretap2", TIMEOUT);
77          assertNotNull(response);
78          assertTrue(response.getPayloadAsString().startsWith("input"));
79          assertTrue(response.getPayloadAsString().endsWith(":A:B:service1 (tapped)"));
80          response = client.request("vm://wiretap2", TIMEOUT);
81          assertNotNull(response);
82          assertTrue(response.getPayloadAsString().startsWith("input"));
83          assertTrue(response.getPayloadAsString().endsWith(":A:B:service1 (tapped)"));
84          response = client.request("vm://wiretap2", TIMEOUT);
85          assertNotNull(response);
86          assertTrue(response.getPayloadAsString().startsWith("input"));
87          assertTrue(response.getPayloadAsString().endsWith(":A:B:service1 (tapped)"));
88          response = client.request("vm://wiretap2", TIMEOUT);
89          assertNull(response);
90  
91          response = client.request("vm://out4", TIMEOUT);
92          assertNotNull(response);
93          assertTrue(response.getPayloadAsString().startsWith("input"));
94          assertTrue(response.getPayloadAsString().endsWith(":A:B:service1:E:F"));
95          response = client.request("vm://out4", TIMEOUT);
96          assertNotNull(response);
97          assertTrue(response.getPayloadAsString().startsWith("input"));
98          assertTrue(response.getPayloadAsString().endsWith(":A:B:service1:E:F"));
99          response = client.request("vm://out4", TIMEOUT);
100         assertNotNull(response);
101         assertTrue(response.getPayloadAsString().startsWith("input"));
102         assertTrue(response.getPayloadAsString().endsWith(":A:B:service1:E:F"));
103         response = client.request("vm://out4", TIMEOUT);
104         assertNull(response);
105     }
106 }