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: BaseMiscInterceptor00.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.ItfSimpleBean;
032: import org.ow2.easybeans.tests.common.ejbs.stateless.containermanaged.interceptororder.SLSBSimpleInterceptorTest00;
033: import org.ow2.easybeans.tests.common.ejbs.stateless.containermanaged.interceptororder.SLSBSimpleInterceptorTest01;
034: import org.ow2.easybeans.tests.common.ejbs.stateless.containermanaged.interceptororder.SLSBSimpleInterceptorTest02;
035: import org.ow2.easybeans.tests.common.ejbs.stateless.containermanaged.interceptororder.SLSBSimpleInterceptorTest03;
036: import org.ow2.easybeans.tests.common.interceptors.business.order.PrintOrder01Interceptor;
037: import org.ow2.easybeans.tests.common.interceptors.business.order.PrintOrder03Interceptor;
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 method and callbacks interceptors is
043: * correct, also verifies the interceptors inheritance.
044: * @author Eduardo Studzinski Estima de Castro
045: * @author Gisele Pinheiro Souza
046: */
047: public class BaseMiscInterceptor00 {
048:
049: /**
050: * Bean used to implement the test.
051: */
052: private ItfSimpleBean<Integer> mtBean00;
053:
054: /**
055: * Bean used to implement the test.
056: */
057: private ItfSimpleBean<Integer> mtBean01;
058:
059: /**
060: * Bean used to implement the test.
061: */
062: private ItfSimpleBean<Integer> mtBean02;
063:
064: /**
065: * Bean used to implement the test.
066: */
067: private ItfSimpleBean<Integer> mtBean03;
068:
069: /**
070: * Verifies if the interceptors are following the order of declaration.
071: * There is an interceptor inside the bean class that has public modifier
072: * access.
073: * @input List with no values inside
074: * @output List with 4 values, the value inserted by the method and value
075: * inserted by the interceptors.
076: */
077: @Test(groups={"withInterceptor"})
078: public void testMiscPublicInterCallOrder() {
079: // The arrays used to know what is the interceptor order
080: List<Integer> arResult = new ArrayList<Integer>();
081: List<Integer> arExpected = new ArrayList<Integer>();
082:
083: // insert the value of interceptor
084: arExpected.add(PrintOrder06Interceptor.ORDER);
085: // insert the value of interceptor
086: arExpected.add(PrintOrder01Interceptor.ORDER);
087: // insert the value of interceptor
088: arExpected.add(ItfSimpleBean.EMBEDDED_INTERCEPTOR);
089: // insert the value of the method
090: arExpected.add(SLSBSimpleInterceptorTest00.ORDER);
091:
092: // gets the result
093: arResult = mtBean00.withInterceptors(arResult);
094:
095: assertEquals(
096: arExpected,
097: arResult,
098: "The method has class interceptors, a method interceptor and a public bean interceptor method"
099: + " declared inside the bean; however it isn't running in the correct order.");
100: }
101:
102: /**
103: * Verifies if the interceptors are following the order of declaration.
104: * There is an interceptor inside the bean class that has protected modifier
105: * access.
106: * @input List with no values inside
107: * @output List with 4 values, the value inserted by the method and value
108: * inserted by the interceptors.
109: */
110: @Test(groups={"withInterceptor"})
111: public void testMiscProtectedInterCallOrder() {
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 interceptor
117: arExpected.add(PrintOrder06Interceptor.ORDER);
118: // insert the value of interceptor
119: arExpected.add(PrintOrder01Interceptor.ORDER);
120: // insert the value of interceptor
121: arExpected.add(ItfSimpleBean.EMBEDDED_INTERCEPTOR);
122: // insert the value of the method
123: arExpected.add(SLSBSimpleInterceptorTest01.ORDER);
124:
125: // gets the result
126: arResult = mtBean01.withInterceptors(arResult);
127:
128: // compares the two values
129: assertEquals(
130: arExpected,
131: arResult,
132: "The method has class interceptors, a method interceptor and a protected bean interceptor method"
133: + " declared inside the bean; however it isn't running in the correct order.");
134: }
135:
136: /**
137: * Verifies if the interceptors are following the order of declaration.
138: * There is an interceptor inside the bean class that has private modifier
139: * access.
140: * @input List with no values inside
141: * @output List with 4 values, the value inserted by the method and value
142: * inserted by the interceptors.
143: */
144: @Test(groups={"withInterceptor"})
145: public void testMiscPrivateInterCallOrder() {
146: // The arrays used to know what is the interceptor order
147: List<Integer> arResult = new ArrayList<Integer>();
148: List<Integer> arExpected = new ArrayList<Integer>();
149:
150: // insert the value of interceptor
151: arExpected.add(PrintOrder06Interceptor.ORDER);
152: // insert the value of interceptor
153: arExpected.add(PrintOrder01Interceptor.ORDER);
154: // insert the value of interceptor
155: arExpected.add(ItfSimpleBean.EMBEDDED_INTERCEPTOR);
156: // insert the value of the method
157: arExpected.add(SLSBSimpleInterceptorTest02.ORDER);
158:
159: // gets the result
160: arResult = mtBean02.withInterceptors(arResult);
161:
162: // compares the two values
163: assertEquals(
164: arExpected,
165: arResult,
166: "The method has class interceptors, a method interceptor and a protected bean interceptor method"
167: + " declared inside the bean; however it isn't running in the correct order.");
168: }
169:
170: /**
171: * Verifies if the interceptors are following the order of declaration.
172: * There is an interceptor inside the bean class that has public modifier
173: * access.
174: * @input List with no values inside
175: * @output List with 4 values, the value inserted by the method and value
176: * inserted by the interceptors.
177: */
178: @Test(groups={"withInterceptor","withInheritance"})
179: public void testMiscInheritanceInterCallOrder00() {
180: // The arrays used to know what is the interceptor order
181: List<Integer> arResult = new ArrayList<Integer>();
182: List<Integer> arExpected = new ArrayList<Integer>();
183:
184: // insert the value of interceptor
185: arExpected.add(PrintOrder06Interceptor.ORDER);
186: // insert the value of interceptor
187: arExpected.add(PrintOrder03Interceptor.ORDER);
188: // insert the value of interceptor
189: arExpected.add(ItfSimpleBean.EMBEDDED_INTERCEPTOR);
190: // insert the value of the method
191: arExpected.add(SLSBSimpleInterceptorTest00.ORDER);
192:
193: // gets the result
194: arResult = mtBean00.withInterceptorsInheritance(arResult);
195:
196: // compares the two values
197: assertEquals(
198: arExpected,
199: arResult,
200: "The method has class interceptors, a method interceptor with inheritance and a public bean interceptor method"
201: + " declared inside the bean; however it isn't running in the correct order.");
202: }
203:
204: /**
205: * Verifies if the interceptors are following the order of declaration.
206: * There is an interceptor inside the bean class that has protected modifier
207: * access.
208: * @input List with no values inside
209: * @output List with 4 values, the value inserted by the method and value
210: * inserted by the interceptors.
211: */
212: @Test(groups={"withInterceptor","withInheritance"})
213: public void testMiscInheritanceInterCallOrder01() {
214: // The arrays used to know what is the interceptor order
215: List<Integer> arResult = new ArrayList<Integer>();
216: List<Integer> arExpected = new ArrayList<Integer>();
217:
218: // insert the value of interceptor
219: arExpected.add(PrintOrder06Interceptor.ORDER);
220: // insert the value of interceptor
221: arExpected.add(PrintOrder03Interceptor.ORDER);
222: // insert the value of interceptor
223: arExpected.add(ItfSimpleBean.EMBEDDED_INTERCEPTOR);
224: // insert the value of the method
225: arExpected.add(SLSBSimpleInterceptorTest01.ORDER);
226:
227: // gets the result
228: arResult = mtBean01.withInterceptorsInheritance(arResult);
229:
230: // compares the two values
231: assertEquals(
232: arExpected,
233: arResult,
234: "The method has class interceptors, a method interceptor with inheritance and a protected bean interceptor method"
235: + " declared inside the bean; however it isn't running in the correct order.");
236: }
237:
238: /**
239: * Verifies if the interceptors are following the order of declaration.
240: * There is an interceptor inside the bean class that has private modifier
241: * access.
242: * @input List with no values inside
243: * @output List with 4 values, the value inserted by the method and value
244: * inserted by the interceptors.
245: */
246: @Test(groups={"withInterceptor","withInheritance"})
247: public void testMiscInheritanceInterCallOrder02() {
248: // The arrays used to know what is the interceptor order
249: List<Integer> arResult = new ArrayList<Integer>();
250: List<Integer> arExpected = new ArrayList<Integer>();
251:
252: // insert the value of interceptor
253: arExpected.add(PrintOrder06Interceptor.ORDER);
254: // insert the value of interceptor
255: arExpected.add(PrintOrder03Interceptor.ORDER);
256: // insert the value of interceptor
257: arExpected.add(ItfSimpleBean.EMBEDDED_INTERCEPTOR);
258: // insert the value of the method
259: arExpected.add(SLSBSimpleInterceptorTest02.ORDER);
260:
261: // gets the result
262: arResult = mtBean02.withInterceptorsInheritance(arResult);
263:
264: // compares the two values
265: assertEquals(
266: arExpected,
267: arResult,
268: "The method has class interceptors, a method interceptor with inheritance and a private bean interceptor method"
269: + " declared inside the bean; however it isn't running in the correct order.");
270: }
271:
272: /**
273: * Verifies if the interceptors are following the order of declaration.
274: * There is an interceptor inside the bean class that has package modifier
275: * access.
276: * @input List with no values inside
277: * @output List with 3 values, the value inserted by the method and value
278: * inserted by the interceptors.
279: */
280: @Test(groups={"withInterceptor"})
281: public void testMiscPackageInterCallOrder() {
282: // The arrays used to know what is the interceptor order
283: List<Integer> arResult = new ArrayList<Integer>();
284: List<Integer> arExpected = new ArrayList<Integer>();
285:
286: // insert the value of interceptor
287: arExpected.add(PrintOrder03Interceptor.ORDER);
288: // insert the value of interceptor
289: arExpected.add(ItfSimpleBean.EMBEDDED_INTERCEPTOR);
290: // insert the value of the method
291: arExpected.add(SLSBSimpleInterceptorTest03.ORDER);
292:
293: // gets the result
294: arResult = mtBean03.withInterceptorsInheritance(arResult);
295:
296: // compares the two values
297: assertEquals(
298: arExpected,
299: arResult,
300: "The method has a method interceptor and a package level bean interceptor method"
301: + " declared inside the bean; however it isn't running in the correct order.");
302: }
303:
304: /**
305: * Sets bean used in the tests.
306: * @param bean00 The bean to set.
307: * @param bean01 The bean to set.
308: * @param bean02 The bean to set.
309: * @param bean03 The bean to set.
310: */
311: public void setBeans(final ItfSimpleBean<Integer> bean00,
312: final ItfSimpleBean<Integer> bean01,
313: final ItfSimpleBean<Integer> bean02,
314: final ItfSimpleBean<Integer> bean03) {
315: this.mtBean00 = bean00;
316: this.mtBean01 = bean01;
317: this.mtBean02 = bean02;
318: this.mtBean03 = bean03;
319: }
320: }
|