KickJava   Java API By Example, From Geeks To Geeks.

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


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: BaseClassInterceptor01.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.SLSBClassInterceptorTest01;
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.testng.annotations.Test;
41
42 /**
43  * Verifies if the order to execute the class and method interceptors is
44  * correct.
45  * @author Gisele Pinheiro Souza
46  * @author Eduardo Studzinski Estima de Castro
47  */

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

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

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

86     @Test(groups = {"excludeDefaultInterceptor", "onlyClassInterceptor"})
87     public void testClassInterCallOrder01() {
88         // The arrays used to know what is the interceptor order
89
List JavaDoc<Integer JavaDoc> arResult = new ArrayList JavaDoc<Integer JavaDoc>();
90         List JavaDoc<Integer JavaDoc> arExpected = new ArrayList JavaDoc<Integer JavaDoc>();
91
92         // insert the value of interceptor class
93
arExpected.add(PrintOrder06Interceptor.ORDER);
94         // insert the value of method
95
arExpected.add(SLSBClassInterceptorTest01.ORDER);
96
97         // gets the result
98
arResult = clBean.withExcludeDefaultInterceptor(arResult);
99
100         // compares the two values
101
assertEquals(arExpected, arResult,
102                 "The class interceptor is not called or it is called in the incorrect order.");
103     }
104
105     /**
106      * Verifies if the interceptor classes are not executed with the annotation
107      * excludeClassInterceptor.
108      * @input List with no values inside.
109      * @output List with only one value, the value inserted by the method.
110      */

111     @Test(groups = {"excludeClassInterceptor", "onlyClassInterceptor"})
112     public void testClassInterCallOrder02() {
113         // The arrays used to know what is the interceptor order
114
List JavaDoc<Integer JavaDoc> arResult = new ArrayList JavaDoc<Integer JavaDoc>();
115         List JavaDoc<Integer JavaDoc> arExpected = new ArrayList JavaDoc<Integer JavaDoc>();
116
117         // insert the value of the method
118
arExpected.add(SLSBClassInterceptorTest01.ORDER);
119
120         // gets the result
121
arResult = clBean.withExcludeClassInterceptor(arResult);
122
123         // compares the two values
124
assertEquals(arExpected, arResult,
125                 "The method has excludeClassInterceptor annotation, but it is calling the interceptor.");
126     }
127
128     /**
129      * Verifies if the interceptor classes are not executed with the annotation
130      * excludeClassInterceptor. Also, this test verifies if the annotation doesn't
131      * modify the interceptor method execution.
132      * @input List with no values inside.
133      * @output List with two values, the value inserted by the method
134      * interceptor and the value inserted by the method.
135      */

136     @Test(groups = {"methodInterceptor", "excludeClassInterceptor"})
137     public void testClassInterCallOrder03() {
138         // The arrays used to know what is the interceptor order
139
List JavaDoc<Integer JavaDoc> arResult = new ArrayList JavaDoc<Integer JavaDoc>();
140         List JavaDoc<Integer JavaDoc> arExpected = new ArrayList JavaDoc<Integer JavaDoc>();
141
142         // insert the value of the interceptor
143
arExpected.add(PrintOrder01Interceptor.ORDER);
144         // insert the value of the method
145
arExpected.add(SLSBClassInterceptorTest01.ORDER);
146
147         // gets the result
148
arResult = clBean.excludeClassAndOneMtd(arResult);
149
150         // compares the two values
151
assertEquals(arExpected, arResult,
152                 "This method has the excludeClassInterceptor, but it is not executing the method interceptor correctly.");
153     }
154
155     /**
156      * Verifies if the interceptor classes are not executed with the annotation
157      * excludeClassInterceptor. Also, this test verifies if the annotation doesn't
158      * modify many interceptor method executions.
159      * @input List with no values inside.
160      * @output List with five values, the value inserted by the
161      * interceptors and the value inserted by the method.
162      */

163     @Test(groups = {"excludeClassInterceptor", "methodInterceptor", "withInheritance"})
164     public void testClassInterCallOrder04() {
165         // The arrays used to know what is the interceptor order
166
List JavaDoc<Integer JavaDoc> arResult = new ArrayList JavaDoc<Integer JavaDoc>();
167         List JavaDoc<Integer JavaDoc> arExpected = new ArrayList JavaDoc<Integer JavaDoc>();
168
169         // insert the value of the interceptor
170
arExpected.add(PrintOrder01Interceptor.ORDER);
171         // insert the value of the interceptor
172
arExpected.add(PrintOrder02Interceptor.ORDER);
173         // insert the value of the interceptor
174
arExpected.add(PrintOrder03Interceptor.ORDER);
175         // insert the value of the interceptor
176
arExpected.add(PrintOrder04Interceptor.ORDER);
177         // insert the value of the method
178
arExpected.add(SLSBClassInterceptorTest01.ORDER);
179
180         // gets the result
181
arResult = clBean.excludeClassDefAndFourMtd(arResult);
182
183         // compares the two values
184
assertEquals(arExpected, arResult,
185                 "This method has the excludeClassInterceptor, but it is not executing the method interceptors correctly.");
186     }
187
188     /**
189      * Verifies if the interceptor classes and the interceptor methods work well
190      * together, i.e., if they respect the order.
191      * @input List with no values inside.
192      * @output List with four values, the values inserted by the method
193      * interceptor and the value inserted by the method.
194      */

195     @Test(groups = {"methodInterceptor", "withInheritance"})
196     public void testClassInterCallOrder05() {
197         // The arrays used to know what is the interceptor order
198
List JavaDoc<Integer JavaDoc> arResult = new ArrayList JavaDoc<Integer JavaDoc>();
199         List JavaDoc<Integer JavaDoc> arExpected = new ArrayList JavaDoc<Integer JavaDoc>();
200
201         // insert the value of the interceptor class
202
arExpected.add(PrintOrder06Interceptor.ORDER);
203         // insert the value of the interceptor
204
arExpected.add(PrintOrder01Interceptor.ORDER);
205         // insert the value of the interceptor
206
arExpected.add(PrintOrder02Interceptor.ORDER);
207         // insert the value of the interceptor
208
arExpected.add(PrintOrder03Interceptor.ORDER);
209         // insert the value of the method
210
arExpected.add(SLSBClassInterceptorTest01.ORDER);
211
212         // gets the result
213
arResult = clBean.withThreeMethodInterceptor(arResult);
214
215         // compares the two values
216
assertEquals(arExpected, arResult,
217                 "The class and the method interceptors are not running in the correct order.");
218     }
219
220     /**
221      * Verifies if the interceptor classes and the interceptor methods work well
222      * together, i.e., if they respect the order.
223      * @input List with no values inside.
224      * @output List with three values, the values inserted by the
225      * interceptors and the value inserted by the method.
226      */

227     @Test(groups = {"methodInterceptor"})
228     public void testClassInterCallOrder06() {
229         // The arrays used to know what is the interceptor order
230
List JavaDoc<Integer JavaDoc> arResult = new ArrayList JavaDoc<Integer JavaDoc>();
231         List JavaDoc<Integer JavaDoc> arExpected = new ArrayList JavaDoc<Integer JavaDoc>();
232
233         // insert the value of the interceptor
234
arExpected.add(PrintOrder06Interceptor.ORDER);
235         // insert the value of the interceptor
236
arExpected.add(PrintOrder01Interceptor.ORDER);
237         // insert the value of the method
238
arExpected.add(SLSBClassInterceptorTest00.ORDER);
239
240         // gets the result
241
arResult = clBean.withOneMethodInterceptor(arResult);
242
243         // compares the two values
244
assertEquals(arExpected, arResult, "The method interceptor are running in the incorrect order.");
245     }
246
247     /**
248      * Sets bean used in the tests.
249      * @param bean The bean to set.
250      */

251     public void setBean(final ItfClassInterceptor<Integer JavaDoc> bean){
252         this.clBean = bean;
253     }
254 }
255
Popular Tags