View Javadoc

1   /*
2    * $Id: JmsExceptionReaderTestCase.java 22387 2011-07-12 03:53:36Z 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.transport.jms;
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.io.IOException;
19  import java.util.List;
20  import java.util.Map;
21  
22  import javax.jms.JMSException;
23  
24  import org.junit.Before;
25  import org.junit.Test;
26  
27  import static org.junit.Assert.assertEquals;
28  import static org.junit.Assert.assertNotNull;
29  import static org.junit.Assert.assertNull;
30  
31  public class JmsExceptionReaderTestCase extends AbstractMuleTestCase
32  {
33  
34      @Before
35      public void registerExceptionReader()
36      {
37          ExceptionHelper.registerExceptionReader(new JmsExceptionReader());
38      }
39  
40      @Test
41      public void testNestedExceptionRetrieval() throws Exception
42      {
43          Exception testException = getException();
44          Throwable t = ExceptionHelper.getRootException(testException);
45          assertNotNull(t);
46          assertEquals("blah", t.getMessage());
47          assertNull(t.getCause());
48  
49          t = ExceptionHelper.getRootMuleException(testException);
50          assertNotNull(t);
51          assertEquals("bar", t.getMessage());
52          assertNotNull(t.getCause());
53  
54          List l = ExceptionHelper.getExceptionsAsList(testException);
55          assertEquals(4, l.size());
56  
57          Map info = ExceptionHelper.getExceptionInfo(testException);
58          assertNotNull(info);
59          assertEquals(2, info.size());
60          assertNotNull(info.get("JavaDoc"));
61          assertEquals("1234", info.get("JMS Code"));
62      }
63  
64      private Exception getException()
65      {
66  
67          JMSException e = new JMSException("Jms error", "1234");
68          e.setLinkedException(new IOException("blah"));
69  
70          return new DefaultMuleException(MessageFactory.createStaticMessage("foo"), new DefaultMuleException(
71              MessageFactory.createStaticMessage("bar"), e));
72      }
73  
74  }