Exception caught = null;
// Check null name throws NullPointerException
try
{
new MBeanServerPermission(null);
}
catch (Exception ex)
{
caught = ex;
}
h.check(caught instanceof NullPointerException, "Null name");
caught = null;
// Check "*" is a valid name
try
{
new MBeanServerPermission("*");
}
catch (Exception ex)
{
caught = ex;
}
h.check(caught, null, "* is valid");
// Check valid values are allowed
String[] valid = new String[] { "createMBeanServer", "newMBeanServer",
"findMBeanServer", "releaseMBeanServer" };
// 1
for (int a = 0; a < valid.length; ++a)
{
caught = null;
try
{
new MBeanServerPermission(valid[a]);
}
catch (Exception ex)
{
caught = ex;
}
h.check(caught, null, valid[a] + " is valid");
}
// 2
for (int a = 0; a < valid.length; ++a)
for (int b = 0; b < valid.length; ++b)
{
caught = null;
String permit = valid[a] + "," + valid[b];
try
{
new MBeanServerPermission(permit);
}
catch (Exception ex)
{
caught = ex;
}
h.check(caught, null, permit + " is valid");
}
// 3
for (int a = 0; a < valid.length; ++a)
for (int b = 0; b < valid.length; ++b)
for (int c = 0; c < valid.length; ++c)
{
caught = null;
String permit = valid[a] + "," + valid[b] + "," + valid[c];
try
{
new MBeanServerPermission(permit);
}
catch (Exception ex)
{
caught = ex;
}
h.check(caught, null, permit + " is valid");
}
// 4
for (int a = 0; a < valid.length; ++a)
for (int b = 0; b < valid.length; ++b)
for (int c = 0; c < valid.length; ++c)
for (int d = 0; d < valid.length; ++d)
{
caught = null;
String permit = valid[a] + "," + valid[b] + "," + valid[c]
+ "," + valid[d];
try
{
new MBeanServerPermission(permit);
}
catch (Exception ex)
{
caught = ex;
}
h.check(caught, null, permit + " is valid");
}
caught = null;
// Check with spaces
try
{
new MBeanServerPermission(" createMBeanServer , newMBeanServer ");
}
catch (Exception ex)
{
caught = ex;
}
h.check(caught, null, "spaces are valid");
caught = null;
// Check random stuff gets thrown out
try
{
new MBeanServerPermission("fjafjlskjflka");
}
catch (Exception ex)
{
caught = ex;
}
h.check(caught instanceof IllegalArgumentException,
"other names are invalid");
caught = null;
// Check non-null non-empty actions are caught
try
{
new MBeanServerPermission("*","fishcakes");
}
catch (Exception ex)
{
caught = ex;
}