Path: blob/master/test/jdk/javax/management/openmbean/CompositeDataStringTest.java
41149 views
/*1* Copyright (c) 2008, 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 661017426* @summary Test that CompositeDataSupport.toString() represents arrays correctly27* @author Eamonn McManus28*/2930import javax.management.openmbean.ArrayType;31import javax.management.openmbean.CompositeData;32import javax.management.openmbean.CompositeDataSupport;33import javax.management.openmbean.CompositeType;34import javax.management.openmbean.OpenType;35import javax.management.openmbean.SimpleType;3637public class CompositeDataStringTest {38public static void main(String[] args) throws Exception {39CompositeType basicCT = new CompositeType(40"basicCT", "basic CompositeType",41new String[] {"name", "value"},42new String[] {"name", "value"},43new OpenType<?>[] {SimpleType.STRING, SimpleType.INTEGER});44CompositeType ct = new CompositeType(45"noddy", "descr",46new String[] {"strings", "ints", "cds"},47new String[] {"string array", "int array", "composite data array"},48new OpenType<?>[] {49ArrayType.getArrayType(SimpleType.STRING),50ArrayType.getPrimitiveArrayType(int[].class),51ArrayType.getArrayType(basicCT)52});53CompositeData basicCD1 = new CompositeDataSupport(54basicCT, new String[] {"name", "value"}, new Object[] {"ceathar", 4});55CompositeData basicCD2 = new CompositeDataSupport(56basicCT, new String[] {"name", "value"}, new Object[] {"naoi", 9});57CompositeData cd = new CompositeDataSupport(58ct,59new String[] {"strings", "ints", "cds"},60new Object[] {61new String[] {"fred", "jim", "sheila"},62new int[] {2, 3, 5, 7},63new CompositeData[] {basicCD1, basicCD2}64});65String s = cd.toString();66System.out.println("CompositeDataSupport.toString(): " + s);67String[] expected = {68"fred, jim, sheila",69"2, 3, 5, 7",70"ceathar",71"naoi",72};73boolean ok = true;74for (String expect : expected) {75if (s.contains(expect))76System.out.println("OK: string contains <" + expect + ">");77else {78ok = false;79System.out.println("NOT OK: string does not contain <" +80expect + ">");81}82}83if (ok)84System.out.println("TEST PASSED");85else86throw new Exception("TEST FAILED: string did not contain expected substrings");87}88}899091