KickJava   Java API By Example, From Geeks To Geeks.

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


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: BaseMiscInterceptor00.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.ItfSimpleBean;
33 import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.interceptororder.SLSBSimpleInterceptorTest00;
34 import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.interceptororder.SLSBSimpleInterceptorTest01;
35 import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.interceptororder.SLSBSimpleInterceptorTest02;
36 import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.interceptororder.SLSBSimpleInterceptorTest03;
37 import org.objectweb.easybeans.tests.common.interceptors.business.order.PrintOrder01Interceptor;
38 import org.objectweb.easybeans.tests.common.interceptors.business.order.PrintOrder03Interceptor;
39 import org.objectweb.easybeans.tests.common.interceptors.business.order.PrintOrder06Interceptor;
40 import org.testng.annotations.Test;
41
42 /**
43  * Verifies if the order to execute the method and callbacks interceptors is
44  * correct, also verifies the interceptors inheritance.
45  * @author Eduardo Studzinski Estima de Castro
46  * @author Gisele Pinheiro Souza
47  */

48 public class BaseMiscInterceptor00 {
49
50     /**
51      * Bean used to implement the test.
52      */

53     private ItfSimpleBean<Integer JavaDoc> mtBean00;
54
55     /**
56      * Bean used to implement the test.
57      */

58     private ItfSimpleBean<Integer JavaDoc> mtBean01;
59
60     /**
61      * Bean used to implement the test.
62      */

63     private ItfSimpleBean<Integer JavaDoc> mtBean02;
64
65     /**
66      * Bean used to implement the test.
67      */

68     private ItfSimpleBean<Integer JavaDoc> mtBean03;
69
70     /**
71      * Verifies if the interceptors are following the order of declaration.
72      * There is an interceptor inside the bean class that has public modifier
73      * access.
74      * @input List with no values inside
75      * @output List with 4 values, the value inserted by the method and value
76      * inserted by the interceptors.
77      */

78     @Test(groups = {"withInterceptor"})
79     public void testMiscPublicInterCallOrder() {
80         // The arrays used to know what is the interceptor order
81
List JavaDoc<Integer JavaDoc> arResult = new ArrayList JavaDoc<Integer JavaDoc>();
82         List JavaDoc<Integer JavaDoc> arExpected = new ArrayList JavaDoc<Integer JavaDoc>();
83
84         // insert the value of interceptor
85
arExpected.add(PrintOrder06Interceptor.ORDER);
86         // insert the value of interceptor
87
arExpected.add(PrintOrder01Interceptor.ORDER);
88         // insert the value of interceptor
89
arExpected.add(ItfSimpleBean.EMBEDDED_INTERCEPTOR);
90         // insert the value of the method
91
arExpected.add(SLSBSimpleInterceptorTest00.ORDER);
92
93         // gets the result
94
arResult = mtBean00.withInterceptors(arResult);
95
96         assertEquals(arExpected, arResult,
97                 "The method has class interceptors, a method interceptor and a public bean interceptor method"
98                         + " declared inside the bean; however it isn't running in the correct order.");
99     }
100
101     /**
102      * Verifies if the interceptors are following the order of declaration.
103      * There is an interceptor inside the bean class that has protected modifier
104      * access.
105      * @input List with no values inside
106      * @output List with 4 values, the value inserted by the method and value
107      * inserted by the interceptors.
108      */

109     @Test(groups = {"withInterceptor"})
110     public void testMiscProtectedInterCallOrder() {
111         // The arrays used to know what is the interceptor order
112
List JavaDoc<Integer JavaDoc> arResult = new ArrayList JavaDoc<Integer JavaDoc>();
113         List JavaDoc<Integer JavaDoc> arExpected = new ArrayList JavaDoc<Integer JavaDoc>();
114
115         // insert the value of interceptor
116
arExpected.add(PrintOrder06Interceptor.ORDER);
117         // insert the value of interceptor
118
arExpected.add(PrintOrder01Interceptor.ORDER);
119         // insert the value of interceptor
120
arExpected.add(ItfSimpleBean.EMBEDDED_INTERCEPTOR);
121         // insert the value of the method
122
arExpected.add(SLSBSimpleInterceptorTest01.ORDER);
123
124         // gets the result
125
arResult = mtBean01.withInterceptors(arResult);
126
127         // compares the two values
128
assertEquals(arExpected, arResult,
129                 "The method has class interceptors, a method interceptor and a protected bean interceptor method"
130                         + " declared inside the bean; however it isn't running in the correct order.");
131     }
132
133     /**
134      * Verifies if the interceptors are following the order of declaration.
135      * There is an interceptor inside the bean class that has private modifier
136      * access.
137      * @input List with no values inside
138      * @output List with 4 values, the value inserted by the method and value
139      * inserted by the interceptors.
140      */

141     @Test(groups = {"withInterceptor"})
142     public void testMiscPrivateInterCallOrder() {
143         // The arrays used to know what is the interceptor order
144
List JavaDoc<Integer JavaDoc> arResult = new ArrayList JavaDoc<Integer JavaDoc>();
145         List JavaDoc<Integer JavaDoc> arExpected = new ArrayList JavaDoc<Integer JavaDoc>();
146
147         // insert the value of interceptor
148
arExpected.add(PrintOrder06Interceptor.ORDER);
149         // insert the value of interceptor
150
arExpected.add(PrintOrder01Interceptor.ORDER);
151         // insert the value of interceptor
152
arExpected.add(ItfSimpleBean.EMBEDDED_INTERCEPTOR);
153         // insert the value of the method
154
arExpected.add(SLSBSimpleInterceptorTest02.ORDER);
155
156         // gets the result
157
arResult = mtBean02.withInterceptors(arResult);
158
159         // compares the two values
160
assertEquals(arExpected, arResult,
161                 "The method has class interceptors, a method interceptor and a protected bean interceptor method"
162                         + " declared inside the bean; however it isn't running in the correct order.");
163     }
164
165     /**
166      * Verifies if the interceptors are following the order of declaration.
167      * There is an interceptor inside the bean class that has public modifier
168      * access.
169      * @input List with no values inside
170      * @output List with 4 values, the value inserted by the method and value
171      * inserted by the interceptors.
172      */

173     @Test(groups = {"withInterceptor", "withInheritance"})
174     public void testMiscInheritanceInterCallOrder00() {
175         // The arrays used to know what is the interceptor order
176
List JavaDoc<Integer JavaDoc> arResult = new ArrayList JavaDoc<Integer JavaDoc>();
177         List JavaDoc<Integer JavaDoc> arExpected = new ArrayList JavaDoc<Integer JavaDoc>();
178
179         // insert the value of interceptor
180
arExpected.add(PrintOrder06Interceptor.ORDER);
181         // insert the value of interceptor
182
arExpected.add(PrintOrder03Interceptor.ORDER);
183         // insert the value of interceptor
184
arExpected.add(ItfSimpleBean.EMBEDDED_INTERCEPTOR);
185         // insert the value of the method
186
arExpected.add(SLSBSimpleInterceptorTest00.ORDER);
187
188         // gets the result
189
arResult = mtBean00.withInterceptorsInheritance(arResult);
190
191         // compares the two values
192
assertEquals(arExpected, arResult,
193                 "The method has class interceptors, a method interceptor with inheritance and a public bean interceptor method"
194                         + " declared inside the bean; however it isn't running in the correct order.");
195     }
196
197     /**
198      * Verifies if the interceptors are following the order of declaration.
199      * There is an interceptor inside the bean class that has protected modifier
200      * access.
201      * @input List with no values inside
202      * @output List with 4 values, the value inserted by the method and value
203      * inserted by the interceptors.
204      */

205     @Test(groups = {"withInterceptor", "withInheritance"})
206     public void testMiscInheritanceInterCallOrder01() {
207         // The arrays used to know what is the interceptor order
208
List JavaDoc<Integer JavaDoc> arResult = new ArrayList JavaDoc<Integer JavaDoc>();
209         List JavaDoc<Integer JavaDoc> arExpected = new ArrayList JavaDoc<Integer JavaDoc>();
210
211         // insert the value of interceptor
212
arExpected.add(PrintOrder06Interceptor.ORDER);
213         // insert the value of interceptor
214
arExpected.add(PrintOrder03Interceptor.ORDER);
215         // insert the value of interceptor
216
arExpected.add(ItfSimpleBean.EMBEDDED_INTERCEPTOR);
217         // insert the value of the method
218
arExpected.add(SLSBSimpleInterceptorTest01.ORDER);
219
220         // gets the result
221
arResult = mtBean01.withInterceptorsInheritance(arResult);
222
223         // compares the two values
224
assertEquals(arExpected, arResult,
225                 "The method has class interceptors, a method interceptor with inheritance and a protected bean interceptor method"
226                         + " declared inside the bean; however it isn't running in the correct order.");
227     }
228
229     /**
230      * Verifies if the interceptors are following the order of declaration.
231      * There is an interceptor inside the bean class that has private modifier
232      * access.
233      * @input List with no values inside
234      * @output List with 4 values, the value inserted by the method and value
235      * inserted by the interceptors.
236      */

237     @Test(groups = {"withInterceptor", "withInheritance"})
238     public void testMiscInheritanceInterCallOrder02() {
239         // The arrays used to know what is the interceptor order
240
List JavaDoc<Integer JavaDoc> arResult = new ArrayList JavaDoc<Integer JavaDoc>();
241         List JavaDoc<Integer JavaDoc> arExpected = new ArrayList JavaDoc<Integer JavaDoc>();
242
243         // insert the value of interceptor
244
arExpected.add(PrintOrder06Interceptor.ORDER);
245         // insert the value of interceptor
246
arExpected.add(PrintOrder03Interceptor.ORDER);
247         // insert the value of interceptor
248
arExpected.add(ItfSimpleBean.EMBEDDED_INTERCEPTOR);
249         // insert the value of the method
250
arExpected.add(SLSBSimpleInterceptorTest02.ORDER);
251
252         // gets the result
253
arResult = mtBean02.withInterceptorsInheritance(arResult);
254
255         // compares the two values
256
assertEquals(arExpected, arResult,
257                 "The method has class interceptors, a method interceptor with inheritance and a private bean interceptor method"
258                         + " declared inside the bean; however it isn't running in the correct order.");
259     }
260
261     /**
262      * Verifies if the interceptors are following the order of declaration.
263      * There is an interceptor inside the bean class that has package modifier
264      * access.
265      * @input List with no values inside
266      * @output List with 3 values, the value inserted by the method and value
267      * inserted by the interceptors.
268      */

269     @Test(groups = {"withInterceptor"})
270     public void testMiscPackageInterCallOrder() {
271         // The arrays used to know what is the interceptor order
272
List JavaDoc<Integer JavaDoc> arResult = new ArrayList JavaDoc<Integer JavaDoc>();
273         List JavaDoc<Integer JavaDoc> arExpected = new ArrayList JavaDoc<Integer JavaDoc>();
274
275         // insert the value of interceptor
276
arExpected.add(PrintOrder03Interceptor.ORDER);
277         // insert the value of interceptor
278
arExpected.add(ItfSimpleBean.EMBEDDED_INTERCEPTOR);
279         // insert the value of the method
280
arExpected.add(SLSBSimpleInterceptorTest03.ORDER);
281
282         // gets the result
283
arResult = mtBean03.withInterceptorsInheritance(arResult);
284
285         // compares the two values
286
assertEquals(arExpected, arResult,
287                 "The method has a method interceptor and a package level bean interceptor method"
288                         + " declared inside the bean; however it isn't running in the correct order.");
289     }
290
291     /**
292      * Sets bean used in the tests.
293      * @param bean00 The bean to set.
294      * @param bean01 The bean to set.
295      * @param bean02 The bean to set.
296      * @param bean03 The bean to set.
297      */

298     public void setBeans(final ItfSimpleBean<Integer JavaDoc> bean00, final ItfSimpleBean<Integer JavaDoc> bean01,
299             final ItfSimpleBean<Integer JavaDoc> bean02, final ItfSimpleBean<Integer JavaDoc> bean03) {
300         this.mtBean00 = bean00;
301         this.mtBean01 = bean01;
302         this.mtBean02 = bean02;
303         this.mtBean03 = bean03;
304     }
305 }
306
Popular Tags