1 23 package com.sun.enterprise.management.config; 24 25 import java.util.Set ; 26 import java.util.Map ; 27 import java.util.HashSet ; 28 import java.util.Iterator ; 29 30 import java.io.IOException ; 31 32 import javax.management.ObjectName ; 33 34 import com.sun.appserv.management.config.SystemPropertiesAccess; 35 import com.sun.appserv.management.base.AMX; 36 import com.sun.appserv.management.base.Util; 37 38 39 import com.sun.enterprise.management.AMXTestBase; 40 import com.sun.enterprise.management.Capabilities; 41 42 44 public final class SystemPropertiesAccessTest extends AMXTestBase 45 { 46 public 47 SystemPropertiesAccessTest( ) 48 { 49 } 50 51 private Set <ObjectName > 52 getAll() 53 throws Exception 54 { 55 final Set <ObjectName > objectNames = 56 getQueryMgr().queryInterfaceObjectNameSet( 57 SystemPropertiesAccess.class.getName(), null); 58 59 return( objectNames ); 60 } 61 62 63 private void 64 checkPropertiesGet( final SystemPropertiesAccess props ) 65 { 66 final Map <String ,String > all = props.getSystemProperties(); 67 68 final String [] propNames = props.getSystemPropertyNames(); 69 70 for( final String name : propNames ) 71 { 72 assert( props.existsSystemProperty( name ) ); 73 final String value = props.getSystemPropertyValue( name ); 74 } 75 } 76 77 private void 78 testPropertiesSetToSameValue( final SystemPropertiesAccess props ) 79 { 80 final String [] propNames = props.getSystemPropertyNames(); 81 82 for( int i = 0; i < propNames.length; ++i ) 85 { 86 final String propName = propNames[ i ]; 87 88 final String value = props.getSystemPropertyValue( propName ); 89 props.setSystemPropertyValue( propName, value ); 90 91 assert( props.getSystemPropertyValue( propName ).equals( value ) ); 92 } 93 } 94 95 private void 96 testCreateEmptySystemProperty( final SystemPropertiesAccess props ) 97 { 98 final String NAME = "test.empty"; 99 100 props.createSystemProperty( NAME, "" ); 101 assert( props.existsSystemProperty( NAME ) ); 102 props.removeSystemProperty( NAME ); 103 assert( ! props.existsSystemProperty( NAME ) ); 104 } 105 106 private void 107 testSystemPropertiesCreateRemove( final SystemPropertiesAccess props ) 108 { 109 final String [] propNames = props.getSystemPropertyNames(); 110 111 final int numToAdd = 1; 113 final long now = System.currentTimeMillis(); 114 for( int i = 0; i < numToAdd; ++i ) 115 { 116 final String testName = "__junittest_" + i + now; 117 118 if ( props.existsSystemProperty( testName ) ) 119 { 120 failure( "test property already exists: " + testName ); 121 } 122 123 props.createSystemProperty( testName, "value_" + i ); 124 assert( props.existsSystemProperty( testName ) ); 125 } 126 final int numProps = props.getSystemPropertyNames().length; 127 128 if ( numProps != numToAdd + propNames.length ) 129 { 130 failure( "expecting " + numProps + " have " + numToAdd + propNames.length ); 131 } 132 133 134 for( int i = 0; i < numToAdd; ++i ) 136 { 137 final String testName = "__junittest_" + i + now; 138 139 props.removeSystemProperty( testName ); 140 assert( ! props.existsSystemProperty( testName ) ); 141 } 142 143 assert( props.getSystemPropertyNames().length == propNames.length ); 144 145 } 146 147 public synchronized void 148 checkGetProperties( final ObjectName src ) 149 throws Exception 150 { 151 final AMX proxy = getProxy( src, AMX.class); 152 153 if ( ! (proxy instanceof SystemPropertiesAccess) ) 154 { 155 throw new IllegalArgumentException ( 156 "MBean does not implement SystemPropertiesAccess: " + quote( src ) ); 157 } 158 159 final SystemPropertiesAccess props = (SystemPropertiesAccess)proxy; 160 checkPropertiesGet( props ); 161 } 162 163 public void 164 checkSetPropertiesSetToSameValue( final ObjectName src ) 165 throws Exception 166 { 167 final SystemPropertiesAccess props = getProxy( src, SystemPropertiesAccess.class ); 168 169 testPropertiesSetToSameValue( props ); 170 } 171 172 173 public void 174 checkCreateRemove( final ObjectName src ) 175 throws Exception 176 { 177 final SystemPropertiesAccess props = 178 getProxy( src, SystemPropertiesAccess.class ); 179 180 testSystemPropertiesCreateRemove( props ); 181 } 182 183 public synchronized void 184 testPropertiesGet() 185 throws Exception 186 { 187 final Set <ObjectName > all = getAll(); 188 189 testAll( all, "checkGetProperties" ); 190 } 191 192 public synchronized void 193 testPropertiesSetToSameValue() 194 throws Exception 195 { 196 final Set <ObjectName > all = getAll(); 197 198 testAll( all, "checkSetPropertiesSetToSameValue" ); 199 } 200 201 202 public synchronized void 203 testCreateRemove() 204 throws Exception 205 { 206 if ( checkNotOffline( "testCreateRemove" ) ) 207 { 208 final Set <ObjectName > all = getAll(); 209 testAll( all, "checkCreateRemove" ); 210 } 211 } 212 213 } 214 215 216 | Popular Tags |