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: TestWrongSpecification.java 1970 2007-10-16 11:49:25Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.tests.enhancer.wrongspecification;
025:
026: import static org.ow2.easybeans.tests.enhancer.ClassesEnhancer.EXT_CLASS;
027: import static org.ow2.easybeans.tests.enhancer.ClassesEnhancer.enhanceNewClassLoader;
028:
029: import java.io.File;
030: import java.util.ArrayList;
031: import java.util.List;
032:
033: import org.ow2.easybeans.deployment.annotations.exceptions.InterceptorsValidationException;
034: import org.ow2.easybeans.tests.enhancer.ClassesEnhancer.TYPE;
035: import org.ow2.easybeans.tests.enhancer.wrongspecification.bean.ArgsConstructorInterceptor;
036: import org.ow2.easybeans.tests.enhancer.wrongspecification.bean.FinalMethodInterceptor;
037: import org.ow2.easybeans.tests.enhancer.wrongspecification.bean.ItfOneMethod;
038: import org.ow2.easybeans.tests.enhancer.wrongspecification.bean.ItfOneMethod00;
039: import org.ow2.easybeans.tests.enhancer.wrongspecification.bean.ItfWithInterceptor;
040: import org.ow2.easybeans.tests.enhancer.wrongspecification.bean.SLSBFinalExternalInterceptor;
041: import org.ow2.easybeans.tests.enhancer.wrongspecification.bean.SLSBFinalFieldEntry;
042: import org.ow2.easybeans.tests.enhancer.wrongspecification.bean.SLSBFinalInternalInterceptor;
043: import org.ow2.easybeans.tests.enhancer.wrongspecification.bean.SLSBItfWithInterceptor;
044: import org.ow2.easybeans.tests.enhancer.wrongspecification.bean.SLSBStaticEntry;
045: import org.ow2.easybeans.tests.enhancer.wrongspecification.bean.SLSBStaticExternalInterceptor;
046: import org.ow2.easybeans.tests.enhancer.wrongspecification.bean.SLSBStaticInternalInterceptor;
047: import org.ow2.easybeans.tests.enhancer.wrongspecification.bean.SLSBStaticMethodEntry;
048: import org.ow2.easybeans.tests.enhancer.wrongspecification.bean.SLSBTwoArInvokeExternalInterceptor;
049: import org.ow2.easybeans.tests.enhancer.wrongspecification.bean.SLSBTwoAroundInvokeError;
050: import org.ow2.easybeans.tests.enhancer.wrongspecification.bean.SLSBVoidExternalInterceptor;
051: import org.ow2.easybeans.tests.enhancer.wrongspecification.bean.SLSBWithArgsInterceptor;
052: import org.ow2.easybeans.tests.enhancer.wrongspecification.bean.StaticMethodInterceptor;
053: import org.ow2.easybeans.tests.enhancer.wrongspecification.bean.TwoAroundInvokeInterceptor;
054: import org.ow2.easybeans.tests.enhancer.wrongspecification.bean.VoidInterceptor;
055: import org.testng.annotations.Test;
056:
057: /**
058: * Verifies if the Enhancer detects violation of the specification.
059: * @reference JSR 220 FINAL
060: * @author Eduardo Studzinski Estima de Castro
061: * @author Gisele Pinheiro Souza
062: */
063: public class TestWrongSpecification {
064:
065: /**
066: * This test should cause an enhancer exception. The @Resource is annoted in a final field, it is denied by the
067: * specification.
068: * @input -
069: * @output -
070: * @throws Exception if there is an enhancer exception.
071: */
072: @Test(groups={"withWrongSpecification"},expectedExceptions=IllegalStateException.class)
073: public void testWrongSpec00() throws Exception {
074: List<String> lstFiles = new ArrayList<String>();
075:
076: lstFiles.add(ItfOneMethod.class.getName().replace(".",
077: File.separator)
078: + EXT_CLASS);
079: lstFiles.add(SLSBStaticMethodEntry.class.getName().replace(".",
080: File.separator)
081: + EXT_CLASS);
082: enhanceNewClassLoader(lstFiles, TYPE.ALL);
083: }
084:
085: /**
086: * This test should cause an enhancer exception. The @Resource is annoted in a static field, it is denied by the
087: * specification.
088: * @input -
089: * @output -
090: * @throws Exception if there is an enhancer exception.
091: */
092: @Test(groups={"withWrongSpecification"},expectedExceptions=IllegalStateException.class)
093: public void testWrongSpec01() throws Exception {
094: List<String> lstFiles = new ArrayList<String>();
095:
096: lstFiles.add(ItfOneMethod.class.getName().replace(".",
097: File.separator)
098: + EXT_CLASS);
099: lstFiles.add(SLSBStaticEntry.class.getName().replace(".",
100: File.separator)
101: + EXT_CLASS);
102: enhanceNewClassLoader(lstFiles, TYPE.ALL);
103: }
104:
105: /**
106: * This test should cause an enhancer exception. The @Resource is annoted in a final field, it is denied by the
107: * specification.
108: * @input -
109: * @output -
110: * @throws Exception if there is an enhancer exception.
111: */
112: @Test(groups={"withWrongSpecification"},expectedExceptions=IllegalStateException.class)
113: public void testWrongSpec02() throws Exception {
114: List<String> lstFiles = new ArrayList<String>();
115:
116: lstFiles.add(ItfOneMethod.class.getName().replace(".",
117: File.separator)
118: + EXT_CLASS);
119: lstFiles.add(SLSBFinalFieldEntry.class.getName().replace(".",
120: File.separator)
121: + EXT_CLASS);
122: enhanceNewClassLoader(lstFiles, TYPE.ALL);
123: }
124:
125: /**
126: * This test should cause an enhancer exception. Verifies if an interceptor
127: * class with two @AroundInvoke doesn't compile.
128: * @input -
129: * @output -
130: * @throws Exception if there is an enhancer exception.
131: */
132: @Test(groups={"withWrongSpecification"},expectedExceptions=InterceptorsValidationException.class)
133: public void testWrongSpec03() throws Exception {
134: List<String> lstFiles = new ArrayList<String>();
135:
136: lstFiles.add(ItfOneMethod00.class.getName().replace(".",
137: File.separator)
138: + EXT_CLASS);
139: lstFiles.add(SLSBTwoArInvokeExternalInterceptor.class.getName()
140: .replace(".", File.separator)
141: + EXT_CLASS);
142: lstFiles.add(TwoAroundInvokeInterceptor.class.getName()
143: .replace(".", File.separator)
144: + EXT_CLASS);
145: enhanceNewClassLoader(lstFiles, TYPE.INTERCEPTOR);
146: }
147:
148: /**
149: * Verifies if an interceptor class with args doesn't compile.
150: * @input -
151: * @output -
152: * @throws Exception if there is an enhancer exception.
153: */
154: @Test(groups={"withWrongSpecification"},expectedExceptions=InterceptorsValidationException.class)
155: public void testWrongSpec04() throws Exception {
156: List<String> lstFiles = new ArrayList<String>();
157:
158: lstFiles.add(SLSBWithArgsInterceptor.class.getName().replace(
159: ".", File.separator)
160: + EXT_CLASS);
161: lstFiles.add(ItfOneMethod00.class.getName().replace(".",
162: File.separator)
163: + EXT_CLASS);
164: lstFiles.add(ArgsConstructorInterceptor.class.getName()
165: .replace(".", File.separator)
166: + EXT_CLASS);
167: enhanceNewClassLoader(lstFiles, TYPE.INTERCEPTOR);
168: }
169:
170: /**
171: * This test should cause an enhancer exception. Verifies if a bean class
172: * with two @AroundInvoke doesn't compile.
173: * @input -
174: * @output -
175: * @throws Exception if there is an enhancer exception.
176: */
177: @Test(groups={"withWrongSpecification"},expectedExceptions=InterceptorsValidationException.class)
178: public void testWrongSpec05() throws Exception {
179: List<String> lstFiles = new ArrayList<String>();
180:
181: lstFiles.add(SLSBTwoAroundInvokeError.class.getName().replace(
182: ".", File.separator)
183: + EXT_CLASS);
184: lstFiles.add(ItfOneMethod00.class.getName().replace(".",
185: File.separator)
186: + EXT_CLASS);
187: enhanceNewClassLoader(lstFiles, TYPE.INTERCEPTOR);
188: }
189:
190: /**
191: * This test should cause an enhancer exception. Verifies if an interceptor
192: * that the return type is void doesn't compile.
193: * @input -
194: * @output -
195: * @throws Exception if there is an enhancer exception.
196: */
197: @Test(groups={"withWrongSpecification"},expectedExceptions=InterceptorsValidationException.class)
198: public void testWrongSpec06() throws Exception {
199: List<String> lstFiles = new ArrayList<String>();
200:
201: lstFiles.add(SLSBVoidExternalInterceptor.class.getName()
202: .replace(".", File.separator)
203: + EXT_CLASS);
204: lstFiles.add(ItfOneMethod00.class.getName().replace(".",
205: File.separator)
206: + EXT_CLASS);
207: lstFiles.add(VoidInterceptor.class.getName().replace(".",
208: File.separator)
209: + EXT_CLASS);
210:
211: enhanceNewClassLoader(lstFiles, TYPE.INTERCEPTOR);
212:
213: }
214:
215: /**
216: * Verifies if an interceptor class with a static method modifier compile.
217: * @input -
218: * @output -
219: * @throws Exception if there is an enhancer exception.
220: */
221: @Test(groups={"withWrongSpecification"},expectedExceptions=InterceptorsValidationException.class)
222: public void testWrongSpec07() throws Exception {
223: List<String> lstFiles = new ArrayList<String>();
224:
225: lstFiles.add(SLSBStaticExternalInterceptor.class.getName()
226: .replace(".", File.separator)
227: + EXT_CLASS);
228: lstFiles.add(ItfOneMethod00.class.getName().replace(".",
229: File.separator)
230: + EXT_CLASS);
231: lstFiles.add(StaticMethodInterceptor.class.getName().replace(
232: ".", File.separator)
233: + EXT_CLASS);
234: enhanceNewClassLoader(lstFiles, TYPE.INTERCEPTOR);
235: }
236:
237: /**
238: * Verifies if an interceptor class with a final method modifier compile.
239: * @input -
240: * @output -
241: * @throws Exception if there is an enhancer exception.
242: */
243: @Test(groups={"withWrongSpecification"},expectedExceptions=InterceptorsValidationException.class)
244: public void testWrongSpec08() throws Exception {
245: List<String> lstFiles = new ArrayList<String>();
246:
247: lstFiles.add(SLSBFinalExternalInterceptor.class.getName()
248: .replace(".", File.separator)
249: + EXT_CLASS);
250: lstFiles.add(ItfOneMethod00.class.getName().replace(".",
251: File.separator)
252: + EXT_CLASS);
253: lstFiles.add(FinalMethodInterceptor.class.getName().replace(
254: ".", File.separator)
255: + EXT_CLASS);
256:
257: enhanceNewClassLoader(lstFiles, TYPE.INTERCEPTOR);
258: }
259:
260: /**
261: * This method should cause an exception. Verifies if an
262: * @AroundInvoke declared into an interface compiles.
263: * @input -
264: * @output -
265: * @throws Exception if there is an enhancer exception.
266: */
267: @Test(groups={"withWrongSpecification"},expectedExceptions=InterceptorsValidationException.class)
268: public void testWrongSpec09() throws Exception {
269: List<String> lstFiles = new ArrayList<String>();
270:
271: lstFiles.add(ItfWithInterceptor.class.getName().replace(".",
272: File.separator)
273: + EXT_CLASS);
274: lstFiles.add(SLSBItfWithInterceptor.class.getName().replace(
275: ".", File.separator)
276: + EXT_CLASS);
277: enhanceNewClassLoader(lstFiles, TYPE.INTERCEPTOR);
278: }
279:
280: /**
281: * Verifies if a bean class with a static interceptor method compiles.
282: * @input -
283: * @output -
284: * @throws Exception if there is an enhancer exception.
285: */
286: @Test(groups={"withWrongSpecification"},expectedExceptions=InterceptorsValidationException.class)
287: public void testWrongSpec10() throws Exception {
288: List<String> lstFiles = new ArrayList<String>();
289:
290: lstFiles.add(SLSBStaticInternalInterceptor.class.getName()
291: .replace(".", File.separator)
292: + EXT_CLASS);
293: lstFiles.add(ItfOneMethod00.class.getName().replace(".",
294: File.separator)
295: + EXT_CLASS);
296: enhanceNewClassLoader(lstFiles, TYPE.INTERCEPTOR);
297: }
298:
299: /**
300: * Verifies if a bean class with a final interceptor method compiles.
301: * @input -
302: * @output -
303: * @throws Exception if there is an enhancer exception.
304: */
305: @Test(groups={"withWrongSpecification"},expectedExceptions=InterceptorsValidationException.class)
306: public void testWrongSpec11() throws Exception {
307: List<String> lstFiles = new ArrayList<String>();
308:
309: lstFiles.add(SLSBFinalInternalInterceptor.class.getName()
310: .replace(".", File.separator)
311: + EXT_CLASS);
312: lstFiles.add(ItfOneMethod00.class.getName().replace(".",
313: File.separator)
314: + EXT_CLASS);
315: enhanceNewClassLoader(lstFiles, TYPE.INTERCEPTOR);
316: }
317: }
|