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