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


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





























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


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





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