1 22 package org.jboss.test.aop.basic; 23 24 import org.jboss.aop.Advised; 25 26 30 public class CallingPOJO 31 { 32 POJO pojo; 33 NonadvisedPOJO nonpojo; 34 PrivateProtectedPOJO privateProtectedPojo; 35 36 public CallingPOJO() 37 { 38 CallerInterceptor.called = false; 39 pojo = new POJO(); 40 if (!CallerInterceptor.called) 41 { 42 throw new RuntimeException ("constructor caller interceptor didn't work from within constructor"); 43 } 44 CallerInterceptor.called = false; 45 pojo.someMethod(); 46 if (!CallerInterceptor.called) 47 { 48 throw new RuntimeException ("caller interceptor didn't work"); 49 } 50 51 CallerInterceptor.called = false; 52 POJO.staticMethod(); 53 if (!CallerInterceptor.called) 54 { 55 throw new RuntimeException ("caller interceptor didn't work"); 56 } 57 58 CallerInterceptor.called = false; 59 nonpojo = new NonadvisedPOJO("helloworld"); 60 if (!CallerInterceptor.called) 61 { 62 throw new RuntimeException ("constructor caller interceptor didn't work"); 63 } 64 CallerInterceptor.called = false; 65 nonpojo.remoteTest(); 66 if (!CallerInterceptor.called) 67 { 68 throw new RuntimeException ("caller interceptor didn't work"); 69 } 70 if (nonpojo instanceof Advised) 71 { 72 throw new RuntimeException ("nonpojo is Advised when it shouldn't be"); 73 } 74 75 privateProtectedPojo = new PrivateProtectedPOJO(); 77 CallerInterceptor.called = false; 78 privateProtectedPojo = new PrivateProtectedPOJO(); 79 if (!CallerInterceptor.called) 80 { 81 throw new RuntimeException ("protected constructor caller interceptor didn't work"); 82 } 83 84 privateProtectedPojo.protectedMethod(); 86 CallerInterceptor.called = false; 87 privateProtectedPojo.protectedMethod(); 88 if (!CallerInterceptor.called) 89 { 90 throw new RuntimeException ("protected method caller interceptor didn't work"); 91 } 92 93 CallerInterceptor.called = false; 94 PrivateProtectedPOJO.protectedStaticMethod(); 95 if (!CallerInterceptor.called) 96 { 97 throw new RuntimeException ("protected static method caller interceptor didn't work"); 98 } 99 100 CallerInterceptor.called = false ; 101 final InterfacePojo interfacePojo = new InterfacePojo() ; 102 final SuperInterface superInterface = interfacePojo ; 103 superInterface.superInterfaceMethod() ; 104 if (!CallerInterceptor.called) 105 { 106 throw new RuntimeException ("interface method via interface caller interceptor didn't work") ; 107 } 108 109 CallerInterceptor.called = false ; 110 final SubInterface subInterface = interfacePojo ; 111 subInterface.superInterfaceMethod() ; 112 if (!CallerInterceptor.called) 113 { 114 throw new RuntimeException ("interface method via sub interface caller interceptor didn't work") ; 115 } 116 } 117 118 121 public void callSomeMethod() 122 { 123 CallerInterceptor.called = false; 124 pojo = new POJO(); 125 if (!CallerInterceptor.called) 126 { 127 throw new RuntimeException ("constructor caller interceptor didn't work within method"); 128 } 129 CallerInterceptor.called = false; 130 POJO.staticMethod(); 131 if (!CallerInterceptor.called) 132 { 133 throw new RuntimeException ("caller interceptor didn't work"); 134 } 135 CallerInterceptor.called = false; 136 pojo.someMethod(); 137 if (!CallerInterceptor.called) 138 { 139 throw new RuntimeException ("caller interceptor didn't work"); 140 } 141 142 privateProtectedPojo = new PrivateProtectedPOJO(); 144 CallerInterceptor.called = false; 145 privateProtectedPojo = new PrivateProtectedPOJO(); 146 if (!CallerInterceptor.called) 147 { 148 throw new RuntimeException ("protected constructor caller interceptor didn't work"); 149 } 150 151 privateProtectedPojo.protectedMethod(); 153 CallerInterceptor.called = false; 154 privateProtectedPojo.protectedMethod(); 155 if (!CallerInterceptor.called) 156 { 157 throw new RuntimeException ("protected method caller interceptor didn't work"); 158 } 159 160 CallerInterceptor.called = false; 161 PrivateProtectedPOJO.callProtectedStaticMethod(); 162 if (!CallerInterceptor.called) 163 { 164 throw new RuntimeException ("protected static method caller interceptor didn't work"); 165 } 166 167 CallerInterceptor.called = false; 168 privateProtectedPojo.callProtectedMethod(); 169 if (!CallerInterceptor.called) 170 { 171 throw new RuntimeException ("protected method caller interceptor (2) didn't work"); 172 } 173 174 CallerInterceptor.called = false; 175 privateProtectedPojo.callPrivateMethod(); 176 if (!CallerInterceptor.called) 177 { 178 throw new RuntimeException ("protected method caller interceptor (2) didn't work"); 179 } 180 181 CallerInterceptor.called = false; 182 privateProtectedPojo = new PrivateProtectedPOJO("s", 1); if (!CallerInterceptor.called) 184 { 185 throw new RuntimeException ("private constructor caller interceptor from constructor didn't work"); 186 } 187 188 CallerInterceptor.called = false; 189 PrivateProtectedPOJO.callPrivateConstructor(); 190 if (!CallerInterceptor.called) 191 { 192 throw new RuntimeException ("private constructor caller interceptor from method didn't work"); 193 } 194 195 CallerInterceptor.called = false ; 196 final InterfacePojo interfacePojo = new InterfacePojo() ; 197 final SuperInterface superInterface = interfacePojo ; 198 superInterface.superInterfaceMethod() ; 199 if (!CallerInterceptor.called) 200 { 201 throw new RuntimeException ("interface method via interface caller interceptor didn't work") ; 202 } 203 204 CallerInterceptor.called = false ; 205 final SubInterface subInterface = interfacePojo ; 206 subInterface.superInterfaceMethod() ; 207 if (!CallerInterceptor.called) 208 { 209 throw new RuntimeException ("interface method via sub interface caller interceptor didn't work") ; 210 } 211 } 212 213 216 public void nocallSomeMethod() 217 { 218 CallerInterceptor.called = false; 219 pojo = new POJO(); 220 if (CallerInterceptor.called) 221 { 222 throw new RuntimeException ("constructor caller interceptor didn't work, interceptor was invoked when it shouldn't have been"); 223 } 224 pojo.someMethod(); 225 if (CallerInterceptor.called) 226 { 227 throw new RuntimeException ("caller interceptor didn't work, caller interceptor was invoked when it shouldn't have been"); 228 } 229 } 230 231 public void callUnadvised() 232 { 233 CallerInterceptor.called = false; 234 nonpojo = new NonadvisedPOJO("helloworld"); 235 if (!CallerInterceptor.called) 236 { 237 throw new RuntimeException ("consturctor caller interceptor didn't work"); 238 } 239 CallerInterceptor.called = false; 240 nonpojo.remoteTest(); 241 if (!CallerInterceptor.called) 242 { 243 throw new RuntimeException ("caller interceptor didn't work"); 244 } 245 if (nonpojo instanceof Advised) 246 { 247 throw new RuntimeException ("nonpojo is Advised when it shouldn't be"); 248 } 249 } 250 251 public void callUnadvisedWithPointcutException() 252 { 253 try 254 { 255 CallerInterceptor.called = false; 256 nonpojo = new NonadvisedPOJO("helloworld"); 257 if (!CallerInterceptor.called) 258 { 259 throw new RuntimeException ("caller interceptor didn't work"); 260 } 261 262 CallerInterceptor.called = false; 263 nonpojo.withException("x", 1); 264 if (!CallerInterceptor.called) 265 { 266 throw new RuntimeException ("caller interceptor didn't work"); 267 } 268 } 269 catch (ClassCastException e) 270 { 271 throw new RuntimeException (e); 273 } 274 catch (SomeException e) 275 { 276 throw new RuntimeException (e); 278 } 279 280 281 } 282 283 } 284 285 | Popular Tags |