1 22 package org.jboss.test.aop.scopedextender; 23 24 import org.jboss.aop.Advised; 25 26 31 public class ScopedChildParentDelegationTester implements ScopedChildParentDelegationTesterMBean 32 { 33 public void testLoaders() throws Exception 34 { 35 System.out.println("=============== ScopedChildParentDelegationTester - LOADERS ================"); 36 ClassLoader mine = this.getClass().getClassLoader(); 37 ClassLoader a3 = Child_A3.class.getClassLoader(); 38 ClassLoader base = Base_Base.class.getClassLoader(); 39 40 if (mine != a3) 41 { 42 throw new RuntimeException ("ClassLoaders for me and Child_A3 should be the same. Mine=" + mine + "; Child_A3=" + a3); 43 } 44 45 if (mine == base) 46 { 47 throw new RuntimeException ("ClassLoaders for me and Base_Base should be different. Mine=" + mine + "; Base_Base=" + base); 48 } 49 } 50 51 public void testMethod() throws Exception 52 { 53 TestUtil testUtil = new TestUtil(); 54 System.out.println("=============== ScopedChildParentDelegationTester - METHOD ================"); 55 Child_A3 a3 = new Child_A3(); 56 57 clear(); 58 a3.a3(); 59 String m = "Child_A3.a3"; 60 testUtil.compare(m, "ChildAspect", new String []{"a3", "a2", "a1", "base"}, ChildAspect.invoked); 61 testUtil.compare(m, "BaseAspect", new String []{"a3", "a2", "a1", "base"}, BaseAspect.invoked); 62 testUtil.compare(m, "BaseParentAspect", new String []{"a3", "a2", "a1", "base"}, BaseParentAspect.invoked); 63 64 clear(); 65 a3.overridden(); 66 m = "Child_A3.overridden"; 67 testUtil.compare(m, "ChildAspect", new String []{"overridden"}, ChildAspect.invoked); 68 testUtil.compare(m, "BaseAspect", new String []{"overridden"}, BaseAspect.invoked); 69 testUtil.compare(m, "BaseParentAspect", new String []{"overridden"}, BaseParentAspect.invoked); 70 71 72 Child_A2 a2 = new Child_A2(); 73 74 clear(); 75 a2.a2(); 76 m = "Child_A2.a2"; 77 testUtil.compare(m, "ChildAspect", new String []{"a2", "a1", "base"}, ChildAspect.invoked); 78 testUtil.compare(m, "BaseAspect", new String []{"a2", "a1", "base"}, BaseAspect.invoked); 79 testUtil.compare(m, "BaseParentAspect", new String []{"a2", "a1", "base"}, BaseParentAspect.invoked); 80 81 clear(); 82 a2.overridden(); 83 m = "Child_A2.overridden"; 84 testUtil.compare(m, "ChildAspect", new String []{"overridden"}, ChildAspect.invoked); 85 testUtil.compare(m, "BaseAspect", new String []{"overridden"}, BaseAspect.invoked); 86 testUtil.compare(m, "BaseParentAspect", new String []{"overridden"}, BaseParentAspect.invoked); 87 88 89 Base_Base base = new Base_Base(); 91 92 clear(); 93 base.base(); 94 m = "Base_Base.base"; 95 testUtil.compare(m, "BaseAspect", new String []{"base"}, BaseAspect.invoked); 96 testUtil.compare(m, "ChildAspect", new String []{}, ChildAspect.invoked); 97 testUtil.compare(m, "BaseParentAspect", new String []{}, BaseParentAspect.invoked); 98 99 clear(); 100 base.overridden(); 101 m = "Base_Base.overridden"; 102 testUtil.compare(m, "BaseAspect", new String [] {"overridden"}, BaseAspect.invoked); 103 testUtil.compare(m, "ChildAspect", new String [] {}, ChildAspect.invoked); 104 testUtil.compare(m, "BaseParentAspect", new String []{}, BaseParentAspect.invoked); 105 106 107 Base_A1 a1 = new Base_A1(); 109 110 clear(); 111 a1.a1(); 112 m = "Base_A1.a1"; 113 testUtil.compare(m, "BaseAspect", new String []{"a1", "base"}, BaseAspect.invoked); 114 testUtil.compare(m, "ChildAspect", new String [] {}, ChildAspect.invoked); 115 testUtil.compare(m, "BaseParentAspect", new String []{}, BaseParentAspect.invoked); 116 117 clear(); 118 a1.overridden(); 119 m = "Base_A1.overridden"; 120 testUtil.compare(m, "BaseAspect", new String [] {"overridden"}, BaseAspect.invoked); 121 testUtil.compare(m, "ChildAspect", new String [] {}, ChildAspect.invoked); 122 testUtil.compare(m, "BaseParentAspect", new String []{}, BaseParentAspect.invoked); 123 124 Child_B1 b1 = new Child_B1(); 125 126 clear(); 127 b1.b1(); 128 m = "Child_B1.b1"; 129 testUtil.compare(m, "ChildAspect", new String []{"b1", "base"}, ChildAspect.invoked); 130 testUtil.compare(m, "BaseAspect", new String []{"b1", "base"}, BaseAspect.invoked); 131 testUtil.compare(m, "BaseParentAspect", new String []{"b1", "base"}, BaseParentAspect.invoked); 132 133 clear(); 134 b1.overridden(); 135 m = "Child_B1.overridden"; 136 testUtil.compare(m, "ChildAspect", new String []{"overridden"}, ChildAspect.invoked); 137 testUtil.compare(m, "BaseAspect", new String []{"overridden"}, BaseAspect.invoked); 138 testUtil.compare(m, "BaseParentAspect", new String []{"overridden"}, BaseParentAspect.invoked); 139 140 Child_B2 b2 = new Child_B2(); 141 142 clear(); 143 b2.b2(); 144 m = "Child_B2.b2"; 145 testUtil.compare(m, "ChildAspect", new String []{"b2", "b1", "base"}, ChildAspect.invoked); 146 testUtil.compare(m, "BaseAspect", new String []{"b2", "b1", "base"}, BaseAspect.invoked); 147 testUtil.compare(m, "BaseParentAspect", new String []{"b2", "b1", "base"}, BaseParentAspect.invoked); 148 149 clear(); 150 b2.overridden(); 151 m = "Child_B2.overridden"; 152 testUtil.compare(m, "ChildAspect", new String []{"overridden"}, ChildAspect.invoked); 153 testUtil.compare(m, "BaseAspect", new String []{"overridden"}, BaseAspect.invoked); 154 testUtil.compare(m, "BaseParentAspect", new String []{"overridden"}, BaseParentAspect.invoked); 155 156 Child_B3 b3 = new Child_B3(); 157 158 clear(); 159 b3.b3(); 160 m = "Child_B3.b3"; 161 testUtil.compare(m, "ChildAspect", new String []{"b3", "b2", "b1", "base"}, ChildAspect.invoked); 162 testUtil.compare(m, "BaseAspect", new String []{"b3", "b2", "b1", "base"}, BaseAspect.invoked); 163 testUtil.compare(m, "BaseParentAspect", new String []{"b3", "b2", "b1", "base"}, BaseParentAspect.invoked); 164 165 clear(); 166 b3.overridden(); 167 m = "Child_B3.overridden"; 168 testUtil.compare(m, "ChildAspect", new String []{"overridden"}, ChildAspect.invoked); 169 testUtil.compare(m, "BaseAspect", new String []{"overridden"}, BaseAspect.invoked); 170 testUtil.compare(m, "BaseParentAspect", new String []{"overridden"}, BaseParentAspect.invoked); 171 172 if (testUtil.getErrors() != null) 173 { 174 throw new RuntimeException (testUtil.getErrors()); 175 } 176 177 if(Advised.class.isAssignableFrom(BaseNotBaseWoven.class)) 178 { 179 throw new RuntimeException ("BaseNotBaseWoven should not be woven"); 180 } 181 } 182 183 public void testConstructor() throws Exception 184 { 185 TestUtil testUtil = new TestUtil(); 186 System.out.println("=============== ScopedChildParentDelegationTester - CTOR ================"); 187 188 clear(); 189 Child_A3 a3 = new Child_A3(); 190 testUtil.compare(a3.getClass().getName(), "ChildAspect", new String []{a3.getClass().getName()}, ChildAspect.invoked); 191 testUtil.compare(a3.getClass().getName(), "BaseAspect", new String []{a3.getClass().getName()}, BaseAspect.invoked); 192 testUtil.compare(a3.getClass().getName(), "BaseParentAspect", new String []{a3.getClass().getName()}, BaseParentAspect.invoked); 193 194 clear(); 195 Child_A2 a2 = new Child_A2(); 196 testUtil.compare(a2.getClass().getName(), "ChildAspect", new String []{a2.getClass().getName()}, ChildAspect.invoked); 197 testUtil.compare(a2.getClass().getName(), "BaseAspect", new String []{a2.getClass().getName()}, BaseAspect.invoked); 198 testUtil.compare(a2.getClass().getName(), "BaseParentAspect", new String []{a2.getClass().getName()}, BaseParentAspect.invoked); 199 200 clear(); 202 Base_Base base = new Base_Base(); 203 testUtil.compare(base.getClass().getName(), "ChildAspect", new String []{}, ChildAspect.invoked); 204 testUtil.compare(base.getClass().getName(), "BaseAspect", new String []{base.getClass().getName()}, BaseAspect.invoked); 205 testUtil.compare(base.getClass().getName(), "BaseParentAspect", new String []{}, BaseParentAspect.invoked); 206 207 208 clear(); 210 Base_A1 a1 = new Base_A1(); 211 testUtil.compare(a1.getClass().getName(), "ChildAspect", new String []{}, ChildAspect.invoked); 212 testUtil.compare(a1.getClass().getName(), "BaseAspect", new String []{a1.getClass().getName()}, BaseAspect.invoked); 213 testUtil.compare(a1.getClass().getName(), "BaseParentAspect", new String []{}, BaseParentAspect.invoked); 214 215 clear(); 216 Child_B1 b1 = new Child_B1(); 217 testUtil.compare(b1.getClass().getName(), "ChildAspect", new String []{b1.getClass().getName()}, ChildAspect.invoked); 218 testUtil.compare(b1.getClass().getName(), "BaseAspect", new String []{b1.getClass().getName()}, BaseAspect.invoked); 219 testUtil.compare(b1.getClass().getName(), "BaseParentAspect", new String []{b1.getClass().getName()}, BaseParentAspect.invoked); 220 221 clear(); 222 Child_B2 b2 = new Child_B2(); 223 testUtil.compare(b2.getClass().getName(), "ChildAspect", new String []{b2.getClass().getName()}, ChildAspect.invoked); 224 testUtil.compare(b2.getClass().getName(), "BaseAspect", new String []{b2.getClass().getName()}, BaseAspect.invoked); 225 testUtil.compare(b2.getClass().getName(), "BaseParentAspect", new String []{b2.getClass().getName()}, BaseParentAspect.invoked); 226 227 clear(); 228 Child_B3 b3 = new Child_B3(); 229 testUtil.compare(b3.getClass().getName(), "ChildAspect", new String []{b3.getClass().getName()}, ChildAspect.invoked); 230 testUtil.compare(b3.getClass().getName(), "BaseAspect", new String []{b3.getClass().getName()}, BaseAspect.invoked); 231 testUtil.compare(b3.getClass().getName(), "BaseParentAspect", new String []{b3.getClass().getName()}, BaseParentAspect.invoked); 232 233 } 234 235 public void testField() throws Exception 236 { 237 TestUtil testUtil = new TestUtil(); 238 System.out.println("=============== ScopedChildParentDelegationTester - FIELD ================"); 239 Child_A3 a3 = new Child_A3(); 240 241 clear(); 242 a3.a3 = 10; 243 String m = "Child_A3.a3"; 244 testUtil.compare(m, "ChildAspect", new String []{"a3"}, ChildAspect.invoked); 245 testUtil.compare(m, "BaseAspect", new String []{"a3"}, BaseAspect.invoked); 246 testUtil.compare(m, "BaseParentAspect", new String []{"a3"}, BaseParentAspect.invoked); 247 248 clear(); 249 testUtil.compare(10, a3.a3); 250 testUtil.compare(m, "ChildAspect", new String []{"a3"}, ChildAspect.invoked); 251 testUtil.compare(m, "BaseAspect", new String []{"a3"}, BaseAspect.invoked); 252 testUtil.compare(m, "BaseParentAspect", new String []{"a3"}, BaseParentAspect.invoked); 253 254 clear(); 255 a3.a2 = 10; 256 m = "Child_A3.a2"; 257 testUtil.compare(m, "ChildAspect", new String []{"a2"}, ChildAspect.invoked); 258 testUtil.compare(m, "BaseAspect", new String []{"a2"}, BaseAspect.invoked); 259 testUtil.compare(m, "BaseParentAspect", new String []{"a2"}, BaseParentAspect.invoked); 260 261 clear(); 262 testUtil.compare(10, a3.a2); 263 testUtil.compare(m, "ChildAspect", new String []{"a2"}, ChildAspect.invoked); 264 testUtil.compare(m, "BaseAspect", new String []{"a2"}, BaseAspect.invoked); 265 testUtil.compare(m, "BaseParentAspect", new String []{"a2"}, BaseParentAspect.invoked); 266 267 clear(); 268 a3.a1 = 10; 269 m = "Child_A3.a1"; 270 testUtil.compare(m, "ChildAspect", new String []{}, ChildAspect.invoked); 271 testUtil.compare(m, "BaseAspect", new String []{"a1"}, BaseAspect.invoked); 272 testUtil.compare(m, "BaseParentAspect", new String []{"a1"}, BaseParentAspect.invoked); 273 274 clear(); 275 testUtil.compare(10, a3.a1); 276 testUtil.compare(m, "ChildAspect", new String []{}, ChildAspect.invoked); 277 testUtil.compare(m, "BaseAspect", new String []{"a1"}, BaseAspect.invoked); 278 testUtil.compare(m, "BaseParentAspect", new String []{"a1"}, BaseParentAspect.invoked); 279 280 clear(); 281 a3.base = 10; 282 m = "Child_A3.base"; 283 testUtil.compare(m, "ChildAspect", new String []{}, ChildAspect.invoked); 284 testUtil.compare(m, "BaseAspect", new String []{"base"}, BaseAspect.invoked); 285 testUtil.compare(m, "BaseParentAspect", new String []{"base"}, BaseParentAspect.invoked); 286 287 clear(); 288 testUtil.compare(10, a3.base); 289 testUtil.compare(m, "ChildAspect", new String []{}, ChildAspect.invoked); 290 testUtil.compare(m, "BaseAspect", new String []{"base"}, BaseAspect.invoked); 291 testUtil.compare(m, "BaseParentAspect", new String []{"base"}, BaseParentAspect.invoked); 292 293 294 Base_A1 a1 = new Base_A1(); 296 297 clear(); 298 a1.a1 = 10; 299 m = "Base_A1.a1"; 300 testUtil.compare(m, "ChildAspect", new String []{}, ChildAspect.invoked); 301 testUtil.compare(m, "BaseAspect", new String []{"a1"}, BaseAspect.invoked); 302 testUtil.compare(m, "BaseParentAspect", new String []{}, BaseParentAspect.invoked); 303 304 clear(); 305 testUtil.compare(10, a1.a1); 306 testUtil.compare(m, "ChildAspect", new String []{}, ChildAspect.invoked); 307 testUtil.compare(m, "BaseAspect", new String []{"a1"}, BaseAspect.invoked); 308 testUtil.compare(m, "BaseParentAspect", new String []{}, BaseParentAspect.invoked); 309 310 clear(); 311 a1.base = 10; 312 m = "Base_A1.base"; 313 testUtil.compare(m, "ChildAspect", new String []{}, ChildAspect.invoked); 314 testUtil.compare(m, "BaseAspect", new String []{"base"}, BaseAspect.invoked); 315 testUtil.compare(m, "BaseParentAspect", new String []{}, BaseParentAspect.invoked); 316 317 clear(); 318 testUtil.compare(10, a1.base); 319 testUtil.compare(m, "ChildAspect", new String []{}, ChildAspect.invoked); 320 testUtil.compare(m, "BaseAspect", new String []{"base"}, BaseAspect.invoked); 321 testUtil.compare(m, "BaseParentAspect", new String []{}, BaseParentAspect.invoked); 322 323 Base_Base base = new Base_Base(); 325 326 clear(); 327 base.base = 10; 328 m = "Base_Base.base"; 329 testUtil.compare(m, "ChildAspect", new String []{}, ChildAspect.invoked); 330 testUtil.compare(m, "BaseAspect", new String []{"base"}, BaseAspect.invoked); 331 testUtil.compare(m, "BaseParentAspect", new String []{}, BaseParentAspect.invoked); 332 333 clear(); 334 testUtil.compare(10, base.base); 335 testUtil.compare(m, "ChildAspect", new String []{}, ChildAspect.invoked); 336 testUtil.compare(m, "BaseAspect", new String []{"base"}, BaseAspect.invoked); 337 testUtil.compare(m, "BaseParentAspect", new String []{}, BaseParentAspect.invoked); 338 339 340 341 Child_B3 b3 = new Child_B3(); 342 343 clear(); 344 b3.b3 = 10; 345 m = "Child_B3.b3"; 346 testUtil.compare(m, "ChildAspect", new String []{"b3"}, ChildAspect.invoked); 347 testUtil.compare(m, "BaseAspect", new String []{"b3"}, BaseAspect.invoked); 348 testUtil.compare(m, "BaseParentAspect", new String []{"b3"}, BaseParentAspect.invoked); 349 350 clear(); 351 testUtil.compare(10, b3.b3); 352 testUtil.compare(m, "ChildAspect", new String []{"b3"}, ChildAspect.invoked); 353 testUtil.compare(m, "BaseAspect", new String []{"b3"}, BaseAspect.invoked); 354 testUtil.compare(m, "BaseParentAspect", new String []{"b3"}, BaseParentAspect.invoked); 355 356 clear(); 357 b3.b2 = 10; 358 m = "Child_B3.b2"; 359 testUtil.compare(m, "ChildAspect", new String []{"b2"}, ChildAspect.invoked); 360 testUtil.compare(m, "BaseAspect", new String []{"b2"}, BaseAspect.invoked); 361 testUtil.compare(m, "BaseParentAspect", new String []{"b2"}, BaseParentAspect.invoked); 362 363 clear(); 364 testUtil.compare(10, b3.b2); 365 testUtil.compare(m, "ChildAspect", new String []{"b2"}, ChildAspect.invoked); 366 testUtil.compare(m, "BaseAspect", new String []{"b2"}, BaseAspect.invoked); 367 testUtil.compare(m, "BaseParentAspect", new String []{"b2"}, BaseParentAspect.invoked); 368 369 clear(); 370 b3.b1 = 10; 371 m = "Child_B3.b1"; 372 testUtil.compare(m, "ChildAspect", new String []{"b1"}, ChildAspect.invoked); 373 testUtil.compare(m, "BaseAspect", new String []{"b1"}, BaseAspect.invoked); 374 testUtil.compare(m, "BaseParentAspect", new String []{"b1"}, BaseParentAspect.invoked); 375 376 clear(); 377 testUtil.compare(10, b3.b1); 378 testUtil.compare(m, "ChildAspect", new String []{"b1"}, ChildAspect.invoked); 379 testUtil.compare(m, "BaseAspect", new String []{"b1"}, BaseAspect.invoked); 380 testUtil.compare(m, "BaseParentAspect", new String []{"b1"}, BaseParentAspect.invoked); 381 382 clear(); 383 b3.base = 10; 384 m = "Child_B3.base"; 385 testUtil.compare(m, "ChildAspect", new String []{}, ChildAspect.invoked); 386 testUtil.compare(m, "BaseAspect", new String []{"base"}, BaseAspect.invoked); 387 testUtil.compare(m, "BaseParentAspect", new String []{"base"}, BaseParentAspect.invoked); 388 389 clear(); 390 testUtil.compare(10, b3.base); 391 testUtil.compare(m, "ChildAspect", new String []{}, ChildAspect.invoked); 392 testUtil.compare(m, "BaseAspect", new String []{"base"}, BaseAspect.invoked); 393 testUtil.compare(m, "BaseParentAspect", new String []{"base"}, BaseParentAspect.invoked); 394 395 if (testUtil.getErrors() != null) 396 { 397 throw new RuntimeException (testUtil.getErrors()); 398 } 399 } 400 401 public void testOverriddenInterceptors() throws Exception 402 { 403 System.out.println("=============== ScopedChildParentDelegationTester - TEST OVERRIDDEN INTERCEPTORS ================"); 405 TestUtil testUtil = new TestUtil(); 406 407 Base_Base base = new Base_Base(); 408 409 clear(); 410 base.differentScopes(); 411 String m = "differentScopes"; 412 testUtil.compare(m, "BaseAspect", new String []{"differentScopes"}, BaseAspect.invoked); 413 testUtil.invoked(BasePerClassInterceptor.class); 414 testUtil.invoked(BasePerInstanceInterceptor.class); 415 testUtil.invoked(BasePerJoinPointInterceptor.class); 416 testUtil.invoked(BasePerClassJoinPointInterceptor.class); 417 418 if (testUtil.getErrors() != null) 419 { 420 throw new RuntimeException (testUtil.getErrors()); 421 } 422 } 423 424 public String readName() 425 { 426 return "ScopedChildParentDelegationTester"; 427 } 428 429 private void clear() 430 { 431 BaseAspect.invoked.clear(); 432 ChildAspect.invoked.clear(); 433 BaseParentAspect.invoked.clear(); 434 BasePerClassInterceptor.invoked = false; 435 BasePerInstanceInterceptor.invoked = false; 436 BasePerJoinPointInterceptor.invoked = false; 437 BasePerClassJoinPointInterceptor.invoked = false; 438 439 } 440 } 441 | Popular Tags |