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 util;
24
25 import java.io.ByteArrayInputStream;
26 import java.io.ByteArrayOutputStream;
27 import java.io.IOException;
28 import java.io.ObjectInputStream;
29 import java.io.ObjectOutputStream;
30 import java.sql.SQLException;
31 import org.testng.annotations.AfterClass;
32 import org.testng.annotations.AfterMethod;
33 import org.testng.annotations.BeforeClass;
34 import org.testng.annotations.BeforeMethod;
35
36 public class BaseTest {
37
38 protected final String reason = "reason";
39 protected final String state = "SQLState";
40 protected final String cause = "java.lang.Throwable: cause";
41 protected final Throwable t = new Throwable("cause");
42 protected final Throwable t1 = new Throwable("cause 1");
43 protected final Throwable t2 = new Throwable("cause 2");
44 protected final int errorCode = 21;
45 protected final String[] msgs = {"Exception 1", "cause 1", "Exception 2",
46 "Exception 3", "cause 2"};
47
48 @BeforeClass
49 public static void setUpClass() throws Exception {
71 return (T) serializeDeserializeObject(ex);
72 }
73
74 /*
75 * Utility method to serialize and deserialize an object
76 */
77 @SuppressWarnings("unchecked")
78 protected <T> T serializeDeserializeObject(T o)
79 throws IOException, ClassNotFoundException {
80 T o1;
81 ByteArrayOutputStream baos = new ByteArrayOutputStream();
82 try (ObjectOutputStream oos = new ObjectOutputStream(baos)) {
83 oos.writeObject(o);
84 }
85 try (ObjectInputStream ois
86 = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) {
87 o1 = (T) ois.readObject();
88 }
89 return o1;
90 }
91 }
|
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 util;
24
25 import java.io.ByteArrayInputStream;
26 import java.io.ByteArrayOutputStream;
27 import java.io.IOException;
28 import java.io.ObjectInputStream;
29 import java.io.ObjectOutputStream;
30 import java.security.Policy;
31 import java.sql.SQLException;
32 import org.testng.annotations.AfterClass;
33 import org.testng.annotations.AfterMethod;
34 import org.testng.annotations.BeforeClass;
35 import org.testng.annotations.BeforeMethod;
36
37 public class BaseTest {
38
39 protected final String reason = "reason";
40 protected final String state = "SQLState";
41 protected final String cause = "java.lang.Throwable: cause";
42 protected final Throwable t = new Throwable("cause");
43 protected final Throwable t1 = new Throwable("cause 1");
44 protected final Throwable t2 = new Throwable("cause 2");
45 protected final int errorCode = 21;
46 protected final String[] msgs = {"Exception 1", "cause 1", "Exception 2",
47 "Exception 3", "cause 2"};
48
49 @BeforeClass
50 public static void setUpClass() throws Exception {
72 return (T) serializeDeserializeObject(ex);
73 }
74
75 /*
76 * Utility method to serialize and deserialize an object
77 */
78 @SuppressWarnings("unchecked")
79 protected <T> T serializeDeserializeObject(T o)
80 throws IOException, ClassNotFoundException {
81 T o1;
82 ByteArrayOutputStream baos = new ByteArrayOutputStream();
83 try (ObjectOutputStream oos = new ObjectOutputStream(baos)) {
84 oos.writeObject(o);
85 }
86 try (ObjectInputStream ois
87 = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) {
88 o1 = (T) ois.readObject();
89 }
90 return o1;
91 }
92
93 /*
94 * Utility Method used to set the current Policy
95 */
96 protected static void setPolicy(Policy p) {
97 Policy.setPolicy(p);
98 //System.out.println("\n" + Policy.getPolicy());
99 }
100 }
|