KickJava   Java API By Example, From Geeks To Geeks.

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


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: BaseClassInterceptor00.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.interceptors.business.order.PrintOrder01Interceptor;
35 import org.objectweb.easybeans.tests.common.interceptors.business.order.PrintOrder02Interceptor;
36 import org.objectweb.easybeans.tests.common.interceptors.business.order.PrintOrder03Interceptor;
37 import org.objectweb.easybeans.tests.common.interceptors.business.order.PrintOrder04Interceptor;
38 import org.testng.annotations.Test;
39
40 /**
41  * Verifies if the order to execute the class and method interceptors is
42  * correct.
43  * @author Gisele Pinheiro Souza
44  * @author Eduardo Studzinski Estima de Castro
45  */

46 public class BaseClassInterceptor00 {
47
48     /**
49      * Bean used to implement the test.
50      */

51     private ItfClassInterceptor<Integer JavaDoc> clBean;
52
53     /**
54      * Verifies if the interceptors are not executed.
55      * @input List with no values inside.
56      * @output List with only one value, the value inserted by the method.
57      */

58     @Test(groups = {"onlyClassInterceptor"})
59     public void testClassInterCallOrder00() {
60         // The arrays used to know what is the interceptor order
61
List JavaDoc<Integer JavaDoc> arResult = new ArrayList JavaDoc<Integer JavaDoc>();
62         List JavaDoc<Integer JavaDoc> arExpected = new ArrayList JavaDoc<Integer JavaDoc>();
63
64         // insert the value of method
65
// there are not interceptors in this class, so only
66
// the method will be executed
67
arExpected.add(SLSBClassInterceptorTest00.ORDER);
68
69         // gets the result
70
arResult = clBean.withoutMethodInterceptor(arResult);
71
72         // compares the two values
73
assertEquals(arExpected, arResult, "This class does not have interceptor, but the method is calling one.");
74     }
75
76     /**
77      * Verifies if the default interceptors are not executed.
78      * @input List with no values inside.
79      * @output List with only one value, the value inserted by the method.
80      */

81     @Test(groups = {"excludeDefaultInterceptor"})
82     public void testClassInterCallOrder01() {
83         // The arrays used to know what is the interceptor order
84
List JavaDoc<Integer JavaDoc> arResult = new ArrayList JavaDoc<Integer JavaDoc>();
85         List JavaDoc<Integer JavaDoc> arExpected = new ArrayList JavaDoc<Integer JavaDoc>();
86
87         // insert the value of method
88
// there are not default interceptors in this class, so only
89
// the metho will be executed
90
arExpected.add(SLSBClassInterceptorTest00.ORDER);
91
92         // gets the result
93
arResult = clBean.withExcludeDefaultInterceptor(arResult);
94
95         // compares the two values
96
assertEquals(arExpected, arResult,
97                 "This class does not have a default interceptor, but the method is calling one.");
98     }
99
100     /**
101      * Verifies if the interceptor classes are not executed with the annotation
102      * excludeClassInterceptor.
103      * @input List with no values inside.
104      * @output List with only one value, the value inserted by the method.
105      */

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

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

157     @Test(groups = {"excludeDefaultInterceptor", "excludeClassInterceptor", "methodInterceptor", "withInheritance"})
158     public void testClassInterCallOrder04() {
159         // The arrays used to know what is the interceptor order
160
List JavaDoc<Integer JavaDoc> arResult = new ArrayList JavaDoc<Integer JavaDoc>();
161         List JavaDoc<Integer JavaDoc> arExpected = new ArrayList JavaDoc<Integer JavaDoc>();
162
163         // insert the value of the interceptor
164
arExpected.add(PrintOrder01Interceptor.ORDER);
165         // insert the value of the interceptor
166
arExpected.add(PrintOrder02Interceptor.ORDER);
167         // insert the value of the interceptor
168
arExpected.add(PrintOrder03Interceptor.ORDER);
169         // insert the value of the interceptor
170
arExpected.add(PrintOrder04Interceptor.ORDER);
171         // insert the value of the method
172
arExpected.add(SLSBClassInterceptorTest00.ORDER);
173
174         // gets the result
175
arResult = clBean.excludeClassDefAndFourMtd(arResult);
176
177         // compares the two values
178
assertEquals(arExpected, arResult, "The method interceptors are running in the incorrect order.");
179     }
180
181     /**
182      * Verifies if the interceptor classes and the interceptor methods work well
183      * together, i.e., if they respect the order.
184      * @input List with no values inside.
185      * @output List with four values, the values inserted by the method
186      * interceptor and the value inserted by the method.
187      */

188     @Test(groups = {"methodInterceptor", "withInheritance"})
189     public void testClassInterCallOrder05() {
190         // The arrays used to know what is the interceptor order
191
List JavaDoc<Integer JavaDoc> arResult = new ArrayList JavaDoc<Integer JavaDoc>();
192         List JavaDoc<Integer JavaDoc> arExpected = new ArrayList JavaDoc<Integer JavaDoc>();
193
194         // insert the value of the interceptor
195
arExpected.add(PrintOrder01Interceptor.ORDER);
196         // insert the value of the interceptor
197
arExpected.add(PrintOrder02Interceptor.ORDER);
198         // insert the value of the interceptor
199
arExpected.add(PrintOrder03Interceptor.ORDER);
200         // insert the value of the method
201
arExpected.add(SLSBClassInterceptorTest00.ORDER);
202
203         // gets the result
204
arResult = clBean.withThreeMethodInterceptor(arResult);
205
206         // compares the two values
207
assertEquals(arExpected, arResult, "The method interceptor are running in the incorrect order.");
208     }
209
210     /**
211      * Verifies if the interceptor classes and the interceptor methods work well
212      * together, i.e., if they respect the order.
213      * @input List with no values inside.
214      * @output List with two values, the values inserted by the method
215      * interceptor and the value inserted by the method.
216      */

217     @Test(groups = {"methodInterceptor"})
218     public void testClassInterCallOrder06() {
219         // The arrays used to know what is the interceptor order
220
List JavaDoc<Integer JavaDoc> arResult = new ArrayList JavaDoc<Integer JavaDoc>();
221         List JavaDoc<Integer JavaDoc> arExpected = new ArrayList JavaDoc<Integer JavaDoc>();
222
223         // insert the value of the interceptor
224
arExpected.add(PrintOrder01Interceptor.ORDER);
225         // insert the value of the method
226
arExpected.add(SLSBClassInterceptorTest00.ORDER);
227
228         // gets the result
229
arResult = clBean.withOneMethodInterceptor(arResult);
230
231         // compares the two values
232
assertEquals(arExpected, arResult, "The method interceptor are running in the incorrect order.");
233     }
234
235     /**
236      * Sets bean used in the tests.
237      * @param bean The bean to set.
238      */

239     public void setBean(final ItfClassInterceptor<Integer JavaDoc> bean){
240         this.clBean = bean;
241     }
242 }
243
Popular Tags