View Javadoc

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