View Javadoc

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