1 /* 2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 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 24 /** 25 * @test 26 * @modules java.sql.rowset/com.sun.rowset 27 * java.sql.rowset/com.sun.rowset.internal 28 * java.sql.rowset/com.sun.rowset.providers 29 */ 30 31 package test.rowset.serial; 32 33 import java.lang.reflect.Field; 34 import java.util.Arrays; 35 import javax.sql.rowset.RowSetMetaDataImpl; 36 import javax.sql.rowset.serial.SerialException; 37 import javax.sql.rowset.serial.SerialJavaObject; 38 import static org.testng.Assert.*; 39 import org.testng.annotations.Test; 40 import util.BaseTest; 41 42 public class SerialJavaObjectTests extends BaseTest { 43 44 /* 45 * Validate that an NPE is thrown when null is specified to create 46 * the SerialJavaObject 47 */ 48 @Test(expectedExceptions = NullPointerException.class) 49 public void test() throws Exception { 50 SerialJavaObject sjo = new SerialJavaObject(null); 51 } 52 53 /* 54 * Validate that an SerialExcepion is thrown when the object specified 55 * contains public static fields 56 */ 57 @Test(expectedExceptions = SerialException.class, enabled = false) 58 public void test01() throws Exception { 59 SerialJavaObject sjo = new SerialJavaObject(new RowSetMetaDataImpl()); 60 } 61 62 /* 63 * Validate that an getFields()s returns the same Field[] for the object 64 * used to create the SerialJavaObject 65 */ 66 @Test 67 public void test02() throws Exception { 68 SerialException e = new SerialException(); 69 SerialJavaObject sjo = new SerialJavaObject(e); 70 Field[] f = e.getClass().getFields(); 71 assertTrue(Arrays.equals(f, sjo.getFields())); 72 assertFalse(Arrays.equals("hello".getClass().getFields(), 73 sjo.getFields())); 74 } 75 76 /* 77 * clone() a SerialJavaObject and check that it is equal to the 78 * object it was cloned from 79 */ 80 @Test 81 public void test03() throws Exception { 82 SerialJavaObject sjo = new SerialJavaObject("Hello"); 83 SerialJavaObject sjo2 = (SerialJavaObject) sjo.clone(); 84 assertTrue(sjo.equals(sjo2)); 85 } 86 87 /** 88 * Validate that a SerialJavaObject that is serialized & deserialized is 89 * equal to itself 90 */ 91 @Test 92 public void test04() throws Exception { 93 SerialJavaObject sjo = new SerialJavaObject("Hello"); 94 SerialJavaObject sjo2 = serializeDeserializeObject(sjo); 95 assertTrue(sjo.equals(sjo2)); 96 } 97 98 /* 99 * Validate that a getObject() returns an object used to create the 100 * SerialJavaObject 101 */ 102 @Test 103 public void test05() throws Exception { 104 String s = "Hello world"; 105 SerialJavaObject sjo = new SerialJavaObject(s); 106 assertTrue(s.equals(sjo.getObject())); 107 } 108 }