View Javadoc

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