01: /*
02: Derby - Class org.apache.derbyTesting.functionTests.tests.derbynet.SqlExceptionTest
03:
04: Licensed to the Apache Software Foundation (ASF) under one or more
05: contributor license agreements. See the NOTICE file distributed with
06: this work for additional information regarding copyright ownership.
07: The ASF licenses this file to You under the Apache License, Version 2.0
08: (the "License"); you may not use this file except in compliance with
09: the License. You may obtain a copy of the License at
10:
11: http://www.apache.org/licenses/LICENSE-2.0
12:
13: Unless required by applicable law or agreed to in writing, software
14: distributed under the License is distributed on an "AS IS" BASIS,
15: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16: See the License for the specific language governing permissions and
17: limitations under the License.
18:
19: */
20: package org.apache.derbyTesting.functionTests.tests.derbynet;
21:
22: import org.apache.derbyTesting.junit.BaseTestCase;
23: import org.apache.derby.client.am.SqlException;
24: import org.apache.derby.client.am.ClientMessageId;
25: import org.apache.derby.shared.common.reference.SQLState;
26: import java.sql.SQLException;
27: import java.io.IOException;
28:
29: /**
30: * This is used for testing the SqlException class. This test can be added
31: * to. My itch right now is to verify that exception chaining is working
32: * correctly.
33: */
34:
35: public class SqlExceptionTest extends BaseTestCase {
36: public SqlExceptionTest(String name) {
37: super (name);
38: }
39:
40: /**
41: * Makes sure exception chaining works correctly (DERBY-1117)
42: */
43: public void testChainedException() {
44: IOException ioe = new IOException("Test exception");
45: SqlException sqle = new SqlException(null, new ClientMessageId(
46: SQLState.NOGETCONN_ON_CLOSED_POOLED_CONNECTION), ioe);
47: SQLException javae = sqle.getSQLException();
48:
49: // The underlying SqlException is the first cause; the IOException
50: // should be the second cause
51: assertEquals(sqle, javae.getCause());
52: assertEquals(ioe, javae.getCause().getCause());
53: assertNull(sqle.getNextException());
54: }
55:
56: /**
57: * Make sure a SQLException is chained as a nextSQLException()
58: * rather than as a chained exception
59: */
60: public void testNextException() {
61: SQLException nexte = new SQLException("test");
62: SqlException sqle = new SqlException(null, new ClientMessageId(
63: SQLState.NOGETCONN_ON_CLOSED_POOLED_CONNECTION), nexte);
64: SQLException javae = sqle.getSQLException();
65:
66: assertEquals(sqle, javae.getCause());
67: assertNull(javae.getCause().getCause());
68: assertEquals(nexte, javae.getNextException());
69:
70: // Make sure exception chaining works with Derby's SqlException
71: // just as well as java.sql.SQLException
72: SqlException internalException = new SqlException(null,
73: new ClientMessageId("08000"));
74:
75: javae = new SqlException(null, new ClientMessageId(
76: SQLState.NOGETCONN_ON_CLOSED_POOLED_CONNECTION),
77: internalException).getSQLException();
78:
79: assertNotNull(javae.getNextException());
80: assertEquals(javae.getNextException().getSQLState(), "08000");
81: }
82: }
|