View Javadoc

1   /*
2    * $Id: ExceptionHelperTestCase.java 19556 2010-09-10 13:51:02Z aperepel $
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.test.config;
12  
13  import org.mule.api.DefaultMuleException;
14  import org.mule.config.ExceptionHelper;
15  import org.mule.config.i18n.MessageFactory;
16  import org.mule.tck.AbstractMuleTestCase;
17  
18  import java.util.List;
19  import java.util.Map;
20  
21  public class ExceptionHelperTestCase extends AbstractMuleTestCase
22  {
23      public void testNestedExceptionRetreval() throws Exception
24      {
25          Exception testException = getException();
26          Throwable t = ExceptionHelper.getRootException(testException);
27          assertNotNull(t);
28          assertEquals("blah", t.getMessage());
29          assertNull(t.getCause());
30  
31          t = ExceptionHelper.getRootMuleException(testException);
32          assertNotNull(t);
33          assertEquals("bar", t.getMessage());
34          assertNotNull(t.getCause());
35  
36          List<?> l = ExceptionHelper.getExceptionsAsList(testException);
37          assertEquals(3, l.size());
38  
39          Map<?, ?> info = ExceptionHelper.getExceptionInfo(testException);
40          assertNotNull(info);
41          assertEquals(1, info.size());
42          assertNotNull(info.get("JavaDoc"));
43      }
44      
45      public void testSummarizeWithDepthBeyondStackTraceLength()
46      {
47          Exception exception = getException();
48          int numberOfStackFrames = exception.getStackTrace().length;
49          int depth = numberOfStackFrames + 1;
50          
51          Throwable summary = ExceptionHelper.summarise(exception, depth);
52          assertNotNull(summary);
53      }
54  
55      private Exception getException()
56      {
57          return new DefaultMuleException(MessageFactory.createStaticMessage("foo"), new DefaultMuleException(
58              MessageFactory.createStaticMessage("bar"), new Exception("blah")));
59      }
60  }