FileDocCategorySizeDatePackage
GeneratedMonitoringMBeanTest.javaAPI DocGlassfish v2 API6534Fri May 04 22:25:56 BST 2007com.sun.enterprise.admin.monitor.util

GeneratedMonitoringMBeanTest

public class GeneratedMonitoringMBeanTest extends TestCase
Unit Test for testing GeneratedMonitoringMBean that gets created through the process of transforming a JSR77 Stats object into a Dynamic MBean. The transformation is helped by the ManagedResourceIntrospector which has its own tests.
author
sg112326

Fields Summary
GeneratedMonitoringMBeanImpl
mbean
S1ASJVMStatsImplMock
jvm
MBeanInfo
m
MBeanAttributeInfo[]
attrs
Hashtable
attributes
Constructors Summary
public GeneratedMonitoringMBeanTest(String testName)
Creates a new instance of GeneratedMonitoringMBeanTest

        super(testName);
    
Methods Summary
public static voidmain(java.lang.String[] args)

        junit.textui.TestRunner.run(suite());
    
protected voidsetUp()

    
       
        mbean = new GeneratedMonitoringMBeanImpl();
        jvm = new S1ASJVMStatsImplMock();
        m = mbean.introspect(jvm);
        attrs = m.getAttributes();
        for(int i=0; i< attrs.length;i++){
            attributes.put(attrs[i].getName(),attrs[i].getName());
        }
    
public static junit.framework.Testsuite()

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

        
    
public voidtestAtrributes()

        Enumeration en = attributes.elements();
        while(en.hasMoreElements()){
            String attr = (String)en.nextElement();
            System.out.println("testing attribute:"+attr);
            try{ assertEquals("HeapSize", attr.substring(0,attr.indexOf("_")));
            }catch(Error ex){
                try{assertEquals("MaxMemory",attr.substring(0,attr.indexOf("_")));
                }catch(Error e){
                    try{assertEquals("UpTime",attr.substring(0,attr.indexOf("_")));
                    }catch(Error e1){
                        assertEquals("AvailableProcessors",attr.substring(0,attr.indexOf("_")));
                    }
                }
            }
        }
    
public voidtestCreation()

        assertNotNull(mbean);
        assertNotNull(m);
        assertNotNull(jvm);
        assertNotNull(attrs);        
    
public voidtestGetAttributeWithCorrectAttrName()

        try{
            Enumeration e = attributes.keys();
            while(e.hasMoreElements()){
                String elem = (String)e.nextElement();
                Object n = mbean.getAttribute(elem);
                try{
                    assertEquals(Long.class, n.getClass());
                }
                catch(Error ex){                    
                        ex.getLocalizedMessage();
                        assertEquals(String.class, n.getClass());
                }
            }
        }
        catch(Exception ex){
            assertEquals(NullPointerException.class, ex.getClass());
        }
    
public voidtestGetAttributeWithIncorrectAttrName()

        try{
            Enumeration e = attributes.keys();
            while(e.hasMoreElements()){
                String elem = (String)e.nextElement();
                Object n = mbean.getAttribute(elem+"o");
                try{
                    assertEquals(Long.class, n.getClass());
                }
                catch(Error ex){                    
                        ex.getLocalizedMessage();
                        assertEquals(String.class, n.getClass());
                }
            }
        }
        catch(Exception ex){
            assertEquals(AttributeNotFoundException.class, ex.getClass());
        }    
    
public voidtestGetAttributeWithNull()

        try{
            Enumeration e = attributes.keys();
            while(e.hasMoreElements()){
                Object n = mbean.getAttribute(null);
                try{
                    assertEquals(Long.class, n.getClass());
                }
                catch(Error ex){                    
                        ex.getLocalizedMessage();
                        assertEquals(String.class, n.getClass());
                }
            }
        }
        catch(Exception ex){
            assertEquals(NullPointerException.class, ex.getClass());
        }