1
2
3
4
5
6
7
8
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.junit4.AbstractMuleTestCase;
17
18 import java.util.List;
19 import java.util.Map;
20
21 import org.junit.Test;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertNull;
26
27 public class ExceptionHelperTestCase extends AbstractMuleTestCase
28 {
29
30 @Test
31 public void testNestedExceptionRetreval() throws Exception
32 {
33 Exception testException = getException();
34 Throwable t = ExceptionHelper.getRootException(testException);
35 assertNotNull(t);
36 assertEquals("blah", t.getMessage());
37 assertNull(t.getCause());
38
39 t = ExceptionHelper.getRootMuleException(testException);
40 assertNotNull(t);
41 assertEquals("bar", t.getMessage());
42 assertNotNull(t.getCause());
43
44 List<?> l = ExceptionHelper.getExceptionsAsList(testException);
45 assertEquals(3, l.size());
46
47 Map<?, ?> info = ExceptionHelper.getExceptionInfo(testException);
48 assertNotNull(info);
49 assertEquals(1, info.size());
50 assertNotNull(info.get("JavaDoc"));
51 }
52
53 @Test
54 public void testSummarizeWithDepthBeyondStackTraceLength()
55 {
56 Exception exception = getException();
57 int numberOfStackFrames = exception.getStackTrace().length;
58 int depth = numberOfStackFrames + 1;
59
60 Throwable summary = ExceptionHelper.summarise(exception, depth);
61 assertNotNull(summary);
62 }
63
64 private Exception getException()
65 {
66 return new DefaultMuleException(MessageFactory.createStaticMessage("foo"), new DefaultMuleException(
67 MessageFactory.createStaticMessage("bar"), new Exception("blah")));
68 }
69 }