1 23 package com.sun.enterprise.management.config; 24 25 import javax.management.ObjectName ; 26 27 import java.util.Collection ; 28 import java.util.Collections ; 29 import java.util.List ; 30 import java.util.Set ; 31 import java.util.HashSet ; 32 import java.util.Map ; 33 import java.util.HashMap ; 34 35 import java.io.IOException ; 36 37 import javax.management.*; 38 39 import com.sun.appserv.management.util.j2ee.J2EEUtil; 40 import com.sun.appserv.management.util.misc.CollectionUtil; 41 import com.sun.appserv.management.util.misc.ExceptionUtil; 42 import com.sun.appserv.management.util.misc.GSetUtil; 43 import com.sun.appserv.management.util.misc.StringUtil; 44 import com.sun.appserv.management.util.misc.TypeCast; 45 import com.sun.appserv.management.util.stringifier.ArrayStringifier; 46 import com.sun.appserv.management.util.jmx.JMXUtil; 47 48 import com.sun.appserv.management.base.Util; 49 50 import com.sun.enterprise.management.support.ComSunAppservTest; 51 52 56 public final class ComSunAppservConfigTest extends ComSunAppservTest 57 { 58 public 59 ComSunAppservConfigTest() 60 { 61 } 62 63 64 private boolean 65 checkConfig(final ObjectName objectName ) 66 throws Exception 67 { 68 boolean worksOK = true; 69 70 final MBeanServerConnection conn = getMBeanServerConnection(); 71 72 final MBeanInfo mbeanInfo = conn.getMBeanInfo( objectName ); 73 assert( mbeanInfo != null ); 74 final MBeanAttributeInfo[] attrInfos = mbeanInfo.getAttributes(); 75 for( final MBeanAttributeInfo attrInfo : attrInfos ) 76 { 77 try 78 { 79 final Object value = conn.getAttribute( objectName, attrInfo.getName() ); 80 } 81 catch( Exception e ) 82 { 83 final Throwable rootCause = ExceptionUtil.getRootCause( e ); 84 85 warning( "MBean " + StringUtil.quote( objectName ) + 86 " threw an exception trying to get Attribute " + 87 StringUtil.quote( attrInfo.getName() ) + ": " + rootCause ); 88 worksOK = false; 89 } 90 } 91 92 final String [] attrNames = JMXUtil.getAttributeNames( attrInfos ); 93 try 94 { 95 final AttributeList attrs = conn.getAttributes( objectName, attrNames ); 97 assert( attrs.size() == attrInfos.length ); 98 99 final Set <String > attrNamesSet = GSetUtil.newSet( attrNames ); 101 assert( attrNamesSet.size() == attrNames.length ); final List <Attribute> typed = TypeCast.asList( attrs ); 103 for( final Attribute attr : typed ) 104 { 105 assert( attrNamesSet.contains( attr.getName() ) ); 106 } 107 } 108 catch( Exception e ) 109 { 110 final Throwable rootCause = ExceptionUtil.getRootCause( e ); 111 112 warning( "MBean " + StringUtil.quote( objectName ) + 113 " threw an exception trying to get getAttributes(" + 114 ArrayStringifier.stringify( attrNames, ", " ) + "): " + rootCause ); 115 worksOK = false; 116 } 117 118 return( worksOK ); 119 } 120 121 private static final Set <String > COM_SUN_APPSERV_EXCLUDED_TYPES = 122 Collections.unmodifiableSet( GSetUtil.newSet( new String [] 123 { 124 "servers", 125 "applications", 126 "configs", 127 "resources", 128 "transactions-recovery", 129 "synchronization", 130 } )); 131 132 133 134 public void 135 testAllConfig() 136 throws Exception 137 { 138 final Map <String ,ObjectName > m = getAllComSunAppservConfig(); 139 140 final Collection <ObjectName > objectNames = m.values(); 141 final Set <ObjectName > defective = new HashSet <ObjectName >(); 142 int testedCount = 0; 143 for( final ObjectName objectName : objectNames ) 144 { 145 final String type = objectName.getKeyProperty( "type" ); 146 if ( COM_SUN_APPSERV_EXCLUDED_TYPES.contains( type ) ) 147 { 148 continue; 149 } 150 151 ++testedCount; 152 if ( ! checkConfig( objectName ) ) 153 { 154 defective.add( objectName ); 155 } 156 } 157 158 printVerbose( "ComSunAppservConfigTest.testAllConfig: checked " + 159 testedCount + " com.sun.appserv:category=config MBeans for basic functionality, " + 160 defective.size() + " failures." ); 161 162 if ( defective.size() != 0 ) 163 { 164 failure( "The following MBeans are defective:\n" + 165 CollectionUtil.toString( defective, "\n") ); 166 } 167 } 168 169 170 171 } 172 173 174 175 176 177 178 | Popular Tags |