User: ejort
Date: 02/02/01 19:16:23
Added: src/main/org/jboss/test/jbossmx/compliance/server
MBeanServerFactoryTestCase.java
MBeanServerTestCase.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/server/MBeanServerFactoryTestCase.java
Index: MBeanServerFactoryTestCase.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.test.jbossmx.compliance.server;
import org.jboss.test.jbossmx.compliance.TestCase;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import java.util.List;
public class MBeanServerFactoryTestCase
extends TestCase
{
public MBeanServerFactoryTestCase(String s)
{
super(s);
}
public void testFindNonCreated()
{
MBeanServer server = MBeanServerFactory.newMBeanServer();
List mbsList = MBeanServerFactory.findMBeanServer(null);
assertEquals(0, mbsList.size());
}
public void testCreateFindAndRelease()
{
MBeanServer server = null;
List mbsList = null;
try
{
server = MBeanServerFactory.createMBeanServer();
mbsList = MBeanServerFactory.findMBeanServer(null);
assertEquals(1, mbsList.size());
}
finally
{
if (null != server)
{
MBeanServerFactory.releaseMBeanServer(server);
}
}
mbsList = MBeanServerFactory.findMBeanServer(null);
assertEquals(0, mbsList.size());
}
public void testRemoveNonCreated()
{
try
{
MBeanServer server = MBeanServerFactory.newMBeanServer();
MBeanServerFactory.releaseMBeanServer(server);
fail("expected an IllegalArgumentException");
}
catch (IllegalArgumentException e)
{
}
catch (Exception e)
{
fail("expected an IllegalArgumentException but got: " + e.getMessage());
}
}
public void testDomainCreated()
{
String domain = "dOmAiN";
MBeanServer server = null;
try
{
server = MBeanServerFactory.createMBeanServer(domain);
assertEquals(domain, server.getDefaultDomain());
List mbsList = MBeanServerFactory.findMBeanServer(null);
assertEquals(server, mbsList.get(0));
assertTrue("expected server reference equality", mbsList.get(0) == server);
}
finally
{
if (null != server)
{
MBeanServerFactory.releaseMBeanServer(server);
}
}
}
public void testDomainNonCreated()
{
String domain = "dOmAiN";
MBeanServer server = MBeanServerFactory.newMBeanServer(domain);
assertEquals(domain, server.getDefaultDomain());
}
public void testFindByAgentID()
{
// FIXME THS - flesh this out
}
}
1.1
jbosstest/src/main/org/jboss/test/jbossmx/compliance/server/MBeanServerTestCase.java
Index: MBeanServerTestCase.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.test.jbossmx.compliance.server;
import org.jboss.test.jbossmx.compliance.TestCase;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.ObjectName;
import javax.management.Attribute;
import javax.management.InstanceNotFoundException;
import javax.management.AttributeNotFoundException;
import javax.management.MBeanException;
import javax.management.RuntimeMBeanException;
import javax.management.RuntimeErrorException;
import javax.management.InvalidAttributeValueException;
import org.jboss.test.jbossmx.compliance.server.support.Test;
import org.jboss.test.jbossmx.compliance.server.support.TestMBean;
import org.jboss.test.jbossmx.compliance.server.support.MyScreamingException;
import org.jboss.test.jbossmx.compliance.server.support.ExceptionOnTheRun;
import org.jboss.test.jbossmx.compliance.server.support.BabarError;
public class MBeanServerTestCase
extends TestCase
{
public MBeanServerTestCase(String s)
{
super(s);
}
public void testInvokeWithNonExistantMBean()
{
try
{
MBeanServer server = MBeanServerFactory.createMBeanServer();
server.invoke(new ObjectName(":mbean=doesnotexist"), "noMethod", null,
null);
// should not reach here
fail("InstanceNotFoundException was not thrown from an invoke operation on
a non-existant MBean.");
}
catch (InstanceNotFoundException e)
{
// should get here
}
catch (Throwable t)
{
t.printStackTrace();
fail("Unexpected error on server.invoke(NonExistantMBean): " +
t.toString());
}
}
public void testInvokeWithBusinessException()
{
try
{
MBeanServer server = MBeanServerFactory.createMBeanServer();
ObjectName name = new ObjectName("test:test=test");
server.registerMBean(new Test(), name);
server.invoke(name, "operationWithException", null, null);
// should not get here
fail("MBeanException was not thrown.");
}
catch (MBeanException e)
{
// this is expected
assertTrue(e.getTargetException() instanceof MyScreamingException);
}
catch (Throwable t)
{
fail("Unexpected error: " + t.toString());
}
}
public void testGetAttributeWithNonExistingAttribute()
{
try
{
MBeanServer server = MBeanServerFactory.createMBeanServer();
Object foo = server.getAttribute(new ObjectName(MBEAN_SERVER_DELEGATE),
"Foo");
// should not reach here
fail("AttributeNotFoundexception was not thrown when invoking
getAttribute() call on a non-existant attribute.");
}
catch (AttributeNotFoundException e)
{
// Expecting this.
}
catch (Throwable t)
{
fail("Unexpected error: " + t.toString());
}
}
public void testGetAttributeWithBusinessException()
{
try
{
MBeanServer server = MBeanServerFactory.createMBeanServer();
ObjectName name = new ObjectName("test:test=test");
server.registerMBean(new Test(), name);
Object foo = server.getAttribute(name, "ThisWillScream");
// should not reach here
fail("Did not throw the screaming exception");
}
catch (MBeanException e)
{
// this is expected
// FIXME THS - is this a valid test?
//assertTrue(e.getMessage().startsWith("Exception thrown by attribute"));
assertTrue(e.getTargetException() instanceof MyScreamingException);
}
catch (Throwable t)
{
fail("Unexpected error: " + t.toString());
}
}
public void testGetAttributeWithNonExistingMBean()
{
try
{
MBeanServer server = MBeanServerFactory.createMBeanServer();
ObjectName name = new ObjectName("test:name=DoesNotExist");
server.getAttribute(name, "Whatever");
// should not reach here
fail("InstanceNotFoundException was not thrown on a nonexistant MBean.");
}
catch (InstanceNotFoundException e)
{
// this is expected
}
catch (Throwable t)
{
fail("Unexpected error: " + t.toString());
}
}
public void testGetAttributeWithUncheckedException()
{
try
{
MBeanServer server = MBeanServerFactory.createMBeanServer();
ObjectName name = new ObjectName("test:test=test");
server.registerMBean(new Test(), name);
server.getAttribute(name, "ThrowUncheckedException");
// should not reach here
fail("RuntimeMBeanException was not thrown");
}
catch (RuntimeMBeanException e)
{
// this is expected
assertTrue(e.getTargetException() instanceof ExceptionOnTheRun);
}
catch (Throwable t)
{
fail("Unexpected err0r: " + t.toString());
}
}
public void testGetAttributeWithError()
{
try
{
MBeanServer server = MBeanServerFactory.createMBeanServer();
ObjectName name = new ObjectName("test:test=test");
server.registerMBean(new Test(), name);
server.getAttribute(name, "Error");
// should not reach here
fail("Error was not thrown");
}
catch (RuntimeErrorException e)
{
// this is expected
assertTrue(e.getTargetError() instanceof BabarError);
}
catch (Throwable t)
{
fail("Unexpected error: " + t.toString());
}
}
public void testSetAttributeWithNonExistingAttribute()
{
try
{
MBeanServer server = MBeanServerFactory.createMBeanServer();
server.setAttribute(new ObjectName(MBEAN_SERVER_DELEGATE), new
Attribute("Foo", "value"));
// should not reach here
fail("AttributeNotFoundexception was not thrown when invoking
getAttribute() call on a non-existant attribute.");
}
catch (AttributeNotFoundException e)
{
// Expecting this.
}
catch (Throwable t)
{
fail("Unexpected error: " + t.toString());
}
}
public void testSetAttributeWithBusinessException()
{
try
{
MBeanServer server = MBeanServerFactory.createMBeanServer();
ObjectName name = new ObjectName("test:test=test");
server.registerMBean(new Test(), name);
server.setAttribute(name, new Attribute("ThisWillScream", "value"));
// should not reach here
fail("Did not throw the screaming exception");
}
catch (MBeanException e)
{
// this is expected
// FIXME THS - commented the assertion below: is that really what's
required?
// assertTrue(e.getMessage().startsWith("Exception thrown by attribute"));
assertTrue(e.getTargetException() instanceof MyScreamingException);
}
catch (Throwable t)
{
fail("Unexpected error: " + t.toString());
}
}
public void testSetAttributeWithNonExistingMBean()
{
try
{
MBeanServer server = MBeanServerFactory.createMBeanServer();
ObjectName name = new ObjectName("test:name=DoesNotExist");
server.setAttribute(name, new Attribute("Whatever", "nothing"));
// should not reach here
fail("InstanceNotFoundException was not thrown on a nonexistant MBean.");
}
catch (InstanceNotFoundException e)
{
// this is expected
}
catch (Throwable t)
{
fail("Unexpected error: " + t.toString());
}
}
public void testSetAttributeWithUncheckedException()
{
try
{
MBeanServer server = MBeanServerFactory.createMBeanServer();
ObjectName name = new ObjectName("test:test=test");
server.registerMBean(new Test(), name);
server.setAttribute(name, new Attribute("ThrowUncheckedException",
"value"));
// should not reach here
fail("RuntimeMBeanException was not thrown");
}
catch (RuntimeMBeanException e)
{
// this is expected
assertTrue(e.getTargetException() instanceof ExceptionOnTheRun);
}
catch (Throwable t)
{
fail("Unexpected err0r: " + t.toString());
}
}
public void testSetAttributeWithError()
{
try
{
MBeanServer server = MBeanServerFactory.createMBeanServer();
ObjectName name = new ObjectName("test:test=test");
server.registerMBean(new Test(), name);
server.setAttribute(name, new Attribute("Error", "value"));
// should not reach here
fail("Error was not thrown");
}
catch (RuntimeErrorException e)
{
// this is expected
assertTrue(e.getTargetError() instanceof BabarError);
}
catch (Throwable t)
{
fail("Unexpected error: " + t.toString());
}
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development