FileDocCategorySizeDatePackage
AdminTest.javaAPI DocGlassfish v2 API28309Fri May 04 22:25:34 BST 2007com.sun.enterprise.admin

AdminTest

public abstract class AdminTest extends Object

Fields Summary
Constructors Summary
Methods Summary
private static java.lang.ObjectgetConfigMbeanProperty(java.lang.String name, javax.management.DynamicMBean mbean)

        return mbean.invoke("getPropertyValue", new Object[]{name}, new String[]{"java.lang.String"});    
    
public static voidmain(java.lang.String[] args)

param
args the command line arguments

        int length = args.length;
/*        if (length < 2) {
            usage();
            System.exit(1);
        }
*/
     //******* call T E S T S *******
        runAdminMbeanTests();
//        runRuntimeMbeanTests();

    
    
private static voidprintAllAttributes(java.lang.String title, java.lang.String pref, javax.management.DynamicMBean mbean)

            printObj(title, pref, mbean.getAttributes(new String[]{""}));
    
private static voidprintAllProperties(java.lang.String title, java.lang.String pref, javax.management.DynamicMBean mbean)

        Object ret = mbean.invoke("getProperties", null, null);    
//            retObject = mbean.invoke("deployApplication", new Object[]{"testName", "testLocation", null, null, null}, new String[]{"java.lang.String", "java.lang.String", "java.lang.String", "java.lang.String", "java.lang.String"});
        printObj(title, pref, ret);
    
private static voidprintObj(java.lang.String title, java.lang.String pref, java.lang.Object obj)

            println(title);
            printObj(pref, obj);
    
private static voidprintObj(java.lang.String pref, java.lang.Object obj)

        if(pref==null)
            pref="";
        if(obj==null)
            println(pref+"null");
        if(obj instanceof Object[])
        {
            Object[] objs = (Object[])obj;
            if(objs.length==0)
                println(pref+"array.length = 0");
            for(int i=0; i<objs.length; i++)
            {
                printObj(pref+" ["+i+"] -> ", objs[i]);
            }
        }
        else if(obj instanceof ArrayList)
        {
            ArrayList objs = (ArrayList)obj;
            if(objs.size()==0)
                println(pref+"list.size() = 0");
            for(int i=0; i<objs.size(); i++)
            {
                printObj(pref/*+" ["+i+"] -> "*/, objs.get(i));
            }
        }
        else if(obj instanceof Attribute)
        {
            println(pref+ ((Attribute)obj).getName() + "=" + ((Attribute)obj).getValue());
        }
        else
        {
            println(pref  + obj);
        }
    
private static voidprintln(java.lang.String str)

        System.out.println(str);
    
static voidrunAdminMbeanTests()

        println("Start....!");
        try 
        { 
            MBeanRegistry registry  = MBeanRegistryFactory.getMBeanRegistry("dtds/admin-mbeans-descriptors.xml");
            ConfigContext configContext = ConfigFactory.createConfigContext("/home/kravtch/domain.xml");
//           MBeanRegistry registry  = MBeanRegistryFactory.getMBeanRegistry("k:\\export\\ias\\admin-core\\admin\\dtds\\admin-mbeans-descriptors2.xml");
//            ConfigContext configContext = ConfigFactory.createConfigContext("k:\\domain2.xml");
            Object retObject;
            
registry.generateAndRegisterAllDottedNames(configContext, "abc.def.xyz");
if(configContext!=null)
   return;
//***********************************************************************************************
//            title("REGISTRY");

            title("REGISTRY (in XPath value order)");
            registry.sortRegistryEntries(registry.SORT_BY_XPATH);

//            println(registry.toFormatString());
//            println(registry.toString());
            String[] location;
            BaseAdminMBean mbean;
            AttributeList attrs;

            //***********************************************************************************************
            title("ejb-container INSTANTIATION");
            location = new String[]{"testdomain", "server-config"};
            mbean = registry.instantiateMBean("ejb-container", location, null, configContext); 
            println(""+mbean.getAttribute("cache_resize_quantity"));

            //***********************************************************************************************
            title("ejb-container set steady_pool_size to 20");
            printAllAttributes("************BEFORE SET ******", "   ", mbean);
            
            mbean.setAttribute(new Attribute("steady_pool_size", (Object)"20"));
            printAllAttributes("\n************AFTER SET******", "   ", mbean);

            mbean.setAttribute(new Attribute("steady_pool_size", (Object)"2"));

            //***********************************************************************************************
            title("resources Instantiate()");
            location = new String[]{"testdomain"};
            mbean = registry.instantiateMBean("resources", location, null, configContext); 
            
            //***********************************************************************************************
            title("resources-> getJdbcResource()");
            retObject = mbean.invoke("getJdbcResource", null, null); //new Object[]{}, new String[]{});
            printObj("Returned object:", "      ", retObject);
                    
            //***********************************************************************************************
            title("jdbc-resource-> Instantiate(jdbc/PointBase)");
            mbean = registry.instantiateMBean("jdbc-resource", new String[]{"testdomain","jdbc/__TimerPool"}, null, configContext); 
            println("returned jdbc-resource[jdbc/PointBase] mbean:"+mbean);

            //***********************************************************************************************
            title("jdbc-resource[jdbc/PointBase]-> getAttributes()");
   
            //***********************************************************************************************
            title("resources Instantiate()");
            location = new String[]{"testdomain"};
            mbean = registry.instantiateMBean("resources", location, null, configContext); 
            
            //***********************************************************************************************
            title("resources-> getCustomResource()");
            retObject = mbean.invoke("getCustomResource", null, null); //new Object[]{}, new String[]{});
            printObj("Returned object:", "      ", retObject);

            //***********************************************************************************************
            title("resources-> createCustomResource(testJndiName2/testResType2/testFactoryClass2)");
            attrs = new AttributeList();
            attrs.add(new Attribute("jndi_name", "testJndiName2"));
            attrs.add(new Attribute("res_type", "testResType2"));
            attrs.add(new Attribute("factory_class", "testFactoryClass2"));
            printObj("Input Attributes:", "   ", attrs);
//          retObject = mbean.invoke("createCustomResource", new Object[]{attrs, null, null}, 
//                      new String[]{attrs.getClass().getName(),"java.util.Properties","java.lang.String"});                                
            retObject = mbean.invoke("createCustomResource", new Object[]{attrs}, new String[]{attrs.getClass().getName()});
            printObj("Returned object:", "      ", retObject);
            
            //***********************************************************************************************
            title("resources-> getCustomResourceByJndiName(testJndiName2)");
            retObject = mbean.invoke("getCustomResourceByJndiName", new Object[]{"testJndiName2"}, new String[]{"java.lang.String"});
            printObj("Returned object:", "      ", retObject);
            
            //***********************************************************************************************
            title("resources-> getCustomResource()");
            retObject = mbean.invoke("getCustomResource", null, null); //new Object[]{}, new String[]{});
            printObj("Returned object:", "      ", retObject);

            //***********************************************************************************************
            title("custom-resource-> Instantiate(testJndiName2)");
            mbean = registry.instantiateMBean("custom-resource", new String[]{"testdomain","testJndiName2"}, null, configContext); 
            printObj("returned custom-resource[testJndiName2] mbean:",mbean);
            
            //***********************************************************************************************
            title("custom-resource[testJndiName2]-> getAttributes()");
            printAllAttributes("Attributes:", "   ", mbean);

            //***********************************************************************************************
            title("custom-resource-> Instantiate(testJndiName2) using ObjectName");
            mbean = registry.instantiateConfigMBean(new ObjectName("testdomain:type=custom-resource,jndi-name=testJndiName2,category=config"), null, configContext); 
            printObj("returned custom-resource[testJndiName2] mbean:",mbean);
            
            //***********************************************************************************************
            title("custom-resource[testJndiName2]-> getAttributes()");
            printAllAttributes("Attributes:", "   ", mbean);
            //***********************************************************************************************
/*            title("custom-resource[testJndiName2]-> setProperty()");
            setConfigMbeanProperty("testPropName1", "testPropValue1", mbean);
            setConfigMbeanProperty("testPropName2", "testPropValue2", mbean);
            setConfigMbeanProperty("testPropName3", "testPropValue3", mbean);
            setConfigMbeanProperty("testPropName4", "testPropValue4", mbean);
            
            //***********************************************************************************************
            title("custom-resource[testJndiName2]-> getProperties()");
            printAllProperties("Properties:", "      ", mbean);
*/
            //***********************************************************************************************
//title("custom-resource[testJndiName2]-> destroyConfigElement()");
//retObject = mbean.invoke("destroyConfigElement", null, null);
//println("Returned object after delete:"+retObject);

            title("resources-> getCustomResource()");
            location = new String[]{"testdomain"};
            mbean = registry.instantiateMBean("resources", location, null, configContext); 
            retObject = mbean.invoke("getCustomResource", null, null); //new Object[]{}, new String[]{});
            printObj("Returned object:","  ",retObject);
            title("resources-> removeCustomResourceByJndiName(testJndiName2)");
            retObject = mbean.invoke("removeCustomResourceByJndiName", new Object[]{"testJndiName2"}, new String[]{"java.lang.String"});
            printObj("Returned object:", "      ", retObject);
            
            //***********************************************************************************************
            title("resources-> getCustomResource()");
            location = new String[]{"testdomain"};
            mbean = registry.instantiateMBean("resources", location, null, configContext); 
            retObject = mbean.invoke("getCustomResource", null, null); //new Object[]{}, new String[]{});
            printObj("Returned object:","  ",retObject);
            
            //***********************************************************************************************
            title("applications-> Instantantiate()");
            location = new String[]{"testdomain"};
            mbean = registry.instantiateMBean("applications", location, null, configContext); 
            
/*            //***********************************************************************************************
            title("applications-> deployApplication()");
            retObject = mbean.invoke("deployApplication", new Object[]{"testName", "testLocation", null, null, null}, new String[]{"java.lang.String", "java.lang.String", "java.lang.String", "java.lang.String", "java.lang.String"});
            printObj("Returned object:", "      ", retObject);

            //***********************************************************************************************
            title("j2ee-application-> getAttributes()");
            location = new String[]{"testdomain","testName"};
            mbean = registry.instantiateMBean("j2ee-application", location, null, configContext); 
            printAllAttributes("Attributes:", "   ", mbean);

            //***********************************************************************************************
            title("j2ee-application-> destroyConfigElement()");
            retObject = mbean.invoke("destroyConfigElement", null, null);
            printObj("Returned object:", "      ", retObject);
            configContext.flush();
*/            
            //***********************************************************************************************
            title("thread-pools Instantiate()");
            location = new String[]{"testdomain", "server-config"};
            mbean = registry.instantiateMBean("thread-pools", location, null, configContext); 
            printObj("Returned object:","  ",mbean);
            title("thread-pools-> createThreadPool");
            attrs = new AttributeList();
            attrs.add(new Attribute("thread_pool_id", "mytestThreadPool"));
            attrs.add(new Attribute("min_thread_pool_size", "100"));
            attrs.add(new Attribute("max_thread_pool_size", "200"));
            attrs.add(new Attribute("num_work_queues", "12"));
            attrs.add(new Attribute("idle_thread_timeout_in_seconds", "50"));
            printObj("Input Attributes:", "   ", attrs);
            retObject = mbean.invoke("createThreadPool", new Object[]{attrs}, new String[]{attrs.getClass().getName()});
            printObj("Returned object:", "      ", retObject);
            
            //***********************************************************************************************
            title("jdbc-connection-pool[PointBasePool] Instantiate()");
            location = new String[]{"testdomain", "PointBasePool"};
            mbean = registry.instantiateMBean("jdbc-connection-pool", location, null, configContext); 
            printObj("Returned object:","  ",mbean);
            //***********************************************************************************************
            title("jdbc-connection-pool[PointBasePool] PrintAllAttributes");
            printAllAttributes("Attributes:", "   ", mbean);
            //***********************************************************************************************
            title("jdbc-connection-pool[PointBasePool] PrintAllProperties");
            printAllProperties("Properties:", "   ", mbean);
            //***********************************************************************************************
            title("set properties: 'testPropName1' and 'testPropName2'");
            setConfigMbeanProperty("testPropName1", "testPropValue1", mbean);
            setConfigMbeanProperty("testPropName2", "testPropValue2", mbean);
            //***********************************************************************************************
            title("jdbc-connection-pool[PointBasePool] PrintAllProperties");
            printAllProperties("Properties:", "   ", mbean);
            //***********************************************************************************************
            title("remove properties: 'testPropName1' and 'testPropName2'");
            setConfigMbeanProperty("testPropName1", null, mbean);
            setConfigMbeanProperty("testPropName2", null, mbean);
            //***********************************************************************************************
            title("jdbc-connection-pool[PointBasePool] PrintAllProperties");
            printAllProperties("Properties:", "   ", mbean);
            //***********************************************************************************************
            title("jdbc-connection-pool.getDefaultAttributeValue[max-pool-size]");
            println("Value:"+mbean.getAttribute("max_pool_size"));
            retObject = mbean.invoke("getDefaultAttributeValue", new Object[]{"max_pool_size"}, new String[]{"java.lang.String"});
            println("Default:"+retObject);
            //***********************************************************************************************
            title("thread-pools Instantiate()");
            location = new String[]{"testdomain", "server-config"};
            mbean = registry.instantiateMBean("java-config", location, null, configContext); 
            printObj("Returned object:","  ",mbean);
            title("jvm-options - String[] attribute test");
            printObj("Value:", "   ", mbean.getAttribute("jvm_options"));
            title("jvm-options - String[] SETattribute test");
            mbean.setAttribute(new Attribute("jvm_options",new String[]{"abc","def","xyz"}));
            printObj("Value:", "   ", mbean.getAttribute("jvm_options"));
            //***********************************************************************************************
            title("auth-realm['file'] Instantiate()");
            location = new String[]{"testdomain", "server-config","file"};
            mbean = registry.instantiateMBean("auth-realm", location, null, configContext); 
            printObj("Returned object:","  ",mbean);
            title("auth-realm['file']-> getProperties()");
            printAllProperties("Properties:", "      ", mbean);
            title("auth-realm['file']-> AddUser()");
            
            String[] groups = new String[]{"testGroup1","testGroup2","testGroup3"};
            retObject = mbean.invoke("updateUser", new Object[]{"testUser", "testPassword", groups}, new String[]{"java.lang.String", "java.lang.String", groups.getClass().getName()});
            printObj("updateUser:Returned object:", "      ", retObject);
            retObject = mbean.invoke("getUserGroupNames", new Object[]{"testUser"}, new String[]{"java.lang.String"});
            printObj("getUserGroupNames:Returned object:", "      ", retObject);
            retObject = mbean.invoke("getGroupNames", new Object[]{}, new String[]{});
            printObj("getGroupNames:Returned object:", "      ", retObject);
            retObject = mbean.invoke("getUserNames", new Object[]{}, new String[]{});
            printObj("getUserNames:Returned object:", "      ", retObject);
            title("resources-> getCustomResource()");
            //***********************************************************************************************
            title("domain Instantiate()");
            location = new String[]{"testdomain"};
            mbean = registry.instantiateMBean("domain", location, null, configContext); 
            printObj("Returned object:","  ",retObject);
            title("domain-> removeResources");
            retObject = mbean.invoke("removeResources", null, null);
            printObj("Returned object:", "      ", retObject);
            
        }
        catch (MBeanException mbe)
        {
            //mbe.printStackTrace();
            Exception e = mbe.getTargetException();
            if(e instanceof InvocationTargetException)
            {
                InvocationTargetException ite = (InvocationTargetException)e;
                Throwable t = ite.getTargetException();
                println(t.getMessage());
                t.printStackTrace();
            }
            else
            {
                println(e.getMessage());
                e.printStackTrace();
            }
        }
        catch (Exception e)
        {
            if(e instanceof InvocationTargetException)
            {
                InvocationTargetException ite = (InvocationTargetException)e;
                Throwable t = ite.getTargetException();
                println(t.getMessage());
                t.printStackTrace();
            }
            else
            {
                println(e.getMessage());
                e.printStackTrace();
            }
        }
        catch (Throwable t)
        {
                println(t.getMessage());
                t.printStackTrace();
        }
        println("Bye....!");
    
static voidrunRuntimeMbeanTests()

        println("Start....!");
        try 
        {
            MBeanRegistry registry  = MBeanRegistryFactory.getMBeanRegistry("dtds/runtime-mbeans-descriptors.xml");
            ConfigContext configContext = ConfigFactory.createConfigContext("/home/kravtch/domain.xml");
            Object retObject;
            
            //***********************************************************************************************
            title("REGISTRY");
            println(registry.toString());
            String[] location;
            BaseAdminMBean mbean;
            AttributeList attrs;

        }
/*        catch (MBeanException mbe)
        {
            //mbe.printStackTrace();
            Exception e = mbe.getTargetException();
            if(e instanceof InvocationTargetException)
            {
                InvocationTargetException ite = (InvocationTargetException)e;
                Throwable t = ite.getTargetException();
                println(t.getMessage());
                t.printStackTrace();
            }
            else
            {
                println(e.getMessage());
                e.printStackTrace();
            }
        }
*/
        catch (Exception e)
        {
            if(e instanceof InvocationTargetException)
            {
                InvocationTargetException ite = (InvocationTargetException)e;
                Throwable t = ite.getTargetException();
                println(t.getMessage());
                t.printStackTrace();
            }
            else
            {
                println(e.getMessage());
                e.printStackTrace();
            }
        }
        catch (Throwable t)
        {
                println(t.getMessage());
                t.printStackTrace();
        }
        println("Bye....!");
    
private static voidsetConfigMbeanProperty(java.lang.String name, java.lang.Object value, javax.management.DynamicMBean mbean)

        Object ret = mbean.invoke("setProperty", new Object[]{new Attribute(name, value)}, new String[]{"javax.management.Attribute"});    
    
private static voidtitle(java.lang.String str)

        System.out.println("\n\n************* " + str + " *******************");