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.spring.events.async;
8   
9   import org.mule.api.MuleEventContext;
10  import org.mule.api.MuleMessage;
11  import org.mule.module.client.MuleClient;
12  import org.mule.tck.functional.EventCallback;
13  import org.mule.tck.junit4.FunctionalTestCase;
14  import org.mule.tck.junit4.rule.DynamicPort;
15  import org.mule.test.integration.spring.events.Order;
16  import org.mule.test.integration.spring.events.OrderManagerBean;
17  
18  import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicInteger;
19  import org.junit.Rule;
20  import org.junit.Test;
21  
22  import static org.junit.Assert.assertEquals;
23  import static org.junit.Assert.assertNotNull;
24  
25  /**
26   * <code>SpringEventsJmsExampleTestCase</code> is a testcase used to test the
27   * example config in the docco. this test is not run when building this module as it
28   * relies on Jms, it's used to verify the example config works.
29   */
30  public class SpringEventsJmsAsyncExampleTestCase extends FunctionalTestCase
31  {
32      private final AtomicInteger eventCount = new AtomicInteger(0);
33  
34      @Rule
35      public DynamicPort dynamicPort = new DynamicPort("port1");
36  
37      @Override
38      protected String getConfigResources()
39      {
40          return "org/mule/test/integration/spring/events/async/mule-events-example-async-app-context.xml";
41      }
42  
43      @Override
44      protected void doSetUp() throws Exception
45      {
46          super.doSetUp();
47          eventCount.set(0);
48      }
49  
50      @Test
51      public void testReceiveAsWebService() throws Exception
52      {
53          MuleClient client = new MuleClient(muleContext);
54          OrderManagerBean orderManager = (OrderManagerBean) muleContext.getRegistry().lookupObject("orderManagerBean");
55          assertNotNull(orderManager);
56          EventCallback callback = new EventCallback()
57          {
58              public void eventReceived(MuleEventContext context, Object o) throws Exception
59              {
60                  eventCount.incrementAndGet();
61              }
62          };
63          orderManager.setEventCallback(callback);
64  
65          Order order = new Order("Sausage and Mash");
66          // Make an async call
67          client.dispatch("axis:http://localhost:" + dynamicPort.getNumber() + "/mule/orderManager?method=processOrderAsync", order, null);
68  
69          MuleMessage result = client.request("jms://processed.queue", 10000);
70          assertNotNull(result);
71          assertEquals("Order 'Sausage and Mash' Processed Async", result.getPayload());
72      }
73  
74  }