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.messaging.meps;
8   
9   import org.mule.DefaultMuleMessage;
10  import org.mule.api.MuleMessage;
11  import org.mule.api.service.Service;
12  import org.mule.module.client.MuleClient;
13  import org.mule.tck.junit4.FunctionalTestCase;
14  import org.mule.transport.NullPayload;
15  
16  import org.junit.Test;
17  
18  import static org.junit.Assert.assertEquals;
19  import static org.junit.Assert.assertNotNull;
20  import static org.junit.Assert.assertNull;
21  
22  public class InOptionalOutOutOnlyAsyncRouterTestCase extends FunctionalTestCase
23  {
24  
25      public static final long TIMEOUT = 3000;
26  
27      @Override
28      protected String getConfigResources()
29      {
30          return "org/mule/test/integration/messaging/meps/pattern_In-Optional-Out_Out-Only-Async-Router.xml";
31      }
32  
33      @Test
34      public void testExchange() throws Exception
35      {
36          MuleClient client = new MuleClient(muleContext);
37  
38          MuleMessage result = client.send("inboundEndpoint", "some data", null);
39          assertNotNull(result);
40          assertEquals(NullPayload.getInstance(), result.getPayload());
41          assertNull(result.getExceptionPayload());
42  
43          DefaultMuleMessage msg = new DefaultMuleMessage("some data", muleContext);
44          msg.setOutboundProperty("foo", "bar");
45          result = client.send("inboundEndpoint", msg);
46          assertNotNull(result);
47          assertEquals("got it!", result.getPayloadAsString());
48  
49          Service async = muleContext.getRegistry().lookupService("In-Out_Out-Only-Async-Service");
50          Service external = muleContext.getRegistry().lookupService("ExternalApp");
51  
52          assertEquals(2, async.getStatistics().getProcessedEvents());
53          assertEquals(1, external.getStatistics().getProcessedEvents());
54      }
55  }