View Javadoc

1   /*
2    * $Id: FunctionalTestComponentTestCase.java 22266 2011-06-27 09:34:13Z 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.test.components;
12  
13  import org.mule.tck.exceptions.FunctionalTestException;
14  import org.mule.tck.functional.FunctionalTestComponent;
15  import org.mule.tck.junit4.AbstractMuleTestCase;
16  
17  import java.io.IOException;
18  
19  import org.junit.Before;
20  import org.junit.Test;
21  
22  import static org.junit.Assert.assertEquals;
23  import static org.junit.Assert.assertTrue;
24  
25  public class FunctionalTestComponentTestCase extends AbstractMuleTestCase
26  {
27      FunctionalTestComponent ftc;
28      
29      @Before
30      public void initFunctionaTestComponent()
31      {
32          ftc = new FunctionalTestComponent();
33          ftc.setThrowException(true);
34      }
35      
36      @Test
37      public void defaultExceptionWithDefaultText() throws Exception
38      {
39          checkExceptionThrown(FunctionalTestException.class, FunctionalTestException.EXCEPTION_MESSAGE);
40      }
41      
42      @Test
43      public void defaultExceptionWithCustomText() throws Exception
44      {
45          String exceptionText = "BOOM";
46          ftc.setExceptionText(exceptionText);
47          
48          checkExceptionThrown(FunctionalTestException.class, exceptionText);
49      }
50      
51      @Test
52      public void customExceptionWithoutText() throws Exception
53      {
54          ftc.setExceptionToThrow(IOException.class);
55          checkExceptionThrown(IOException.class, null);
56      }
57  
58      @Test
59      public void customExceptionWithCustomText() throws Exception
60      {
61          String exceptionText = "BOOM";
62          ftc.setExceptionToThrow(IOException.class);
63          ftc.setExceptionText(exceptionText);
64          checkExceptionThrown(IOException.class, exceptionText);
65      }
66  
67      private void checkExceptionThrown(Class<? extends Exception> exceptionClass, String expectedMessage)
68      {
69          try
70          {
71              ftc.onCall(null);
72          }
73          catch (Exception e)
74          {
75              assertTrue(e.getClass().isAssignableFrom(exceptionClass));
76              assertEquals(expectedMessage, e.getMessage());
77          }
78      }
79  }