View Javadoc

1   /*
2    * $Id: ExceptionsTestCase.java 22377 2011-07-11 12:41:42Z dirk.olmes $
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.junit4.AbstractMuleContextTestCase;
21  
22  import org.junit.Test;
23  
24  import static org.junit.Assert.assertEquals;
25  import static org.junit.Assert.assertNotNull;
26  import static org.junit.Assert.assertSame;
27  
28  public class ExceptionsTestCase extends AbstractMuleContextTestCase
29  {
30  
31      @Test
32      public void testExceptionChaining()
33      {
34          String rootMsg = "Root Test Exception Message";
35          String msg = "Test Exception Message";
36  
37          Exception e = new MuleContextException(MessageFactory.createStaticMessage(msg), new DefaultMuleException(
38              MessageFactory.createStaticMessage(rootMsg)));
39  
40          assertEquals(rootMsg, e.getCause().getMessage());
41          assertEquals(msg, e.getMessage());
42          assertEquals(e.getClass().getName() + ": " + msg, e.toString());
43      }
44  
45      public final void testRoutingExceptionNullMessageValidEndpoint() throws MuleException
46      {
47          OutboundEndpoint endpoint = muleContext.getEndpointFactory().getOutboundEndpoint("test://outbound");
48          assertNotNull(endpoint);
49  
50          RoutingException rex = new RoutingException((MuleEvent) null, endpoint);
51          assertSame(endpoint, rex.getRoute());
52      }
53  
54  }