RequiredModelMBeanGetAttributeTest.java revision 0
/*
* Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
* 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 5043245
* @summary Test the following in RequiredModelMBean.getAttribute():
* The declared type of the attribute is the String returned by
* ModelMBeanAttributeInfo.getType(). A value is compatible
* with this type if one of the following is true:
* - the value is null;
* - the declared name is a primitive type name (such as "int")
* and the value is an instance of the corresponding wrapper
* type (such as java.lang.Integer);
* - the name of the value's class is identical to the declared name;
* - the declared name can be loaded by the value's class loader and
* produces a class to which the value can be assigned.
* @author Luis-Miguel Alventosa
* @run clean RequiredModelMBeanGetAttributeTest
* @run build RequiredModelMBeanGetAttributeTest
* @run main RequiredModelMBeanGetAttributeTest
*/
public class RequiredModelMBeanGetAttributeTest {
boolean ok = true;
// Resource methods
// ModelMBeanOperationInfo
new DescriptorSupport(new String[] {
"name=getNull",
"descriptorType=operation",
"role=getter"
});
new ModelMBeanOperationInfo("Null attribute",
new DescriptorSupport(new String[] {
"name=getInteger",
"descriptorType=operation",
"role=getter"
});
new ModelMBeanOperationInfo("Integer attribute",
new DescriptorSupport(new String[] {
"name=getHashtable",
"descriptorType=operation",
"role=getter"
});
new ModelMBeanOperationInfo("Hashtable attribute",
new DescriptorSupport(new String[] {
"name=getMap",
"descriptorType=operation",
"role=getter"
});
new ModelMBeanOperationInfo("Map attribute",
// ModelMBeanAttributeInfo
new DescriptorSupport(new String[] {
"name=Null",
"descriptorType=attribute",
"getMethod=getNull"
});
new ModelMBeanAttributeInfo("Null",
"java.lang.Object",
"Null attribute",
true,
false,
false,
new DescriptorSupport(new String[] {
"name=Integer",
"descriptorType=attribute",
"getMethod=getInteger"
});
new ModelMBeanAttributeInfo("Integer",
"int",
"Integer attribute",
true,
false,
false,
new DescriptorSupport(new String[] {
"name=Hashtable",
"descriptorType=attribute",
"getMethod=getHashtable"
});
new ModelMBeanAttributeInfo("Hashtable",
"java.util.Hashtable",
"Hashtable attribute",
true,
false,
false,
new DescriptorSupport(new String[] {
"name=Map",
"descriptorType=attribute",
"getMethod=getMap"
});
new ModelMBeanAttributeInfo("Map",
"java.util.Map",
"Map attribute",
true,
false,
false,
new DescriptorSupport(new String[] {
"name=Null2",
"descriptorType=attribute"
});
new ModelMBeanAttributeInfo("Null2",
"java.lang.Object",
"Null2 attribute",
true,
false,
false,
new DescriptorSupport(new String[] {
"name=Integer2",
"descriptorType=attribute"
});
new ModelMBeanAttributeInfo("Integer2",
"int",
"Integer2 attribute",
true,
false,
false,
new DescriptorSupport(new String[] {
"name=Hashtable2",
"descriptorType=attribute"
});
new ModelMBeanAttributeInfo("Hashtable2",
"java.util.Hashtable",
"Hashtable2 attribute",
true,
false,
false,
new DescriptorSupport(new String[] {
"name=Map2",
"descriptorType=attribute"
});
new ModelMBeanAttributeInfo("Map2",
"java.util.Map",
"Map2 attribute",
true,
false,
false,
// ModelMBeanInfo
"Resource MBean",
new ModelMBeanAttributeInfo[] { nullAttributeInfo,
null,
new ModelMBeanOperationInfo[] { nullOperationInfo,
null);
// RequiredModelMBean
// Run tests
try {
} catch (Exception e) {
ok = false;
}
try {
} catch (Exception e) {
ok = false;
}
try {
"java.util.Hashtable");
} catch (Exception e) {
ok = false;
}
try {
"java.util.Map");
} catch (Exception e) {
ok = false;
}
try {
} catch (Exception e) {
ok = false;
}
try {
} catch (Exception e) {
ok = false;
}
try {
"java.util.Hashtable");
} catch (Exception e) {
ok = false;
}
try {
"java.util.Map");
} catch (Exception e) {
ok = false;
}
if (ok)
else {
}
}
public static class Resource {
return null;
}
public int getInteger() {
return 10;
}
public Hashtable getHashtable() {
return new Hashtable();
}
return new Hashtable();
}
}
}