View Javadoc

1   /*
2    * $Id: ExceptionsTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
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;
12  
13  import org.mule.api.DefaultMuleException;
14  import org.mule.api.MuleEvent;
15  import org.mule.api.MuleException;
16  import org.mule.api.context.MuleContextException;
17  import org.mule.api.endpoint.OutboundEndpoint;
18  import org.mule.api.routing.RoutingException;
19  import org.mule.config.i18n.MessageFactory;
20  import org.mule.tck.AbstractMuleTestCase;
21  
22  public class ExceptionsTestCase extends AbstractMuleTestCase
23  {
24  
25      public void testExceptionChaining()
26      {
27          String rootMsg = "Root Test Exception Message";
28          String msg = "Test Exception Message";
29  
30          Exception e = new MuleContextException(MessageFactory.createStaticMessage(msg), new DefaultMuleException(
31              MessageFactory.createStaticMessage(rootMsg)));
32  
33          assertEquals(rootMsg, e.getCause().getMessage());
34          assertEquals(msg, e.getMessage());
35          assertEquals(e.getClass().getName() + ": " + msg, e.toString());
36      }
37  
38      public final void testRoutingExceptionNullMessageValidEndpoint() throws MuleException
39      {
40          OutboundEndpoint endpoint = muleContext.getRegistry().lookupEndpointFactory().getOutboundEndpoint("test://outbound");
41          assertNotNull(endpoint);
42  
43          RoutingException rex = new RoutingException((MuleEvent) null, endpoint);
44          assertSame(endpoint, rex.getRoute());
45      }
46  
47  }