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.test.integration.exceptions;
8   
9   import static org.junit.Assert.assertEquals;
10  import static org.junit.Assert.assertNotNull;
11  import static org.junit.Assert.assertTrue;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.module.client.MuleClient;
15  import org.mule.tck.junit4.FunctionalTestCase;
16  import org.mule.transport.NullPayload;
17  
18  import org.junit.Test;
19  
20  public class ExceptionStrategyReturnMessageTestCase extends FunctionalTestCase
21  {
22  
23      @Override
24      protected String getConfigResources()
25      {
26          return "org/mule/test/integration/exceptions/exception-strategy-return-message.xml";
27      }
28  
29      @Test
30      public void testReturnPayloadDefaultStrategy() throws Exception
31      {
32          MuleClient client = new MuleClient(muleContext);
33          MuleMessage msg = client.send("vm://in-default-strategy", "Test Message", null);
34  
35          assertNotNull(msg);
36          assertNotNull(msg.getExceptionPayload());
37          assertEquals("Functional Test Service Exception", msg.getExceptionPayload().getMessage());
38  
39          assertNotNull(msg.getPayload());
40          assertTrue(msg.getPayload() instanceof NullPayload);
41      }
42  
43      @Test
44      public void testReturnPayloadCustomStrategy() throws Exception
45      {
46          MuleClient client = new MuleClient(muleContext);
47          MuleMessage msg = client.send("vm://in-custom-strategy", "Test Message", null);
48  
49          assertNotNull(msg);
50          assertNotNull(msg.getExceptionPayload());
51          assertEquals("Functional Test Service Exception", msg.getExceptionPayload().getMessage());
52  
53          assertNotNull(msg.getPayload());
54          assertEquals("Ka-boom!", msg.getPayload());
55      }
56  }