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