test/java/sql/test/sql/SQLFeatureNotSupportedExceptionTests.java

Print this page




   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.SQLFeatureNotSupportedException;
  30 import java.sql.SQLException;

  31 import java.sql.SQLNonTransientException;
  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 SQLFeatureNotSupportedExceptionTests {
  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 SQLFeatureNotSupportedExceptionTests() {
  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 SQLFeatureNotSupportedException and setting all objects to null
  72      */
  73     @Test
  74     public void test() {
  75         SQLFeatureNotSupportedException e =
  76                 new SQLFeatureNotSupportedException(null, null, errorCode, null);
  77         assertTrue(e.getMessage() == null && e.getSQLState() == null
  78                 && e.getCause() == null && e.getErrorCode() == errorCode);
  79     }
  80 
  81     /**
  82      * Create SQLFeatureNotSupportedException with no-arg constructor
  83      */
  84     @Test
  85     public void test1() {
  86         SQLFeatureNotSupportedException ex = new SQLFeatureNotSupportedException();
  87         assertTrue(ex.getMessage() == null
  88                 && ex.getSQLState() == null


 184     /**
 185      * Create SQLFeatureNotSupportedException with Throwable
 186      */
 187     @Test
 188     public void test9() {
 189         SQLFeatureNotSupportedException ex =
 190                 new SQLFeatureNotSupportedException(t);
 191         assertTrue(ex.getMessage().equals(cause)
 192                 && ex.getSQLState() == null
 193                 && cause.equals(ex.getCause().toString())
 194                 && ex.getErrorCode() == 0);
 195     }
 196 
 197     /**
 198      * Serialize a SQLFeatureNotSupportedException and make sure you can read it back properly
 199      */
 200     @Test
 201     public void test10() throws Exception {
 202         SQLFeatureNotSupportedException e =
 203                 new SQLFeatureNotSupportedException(reason, state, errorCode, t);
 204         ObjectOutputStream out
 205                 = new ObjectOutputStream(
 206                         new FileOutputStream("SQLFeatureNotSupportedException.ser"));
 207         out.writeObject(e);
 208         ObjectInputStream is = new ObjectInputStream(
 209                 new FileInputStream("SQLFeatureNotSupportedException.ser"));
 210         SQLFeatureNotSupportedException ex1 = (SQLFeatureNotSupportedException) is.readObject();
 211         assertTrue(reason.equals(ex1.getMessage())
 212                 && ex1.getSQLState().equals(state)
 213                 && cause.equals(ex1.getCause().toString())
 214                 && ex1.getErrorCode() == errorCode);
 215     }
 216 
 217     /**
 218      * Validate that the ordering of the returned Exceptions is correct
 219      * using for-each loop
 220      */
 221     @Test
 222     public void test11() {
 223         SQLFeatureNotSupportedException ex =
 224                 new SQLFeatureNotSupportedException("Exception 1", t1);
 225         SQLFeatureNotSupportedException ex1 =
 226                 new SQLFeatureNotSupportedException("Exception 2");
 227         SQLFeatureNotSupportedException ex2 =
 228                 new SQLFeatureNotSupportedException("Exception 3", t2);
 229         ex.setNextException(ex1);
 230         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.SQLFeatureNotSupportedException;
  27 import java.sql.SQLNonTransientException;
  28 import static org.testng.Assert.*;




  29 import org.testng.annotations.Test;
  30 import util.BaseTest;
  31 
  32 public class SQLFeatureNotSupportedExceptionTests extends BaseTest {





























  33 
  34     /**
  35      * Create SQLFeatureNotSupportedException and setting all objects to null
  36      */
  37     @Test
  38     public void test() {
  39         SQLFeatureNotSupportedException e =
  40                 new SQLFeatureNotSupportedException(null, null, errorCode, null);
  41         assertTrue(e.getMessage() == null && e.getSQLState() == null
  42                 && e.getCause() == null && e.getErrorCode() == errorCode);
  43     }
  44 
  45     /**
  46      * Create SQLFeatureNotSupportedException with no-arg constructor
  47      */
  48     @Test
  49     public void test1() {
  50         SQLFeatureNotSupportedException ex = new SQLFeatureNotSupportedException();
  51         assertTrue(ex.getMessage() == null
  52                 && ex.getSQLState() == null


 148     /**
 149      * Create SQLFeatureNotSupportedException with Throwable
 150      */
 151     @Test
 152     public void test9() {
 153         SQLFeatureNotSupportedException ex =
 154                 new SQLFeatureNotSupportedException(t);
 155         assertTrue(ex.getMessage().equals(cause)
 156                 && ex.getSQLState() == null
 157                 && cause.equals(ex.getCause().toString())
 158                 && ex.getErrorCode() == 0);
 159     }
 160 
 161     /**
 162      * Serialize a SQLFeatureNotSupportedException and make sure you can read it back properly
 163      */
 164     @Test
 165     public void test10() throws Exception {
 166         SQLFeatureNotSupportedException e =
 167                 new SQLFeatureNotSupportedException(reason, state, errorCode, t);
 168         SQLFeatureNotSupportedException ex1 =
 169                 createSerializedException(e);





 170         assertTrue(reason.equals(ex1.getMessage())
 171                 && ex1.getSQLState().equals(state)
 172                 && cause.equals(ex1.getCause().toString())
 173                 && ex1.getErrorCode() == errorCode);
 174     }
 175 
 176     /**
 177      * Validate that the ordering of the returned Exceptions is correct
 178      * using for-each loop
 179      */
 180     @Test
 181     public void test11() {
 182         SQLFeatureNotSupportedException ex =
 183                 new SQLFeatureNotSupportedException("Exception 1", t1);
 184         SQLFeatureNotSupportedException ex1 =
 185                 new SQLFeatureNotSupportedException("Exception 2");
 186         SQLFeatureNotSupportedException ex2 =
 187                 new SQLFeatureNotSupportedException("Exception 3", t2);
 188         ex.setNextException(ex1);
 189         ex.setNextException(ex2);