2362N/A * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * @summary Test that Open MBean attributes and parameters check constraints 0N/A * @author Eamonn McManus 0N/A * @run clean ConstraintTest 0N/A * @run build ConstraintTest 0N/A * @run main ConstraintTest 0N/A throw new Exception(
"Test constraints should have size 4: " +
0N/A /* This hack is needed to avoid grief from the parameter checking 0N/A in the OpenMBean*InfoSupport constructors. Since they are defined 0N/A to check that the defaultValue etc are of the same type as the 0N/A OpenType<T>, there is no way to pass a defaultValue etc when 0N/A the type is OpenType<?>. So either you have to write plain 0N/A OpenType, and get unchecked warnings for every constructor 0N/A invocation, or you do this, and get the unchecked warnings just 0N/A true,
true,
false, d),
0N/A true,
true,
false, d),
0N/A // Legal values in descriptor can be either an array or a set 0N/A /* Test one of the objects. Note that OpenMBeanAttributeInfo 0N/A extends OpenMBeanParameterInfo, so OpenMBeanAttributeInfoSupport 0N/A is-an OpenMBeanParameterInfo. */ 0N/A // Check that the constraints can be specified as strings 0N/A // rather than objects 0N/A fail(
"Object should be valid but is not: " + x +
" for: " +
0N/A fail(
"Object should not be valid but is: " + x +
" for: " +
0N/A /* If you specify e.g. minValue in a descriptor, then we arrange 0N/A for getMinValue() to return the same value, and if you specify 0N/A a minValue as a constructor parameter then we arrange for the 0N/A descriptor to have a minValue entry. Check that these values 0N/A do in fact match. */ 0N/A fail(
"Getter returned null but descriptor has entry for " +
0N/A fail(
"Getter returned value but descriptor has no entry for " +
0N/A fail(
"Getter returned null but descriptor has entry for " +
0N/A fail(
"Getter returned value but descriptor has no entry for " +
0N/A /* The elements of this array are grouped as follows. Each 0N/A element contains four Object[]s. The first one is a set of 0N/A four values: default value, min value, max value, legal values 0N/A (an Object[]), some of which can be null. These will be used 0N/A to derive the OpenMBean*Info values to be tested. The second 0N/A is an array with one element that is the OpenType that will be 0N/A given to the constructors of the OpenMBean*Infos. The third 0N/A element is a set of values that should be valid according to 0N/A the constraints in the OpenMBean*Info. The fourth is a set of 0N/A values that should be invalid according to those 0N/A // Test cases when there are no constraints 0N/A // Validity checking is limited to type of object 0N/A {
"goodbye",
"cruel",
"world"}}},
0N/A // Test cases where there is a default value, so null is allowed 0N/A // Test cases where there is a min and/or max, with or without default 0N/A {
"A",
"~",
"", -
1}},
0N/A // Test cases where there is a set of legal values 0N/A {{
23,
null,
null,
new Integer[] {
2,
3,
5,
7,
11,
13,
17,
23}},
0N/A {},
// constraint is impossible to satisfy!