View Javadoc

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