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