View Javadoc

1   /*
2    * $Id: InOptionalOutOutOnlyAsyncRouterTestCase.java 22659 2011-08-12 12:22: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.test.integration.messaging.meps;
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.DefaultMuleMessage;
23  import org.mule.api.MuleMessage;
24  import org.mule.api.construct.FlowConstruct;
25  import org.mule.api.service.Service;
26  import org.mule.module.client.MuleClient;
27  import org.mule.tck.AbstractServiceAndFlowTestCase;
28  import org.mule.transport.NullPayload;
29  
30  public class InOptionalOutOutOnlyAsyncRouterTestCase extends AbstractServiceAndFlowTestCase
31  {
32      public static final long TIMEOUT = 3000;
33  
34      public InOptionalOutOutOnlyAsyncRouterTestCase(ConfigVariant variant, String configResources)
35      {
36          super(variant, configResources);
37      }
38  
39      @Parameters
40      public static Collection<Object[]> parameters()
41      {
42          return Arrays.asList(new Object[][]{
43              {ConfigVariant.SERVICE,
44                  "org/mule/test/integration/messaging/meps/pattern_In-Optional-Out_Out-Only-Async-Router-service.xml"},
45              {ConfigVariant.FLOW,
46                  "org/mule/test/integration/messaging/meps/pattern_In-Optional-Out_Out-Only-Async-Router-flow.xml"}
47  
48          });
49      }
50  
51      @Test
52      public void testExchange() throws Exception
53      {
54          MuleClient client = new MuleClient(muleContext);
55  
56          MuleMessage result = client.send("inboundEndpoint", "some data", null);
57          assertNotNull(result);
58          assertEquals(NullPayload.getInstance(), result.getPayload());
59          assertNull(result.getExceptionPayload());
60  
61          DefaultMuleMessage msg = new DefaultMuleMessage("some data", muleContext);
62          msg.setOutboundProperty("foo", "bar");
63          result = client.send("inboundEndpoint", msg);
64          assertNotNull(result);
65          assertEquals("got it!", result.getPayloadAsString());
66  
67          if (ConfigVariant.SERVICE.equals(variant))
68          {
69              Service async = muleContext.getRegistry().lookupService("In-Out_Out-Only-Async-Service");
70              Service external = muleContext.getRegistry().lookupService("ExternalApp");
71  
72              assertEquals(2, async.getStatistics().getProcessedEvents());
73              assertEquals(1, external.getStatistics().getProcessedEvents());
74          }
75          else
76          {
77              FlowConstruct async = muleContext.getRegistry().lookupFlowConstruct(
78                  "In-Out_Out-Only-Async-Service");
79              FlowConstruct external = muleContext.getRegistry().lookupFlowConstruct("ExternalApp");
80  
81              assertEquals(2, async.getStatistics().getProcessedEvents());
82              assertEquals(1, external.getStatistics().getProcessedEvents());
83          }
84  
85      }
86  }