jdk/test/javax/management/openmbean/NullConstructorParamsTest.java
author iignatyev
Mon, 23 Dec 2013 18:39:47 +0000
changeset 22195 c39aa322d33a
parent 5506 202f599c92aa
child 30376 2ccf2cf7ea48
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 6434298
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Test IAE is thrown when typeName or description parameter is null for TabularType and CompositeType constructors
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @author Joel FERAUD
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.management.openmbean.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
public class NullConstructorParamsTest {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
     * Print message
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    private static void echo(String message) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
        System.out.println(message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
     * Main
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        echo("SUMMARY: Test IAE is thrown when typeName or description parameter is null " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
             "for TabularType and CompositeType constructors");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        echo(">>> Create CompositeType with non null params: should be ok");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        CompositeType ctok =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
            new CompositeType(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
                              "typeNameOK",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
                              "for test",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
                              new String[] {"a", "b"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
                              new String[] {"a_desc", "b_desc"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
                              new OpenType[] {SimpleType.BOOLEAN,SimpleType.STRING});
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        echo("+++ CompositeType created ok");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        echo("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        echo(">>> Create TabularType with non null params: should be ok");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        TabularType tabok =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            new TabularType(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                            "typeNameOK",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                            "for test",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                            ctok,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                            new String[] {"a"});
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        echo("+++ TabularType created ok");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        echo("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        int IAENotThrown = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            echo(">>> Create CompositeType with null typeName: expect IAE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            CompositeType ctnull1 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                new CompositeType(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                                  null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                                  "for test",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                                  new String[] {"a", "b"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                                  new String[] {"a_desc", "b_desc"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                                  new OpenType[] {SimpleType.BOOLEAN, SimpleType.STRING});
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            IAENotThrown++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            echo("*** IAE not thrown as expected ***");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            echo("*** Test will FAIL ***");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            echo("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        } catch (IllegalArgumentException iae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            echo("+++ IAE thrown as expected");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            echo("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            IAENotThrown++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            echo("*** Did not get IAE as expected, but instead: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            echo("*** Test will FAIL ***");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            echo("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            echo(">>> Create TabularType with null typeName: expect IAE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            TabularType tabnull1 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                new TabularType(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                                null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                                "for test",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                                ctok,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                                new String[] {"a"});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            IAENotThrown++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            echo("*** IAE not thrown as expected ***");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            echo("*** Test will FAIL ***");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            echo("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        } catch (IllegalArgumentException iae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            echo("+++ IAE thrown as expected");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            echo("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            IAENotThrown++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            echo("*** Did not get IAE as expected, but instead: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            echo("*** Test will FAIL ***");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            echo("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            echo(">>> Create CompositeType with null description: expect IAE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            CompositeType ctnull2 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                new CompositeType(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                                  "test",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                                  null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                                  new String[] {"a", "b"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                                  new String[] {"a_desc", "b_desc"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                                  new OpenType[] {SimpleType.BOOLEAN, SimpleType.STRING});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            IAENotThrown++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            echo("*** IAE not thrown as expected ***");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            echo("*** Test will FAIL ***");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            echo("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        } catch (IllegalArgumentException iae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            echo("+++ IAE thrown as expected");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            echo("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            IAENotThrown++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            echo("*** Did not get IAE as expected, but instead: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            echo("*** Test will FAIL ***");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            echo("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            echo(">>> Create TabularType with null description: expect IAE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            TabularType tabnull2 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                new TabularType(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                                "test",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                                null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                                ctok,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                                new String[] {"a"});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            IAENotThrown++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            echo("*** IAE not thrown as expected ***");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            echo("*** Test will FAIL ***");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            echo("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        } catch (IllegalArgumentException iae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            echo("+++ IAE thrown as expected");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            echo("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            IAENotThrown++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            echo("*** Did not get IAE as expected, but instead: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            echo("*** Test will FAIL ***");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            echo("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        if (IAENotThrown != 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            echo("*** Test FAILED: IAE not thrown as expected ***");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            echo("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            throw new RuntimeException("IAE not thrown as expected");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        echo("+++ Test PASSED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        echo("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
}