Path: blob/master/test/jdk/javax/management/MBeanInfo/SerializationTest.java
41149 views
/*1* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 628810026* @summary Test the new serialization/deserialization methods.27* @author Shanliang JIANG28*29* @run clean SerializationTest30* @run build SerializationTest31* @run main SerializationTest32*/3334import java.io.*;35import javax.management.*;3637public class SerializationTest {38public static void main(String[] args) throws Exception {39MBeanFeatureInfo mfi1 = new MBeanFeatureInfo("", "", null);40test(mfi1);4142MBeanFeatureInfo mfi2 = new MBeanFeatureInfo("",43"",44ImmutableDescriptor.EMPTY_DESCRIPTOR);45test(mfi2);4647MBeanFeatureInfo mfi3 = new MBeanFeatureInfo("", "",48new ImmutableDescriptor(new String[] {"hi"},49new Object[] {"ha"}));50test(mfi3);5152MBeanInfo mi1 = new MBeanInfo("",53"",54new MBeanAttributeInfo[]{},55new MBeanConstructorInfo[]{},56new MBeanOperationInfo[]{},57new MBeanNotificationInfo[]{},58null);596061test(mi1);6263MBeanInfo mi2 = new MBeanInfo("",64"",65new MBeanAttributeInfo[]{},66new MBeanConstructorInfo[]{},67new MBeanOperationInfo[]{},68new MBeanNotificationInfo[]{},69ImmutableDescriptor.EMPTY_DESCRIPTOR);707172test(mi2);7374MBeanInfo mi3 = new MBeanInfo("",75"",76new MBeanAttributeInfo[]{},77new MBeanConstructorInfo[]{},78new MBeanOperationInfo[]{},79new MBeanNotificationInfo[]{},80new ImmutableDescriptor(new String[] {"hi"},81new Object[] {"ha"}));828384test(mi3);858687}8889public static void test(Object obj) throws Exception {90ByteArrayOutputStream baos = new ByteArrayOutputStream();91ObjectOutputStream oos = new ObjectOutputStream(baos);92oos.writeObject(obj);9394ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());95ObjectInputStream ois = new ObjectInputStream(bais);96Object newObj = ois.readObject();9798if (!obj.equals(newObj)) {99throw new RuntimeException("Serialization/deserialization failed.");100}101}102}103104105