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;
8   
9   import org.mule.api.DefaultMuleException;
10  import org.mule.api.MuleEvent;
11  import org.mule.api.MuleException;
12  import org.mule.api.context.MuleContextException;
13  import org.mule.api.endpoint.OutboundEndpoint;
14  import org.mule.api.routing.RoutingException;
15  import org.mule.config.i18n.MessageFactory;
16  import org.mule.tck.junit4.AbstractMuleContextTestCase;
17  
18  import org.junit.Test;
19  
20  import static org.junit.Assert.assertEquals;
21  import static org.junit.Assert.assertNotNull;
22  import static org.junit.Assert.assertSame;
23  
24  public class ExceptionsTestCase extends AbstractMuleContextTestCase
25  {
26  
27      @Test
28      public void testExceptionChaining()
29      {
30          String rootMsg = "Root Test Exception Message";
31          String msg = "Test Exception Message";
32  
33          Exception e = new MuleContextException(MessageFactory.createStaticMessage(msg), new DefaultMuleException(
34              MessageFactory.createStaticMessage(rootMsg)));
35  
36          assertEquals(rootMsg, e.getCause().getMessage());
37          assertEquals(msg, e.getMessage());
38          assertEquals(e.getClass().getName() + ": " + msg, e.toString());
39      }
40  
41      public final void testRoutingExceptionNullMessageValidEndpoint() throws MuleException
42      {
43          OutboundEndpoint endpoint = muleContext.getEndpointFactory().getOutboundEndpoint("test://outbound");
44          assertNotNull(endpoint);
45  
46          RoutingException rex = new RoutingException((MuleEvent) null, endpoint);
47          assertSame(endpoint, rex.getRoute());
48      }
49  
50  }