KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > aop > jdk15 > dynamic > prepareAll > 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.prepareAll;
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 all of its 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     * Runs "interceptPerClassLoadAfter" scenario and checks which
82     * interceptions were performed.
83     * @throws Throwable
84     * @see ScenarioLoader#interceptPerClassLoadAfter()
85     */

86    public void testPerClassLoadAfterInterception() throws Throwable JavaDoc
87    {
88       // run scenario
89
POJOWrappingInfo[] wrappingInfos = scenarioLoader.interceptPerClassLoadAfter();
90       // check wrapping status
91
assertFullyWrapped(wrappingInfos[0]);
92       assertUnwrapped(wrappingInfos[1]);
93       // check interception counts
94
InterceptionsCount instance = InstanceInterceptor.getInterceptionsCount();
95       assertEquals(0, instance.total);
96       InterceptionsCount binding = BindingInterceptor.getInterceptionsCount();
97       assertTrue(binding.total >= 5 && binding.total <= 8);
98       assertTrue(binding.constructor >= 1 && binding.constructor <= 2);
99       assertTrue(binding.fieldRead >= 1 && binding.fieldRead <= 2);
100       assertTrue(binding.fieldWrite >= 1 && binding.fieldWrite <= 2);
101       assertEquals(2, binding.method);
102    }
103    
104    /**
105     * Runs "interceptPerClassLoadBefore" scenario and checks which
106     * interceptions were performed.
107     * @throws Throwable
108     * @see ScenarioscenarioLoader#interceptPerClassLoadBefore()
109     */

110    public void testPerClassLoadBeforeInterception() throws Throwable JavaDoc
111    {
112       // run scenario
113
POJOWrappingInfo[] wrappingInfos = scenarioLoader.interceptPerClassLoadBefore();
114       // check wrapping status
115
assertUnwrapped(wrappingInfos[0]);
116       assertFullyWrapped(wrappingInfos[1]);
117       assertUnwrapped(wrappingInfos[2]);
118       // check interception counts
119
InterceptionsCount instance = InstanceInterceptor.getInterceptionsCount();
120       assertEquals(0, instance.total);
121       assertEquals(0, instance.constructor);
122       assertEquals(0, instance.fieldRead);
123       assertEquals(0, instance.fieldWrite);
124       assertEquals(0, instance.method);
125       InterceptionsCount binding = BindingInterceptor.getInterceptionsCount();
126       assertEquals(4, binding.total);
127       assertEquals(1, binding.constructor);
128       assertEquals(1, binding.fieldRead);
129       assertEquals(1, binding.fieldWrite);
130       assertEquals(1, binding.method);
131    }
132    
133    /**
134     * Runs "addAndRemoveBindingTwice" scenario and checks which
135     * interceptions were performed.
136     * @throws Throwable
137     * @see ScenarioLoader#interceptPerClassLoadBefore()
138     */

139    public void testAddAndRemoveBindingTwice() throws Throwable JavaDoc
140    {
141       // run scenario
142
POJOWrappingInfo[] wrappingInfos = scenarioLoader.addAndRemoveBindingTwice();
143       // check wrapping status
144
assertUnwrapped(wrappingInfos[0]);
145       assertFullyWrapped(wrappingInfos[1]);
146       assertUnwrapped(wrappingInfos[2]);
147       assertFullyWrapped(wrappingInfos[3]);
148       assertUnwrapped(wrappingInfos[4]);
149       // check interception counts
150
InterceptionsCount instance = InstanceInterceptor.getInterceptionsCount();
151       assertEquals(0, instance.total);
152       InterceptionsCount binding = BindingInterceptor.getInterceptionsCount();
153       assertEquals(8, binding.total);
154       assertEquals(2, binding.constructor);
155       assertEquals(2, binding.fieldRead);
156       assertEquals(2, binding.fieldWrite);
157       assertEquals(2, binding.method);
158    }
159    
160    /**
161     * Runs "interceptPerInstance" scenario and checks which
162     * interceptions were performed.
163     * @throws Throwable
164     * @see ScenarioLoader#interceptPerInstance()
165     */

166    public void testPerInstanceInterception() throws Throwable JavaDoc
167    {
168       // run scenario
169
POJOWrappingInfo[] wrappingInfos = scenarioLoader.interceptPerInstance();
170       // check wrapping status
171
assertUnwrapped(wrappingInfos[0]);
172       assertFullyWrapped(wrappingInfos[1]);
173       // check interception counts
174
InterceptionsCount binding = BindingInterceptor.getInterceptionsCount();
175       assertEquals(0, binding.total);
176       InterceptionsCount instance = InstanceInterceptor.getInterceptionsCount();
177       assertTrue(instance.total >= 3 && instance.total <= 6);
178       assertEquals(0, instance.constructor);
179       assertTrue(instance.fieldRead >= 1 && instance.fieldRead <= 2);
180       assertTrue(instance.fieldWrite >=1 && instance.fieldWrite <= 2);
181       assertTrue(instance.method >= 1 && instance.method <= 2);
182    }
183
184    
185    /**
186     * Runs "interceptPerInstanceGC" scenario and checks which
187     * interceptions were performed.
188     * @throws Throwable
189     * @see ScenarioLoader#interceptPerInstanceGC()
190     */

191    public void testPerInstanceGcInterception() throws Throwable JavaDoc
192    {
193       // run scenario
194
POJOWrappingInfo[] wrappingInfos = scenarioLoader.interceptPerInstanceGC();
195       // check wrapping status
196
assertUnwrapped(wrappingInfos[0]);
197       assertFullyWrapped(wrappingInfos[1]);
198       assertUnwrapped(wrappingInfos[2]);
199       // check interception counts
200
InterceptionsCount binding = BindingInterceptor.getInterceptionsCount();
201       assertEquals(0, binding.total);
202       InterceptionsCount instance = InstanceInterceptor.getInterceptionsCount();
203       assertTrue(instance.total >= 3 && instance.total <= 6);
204       assertEquals(0, instance.constructor);
205       assertTrue(instance.fieldRead >= 1 && instance.fieldRead <= 2);
206       assertTrue(instance.fieldWrite >=1 && instance.fieldWrite <= 2);
207       assertTrue(instance.method >= 1 && instance.method <= 2);
208    }
209    
210    /**
211     * Runs "interceptPerClassPerInstance" scenario and checks which
212     * interceptions were performed.
213     * @throws Throwable
214     * @see ScenarioLoader#interceptPerClassPerInstance()
215     */

216    public void testPerClassPerInstanceInterception() throws Throwable JavaDoc
217    {
218       // run scenario
219
POJOWrappingInfo[] wrappingInfos = scenarioLoader.interceptPerClassPerInstance();
220       // check wrapping status
221
assertUnwrapped(wrappingInfos[0]);
222       assertFullyWrapped(wrappingInfos[1]);
223       assertFullyWrapped(wrappingInfos[2]);
224       // check interception counts
225
InterceptionsCount binding = BindingInterceptor.getInterceptionsCount();
226       assertEquals(4, binding.total);
227       assertEquals(1, binding.constructor);
228       assertEquals(1, binding.fieldRead);
229       assertEquals(1, binding.fieldWrite);
230       assertEquals(1, binding.method);
231       InterceptionsCount instance = InstanceInterceptor.getInterceptionsCount();
232       assertEquals(3, instance.total);
233       assertEquals(0, instance.constructor);
234       assertEquals(1, instance.fieldRead);
235       assertEquals(1, instance.fieldWrite);
236       assertEquals(1, instance.method);
237    }
238    
239    /**
240     * Runs "interceptPerInstancePerClass" scenario and checks which
241     * interceptions were performed.
242     * @throws Throwable
243     * @see ScenarioLoader#interceptPerInstancePerClass()
244     */

245    public void testPerInstancePerClassInterception() throws Throwable JavaDoc
246    {
247       // run scenario
248
POJOWrappingInfo[] wrappingInfos = scenarioLoader.interceptPerInstancePerClass();
249       // check wrapping status
250
assertFullyWrapped(wrappingInfos[0]);
251       assertFullyWrapped(wrappingInfos[1]);
252       assertFullyWrapped(wrappingInfos[2]);
253       // check interception counts
254
InterceptionsCount binding = BindingInterceptor.getInterceptionsCount();
255       assertEquals(4, binding.total);
256       assertEquals(1, binding.constructor);
257       assertEquals(1, binding.fieldRead);
258       assertEquals(1, binding.fieldWrite);
259       assertEquals(1, binding.method);
260       InterceptionsCount instance = InstanceInterceptor.getInterceptionsCount();
261       assertTrue(instance.total >= 6 && instance.total <= 9);
262       assertEquals(0, instance.constructor);
263       assertTrue(instance.fieldRead >= 2 && instance.fieldRead <= 3);
264       assertTrue(instance.fieldWrite >= 2 && instance.fieldWrite <= 3);
265       assertTrue(instance.method >= 2 && instance.method <= 3);
266    }
267    
268    /**
269     * Runs "executeAfterBindingRemoval" scenario and checks which
270     * interceptions were performed.
271     * @throws Throwable
272     * @see ScenarioLoader#executeAfterBindingRemoval()
273     */

274    public void testAfterBindingRemovalExecution() throws Throwable JavaDoc
275    {
276       // run scenario
277
POJOWrappingInfo[] wrappingInfos = scenarioLoader.executeAfterBindingRemoval();
278       // check wrapping status
279
assertUnwrapped(wrappingInfos[0]);
280       // check interception counts
281
InterceptionsCount binding = BindingInterceptor.getInterceptionsCount();
282       assertEquals(0, binding.total);
283       InterceptionsCount instance = InstanceInterceptor.getInterceptionsCount();
284       assertEquals(0, instance.total);
285    }
286 }
Popular Tags