KickJava   Java API By Example, From Geeks To Geeks.

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


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: BaseClassInterceptor02.java 820 2006-07-04 12:37:48Z 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.ItfClassInterceptor;
33 import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.interceptororder.SLSBClassInterceptorTest00;
34 import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.interceptororder.SLSBClassInterceptorTest02;
35 import org.objectweb.easybeans.tests.common.interceptors.business.order.PrintOrder01Interceptor;
36 import org.objectweb.easybeans.tests.common.interceptors.business.order.PrintOrder02Interceptor;
37 import org.objectweb.easybeans.tests.common.interceptors.business.order.PrintOrder03Interceptor;
38 import org.objectweb.easybeans.tests.common.interceptors.business.order.PrintOrder04Interceptor;
39 import org.objectweb.easybeans.tests.common.interceptors.business.order.PrintOrder06Interceptor;
40 import org.objectweb.easybeans.tests.common.interceptors.business.order.PrintOrder07Interceptor;
41 import org.objectweb.easybeans.tests.common.interceptors.business.order.PrintOrder08Interceptor;
42 import org.objectweb.easybeans.tests.common.interceptors.business.order.PrintOrder09Interceptor;
43 import org.testng.annotations.Test;
44
45 /**
46  * Verifies if the order to execute the class and method interceptors is
47  * correct.
48  * @author Eduardo Studzinski Estima de Castro
49  * @author Gisele Pinheiro Souza
50  */

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

56     private ItfClassInterceptor<Integer JavaDoc> clBean;
57
58     /**
59      * Verifies if the interceptors are not executed.
60      * @input List with no values inside.
61      * @output List with five values, the value inserted by the method and the
62      * value inserted by the interceptors.
63      */

64     @Test(groups = {"onlyClassInterceptor", "withInheritance"})
65     public void testClassInterCallOrder00() {
66         // The arrays used to know what is the interceptor order
67
List JavaDoc<Integer JavaDoc> arResult = new ArrayList JavaDoc<Integer JavaDoc>();
68         List JavaDoc<Integer JavaDoc> arExpected = new ArrayList JavaDoc<Integer JavaDoc>();
69
70         // insert the value of interceptor class
71
arExpected.add(PrintOrder06Interceptor.ORDER);
72         // insert the value of interceptor class
73
arExpected.add(PrintOrder07Interceptor.ORDER);
74         // insert the value of interceptor class
75
arExpected.add(PrintOrder08Interceptor.ORDER);
76         // insert the value of interceptor class
77
arExpected.add(PrintOrder09Interceptor.ORDER);
78         // insert the value of method
79
arExpected.add(SLSBClassInterceptorTest02.ORDER);
80
81         // gets the result
82
arResult = clBean.withoutMethodInterceptor(arResult);
83
84         // compares the two values
85
assertEquals(arExpected, arResult,
86                 "The class interceptors are not called or they are called in the incorrect order.");
87     }
88
89     /**
90      * Verifies if the interceptors are not executed.
91      * @input List with no values inside.
92      * @output List with five values, the value inserted by the method and the
93      * value inserted by the interceptors.
94      */

95     @Test(groups = {"excludeDefaultInterceptor", "onlyClassInterceptor", "withInheritance"})
96     public void testClassInterCallOrder01() {
97         // The arrays used to know what is the interceptor order
98
List JavaDoc<Integer JavaDoc> arResult = new ArrayList JavaDoc<Integer JavaDoc>();
99         List JavaDoc<Integer JavaDoc> arExpected = new ArrayList JavaDoc<Integer JavaDoc>();
100
101         // insert the value of interceptor class
102
arExpected.add(PrintOrder06Interceptor.ORDER);
103         // insert the value of interceptor class
104
arExpected.add(PrintOrder07Interceptor.ORDER);
105         // insert the value of interceptor class
106
arExpected.add(PrintOrder08Interceptor.ORDER);
107         // insert the value of interceptor class
108
arExpected.add(PrintOrder09Interceptor.ORDER);
109         // insert the value of method
110
arExpected.add(SLSBClassInterceptorTest02.ORDER);
111         // gets the result
112
arResult = clBean.withExcludeDefaultInterceptor(arResult);
113
114         // compares the two values
115
assertEquals(arExpected, arResult,
116                 "The class interceptors are not called or they are called in the incorrect order.");
117     }
118
119     /**
120      * Verifies if the interceptor classes are not executed with the annotation
121      * excludeClassInterceptor.
122      * @input List with no values inside.
123      * @output List with only one value, the value inserted by the method.
124      */

125     @Test(groups = {"excludeClassInterceptor", "onlyClassInterceptor"})
126     public void testClassInterCallOrder02() {
127         // The arrays used to know what is the interceptor order
128
List JavaDoc<Integer JavaDoc> arResult = new ArrayList JavaDoc<Integer JavaDoc>();
129         List JavaDoc<Integer JavaDoc> arExpected = new ArrayList JavaDoc<Integer JavaDoc>();
130
131         // insert the value of the method
132
arExpected.add(SLSBClassInterceptorTest02.ORDER);
133
134         // gets the result
135
arResult = clBean.withExcludeClassInterceptor(arResult);
136
137         // compares the two values
138
assertEquals(arExpected, arResult,
139                 "The method has excludeClassInterceptor annotation, but it is calling the interceptor.");
140     }
141
142     /**
143      * Verifies if the interceptor classes are not executed with the annotation
144      * excludeClassInterceptor. Also, this test verifies if the annotation doesn't
145      * modify the interceptor method execution.
146      * @input List with no values inside.
147      * @output List with two values, the value inserted by the method
148      * interceptor and the value inserted by the method.
149      */

150     @Test(groups = {"methodInterceptor", "excludeClassInterceptor"})
151     public void testClassInterCallOrder03() {
152         // The arrays used to know what is the interceptor order
153
List JavaDoc<Integer JavaDoc> arResult = new ArrayList JavaDoc<Integer JavaDoc>();
154         List JavaDoc<Integer JavaDoc> arExpected = new ArrayList JavaDoc<Integer JavaDoc>();
155
156         // insert the value of the interceptor
157
arExpected.add(PrintOrder01Interceptor.ORDER);
158         // insert the value of the method
159
arExpected.add(SLSBClassInterceptorTest02.ORDER);
160
161         // gets the result
162
arResult = clBean.excludeClassAndOneMtd(arResult);
163
164         // compares the two values
165
assertEquals(arExpected, arResult,
166                 "This method has the excludeClassInterceptor, but it is not executing the method interceptor correctly.");
167     }
168
169     /**
170      * Verifies if the interceptor classes are not executed with the annotation
171      * excludeClassInterceptor. Also, this test verifies if the annotation doesn't
172      * modify many interceptor method executions.
173      * @input List with no values inside.
174      * @output List with two values, the value inserted by the method
175      * interceptor and the value inserted by the method.
176      */

177     @Test(groups = {"excludeDefaultInterceptor", "excludeClassInterceptor", "methodInterceptor", "withInheritance"})
178     public void testClassInterCallOrder04() {
179         // The arrays used to know what is the interceptor order
180
List JavaDoc<Integer JavaDoc> arResult = new ArrayList JavaDoc<Integer JavaDoc>();
181         List JavaDoc<Integer JavaDoc> arExpected = new ArrayList JavaDoc<Integer JavaDoc>();
182
183         // insert the value of the interceptor
184
arExpected.add(PrintOrder01Interceptor.ORDER);
185         // insert the value of the interceptor
186
arExpected.add(PrintOrder02Interceptor.ORDER);
187         // insert the value of the interceptor
188
arExpected.add(PrintOrder03Interceptor.ORDER);
189         // insert the value of the interceptor
190
arExpected.add(PrintOrder04Interceptor.ORDER);
191         // insert the value of the method
192
arExpected.add(SLSBClassInterceptorTest02.ORDER);
193
194         // gets the result
195
arResult = clBean.excludeClassDefAndFourMtd(arResult);
196
197         // compares the two values
198
assertEquals(arExpected, arResult,
199                 "This method has the excludeClassInterceptor, but it is not executing the method interceptors correctly.");
200     }
201
202     /**
203      * Verifies if the interceptor classes and the interceptor methods work well
204      * together, i.e., if they respect the order.
205      * @input List with no values inside.
206      * @output List with eight values, the values inserted by the method
207      * interceptor and the value inserted by the method.
208      */

209     @Test(groups = {"methodInterceptor", "withInheritance"})
210     public void testClassInterCallOrder05() {
211         // The arrays used to know what is the interceptor order
212
List JavaDoc<Integer JavaDoc> arResult = new ArrayList JavaDoc<Integer JavaDoc>();
213         List JavaDoc<Integer JavaDoc> arExpected = new ArrayList JavaDoc<Integer JavaDoc>();
214
215         // insert the value of interceptor class
216
arExpected.add(PrintOrder06Interceptor.ORDER);
217         // insert the value of interceptor class
218
arExpected.add(PrintOrder07Interceptor.ORDER);
219         // insert the value of interceptor class
220
arExpected.add(PrintOrder08Interceptor.ORDER);
221         // insert the value of interceptor class
222
arExpected.add(PrintOrder09Interceptor.ORDER);
223         // insert the value of the interceptor
224
arExpected.add(PrintOrder01Interceptor.ORDER);
225         // insert the value of the interceptor
226
arExpected.add(PrintOrder02Interceptor.ORDER);
227         // insert the value of the interceptor
228
arExpected.add(PrintOrder03Interceptor.ORDER);
229         // insert the value of the method
230
arExpected.add(SLSBClassInterceptorTest02.ORDER);
231
232         // gets the result
233
arResult = clBean.withThreeMethodInterceptor(arResult);
234
235         // compares the two values
236
assertEquals(arExpected, arResult,
237                 "The class and the method interceptors are not running in the correct order.");
238     }
239
240     /**
241      * Verifies if the interceptor classes and the interceptor methods work well
242      * together, i.e., if they respect the order.
243      * @input List with no values inside.
244      * @output List with two values, the values inserted by the method
245      * interceptor and the value inserted by the method.
246      */

247     @Test(groups = {"methodInterceptor", "withInheritance"})
248     public void testClassInterCallOrder06() {
249         // The arrays used to know what is the interceptor order
250
List JavaDoc<Integer JavaDoc> arResult = new ArrayList JavaDoc<Integer JavaDoc>();
251         List JavaDoc<Integer JavaDoc> arExpected = new ArrayList JavaDoc<Integer JavaDoc>();
252
253         // insert the value of interceptor class
254
arExpected.add(PrintOrder06Interceptor.ORDER);
255         // insert the value of interceptor class
256
arExpected.add(PrintOrder07Interceptor.ORDER);
257         // insert the value of interceptor class
258
arExpected.add(PrintOrder08Interceptor.ORDER);
259         // insert the value of interceptor class
260
arExpected.add(PrintOrder09Interceptor.ORDER);
261         // insert the value of the interceptor
262
arExpected.add(PrintOrder01Interceptor.ORDER);
263         // insert the value of the method
264
arExpected.add(SLSBClassInterceptorTest00.ORDER);
265
266         // gets the result
267
arResult = clBean.withOneMethodInterceptor(arResult);
268
269         // compares the two values
270
assertEquals(arExpected, arResult, "The method interceptor are running in the incorrect order.");
271     }
272
273     /**
274      * Sets bean used in the tests.
275      * @param bean The bean to set.
276      */

277     public void setBean(final ItfClassInterceptor<Integer JavaDoc> bean){
278         this.clBean = bean;
279     }
280 }
281
Popular Tags