1   /*
2    * $Id: SqlExceptionReaderTestCase.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.providers.jdbc;
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.sql.SQLException;
19  import java.util.List;
20  import java.util.Map;
21  
22  public class SqlExceptionReaderTestCase extends AbstractMuleTestCase
23  {
24  
25      /**
26       * Print the name of this test to standard output
27       */
28      protected void doSetUp() throws Exception
29      {
30          ExceptionHelper.registerExceptionReader(new SQLExceptionReader());
31      }
32  
33      public void testNestedExceptionRetreval() throws Exception
34      {
35          Exception testException = getException();
36          Throwable t = ExceptionHelper.getRootException(testException);
37          assertNotNull(t);
38          assertEquals("blah", t.getMessage());
39          assertNull(t.getCause());
40  
41          t = ExceptionHelper.getRootMuleException(testException);
42          assertNotNull(t);
43          assertEquals("bar", t.getMessage());
44          assertNotNull(t.getCause());
45  
46          List l = ExceptionHelper.getExceptionsAsList(testException);
47          assertEquals(4, l.size());
48  
49          Map info = ExceptionHelper.getExceptionInfo(testException);
50          assertNotNull(info);
51          assertEquals(3, info.size());
52          assertNotNull(info.get("JavaDoc"));
53          assertEquals("1234", info.get("SQL Code"));
54          assertEquals("bad SQL state", info.get("SQL State"));
55      }
56  
57      private Exception getException()
58      {
59  
60          SQLException e = new SQLException("SQL error", "bad SQL state", 1234);
61          e.setNextException(new SQLException("blah"));
62  
63          return new MuleException(MessageFactory.createStaticMessage("foo"), new MuleException(
64              MessageFactory.createStaticMessage("bar"), e));
65      }
66  }