KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > aop > jdk15 > dynamic > prepareAll > 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.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 disabled. 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 HotSwapDisabledTester extends AOPTestWithSetup
39 {
40    private ScenarioLoader scenarioLoader;
41  
42    public HotSwapDisabledTester(String JavaDoc name)
43    {
44       super(name);
45    }
46    /**
47     * Runs before each test method.
48     */

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

59    private void assertFullyWrapped(POJOWrappingInfo[] wrappingInfos) throws Exception JavaDoc
60    {
61       for (int i = 0; i < wrappingInfos.length; i++)
62       {
63          assertTrue(wrappingInfos[i].isConstructorWrapped());
64          assertTrue(wrappingInfos[i].isFieldReadWrapped());
65          assertTrue(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 wrapping status
81
assertFullyWrapped(wrappingInfos);
82       // check interception counts
83
InterceptionsCount instance = InstanceInterceptor.getInterceptionsCount();
84       assertEquals(0, instance.total);
85       InterceptionsCount binding = BindingInterceptor.getInterceptionsCount();
86       assertEquals(8, binding.total);
87       assertEquals(2, binding.constructor);
88       assertEquals(2, binding.fieldRead);
89       assertEquals(2, binding.fieldWrite);
90       assertEquals(2, binding.method);
91    }
92    
93    /**
94     * Runs "interceptPerClassLoadBefore" scenario and checks which
95     * interceptions were performed.
96     * @throws Throwable
97     * @see ScenarioLoader#interceptPerClassLoadBefore()
98     */

99    public void testPerClassLoadBeforeInterception() throws Throwable JavaDoc
100    {
101       // run scenario
102
POJOWrappingInfo[] wrappingInfos = scenarioLoader.interceptPerClassLoadBefore();
103       // check wrapping status
104
assertFullyWrapped(wrappingInfos);
105       // check interception counts
106
InterceptionsCount instance = InstanceInterceptor.getInterceptionsCount();
107       assertEquals(0, instance.total);
108       InterceptionsCount binding = BindingInterceptor.getInterceptionsCount();
109       assertEquals(4, binding.total);
110       assertEquals(1, binding.constructor);
111       assertEquals(1, binding.fieldRead);
112       assertEquals(1, binding.fieldWrite);
113       assertEquals(1, binding.method);
114    }
115    
116    /**
117     * Runs "addAndRemoveBindingTwice" scenario and checks which
118     * interceptions were performed.
119     * @throws Throwable
120     * @see ScenarioLoader#interceptPerClassLoadBefore()
121     */

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

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

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

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

218    public void testPerInstancePerClassInterception() throws Throwable JavaDoc
219    {
220       // run scenario
221
POJOWrappingInfo[] wrappingInfos = scenarioLoader.interceptPerInstancePerClass();
222       // check wrapping status
223
assertFullyWrapped(wrappingInfos);
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(9, instance.total);
233       assertEquals(0, instance.constructor);
234       assertEquals(3, instance.fieldRead);
235       assertEquals(3, instance.fieldWrite);
236       assertEquals(3, instance.method);
237    }
238    
239    /**
240     * Runs "executeAfterBindingRemoval" scenario and checks which
241     * interceptions were performed.
242     * @throws Throwable
243     * @see ScenarioLoader#executeAfterBindingRemoval()
244     */

245    public void testAfterBindingRemovalExecution() throws Throwable JavaDoc
246    {
247       // run scenario
248
POJOWrappingInfo[] wrappingInfos = scenarioLoader.executeAfterBindingRemoval();
249       // check wrapping status
250
assertFullyWrapped(wrappingInfos);
251       // check interception counts
252
InterceptionsCount binding = BindingInterceptor.getInterceptionsCount();
253       assertEquals(0, binding.total);
254       InterceptionsCount instance = InstanceInterceptor.getInterceptionsCount();
255       assertEquals(0, instance.total);
256    }
257 }
Popular Tags