1   /*
2    * $Id: ChainingRouterNullsHandlingTestCase.java 10789 2008-02-12 20:04:43Z dfeist $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.routing.outbound;
12  
13  import org.mule.DefaultMuleMessage;
14  import org.mule.api.MuleMessage;
15  import org.mule.api.service.ServiceException;
16  import org.mule.module.client.MuleClient;
17  import org.mule.tck.FunctionalTestCase;
18  import org.mule.transport.NullPayload;
19  
20  
21  /**
22   */
23  public class ChainingRouterNullsHandlingTestCase extends FunctionalTestCase
24  {
25      protected String getConfigResources() {
26          return "org/mule/test/integration/routing/outbound/chaining-router-null-handling.xml";
27      }
28  
29      public void testNoComponentFails() throws Exception {
30  
31          MuleClient muleClient = new MuleClient();
32          MuleMessage result = muleClient.send("vm://incomingPass", new DefaultMuleMessage("thePayload"));
33          assertNull("Shouldn't have any exceptions", result.getExceptionPayload());
34          assertEquals("thePayload Received component1 Received component2Pass", result.getPayloadAsString());
35      }
36  
37      public void testLastComponentFails() throws Exception {
38  
39          MuleClient muleClient = new MuleClient();
40          MuleMessage result = muleClient.send("vm://incomingLastFail", new DefaultMuleMessage("thePayload"));
41          assertNotNull("Should be a NullPayload instead.", result);
42          assertEquals("Should be a NullPayload instead.", NullPayload.getInstance(), result.getPayload());
43          assertNotNull("Should've contained an exception payload", result.getExceptionPayload());
44          Throwable exception = result.getExceptionPayload().getException();
45          assertNotNull("Exception required", exception);
46          assertTrue("Wrong exception", exception instanceof ServiceException);
47          String compName = ((ServiceException) exception).getService().getName();
48          assertEquals("Exception raised in wrong service", "component2Fail", compName);
49      }
50  
51      public void testFirstComponentFails() throws Exception {
52  
53          MuleClient muleClient = new MuleClient();
54          MuleMessage result = muleClient.send("vm://incomingFirstFail", new DefaultMuleMessage("thePayload"));
55          assertNotNull("Should be a NullPayload instead.", result);
56          assertEquals("Should be a NullPayload instead.", NullPayload.getInstance(), result.getPayload());
57          assertNotNull("Should've contained an exception payload", result.getExceptionPayload());
58          Throwable exception = result.getExceptionPayload().getException();
59          assertNotNull("Exception required", exception);
60          assertTrue("Wrong exception", exception instanceof ServiceException);
61          String compName = ((ServiceException) exception).getService().getName();
62          assertEquals("Exception raised in wrong service", "component1Fail", compName);
63      }
64  }