From: Andreas S. <sch...@us...> - 2002-05-16 16:57:08
|
User: schaefera Date: 02/05/16 09:57:07 Modified: src/main/org/jboss/test/management/test JSR77SpecUnitTestCase.java Log: Renamed SARModule to ServiceModule because SAR is not official. Also added a new test which just go over the JSR-77 tree and retrieve all their attribute (checks the navigation and attribute retrieval. Revision Changes Path 1.13 +120 -3 jbosstest/src/main/org/jboss/test/management/test/JSR77SpecUnitTestCase.java Index: JSR77SpecUnitTestCase.java =================================================================== RCS file: /cvsroot/jboss/jbosstest/src/main/org/jboss/test/management/test/JSR77SpecUnitTestCase.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- JSR77SpecUnitTestCase.java 15 May 2002 01:54:06 -0000 1.12 +++ JSR77SpecUnitTestCase.java 16 May 2002 16:57:07 -0000 1.13 @@ -12,6 +12,11 @@ import java.util.Set; import javax.ejb.CreateException; import javax.ejb.Handle; +import javax.management.Attribute; +import javax.management.AttributeList; +import javax.management.JMException; +import javax.management.MBeanInfo; +import javax.management.MBeanAttributeInfo; import javax.management.Notification; import javax.management.NotificationListener; import javax.management.ObjectName; @@ -30,18 +35,22 @@ import org.jboss.test.JBossTestCase; import org.jboss.test.JBossTestSetup; +import org.jboss.management.j2ee.EJBModule; import org.jboss.management.j2ee.J2EEDomain; import org.jboss.management.j2ee.J2EEManagedObject; import org.jboss.management.j2ee.J2EEServer; import org.jboss.management.j2ee.JavaMailResource; import org.jboss.management.j2ee.JCAConnectionFactory; +import org.jboss.management.j2ee.ResourceAdapterModule; +import org.jboss.management.j2ee.ServiceModule; +import org.jboss.management.j2ee.WebModule; /** * Test of JSR-77 specification conformance using the ??ToDo * These test the basic JSR-77 handling and access. * * @author <a href="mailto:an...@jb...">Andreas Schaefer</a>. - * @version $Revision: 1.12 $ + * @version $Revision: 1.13 $ * * <p><b>Revisions:</b> * @@ -105,10 +114,10 @@ throws Exception { - getLog().debug("+++ testConnect"); + log.debug("+++ testConnect"); Management lManagement = getManagementEJB(); String lDomain = lManagement.getDefaultDomain(); - getLog().debug( "+++ testConnect, domain: " + lDomain ); + log.debug( "+++ testConnect, domain: " + lDomain ); lManagement.remove(); } @@ -296,6 +305,114 @@ } } // */ + + /** + * Test the Navigation through the current JSR-77 tree + **/ + public void testNavigation() + throws + Exception + { + Management lMEJB = null; + try { + // Get Management EJB and then the management domain + lMEJB = getManagementEJB(); + Set lNames = lMEJB.queryNames( + new ObjectName( + lMEJB.getDefaultDomain() + ":" + + J2EEManagedObject.TYPE + "=" + J2EEDomain.J2EE_TYPE + "," + + "*" + ), + null + ); + if( lNames.isEmpty() ) { + fail( "Could not found JSR-77 root object of type '" + J2EEDomain.J2EE_TYPE + "'" ); + } + if( lNames.size() > 1 ) { + fail( "Found more than one JSR-77 root objects of type '" + J2EEDomain.J2EE_TYPE + "'" ); + } + ObjectName lManagementDomain = (ObjectName) lNames.iterator().next(); + // Report the attributes and references + report( lMEJB, lManagementDomain ); + } + catch( Exception e ) { + log.debug( "failed", e ); + throw e; + } + catch( Error err ) { + log.debug( "failed", err ); + throw err; + } + finally { + if( lMEJB != null ) { + lMEJB.remove(); + } + } + } + + private void report( Management pMEJB, ObjectName pRoot ) + throws + JMException, + RemoteException + { + log.debug( "Report Object: " + pRoot ); + MBeanInfo lInfo = pMEJB.getMBeanInfo( pRoot ); + MBeanAttributeInfo[] lAttributes = lInfo.getAttributes(); + String[] lAttributeNames = new String[ lAttributes.length ]; + for( int i = 0; i < lAttributes.length; i++ ) { + log.debug( "Attribute: " + lAttributes[ i ].getName() + ", " + lAttributes[ i ].getType() ); + lAttributeNames[ i ] = lAttributes[ i ].getName(); + } + AttributeList lValues = pMEJB.getAttributes( pRoot, lAttributeNames ); + for( int i = 0; i < lAttributes.length; i++ ) { + Attribute lValue = (Attribute) lValues.get( i ); + if( lValue.getValue() == null ) { + log.debug( "Attribute: " + lValue.getName() + " is empty" ); + } else + if( ObjectName.class.getName().equals( lAttributes[ i ].getType() ) ) { + // Check if this attribute is not support to be followed + if( checkBlock( pRoot, lAttributes[ i ].getName() ) ) { + log.debug( "Blocked Attribute: " + lValue.getName() + " contains: " + lValue.getValue() ); + continue; + } + // Report this Object's attribute first + log.debug( "Attribute: " + lValue.getName() + ", value: " + lValue.getValue() + ", is reported" ); + report( pMEJB, (ObjectName) lValue.getValue() ); + } else + if( ObjectName[].class.getName().equals( lAttributes[ i ].getType() ) ) { + ObjectName[] lNames = (ObjectName[]) lValue.getValue(); + for( int j = 0; j < lNames.length; j++ ) { + report( pMEJB, lNames[ j ] ); + } + } else { + log.debug( "Attribute: " + lValue.getName() + " contains: " + lValue.getValue() ); + } + } + } + + /** + * @return True if the given attribute must be blocked to avoid + * an endless loop in the graph of JSR-77 object name + * references (like J2EEServer refences J2EEDeployedObjects + * and this references J2EEServer) + **/ + private boolean checkBlock( ObjectName pName, String pAttributeName ) { + String lType = (String) pName.getKeyPropertyList().get( J2EEManagedObject.TYPE ); + if( EJBModule.J2EE_TYPE.equals( lType ) || + WebModule.J2EE_TYPE.equals( lType ) || + ResourceAdapterModule.J2EE_TYPE.equals( lType ) || + ServiceModule.J2EE_TYPE.equals( lType ) + ) { + if( "Server".equals( pAttributeName ) ) { + // Block Attribute Server for any J2EE Deployed Objects + return true; + } + } + return ( + "Parent".equals( pAttributeName ) || + "ObjectName".equals( pAttributeName ) + ); + } // Z implementation ---------------------------------------------- |