KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > aop > jdk15 > dynamic > prepareMethod > 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.prepareMethod;
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 using a class processed by aopc. This class (POJO class)
35  * was configured to have only its method "someMethod" prepared.
36  * @author Flavia Rainone
37  */

38 public class HotSwapDisabledTester extends AOPTestWithSetup
39 {
40    private ScenarioLoader scenarioLoader;
41    
42    public HotSwapDisabledTester(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     * Cheks that only the POJO method "someMethod" is advised.
58     */

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

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

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

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

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

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

218    public void testPerClassPerInstanceInterception() throws Throwable JavaDoc
219    {
220       // run scenario
221
POJOWrappingInfo[] wrappingInfos = scenarioLoader.interceptPerClassPerInstance();
222       // check wrapping status
223
assertOnlyMethodWrapped(wrappingInfos);
224       // check interception counts
225
InterceptionsCount binding = BindingInterceptor.getInterceptionsCount();
226       assertEquals(1, binding.total);
227       assertEquals(0, binding.constructor);
228       assertEquals(0, binding.fieldRead);
229       assertEquals(0, binding.fieldWrite);
230       assertEquals(1, binding.method);
231       InterceptionsCount instance = InstanceInterceptor.getInterceptionsCount();
232       assertEquals(1, instance.total);
233       assertEquals(0, instance.constructor);
234       assertEquals(0, instance.fieldRead);
235       assertEquals(0, 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
assertOnlyMethodWrapped(wrappingInfos);
251       // check interception counts
252
InterceptionsCount binding = BindingInterceptor.getInterceptionsCount();
253       assertEquals(1, binding.total);
254       assertEquals(0, binding.constructor);
255       assertEquals(0, binding.fieldRead);
256       assertEquals(0, binding.fieldWrite);
257       assertEquals(1, binding.method);
258       InterceptionsCount instance = InstanceInterceptor.getInterceptionsCount();
259       assertEquals(3, instance.total);
260       assertEquals(0, instance.constructor);
261       assertEquals(0, instance.fieldRead);
262       assertEquals(0, instance.fieldWrite);
263       assertEquals(3, instance.method);
264    }
265    
266    /**
267     * Runs "executeAfterBindingRemoval" scenario and checks which
268     * interceptions were performed.
269     * @throws Throwable
270     * @see ScenarioLoader#executeAfterBindingRemoval()
271     */

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