Path: blob/master/test/jdk/sun/management/LazyCompositeDataTest.java
41144 views
/*1* Copyright (c) 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*/2223import java.util.HashMap;24import java.util.Map;25import javax.management.openmbean.ArrayType;26import javax.management.openmbean.CompositeData;27import javax.management.openmbean.CompositeDataSupport;28import javax.management.openmbean.CompositeType;29import javax.management.openmbean.OpenDataException;30import javax.management.openmbean.OpenType;31import javax.management.openmbean.SimpleType;32import sun.management.LazyCompositeData;3334/**35* @test36* @bug 813987037* @summary sun.management.LazyCompositeData.isTypeMatched() fails for composite types with items of ArrayType38* @author Jaroslav Bachorik39*/4041public class LazyCompositeDataTest {42private final static CompositeData dataV1, dataV2;4344static {45try {46// ***47// prepare the composite types4849// composite type stored in an array; V150CompositeType subtypeV1 = new CompositeType(51"Subtype1",52"Version 1",53new String[]{"item1"},54new String[]{"Item 1"},55new OpenType<?>[]{56SimpleType.STRING57}58);5960// composite type stored in an array; V261CompositeType subtypeV2 = new CompositeType(62"Subtype2",63"Version 2",64new String[]{"item1", "item2"},65new String[]{"Item 1", "Item 2"},66new OpenType<?>[]{67SimpleType.STRING,68SimpleType.INTEGER69}70);717273// main composite type; V174// one of the items is array of 'subtypeV1' instances75CompositeType typeV1 = new CompositeType(76"MyDataV1",77"Version 1",78new String[]{"item1", "item2"},79new String[]{"Item 1", "Item 2"},80new OpenType<?>[]{81SimpleType.STRING,82ArrayType.getArrayType(subtypeV1)83}84);8586// main composite type; V287// one of the items is array of 'subtypeV2' instances88CompositeType typeV2 = new CompositeType(89"MyDataV2",90"Version 2",91new String[]{"item1", "item2"},92new String[]{"Item 1", "Item 2"},93new OpenType<?>[]{94SimpleType.STRING,95ArrayType.getArrayType(subtypeV2)96}97);98// ***99100// ***101// construct the data102Map<String, Object> subitemsV1 = new HashMap<>();103Map<String, Object> subitemsV2 = new HashMap<>();104105Map<String, Object> itemsV1 = new HashMap<>();106Map<String, Object> itemsV2 = new HashMap<>();107108subitemsV1.put("item1", "item1");109subitemsV2.put("item1", "item1");110subitemsV2.put("item2", 42);111112itemsV1.put("item1", "item1");113itemsV1.put("item2", new CompositeData[]{new CompositeDataSupport(subtypeV1, subitemsV1)});114115itemsV2.put("item1", "item1");116itemsV2.put("item2", new CompositeData[]{new CompositeDataSupport(subtypeV2, subitemsV2)});117118dataV1 = new CompositeDataSupport(typeV1, itemsV1);119dataV2 = new CompositeDataSupport(typeV2, itemsV2);120// ***121} catch (OpenDataException e) {122throw new Error(e);123}124}125126private static class MyDataV1 extends LazyCompositeData {127@Override128protected CompositeData getCompositeData() {129return dataV1;130}131132public boolean isTypeMached(CompositeType type) {133return isTypeMatched(this.getCompositeType(), type);134}135}136137private static class MyDataV2 extends LazyCompositeData {138@Override139protected CompositeData getCompositeData() {140return dataV2;141}142143}144145public static void main(String[] args) throws Exception {146System.out.println("Checking LazyCompositeData.isTypeMatched()");147MyDataV1 v1 = new MyDataV1();148MyDataV2 v2 = new MyDataV2();149150if (!v1.isTypeMached(v2.getCompositeType())) {151System.err.println("=== FAILED");152System.err.println("V1 should be matched by V2");153System.err.println("\n=== V1");154System.err.println(v1.getCompositeType());155System.err.println("\n=== V2");156System.err.println(v2.getCompositeType());157throw new Error();158}159System.out.println("=== PASSED");160}161}162163164165