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.routing;
8   
9   import org.mule.api.MuleEvent;
10  import org.mule.api.MuleMessage;
11  import org.mule.api.routing.filter.Filter;
12  import org.mule.tck.SensingNullMessageProcessor;
13  import org.mule.tck.junit4.AbstractMuleContextTestCase;
14  
15  import org.junit.Test;
16  
17  import static org.junit.Assert.assertEquals;
18  import static org.junit.Assert.assertNotNull;
19  import static org.junit.Assert.assertNull;
20  import static org.junit.Assert.assertSame;
21  
22  public class WireTapTestCase extends AbstractMuleContextTestCase
23  {
24  
25      protected SensingNullMessageProcessor tapListener;
26      protected WireTap wireTap;
27  
28      @Override
29      protected void doSetUp() throws Exception
30      {
31          super.doSetUp();
32  
33          wireTap = new WireTap();
34          tapListener = getSensingNullMessageProcessor();
35          wireTap.setTap(tapListener);
36      }
37  
38      @Test
39      public void testWireTapNoFilter() throws Exception
40      {
41          MuleEvent event = getTestInboundEvent("data");
42          MuleEvent primaryOutput = wireTap.process(event);
43  
44          assertSame(event, primaryOutput);
45  
46          assertNotNull(tapListener.event);
47          assertEquals(event.getMessage().getPayload(), tapListener.event.getMessage().getPayload());
48      }
49  
50      @Test
51      public void testWireTapFilterAccepted() throws Exception
52      {
53          wireTap.setFilter(new Filter()
54          {
55              public boolean accept(MuleMessage message)
56              {
57                  return true;
58              }
59          });
60  
61          MuleEvent event = getTestInboundEvent("data");
62          MuleEvent primaryOutput = wireTap.process(event);
63  
64          assertSame(event, primaryOutput);
65  
66          assertNotNull(tapListener.event);
67          assertEquals(event.getMessage().getPayload(), tapListener.event.getMessage().getPayload());
68      }
69  
70      @Test
71      public void testWireTapFilterUnaccepted() throws Exception
72      {
73          wireTap.setFilter(new Filter()
74          {
75              public boolean accept(MuleMessage message)
76              {
77                  return false;
78              }
79          });
80  
81          MuleEvent event = getTestInboundEvent("data");
82          MuleEvent primaryOutput = wireTap.process(event);
83  
84          assertSame(event, primaryOutput);
85  
86          assertNull(tapListener.event);
87      }
88  
89      @Test
90      public void testWireTapNullTap() throws Exception
91      {
92          wireTap.setTap(null);
93  
94          MuleEvent event = getTestInboundEvent("data");
95          MuleEvent primaryOutput = wireTap.process(event);
96  
97          assertSame(event, primaryOutput);
98      }
99  
100 }