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: TestExceptionHandleDefault.java 1970 2007-10-16 11:49:25Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.tests.transaction.containermanaged.stateful;
025:
026: import java.sql.SQLException;
027:
028: import javax.ejb.EJBTransactionRolledbackException;
029:
030: import org.ow2.easybeans.tests.common.ejbs.stateful.containermanaged.transaction.SFSBContainerTransacDefaultApp01;
031: import org.ow2.easybeans.tests.common.ejbs.stateful.containermanaged.transaction.SFSBContainerTransacDefaultApp02;
032: import org.ow2.easybeans.tests.common.ejbs.stateful.containermanaged.transaction.SFSBContainerTransactionDefaultApp;
033: import org.ow2.easybeans.tests.common.ejbs.stateful.containermanaged.transaction.SFSBContainerTransactionDefaultRollback;
034: import org.ow2.easybeans.tests.common.ejbs.stateful.containermanaged.transaction.SFSBContainerTransactionDefaultRuntime;
035: import org.ow2.easybeans.tests.transaction.containermanaged.base.TestExceptionHandleBase;
036: import org.testng.annotations.BeforeMethod;
037: import org.testng.annotations.Test;
038:
039: /**
040: * Verifies if the container-managed transaction in the session bean is
041: * following the JSR 220. The container must handle the different types of
042: * exception in the transaction context. The items covered in this test are:
043: * 14.3.1
044: * @reference JSR 220-FINAL RELEASE
045: * @requirement Application Server must be running; the bean .
046: * SFSBContainerTransactionDefaultApp,
047: * SFSBContainerTransacDefaultApp01,
048: * SFSBContainerTransacDefaultApp02
049: * SFSBContainerTransactionDefaultRollback and
050: * SFSBContainerTransactionDefaultRuntime must be deployed .
051: * @setup gets the reference of the beans , cleans the database and close all
052: * transactions.
053: * @author Gisele Pinheiro Souza
054: * @author Eduardo Studzinski Estima de Castro
055: */
056: public class TestExceptionHandleDefault extends TestExceptionHandleBase {
057:
058: /**
059: * Creates the bean intances, closes the transactions and cleans the
060: * database.
061: * @throws Exception if an error during the bean creation occurs.
062: */
063: @BeforeMethod
064: @Override
065: public void setup() throws Exception {
066: super .setup();
067: }
068:
069: /**
070: * Creates a bean that throws always an application exception that extends
071: * Exception and has the rollback element as false.
072: * @throws Exception if an error during the bean creation occurs.
073: */
074: @Override
075: public void createBeanApp() throws Exception {
076: super .createBeanApp(SFSBContainerTransactionDefaultApp.class);
077:
078: }
079:
080: /**
081: * Creates a bean that throws always an application exception that extends
082: * RuntimeException and has the rollback element as false.
083: * @throws Exception if an error during the bean creation occurs.
084: */
085: @Override
086: public void createBeanApp01() throws Exception {
087: super .createBeanApp01(SFSBContainerTransacDefaultApp01.class);
088: }
089:
090: /**
091: * Creates a bean that throws always an application exception that extends
092: * RuntimeException and has the rollback element as true.
093: * @throws Exception if an error during the bean creation occurs.
094: */
095: @Override
096: public void createBeanApp02() throws Exception {
097: super .createBeanApp02(SFSBContainerTransacDefaultApp02.class);
098: }
099:
100: /**
101: * Creates a bean that throws always an application exception that extends
102: * Exception and has the rollback element as true.
103: * @throws Exception if an error during the bean creation occurs.
104: */
105: @Override
106: public void createBeanRollback() throws Exception {
107: super
108: .createBeanRollback(SFSBContainerTransactionDefaultRollback.class);
109: }
110:
111: /**
112: * Creates a bean that throws always aa runtime exception.
113: * @throws Exception if an error during the bean creation occurs.
114: */
115: @Override
116: public void createBeanRuntime() throws Exception {
117: super
118: .createBeanRuntime(SFSBContainerTransactionDefaultRuntime.class);
119: }
120:
121: /**
122: * Inserts a table in an database and after throws an application exception
123: * that extends Exception and has the rollback element as false. So, the
124: * container must not rollback the transaction and must re-throw the
125: * exception.
126: * @input -
127: * @output the correct method execution.
128: * @see org.ow2.easybeans.tests.transaction.containermanaged.base.TestExceptionHandleBase
129: * @throws Exception if an error during the tests occurs.
130: */
131: @Test(groups={"application exception tests"})
132: @Override
133: public void testNotUsingClientTransWithAppException()
134: throws Exception {
135: super .testNotUsingClientTransWithAppException();
136: }
137:
138: /**
139: * Inserts a table in an database and after throws an application exception
140: * that extends Exception and has the rollback element as true. So, the
141: * container must rollback the transaction and must re-throw the exception.
142: * @input -
143: * @output the exception when the test makes a select in the database to
144: * find the table created.
145: * @see org.ow2.easybeans.tests.transaction.containermanaged.base.TestExceptionHandleBase
146: * @throws Exception if an error during the tests occurs.
147: */
148: @Test(groups={"application rollback exception tests"},expectedExceptions=SQLException.class)
149: @Override
150: public void testNotUsingClientTransWithAppRollbackException()
151: throws Exception {
152: super .testNotUsingClientTransWithAppRollbackException();
153: }
154:
155: /**
156: * Inserts a table in an database and after throws a runtime exception. So,
157: * the container must rollback the transaction, discards the bean and throws
158: * an EJBException.
159: * @input -
160: * @output the exception when the test makes a select in the database to
161: * find the table created.
162: * @see org.ow2.easybeans.tests.transaction.containermanaged.base.TestExceptionHandleBase
163: * @throws Exception if an error during the tests occurs.
164: */
165: @Test(groups={"runtime exception tests"},expectedExceptions=SQLException.class)
166: @Override
167: public void testNotUsingClientTransWithRuntimeException()
168: throws Exception {
169: super .testNotUsingClientTransWithRuntimeException();
170: }
171:
172: /**
173: * Inserts a table in an database and after throws an application exception
174: * that extends RuntimeException and has the rollback element as false. So,
175: * the container must not rollback the transaction and must re-throw the
176: * exception.
177: * @input -
178: * @output the correct method execution.
179: * @see org.ow2.easybeans.tests.transaction.containermanaged.base.TestExceptionHandleBase
180: * @throws Exception if an error during the tests occurs.
181: */
182: @Test
183: @Override
184: public void testNotUsingClientTransWithAppRuntimeException()
185: throws Exception {
186: super .testNotUsingClientTransWithAppRuntimeException();
187: }
188:
189: /**
190: * Inserts a table in an database and after throws an application exception
191: * that extends RuntimeException and has the rollback element as true. So,
192: * the container must rollback the transaction and must re-throw the
193: * exception.
194: * @input -
195: * @output the exception when the test makes a select in the database to
196: * find the table created.
197: * @see org.ow2.easybeans.tests.transaction.containermanaged.base.TestExceptionHandleBase
198: * @throws Exception if an error during the tests occurs.
199: */
200: @Test(expectedExceptions=SQLException.class)
201: @Override
202: public void testNotUsingClientTransWithAppRuntimeRollbackException()
203: throws Exception {
204: super .testNotUsingClientTransWithAppRuntimeRollbackException();
205: }
206:
207: /**
208: * Inserts a table in an database and after throws an application exception
209: * that extends Exception and has the rollback element as false. The test
210: * uses the client transaction, so, the container must not mark the client
211: * transaction for rollback and must re-throw the exception.
212: * @input -
213: * @output the correct method execution.
214: * @see org.ow2.easybeans.tests.transaction.containermanaged.base.TestExceptionHandleBase
215: * @throws Exception if an error during the tests occurs.
216: */
217: @Override
218: @Test(groups={"application exception tests"})
219: public void testUsingClientTransWithAppException() throws Exception {
220: super .testUsingClientTransWithAppException();
221: }
222:
223: /**
224: * Inserts a table in an database and after throws an application exception
225: * that extends Exception and has the rollback element as true. The test
226: * uses the client transaction, so, the container must mark the client
227: * transaction for rollback and must re-throw the exception.
228: * @input - *
229: * @output the exception when the test makes a select in the database to
230: * find the table created.
231: * @see org.ow2.easybeans.tests.transaction.containermanaged.base.TestExceptionHandleBase
232: * @throws Exception if an error during the tests occurs.
233: */
234: @Test(groups={"application rollback exception tests"},expectedExceptions=SQLException.class)
235: public void tesUsingClientTransWithAppRollbackException()
236: throws Exception {
237: super .testUsingClientTransWithAppRollbackException(false);
238: }
239:
240: /**
241: * Inserts a table in an database and after throws an application exception
242: * that extends RuntimeException and has the rollback element as false. The
243: * test uses the client transaction, so, the container must not mark the
244: * client transaction for rollback and must re-throw the exception.
245: * @input -
246: * @output the correct method execution.
247: * @see org.ow2.easybeans.tests.transaction.containermanaged.base.TestExceptionHandleBase
248: * @throws Exception if an error during the tests occurs.
249: */
250: @Test(groups={"runtime exception tests"})
251: public void testUsingClientTransWithRuntimeException()
252: throws Exception {
253: super .testUsingClientTransWithRuntimeException(
254: EJBTransactionRolledbackException.class, false);
255: }
256:
257: /**
258: * Inserts a table in an database and after throws an application exception
259: * that extends RuntimeException and has the rollback element as false. The
260: * test uses the client transaction, so, the container must not mark the
261: * client transaction for rollback and must re-throw the exception.
262: * @input -
263: * @output the correct method execution.
264: * @see org.ow2.easybeans.tests.transaction.containermanaged.base.TestExceptionHandleBase
265: * @throws Exception if an error during the tests occurs.
266: */
267: @Override
268: @Test
269: public void testUsingClientTransWithAppRuntimeException()
270: throws Exception {
271: super .testUsingClientTransWithAppRuntimeException();
272: }
273:
274: /**
275: * Inserts a table in an database and after throws an application exception
276: * that extends RuntimeException and has the rollback element as false. The
277: * test uses the client transaction, so, the container must not mark the
278: * client transaction for rollback and must re-throw the exception.
279: * @input -
280: * @output the correct method execution.
281: * @see org.ow2.easybeans.tests.transaction.containermanaged.base.TestExceptionHandleBase
282: * @throws Exception if an error during the tests occurs.
283: */
284: @Test(expectedExceptions=SQLException.class)
285: public void testUsingClientTransWithAppRuntimeRollbackException()
286: throws Exception {
287: super
288: .testUsingClientTransWithAppRuntimeRollbackException(false);
289: }
290:
291: }
|