/*
* 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 4967769 4980655 4980668 4981214
* @summary Test that ModelMBeanInfoSupport.setDescriptor rejects
* null descriptor, that empty arrays are handled correctly,
* that getDescriptors("mbean") works, and that default values for
* MBean descriptors are correctly assigned.
* @author Eamonn McManus
* @run clean InfoSupportTest
* @run build InfoSupportTest
* @run main InfoSupportTest
*/
public class InfoSupportTest {
boolean ok = true;
ok &= testSetDescriptorNull();
ok &= testEmptyArrayParameters();
ok &= testGetDescriptorsForMBean();
if (ok)
else {
}
}
private static boolean testSetDescriptorNull() {
"ModelMBeanInfoSupport.setDescriptor(null, \"x\")" +
" throws an exception");
new ModelMBeanAttributeInfo("attribute",
"java.lang.String",
"an attribute",
true, true, false);
new ModelMBeanInfoSupport("bogus.class.name",
"an MBean",
new ModelMBeanAttributeInfo[] {mmbai},
try {
} catch (RuntimeOperationsException e) {
if (e.getTargetException() instanceof IllegalArgumentException) {
"RuntimeOperationsException wrapping an " +
"IllegalArgumentException");
return true;
} else {
return false;
}
} catch (Exception e) {
return false;
}
return false;
}
private static boolean testEmptyArrayParameters()
throws Exception {
"produce the right type from getters");
boolean ok = true;
mmbi =
mmbi =
mmbi =
new ModelMBeanAttributeInfo[0],
new ModelMBeanConstructorInfo[0],
new ModelMBeanOperationInfo[0],
new ModelMBeanNotificationInfo[0]);
mmbi =
new ModelMBeanAttributeInfo[0],
new ModelMBeanConstructorInfo[0],
new ModelMBeanOperationInfo[0],
new ModelMBeanNotificationInfo[0],
null);
return ok;
}
throws Exception {
bad += " attributes";
bad += " constructors";
bad += " operations";
bad += " notifications";
return true;
} else {
return false;
}
}
private static boolean testGetDescriptorsForMBean()
throws Exception {
boolean ok = true;
try {
else {
ok = false;
}
} catch (Exception e) {
ok = false;
}
"displayName", "persistPolicy", "log", "visibility",
};
"bogus.class.name", "never", "F", "1",
};
try {
} catch (Exception e) {
}
boolean thisok = true;
// Check that the fields we supplied survived in the copy
// and were not changed in the original
value);
thisok = false;
}
"original: " + value);
thisok = false;
}
}
// Check that the default fields were added
"default value of " + field +
defaultValues[i]);
thisok = false;
}
}
// Check that the original did not acquire new fields
"acquired new fields: " + c);
thisok = false;
}
if (thisok)
else
ok = false;
} else {
ok = false;
}
return ok;
}
}