Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/MBeanInfo/SerializationTest.java
38840 views
/*1* Copyright (c) 2005, 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* @run clean SerializationTest29* @run build SerializationTest30* @run main SerializationTest31*/3233import java.io.*;34import javax.management.*;3536public class SerializationTest {37public static void main(String[] args) throws Exception {38MBeanFeatureInfo mfi1 = new MBeanFeatureInfo("", "", null);39test(mfi1);4041MBeanFeatureInfo mfi2 = new MBeanFeatureInfo("",42"",43ImmutableDescriptor.EMPTY_DESCRIPTOR);44test(mfi2);4546MBeanFeatureInfo mfi3 = new MBeanFeatureInfo("", "",47new ImmutableDescriptor(new String[] {"hi"},48new Object[] {"ha"}));49test(mfi3);5051MBeanInfo mi1 = new MBeanInfo("",52"",53new MBeanAttributeInfo[]{},54new MBeanConstructorInfo[]{},55new MBeanOperationInfo[]{},56new MBeanNotificationInfo[]{},57null);585960test(mi1);6162MBeanInfo mi2 = new MBeanInfo("",63"",64new MBeanAttributeInfo[]{},65new MBeanConstructorInfo[]{},66new MBeanOperationInfo[]{},67new MBeanNotificationInfo[]{},68ImmutableDescriptor.EMPTY_DESCRIPTOR);697071test(mi2);7273MBeanInfo mi3 = new MBeanInfo("",74"",75new MBeanAttributeInfo[]{},76new MBeanConstructorInfo[]{},77new MBeanOperationInfo[]{},78new MBeanNotificationInfo[]{},79new ImmutableDescriptor(new String[] {"hi"},80new Object[] {"ha"}));818283test(mi3);848586}8788public static void test(Object obj) throws Exception {89ByteArrayOutputStream baos = new ByteArrayOutputStream();90ObjectOutputStream oos = new ObjectOutputStream(baos);91oos.writeObject(obj);9293ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());94ObjectInputStream ois = new ObjectInputStream(bais);95Object newObj = ois.readObject();9697if (!obj.equals(newObj)) {98throw new RuntimeException("Serialization/deserialization failed.");99}100}101}102103104