5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package test.sql; 24 25 import java.io.FileInputStream; 26 import java.io.FileOutputStream; 27 import java.io.ObjectInputStream; 28 import java.io.ObjectOutputStream; 29 import java.sql.SQLException; 30 import java.sql.SQLTransactionRollbackException; 31 import java.sql.SQLTransientException; 32 import static org.testng.Assert.*; 33 import org.testng.annotations.AfterClass; 34 import org.testng.annotations.AfterMethod; 35 import org.testng.annotations.BeforeClass; 36 import org.testng.annotations.BeforeMethod; 37 import org.testng.annotations.Test; 38 39 public class SQLTransactionRollbackExceptionTests { 40 41 private final String reason = "reason"; 42 private final String state = "SQLState"; 43 private final String cause = "java.lang.Throwable: cause"; 44 private final Throwable t = new Throwable("cause"); 45 private final Throwable t1 = new Throwable("cause 1"); 46 private final Throwable t2 = new Throwable("cause 2"); 47 private final int errorCode = 21; 48 private final String[] msgs = {"Exception 1", "cause 1", "Exception 2", 49 "Exception 3", "cause 2"}; 50 51 public SQLTransactionRollbackExceptionTests() { 52 } 53 54 @BeforeClass 55 public static void setUpClass() throws Exception { 56 } 57 58 @AfterClass 59 public static void tearDownClass() throws Exception { 60 } 61 62 @BeforeMethod 63 public void setUpMethod() throws Exception { 64 } 65 66 @AfterMethod 67 public void tearDownMethod() throws Exception { 68 } 69 70 /** 71 * Create SQLTransactionRollbackException and setting all objects to null 72 */ 73 @Test 74 public void test() { 75 SQLTransactionRollbackException e = 76 new SQLTransactionRollbackException(null, 77 null, errorCode, null); 78 assertTrue(e.getMessage() == null && e.getSQLState() == null 79 && e.getCause() == null && e.getErrorCode() == errorCode); 80 } 81 82 /** 83 * Create SQLTransactionRollbackException with no-arg constructor 84 */ 85 @Test 86 public void test1() { 87 SQLTransactionRollbackException ex = new SQLTransactionRollbackException(); 88 assertTrue(ex.getMessage() == null 185 /** 186 * Create SQLTransactionRollbackException with Throwable 187 */ 188 @Test 189 public void test9() { 190 SQLTransactionRollbackException ex = 191 new SQLTransactionRollbackException(t); 192 assertTrue(ex.getMessage().equals(cause) 193 && ex.getSQLState() == null 194 && cause.equals(ex.getCause().toString()) 195 && ex.getErrorCode() == 0); 196 } 197 198 /** 199 * Serialize a SQLTransactionRollbackException and make sure you can read it back properly 200 */ 201 @Test 202 public void test10() throws Exception { 203 SQLTransactionRollbackException e = 204 new SQLTransactionRollbackException(reason, state, errorCode, t); 205 ObjectOutputStream out 206 = new ObjectOutputStream( 207 new FileOutputStream("SQLTransactionRollbackException.ser")); 208 out.writeObject(e); 209 ObjectInputStream is = new ObjectInputStream( 210 new FileInputStream("SQLTransactionRollbackException.ser")); 211 SQLTransactionRollbackException ex1 = (SQLTransactionRollbackException) is.readObject(); 212 assertTrue(reason.equals(ex1.getMessage()) 213 && ex1.getSQLState().equals(state) 214 && cause.equals(ex1.getCause().toString()) 215 && ex1.getErrorCode() == errorCode); 216 } 217 218 /** 219 * Validate that the ordering of the returned Exceptions is correct 220 * using for-each loop 221 */ 222 @Test 223 public void test11() { 224 SQLTransactionRollbackException ex = 225 new SQLTransactionRollbackException("Exception 1", t1); 226 SQLTransactionRollbackException ex1 = 227 new SQLTransactionRollbackException("Exception 2"); 228 SQLTransactionRollbackException ex2 = 229 new SQLTransactionRollbackException("Exception 3", t2); 230 ex.setNextException(ex1); 231 ex.setNextException(ex2); | 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package test.sql; 24 25 import java.sql.SQLException; 26 import java.sql.SQLTransactionRollbackException; 27 import java.sql.SQLTransientException; 28 import static org.testng.Assert.*; 29 import org.testng.annotations.Test; 30 import util.BaseTest; 31 32 public class SQLTransactionRollbackExceptionTests extends BaseTest { 33 34 /** 35 * Create SQLTransactionRollbackException and setting all objects to null 36 */ 37 @Test 38 public void test() { 39 SQLTransactionRollbackException e = 40 new SQLTransactionRollbackException(null, 41 null, errorCode, null); 42 assertTrue(e.getMessage() == null && e.getSQLState() == null 43 && e.getCause() == null && e.getErrorCode() == errorCode); 44 } 45 46 /** 47 * Create SQLTransactionRollbackException with no-arg constructor 48 */ 49 @Test 50 public void test1() { 51 SQLTransactionRollbackException ex = new SQLTransactionRollbackException(); 52 assertTrue(ex.getMessage() == null 149 /** 150 * Create SQLTransactionRollbackException with Throwable 151 */ 152 @Test 153 public void test9() { 154 SQLTransactionRollbackException ex = 155 new SQLTransactionRollbackException(t); 156 assertTrue(ex.getMessage().equals(cause) 157 && ex.getSQLState() == null 158 && cause.equals(ex.getCause().toString()) 159 && ex.getErrorCode() == 0); 160 } 161 162 /** 163 * Serialize a SQLTransactionRollbackException and make sure you can read it back properly 164 */ 165 @Test 166 public void test10() throws Exception { 167 SQLTransactionRollbackException e = 168 new SQLTransactionRollbackException(reason, state, errorCode, t); 169 SQLTransactionRollbackException ex1 = 170 createSerializedException(e); 171 assertTrue(reason.equals(ex1.getMessage()) 172 && ex1.getSQLState().equals(state) 173 && cause.equals(ex1.getCause().toString()) 174 && ex1.getErrorCode() == errorCode); 175 } 176 177 /** 178 * Validate that the ordering of the returned Exceptions is correct 179 * using for-each loop 180 */ 181 @Test 182 public void test11() { 183 SQLTransactionRollbackException ex = 184 new SQLTransactionRollbackException("Exception 1", t1); 185 SQLTransactionRollbackException ex1 = 186 new SQLTransactionRollbackException("Exception 2"); 187 SQLTransactionRollbackException ex2 = 188 new SQLTransactionRollbackException("Exception 3", t2); 189 ex.setNextException(ex1); 190 ex.setNextException(ex2); |