KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > aop > jdk15 > dynamic > prepareConstructor > 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.prepareConstructor;
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 /**
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 constructor joinpont 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 constructor joinpoint is wrapped.
59     * @param wrappingInfos contains the joinpoints wrapping informations to be checked.
60     */

61    private void assertOnlyConstructorWrapped(POJOWrappingInfo[] wrappingInfos) throws Exception JavaDoc
62    {
63       for (int i = 0; i < wrappingInfos.length; i++)
64       {
65          assertTrue(wrappingInfos[i].isConstructorWrapped());
66          assertFalse(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 ScenarioLoader#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(2, binding.constructor);
99          assertEquals(0, binding.fieldRead);
100          assertEquals(0, binding.fieldWrite);
101          assertEquals(2, binding.method);
102          return;
103       }
104       // check wrapping status
105
assertOnlyConstructorWrapped(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(2, binding.constructor);
112       assertEquals(0, 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 ScenarioLoader#interceptPerClassLoadBefore()
122     */

123    public void testPerClassLoadBeforeInterception() throws Throwable JavaDoc
124    {
125       // run scenario
126
POJOWrappingInfo[] wrappingInfos = scenarioLoader.interceptPerClassLoadBefore();
127       // check wrapping status
128
assertOnlyConstructorWrapped(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(1, binding.constructor);
135       assertEquals(0, 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
assertOnlyConstructorWrapped(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(2, binding.constructor);
158       assertEquals(0, 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 ScenarioLoader#interceptPerInstance()
168     */

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

188    public void testPerInstanceGcInterception() throws Throwable JavaDoc
189    {
190       // run scenario
191
POJOWrappingInfo[] wrappingInfos = scenarioLoader.interceptPerInstanceGC();
192       // check wrapping status
193
assertOnlyConstructorWrapped(wrappingInfos);
194       // check interception counts
195
InterceptionsCount instance = InstanceInterceptor.getInterceptionsCount();
196       assertEquals(0, instance.total);
197       InterceptionsCount binding = BindingInterceptor.getInterceptionsCount();
198       assertEquals(0, binding.total);
199    }
200    
201    /**
202     * Runs "interceptPerClassPerInstance" scenario and checks which
203     * interceptions were performed.
204     * @throws Throwable
205     * @see ScenarioLoader#interceptPerClassPerInstance()
206     */

207    public void testPerClassPerInstanceInterception() throws Throwable JavaDoc
208    {
209       // run scenario
210
POJOWrappingInfo[] wrappingInfos = scenarioLoader.interceptPerClassPerInstance();
211       // check wrapping status
212
assertOnlyConstructorWrapped(wrappingInfos);
213       // check interception counts
214
InterceptionsCount instance = InstanceInterceptor.getInterceptionsCount();
215       assertEquals(0, instance.total);
216       InterceptionsCount binding = BindingInterceptor.getInterceptionsCount();
217       assertEquals(1, binding.total);
218       assertEquals(1, binding.constructor);
219       assertEquals(0, binding.fieldRead);
220       assertEquals(0, binding.fieldWrite);
221       assertEquals(0, binding.method);
222    }
223    
224    /**
225     * Runs "interceptPerInstancePerClass" scenario and checks which
226     * interceptions were performed.
227     * @throws Throwable
228     * @see ScenarioLoader#interceptPerInstancePerClass()
229     */

230    public void testPerInstancePerClassInterception() throws Throwable JavaDoc
231    {
232       // run scenario
233
POJOWrappingInfo[] wrappingInfos = scenarioLoader.interceptPerInstancePerClass();
234       // check wrapping status
235
assertOnlyConstructorWrapped(wrappingInfos);
236       // check interception counts
237
InterceptionsCount instance = InstanceInterceptor.getInterceptionsCount();
238       assertEquals(0, instance.total);
239       InterceptionsCount binding = BindingInterceptor.getInterceptionsCount();
240       assertEquals(1, binding.total);
241       assertEquals(1, binding.constructor);
242       assertEquals(0, binding.fieldRead);
243       assertEquals(0, binding.fieldWrite);
244       assertEquals(0, binding.method);
245    }
246    
247    /**
248     * Runs "executeAfterBindingRemoval" scenario and checks which
249     * interceptions were performed.
250     * @throws Throwable
251     * @see ScenarioLoader#executeAfterBindingRemoval()
252     */

253    public void testAfterBindingRemovalExecution() throws Throwable JavaDoc
254    {
255       // run scenario
256
POJOWrappingInfo[] wrappingInfos = scenarioLoader.executeAfterBindingRemoval();
257       // check wrapping status
258
assertOnlyConstructorWrapped(wrappingInfos);
259       // check interception counts
260
InterceptionsCount instance = InstanceInterceptor.getInterceptionsCount();
261       assertEquals(0, instance.total);
262       InterceptionsCount binding = BindingInterceptor.getInterceptionsCount();
263       assertEquals(0, binding.total);
264    }
265 }
Popular Tags