View Javadoc

1   /*
2    * $Id: MulticastRouterMule2112TestCase.java 20321 2010-11-24 15:21:24Z dfeist $
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.issues;
12  
13  import org.mule.api.MuleEventContext;
14  import org.mule.module.client.MuleClient;
15  import org.mule.tck.FunctionalTestCase;
16  import org.mule.tck.functional.EventCallback;
17  import org.mule.tck.functional.FunctionalTestComponent;
18  
19  import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicBoolean;
20  
21  public class MulticastRouterMule2112TestCase  extends FunctionalTestCase
22  {
23  
24      protected String getConfigResources()
25      {
26          return "issues/multicast-router-mule-2112-test.xml";
27      }
28  
29      public void testMulticastRoutingOverTwoEndpoints() throws Exception
30      {
31          FunctionalTestComponent hop1 = getFunctionalTestComponent("hop1");
32          assertNotNull(hop1);
33          FunctionalTestComponent hop2 = getFunctionalTestComponent("hop2");
34          assertNotNull(hop2);
35  
36          final AtomicBoolean hop1made = new AtomicBoolean(false);
37          EventCallback callback1 = new EventCallback()
38          {
39              public void eventReceived(final MuleEventContext context, final Object component) throws Exception
40              {
41                  assertTrue(hop1made.compareAndSet(false, true));
42              }
43          };
44  
45          final AtomicBoolean hop2made = new AtomicBoolean(false);
46          EventCallback callback2 = new EventCallback()
47          {
48              public void eventReceived(final MuleEventContext context, final Object component) throws Exception
49              {
50                  assertTrue(hop2made.compareAndSet(false, true));
51              }
52          };
53  
54          hop1.setEventCallback(callback1);
55          hop2.setEventCallback(callback2);
56  
57          MuleClient client = new MuleClient(muleContext);
58          client.send("vm://inbound", "payload", null);
59          Thread.sleep(1000);
60  
61          assertTrue("First callback never fired", hop1made.get());
62          assertTrue("Second callback never fired", hop2made.get());
63      }
64  
65  }