View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.test.integration.routing;
8   
9   
10  import org.mule.api.context.notification.ServerNotification;
11  import org.mule.module.client.MuleClient;
12  import org.mule.tck.functional.FunctionalTestNotificationListener;
13  import org.mule.tck.junit4.FunctionalTestCase;
14  import org.mule.util.concurrent.Latch;
15  
16  import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
17  import org.junit.Test;
18  
19  import static org.junit.Assert.assertTrue;
20  
21  public class WireTapTestCase extends FunctionalTestCase
22  {
23  
24      @Override
25      protected String getConfigResources()
26      {
27          return "org/mule/test/integration/routing/wire-tap.xml";
28      }
29  
30      @Test
31      public void testWireTap() throws Exception
32      {
33          final Latch receiverLatch = new Latch();
34          final Latch tappedReceiver1Latch = new Latch();
35          final Latch tappedReceiver2Latch = new Latch();
36          muleContext.registerListener(new FunctionalTestNotificationListener()
37          {
38              public void onNotification(ServerNotification notification)
39              {
40                  if (notification.getResourceIdentifier().equals("Receiver"))
41                  {
42                      receiverLatch.countDown();
43                  }
44                  else if (notification.getResourceIdentifier().equals("TappedReceiver1"))
45                  {
46                      tappedReceiver1Latch.countDown();
47                  }
48                  else if (notification.getResourceIdentifier().equals("TappedReceiver2"))
49                  {
50                      tappedReceiver2Latch.countDown();
51                  }
52              }
53          });
54          MuleClient client = new MuleClient(muleContext);
55          client.send("vm://inbound.channel", "test", null);
56          assertTrue(receiverLatch.await(3L, TimeUnit.SECONDS));
57          assertTrue(tappedReceiver1Latch.await(1L, TimeUnit.SECONDS));
58          assertTrue(tappedReceiver2Latch.await(1L, TimeUnit.SECONDS));
59      }
60  }