User: ejort
Date: 02/02/01 19:16:23
Added: src/main/org/jboss/test/jbossmx/compliance/standard
AttributeInfoTEST.java ConstructorInfoTEST.java
InfoTortureTestCase.java InfoUtil.java
InheritanceTestCase.java OperationInfoTEST.java
SpuriousAttributeTEST.java TrivialTestCase.java
Log:
JBossMX tests, temporary modifications to classpaths see comment in build.xml
Revision Changes Path
1.1
jbosstest/src/main/org/jboss/test/jbossmx/compliance/standard/AttributeInfoTEST.java
Index: AttributeInfoTEST.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.test.jbossmx.compliance.standard;
import junit.framework.TestCase;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanInfo;
/**
* @author <a href="mailto:[EMAIL PROTECTED]">Trevor Squires</a>.
*/
public class AttributeInfoTEST
extends TestCase
{
private String failureHint;
private MBeanInfo info;
private String attributeName;
private String type;
private boolean read;
private boolean write;
private boolean is;
public AttributeInfoTEST(String failureHint, MBeanInfo info, String
attributeName, String type, boolean read, boolean write, boolean is)
{
super("testValidAttribute");
this.failureHint = failureHint;
this.info = info;
this.attributeName = attributeName;
this.type = type;
this.read= read;
this.write= write;
this.is= is;
}
public void testValidAttribute()
{
MBeanAttributeInfo[] attributes = info.getAttributes();
MBeanAttributeInfo attribute = InfoUtil.findAttribute(attributes,
attributeName);
assertNotNull(failureHint + ": " + info.getClassName() + ": " + attributeName
+ " was not found", attribute);
assertEquals(failureHint + ": " + info.getClassName() + ": " + attributeName +
" type", type, attribute.getType());
assertEquals(failureHint + ": " + info.getClassName() + ": " + attributeName +
" readable", read, attribute.isReadable());
assertEquals(failureHint + ": " + info.getClassName() + ": " + attributeName +
" writable", write, attribute.isWritable());
assertEquals(failureHint + ": " + info.getClassName() + ": " + attributeName +
" isIS", is, attribute.isIs());
}
}
1.1
jbosstest/src/main/org/jboss/test/jbossmx/compliance/standard/ConstructorInfoTEST.java
Index: ConstructorInfoTEST.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.test.jbossmx.compliance.standard;
import junit.framework.TestCase;
import javax.management.MBeanConstructorInfo;
import javax.management.MBeanInfo;
/**
* @author <a href="mailto:[EMAIL PROTECTED]">Trevor Squires</a>.
*/
public class ConstructorInfoTEST extends TestCase
{
private String failureHint;
private MBeanInfo info;
private String constructorName;
private String signatureString;
public ConstructorInfoTEST(String failureHint, MBeanInfo info, String
constructorName, String[] signature)
{
super("testValidConstructor");
this.failureHint = failureHint;
this.info = info;
this.constructorName = constructorName;
this.signatureString = InfoUtil.makeSignatureString(signature);
}
public void testValidConstructor()
{
MBeanConstructorInfo[] constructors = info.getConstructors();
MBeanConstructorInfo foundConstructor= null;
for (int i = 0; i < constructors.length; i++)
{
if
(signatureString.equals(InfoUtil.makeSignatureString(constructors[i].getSignature())))
{
foundConstructor = constructors[i];
break;
}
}
assertNotNull(failureHint + ": " + info.getClassName() + "." + constructorName
+ signatureString + " was not found", foundConstructor);
}
}
1.1
jbosstest/src/main/org/jboss/test/jbossmx/compliance/standard/InfoTortureTestCase.java
Index: InfoTortureTestCase.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.test.jbossmx.compliance.standard;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.jboss.test.jbossmx.compliance.TestCase;
import org.jboss.test.jbossmx.compliance.standard.support.Torture;
import javax.management.MBeanInfo;
import javax.management.MBeanOperationInfo;
/**
* Beat the heck out of the server's standard MBeanInfo
*
* @author <a href="mailto:[EMAIL PROTECTED]">Trevor Squires</a>.
*/
public class InfoTortureTestCase
extends TestCase
{
private static int attributeTestCount = 0;
private static int operationTestCount = 0;
private static int constructorTestCount = 0;
public InfoTortureTestCase(String s)
{
super(s);
}
public static Test suite()
{
TestSuite testSuite = new TestSuite("All MBeanInfo Torture Tests for Standard
MBeans");
Object mbean = new Torture();
MBeanInfo info = InfoUtil.getMBeanInfo(mbean, "test:type=mbeaninfo");
// Tests for valid constructors
addConstructorTest(testSuite, info, Torture.class.getName(), new String[0]);
addConstructorTest(testSuite, info, Torture.class.getName(), new String[] {
String[][].class.getName() });
// make sure we are testing all exposed constructors (each
ValidConstructorTest increments a counter
// which is used to figure out whether we have adequate test coverage)
testSuite.addTest(new TestCoverageTEST("Torture constructor list length",
constructorTestCount, info.getConstructors().length));
// Tests for attributes that should not be there
addSpuriousAttributeTest(testSuite, info, "peachy");
addSpuriousAttributeTest(testSuite, info, "Peachy");
addSpuriousAttributeTest(testSuite, info, "suer");
addSpuriousAttributeTest(testSuite, info, "settlement");
addSpuriousAttributeTest(testSuite, info, "Result");
addSpuriousAttributeTest(testSuite, info, "Multi");
// make sure remaining attributes are correct
// Args are: Name, Type, Readable, Writable, IsIS
addAttributeTest(testSuite, info, "NiceString", String.class.getName(), true,
true, false);
addAttributeTest(testSuite, info, "NiceBoolean", boolean.class.getName(),
true, true, true);
addAttributeTest(testSuite, info, "Something", String.class.getName(), false,
true, false);
addAttributeTest(testSuite, info, "Int", int.class.getName(), false, true,
false);
addAttributeTest(testSuite, info, "IntArray", int[].class.getName(), false,
true, false);
addAttributeTest(testSuite, info, "NestedIntArray", int[][][].class.getName(),
false, true, false);
addAttributeTest(testSuite, info, "Integer", Integer.class.getName(), false,
true, false);
addAttributeTest(testSuite, info, "IntegerArray", Integer[].class.getName(),
false, true, false);
addAttributeTest(testSuite, info, "NestedIntegerArray",
Integer[][][].class.getName(), false, true, false);
addAttributeTest(testSuite, info, "Myinteger", int.class.getName(), true,
false, false);
addAttributeTest(testSuite, info, "MyintegerArray", int[].class.getName(),
true, false, false);
addAttributeTest(testSuite, info, "MyNestedintegerArray",
int[][][].class.getName(), true, false, false);
addAttributeTest(testSuite, info, "MyInteger", Integer.class.getName(), true,
false, false);
addAttributeTest(testSuite, info, "MyIntegerArray", Integer[].class.getName(),
true, false, false);
addAttributeTest(testSuite, info, "MyNestedIntegerArray",
Integer[][][].class.getName(), true, false, false);
addAttributeTest(testSuite, info, "ready", boolean.class.getName(), true,
false, true);
addAttributeTest(testSuite, info, "Ready", Boolean.class.getName(), true,
false, true);
// make sure we are testing all exposed attributes (each ValidAttributeTest
increments a counter
// which is used to figure out whether we have adequate test coverage)
testSuite.addTest(new TestCoverageTEST("Torture attribute list length",
attributeTestCount, info.getAttributes().length));
// validate the operations
// Args are: Name, impact, returnTypeString, SignatureAsStringArray
addOperationTest(testSuite, info, "settlement", MBeanOperationInfo.UNKNOWN,
int.class.getName(), new String[] { String.class.getName() });
addOperationTest(testSuite, info, "getSomething", MBeanOperationInfo.UNKNOWN,
Void.TYPE.getName(), new String[0]);
addOperationTest(testSuite, info, "ispeachy", MBeanOperationInfo.UNKNOWN,
boolean.class.getName(), new String[] { int.class.getName() });
addOperationTest(testSuite, info, "isPeachy", MBeanOperationInfo.UNKNOWN,
Boolean.class.getName(), new String[] { int.class.getName() });
addOperationTest(testSuite, info, "setMulti", MBeanOperationInfo.UNKNOWN,
Void.TYPE.getName(), new String[] { String.class.getName(), Integer.class.getName() });
addOperationTest(testSuite, info, "getResult", MBeanOperationInfo.UNKNOWN,
String.class.getName(), new String[] { String.class.getName() });
addOperationTest(testSuite, info, "setNothing", MBeanOperationInfo.UNKNOWN,
Void.TYPE.getName(), new String[0]);
addOperationTest(testSuite, info, "getNothing", MBeanOperationInfo.UNKNOWN,
Void.TYPE.getName(), new String[0]);
addOperationTest(testSuite, info, "doSomethingCrazy",
MBeanOperationInfo.UNKNOWN, String[][].class.getName(), new String[] {
Object[].class.getName(), String[].class.getName(), int[][][].class.getName() });
// Hmmm... This fails in the RI (which causes the operation coverage test to
fail too.
// it's odd because in the RI issuer() isn't treated as an attribute and it
doesn't
// appear as an operation - it just disappears!
addOperationTest(testSuite, info, "issuer", MBeanOperationInfo.UNKNOWN,
String.class.getName(), new String[0]);
// make sure we are testing all exposed operations (each ValidOperationTest
increments a counter
// which is used to figure out whether we have adequate test coverage)
testSuite.addTest(new TestCoverageTEST("Torture operation list length",
operationTestCount, info.getOperations().length));
return testSuite;
}
public static void addConstructorTest(TestSuite testSuite, MBeanInfo info, String
name, String[] signature)
{
testSuite.addTest(new ConstructorInfoTEST("InfoTortureSUITE constructor",
info, name, signature));
constructorTestCount++;
}
public static void addSpuriousAttributeTest(TestSuite testSuite, MBeanInfo info,
String name)
{
testSuite.addTest(new SpuriousAttributeTEST("InfoTortureSUITE
spuriousAttribute", info, name));
}
public static void addAttributeTest(TestSuite testSuite, MBeanInfo info, String
name, String type, boolean read, boolean write, boolean is)
{
testSuite.addTest(new AttributeInfoTEST("InfoTortureSUITE attribute", info,
name, type, read, write, is));
attributeTestCount++;
}
public static void addOperationTest(TestSuite testSuite, MBeanInfo info, String
name, int impact, String returnType, String[] signature)
{
testSuite.addTest(new OperationInfoTEST("InfoTortureSUITE operation", info,
name, impact, returnType, signature));
operationTestCount++;
}
public static class TestCoverageTEST
extends TestCase
{
private String msg;
private int expected;
private int got;
public TestCoverageTEST(String msg, int expected, int got)
{
super("testAdequateCoverage");
this.msg = msg;
this.expected = expected;
this.got = got;
}
public void testAdequateCoverage()
{
assertEquals(msg, expected, got);
}
}
}
1.1
jbosstest/src/main/org/jboss/test/jbossmx/compliance/standard/InfoUtil.java
Index: InfoUtil.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.test.jbossmx.compliance.standard;
import org.jboss.test.jbossmx.compliance.standard.support.Torture;
import javax.management.MBeanInfo;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.ObjectName;
import javax.management.ObjectInstance;
import javax.management.MalformedObjectNameException;
import javax.management.InstanceAlreadyExistsException;
import javax.management.MBeanRegistrationException;
import javax.management.NotCompliantMBeanException;
import javax.management.InstanceNotFoundException;
import javax.management.IntrospectionException;
import javax.management.ReflectionException;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanConstructorInfo;
import javax.management.MBeanOperationInfo;
import javax.management.MBeanParameterInfo;
import junit.framework.Assert;
public class InfoUtil
{
public static MBeanInfo getMBeanInfo(Object mbean, String name)
{
MBeanInfo info = null;
try
{
MBeanServer server = MBeanServerFactory.newMBeanServer();
ObjectName objectName = new ObjectName(name);
ObjectInstance instance = server.registerMBean(mbean, objectName);
info = server.getMBeanInfo(objectName);
}
catch (MalformedObjectNameException e)
{
Assert.fail("got spurious MalformedObjectNameException");
}
catch (InstanceAlreadyExistsException e)
{
Assert.fail("got spurious InstanceAlreadyExistsException");
}
catch (MBeanRegistrationException e)
{
Assert.fail("got spurious MBeanRegistrationException");
}
catch (NotCompliantMBeanException e)
{
Assert.fail("got spurious NotCompliantMBeanException");
}
catch (InstanceNotFoundException e)
{
Assert.fail("got spurious InstanceNotFoundException");
}
catch (IntrospectionException e)
{
Assert.fail("got spurious IntrospectionException");
}
catch (ReflectionException e)
{
Assert.fail("got spurious ReflectionException");
}
return info;
}
public static MBeanAttributeInfo findAttribute(MBeanAttributeInfo[] attributes,
String name)
{
for (int i = 0; i < attributes.length; i++)
{
if (attributes[i].getName().equals(name))
{
return attributes[i];
}
}
return null;
}
public static void dumpConstructors(MBeanConstructorInfo[] constructors)
{
System.out.println("");
System.out.println("Constructors:");
for (int i = 0; i < constructors.length; i++)
{
StringBuffer dump = new StringBuffer();
MBeanConstructorInfo constructor = constructors[i];
dump.append("name=").append(constructor.getName());
dump.append(",signature=").append(makeSignatureString(constructor.getSignature()));
System.out.println(dump);
}
}
public static void dumpAttributes(MBeanAttributeInfo[] attributes)
{
System.out.println("");
System.out.println("Attributes:");
for (int i = 0; i < attributes.length; i++)
{
StringBuffer dump = new StringBuffer();
MBeanAttributeInfo attribute = attributes[i];
dump.append("name=").append(attribute.getName());
dump.append(",type=").append(attribute.getType());
dump.append(",readable=").append(attribute.isReadable());
dump.append(",writable=").append(attribute.isWritable());
dump.append(",isIS=").append(attribute.isIs());
System.out.println(dump);
}
}
public static void dumpOperations(MBeanOperationInfo[] operations)
{
System.out.println("");
System.out.println("Operations:");
for (int i = 0; i < operations.length; i++)
{
StringBuffer dump = new StringBuffer();
MBeanOperationInfo operation = operations[i];
dump.append("name=").append(operation.getName());
dump.append(",impact=").append(decodeImpact(operation.getImpact()));
dump.append(",returnType=").append(operation.getReturnType());
dump.append(",signature=").append(makeSignatureString(operation.getSignature()));
System.out.println(dump);
}
}
public static String makeSignatureString(MBeanParameterInfo[] info)
{
String[] sig = new String[info.length];
for (int i = 0; i < info.length; i++)
{
sig[i] = info[i].getType();
}
return makeSignatureString(sig);
}
public static String makeSignatureString(String[] sig)
{
StringBuffer buf = new StringBuffer("(");
for (int i = 0; i < sig.length; i++)
{
buf.append(sig[i]);
if (i != sig.length - 1)
{
buf.append(",");
}
}
buf.append(")");
return buf.toString();
}
public static String decodeImpact(int impact)
{
switch (impact)
{
case MBeanOperationInfo.ACTION:
return "ACTION";
case MBeanOperationInfo.ACTION_INFO:
return "ACTION_INFO";
case MBeanOperationInfo.INFO:
return "INFO";
case MBeanOperationInfo.UNKNOWN:
return "UNKNOWN";
}
throw new IllegalArgumentException("unknown impact value:" + impact);
}
}
1.1
jbosstest/src/main/org/jboss/test/jbossmx/compliance/standard/InheritanceTestCase.java
Index: InheritanceTestCase.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.test.jbossmx.compliance.standard;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.jboss.test.jbossmx.compliance.TestCase;
import org.jboss.test.jbossmx.compliance.standard.support.StandardDerived1;
import org.jboss.test.jbossmx.compliance.standard.support.StandardDerived2;
import org.jboss.test.jbossmx.compliance.standard.support.DynamicDerived1;
import org.jboss.test.jbossmx.compliance.standard.support.StandardDerived3;
import javax.management.MBeanInfo;
import javax.management.MBeanOperationInfo;
/**
* Beat the heck out of the server's standard MBeanInfo inheritance handling
*
* @author <a href="mailto:[EMAIL PROTECTED]">Trevor Squires</a>.
*/
public class InheritanceTestCase
extends TestCase
{
private static int attributeTestCount = 0;
private static int operationTestCount = 0;
private static int constructorTestCount = 0;
public InheritanceTestCase(String s)
{
super(s);
}
public static Test suite()
{
TestSuite testSuite = new TestSuite("All MBeanInfo Torture Tests for Standard
MBeans");
Object mbean = new StandardDerived1();
MBeanInfo info = InfoUtil.getMBeanInfo(mbean, "test:type=mbeaninfo");
addConstructorTest(testSuite, info, StandardDerived1.class.getName(), new
String[0]);
testSuite.addTest(new TestCoverageTEST("StandardDerived1 constructor list
length", constructorTestCount, info.getConstructors().length));
addAttributeTest(testSuite, info, "ParentValue", String.class.getName(),
false, true, false);
addAttributeTest(testSuite, info, "Available", boolean.class.getName(), false,
true, false);
testSuite.addTest(new TestCoverageTEST("StandardDerived1 attribute list
length", attributeTestCount, info.getAttributes().length));
testSuite.addTest(new TestCoverageTEST("StandardDerived1 operation list
length", operationTestCount, info.getOperations().length));
resetCounters();
mbean = new StandardDerived2();
info = InfoUtil.getMBeanInfo(mbean, "test:type=mbeaninfo");
addConstructorTest(testSuite, info, StandardDerived2.class.getName(), new
String[0]);
testSuite.addTest(new TestCoverageTEST("StandardDerived2 constructor list
length", constructorTestCount, info.getConstructors().length));
addAttributeTest(testSuite, info, "DerivedValue", String.class.getName(),
false, true, false);
addAttributeTest(testSuite, info, "ParentValue", String.class.getName(), true,
false, false);
addSpuriousAttributeTest(testSuite, info, "Available");
testSuite.addTest(new TestCoverageTEST("StandardDerived2 attribute list
length", attributeTestCount, info.getAttributes().length));
testSuite.addTest(new TestCoverageTEST("StandardDerived2 operation list
length", operationTestCount, info.getOperations().length));
resetCounters();
mbean = new StandardDerived3();
info = InfoUtil.getMBeanInfo(mbean, "test:type=mbeaninfo");
addConstructorTest(testSuite, info, StandardDerived3.class.getName(), new
String[0]);
testSuite.addTest(new TestCoverageTEST("StandardDerived3 constructor list
length", constructorTestCount, info.getConstructors().length));
addAttributeTest(testSuite, info, "ArbitraryValue", String.class.getName(),
false, true, false);
testSuite.addTest(new TestCoverageTEST("StandardDerived3 attribute list
length", attributeTestCount, info.getAttributes().length));
testSuite.addTest(new TestCoverageTEST("StandardDerived3 operation list
length", operationTestCount, info.getOperations().length));
resetCounters();
mbean = new DynamicDerived1();
info = InfoUtil.getMBeanInfo(mbean, "test:type=mbeaninfo");
testSuite.addTest(new TestCoverageTEST("DynamicDerived1 constructor list
length", constructorTestCount, info.getConstructors().length));
testSuite.addTest(new TestCoverageTEST("DynamicDerived1 attribute list
length", attributeTestCount, info.getAttributes().length));
testSuite.addTest(new TestCoverageTEST("DynamicDerived1 operation list
length", operationTestCount, info.getOperations().length));
return testSuite;
}
public static void resetCounters()
{
constructorTestCount = 0;
attributeTestCount = 0;
operationTestCount = 0;
}
public static void addConstructorTest(TestSuite testSuite, MBeanInfo info, String
name, String[] signature)
{
testSuite.addTest(new ConstructorInfoTEST("InheritanceSUITE constructor",
info, name, signature));
constructorTestCount++;
}
public static void addSpuriousAttributeTest(TestSuite testSuite, MBeanInfo info,
String name)
{
testSuite.addTest(new SpuriousAttributeTEST("InheritanceSUITE
spuriousAttribute", info, name));
}
public static void addAttributeTest(TestSuite testSuite, MBeanInfo info, String
name, String type, boolean read, boolean write, boolean is)
{
testSuite.addTest(new AttributeInfoTEST("InheritanceSUITE attribute", info,
name, type, read, write, is));
attributeTestCount++;
}
public static void addOperationTest(TestSuite testSuite, MBeanInfo info, String
name, int impact, String returnType, String[] signature)
{
testSuite.addTest(new OperationInfoTEST("InheritanceSUITE operation", info,
name, impact, returnType, signature));
operationTestCount++;
}
public static class TestCoverageTEST extends TestCase
{
private String msg;
private int expected;
private int got;
public TestCoverageTEST(String msg, int expected, int got)
{
super("testAdequateCoverage");
this.msg = msg;
this.expected = expected;
this.got = got;
}
public void testAdequateCoverage()
{
assertEquals(msg, expected, got);
}
}
}
1.1
jbosstest/src/main/org/jboss/test/jbossmx/compliance/standard/OperationInfoTEST.java
Index: OperationInfoTEST.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.test.jbossmx.compliance.standard;
import junit.framework.TestCase;
import javax.management.MBeanInfo;
import javax.management.MBeanOperationInfo;
/**
* @author <a href="mailto:[EMAIL PROTECTED]">Trevor Squires</a>.
*/
public class OperationInfoTEST extends TestCase
{
private String failureHint;
private MBeanInfo info;
private String operationName;
private int impact;
private String returnType;
private String signatureString;
public OperationInfoTEST(String failureHint, MBeanInfo info, String
operationName, int impact, String returnType, String[] signature)
{
super("testValidOperation");
this.failureHint = failureHint;
this.info = info;
this.operationName = operationName;
this.impact = impact;
this.returnType = returnType;
this.signatureString = InfoUtil.makeSignatureString(signature);
}
public void testValidOperation()
{
MBeanOperationInfo[] operations = info.getOperations();
MBeanOperationInfo foundOperation = null;
for (int i = 0; i < operations.length; i++)
{
if (operations[i].getName().equals(operationName))
{
if
(signatureString.equals(InfoUtil.makeSignatureString(operations[i].getSignature())))
{
foundOperation = operations[i];
break;
}
}
}
assertNotNull(failureHint + ": " + info.getClassName() + "." + operationName +
signatureString + " was not found", foundOperation);
assertEquals(failureHint + ": " + info.getClassName() + "." + operationName +
signatureString + " impact", impact, foundOperation.getImpact());
assertEquals(failureHint + ": " + info.getClassName() + "." + operationName +
signatureString + " returnType", returnType, foundOperation.getReturnType());
}
}
1.1
jbosstest/src/main/org/jboss/test/jbossmx/compliance/standard/SpuriousAttributeTEST.java
Index: SpuriousAttributeTEST.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.test.jbossmx.compliance.standard;
import junit.framework.TestCase;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanInfo;
/**
* @author <a href="mailto:[EMAIL PROTECTED]">Trevor Squires</a>.
*/
public class SpuriousAttributeTEST extends TestCase
{
private String failureHint;
private MBeanInfo info;
private String attributeName;
public SpuriousAttributeTEST(String failureHint, MBeanInfo info, String
attributeName)
{
super("testForSpuriousAttribute");
this.failureHint = failureHint;
this.info = info;
this.attributeName = attributeName;
}
public void testForSpuriousAttribute()
{
MBeanAttributeInfo[] attributes = info.getAttributes();
assertNull(failureHint + ": attribute " + info.getClassName() + ": " +
attributeName + " should not be present",
InfoUtil.findAttribute(attributes, attributeName));
}
}
1.1
jbosstest/src/main/org/jboss/test/jbossmx/compliance/standard/TrivialTestCase.java
Index: TrivialTestCase.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.test.jbossmx.compliance.standard;
import org.jboss.test.jbossmx.compliance.TestCase;
import org.jboss.test.jbossmx.compliance.standard.support.Trivial;
import javax.management.InstanceAlreadyExistsException;
import javax.management.InstanceNotFoundException;
import javax.management.IntrospectionException;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanConstructorInfo;
import javax.management.MBeanInfo;
import javax.management.MBeanNotificationInfo;
import javax.management.MBeanOperationInfo;
import javax.management.MBeanParameterInfo;
import javax.management.MBeanRegistrationException;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.MalformedObjectNameException;
import javax.management.NotCompliantMBeanException;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
import javax.management.ReflectionException;
/**
* @author <a href="mailto:[EMAIL PROTECTED]">Trevor Squires</a>.
*/
public class TrivialTestCase
extends TestCase
{
public TrivialTestCase(String s)
{
super(s);
}
public void testRegistration()
{
MBeanServer server = MBeanServerFactory.newMBeanServer();
Trivial trivial = new Trivial();
ObjectName name = null;
try
{
name = new ObjectName("trivial:key=val");
ObjectInstance instance = server.registerMBean(trivial, name);
}
catch (Exception e)
{
fail("registration failed: " + e.getMessage());
}
assertTrue("expected server to report it as registered",
server.isRegistered(name));
}
public void testConstructorInfo()
{
MBeanInfo info = getTrivialInfo();
MBeanConstructorInfo[] constructors = info.getConstructors();
assertEquals("constructor list length", 1, constructors.length);
// I really don't feel like reflecting to get the name of the constructor,
// it should just be the name of the class right?
assertEquals("constructor name", Trivial.class.getName(),
constructors[0].getName());
MBeanParameterInfo[] params = constructors[0].getSignature();
assertEquals("constructor signature length", 0, params.length);
}
public void testAttributeInfo()
{
MBeanInfo info = getTrivialInfo();
MBeanAttributeInfo[] attributes = info.getAttributes();
assertEquals("attribute list length", 1, attributes.length);
assertEquals("attribute name", "Something", attributes[0].getName());
assertEquals("attribute type", String.class.getName(),
attributes[0].getType());
assertEquals("attribute readable", true, attributes[0].isReadable());
assertEquals("attribute writable", true, attributes[0].isWritable());
assertEquals("attribute isIs", false, attributes[0].isIs());
}
public void testOperationInfo()
{
MBeanInfo info = getTrivialInfo();
MBeanOperationInfo[] operations = info.getOperations();
assertEquals("operations list length", 1, operations.length);
assertEquals("operation name", "doOperation", operations[0].getName());
assertEquals("operation return type", Void.TYPE.getName(),
operations[0].getReturnType());
assertEquals("operation impact", MBeanOperationInfo.UNKNOWN,
operations[0].getImpact());
MBeanParameterInfo[] params = operations[0].getSignature();
assertEquals("signature length", 1, params.length);
assertEquals("parameter type", String.class.getName(), params[0].getType());
}
public void testNotificationInfo()
{
MBeanInfo info = getTrivialInfo();
MBeanNotificationInfo[] notifications = info.getNotifications();
assertEquals("notification list length", 0, notifications.length);
}
private MBeanInfo getTrivialInfo()
{
MBeanInfo info = null;
try
{
MBeanServer server = MBeanServerFactory.newMBeanServer();
Trivial trivial = new Trivial();
ObjectName name = new ObjectName("trivial:key=val");
ObjectInstance instance = server.registerMBean(trivial, name);
info = server.getMBeanInfo(name);
}
catch (MalformedObjectNameException e)
{
fail("got spurious MalformedObjectNameException");
}
catch (InstanceAlreadyExistsException e)
{
fail("got spurious InstanceAlreadyExistsException");
}
catch (MBeanRegistrationException e)
{
fail("got spurious MBeanRegistrationException");
}
catch (NotCompliantMBeanException e)
{
fail("got spurious NotCompliantMBeanException");
}
catch (InstanceNotFoundException e)
{
fail("got spurious InstanceNotFoundException");
}
catch (IntrospectionException e)
{
fail("got spurious IntrospectionException");
}
catch (ReflectionException e)
{
fail("got spurious ReflectionException");
}
return info;
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development