FileDocCategorySizeDatePackage
ResourcesMBeanTest.javaAPI DocGlassfish v2 API8973Fri May 04 22:24:18 BST 2007com.sun.enterprise.admin.mbeans

ResourcesMBeanTest

public class ResourcesMBeanTest extends TestCase

Fields Summary
private JMXConnector
connector
private static final String
HOST
private static final String
PORT
private static final String
ADMIN_USER
private static final String
ADMIN_PASSWORD
private static final String
APPLICATION
Constructors Summary
public ResourcesMBeanTest(String name)

    
         
        super(name);
    
Methods Summary
public voidexecuteCreateResource(java.lang.String target, java.lang.String resourceName, java.util.Map options)

        try {
             final MBeanServerConnection server = getMBeanServer();
             String methodToInvoke = "createJdbcConnectionPool";
             Attribute attr1 = new Attribute("datasource_classname","com.pointbase.xa.xaDataSource");
             Attribute attr2 = new Attribute("name",resourceName);
             AttributeList list = new AttributeList();
             list.add(attr1);
             list.add(attr2);
             ObjectName objectName = 
                    new ObjectName(
                        "com.sun.appserv:type=resources,category=config");       
             printMBeanTestInfo(objectName);
             ObjectName result = (ObjectName)server.invoke(objectName,  
                methodToInvoke, new Object[]{list,new Properties(),target},
                new String[]{"javax.management.AttributeList", "java.util.Properties","java.lang.String"});
        } catch(Throwable e) {
            fail(e.getMessage());
        }
    
public voidexecuteDeleteResource(java.lang.String target, java.lang.String resourceName)

        try {
             final MBeanServerConnection server = getMBeanServer();
             String methodToInvoke = "deleteJdbcConnectionPool";
             ObjectName objectName = 
                    new ObjectName(
                        "com.sun.appserv:type=resources,category=config");       
             printMBeanTestInfo(objectName);
             ObjectName result = (ObjectName)server.invoke(objectName,  
                methodToInvoke, new Object[]{resourceName,target},
                new String[]{"java.lang.String","java.lang.String"});
        } catch(Throwable e) {
            System.out.println("Something failed in deleting the resource!");
            e.printStackTrace();
        }
    
public java.util.PropertiesgetDeploymentProperties()

        java.util.Properties props = new java.util.Properties();
        props.setProperty(DeploymentProperties.ARCHIVE_NAME, APPLICATION);
        props.setProperty(DeploymentProperties.VERIFY, "false");
        props.setProperty(DeploymentProperties.PRECOMPILE_JSP, "false");
        props.setProperty(DeploymentProperties.ENABLE, "true");
        props.setProperty(DeploymentProperties.FORCE, "true");
        return props;
    
private javax.management.MBeanServerConnectiongetMBeanServer()

        MBeanServerConnection conn = null;
        try {
            conn = connector.getMBeanServerConnection();
        } catch(Exception e) {
            System.out.println("Could not retrieve connection! " 
                + e.getMessage());
            e.printStackTrace();
        }
        return conn;
    
private javax.management.ObjectNamegetSampleObjectName()

        ObjectName name = null;
        try {
            name = 
                new ObjectName("com.sun.appserv:type=jdbc-connection-pool," + 
                    "name=__TimerPool,category=config");
        } catch(Exception e) {
            e.printStackTrace();
        }
        return name;
    
private voidinitConnector()

        try {
            connector = JMXConnectorFactory.connect(
                new JMXServiceURL("service:jmx:s1ashttp://" + HOST + 
                    ":" + PORT), initConnectorEnvironment());
        } catch (Exception ex) {
            System.out.println("Remote Connect Failed!!!");
            System.out.println(ex.getMessage());
            throw new RuntimeException(ex);
        }
    
private java.util.MapinitConnectorEnvironment()

        final java.util.Map env = new java.util.HashMap();
        final String PKGS = "com.sun.enterprise.admin.jmx.remote.protocol";
        env.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, PKGS);
        env.put(DefaultConfiguration.ADMIN_USER_ENV_PROPERTY_NAME, ADMIN_USER);
        env.put(DefaultConfiguration.ADMIN_PASSWORD_ENV_PROPERTY_NAME, ADMIN_PASSWORD);
        env.put(DefaultConfiguration.HTTP_AUTH_PROPERTY_NAME,
                DefaultConfiguration.DEFAULT_HTTP_AUTH_SCHEME);
        return (env);
    
public static voidmain(java.lang.String[] args)

        final TestRunner runner= new TestRunner();
        final TestResult result = runner.doRun(ResourcesMBeanTest.suite(), false);
        System.exit(result.errorCount() + result.failureCount());
    
private voidprintMBeanTestInfo(javax.management.ObjectName objectName)

        System.out.println("Testing mbean invocation on <" + objectName + ">");
    
protected voidsetUp()

        initConnector();
    
public static junit.framework.Testsuite()

        TestSuite suite = new TestSuite(ResourcesMBeanTest.class);
        return suite;
    
protected voidtearDown()

    
public voidtestCreateResource()

        System.out.println("..testCreateResource");
        executeCreateResource("null","dummy", new java.util.HashMap());
        executeCreateResource("","dummy1",new java.util.HashMap());
        executeCreateResource(null,"dummy2",new java.util.HashMap());
    
public voidtestDeleteResource()

        System.out.println("..testDeleteResource");
        executeDeleteResource("null","dummy");
        executeDeleteResource(null,"dummy1");
        executeDeleteResource("","dummy2");