KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > aop > jdk15 > dynamic > prepareField > HotSwapEnabledTester


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

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 /**
33  * TestCase that checks the jboss aop behaviour in dynamic aop operations
34  * performed with hot swap enabled. The aop operations target class, (POJO class)
35  * was configured to have only the field read and write joinpoints prepared.
36  * @author Flavia Rainone
37  */

38 public class HotSwapEnabledTester extends AOPTestWithSetup
39 {
40    private ScenarioLoader scenarioLoader;
41  
42    public HotSwapEnabledTester(String JavaDoc name)
43    {
44       super(name);
45    }
46
47    /**
48     * Runs before each test method.
49     */

50    public void setUp() throws Exception JavaDoc
51    {
52       super.setUp();
53       this.scenarioLoader = new ScenarioLoader(((AOPTestDelegate)getDelegate()).getSystemProperties());
54    }
55    
56    /**
57     * Asserts no pojo joinpoints are wrapped.
58     * @param wrappingInfo contains the joinpoints wrapping information to be checked.
59     */

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    /**
69     * Asserts all pojo joinpoints are wrapped.
70     * @param wrappingInfo contains the joinpoints wrapping information to be checked.
71     */

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    /**
81     * Asserts only field read and write joinpoints are wrapped.
82     * @param wrappingInfo contains the joinpoints wrapping information to be checked.
83     */

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    /**
93     * Runs "interceptPerClassLoadAfter" scenario and checks which
94     * interceptions were performed.
95     * @throws Throwable
96     * @see ScenarioLoader#interceptPerClassLoadAfter()
97     */

98    public void testPerClassLoadAfterInterception() throws Throwable JavaDoc
99    {
100       // run scenario
101
POJOWrappingInfo[] wrappingInfos = scenarioLoader.interceptPerClassLoadAfter();
102       // check wrapping status
103
assertFullyWrapped(wrappingInfos[0]);
104       assertUnwrapped(wrappingInfos[1]);
105       // check interception counts
106
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    /**
117     * Runs "interceptPerClassLoadBefore" scenario and checks which
118     * interceptions were performed.
119     * @throws Throwable
120     * @see ScenarioscenarioLoader#interceptPerClassLoadBefore()
121     */

122    public void testPerClassLoadBeforeInterception() throws Throwable JavaDoc
123    {
124       // run scenario
125
POJOWrappingInfo[] wrappingInfos = scenarioLoader.interceptPerClassLoadBefore();
126       // check wrapping status
127
assertUnwrapped(wrappingInfos[0]);
128       assertOnlyFieldWrapped(wrappingInfos[1]);
129       assertUnwrapped(wrappingInfos[2]);
130       // check interception counts
131
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    /**
142     * Runs "addAndRemoveBindingTwice" scenario and checks which
143     * interceptions were performed.
144     * @throws Throwable
145     * @see ScenarioLoader#interceptPerClassLoadBefore()
146     */

147    public void testAddAndRemoveBindingTwice() throws Throwable JavaDoc
148    {
149       // run scenario
150
POJOWrappingInfo[] wrappingInfos = scenarioLoader.addAndRemoveBindingTwice();
151       // check wrapping status
152
assertUnwrapped(wrappingInfos[0]);
153       assertOnlyFieldWrapped(wrappingInfos[1]);
154       assertUnwrapped(wrappingInfos[2]);
155       assertOnlyFieldWrapped(wrappingInfos[3]);
156       assertUnwrapped(wrappingInfos[4]);
157       // check interception counts
158
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    /**
169     * Runs "interceptPerInstance" scenario and checks which
170     * interceptions were performed.
171     * @throws Throwable
172     * @see ScenarioLoader#interceptPerInstance()
173     */

174    public void testPerInstanceInterception() throws Throwable JavaDoc
175    {
176       // run scenario
177
POJOWrappingInfo[] wrappingInfos = scenarioLoader.interceptPerInstance();
178       // check wrapping status
179
assertUnwrapped(wrappingInfos[0]);
180       assertOnlyFieldWrapped(wrappingInfos[1]);
181       // check interception counts
182
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    /**
194     * Runs "interceptPerInstanceGC" scenario and checks which
195     * interceptions were performed.
196     * @throws Throwable
197     * @see ScenarioLoader#interceptPerInstanceGC()
198     */

199    public void testPerInstanceGcInterception() throws Throwable JavaDoc
200    {
201       // run scenario
202
POJOWrappingInfo[] wrappingInfos = scenarioLoader.interceptPerInstanceGC();
203       // check wrapping status
204
assertUnwrapped(wrappingInfos[0]);
205       assertOnlyFieldWrapped(wrappingInfos[1]);
206       assertUnwrapped(wrappingInfos[2]);
207       // check interception counts
208
InterceptionsCount binding = BindingInterceptor.getInterceptionsCount();
209       assertEquals(0, binding.total);
210       // result of the time the JVMTI takes to hot swap classes
211
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    /**
220     * Runs "interceptPerClassPerInstance" scenario and checks which
221     * interceptions were performed.
222     * @throws Throwable
223     * @see ScenarioLoader#interceptPerClassPerInstance()
224     */

225    public void testPerClassPerInstanceInterception() throws Throwable JavaDoc
226    {
227       // run scenario
228
POJOWrappingInfo[] wrappingInfos = scenarioLoader.interceptPerClassPerInstance();
229       // check wrapping status
230
assertUnwrapped(wrappingInfos[0]);
231       assertOnlyFieldWrapped(wrappingInfos[1]);
232       assertOnlyFieldWrapped(wrappingInfos[2]);
233       // check interception counts
234
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    /**
247     * Runs "interceptPerInstancePerClass" scenario and checks which
248     * interceptions were performed.
249     * @throws Throwable
250     * @see ScenarioLoader#interceptPerInstancePerClass()
251     */

252    public void testPerInstancePerClassInterception() throws Throwable JavaDoc
253    {
254       // run scenario
255
POJOWrappingInfo[] wrappingInfos = scenarioLoader.interceptPerInstancePerClass();
256       // check wrapping status
257
assertOnlyFieldWrapped(wrappingInfos[0]);
258       assertOnlyFieldWrapped(wrappingInfos[1]);
259       assertOnlyFieldWrapped(wrappingInfos[2]);
260       // check interception counts
261
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    /**
276     * Runs "executeAfterBindingRemoval" scenario and checks which
277     * interceptions were performed.
278     * @throws Throwable
279     * @see ScenarioLoader#executeAfterBindingRemoval()
280     */

281    public void testAfterBindingRemovalExecution() throws Throwable JavaDoc
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