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: BaseClassInterceptor02.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.ItfClassInterceptor;
032: import org.ow2.easybeans.tests.common.ejbs.stateless.containermanaged.interceptororder.SLSBClassInterceptorTest00;
033: import org.ow2.easybeans.tests.common.ejbs.stateless.containermanaged.interceptororder.SLSBClassInterceptorTest02;
034: import org.ow2.easybeans.tests.common.interceptors.business.order.PrintOrder01Interceptor;
035: import org.ow2.easybeans.tests.common.interceptors.business.order.PrintOrder02Interceptor;
036: import org.ow2.easybeans.tests.common.interceptors.business.order.PrintOrder03Interceptor;
037: import org.ow2.easybeans.tests.common.interceptors.business.order.PrintOrder04Interceptor;
038: import org.ow2.easybeans.tests.common.interceptors.business.order.PrintOrder06Interceptor;
039: import org.ow2.easybeans.tests.common.interceptors.business.order.PrintOrder07Interceptor;
040: import org.ow2.easybeans.tests.common.interceptors.business.order.PrintOrder08Interceptor;
041: import org.ow2.easybeans.tests.common.interceptors.business.order.PrintOrder09Interceptor;
042: import org.testng.annotations.Test;
043:
044: /**
045: * Verifies if the order to execute the class and method interceptors is
046: * correct.
047: * @author Eduardo Studzinski Estima de Castro
048: * @author Gisele Pinheiro Souza
049: */
050: public class BaseClassInterceptor02 {
051:
052: /**
053: * Bean used to implement the test.
054: */
055: private ItfClassInterceptor<Integer> clBean;
056:
057: /**
058: * Verifies if the interceptors are not executed.
059: * @input List with no values inside.
060: * @output List with five values, the value inserted by the method and the
061: * value inserted by the interceptors.
062: */
063: @Test(groups={"onlyClassInterceptor","withInheritance"})
064: public void testClassInterCallOrder00() {
065: // The arrays used to know what is the interceptor order
066: List<Integer> arResult = new ArrayList<Integer>();
067: List<Integer> arExpected = new ArrayList<Integer>();
068:
069: // insert the value of interceptor class
070: arExpected.add(PrintOrder06Interceptor.ORDER);
071: // insert the value of interceptor class
072: arExpected.add(PrintOrder07Interceptor.ORDER);
073: // insert the value of interceptor class
074: arExpected.add(PrintOrder08Interceptor.ORDER);
075: // insert the value of interceptor class
076: arExpected.add(PrintOrder09Interceptor.ORDER);
077: // insert the value of method
078: arExpected.add(SLSBClassInterceptorTest02.ORDER);
079:
080: // gets the result
081: arResult = clBean.withoutMethodInterceptor(arResult);
082:
083: // compares the two values
084: assertEquals(
085: arExpected,
086: arResult,
087: "The class interceptors are not called or they are called in the incorrect order.");
088: }
089:
090: /**
091: * Verifies if the interceptors are not executed.
092: * @input List with no values inside.
093: * @output List with five values, the value inserted by the method and the
094: * value inserted by the interceptors.
095: */
096: @Test(groups={"excludeDefaultInterceptor","onlyClassInterceptor","withInheritance"})
097: public void testClassInterCallOrder01() {
098: // The arrays used to know what is the interceptor order
099: List<Integer> arResult = new ArrayList<Integer>();
100: List<Integer> arExpected = new ArrayList<Integer>();
101:
102: // insert the value of interceptor class
103: arExpected.add(PrintOrder06Interceptor.ORDER);
104: // insert the value of interceptor class
105: arExpected.add(PrintOrder07Interceptor.ORDER);
106: // insert the value of interceptor class
107: arExpected.add(PrintOrder08Interceptor.ORDER);
108: // insert the value of interceptor class
109: arExpected.add(PrintOrder09Interceptor.ORDER);
110: // insert the value of method
111: arExpected.add(SLSBClassInterceptorTest02.ORDER);
112: // gets the result
113: arResult = clBean.withExcludeDefaultInterceptor(arResult);
114:
115: // compares the two values
116: assertEquals(
117: arExpected,
118: arResult,
119: "The class interceptors are not called or they are called in the incorrect order.");
120: }
121:
122: /**
123: * Verifies if the interceptor classes are not executed with the annotation
124: * excludeClassInterceptor.
125: * @input List with no values inside.
126: * @output List with only one value, the value inserted by the method.
127: */
128: @Test(groups={"excludeClassInterceptor","onlyClassInterceptor"})
129: public void testClassInterCallOrder02() {
130: // The arrays used to know what is the interceptor order
131: List<Integer> arResult = new ArrayList<Integer>();
132: List<Integer> arExpected = new ArrayList<Integer>();
133:
134: // insert the value of the method
135: arExpected.add(SLSBClassInterceptorTest02.ORDER);
136:
137: // gets the result
138: arResult = clBean.withExcludeClassInterceptor(arResult);
139:
140: // compares the two values
141: assertEquals(
142: arExpected,
143: arResult,
144: "The method has excludeClassInterceptor annotation, but it is calling the interceptor.");
145: }
146:
147: /**
148: * Verifies if the interceptor classes are not executed with the annotation
149: * excludeClassInterceptor. Also, this test verifies if the annotation doesn't
150: * modify the interceptor method execution.
151: * @input List with no values inside.
152: * @output List with two values, the value inserted by the method
153: * interceptor and the value inserted by the method.
154: */
155: @Test(groups={"methodInterceptor","excludeClassInterceptor"})
156: public void testClassInterCallOrder03() {
157: // The arrays used to know what is the interceptor order
158: List<Integer> arResult = new ArrayList<Integer>();
159: List<Integer> arExpected = new ArrayList<Integer>();
160:
161: // insert the value of the interceptor
162: arExpected.add(PrintOrder01Interceptor.ORDER);
163: // insert the value of the method
164: arExpected.add(SLSBClassInterceptorTest02.ORDER);
165:
166: // gets the result
167: arResult = clBean.excludeClassAndOneMtd(arResult);
168:
169: // compares the two values
170: assertEquals(
171: arExpected,
172: arResult,
173: "This method has the excludeClassInterceptor, but it is not executing the method interceptor correctly.");
174: }
175:
176: /**
177: * Verifies if the interceptor classes are not executed with the annotation
178: * excludeClassInterceptor. Also, this test verifies if the annotation doesn't
179: * modify many interceptor method executions.
180: * @input List with no values inside.
181: * @output List with two values, the value inserted by the method
182: * interceptor and the value inserted by the method.
183: */
184: @Test(groups={"excludeDefaultInterceptor","excludeClassInterceptor","methodInterceptor","withInheritance"})
185: public void testClassInterCallOrder04() {
186: // The arrays used to know what is the interceptor order
187: List<Integer> arResult = new ArrayList<Integer>();
188: List<Integer> arExpected = new ArrayList<Integer>();
189:
190: // insert the value of the interceptor
191: arExpected.add(PrintOrder01Interceptor.ORDER);
192: // insert the value of the interceptor
193: arExpected.add(PrintOrder02Interceptor.ORDER);
194: // insert the value of the interceptor
195: arExpected.add(PrintOrder03Interceptor.ORDER);
196: // insert the value of the interceptor
197: arExpected.add(PrintOrder04Interceptor.ORDER);
198: // insert the value of the method
199: arExpected.add(SLSBClassInterceptorTest02.ORDER);
200:
201: // gets the result
202: arResult = clBean.excludeClassDefAndFourMtd(arResult);
203:
204: // compares the two values
205: assertEquals(
206: arExpected,
207: arResult,
208: "This method has the excludeClassInterceptor, but it is not executing the method interceptors correctly.");
209: }
210:
211: /**
212: * Verifies if the interceptor classes and the interceptor methods work well
213: * together, i.e., if they respect the order.
214: * @input List with no values inside.
215: * @output List with eight values, the values inserted by the method
216: * interceptor and the value inserted by the method.
217: */
218: @Test(groups={"methodInterceptor","withInheritance"})
219: public void testClassInterCallOrder05() {
220: // The arrays used to know what is the interceptor order
221: List<Integer> arResult = new ArrayList<Integer>();
222: List<Integer> arExpected = new ArrayList<Integer>();
223:
224: // insert the value of interceptor class
225: arExpected.add(PrintOrder06Interceptor.ORDER);
226: // insert the value of interceptor class
227: arExpected.add(PrintOrder07Interceptor.ORDER);
228: // insert the value of interceptor class
229: arExpected.add(PrintOrder08Interceptor.ORDER);
230: // insert the value of interceptor class
231: arExpected.add(PrintOrder09Interceptor.ORDER);
232: // insert the value of the interceptor
233: arExpected.add(PrintOrder01Interceptor.ORDER);
234: // insert the value of the interceptor
235: arExpected.add(PrintOrder02Interceptor.ORDER);
236: // insert the value of the interceptor
237: arExpected.add(PrintOrder03Interceptor.ORDER);
238: // insert the value of the method
239: arExpected.add(SLSBClassInterceptorTest02.ORDER);
240:
241: // gets the result
242: arResult = clBean.withThreeMethodInterceptor(arResult);
243:
244: // compares the two values
245: assertEquals(arExpected, arResult,
246: "The class and the method interceptors are not running in the correct order.");
247: }
248:
249: /**
250: * Verifies if the interceptor classes and the interceptor methods work well
251: * together, i.e., if they respect the order.
252: * @input List with no values inside.
253: * @output List with two values, the values inserted by the method
254: * interceptor and the value inserted by the method.
255: */
256: @Test(groups={"methodInterceptor","withInheritance"})
257: public void testClassInterCallOrder06() {
258: // The arrays used to know what is the interceptor order
259: List<Integer> arResult = new ArrayList<Integer>();
260: List<Integer> arExpected = new ArrayList<Integer>();
261:
262: // insert the value of interceptor class
263: arExpected.add(PrintOrder06Interceptor.ORDER);
264: // insert the value of interceptor class
265: arExpected.add(PrintOrder07Interceptor.ORDER);
266: // insert the value of interceptor class
267: arExpected.add(PrintOrder08Interceptor.ORDER);
268: // insert the value of interceptor class
269: arExpected.add(PrintOrder09Interceptor.ORDER);
270: // insert the value of the interceptor
271: arExpected.add(PrintOrder01Interceptor.ORDER);
272: // insert the value of the method
273: arExpected.add(SLSBClassInterceptorTest00.ORDER);
274:
275: // gets the result
276: arResult = clBean.withOneMethodInterceptor(arResult);
277:
278: // compares the two values
279: assertEquals(arExpected, arResult,
280: "The method interceptor are running in the incorrect order.");
281: }
282:
283: /**
284: * Sets bean used in the tests.
285: * @param bean The bean to set.
286: */
287: public void setBean(final ItfClassInterceptor<Integer> bean) {
288: this.clBean = bean;
289: }
290: }
|