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