/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6204469
* @summary Test that Open MBean attributes and parameters cannot have
* illegal constraints like min greater than max
* @author Eamonn McManus
* @run clean BadConstraintTest
* @run build BadConstraintTest
* @run main BadConstraintTest
*/
import javax.management.*;
public class BadConstraintTest {
genericTests();
else
}
throw new Exception("Test element has wrong length: " +
}
"; defaultValue=" + defaultValue +
"; minValue=" + minValue +
"; maxValue=" + maxValue +
}
}
throw new Exception("Test element has wrong length: " +
}
throw new Exception("Test element should have one OpenType: " +
}
"; descriptor=" + d);
descriptorTest(openType, d);
}
}
/* Tests that apply to both the Descriptor and the non-Descriptor
constructors. We invoke the non-Descriptor constructors by
reflection, then we make the corresponding Descriptor and call
the descriptorTest with it. */
Comparable<?> minValue,
Comparable<?> maxValue,
throws Exception {
if (defaultValue == null)
throw new Exception("What am I testing?");
boolean.class, boolean.class, boolean.class,
Object.class
};
Object.class
};
}
if (legalValues == null) {
boolean.class, boolean.class, boolean.class,
};
};
"minValue", minValue,
"maxValue", maxValue));
}
if (legalValues != null) {
boolean.class, boolean.class, boolean.class,
};
};
"legalValues", legalValues));
for (Object x : legalValues)
"legalValues", strings));
"legalValues",
}
}
throws Exception {
boolean.class, boolean.class, boolean.class,
Descriptor.class
};
Descriptor.class
};
}
/* Check that the given constructor invocation gets an
IllegalArgumentException. */
}
/* Check that the given constructor invocation gets an
OpenDataException. */
}
try {
} catch (InvocationTargetException e) {
return;
} catch (Exception e) {
throw new IllegalArgumentException("Reflection failed", e);
}
}
}
throw new RuntimeException("Odd length descriptor entries");
}
}
}
if (x == null)
return "null";
for (int i = 0; i < len; i++) {
if (i > 0)
}
} else
return x.toString();
}
if (x == null)
return null;
return toString(x);
}
private static final OpenType<?>
static {
try {
} catch (OpenDataException e) { // damn checked exceptions...
throw new IllegalArgumentException(e.toString(), e);
}
}
private static final Descriptor
/* Each element of this array contains five Objects:
- OpenType;
- defaultValue;
- minValue;
- maxValue;
- legalValues. The objects are used to construct tests cases
where all possible constructors that make sense for that
combination of values are invoked, and all are checked to ensure
that they throw the right exception. */
// Values must be of appropriate type
// If defaultValue is present then it must satisfy the constraints
// defined by legalValues, minValue, or maxValue when any of
// these is also present
// If minValue and maxValue are both present then minValue must
// not be greater than maxValue
// We don't support default values or legal sets for arrays (yet)
};
/* The tests here can only be expressed via Descriptors because an
attempt to invoke one of the non-Descriptor constructors with
the implied parameters would not compile (or would fail at the
reflection stage when reflection is being used).
Each element of this array contains two subarrays. The first
is an array of OpenTypes that must contain exactly one element.
The second is an array of alternating field names and field
values that will be used to construct a Descriptor that is supposed
to fail when given to an OpenMBean*Info constructor with the given
OpenType. */
// Values must be of appropriate type
{{oint},
{"minValue", 25L}},
{{oint},
{{oint},
{{oint},
{"defaultValue", 3,
"minValue", new Object()}},
{{oint},
{"defaultValue", 3,
"maxValue", new Object()}},
{{oint},
{"legalValues", new int[] {3}}}, // should be new Integer[] to work
{{oint},
{"legalValues", 3}},
// If legalValues is present then neither minValue nor maxValue
// must be present
{{oint},
{{oint},
{{oint},
// We don't support min or max arrays (what would they mean?)
{{ostringarray},
{{ostringarray},
};
}