Path: blob/master/test/jdk/javax/management/descriptor/ImmutableDescriptorSetFieldsTest.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 630513926* @summary Check that calling setFields with a field names array with a27* null name in it and calling setFields with a field names array with an28* empty name in it throw the expected exceptions.29* @author Luis-Miguel Alventosa30*31* @run clean ImmutableDescriptorSetFieldsTest32* @run build ImmutableDescriptorSetFieldsTest33* @run main ImmutableDescriptorSetFieldsTest34*/3536import javax.management.ImmutableDescriptor;37import javax.management.RuntimeOperationsException;3839public class ImmutableDescriptorSetFieldsTest {40public static void main(String[] args) throws Exception {41boolean ok = true;42ImmutableDescriptor d = new ImmutableDescriptor("k=v");43try {44System.out.println(45"Call ImmutableDescriptor.setFields(fieldNames,fieldValues) " +46"with empty name in field names array");47String fieldNames[] = { "a", "", "c" };48Object fieldValues[] = { 1, 2, 3 };49d.setFields(fieldNames, fieldValues);50System.out.println("Didn't get expected exception");51ok = false;52} catch (RuntimeOperationsException e) {53if (e.getCause() instanceof IllegalArgumentException) {54System.out.println("Got expected exception:");55ok = true;56} else {57System.out.println("Got unexpected exception:");58ok = false;59}60e.printStackTrace(System.out);61} catch (Exception e) {62System.out.println("Got unexpected exception:");63ok = false;64e.printStackTrace(System.out);65}66try {67System.out.println(68"Call ImmutableDescriptor.setFields(fieldNames,fieldValues) " +69"with null name in field names array");70String fieldNames[] = { "a", null, "c" };71Object fieldValues[] = { 1, 2, 3 };72d.setFields(fieldNames, fieldValues);73System.out.println("Didn't get expected exception");74ok = false;75} catch (RuntimeOperationsException e) {76if (e.getCause() instanceof IllegalArgumentException) {77System.out.println("Got expected exception:");78ok = true;79} else {80System.out.println("Got unexpected exception:");81ok = false;82}83e.printStackTrace(System.out);84} catch (Exception e) {85System.out.println("Got unexpected exception:");86ok = false;87e.printStackTrace(System.out);88}89if (ok) {90System.out.println("TEST PASSED");91} else {92System.out.println("TEST FAILED");93throw new Exception("Got unexpected exceptions");94}95}96}979899