1 23 package com.sun.enterprise.management.config; 24 25 import java.util.Set ; 26 import java.util.HashSet ; 27 28 import javax.management.ObjectName ; 29 30 import com.sun.appserv.management.config.PropertiesAccess; 31 import com.sun.appserv.management.base.AMX; 32 import com.sun.appserv.management.base.Util; 33 import com.sun.appserv.management.base.XTypes; 34 35 import com.sun.appserv.management.config.ResourceConfig; 36 37 import com.sun.appserv.management.util.misc.GSetUtil; 38 39 40 import com.sun.enterprise.management.AMXTestBase; 41 import com.sun.enterprise.management.Capabilities; 42 import com.sun.enterprise.management.TestUtil; 43 44 46 public final class PropertiesAccessTest extends AMXTestBase 47 { 48 public 49 PropertiesAccessTest( ) 50 { 51 } 52 53 private Set <ObjectName > 54 getAllImplementorsOfProperties() 55 throws Exception 56 { 57 final Set <AMX> amxs = getQueryMgr().queryInterfaceSet( 58 PropertiesAccess.class.getName(), null); 59 60 return( TestUtil.newSortedSet( Util.toObjectNames( amxs ) ) ); 61 62 } 63 64 65 private void 66 testCreateEmptyProperty( final PropertiesAccess props ) 67 { 68 final String NAME = "test.empty"; 69 70 props.createProperty( NAME, "" ); 71 assert( props.existsProperty( NAME ) ); 72 props.removeProperty( NAME ); 73 assert( ! props.existsProperty( NAME ) ); 74 } 75 76 private void 77 testPropertiesGet( final PropertiesAccess props ) 78 { 79 final String [] propNames = props.getPropertyNames(); 80 81 for( final String name : propNames ) 82 { 83 assert( props.existsProperty( name ) ); 84 final String value = props.getPropertyValue( name ); 85 } 86 } 87 88 private void 89 testPropertiesSetToSameValue( final PropertiesAccess props ) 90 { 91 final String [] propNames = props.getPropertyNames(); 92 93 for( int i = 0; i < propNames.length; ++i ) 96 { 97 final String propName = propNames[ i ]; 98 99 assert( props.existsProperty( propName ) ); 100 final String value = props.getPropertyValue( propName ); 101 props.setPropertyValue( propName, value ); 102 103 assert( props.getPropertyValue( propName ).equals( value ) ); 104 } 105 } 106 107 112 private static final Set <String > TEST_CREATE_REMOVE_TYPES = 113 GSetUtil.newUnmodifiableStringSet( 114 XTypes.DOMAIN_CONFIG, 115 XTypes.CONFIG_CONFIG, 116 XTypes.PROFILER_CONFIG, 117 XTypes.STANDALONE_SERVER_CONFIG, 118 XTypes.CLUSTERED_SERVER_CONFIG, 119 XTypes.ORB_CONFIG, 120 XTypes.MODULE_MONITORING_LEVELS_CONFIG, 121 XTypes.NODE_AGENT_CONFIG 122 ); 123 124 private void 125 testPropertiesCreateRemove( final PropertiesAccess props ) 126 { 127 final String [] propNames = props.getPropertyNames(); 128 129 final AMX amx = Util.asAMX( props ); 130 final String j2eeType = amx.getJ2EEType(); 131 if ( ! TEST_CREATE_REMOVE_TYPES.contains( j2eeType ) ) 132 { 133 return; 134 } 135 136 final int numToAdd = 1; 138 final long now = System.currentTimeMillis(); 139 for( int i = 0; i < numToAdd; ++i ) 140 { 141 final String testName = "__junittest_" + i + now; 142 143 if ( props.existsProperty( testName ) ) 144 { 145 failure( "test property already exists: " + testName ); 146 } 147 148 props.createProperty( testName, "value_" + i ); 149 assert( props.existsProperty( testName ) ); 150 } 151 final int numProps = props.getPropertyNames().length; 152 153 if ( numProps != numToAdd + propNames.length ) 154 { 155 failure( "expecting " + numProps + " have " + numToAdd + propNames.length ); 156 } 157 158 159 for( int i = 0; i < numToAdd; ++i ) 161 { 162 final String testName = "__junittest_" + i + now; 163 164 props.removeProperty( testName ); 165 assert( ! props.existsProperty( testName ) ); 166 } 167 168 assert( props.getPropertyNames().length == propNames.length ); 169 } 170 171 public void 172 checkGetProperties( final ObjectName src ) 173 throws Exception 174 { 175 final AMX proxy = getProxy( src ); 176 177 if ( ! (proxy instanceof PropertiesAccess) ) 178 { 179 throw new IllegalArgumentException ( 180 "MBean does not implement PropertiesAccess: " + quote( src ) ); 181 } 182 183 final PropertiesAccess props = (PropertiesAccess)proxy; 184 testPropertiesGet( props ); 185 } 186 187 public void 188 checkSetPropertiesSetToSameValue( final ObjectName src ) 189 throws Exception 190 { 191 final PropertiesAccess props = (PropertiesAccess)getProxy( src ); 192 193 testPropertiesSetToSameValue( props ); 194 } 195 196 197 public void 198 checkCreateRemove( final ObjectName src ) 199 throws Exception 200 { 201 final PropertiesAccess props = (PropertiesAccess)getProxy( src ); 202 203 testPropertiesCreateRemove( props ); 204 } 205 206 public synchronized void 207 testPropertiesGet() 208 throws Exception 209 { 210 final Set <ObjectName > all = getAllImplementorsOfProperties(); 211 212 testAll( all, "checkGetProperties" ); 213 } 214 215 public synchronized void 216 testPropertiesSetToSameValue() 217 throws Exception 218 { 219 final Set <ObjectName > all = getAllImplementorsOfProperties(); 220 221 testAll( all, "checkSetPropertiesSetToSameValue" ); 222 } 223 224 225 public synchronized void 226 testPropertiesCreateRemove() 227 throws Exception 228 { 229 if ( checkNotOffline( "testPropertiesCreateRemove" ) ) 230 { 231 final Set <ObjectName > all = getAllImplementorsOfProperties(); 232 233 testAll( all, "checkCreateRemove" ); 234 } 235 } 236 237 } 238 239 240 | Popular Tags |