Path: blob/master/test/jdk/javax/management/openmbean/NullConstructorParamsTest.java
41149 views
/*1* Copyright (c) 2006, 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 643429826* @summary Test IAE is thrown when typeName or description parameter is null for TabularType and CompositeType constructors27* @author Joel FERAUD28*/2930import javax.management.openmbean.*;3132public class NullConstructorParamsTest {3334/**35* Print message36*/37private static void echo(String message) {38System.out.println(message);39}4041/**42* Main43*/44public static void main(String[] args) throws Exception {4546echo("SUMMARY: Test IAE is thrown when typeName or description parameter is null " +47"for TabularType and CompositeType constructors");4849echo(">>> Create CompositeType with non null params: should be ok");50CompositeType ctok =51new CompositeType(52"typeNameOK",53"for test",54new String[] {"a", "b"},55new String[] {"a_desc", "b_desc"},56new OpenType[] {SimpleType.BOOLEAN,SimpleType.STRING});57echo("+++ CompositeType created ok");58echo("");5960echo(">>> Create TabularType with non null params: should be ok");61TabularType tabok =62new TabularType(63"typeNameOK",64"for test",65ctok,66new String[] {"a"});67echo("+++ TabularType created ok");68echo("");697071int IAENotThrown = 0;7273try {74echo(">>> Create CompositeType with null typeName: expect IAE");75CompositeType ctnull1 =76new CompositeType(77null,78"for test",79new String[] {"a", "b"},80new String[] {"a_desc", "b_desc"},81new OpenType[] {SimpleType.BOOLEAN, SimpleType.STRING});82IAENotThrown++;83echo("*** IAE not thrown as expected ***");84echo("*** Test will FAIL ***");85echo("");86} catch (IllegalArgumentException iae) {87echo("+++ IAE thrown as expected");88echo("");89} catch (Exception e) {90IAENotThrown++;91echo("*** Did not get IAE as expected, but instead: ");92e.printStackTrace();93echo("*** Test will FAIL ***");94echo("");95}9697try {98echo(">>> Create TabularType with null typeName: expect IAE");99TabularType tabnull1 =100new TabularType(101null,102"for test",103ctok,104new String[] {"a"});105IAENotThrown++;106echo("*** IAE not thrown as expected ***");107echo("*** Test will FAIL ***");108echo("");109} catch (IllegalArgumentException iae) {110echo("+++ IAE thrown as expected");111echo("");112} catch (Exception e) {113IAENotThrown++;114echo("*** Did not get IAE as expected, but instead: ");115e.printStackTrace();116echo("*** Test will FAIL ***");117echo("");118}119120try {121echo(">>> Create CompositeType with null description: expect IAE");122CompositeType ctnull2 =123new CompositeType(124"test",125null,126new String[] {"a", "b"},127new String[] {"a_desc", "b_desc"},128new OpenType[] {SimpleType.BOOLEAN, SimpleType.STRING});129IAENotThrown++;130echo("*** IAE not thrown as expected ***");131echo("*** Test will FAIL ***");132echo("");133} catch (IllegalArgumentException iae) {134echo("+++ IAE thrown as expected");135echo("");136} catch (Exception e) {137IAENotThrown++;138echo("*** Did not get IAE as expected, but instead: ");139e.printStackTrace();140echo("*** Test will FAIL ***");141echo("");142}143144try {145echo(">>> Create TabularType with null description: expect IAE");146TabularType tabnull2 =147new TabularType(148"test",149null,150ctok,151new String[] {"a"});152IAENotThrown++;153echo("*** IAE not thrown as expected ***");154echo("*** Test will FAIL ***");155echo("");156} catch (IllegalArgumentException iae) {157echo("+++ IAE thrown as expected");158echo("");159} catch (Exception e) {160IAENotThrown++;161echo("*** Did not get IAE as expected, but instead: ");162e.printStackTrace();163echo("*** Test will FAIL ***");164echo("");165}166167if (IAENotThrown != 0 ) {168echo("*** Test FAILED: IAE not thrown as expected ***");169echo("");170throw new RuntimeException("IAE not thrown as expected");171}172echo("+++ Test PASSED");173echo("");174175}176}177178179