001: /**
002: * EasyBeans
003: * Copyright (C) 2006 Bull S.A.S.
004: * Contact: easybeans@ow2.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: BaseMethodInterceptor.java 1970 2007-10-16 11:49:25Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.tests.interceptors.business.base.invocationorder;
025:
026: import static org.ow2.easybeans.tests.common.asserts.Assert.assertEquals;
027:
028: import java.util.ArrayList;
029: import java.util.List;
030:
031: import org.ow2.easybeans.tests.common.ejbs.base.ItfMethodInterceptor;
032: import org.ow2.easybeans.tests.common.ejbs.stateless.containermanaged.interceptororder.SLSBMethodInterceptorTest;
033: import org.ow2.easybeans.tests.common.interceptors.business.basic.PackageInterceptor;
034: import org.ow2.easybeans.tests.common.interceptors.business.basic.PrivateInterceptor;
035: import org.ow2.easybeans.tests.common.interceptors.business.basic.ProtectedInterceptor;
036: import org.ow2.easybeans.tests.common.interceptors.business.order.PrintOrder01Interceptor;
037: import org.ow2.easybeans.tests.common.interceptors.business.order.PrintOrder02Interceptor;
038: import org.ow2.easybeans.tests.common.interceptors.business.order.PrintOrder03Interceptor;
039: import org.ow2.easybeans.tests.common.interceptors.business.order.PrintOrder04Interceptor;
040: import org.ow2.easybeans.tests.common.interceptors.business.order.PrintOrder05Interceptor;
041: import org.testng.annotations.Test;
042:
043: /**
044: * Verifies if the order to execute the method interceptors is
045: * correct.
046: * @author Eduardo Studzinski Estima de Castro
047: * @author Gisele Pinheiro Souza
048: */
049: public class BaseMethodInterceptor {
050:
051: /**
052: * Bean used to implement the test.
053: */
054: private ItfMethodInterceptor<Integer> mtBean;
055:
056: /**
057: * Verifies if the interceptors are not executed.
058: * @input List with no values inside
059: * @output List with only one value, the value inserted by the method
060: */
061: @Test(groups={"withoutInterceptor"})
062: public void interceptorMethodTest00() {
063: // The arrays used to know what is the interceptor order
064: List<Integer> arResult = new ArrayList<Integer>();
065: List<Integer> arExpected = new ArrayList<Integer>();
066:
067: // insert the value of the method
068: arExpected.add(SLSBMethodInterceptorTest.ORDER);
069:
070: // gets the result
071: arResult = mtBean.withoutInterceptor(arResult);
072:
073: // compares the two values
074: assertEquals(arExpected, arResult, "");
075: }
076:
077: /**
078: * Verifies if the interceptor is executed.
079: * @input List with no values inside
080: * @output List with two values, the value inserted by the method and the
081: * value inserted by the interceptor
082: */
083: @Test(groups={"withInterceptor"})
084: public void interceptorMethodTest02() {
085: // The arrays used to know what is the interceptor order
086: List<Integer> arResult = new ArrayList<Integer>();
087: List<Integer> arExpected = new ArrayList<Integer>();
088:
089: // insert the value of the interceptor
090: arExpected.add(PrintOrder01Interceptor.ORDER);
091: // insert the value of the method
092: arExpected.add(SLSBMethodInterceptorTest.ORDER);
093:
094: // gets the result
095: arResult = mtBean.withOneMethodInterceptor(arResult);
096:
097: // compares the two values
098: assertEquals(arExpected, arResult,
099: "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<Integer> arResult = new ArrayList<Integer>();
112: List<Integer> arExpected = new ArrayList<Integer>();
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,
126: "The interceptors are not called in the correct order.");
127: }
128:
129: /**
130: * Verifies if many interceptors are executed in order.
131: * @input List with no values inside
132: * @output List with six values, the value inserted by the method and the
133: * value inserted by the interceptors.
134: */
135: @Test(groups={"withInterceptor","withInheritance"})
136: public void interceptorMethodTest04() {
137: // The arrays used to know what is the interceptor order
138: List<Integer> arResult = new ArrayList<Integer>();
139: List<Integer> arExpected = new ArrayList<Integer>();
140:
141: // insert the value of the interceptor
142: arExpected.add(PrintOrder01Interceptor.ORDER);
143: // insert the value of the interceptor
144: arExpected.add(PrintOrder02Interceptor.ORDER);
145: // insert the value of the method
146: arExpected.add(PrintOrder03Interceptor.ORDER);
147: // insert the value of the interceptor
148: arExpected.add(PrintOrder04Interceptor.ORDER);
149: // insert the value of the interceptor
150: arExpected.add(PrintOrder05Interceptor.ORDER);
151: // insert the value of the method
152: arExpected.add(SLSBMethodInterceptorTest.ORDER);
153:
154: // gets the result
155: arResult = mtBean.withFiveMethodInterceptors(arResult);
156:
157: // compares the two values
158: assertEquals(
159: arExpected,
160: arResult,
161: "The interceptors are not running in the correct order."
162: + " Maybe there is a problem with the interceptors inheritance.");
163: }
164:
165: /**
166: * Verifies if many interceptors are executed in order. This must repect the
167: * declaration order.
168: * @input List with no values inside
169: * @output List with six values, the value inserted by the method and the
170: * value inserted by the interceptors.
171: */
172: @Test(groups={"withInterceptor","withInheritance"})
173: public void interceptorMethodTest05() {
174: // The arrays used to know what is the interceptor order
175: List<Integer> arResult = new ArrayList<Integer>();
176: List<Integer> arExpected = new ArrayList<Integer>();
177:
178: // insert the value of the interceptor
179: arExpected.add(PrintOrder05Interceptor.ORDER);
180: // insert the value of the interceptor
181: arExpected.add(PrintOrder04Interceptor.ORDER);
182: // insert the value of the method
183: arExpected.add(PrintOrder03Interceptor.ORDER);
184: // insert the value of the interceptor
185: arExpected.add(PrintOrder02Interceptor.ORDER);
186: // insert the value of the interceptor
187: arExpected.add(PrintOrder01Interceptor.ORDER);
188: // insert the value of the method
189: arExpected.add(SLSBMethodInterceptorTest.ORDER);
190:
191: // gets the result
192: arResult = mtBean.withFiveMethodInterceptorsInverse(arResult);
193:
194: // compares the two values
195: assertEquals(
196: arExpected,
197: arResult,
198: "The interceptors are not running in the correct order."
199: + " Maybe there is a problem with the interceptors inheritance.");
200: }
201:
202: /**
203: * Verifies if interceptors are executed in order. All interceptors have a
204: * private method that intercepts.
205: * @input List with no values inside
206: * @output List with 4 values, the value inserted by the method and the
207: * value inserted by the interceptors.
208: */
209: @Test(groups={"withInterceptor"})
210: public void interceptorMethodTest06() {
211: // The arrays used to know what is the interceptor order
212: List<Integer> arResult = new ArrayList<Integer>();
213: List<Integer> arExpected = new ArrayList<Integer>();
214:
215: // insert the value of the interceptor
216: arExpected.add(PrivateInterceptor.ORDER);
217: // insert the value of the interceptor
218: arExpected.add(PrivateInterceptor.ORDER);
219: // insert the value of the interceptor
220: arExpected.add(PrivateInterceptor.ORDER);
221: // insert the value of the method
222: arExpected.add(SLSBMethodInterceptorTest.ORDER);
223:
224: // gets the result
225: arResult = mtBean.withPrivateInterceptors(arResult);
226:
227: // compares the two values
228: assertEquals(arExpected, arResult,
229: "The interceptors with private method are not running in the correct order.");
230: }
231:
232: /**
233: * Verifies if interceptors are executed in order. All interceptors have a
234: * protected method that intercepts.
235: * @input List with no values inside
236: * @output List with 3 values, the value inserted by the method and the
237: * value inserted by the interceptors.
238: */
239: @Test(groups={"withInterceptor"})
240: public void interceptorMethodTest07() {
241: // The arrays used to know what is the interceptor order
242: List<Integer> arResult = new ArrayList<Integer>();
243: List<Integer> arExpected = new ArrayList<Integer>();
244:
245: // insert the value of the interceptor
246: arExpected.add(ProtectedInterceptor.ORDER);
247: // insert the value of the interceptor
248: arExpected.add(ProtectedInterceptor.ORDER);
249: // insert the value of the method
250: arExpected.add(SLSBMethodInterceptorTest.ORDER);
251:
252: // gets the result
253: arResult = mtBean.withProtectedInterceptors(arResult);
254:
255: // compares the two values
256: assertEquals(arExpected, arResult,
257: "The interceptors with protected method are not running in the correct order.");
258: }
259:
260: /**
261: * Verifies if interceptors are executed in order. There is interceptors
262: * with private, protected, and public method, also there is inheritance in
263: * one interceptor(PrintOrder03Interceptor.class).
264: * @input List with no values inside
265: * @output List with 9 values, the value inserted by the method and the
266: * value inserted by the interceptors.
267: */
268: @Test(groups={"withInterceptor","withInheritance"})
269: public void interceptorMethodTest08() {
270: // The arrays used to know what is the interceptor order
271: List<Integer> arResult = new ArrayList<Integer>();
272: List<Integer> arExpected = new ArrayList<Integer>();
273:
274: // insert the value of the interceptor
275: arExpected.add(PrivateInterceptor.ORDER);
276: // insert the value of the interceptor
277: arExpected.add(ProtectedInterceptor.ORDER);
278: // insert the value of the interceptor
279: arExpected.add(PrintOrder01Interceptor.ORDER);
280: // insert the value of the interceptor
281: arExpected.add(PrivateInterceptor.ORDER);
282: // insert the value of the interceptor
283: arExpected.add(PrintOrder03Interceptor.ORDER);
284: // insert the value of the interceptor
285: arExpected.add(PrivateInterceptor.ORDER);
286: // insert the value of the interceptor
287: arExpected.add(ProtectedInterceptor.ORDER);
288: // insert the value of the interceptor
289: arExpected.add(ProtectedInterceptor.ORDER);
290: // insert the value of the method
291: arExpected.add(SLSBMethodInterceptorTest.ORDER);
292:
293: // gets the result
294: arResult = mtBean
295: .withPrivateProtectedPublicInterceptors(arResult);
296:
297: // compares the two values
298: assertEquals(arExpected, arResult,
299: "The interceptors are not running in the correct order.");
300: }
301:
302: /**
303: * Verifies if interceptors are executed in order. There is interceptors
304: * with package method modifier.
305: * @input List with no values inside
306: * @output List with 5 values, the value inserted by the method and the
307: * value inserted by the interceptors.
308: */
309: @Test(groups={"withInterceptor","withInheritance"})
310: public void interceptorMethodTest09() {
311: // The arrays used to know what is the interceptor order
312: List<Integer> arResult = new ArrayList<Integer>();
313: List<Integer> arExpected = new ArrayList<Integer>();
314:
315: // insert the value of the interceptor
316: arExpected.add(PackageInterceptor.ORDER);
317: // insert the value of the interceptor
318: arExpected.add(PackageInterceptor.ORDER);
319: // insert the value of the interceptor
320: arExpected.add(PackageInterceptor.ORDER);
321: // insert the value of the interceptor
322: arExpected.add(PackageInterceptor.ORDER);
323:
324: // insert the value of the method
325: arExpected.add(SLSBMethodInterceptorTest.ORDER);
326:
327: // gets the result
328: arResult = mtBean.withPackageInterceptors(arResult);
329:
330: // compares the two values
331: assertEquals(arExpected, arResult,
332: "The interceptors are not running in the correct order.");
333: }
334:
335: /**
336: * Sets bean used in the tests.
337: * @param bean The bean to set.
338: */
339: public void setBean(final ItfMethodInterceptor<Integer> bean) {
340: this.mtBean = bean;
341: }
342: }
|