KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > tests > interceptors > business > base > invocationorder > BaseMethodInterceptor


1 /**
2  * EasyBeans
3  * Copyright (C) 2006 Bull S.A.S.
4  * Contact: easybeans@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: BaseMethodInterceptor.java 821 2006-07-04 13:28:52Z studzine $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.easybeans.tests.interceptors.business.base.invocationorder;
26
27 import static org.objectweb.easybeans.tests.common.asserts.Assert.assertEquals;
28
29 import java.util.ArrayList JavaDoc;
30 import java.util.List JavaDoc;
31
32 import org.objectweb.easybeans.tests.common.ejbs.base.ItfMethodInterceptor;
33 import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.interceptororder.SLSBMethodInterceptorTest;
34 import org.objectweb.easybeans.tests.common.interceptors.business.basic.PackageInterceptor;
35 import org.objectweb.easybeans.tests.common.interceptors.business.basic.PrivateInterceptor;
36 import org.objectweb.easybeans.tests.common.interceptors.business.basic.ProtectedInterceptor;
37 import org.objectweb.easybeans.tests.common.interceptors.business.order.PrintOrder01Interceptor;
38 import org.objectweb.easybeans.tests.common.interceptors.business.order.PrintOrder02Interceptor;
39 import org.objectweb.easybeans.tests.common.interceptors.business.order.PrintOrder03Interceptor;
40 import org.objectweb.easybeans.tests.common.interceptors.business.order.PrintOrder04Interceptor;
41 import org.objectweb.easybeans.tests.common.interceptors.business.order.PrintOrder05Interceptor;
42 import org.testng.annotations.Test;
43
44 /**
45  * Verifies if the order to execute the method interceptors is
46  * correct.
47  * @author Eduardo Studzinski Estima de Castro
48  * @author Gisele Pinheiro Souza
49  */

50 public class BaseMethodInterceptor {
51
52     /**
53      * Bean used to implement the test.
54      */

55     private ItfMethodInterceptor<Integer JavaDoc> mtBean;
56
57     /**
58      * Verifies if the interceptors are not executed.
59      * @input List with no values inside
60      * @output List with only one value, the value inserted by the method
61      */

62     @Test(groups = {"withoutInterceptor"})
63     public void interceptorMethodTest00() {
64         // The arrays used to know what is the interceptor order
65
List JavaDoc<Integer JavaDoc> arResult = new ArrayList JavaDoc<Integer JavaDoc>();
66         List JavaDoc<Integer JavaDoc> arExpected = new ArrayList JavaDoc<Integer JavaDoc>();
67
68         // insert the value of the method
69
arExpected.add(SLSBMethodInterceptorTest.ORDER);
70
71         // gets the result
72
arResult = mtBean.withoutInterceptor(arResult);
73
74         // compares the two values
75
assertEquals(arExpected, arResult, "");
76     }
77
78     /**
79      * Verifies if the interceptor is executed.
80      * @input List with no values inside
81      * @output List with two values, the value inserted by the method and the
82      * value inserted by the interceptor
83      */

84     @Test(groups = {"withInterceptor"})
85     public void interceptorMethodTest02() {
86         // The arrays used to know what is the interceptor order
87
List JavaDoc<Integer JavaDoc> arResult = new ArrayList JavaDoc<Integer JavaDoc>();
88         List JavaDoc<Integer JavaDoc> arExpected = new ArrayList JavaDoc<Integer JavaDoc>();
89
90         // insert the value of the interceptor
91
arExpected.add(PrintOrder01Interceptor.ORDER);
92         // insert the value of the method
93
arExpected.add(SLSBMethodInterceptorTest.ORDER);
94
95         // gets the result
96
arResult = mtBean.withOneMethodInterceptor(arResult);
97
98         // compares the two values
99
assertEquals(arExpected, arResult, "The interceptor is not running or it is running in the incorrect order.");
100     }
101
102     /**
103      * Verifies if two interceptors are executed in order.
104      * @input List with no values inside
105      * @output List with three values, the value inserted by the method and the
106      * value inserted by the interceptors.
107      */

108     @Test(groups = {"withInterceptor"})
109     public void interceptorMethodTest03() {
110         // The arrays used to know what is the interceptor order
111
List JavaDoc<Integer JavaDoc> arResult = new ArrayList JavaDoc<Integer JavaDoc>();
112         List JavaDoc<Integer JavaDoc> arExpected = new ArrayList JavaDoc<Integer JavaDoc>();
113
114         // insert the value of the interceptor
115
arExpected.add(PrintOrder01Interceptor.ORDER);
116         // insert the value of the interceptor
117
arExpected.add(PrintOrder02Interceptor.ORDER);
118         // insert the value of the method
119
arExpected.add(SLSBMethodInterceptorTest.ORDER);
120
121         // gets the result
122
arResult = mtBean.withTwoMethodInterceptors(arResult);
123
124         // compares the two values
125
assertEquals(arExpected, arResult, "The interceptors are not called in the correct order.");
126     }
127
128     /**
129      * Verifies if many interceptors are executed in order.
130      * @input List with no values inside
131      * @output List with six values, the value inserted by the method and the
132      * value inserted by the interceptors.
133      */

134     @Test(groups = {"withInterceptor", "withInheritance"})
135     public void interceptorMethodTest04() {
136         // The arrays used to know what is the interceptor order
137
List JavaDoc<Integer JavaDoc> arResult = new ArrayList JavaDoc<Integer JavaDoc>();
138         List JavaDoc<Integer JavaDoc> arExpected = new ArrayList JavaDoc<Integer JavaDoc>();
139
140         // insert the value of the interceptor
141
arExpected.add(PrintOrder01Interceptor.ORDER);
142         // insert the value of the interceptor
143
arExpected.add(PrintOrder02Interceptor.ORDER);
144         // insert the value of the method
145
arExpected.add(PrintOrder03Interceptor.ORDER);
146         // insert the value of the interceptor
147
arExpected.add(PrintOrder04Interceptor.ORDER);
148         // insert the value of the interceptor
149
arExpected.add(PrintOrder05Interceptor.ORDER);
150         // insert the value of the method
151
arExpected.add(SLSBMethodInterceptorTest.ORDER);
152
153         // gets the result
154
arResult = mtBean.withFiveMethodInterceptors(arResult);
155
156         // compares the two values
157
assertEquals(arExpected, arResult, "The interceptors are not running in the correct order."
158                 + " Maybe there is a problem with the interceptors inheritance.");
159     }
160
161     /**
162      * Verifies if many interceptors are executed in order. This must repect the
163      * declaration order.
164      * @input List with no values inside
165      * @output List with six values, the value inserted by the method and the
166      * value inserted by the interceptors.
167      */

168     @Test(groups = {"withInterceptor", "withInheritance"})
169     public void interceptorMethodTest05() {
170         // The arrays used to know what is the interceptor order
171
List JavaDoc<Integer JavaDoc> arResult = new ArrayList JavaDoc<Integer JavaDoc>();
172         List JavaDoc<Integer JavaDoc> arExpected = new ArrayList JavaDoc<Integer JavaDoc>();
173
174         // insert the value of the interceptor
175
arExpected.add(PrintOrder05Interceptor.ORDER);
176         // insert the value of the interceptor
177
arExpected.add(PrintOrder04Interceptor.ORDER);
178         // insert the value of the method
179
arExpected.add(PrintOrder03Interceptor.ORDER);
180         // insert the value of the interceptor
181
arExpected.add(PrintOrder02Interceptor.ORDER);
182         // insert the value of the interceptor
183
arExpected.add(PrintOrder01Interceptor.ORDER);
184         // insert the value of the method
185
arExpected.add(SLSBMethodInterceptorTest.ORDER);
186
187         // gets the result
188
arResult = mtBean.withFiveMethodInterceptorsInverse(arResult);
189
190         // compares the two values
191
assertEquals(arExpected, arResult, "The interceptors are not running in the correct order."
192                 + " Maybe there is a problem with the interceptors inheritance.");
193     }
194
195     /**
196      * Verifies if interceptors are executed in order. All interceptors have a
197      * private method that intercepts.
198      * @input List with no values inside
199      * @output List with 4 values, the value inserted by the method and the
200      * value inserted by the interceptors.
201      */

202     @Test(groups = {"withInterceptor"})
203     public void interceptorMethodTest06() {
204         // The arrays used to know what is the interceptor order
205
List JavaDoc<Integer JavaDoc> arResult = new ArrayList JavaDoc<Integer JavaDoc>();
206         List JavaDoc<Integer JavaDoc> arExpected = new ArrayList JavaDoc<Integer JavaDoc>();
207
208         // insert the value of the interceptor
209
arExpected.add(PrivateInterceptor.ORDER);
210         // insert the value of the interceptor
211
arExpected.add(PrivateInterceptor.ORDER);
212         // insert the value of the interceptor
213
arExpected.add(PrivateInterceptor.ORDER);
214         // insert the value of the method
215
arExpected.add(SLSBMethodInterceptorTest.ORDER);
216
217         // gets the result
218
arResult = mtBean.withPrivateInterceptors(arResult);
219
220         // compares the two values
221
assertEquals(arExpected, arResult, "The interceptors with private method are not running in the correct order.");
222     }
223
224     /**
225      * Verifies if interceptors are executed in order. All interceptors have a
226      * protected method that intercepts.
227      * @input List with no values inside
228      * @output List with 3 values, the value inserted by the method and the
229      * value inserted by the interceptors.
230      */

231     @Test(groups = {"withInterceptor"})
232     public void interceptorMethodTest07() {
233         // The arrays used to know what is the interceptor order
234
List JavaDoc<Integer JavaDoc> arResult = new ArrayList JavaDoc<Integer JavaDoc>();
235         List JavaDoc<Integer JavaDoc> arExpected = new ArrayList JavaDoc<Integer JavaDoc>();
236
237         // insert the value of the interceptor
238
arExpected.add(ProtectedInterceptor.ORDER);
239         // insert the value of the interceptor
240
arExpected.add(ProtectedInterceptor.ORDER);
241         // insert the value of the method
242
arExpected.add(SLSBMethodInterceptorTest.ORDER);
243
244         // gets the result
245
arResult = mtBean.withProtectedInterceptors(arResult);
246
247         // compares the two values
248
assertEquals(arExpected, arResult,
249                 "The interceptors with protected method are not running in the correct order.");
250     }
251
252     /**
253      * Verifies if interceptors are executed in order. There is interceptors
254      * with private, protected, and public method, also there is inheritance in
255      * one interceptor(PrintOrder03Interceptor.class).
256      * @input List with no values inside
257      * @output List with 9 values, the value inserted by the method and the
258      * value inserted by the interceptors.
259      */

260     @Test(groups = {"withInterceptor", "withInheritance"})
261     public void interceptorMethodTest08() {
262         // The arrays used to know what is the interceptor order
263
List JavaDoc<Integer JavaDoc> arResult = new ArrayList JavaDoc<Integer JavaDoc>();
264         List JavaDoc<Integer JavaDoc> arExpected = new ArrayList JavaDoc<Integer JavaDoc>();
265
266         // insert the value of the interceptor
267
arExpected.add(PrivateInterceptor.ORDER);
268         // insert the value of the interceptor
269
arExpected.add(ProtectedInterceptor.ORDER);
270         // insert the value of the interceptor
271
arExpected.add(PrintOrder01Interceptor.ORDER);
272         // insert the value of the interceptor
273
arExpected.add(PrivateInterceptor.ORDER);
274         // insert the value of the interceptor
275
arExpected.add(PrintOrder03Interceptor.ORDER);
276         // insert the value of the interceptor
277
arExpected.add(PrivateInterceptor.ORDER);
278         // insert the value of the interceptor
279
arExpected.add(ProtectedInterceptor.ORDER);
280         // insert the value of the interceptor
281
arExpected.add(ProtectedInterceptor.ORDER);
282         // insert the value of the method
283
arExpected.add(SLSBMethodInterceptorTest.ORDER);
284
285         // gets the result
286
arResult = mtBean.withPrivateProtectedPublicInterceptors(arResult);
287
288         // compares the two values
289
assertEquals(arExpected, arResult, "The interceptors are not running in the correct order.");
290     }
291
292     /**
293      * Verifies if interceptors are executed in order. There is interceptors
294      * with package method modifier.
295      * @input List with no values inside
296      * @output List with 5 values, the value inserted by the method and the
297      * value inserted by the interceptors.
298      */

299     @Test(groups = {"withInterceptor", "withInheritance"})
300     public void interceptorMethodTest09() {
301         // The arrays used to know what is the interceptor order
302
List JavaDoc<Integer JavaDoc> arResult = new ArrayList JavaDoc<Integer JavaDoc>();
303         List JavaDoc<Integer JavaDoc> arExpected = new ArrayList JavaDoc<Integer JavaDoc>();
304
305         // insert the value of the interceptor
306
arExpected.add(PackageInterceptor.ORDER);
307         // insert the value of the interceptor
308
arExpected.add(PackageInterceptor.ORDER);
309         // insert the value of the interceptor
310
arExpected.add(PackageInterceptor.ORDER);
311         // insert the value of the interceptor
312
arExpected.add(PackageInterceptor.ORDER);
313
314         // insert the value of the method
315
arExpected.add(SLSBMethodInterceptorTest.ORDER);
316
317         // gets the result
318
arResult = mtBean.withPackageInterceptors(arResult);
319
320         // compares the two values
321
assertEquals(arExpected, arResult, "The interceptors are not running in the correct order.");
322     }
323
324     /**
325      * Sets bean used in the tests.
326      * @param bean The bean to set.
327      */

328     public void setBean(final ItfMethodInterceptor<Integer JavaDoc> bean){
329         this.mtBean = bean;
330     }
331 }
332
Popular Tags