KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > aop > jdk15 > dynamic > prepareFieldGet > HotSwapDisabledTester


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.prepareFieldGet;
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 import org.jboss.test.aop.jdk15.dynamic.common.scenario.ScenarioRunner;
32
33 /**
34  * TestCase that checks the jboss aop behaviour in dynamic aop operations
35  * performed with hot swap disabled. The aop operations target class, (POJO class)
36  * was configured to have only the field read joinponts prepared.
37  * @author Flavia Rainone
38  */

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

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

61    private void assertOnlyFieldReadWrapped(POJOWrappingInfo[] wrappingInfos) throws Exception JavaDoc
62    {
63       for (int i = 0; i < wrappingInfos.length; i++)
64       {
65          assertFalse(wrappingInfos[i].isConstructorWrapped());
66          assertTrue(wrappingInfos[i].isFieldReadWrapped());
67          assertFalse(wrappingInfos[i].isFieldWriteWrapped());
68          assertFalse(wrappingInfos[i].isMethodWrapped());
69       }
70    }
71    
72    /**
73     * Runs "interceptPerClassLoadAfter" scenario and checks which
74     * interceptions were performed.
75     * @throws Throwable
76     * @see ScenarioRunner#interceptPerClassLoadAfter()
77     */

78    public void testPerClassLoadAfterInterception() throws Throwable JavaDoc
79    {
80       // run scenario
81
POJOWrappingInfo[] wrappingInfos = scenarioLoader.interceptPerClassLoadAfter();
82       // check if java 5 is being used
83
if (((AOPTestDelegate)getDelegate()).getSystemProperties().getProperty("java5Agent") != null)
84       {
85          // check wrapping status
86
for (int i = 0; i < wrappingInfos.length; i++)
87          {
88             assertTrue(wrappingInfos[i].isConstructorWrapped());
89             assertTrue(wrappingInfos[i].isFieldReadWrapped());
90             assertTrue(wrappingInfos[i].isFieldWriteWrapped());
91             assertTrue(wrappingInfos[i].isMethodWrapped());
92          }
93          // check interception counts
94
InterceptionsCount instance = InstanceInterceptor.getInterceptionsCount();
95          assertEquals(0, instance.total);
96          InterceptionsCount binding = BindingInterceptor.getInterceptionsCount();
97          assertEquals(4, binding.total);
98          assertEquals(0, binding.constructor);
99          assertEquals(2, binding.fieldRead);
100          assertEquals(0, binding.fieldWrite);
101          assertEquals(2, binding.method);
102          return;
103       }
104       // check wrapping status
105
assertOnlyFieldReadWrapped(wrappingInfos);
106       // check interception counts
107
InterceptionsCount instance = InstanceInterceptor.getInterceptionsCount();
108       assertEquals(0, instance.total);
109       InterceptionsCount binding = BindingInterceptor.getInterceptionsCount();
110       assertEquals(2, binding.total);
111       assertEquals(0, binding.constructor);
112       assertEquals(2, binding.fieldRead);
113       assertEquals(0, binding.fieldWrite);
114       assertEquals(0, binding.method);
115    }
116    
117    /**
118     * Runs "interceptPerClassLoadBefore" scenario and checks which
119     * interceptions were performed.
120     * @throws Throwable
121     * @see ScenarioRunner#interceptPerClassLoadBefore()
122     */

123    public void testPerClassLoadBeforeInterception() throws Throwable JavaDoc
124    {
125       // run scenario
126
POJOWrappingInfo[] wrappingInfos = scenarioLoader.interceptPerClassLoadBefore();
127       // check wrapping status
128
assertOnlyFieldReadWrapped(wrappingInfos);
129       // check interception counts
130
InterceptionsCount instance = InstanceInterceptor.getInterceptionsCount();
131       assertEquals(0, instance.total);
132       InterceptionsCount binding = BindingInterceptor.getInterceptionsCount();
133       assertEquals(1, binding.total);
134       assertEquals(0, binding.constructor);
135       assertEquals(1, binding.fieldRead);
136       assertEquals(0, binding.fieldWrite);
137       assertEquals(0, binding.method);
138    }
139    
140    /**
141     * Runs "addAndRemoveBindingTwice" scenario and checks which
142     * interceptions were performed.
143     * @throws Throwable
144     * @see ScenarioLoader#interceptPerClassLoadBefore()
145     */

146    public void testAddAndRemoveBindingTwice() throws Throwable JavaDoc
147    {
148       // run scenario
149
POJOWrappingInfo[] wrappingInfos = scenarioLoader.addAndRemoveBindingTwice();
150       // check wrapping status
151
assertOnlyFieldReadWrapped(wrappingInfos);
152       // check interception counts
153
InterceptionsCount instance = InstanceInterceptor.getInterceptionsCount();
154       assertEquals(0, instance.total);
155       InterceptionsCount binding = BindingInterceptor.getInterceptionsCount();
156       assertEquals(2, binding.total);
157       assertEquals(0, binding.constructor);
158       assertEquals(2, binding.fieldRead);
159       assertEquals(0, binding.fieldWrite);
160       assertEquals(0, binding.method);
161    }
162
163    /**
164     * Runs "interceptPerInstance" scenario and checks which
165     * interceptions were performed.
166     * @throws Throwable
167     * @see ScenarioRunner#interceptPerInstance()
168     */

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

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

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

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

269    public void testAfterBindingRemovalExecution() throws Throwable JavaDoc
270    {
271       // run scenario
272
POJOWrappingInfo[] wrappingInfos = scenarioLoader.executeAfterBindingRemoval();
273       // check wrapping status
274
assertOnlyFieldReadWrapped(wrappingInfos);
275       // check interception counts
276
InterceptionsCount binding = BindingInterceptor.getInterceptionsCount();
277       assertEquals(0, binding.total);
278       InterceptionsCount instance = InstanceInterceptor.getInterceptionsCount();
279       assertEquals(0, instance.total);
280    }
281 }
Popular Tags