ConstraintTest.java revision 2362
0N/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. 0N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/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: " +
/* This hack is needed to avoid grief from the parameter checking in the OpenMBean*InfoSupport constructors. Since they are defined to check that the defaultValue etc are of the same type as the OpenType<T>, there is no way to pass a defaultValue etc when the type is OpenType<?>. So either you have to write plain OpenType, and get unchecked warnings for every constructor invocation, or you do this, and get the unchecked warnings just true,
true,
false,
nullD),
// Legal values in descriptor can be either an array or a set /* Test one of the objects. Note that OpenMBeanAttributeInfo extends OpenMBeanParameterInfo, so OpenMBeanAttributeInfoSupport is-an OpenMBeanParameterInfo. */ // Check that the constraints can be specified as strings fail(
"Object should be valid but is not: " + x +
" for: " +
fail(
"Object should not be valid but is: " + x +
" for: " +
/* If you specify e.g. minValue in a descriptor, then we arrange for getMinValue() to return the same value, and if you specify a minValue as a constructor parameter then we arrange for the descriptor to have a minValue entry. Check that these values fail(
"Getter returned null but descriptor has entry for " +
fail(
"Getter returned value but descriptor has no entry for " +
fail(
"Getter returned null but descriptor has entry for " +
fail(
"Getter returned value but descriptor has no entry for " +
new String[] {
"sdesc",
"idesc"},
/* The elements of this array are grouped as follows. Each element contains four Object[]s. The first one is a set of four values: default value, min value, max value, legal values (an Object[]), some of which can be null. These will be used to derive the OpenMBean*Info values to be tested. The second is an array with one element that is the OpenType that will be given to the constructors of the OpenMBean*Infos. The third element is a set of values that should be valid according to the constraints in the OpenMBean*Info. The fourth is a set of values that should be invalid according to those // Test cases when there are no constraints // Validity checking is limited to type of object {
"goodbye",
"cruel",
"world"}}},
// Test cases where there is a default value, so null is allowed // Test cases where there is a min and/or max, with or without default {{
"go",
"a",
"z~",
null},
{
null,
"a",
"z~",
"zzzz",
"z!"},
// Test cases where there is a set of legal values {{
23,
null,
null,
new Integer[] {
2,
3,
5,
7,
11,
13,
17,
23}},
{},
// constraint is impossible to satisfy!