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