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

ConfigsMBeanTest

public class ConfigsMBeanTest extends TestCase

Fields Summary
private com.sun.enterprise.config.ConfigContext
configContext
private ConfigsMBean
configsMBean
private static File
domainXml
private static File
mbeanDescriptor
private static com.sun.enterprise.admin.meta.MBeanRegistry
mbeanRegistry
Constructors Summary
public ConfigsMBeanTest(String name)

        super(name);
    
Methods Summary
booleanexists(java.lang.Object on, java.lang.Object[] names)

        for (int i = 0; i < names.length; i++)
        {
            if (names[i].equals(on))
            {
                return true;
            }
        }
        return false;
    
javax.management.ObjectNamegetAuditModule(java.lang.String name)

        return new ObjectName(
            getTestDomain() + 
            ":type=audit-module,category=config,config=" + getConfigRef() + 
            ",name=" + name);
    
javax.management.ObjectNamegetAuthRealm(java.lang.String name)

        return new ObjectName(
            getTestDomain() + 
            ":type=auth-realm,category=config,config=" + getConfigRef() + 
            ",name=" + name);
    
private voidgetChild(java.lang.String type, java.lang.String[] loc)

        try
        {
            ObjectName on = configsMBean.getChild(type, loc, getTargetName());
            Assert.assertEquals(getObjectName(type, loc), on);
        }
        catch (MBeanException mbe) {}
    
javax.management.ObjectNamegetConfigMBean()

        return new ObjectName(
            getTestDomain() + 
            ":type=config,category=config,name=" + getConfigRef());
    
private java.lang.StringgetConfigRef()

        Target target = TargetBuilder.INSTANCE.createTarget(
                            getTargetName(), configContext);
        return target.getConfigRef();
    
javax.management.ObjectNamegetEjbContainer()

        return new ObjectName(
            getTestDomain() + 
            ":type=ejb-container,category=config,config=" + getConfigRef());
    
javax.management.ObjectNamegetHttpListener()

        return new ObjectName(
            getTestDomain() + 
            ":type=http-listener,category=config,id=mylistener,config=" + 
            getConfigRef());
    
javax.management.ObjectNamegetHttpListener(java.lang.String listenerId)

        return new ObjectName(
            getTestDomain() + 
            ":type=http-listener,category=config,id=" + listenerId + 
            ",config=" + getConfigRef());
    
private javax.management.AttributeListgetHttpListenerAttrs()

        AttributeList attrList = new AttributeList();
        attrList.add(new Attribute("id", "mylistener"));
        attrList.add(new Attribute("address", "abcd"));
        attrList.add(new Attribute("port", "9999"));
        attrList.add(new Attribute("server-name", "server-name"));
        attrList.add(new Attribute("default-virtual-server", "server-name"));
        return attrList;
    
javax.management.ObjectNamegetHttpService()

        return new ObjectName(
            getTestDomain() + 
            ":type=http-service,category=config,config=" + getConfigRef());
    
javax.management.ObjectNamegetIiopListener()

        return new ObjectName(
            getTestDomain() + 
            ":type=iiop-listener,category=config,id=mylistener,config=" + 
            getConfigRef());
    
private javax.management.AttributeListgetIiopListenerAttrs()

        AttributeList attrList = new AttributeList();
        attrList.add(new Attribute("id", "mylistener"));
        attrList.add(new Attribute("address", "address"));
        return attrList;
    
javax.management.ObjectNamegetJaccProvider(java.lang.String name)

        return new ObjectName(
            getTestDomain() + 
            ":type=jacc-provider,category=config,config=" + getConfigRef() + 
            ",name=" + name);
    
javax.management.ObjectNamegetJmsHost(java.lang.String name)

        return new ObjectName(
            getTestDomain() + 
            ":type=jms-host,category=config,config=" + getConfigRef() + 
            ",name=" + name);
    
javax.management.ObjectNamegetObjectName(java.lang.String type, java.lang.String[] loc)

        if (null == loc) { loc = new String[0]; }
        String[] oTokens = new String[loc.length + 2];
        oTokens[0] = getTestDomain();
        oTokens[1] = getConfigRef();
        for (int i = 2; i < oTokens.length; i++)
        {
            oTokens[i] = loc[i-2];
        }
        return mbeanRegistry.getMbeanObjectName(type, oTokens);
    
javax.management.ObjectNamegetObjectName1(java.lang.String type, java.lang.String loc)

        return getObjectName(type, new String[] {loc});
    
javax.management.ObjectNamegetObjectName2(java.lang.String type, java.lang.String loc1, java.lang.String loc2)

        return getObjectName(type, new String[] {loc1, loc2});
    
javax.management.ObjectNamegetProfiler()

        return new ObjectName(
            getTestDomain() + 
            ":type=profiler,category=config,config=" + getConfigRef());
    
private java.util.PropertiesgetProperties()

        Properties props = new Properties();
        props.put("prop1", "val1");
        return props;
    
javax.management.ObjectNamegetSsl(java.lang.String type, java.lang.String id)

        String on = getTestDomain() + ":type=ssl,category=config,config=" + 
                    getConfigRef();
        on += "iiop-service".equals(type) ? "" : ("," + type + '=" + id);
        return new ObjectName(on);
    
private TargetgetTarget()

        return TargetBuilder.INSTANCE.createTarget(getTargetName(), 
                    configContext);
    
private java.lang.StringgetTargetName()

        return null;
    
private java.lang.StringgetTestDomain()

        return "testdomain";
    
javax.management.ObjectNamegetThreadPool(java.lang.String threadPoolId)

        return new ObjectName(
            getTestDomain() + 
            ":type=thread-pool,category=config,config=" + getConfigRef() + 
            ",thread-pool-id=" + threadPoolId);
    
javax.management.ObjectNamegetVirtualServer()

        return new ObjectName(
            getTestDomain() + 
            ":type=virtual-server,category=config,id=my-virtual-server,config="
            + getConfigRef());
    
private javax.management.AttributeListgetVirtualServerAttrs()

        AttributeList attrList = new AttributeList();
        attrList.add(new Attribute("id", "my-virtual-server"));
        attrList.add(new Attribute("hosts", "host1,host2"));
        return attrList;
    
private static voidloadMBeanRegistry()

        if (null == mbeanRegistry)
        {
            mbeanRegistry = MBeanRegistryFactory.getMBeanRegistry(
                                mbeanDescriptor.getAbsolutePath());
        }
    
public static voidmain(java.lang.String[] args)

        setDomainXml(new File(args[0]));
        setMBeanDescriptor(new File(args[1]));

        final TestRunner runner= new TestRunner();
        final TestResult result = runner.doRun(ConfigsMBeanTest.suite(), false);
        System.exit(result.errorCount() + result.failureCount());
    
public static voidsetDomainXml(java.io.File xml)

        domainXml = xml;
    
public static voidsetMBeanDescriptor(java.io.File f)

        mbeanDescriptor = f;
    
protected voidsetUp()

        configsMBean = new MyConfigsMBean();
        try
        {
            configContext = ConfigFactory.createConfigContext(
                                domainXml.getAbsolutePath());
            loadMBeanRegistry();
        }
        catch (Exception e)
        {
            throw new RuntimeException(e.getMessage());
        }
    
public static junit.framework.Testsuite()

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

        configsMBean = null;
        configContext = null;
        mbeanRegistry = null;
    
public voidtestAuditModule()

        AttributeList attrs = new AttributeList();
        attrs.add(new Attribute("name", "xaudit"));
        attrs.add(new Attribute("classname", "audit.xaudit"));

        ObjectName on = configsMBean.createAuditModule(
                            attrs, getProperties(), getTargetName());
        Assert.assertTrue(on != null);
        Assert.assertEquals(getAuditModule("xaudit"), on);

        ObjectName[] onames = configsMBean.listAuditModules(getTargetName());
        Assert.assertTrue(onames != null);
        Assert.assertTrue(onames.length > 0);
        Assert.assertTrue(exists(getAuditModule("xaudit"), onames));

        boolean isDeleted = configsMBean.deleteAuditModule(
                                "xaudit", getTargetName());
        Assert.assertTrue(isDeleted);
        onames = configsMBean.listAuditModules(getTargetName());
        Assert.assertTrue(!exists(getAuditModule("xaudit"), onames));
    
public voidtestAuthRealm()

        final String target = getTargetName();
        final String realm = "myAuth";
        final AttributeList al = new AttributeList();
        al.add(new Attribute("name", realm));
        al.add(new Attribute("classname", "myauth.Auth"));

        ObjectName on = configsMBean.createAuthRealm(al, null, target);
        Assert.assertTrue(on != null);
        Assert.assertEquals(getAuthRealm(realm), on);
        ObjectName[] authRealms = configsMBean.listAuthRealms(target);
        Assert.assertTrue(authRealms != null);
        Assert.assertTrue(exists(on, authRealms));
        boolean deleted = configsMBean.deleteAuthRealm(realm, target);
        Assert.assertTrue(deleted);
        authRealms = configsMBean.listAuthRealms(target);
        Assert.assertTrue(authRealms != null);
        Assert.assertTrue(!exists(on, authRealms));
    
public voidtestCreateConfigsMBean()

        ConfigsMBean mbean = new ConfigsMBean();
        Assert.assertTrue(mbean != null);
    
public voidtestEjbTimerService()

        ObjectName on = configsMBean.createEjbTimerService(
            null, getProperties(), getTargetName());
        Assert.assertTrue(on != null);
        on = configsMBean.getEjbTimerService(getTargetName());
        Assert.assertEquals(getObjectName("ejb-timer-service", null), on);
        boolean isDeleted = configsMBean.deleteEjbTimerService(getTargetName());
        Assert.assertTrue(isDeleted);
        try
        {
            configsMBean.getEjbTimerService(getTargetName());
            Assert.assertTrue(false);
        }
        catch (Exception e)
        {
            //ok
        }
    
public voidtestFileUser()

        final String    user    = "ramakant3";
        final String    pwd     = "ramakant";
        final String[]  grps    = {"grp1"};
        final String    realm   = "file";

        configsMBean.addUser(user, pwd, grps, realm, getTargetName());
        configsMBean.updateUser(user, pwd, grps, realm, getTargetName());
        String[] users = configsMBean.getUserNames(realm, getTargetName());
        Assert.assertTrue(users != null);
        Assert.assertTrue(exists(user, users));

        String[] groups = configsMBean.getGroupNames(user, realm, 
                            getTargetName());
        Assert.assertTrue(groups != null);
        Assert.assertTrue(exists(grps[0], groups));

        configsMBean.removeUser(user, realm, getTargetName());
        users = configsMBean.getUserNames(realm, getTargetName());
        Assert.assertFalse(exists(user, users));
        groups = configsMBean.getGroupNames(null, realm, getTargetName());
        Assert.assertFalse(exists(grps[0], groups));
    
public voidtestGetChild()

        getChild("http-listener", new String[] {"http-listener-1"});
        getChild("ejb-container", null);
        getChild("ssl", new String[] {"http-listener-1"});
        getChild("ssl#", null);
        getChild("ssl##", new String[]{"SSL"});

        try
        {
            ObjectName on = configsMBean.getChild(null, null, getTargetName());
            Assert.assertTrue(false);
        }
        catch (Exception e)
        {
            //ok
        }
    
public voidtestGetConfigMBean()

        ObjectName on = configsMBean.getConfigMBean(getTarget());
        Assert.assertEquals(getConfigMBean(), on);
    
public voidtestGetHttpServiceMBean()

        ObjectName on = configsMBean.getHttpServiceMBean(getTarget());
        Assert.assertEquals(getHttpService(), on);
    
public voidtestGetters()

        ObjectName on = configsMBean.getHttpService(getTargetName());
        Assert.assertEquals(getObjectName("http-service", null), on);

        on = configsMBean.getIiopService(getTargetName());
        Assert.assertEquals(getObjectName("iiop-service", null), on);

        on = configsMBean.getTransactionService(getTargetName());
        Assert.assertEquals(getObjectName("transaction-service", null), on);

        on = configsMBean.getMonitoringService(getTargetName());
        Assert.assertEquals(getObjectName("monitoring-service", null), on);

        on = configsMBean.getLogService(getTargetName());
        Assert.assertEquals(getObjectName("log-service", null), on);

        on = configsMBean.getSecurityService(getTargetName());
        Assert.assertEquals(getObjectName("security-service", null), on);

        on = configsMBean.getJmsService(getTargetName());
        Assert.assertEquals(getObjectName("jms-service", null), on);

        on = configsMBean.getEjbContainer(getTargetName());
        Assert.assertEquals(getObjectName("ejb-container", null), on);

        on = configsMBean.getWebContainer(getTargetName());
        Assert.assertEquals(getObjectName("web-container", null), on);

        on = configsMBean.getMdbContainer(getTargetName());
        Assert.assertEquals(getObjectName("mdb-container", null), on);

        on = configsMBean.getJavaConfig(getTargetName());
        Assert.assertEquals(getObjectName("java-config", null), on);

        on = configsMBean.getHttpListener("http-listener-1", getTargetName());
        Assert.assertEquals(
            getObjectName1("http-listener", "http-listener-1"), on);

        on = configsMBean.getVirtualServer("server", getTargetName());
        Assert.assertEquals(getObjectName1("virtual-server", "server"), on);

        on = configsMBean.getOrb(getTargetName());
        Assert.assertEquals(getObjectName("orb", null), on);

        on = configsMBean.getIiopListener("orb-listener-1", getTargetName());
        Assert.assertEquals(
            getObjectName1("iiop-listener", "orb-listener-1"), on);

        on = configsMBean.getJmsHost("default_JMS_host", getTargetName());
        Assert.assertEquals(getObjectName1("jms-host", "default_JMS_host"), on);

        on = configsMBean.getAuthRealm("file", getTargetName());
        Assert.assertEquals(getObjectName1("auth-realm", "file"), on);

        on = configsMBean.getAuditModule("default", getTargetName());
        Assert.assertEquals(getObjectName1("audit-module", "default"), on);

        on = configsMBean.getJaccProvider("default", getTargetName());
        Assert.assertEquals(getObjectName1("jacc-provider", "default"), on);

        on = configsMBean.getModuleLogLevels(getTargetName());
        Assert.assertEquals(getObjectName("module-log-levels", null), on);

        on = configsMBean.getModuleMonitoringLevels(getTargetName());
        Assert.assertEquals(getObjectName("module-monitoring-levels", null), on);

        on = configsMBean.getThreadPool("thread-pool-1", getTargetName());
        Assert.assertEquals(getObjectName1("thread-pool", "thread-pool-1"), on);
    
public voidtestHttpListener()

        final String target = getTargetName();
        ObjectName on = configsMBean.createHttpListener(
                                getHttpListenerAttrs(), null, target);
        Assert.assertTrue(on != null);
        Assert.assertEquals(getHttpListener(), on);
        ObjectName[] names = configsMBean.listHttpListeners(target);
        Assert.assertTrue(names != null);
        Assert.assertTrue(names.length > 0);
        Assert.assertTrue(exists(getHttpListener(), names));
        boolean isDeleted = configsMBean.deleteHttpListener("mylistener", null);
        Assert.assertTrue(isDeleted);
        names = configsMBean.listHttpListeners(target);
        Assert.assertFalse(exists(getHttpListener(), names));
    
public voidtestIiopListener()

        final String target = getTargetName();
        ObjectName on = configsMBean.createIiopListener(
                                getIiopListenerAttrs(), null, target);
        Assert.assertTrue(on != null);
        Assert.assertEquals(getIiopListener(), on);
        ObjectName[] names = configsMBean.listIiopListeners(target);
        Assert.assertTrue(names != null);
        Assert.assertTrue(names.length > 0);
        Assert.assertTrue(exists(getIiopListener(), names));
        boolean isDeleted = configsMBean.deleteIiopListener("mylistener", null);
        Assert.assertTrue(isDeleted);
        names = configsMBean.listIiopListeners(target);
        Assert.assertFalse(exists(getIiopListener(), names));
    
public voidtestJaccProvider()

        final AttributeList attrs = new AttributeList();
        attrs.add(new Attribute("name", "provider1"));
        attrs.add(new Attribute("policy-provider", "provider1"));
        attrs.add(new Attribute("policy-configuration-factory-provider", 
                    "providerfactory"));

        ObjectName on = configsMBean.createJaccProvider(
                            attrs, getProperties(), getTargetName());
        ObjectName[] onames = configsMBean.listJaccProviders(getTargetName());
        Assert.assertTrue(onames != null);
        Assert.assertTrue(onames.length > 0);
        Assert.assertTrue(exists(getJaccProvider("provider1"), onames));
        boolean isDeleted = configsMBean.deleteJaccProvider(
                                "provider1", getTargetName());
        Assert.assertTrue(isDeleted);
        onames = configsMBean.listJaccProviders(getTargetName());
        Assert.assertTrue(!exists(getJaccProvider("provider1"), onames));
    
public voidtestJmsHost()

        final AttributeList attrs = new AttributeList();
        attrs.add(new Attribute("name", "host1"));

        ObjectName on = configsMBean.createJmsHost(
                            attrs, getProperties(), getTargetName());
        Assert.assertTrue(on != null);
        Assert.assertEquals(getJmsHost("host1"), on);
        ObjectName[] onames = configsMBean.listJmsHosts(getTargetName());
        Assert.assertTrue(onames != null);
        Assert.assertTrue(onames.length > 0);
        Assert.assertTrue(exists(getJmsHost("host1"), onames));
        boolean isDeleted = configsMBean.deleteJmsHost("host1", getTargetName());
        Assert.assertTrue(isDeleted);
        onames = configsMBean.listJmsHosts(getTargetName());
        Assert.assertTrue(!exists(getJmsHost("host1"), onames));
    
public voidtestJvmOptions()

        String[] exOpts = configsMBean.getJvmOptions(false, getTargetName());
        Assert.assertTrue(exOpts != null);
        String[] jvmOpts = new String[] {"-Dn1=v1", "-Dn2=v2", "-Dn3=v3"};
        configsMBean.createJvmOptions(jvmOpts, false, getTargetName());
        configsMBean.deleteJvmOptions(jvmOpts, false, getTargetName());
    
public voidtestProfiler()

        final String name = "myprofiler";
        AttributeList al = new AttributeList();
        al.add(new Attribute("name", name));

        ObjectName on = configsMBean.createProfiler(
                                al, getProperties(), null);
        Assert.assertTrue(on != null);
        Assert.assertEquals(getProfiler(), on);
        on = configsMBean.getProfiler(getTargetName());
        Assert.assertEquals(getObjectName("profiler", null), on);
        boolean isDeleted = configsMBean.deleteProfiler(null);
        Assert.assertTrue(isDeleted);
    
public voidtestSSL()

        final String target = getTargetName();
        try
        {
            configsMBean.createHttpListener(getHttpListenerAttrs(), null, target);
            configsMBean.createIiopListener(getIiopListenerAttrs(), null, target);
            testSSL("http-listener");
            testSSL("iiop-listener");
            testSSL("iiop-service");
        }
        finally
        {
            configsMBean.deleteHttpListener("mylistener", target);
            configsMBean.deleteIiopListener("mylistener", target);
        }
    
voidtestSSL(java.lang.String type)

        ObjectName ssl = null;
        final String target = getTargetName();
        AttributeList al = new AttributeList();
        al.add(new Attribute("cert-nickname", "nick1"));
        ssl = configsMBean.createSsl(al, "mylistener", type, target);
        Assert.assertTrue(ssl != null);
        ObjectName on = configsMBean.getSsl(type, "mylistener", target);
        Assert.assertEquals(ssl, on);
        boolean isDeleted = configsMBean.deleteSsl(
                            "mylistener", type, target);
        Assert.assertTrue(isDeleted);
    
public voidtestSessionConfig()

        ObjectName  on          = null;
        boolean     isDeleted   = false;

        on = configsMBean.createSessionProperties(null, getProperties(), 
            getTargetName());
        Assert.assertEquals(getObjectName("session-properties", null), on);
        on = configsMBean.getSessionProperties(getTargetName());
        Assert.assertEquals(getObjectName("session-properties", null), on);
        isDeleted = configsMBean.deleteSessionProperties(getTargetName());
        Assert.assertTrue(isDeleted);

        on = configsMBean.createManagerProperties(null, null, getTargetName());
        Assert.assertEquals(getObjectName("manager-properties", null), on);
        on = configsMBean.getManagerProperties(getTargetName());
        Assert.assertEquals(getObjectName("manager-properties", null), on);
        isDeleted = configsMBean.deleteManagerProperties(getTargetName());
        Assert.assertTrue(isDeleted);

        on = configsMBean.createStoreProperties(null, null, getTargetName());
        Assert.assertEquals(getObjectName("store-properties", null), on);
        on = configsMBean.getStoreProperties(getTargetName());
        Assert.assertEquals(getObjectName("store-properties", null), on);
        isDeleted = configsMBean.deleteStoreProperties(getTargetName());
        Assert.assertTrue(isDeleted);

        isDeleted = configsMBean.deleteSessionConfig(getTargetName());
        Assert.assertTrue(isDeleted);
    
public voidtestThreadPool()

        final AttributeList attrs = new AttributeList();
        attrs.add(new Attribute("thread-pool-id", "testPool"));

        ObjectName on = configsMBean.createThreadPool(
                            attrs, null, getTargetName());
        ObjectName[] onames = configsMBean.listThreadPools(getTargetName());
        Assert.assertTrue(onames != null);
        Assert.assertTrue(onames.length > 0);
        Assert.assertTrue(exists(getThreadPool("testPool"), onames));
        boolean isDeleted = configsMBean.deleteThreadPool(
                                "testPool", getTargetName());
        Assert.assertTrue(isDeleted);
        onames = configsMBean.listThreadPools(getTargetName());
        Assert.assertTrue(!exists(getThreadPool("testPool"), onames));
    
public voidtestVirtualServer()

        final String target = getTargetName();
        ObjectName on = configsMBean.createVirtualServer(
                                getVirtualServerAttrs(), null, target);
        Assert.assertTrue(on != null);
        Assert.assertEquals(getVirtualServer(), on);
        ObjectName[] names = configsMBean.listVirtualServers(target);
        Assert.assertTrue(names != null);
        Assert.assertTrue(names.length > 0);
        Assert.assertTrue(exists(getVirtualServer(), names));
        boolean isDeleted = configsMBean.deleteVirtualServer(
            "my-virtual-server", null);
        Assert.assertTrue(isDeleted);
        names = configsMBean.listVirtualServers(target);
        Assert.assertFalse(exists(getVirtualServer(), names));