1   /*
2    * $Id: ExceptionHelperTestCase.java 7976 2007-08-21 14:26:13Z dirk.olmes $
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.test.config;
12  
13  import org.mule.MuleException;
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  
24      public void testNestedExceptionRetreval() throws Exception
25      {
26          Exception testException = getException();
27          Throwable t = ExceptionHelper.getRootException(testException);
28          assertNotNull(t);
29          assertEquals("blah", t.getMessage());
30          assertNull(t.getCause());
31  
32          t = ExceptionHelper.getRootMuleException(testException);
33          assertNotNull(t);
34          assertEquals("bar", t.getMessage());
35          assertNotNull(t.getCause());
36  
37          List l = ExceptionHelper.getExceptionsAsList(testException);
38          assertEquals(3, l.size());
39  
40          Map info = ExceptionHelper.getExceptionInfo(testException);
41          assertNotNull(info);
42          assertEquals(1, info.size());
43          assertNotNull(info.get("JavaDoc"));
44  
45      }
46  
47      private Exception getException()
48      {
49  
50          return new MuleException(MessageFactory.createStaticMessage("foo"), new MuleException(
51              MessageFactory.createStaticMessage("bar"), new Exception("blah")));
52      }
53  }