1 22 package org.jboss.test.aop.scopedextender; 23 24 import org.jboss.aop.Advised; 25 26 31 public class BaseLoadedTester implements BaseLoadedTesterMBean 32 { 33 public void testLoaders() throws Exception 34 { 35 System.out.println("=============== BaseLoadedTester - LOADERS ================"); 36 ClassLoader mine = this.getClass().getClassLoader(); 37 ClassLoader base = Base_Base.class.getClassLoader(); 38 39 if (mine != base) 40 { 41 throw new RuntimeException ("ClassLoaders for me and Base_Base should be the same. Mine=" + mine + "; Base_Base=" + base); 42 } 43 } 44 45 public void testMethod() throws Exception 46 { 47 TestUtil testUtil = new TestUtil(); 48 try 49 { 50 System.out.println("=============== BaseLoadedTester - METHOD ================"); 51 Base_Base base = new Base_Base(); 52 53 clear(); 54 base.base(); 55 String m = "Base_Base.base"; 56 testUtil.compare(m, "BaseAspect", new String []{"base"}, BaseAspect.invoked); 57 58 clear(); 59 base.overridden(); 60 m = "Base_Base.overridden"; 61 testUtil.compare(m, "BaseAspect", new String [] {"overridden"}, BaseAspect.invoked); 62 63 Base_A1 a1 = new Base_A1(); 64 65 clear(); 66 a1.a1(); 67 m = "Base_A1.a1"; 68 testUtil.compare(m, "BaseAspect", new String []{"a1", "base"}, BaseAspect.invoked); 69 70 clear(); 71 a1.overridden(); 72 m = "Base_A1.overridden"; 73 testUtil.compare(m, "BaseAspect", new String [] {"overridden"}, BaseAspect.invoked); 74 75 } 76 catch (RuntimeException e) 77 { 78 throw new RuntimeException (e); 80 } 81 82 if (testUtil.getErrors() != null) 83 { 84 throw new RuntimeException (testUtil.getErrors()); 85 } 86 87 if(Advised.class.isAssignableFrom(BaseNotBaseWoven.class)) 88 { 89 throw new RuntimeException ("BaseNotBaseWoven should not be woven"); 90 } 91 } 92 93 public void testConstructor() throws Exception 94 { 95 TestUtil testUtil = new TestUtil(); 96 try 97 { 98 System.out.println("=============== BaseLoadedTester - CTOR ================"); 99 100 clear(); 101 Base_Base base = new Base_Base(); 102 testUtil.compare(base.getClass().getName(), "BaseAspect", new String []{base.getClass().getName()}, BaseAspect.invoked); 103 104 clear(); 105 Base_A1 a1 = new Base_A1(); 106 testUtil.compare(a1.getClass().getName(), "BaseAspect", new String []{a1.getClass().getName()}, BaseAspect.invoked); 107 } 108 catch (RuntimeException e) 109 { 110 throw new RuntimeException (e); 112 } 113 if (testUtil.getErrors() != null) 114 { 115 throw new RuntimeException (testUtil.getErrors()); 116 } 117 if(Advised.class.isAssignableFrom(BaseNotBaseWoven.class)) 118 { 119 throw new RuntimeException ("BaseNotBaseWoven should not be woven"); 120 } 121 } 122 123 public void testField() throws Exception 124 { 125 TestUtil testUtil = new TestUtil(); 126 try 127 { 128 System.out.println("=============== BaseLoadedTester - FIELD ================"); 129 Base_Base base = new Base_Base(); 130 131 clear(); 132 base.base = 5; 133 String m = "Base_Base.base"; 134 testUtil.compare(m, "BaseAspect", new String []{"base"}, BaseAspect.invoked); 135 136 clear(); 137 testUtil.compare(5, base.base); 138 testUtil.compare(m, "BaseAspect", new String []{"base"}, BaseAspect.invoked); 139 140 141 Base_A1 a1 = new Base_A1(); 142 143 clear(); 144 a1.a1 = 10; 145 m = "Base_A1.a1"; 146 testUtil.compare(m, "BaseAspect", new String []{"a1"}, BaseAspect.invoked); 147 148 clear(); 149 testUtil.compare(10, a1.a1); 150 testUtil.compare(m, "BaseAspect", new String []{"a1"}, BaseAspect.invoked); 151 } 152 catch (RuntimeException e) 153 { 154 throw new RuntimeException (e); 156 } 157 158 if (testUtil.getErrors() != null) 159 { 160 throw new RuntimeException (testUtil.getErrors()); 161 } 162 163 if(Advised.class.isAssignableFrom(BaseNotBaseWoven.class)) 164 { 165 throw new RuntimeException ("BaseNotBaseWoven should not be woven"); 166 } 167 } 168 169 170 public void testOverriddenInterceptors() throws Exception 171 { 172 System.out.println("=============== BaseLoadedTester - TEST OVERRIDDEN INTERCEPTORS ================"); 174 TestUtil testUtil = new TestUtil(); 175 176 Base_Base base = new Base_Base(); 177 178 clear(); 179 base.differentScopes(); 180 String m = "differentScopes"; 181 testUtil.compare(m, "BaseAspect", new String []{"differentScopes"}, BaseAspect.invoked); 182 testUtil.invoked(BasePerClassInterceptor.class); 183 testUtil.invoked(BasePerInstanceInterceptor.class); 184 testUtil.invoked(BasePerJoinPointInterceptor.class); 185 testUtil.invoked(BasePerClassJoinPointInterceptor.class); 186 187 if (testUtil.getErrors() != null) 188 { 189 throw new RuntimeException (testUtil.getErrors()); 190 } 191 } 192 193 public String readName() 194 { 195 return "BaseLoadedTester"; 196 } 197 198 private void clear() 199 { 200 BaseAspect.invoked.clear(); 201 BasePerClassInterceptor.invoked = false; 202 BasePerInstanceInterceptor.invoked = false; 203 BasePerJoinPointInterceptor.invoked = false; 204 BasePerClassJoinPointInterceptor.invoked = false; 205 } 206 } 207 | Popular Tags |