View Javadoc

1   /*
2    * $Id: WireTapTestCase.java 22422 2011-07-15 08:22:16Z 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.routing;
12  
13  import org.mule.api.context.notification.ServerNotification;
14  import org.mule.module.client.MuleClient;
15  import org.mule.tck.AbstractServiceAndFlowTestCase;
16  import org.mule.tck.functional.FunctionalTestNotificationListener;
17  import org.mule.util.concurrent.Latch;
18  
19  import java.util.Arrays;
20  import java.util.Collection;
21  import java.util.concurrent.TimeUnit;
22  
23  import org.junit.Test;
24  import org.junit.runners.Parameterized.Parameters;
25  
26  import static org.junit.Assert.assertTrue;
27  
28  public class WireTapTestCase extends AbstractServiceAndFlowTestCase
29  {
30      @Parameters
31      public static Collection<Object[]> parameters()
32      {
33          return Arrays.asList(new Object[][]{
34              {ConfigVariant.SERVICE, "org/mule/test/integration/routing/wire-tap-service.xml"},
35              {ConfigVariant.FLOW, "org/mule/test/integration/routing/wire-tap-flow.xml"}});
36      }
37  
38      public WireTapTestCase(ConfigVariant variant, String configResources)
39      {
40          super(variant, configResources);
41      }
42  
43      @Test
44      public void testWireTap() throws Exception
45      {
46          final Latch receiverLatch = new Latch();
47          final Latch tappedReceiver1Latch = new Latch();
48          final Latch tappedReceiver2Latch = new Latch();
49          muleContext.registerListener(new FunctionalTestNotificationListener()
50          {
51              @Override
52              public void onNotification(ServerNotification notification)
53              {
54                  if (notification.getResourceIdentifier().equals("Receiver"))
55                  {
56                      receiverLatch.countDown();
57                  }
58                  else if (notification.getResourceIdentifier().equals("TappedReceiver1"))
59                  {
60                      tappedReceiver1Latch.countDown();
61                  }
62                  else if (notification.getResourceIdentifier().equals("TappedReceiver2"))
63                  {
64                      tappedReceiver2Latch.countDown();
65                  }
66              }
67          });
68          MuleClient client = new MuleClient(muleContext);
69          client.send("vm://inbound.channel", "test", null);
70          assertTrue(receiverLatch.await(3L, TimeUnit.SECONDS));
71          assertTrue(tappedReceiver1Latch.await(1L, TimeUnit.SECONDS));
72          assertTrue(tappedReceiver2Latch.await(1L, TimeUnit.SECONDS));
73      }
74  }