View Javadoc

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