User: squirest
Date: 02/01/17 17:12:23
Modified: src/main/test/compliance/standard StandardSUITE.java
TrivialTEST.java
Added: src/main/test/compliance/standard AttributeInfoTEST.java
ConstructorInfoTEST.java InfoTortureSUITE.java
InfoTortureTEST.java OperationInfoTEST.java
SpuriousAttributeTEST.java
Log:
testsuite updates, mostly related to standard MBeanInfo
Revision Changes Path
1.2 +5 -1 jmx/src/main/test/compliance/standard/StandardSUITE.java
Index: StandardSUITE.java
===================================================================
RCS file: /cvsroot/jboss/jmx/src/main/test/compliance/standard/StandardSUITE.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- StandardSUITE.java 2001/12/20 01:50:59 1.1
+++ StandardSUITE.java 2002/01/18 01:12:22 1.2
@@ -10,6 +10,10 @@
import junit.framework.Test;
import junit.framework.TestSuite;
+/**
+ * @author <a href="mailto:[EMAIL PROTECTED]">Trevor Squires</a>.
+ */
+
public class StandardSUITE extends TestSuite
{
public static void main(String[] args)
@@ -22,8 +26,8 @@
TestSuite suite = new TestSuite("StandardMBean Tests");
suite.addTest(new TestSuite(TrivialTEST.class));
+ suite.addTest(InfoTortureSUITE.suite());
return suite;
}
-
}
1.2 +114 -10 jmx/src/main/test/compliance/standard/TrivialTEST.java
Index: TrivialTEST.java
===================================================================
RCS file: /cvsroot/jboss/jmx/src/main/test/compliance/standard/TrivialTEST.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TrivialTEST.java 2001/12/20 01:50:59 1.1
+++ TrivialTEST.java 2002/01/18 01:12:22 1.2
@@ -10,11 +10,28 @@
import junit.framework.TestCase;
import test.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 TrivialTEST extends TestCase
{
public TrivialTEST(String s)
@@ -39,14 +56,101 @@
}
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");
+ }
-// public void testAvailableInfo()
-// {
-// MBeanServer server = MBeanServerFactory.newMBeanServer();
-// Trivial trivial = new Trivial();
-//
-// ObjectName name = new ObjectName("trivial:key=val");
-// ObjectInstance instance = server.registerMBean(trivial, name);
-// MBeanInfo info = server.getMBeanInfo(name);
-// }
-}
\ No newline at end of file
+ return info;
+ }
+}
1.1 jmx/src/main/test/compliance/standard/AttributeInfoTEST.java
Index: AttributeInfoTEST.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package test.compliance.standard;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanInfo;
/**
* @author <a href="mailto:[EMAIL PROTECTED]">Trevor Squires</a>.
*/
public class AttributeInfoTEST extends InfoTortureTEST
{
private MBeanInfo info;
private String attributeName;
private String type;
private boolean read;
private boolean write;
private boolean is;
public AttributeInfoTEST(MBeanInfo info, String attributeName, String type,
boolean read, boolean write, boolean is)
{
super("testValidAttribute");
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 = findAttribute(attributes, attributeName);
assertNotNull("findAttribute() for " + attributeName, attribute);
assertEquals(attributeName + " type", type, attribute.getType());
assertEquals(attributeName + " readable", read, attribute.isReadable());
assertEquals(attributeName + " writable", write, attribute.isWritable());
assertEquals(attributeName + " isIS", is, attribute.isIs());
}
}
1.1 jmx/src/main/test/compliance/standard/ConstructorInfoTEST.java
Index: ConstructorInfoTEST.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package test.compliance.standard;
import javax.management.MBeanConstructorInfo;
import javax.management.MBeanInfo;
/**
* @author <a href="mailto:[EMAIL PROTECTED]">Trevor Squires</a>.
*/
public class ConstructorInfoTEST extends InfoTortureTEST
{
private MBeanInfo info;
private String constructorName;
private String signatureString;
public ConstructorInfoTEST(MBeanInfo info, String constructorName, String[]
signature)
{
super("testValidConstructor");
this.info = info;
this.constructorName = constructorName;
this.signatureString = makeSignatureString(signature);
}
public void testValidConstructor()
{
MBeanConstructorInfo[] constructors = info.getConstructors();
MBeanConstructorInfo foundConstructor= null;
for (int i = 0; i < constructors.length; i++)
{
if
(signatureString.equals(makeSignatureString(constructors[i].getSignature())))
{
foundConstructor = constructors[i];
break;
}
}
assertNotNull(constructorName + signatureString, foundConstructor);
}
}
1.1 jmx/src/main/test/compliance/standard/InfoTortureSUITE.java
Index: InfoTortureSUITE.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package test.compliance.standard;
import junit.framework.Assert;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import test.compliance.standard.support.Torture;
import javax.management.InstanceAlreadyExistsException;
import javax.management.InstanceNotFoundException;
import javax.management.IntrospectionException;
import javax.management.MBeanInfo;
import javax.management.MBeanOperationInfo;
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;
/**
* Beat the heck out of the server's standard MBeanInfo
*
* @author <a href="mailto:[EMAIL PROTECTED]">Trevor Squires</a>.
*/
public class InfoTortureSUITE extends TestSuite
{
private static int attributeTestCount = 0;
private static int operationTestCount = 0;
private static int constructorTestCount = 0;
public static void main(String[] args)
{
junit.textui.TestRunner.run(suite());
}
public static Test suite()
{
TestSuite testSuite = new TestSuite("All MBeanInfo Torture Tests for Standard
MBeans");
MBeanInfo info = getTortureInfo();
// 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("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("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("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(info, name, signature));
constructorTestCount++;
}
public static void addSpuriousAttributeTest(TestSuite testSuite, MBeanInfo info,
String name)
{
testSuite.addTest(new SpuriousAttributeTEST(info, name));
}
public static void addAttributeTest(TestSuite testSuite, MBeanInfo info, String
name, String type, boolean read, boolean write, boolean is)
{
testSuite.addTest(new AttributeInfoTEST(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(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);
}
}
private static MBeanInfo getTortureInfo()
{
MBeanInfo info = null;
try
{
MBeanServer server = MBeanServerFactory.newMBeanServer();
Torture trivial = new Torture();
ObjectName name = new ObjectName("trivial:key=val");
ObjectInstance instance = server.registerMBean(trivial, name);
info = server.getMBeanInfo(name);
}
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;
}
}
1.1 jmx/src/main/test/compliance/standard/InfoTortureTEST.java
Index: InfoTortureTEST.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package test.compliance.standard;
import junit.framework.TestCase;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanConstructorInfo;
import javax.management.MBeanOperationInfo;
import javax.management.MBeanParameterInfo;
/**
* @author <a href="mailto:[EMAIL PROTECTED]">Trevor Squires</a>.
*/
public abstract class InfoTortureTEST extends TestCase
{
public InfoTortureTEST(String s)
{
super(s);
}
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 jmx/src/main/test/compliance/standard/OperationInfoTEST.java
Index: OperationInfoTEST.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package test.compliance.standard;
import javax.management.MBeanInfo;
import javax.management.MBeanOperationInfo;
/**
* @author <a href="mailto:[EMAIL PROTECTED]">Trevor Squires</a>.
*/
public class OperationInfoTEST extends InfoTortureTEST
{
private MBeanInfo info;
private String operationName;
private int impact;
private String returnType;
private String signatureString;
public OperationInfoTEST(MBeanInfo info, String operationName, int impact, String
returnType, String[] signature)
{
super("testValidOperation");
this.info = info;
this.operationName = operationName;
this.impact = impact;
this.returnType = returnType;
this.signatureString = 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(makeSignatureString(operations[i].getSignature())))
{
foundOperation = operations[i];
break;
}
}
}
assertNotNull(operationName + signatureString, foundOperation);
assertEquals(operationName + signatureString + " impact", impact,
foundOperation.getImpact());
assertEquals(operationName + signatureString + " returnType", returnType,
foundOperation.getReturnType());
}
}
1.1 jmx/src/main/test/compliance/standard/SpuriousAttributeTEST.java
Index: SpuriousAttributeTEST.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package test.compliance.standard;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanInfo;
/**
* @author <a href="mailto:[EMAIL PROTECTED]">Trevor Squires</a>.
*/
public class SpuriousAttributeTEST extends InfoTortureTEST
{
private MBeanInfo info;
private String attributeName;
public SpuriousAttributeTEST(MBeanInfo info, String attributeName)
{
super("testForSpuriousAttribute");
this.info = info;
this.attributeName = attributeName;
}
public void testForSpuriousAttribute()
{
MBeanAttributeInfo[] attributes = info.getAttributes();
assertNull("attribute " + attributeName, findAttribute(attributes,
attributeName));
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development