View Javadoc

1   /*
2    * $Id: EndpointMessageProcessorsTestCase.java 22419 2011-07-15 03:41:06Z dirk.olmes $
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.test.integration.endpoints;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.module.client.MuleClient;
15  import org.mule.tck.junit4.FunctionalTestCase;
16  
17  import org.junit.Test;
18  
19  import static org.junit.Assert.assertEquals;
20  import static org.junit.Assert.assertNotNull;
21  import static org.junit.Assert.assertNull;
22  import static org.junit.Assert.assertTrue;
23  
24  public class EndpointMessageProcessorsTestCase extends FunctionalTestCase
25  {
26  
27      private static final int TIMEOUT = 5000;
28  
29      @Override
30      protected String getConfigResources()
31      {
32          return "org/mule/test/integration/endpoints/endpoint-message-processors.xml";
33      }
34  
35      @Test
36      public void testSynchronousOutbound() throws Exception
37      {
38          MuleClient client = new MuleClient(muleContext);
39          
40          MuleMessage response = client.send("vm://in1", "input", null);
41          assertNotNull(response);
42          assertEquals("input:A:B:service1:E:F:service2:G:H:C:D", response.getPayload());
43      }
44  
45      @Test
46      public void testAsynchronousOutbound() throws Exception
47      {
48          MuleClient client = new MuleClient(muleContext);
49          
50          MuleMessage response = client.send("vm://in2", "input", null);
51          assertNotNull(response);
52          assertEquals("input:A:B:service1:C:D", response.getPayload());
53  
54          response = client.request("vm://out2", TIMEOUT);
55          assertNotNull(response);
56          assertEquals("input:A:B:service1:E:F", response.getPayload());
57      }
58  
59      @Test
60      public void testLegacyAttributes() throws Exception
61      {
62          MuleClient client = new MuleClient(muleContext);
63          
64          MuleMessage response = client.send("vm://in3", "input", null);
65          assertNotNull(response);
66          assertEquals("input:A:B:service1:E:F:service2:G:H:C:D", response.getPayload());
67      }
68  
69      @Test
70      public void testRouters() throws Exception
71      {
72          MuleClient client = new MuleClient(muleContext);
73          
74          client.dispatch("vm://in4", "input1,input2,input3", null);
75  
76          MuleMessage response = client.request("vm://wiretap1", TIMEOUT);
77          assertNotNull(response);
78          assertEquals("input1,input2,input3 (tapped)", response.getPayload());
79  
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          assertNotNull(response);
90          assertTrue(response.getPayloadAsString().startsWith("input"));
91          assertTrue(response.getPayloadAsString().endsWith(":A:B:service1 (tapped)"));
92          response = client.request("vm://wiretap2", TIMEOUT);
93          assertNull(response);
94  
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         assertNotNull(response);
105         assertTrue(response.getPayloadAsString().startsWith("input"));
106         assertTrue(response.getPayloadAsString().endsWith(":A:B:service1:E:F"));
107         response = client.request("vm://out4", TIMEOUT);
108         assertNull(response);
109     }
110 }