KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > aop > beanstyleconfig > ConfigTester


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.beanstyleconfig;
23
24 import junit.framework.Test;
25 import junit.framework.TestSuite;
26
27 import java.util.ArrayList JavaDoc;
28
29 import org.jboss.test.aop.AOPTestWithSetup;
30
31 /**
32  * Comment
33  *
34  * @author <a HREF="mailto:kabir.khan@jboss.org">Kabir Khan</a>
35  * @version $Revision: 45977 $
36  */

37 public class ConfigTester extends AOPTestWithSetup
38 {
39    public static Test suite()
40    {
41       TestSuite suite = new TestSuite("ConfigTester");
42       suite.addTestSuite(ConfigTester.class);
43       return suite;
44    }
45
46    public ConfigTester(String JavaDoc name)
47    {
48       super(name);
49    }
50
51    protected void setUp() throws Exception JavaDoc
52    {
53       System.out.println("setup");
54       super.setUp();
55       InvokedConfigs.clearData();
56    }
57
58    public void testPerVm() throws Exception JavaDoc
59    {
60       System.out.println("****** testPerVm");
61       POJO pojo = new POJO();
62       pojo.perVmMethod();
63
64       ArrayList JavaDoc invoked = InvokedConfigs.getInvokedConfigs();
65       assertEquals("Wrong number of interceptions in testPerVm", 2, invoked.size());
66
67       System.out.println("****** testPerVm (aspect)");
68       InvokedConfig invokedConfig = (InvokedConfig) invoked.get(0);
69       assertEquals("Wrong interceptor class in testPerVm", InterceptorPerVm.class.getName(), invokedConfig.name);
70       assertEquals("Wrong aspect int attribute for interceptor in testPerVm", 11, invokedConfig.intAttr);
71       assertEquals("Wrong aspect string for interceptor in testPerVm", InterceptorPerVm.class.getName(), invokedConfig.stringAttr);
72       assertNull("Advisor was not null in interceptor in testPerVm", invokedConfig.advisor);
73       assertNull("InstanceAdvisor was not null in interceptor in testPerVm", invokedConfig.instanceAdvisor);
74       assertNull("Joinpoint was not null in interceptor in testPerVm", invokedConfig.joinpoint);
75
76       System.out.println("****** testPerVm (interceptor)");
77       invokedConfig = (InvokedConfig) invoked.get(1);
78       assertEquals("Wrong aspect class in testPerVm", AdvicePerVm.class.getName(), invokedConfig.name);
79       assertEquals("Wrong aspect int attribute in testPerVm", 21, invokedConfig.intAttr);
80       assertEquals("Wrong aspect string attribute in testPerVm", AdvicePerVm.class.getName(), invokedConfig.stringAttr);
81       assertNull("Advisor was not null in aspect in testPerVm", invokedConfig.advisor);
82       assertNull("InstanceAdvisor was not null in aspect in testPerVm", invokedConfig.instanceAdvisor);
83       assertNull("Joinpoint was not null in aspect in testPerVm", invokedConfig.joinpoint);
84    }
85
86    public void testPerVmStatic() throws Exception JavaDoc
87    {
88       System.out.println("****** testPerVmStatic");
89       POJO.perVmMethodStatic();
90
91       ArrayList JavaDoc invoked = InvokedConfigs.getInvokedConfigs();
92       assertEquals("Wrong number of interceptions in testPerVmStatic", 2, invoked.size());
93
94       System.out.println("****** testPerVmStatic (aspect)");
95       InvokedConfig invokedConfig = (InvokedConfig) invoked.get(0);
96       assertEquals("Wrong interceptor class in testPerVmStatic", InterceptorPerVm.class.getName(), invokedConfig.name);
97       assertEquals("Wrong aspect int attribute for interceptor in testPerVmStatic", 11, invokedConfig.intAttr);
98       assertEquals("Wrong aspect string for interceptor in testPerVmStatic", InterceptorPerVm.class.getName(), invokedConfig.stringAttr);
99       assertNull("Advisor was not null in interceptor in testPerVmStatic", invokedConfig.advisor);
100       assertNull("InstanceAdvisor was not null in interceptor in testPerVmStatic", invokedConfig.instanceAdvisor);
101       assertNull("Joinpoint was not null in interceptor in testPerVmStatic", invokedConfig.joinpoint);
102
103       System.out.println("****** testPerVmStatic (interceptor)");
104       invokedConfig = (InvokedConfig) invoked.get(1);
105       assertEquals("Wrong aspect class in testPerVmStatic", AdvicePerVm.class.getName(), invokedConfig.name);
106       assertEquals("Wrong aspect int attribute in testPerVmStatic", 21, invokedConfig.intAttr);
107       assertEquals("Wrong aspect string attribute in testPerVmStatic", AdvicePerVm.class.getName(), invokedConfig.stringAttr);
108       assertNull("Advisor was not null in aspect in testPerVmStatic", invokedConfig.advisor);
109       assertNull("InstanceAdvisor was not null in aspect in testPerVmStatic", invokedConfig.instanceAdvisor);
110       assertNull("Joinpoint was not null in aspect in testPerVmStatic", invokedConfig.joinpoint);
111    }
112
113    public void testPerClass() throws Exception JavaDoc
114    {
115       System.out.println("****** testPerClass");
116       POJO pojo = new POJO();
117       pojo.perClassMethod();
118
119       ArrayList JavaDoc invoked = InvokedConfigs.getInvokedConfigs();
120       assertEquals("Wrong number of interceptions in testPerClass", invoked.size(), 2);
121
122       System.out.println("****** testPerClass (aspect)");
123       InvokedConfig invokedConfig = (InvokedConfig) invoked.get(0);
124       assertEquals("Wrong interceptor class in testPerClass", InterceptorPerClass.class.getName(), invokedConfig.name);
125       assertEquals("Wrong aspect int attribute for interceptor in testPerClass", 12, invokedConfig.intAttr);
126       assertEquals("Wrong aspect string for interceptor in testPerClass", InterceptorPerClass.class.getName(), invokedConfig.stringAttr);
127       assertNotNull("Advisor was null in interceptor in testPerClass", invokedConfig.advisor);
128       assertNull("InstanceAdvisor was not null in interceptor in testPerClass", invokedConfig.instanceAdvisor);
129       assertNull("Joinpoint was not null in interceptor in testPerClass", invokedConfig.joinpoint);
130
131       System.out.println("****** testPerClass (interceptor)");
132       invokedConfig = (InvokedConfig) invoked.get(1);
133       assertEquals("Wrong aspect class in testPerClass", AdvicePerClass.class.getName(), invokedConfig.name);
134       assertEquals("Wrong aspect int attribute in testPerClass", 22, invokedConfig.intAttr);
135       assertEquals("Wrong aspect string attribute in testPerClass", AdvicePerClass.class.getName(), invokedConfig.stringAttr);
136       assertNotNull("Advisor was null in aspect in testPerClass", invokedConfig.advisor);
137       assertNull("InstanceAdvisor was not null in aspect in testPerClass", invokedConfig.instanceAdvisor);
138       assertNull("Joinpoint was not null in aspect in testPerClass", invokedConfig.joinpoint);
139
140    }
141
142    public void testPerClassStatic() throws Exception JavaDoc
143    {
144       System.out.println("****** testPerClassStatic");
145       POJO.perClassMethodStatic();
146
147       ArrayList JavaDoc invoked = InvokedConfigs.getInvokedConfigs();
148       assertEquals("Wrong number of interceptions in testPerClassStatic", 2, invoked.size());
149
150       System.out.println("****** testPerClassStatic (aspect)");
151       InvokedConfig invokedConfig = (InvokedConfig) invoked.get(0);
152       assertEquals("Wrong interceptor class in testPerClassStatic", InterceptorPerClass.class.getName(), invokedConfig.name);
153       assertEquals("Wrong aspect int attribute for interceptor in testPerClassStatic", 12, invokedConfig.intAttr);
154       assertEquals("Wrong aspect string for interceptor in testPerClassStatic", InterceptorPerClass.class.getName(), invokedConfig.stringAttr);
155       assertNotNull("Advisor was null in interceptor in testPerClassStatic", invokedConfig.advisor);
156       assertNull("InstanceAdvisor was not null in interceptor in testPerClassStatic", invokedConfig.instanceAdvisor);
157       assertNull("Joinpoint was not null in interceptor in testPerClassStatic", invokedConfig.joinpoint);
158
159       System.out.println("****** testPerClassStatic (interceptor)");
160       invokedConfig = (InvokedConfig) invoked.get(1);
161       assertEquals("Wrong aspect class in testPerClassStatic", AdvicePerClass.class.getName(), invokedConfig.name);
162       assertEquals("Wrong aspect int attribute in testPerClassStatic", 22, invokedConfig.intAttr);
163       assertEquals("Wrong aspect string attribute in testPerClassStatic", AdvicePerClass.class.getName(), invokedConfig.stringAttr);
164       assertNotNull("Advisor was null in aspect in testPerClassStatic", invokedConfig.advisor);
165       assertNull("InstanceAdvisor was not null in aspect in testPerClassStatic", invokedConfig.instanceAdvisor);
166       assertNull("Joinpoint was not null in aspect in testPerClassStatic", invokedConfig.joinpoint);
167
168    }
169
170    public void testPerInstance() throws Exception JavaDoc
171    {
172       System.out.println("****** testPerInstance");
173       POJO pojo = new POJO();
174       pojo.perInstanceMethod();
175
176       ArrayList JavaDoc invoked = InvokedConfigs.getInvokedConfigs();
177       assertEquals("Wrong number of interceptions in testPerInstance", 2, invoked.size());
178
179       System.out.println("****** testPerInstance (aspect)");
180       InvokedConfig invokedConfig = (InvokedConfig) invoked.get(0);
181       assertEquals("Wrong interceptor class in testPerInstance", InterceptorPerInstance.class.getName(), invokedConfig.name);
182       assertEquals("Wrong aspect int attribute for interceptor in testPerInstance", 13, invokedConfig.intAttr);
183       assertEquals("Wrong aspect string for interceptor in testPerInstance", InterceptorPerInstance.class.getName(), invokedConfig.stringAttr);
184       assertNotNull("Advisor was null in interceptor in testPerInstance", invokedConfig.advisor);
185       assertNotNull("InstanceAdvisor was null in interceptor in testPerInstance", invokedConfig.instanceAdvisor);
186       assertNull("Joinpoint was not null in interceptor in testPerInstance", invokedConfig.joinpoint);
187
188       System.out.println("****** testPerInstance (interceptor)");
189       invokedConfig = (InvokedConfig) invoked.get(1);
190       assertEquals("Wrong aspect class in testPerInstance", AdvicePerInstance.class.getName(), invokedConfig.name);
191       assertEquals("Wrong aspect int attribute in testPerInstance", 23, invokedConfig.intAttr);
192       assertEquals("Wrong aspect string attribute in testPerInstance", AdvicePerInstance.class.getName(), invokedConfig.stringAttr);
193       assertNotNull("Advisor was null in aspect in testPerInstance", invokedConfig.advisor);
194       assertNotNull("InstanceAdvisor was null in aspect in testPerInstance", invokedConfig.instanceAdvisor);
195       assertNull("Joinpoint was not null in aspect in testPerInstance", invokedConfig.joinpoint);
196
197
198    }
199
200    public void testPerInstanceStatic() throws Exception JavaDoc
201    {
202       System.out.println("****** testPerInstanceStatic");
203       POJO.perInstanceMethodStatic();
204
205       ArrayList JavaDoc invoked = InvokedConfigs.getInvokedConfigs();
206       assertEquals("Wrong number of interceptions in testPerInstanceStatic", invoked.size(), 0);
207
208    }
209
210    public void testPerJoinpoint() throws Exception JavaDoc
211    {
212       System.out.println("****** testPerJoinpoint");
213       POJO pojo = new POJO();
214       pojo.perJoinpointMethod();
215
216       ArrayList JavaDoc invoked = InvokedConfigs.getInvokedConfigs();
217       assertEquals("Wrong number of interceptions in testPerJoinpoint", 2, invoked.size());
218
219       System.out.println("****** testPerJoinpoint (aspect)");
220       InvokedConfig invokedConfig = (InvokedConfig) invoked.get(0);
221       assertEquals("Wrong interceptor class in testPerJoinpoint", InterceptorPerJoinpoint.class.getName(), invokedConfig.name);
222       assertEquals("Wrong aspect int attribute for interceptor in testPerJoinpoint", 14, invokedConfig.intAttr);
223       assertEquals("Wrong aspect string for interceptor in testPerJoinpoint", InterceptorPerJoinpoint.class.getName(), invokedConfig.stringAttr);
224       assertNotNull("Advisor was null in interceptor in testPerJoinpoint", invokedConfig.advisor);
225       assertNotNull("InstanceAdvisor was null in interceptor in testPerJoinpoint", invokedConfig.instanceAdvisor);
226       assertNotNull("Joinpoint was null in interceptor in testPerJoinpoint", invokedConfig.joinpoint);
227
228       System.out.println("****** testPerJoinpoint (interceptor)");
229       invokedConfig = (InvokedConfig) invoked.get(1);
230       assertEquals("Wrong aspect class in testPerJoinpoint", AdvicePerJoinpoint.class.getName(), invokedConfig.name);
231       assertEquals("Wrong aspect int attribute in testPerJoinpoint", 24, invokedConfig.intAttr);
232       assertEquals("Wrong aspect string attribute in testPerJoinpoint", AdvicePerJoinpoint.class.getName(), invokedConfig.stringAttr);
233       assertNotNull("Advisor was null in aspect in testPerJoinpoint", invokedConfig.advisor);
234       assertNotNull("InstanceAdvisor was null in aspect in testPerJoinpoint", invokedConfig.instanceAdvisor);
235       assertNotNull("Joinpoint was null in aspect in testPerJoinpoint", invokedConfig.joinpoint);
236    }
237
238    public void testPerJoinpointStatic() throws Exception JavaDoc
239    {
240       System.out.println("****** testPerJoinpointStatic");
241       POJO.perJoinpointMethodStatic();
242
243       ArrayList JavaDoc invoked = InvokedConfigs.getInvokedConfigs();
244       assertEquals("Wrong number of interceptions in testPerJoinpointStatic", 2, invoked.size());
245
246       System.out.println("****** testPerJoinpointStatic (aspect)");
247       InvokedConfig invokedConfig = (InvokedConfig) invoked.get(0);
248       assertEquals("Wrong interceptor class in testPerJoinpointStatic", InterceptorPerJoinpoint.class.getName(), invokedConfig.name);
249       assertEquals("Wrong aspect int attribute for interceptor in testPerJoinpointStatic", 14, invokedConfig.intAttr);
250       assertEquals("Wrong aspect string for interceptor in testPerJoinpointStatic", InterceptorPerJoinpoint.class.getName(), invokedConfig.stringAttr);
251       assertNotNull("Advisor was null in interceptor in testPerJoinpointStatic", invokedConfig.advisor);
252       assertNull("InstanceAdvisor was not null in interceptor in testPerJoinpointStatic", invokedConfig.instanceAdvisor);
253       assertNotNull("Joinpoint was null in interceptor in testPerJoinpointStatic", invokedConfig.joinpoint);
254
255       System.out.println("****** testPerJoinpointStatic (interceptor)");
256       invokedConfig = (InvokedConfig) invoked.get(1);
257       assertEquals("Wrong aspect class in testPerJoinpointStatic", AdvicePerJoinpoint.class.getName(), invokedConfig.name);
258       assertEquals("Wrong aspect int attribute in testPerJoinpointStatic", 24, invokedConfig.intAttr);
259       assertEquals("Wrong aspect string attribute in testPerJoinpointStatic", AdvicePerJoinpoint.class.getName(), invokedConfig.stringAttr);
260       assertNotNull("Advisor was null in aspect in testPerJoinpointStatic", invokedConfig.advisor);
261       assertNull("InstanceAdvisor was not null in aspect in testPerJoinpointStatic", invokedConfig.instanceAdvisor);
262       assertNotNull("Joinpoint was null in aspect in testPerJoinpointStatic", invokedConfig.joinpoint);
263    }
264
265 }
266
Popular Tags