View Javadoc

1   /*
2    * $Id: ExceptionTypeFilterTestCase.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.filters;
12  
13  import org.mule.DefaultMuleMessage;
14  import org.mule.api.MuleContext;
15  import org.mule.api.MuleMessage;
16  import org.mule.message.DefaultExceptionPayload;
17  import org.mule.tck.junit4.AbstractMuleTestCase;
18  
19  import java.io.IOException;
20  
21  import org.junit.Test;
22  
23  import static org.junit.Assert.assertNull;
24  import static org.junit.Assert.assertTrue;
25  import static org.mockito.Mockito.mock;
26  
27  public class ExceptionTypeFilterTestCase extends AbstractMuleTestCase
28  {
29  
30      private MuleContext muleContext = mock(MuleContext.class);
31  
32      @Test
33      public void testExceptionTypeFilter()
34      {
35          ExceptionTypeFilter filter = new ExceptionTypeFilter();
36          assertNull(filter.getExpectedType());
37          MuleMessage m = new DefaultMuleMessage("test", muleContext);
38          assertTrue(!filter.accept(m));
39          m.setExceptionPayload(new DefaultExceptionPayload(new IllegalArgumentException("test")));
40          assertTrue(filter.accept(m));
41  
42          filter = new ExceptionTypeFilter(IOException.class);
43          assertTrue(!filter.accept(m));
44          m.setExceptionPayload(new DefaultExceptionPayload(new IOException("test")));
45          assertTrue(filter.accept(m));
46      }
47  
48  }