View Javadoc

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