1 23 package com.sun.enterprise.management.deploy; 24 25 import java.util.Map ; 26 import java.util.HashMap ; 27 import java.util.List ; 28 import java.util.ArrayList ; 29 import java.util.Iterator ; 30 31 import java.io.Serializable ; 32 33 import com.sun.appserv.management.deploy.DeploymentStatus; 34 35 import com.sun.appserv.management.deploy.DeploymentStatusImpl; 36 37 38 import com.sun.enterprise.management.AMXTestBase; 39 import com.sun.enterprise.management.Capabilities; 40 import com.sun.appserv.management.util.misc.IteratorUtil; 41 42 44 public final class DeploymentStatusTest extends junit.framework.TestCase 45 { 46 public 47 DeploymentStatusTest( ) 48 { 49 } 50 51 52 53 private DeploymentStatusImpl 54 createDeploymentStatus( final Object deployID ) 55 { 56 final DeploymentStatusImpl ds = 57 new DeploymentStatusImpl( 58 0, 59 "success", 60 "description", 61 null ); 62 63 final Throwable t = new Exception ( "test", new Throwable ( "test2" ) ); 64 65 ds.setStageThrowable( t ); 66 assert( ds.getStageThrowable() == t ); 67 68 return( ds ); 69 } 70 71 public void 72 testCreateDeploymentStatus() 73 { 74 createDeploymentStatus( "dummy" ); 75 } 76 77 80 private static final class DeploymentStatusFoo 81 implements DeploymentStatus, Serializable 82 { 83 public static final long serialVersionUID = 983629292; 84 85 final ArrayList <DeploymentStatus> mSubStages; 86 final Map <String ,Serializable > mMap; 87 final Exception mException; 88 DeploymentStatus mParent; 89 90 public 91 DeploymentStatusFoo() 92 { 93 mSubStages = new ArrayList <DeploymentStatus>(); 94 mException = new Exception (); 95 mParent = null; 96 97 mMap = new HashMap <String ,Serializable >(); 98 putField( STAGE_STATUS_KEY, new Integer ( 0 ) ); 99 putField( STAGE_STATUS_MESSAGE_KEY, "status message" ); 100 putField( STAGE_DESCRIPTION_KEY, "description" ); 102 } 103 public void 104 addSubStage( DeploymentStatus subStage ) 105 { 106 mSubStages.add( subStage ); 107 subStage.setParent( this ); 108 } 109 110 public String 111 getMapClassName() 112 { 113 return( DEPLOYMENT_STATUS_CLASS_NAME ); 114 } 115 116 public Map <String ,Serializable > 117 asMap() 118 { 119 final Map <String ,Serializable > m = new HashMap <String ,Serializable >(); 120 121 m.putAll( mMap ); 122 123 if ( mSubStages.size() != 0 ) 124 { 125 final DeploymentStatus[] s = new DeploymentStatus[ mSubStages.size() ]; 126 mSubStages.toArray( s ); 127 m.put( SUB_STAGES_KEY, s ); 128 } 129 130 m.put( MAP_CAPABLE_CLASS_NAME_KEY, getMapClassName() ); 131 132 return( m ); 133 } 134 135 public void 136 putField( final String key, final Serializable value ) 137 { 138 mMap.put( key, value ); 139 } 140 141 public Iterator <Map <String ,Serializable >> 142 getSubStages() 143 { 144 if ( mSubStages.size() == 0 ) 145 { 146 return( null ); 147 } 148 149 final List <Map <String ,Serializable >> maps = new ArrayList <Map <String ,Serializable >>(); 150 for( final DeploymentStatus ds : mSubStages ) 151 { 152 maps.add( ds.asMap() ); 153 } 154 155 return( maps.iterator() ); 156 } 157 158 public List <DeploymentStatus> 159 getSubStagesList() 160 { 161 return( mSubStages ); 162 } 163 164 public int getStageStatus() { return( getStatusCode() ); } 165 public String getStageStatusMessage() { return( "status message" ); } 166 167 public Throwable getThrowable() { return( mException ); } 168 public Throwable getStageThrowable() { return( getThrowable() ); } 169 public int getStatusCode() 170 { return( getStageThrowable() == null ? STATUS_CODE_SUCCESS : STATUS_CODE_FAILURE ); } 171 172 public String getStageDescription() { return( "stage description" ); } 173 174 public DeploymentStatus getParent() { return( mParent ); } 175 176 public Map <String ,Serializable > getAdditionalStatus() 177 { 178 return( null ); 179 } 180 181 public void 182 setParent( DeploymentStatus parent ) 183 { 184 mParent = parent; 185 } 186 187 public boolean 188 equals( Object rhs ) 189 { 190 return( new DeploymentStatusImpl( this ).equals( rhs ) ); 191 } 192 193 public String 194 toString() 195 { 196 return( new DeploymentStatusImpl( this.asMap() ).toString() ); 197 } 198 } 199 200 public void 201 testDeploymentStatusFromMap() 202 { 203 final DeploymentStatusImpl ds = createDeploymentStatus( "dummy" ); 204 final DeploymentStatusFoo stage1 = new DeploymentStatusFoo(); 205 ds.addSubStage( stage1 ); 206 207 final Map <String ,Serializable > data = ds.asMap(); 208 209 final DeploymentStatusImpl ds2 = new DeploymentStatusImpl( data ); 210 211 assert( ds2.equals( ds ) ); 212 } 213 214 215 public void 216 testDeploymentStatusAsMap() 217 { 218 final DeploymentStatusImpl ds = createDeploymentStatus( "dummy" ); 219 220 final Map <String ,Serializable > m = ds.asMap(); 221 } 222 223 224 public void 225 testCreateDeploymentStatusFromDeploymentStatus() 226 { 227 final DeploymentStatusFoo foo = new DeploymentStatusFoo(); 228 final DeploymentStatusImpl ds = new DeploymentStatusImpl( foo ); 229 230 assert( foo.equals( ds ) ); 231 assert( ds.equals( foo ) ); 232 } 233 234 public void 235 testDeploymentStatusSubStages() 236 { 237 final DeploymentStatusFoo stage1 = new DeploymentStatusFoo(); 238 final DeploymentStatusFoo stage2 = new DeploymentStatusFoo(); 239 final DeploymentStatusFoo stage1_1 = new DeploymentStatusFoo(); 240 final DeploymentStatusFoo stage2_1 = new DeploymentStatusFoo(); 241 242 final DeploymentStatusImpl root = createDeploymentStatus( "root" ); 243 assert( stage1.getParent() == null ); 244 root.addSubStage( stage1 ); 245 assert( stage1.getParent() == root ); 246 root.addSubStage( stage2 ); 247 assert( stage2.getParent() == root ); 248 stage1.addSubStage( stage1_1 ); 249 assert( stage1_1.getParent() == stage1 ); 250 stage2.addSubStage( stage2_1 ); 251 assert( stage2_1.getParent() == stage2 ); 252 253 final List <DeploymentStatus> subStages = root.getSubStagesList(); 254 assert( subStages.get(0) == stage1 ); 255 assert( subStages.get(1) == stage2 ); 256 } 257 258 private static final class MyException extends Exception 259 { 260 public static final long serialVersionUID = 833629292; 261 262 public MyException( Throwable cause ) 263 { 264 super( cause ); 265 } 266 267 public MyException( ) 268 { 269 } 270 } 271 272 public void 273 testIllegalThrowableDetected() 274 { 275 final DeploymentStatusImpl root = createDeploymentStatus( "root" ); 276 277 final Throwable t = new MyException( new MyException() ); 278 root.setStageThrowable( t ); 279 assert( root.getStageThrowable() != t ); 280 } 281 282 } 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | Popular Tags |