View Javadoc

1   /*
2    * $Id: MuleEventMulticasterTestCase.java 22431 2011-07-18 07:40:35Z 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;
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  
20  import java.util.concurrent.atomic.AtomicInteger;
21  import org.junit.Rule;
22  import org.junit.Test;
23  
24  import static org.junit.Assert.assertEquals;
25  import static org.junit.Assert.assertNotNull;
26  
27  public class MuleEventMulticasterTestCase extends FunctionalTestCase
28  {
29  
30      private final AtomicInteger eventCount = new AtomicInteger(0);
31  
32      @Rule
33      public DynamicPort dynamicPort = new DynamicPort("port1");
34  
35      @Override
36      protected String getConfigResources()
37      {
38          return "org/mule/test/integration/spring/events/mule-events-example-app-context.xml";
39      }
40  
41      @Override
42      protected void doSetUp() throws Exception
43      {
44          eventCount.set(0);
45      }
46  
47      @Test
48      public void testReceiveAsWebService() throws Exception
49      {
50          MuleClient client = new MuleClient(muleContext);
51          OrderManagerBean orderManager = muleContext.getRegistry().get("orderManagerBean");
52          assertNotNull(orderManager);
53          EventCallback callback = new EventCallback()
54          {
55              public void eventReceived(MuleEventContext context, Object o) throws Exception
56              {
57                  eventCount.incrementAndGet();
58              }
59          };
60          orderManager.setEventCallback(callback);
61  
62          Order order = new Order("Sausage and Mash");
63          MuleMessage result = client.send("axis:http://localhost:" + dynamicPort.getNumber() + "/mule/orderManager?method=processOrder", order,
64              null);
65  
66          assertNotNull(result);
67          assertEquals("Order 'Sausage and Mash' Processed", (result.getPayload()));
68      }
69  }