1 22 package org.jboss.test.aop.jdk15.dynamic.prepareField; 23 24 import org.jboss.test.aop.AOPTestDelegate; 25 import org.jboss.test.aop.AOPTestWithSetup; 26 import org.jboss.test.aop.jdk15.dynamic.common.BindingInterceptor; 27 import org.jboss.test.aop.jdk15.dynamic.common.InstanceInterceptor; 28 import org.jboss.test.aop.jdk15.dynamic.common.InterceptionsCount; 29 import org.jboss.test.aop.jdk15.dynamic.common.POJOWrappingInfo; 30 import org.jboss.test.aop.jdk15.dynamic.common.ScenarioLoader; 31 32 38 public class HotSwapEnabledTester extends AOPTestWithSetup 39 { 40 private ScenarioLoader scenarioLoader; 41 42 public HotSwapEnabledTester(String name) 43 { 44 super(name); 45 } 46 47 50 public void setUp() throws Exception 51 { 52 super.setUp(); 53 this.scenarioLoader = new ScenarioLoader(((AOPTestDelegate)getDelegate()).getSystemProperties()); 54 } 55 56 60 private void assertUnwrapped(POJOWrappingInfo wrappingInfo) 61 { 62 assertFalse(wrappingInfo.isConstructorWrapped()); 63 assertFalse(wrappingInfo.isFieldReadWrapped()); 64 assertFalse(wrappingInfo.isFieldWriteWrapped()); 65 assertFalse(wrappingInfo.isMethodWrapped()); 66 } 67 68 72 private void assertFullyWrapped(POJOWrappingInfo wrappingInfo) 73 { 74 assertTrue(wrappingInfo.isConstructorWrapped()); 75 assertTrue(wrappingInfo.isFieldReadWrapped()); 76 assertTrue(wrappingInfo.isFieldWriteWrapped()); 77 assertTrue(wrappingInfo.isMethodWrapped()); 78 } 79 80 84 private void assertOnlyFieldWrapped(POJOWrappingInfo wrappingInfo) 85 { 86 assertFalse(wrappingInfo.isConstructorWrapped()); 87 assertTrue(wrappingInfo.isFieldReadWrapped()); 88 assertTrue(wrappingInfo.isFieldWriteWrapped()); 89 assertFalse(wrappingInfo.isMethodWrapped()); 90 } 91 92 98 public void testPerClassLoadAfterInterception() throws Throwable 99 { 100 POJOWrappingInfo[] wrappingInfos = scenarioLoader.interceptPerClassLoadAfter(); 102 assertFullyWrapped(wrappingInfos[0]); 104 assertUnwrapped(wrappingInfos[1]); 105 InterceptionsCount instance = InstanceInterceptor.getInterceptionsCount(); 107 assertEquals(0, instance.total); 108 InterceptionsCount binding = BindingInterceptor.getInterceptionsCount(); 109 assertTrue(binding.total >= 5 && binding.total <= 8); 110 assertTrue(binding.constructor >= 1 && binding.constructor <= 2); 111 assertTrue(binding.fieldRead >= 1 && binding.fieldRead <= 2); 112 assertTrue(binding.fieldWrite >= 1 && binding.fieldWrite <= 2); 113 assertEquals(2, binding.method); 114 } 115 116 122 public void testPerClassLoadBeforeInterception() throws Throwable 123 { 124 POJOWrappingInfo[] wrappingInfos = scenarioLoader.interceptPerClassLoadBefore(); 126 assertUnwrapped(wrappingInfos[0]); 128 assertOnlyFieldWrapped(wrappingInfos[1]); 129 assertUnwrapped(wrappingInfos[2]); 130 InterceptionsCount instance = InstanceInterceptor.getInterceptionsCount(); 132 assertEquals(0, instance.total); 133 InterceptionsCount binding = BindingInterceptor.getInterceptionsCount(); 134 assertEquals(2, binding.total); 135 assertEquals(0, binding.constructor); 136 assertEquals(1, binding.fieldRead); 137 assertEquals(1, binding.fieldWrite); 138 assertEquals(0, binding.method); 139 } 140 141 147 public void testAddAndRemoveBindingTwice() throws Throwable 148 { 149 POJOWrappingInfo[] wrappingInfos = scenarioLoader.addAndRemoveBindingTwice(); 151 assertUnwrapped(wrappingInfos[0]); 153 assertOnlyFieldWrapped(wrappingInfos[1]); 154 assertUnwrapped(wrappingInfos[2]); 155 assertOnlyFieldWrapped(wrappingInfos[3]); 156 assertUnwrapped(wrappingInfos[4]); 157 InterceptionsCount instance = InstanceInterceptor.getInterceptionsCount(); 159 assertEquals(0, instance.total); 160 InterceptionsCount binding = BindingInterceptor.getInterceptionsCount(); 161 assertEquals(4, binding.total); 162 assertEquals(0, binding.constructor); 163 assertEquals(2, binding.fieldRead); 164 assertEquals(2, binding.fieldWrite); 165 assertEquals(0, binding.method); 166 } 167 168 174 public void testPerInstanceInterception() throws Throwable 175 { 176 POJOWrappingInfo[] wrappingInfos = scenarioLoader.interceptPerInstance(); 178 assertUnwrapped(wrappingInfos[0]); 180 assertOnlyFieldWrapped(wrappingInfos[1]); 181 InterceptionsCount binding = BindingInterceptor.getInterceptionsCount(); 183 assertEquals(0, binding.total); 184 InterceptionsCount instance = InstanceInterceptor.getInterceptionsCount(); 185 assertTrue(instance.total >= 2 && instance.total <= 4); 186 assertEquals(0, instance.constructor); 187 assertTrue(instance.fieldRead >= 1 && instance.fieldRead <= 2); 188 assertTrue(instance.fieldWrite >= 1 && instance.fieldWrite <= 2); 189 assertEquals(0, instance.method); 190 } 191 192 193 199 public void testPerInstanceGcInterception() throws Throwable 200 { 201 POJOWrappingInfo[] wrappingInfos = scenarioLoader.interceptPerInstanceGC(); 203 assertUnwrapped(wrappingInfos[0]); 205 assertOnlyFieldWrapped(wrappingInfos[1]); 206 assertUnwrapped(wrappingInfos[2]); 207 InterceptionsCount binding = BindingInterceptor.getInterceptionsCount(); 209 assertEquals(0, binding.total); 210 InterceptionsCount instance = InstanceInterceptor.getInterceptionsCount(); 212 assertTrue(instance.total >= 2 && instance.total <= 4); 213 assertEquals(0, instance.constructor); 214 assertTrue(instance.fieldRead >= 1 && instance.fieldRead <= 2); 215 assertTrue(instance.fieldWrite >= 1 && instance.fieldWrite <= 2); 216 assertEquals(0, instance.method); 217 } 218 219 225 public void testPerClassPerInstanceInterception() throws Throwable 226 { 227 POJOWrappingInfo[] wrappingInfos = scenarioLoader.interceptPerClassPerInstance(); 229 assertUnwrapped(wrappingInfos[0]); 231 assertOnlyFieldWrapped(wrappingInfos[1]); 232 assertOnlyFieldWrapped(wrappingInfos[2]); 233 InterceptionsCount binding = BindingInterceptor.getInterceptionsCount(); 235 assertEquals(2, binding.total); 236 assertEquals(0, binding.constructor); 237 assertEquals(1, binding.fieldRead); 238 assertEquals(1, binding.fieldWrite); 239 assertEquals(0, binding.method); 240 InterceptionsCount instance = InstanceInterceptor.getInterceptionsCount(); 241 assertEquals(2, instance.total); 242 assertEquals(1, instance.fieldRead); 243 assertEquals(1, instance.fieldWrite); 244 } 245 246 252 public void testPerInstancePerClassInterception() throws Throwable 253 { 254 POJOWrappingInfo[] wrappingInfos = scenarioLoader.interceptPerInstancePerClass(); 256 assertOnlyFieldWrapped(wrappingInfos[0]); 258 assertOnlyFieldWrapped(wrappingInfos[1]); 259 assertOnlyFieldWrapped(wrappingInfos[2]); 260 InterceptionsCount binding = BindingInterceptor.getInterceptionsCount(); 262 assertEquals(2, binding.total); 263 assertEquals(0, binding.constructor); 264 assertEquals(1, binding.fieldRead); 265 assertEquals(1, binding.fieldWrite); 266 assertEquals(0, binding.method); 267 InterceptionsCount instance = InstanceInterceptor.getInterceptionsCount(); 268 assertTrue(instance.total >= 4 && instance.total <= 6); 269 assertEquals(0, instance.constructor); 270 assertTrue(instance.fieldRead >= 2 && instance.fieldRead <= 3); 271 assertTrue(instance.fieldWrite >= 2 && instance.fieldWrite <= 3); 272 assertEquals(0, instance.method); 273 } 274 275 281 public void testAfterBindingRemovalExecution() throws Throwable 282 { 283 POJOWrappingInfo[] wrappingInfos = scenarioLoader.executeAfterBindingRemoval(); 284 assertUnwrapped(wrappingInfos[0]); 285 InterceptionsCount binding = BindingInterceptor.getInterceptionsCount(); 286 assertEquals(0, binding.total); 287 InterceptionsCount instance = InstanceInterceptor.getInterceptionsCount(); 288 assertEquals(0, instance.total); 289 } 290 } | Popular Tags |