View Javadoc

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