View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.module.jbpm;
8   
9   import org.mule.api.MuleMessage;
10  import org.mule.api.client.MuleClient;
11  import org.mule.api.transformer.TransformerException;
12  import org.mule.tck.junit4.FunctionalTestCase;
13  import org.mule.tck.exceptions.FunctionalTestException;
14  import org.mule.util.ExceptionUtils;
15  
16  import org.junit.Test;
17  
18  import static org.junit.Assert.assertNotNull;
19  import static org.junit.Assert.assertNull;
20  import static org.junit.Assert.assertTrue;
21  
22  public class MessagingExceptionComponentTestCase extends FunctionalTestCase
23  {
24      
25      @Override
26      protected String getConfigResources()
27      {
28          return "jbpm-component-functional-test.xml";
29      }
30  
31      @Test
32      public void testNoException() throws Exception
33      {
34          MuleClient client = muleContext.getClient();
35          client.send("vm://exception", "testNoException", null);                                  
36  
37          // Both messages should have been sent.
38          assertNotNull(client.request("vm://queueC", 1000));            
39          assertNotNull(client.request("vm://queueD", 1000));            
40      }
41  
42      @Test
43      public void testExceptionInService() throws Exception
44      {
45          MuleClient client = muleContext.getClient();
46          
47          MuleMessage response = client.send("vm://exception", "testExceptionInService", null);                      
48          assertNotNull("Should have thrown an exception", response.getExceptionPayload());
49          assertTrue(ExceptionUtils.getRootCause(response.getExceptionPayload().getException()) instanceof FunctionalTestException);
50          
51          // The first message should have been sent, but not the second one.
52          assertNotNull(client.request("vm://queueC", 1000));            
53          assertNull(client.request("vm://queueD", 1000));            
54      }
55  
56      @Test
57      public void testExceptionInTransformer() throws Exception
58      {
59          MuleClient client = muleContext.getClient();
60          
61          MuleMessage response = client.send("vm://exception", "testExceptionInTransformer", null);                      
62          assertNotNull("Should have thrown an exception", response.getExceptionPayload());
63          assertTrue(ExceptionUtils.getRootCause(response.getExceptionPayload().getException()) instanceof TransformerException);
64          
65          // The first message should have been sent, but not the second one.
66          assertNotNull(client.request("vm://queueC", 1000));            
67          assertNull(client.request("vm://queueD", 1000));            
68      }
69  
70  }