test/java/sql/test/sql/SQLClientInfoExceptionTests.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.ClientInfoStatus;
  30 import java.sql.SQLClientInfoException;
  31 import java.sql.SQLException;
  32 import java.util.HashMap;
  33 import static org.testng.Assert.*;
  34 import org.testng.annotations.AfterClass;
  35 import org.testng.annotations.AfterMethod;
  36 import org.testng.annotations.BeforeClass;
  37 import org.testng.annotations.BeforeMethod;
  38 import org.testng.annotations.Test;

  39 
  40 public class SQLClientInfoExceptionTests {
  41 
  42     private final String reason = "reason";
  43     private final String state = "SQLState";
  44     private final String cause = "java.lang.Throwable: cause";
  45     private final HashMap<String, ClientInfoStatus> map = new HashMap<>();
  46     private final Throwable t = new Throwable("cause");
  47     private final Throwable t1 = new Throwable("cause 1");
  48     private final Throwable t2 = new Throwable("cause 2");
  49     private final int errorCode = 21;
  50     private final String[] msgs = {"Exception 1", "cause 1", "Exception 2",
  51         "Exception 3", "cause 2"};
  52 
  53     public SQLClientInfoExceptionTests() {
  54         map.put("1", ClientInfoStatus.REASON_UNKNOWN_PROPERTY);
  55         map.put("21", ClientInfoStatus.REASON_UNKNOWN_PROPERTY);
  56     }
  57 
  58     @BeforeClass
  59     public static void setUpClass() throws Exception {
  60     }
  61 
  62     @AfterClass
  63     public static void tearDownClass() throws Exception {
  64     }
  65 
  66     @BeforeMethod
  67     public void setUpMethod() throws Exception {
  68     }
  69 
  70     @AfterMethod
  71     public void tearDownMethod() throws Exception {
  72     }
  73 
  74     /**
  75      * Create SQLClientInfoException and setting all objects to null
  76      */
  77     @Test
  78     public void test() {
  79         SQLClientInfoException e = new SQLClientInfoException(null);
  80         assertTrue(e.getMessage() == null && e.getSQLState() == null
  81                 && e.getCause() == null && e.getErrorCode() == 0
  82                 && e.getFailedProperties() == null);
  83     }
  84 
  85     /**
  86      * Create SQLClientInfoException with no-arg constructor
  87      */
  88     @Test
  89     public void test1() {
  90         SQLClientInfoException ex = new SQLClientInfoException();
  91         assertTrue(ex.getMessage() == null
  92                 && ex.getSQLState() == null
  93                 && ex.getCause() == null


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




   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.ClientInfoStatus;
  26 import java.sql.SQLClientInfoException;
  27 import java.sql.SQLException;
  28 import java.util.HashMap;
  29 import static org.testng.Assert.*;




  30 import org.testng.annotations.Test;
  31 import util.BaseTest;
  32 
  33 public class SQLClientInfoExceptionTests extends BaseTest {
  34 



  35     private final HashMap<String, ClientInfoStatus> map = new HashMap<>();






  36 
  37     public SQLClientInfoExceptionTests() {
  38         map.put("1", ClientInfoStatus.REASON_UNKNOWN_PROPERTY);
  39         map.put("21", ClientInfoStatus.REASON_UNKNOWN_PROPERTY);
  40     }
  41 
















  42     /**
  43      * Create SQLClientInfoException and setting all objects to null
  44      */
  45     @Test
  46     public void test() {
  47         SQLClientInfoException e = new SQLClientInfoException(null);
  48         assertTrue(e.getMessage() == null && e.getSQLState() == null
  49                 && e.getCause() == null && e.getErrorCode() == 0
  50                 && e.getFailedProperties() == null);
  51     }
  52 
  53     /**
  54      * Create SQLClientInfoException with no-arg constructor
  55      */
  56     @Test
  57     public void test1() {
  58         SQLClientInfoException ex = new SQLClientInfoException();
  59         assertTrue(ex.getMessage() == null
  60                 && ex.getSQLState() == null
  61                 && ex.getCause() == null


 152      */
 153     @Test
 154     public void test8() {
 155         SQLClientInfoException ex = new SQLClientInfoException(reason, state,
 156                 errorCode, map, t);
 157         assertTrue(ex.getMessage().equals(reason)
 158                 && ex.getSQLState().equals(state)
 159                 && cause.equals(ex.getCause().toString())
 160                 && ex.getErrorCode() == errorCode
 161                 && ex.getFailedProperties().equals(map));
 162     }
 163 
 164     /**
 165      * Serialize a SQLClientInfoException and make sure you can read it back
 166      * properly
 167      */
 168     @Test
 169     public void test10() throws Exception {
 170         SQLClientInfoException e = new SQLClientInfoException(reason, state,
 171                 errorCode, map, t);
 172         SQLClientInfoException ex1 =
 173                 createSerializedException(e);





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