View Javadoc

1   /*
2    * $Id: WireTapTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
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.routing;
12  
13  
14  import org.mule.api.context.notification.ServerNotification;
15  import org.mule.module.client.MuleClient;
16  import org.mule.tck.FunctionalTestCase;
17  import org.mule.tck.functional.FunctionalTestNotificationListener;
18  import org.mule.util.concurrent.Latch;
19  
20  import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
21  
22  public class WireTapTestCase extends FunctionalTestCase
23  {
24  
25      protected String getConfigResources()
26      {
27          return "org/mule/test/integration/routing/wire-tap.xml";
28      }
29  
30      public void testWireTap() throws Exception
31      {
32          final Latch receiverLatch = new Latch();
33          final Latch tappedReceiver1Latch = new Latch();
34          final Latch tappedReceiver2Latch = new Latch();
35          muleContext.registerListener(new FunctionalTestNotificationListener()
36          {
37              public void onNotification(ServerNotification notification)
38              {
39                  if (notification.getResourceIdentifier().equals("Receiver"))
40                  {
41                      receiverLatch.countDown();
42                  }
43                  else if (notification.getResourceIdentifier().equals("TappedReceiver1"))
44                  {
45                      tappedReceiver1Latch.countDown();
46                  }
47                  else if (notification.getResourceIdentifier().equals("TappedReceiver2"))
48                  {
49                      tappedReceiver2Latch.countDown();
50                  }
51              }
52          });
53          MuleClient client = new MuleClient(muleContext);
54          client.send("vm://inbound.channel", "test", null);
55          assertTrue(receiverLatch.await(3L, TimeUnit.SECONDS));
56          assertTrue(tappedReceiver1Latch.await(1L, TimeUnit.SECONDS));
57          assertTrue(tappedReceiver2Latch.await(1L, TimeUnit.SECONDS));
58      }
59  }