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: TestMandatoryException.java 1970 2007-10-16 11:49:25Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.tests.transaction.containermanaged.base;
025:
026: import static org.testng.Assert.fail;
027:
028: import java.sql.SQLException;
029:
030: import javax.ejb.EJBTransactionRolledbackException;
031: import javax.transaction.UserTransaction;
032:
033: import org.ow2.easybeans.tests.common.ejbs.base.transaction.ItfContainerTransaction;
034: import org.ow2.easybeans.tests.common.ejbs.stateless.containermanaged.transaction.ItfTransactionMisc00;
035: import org.ow2.util.log.Log;
036: import org.ow2.util.log.LogFactory;
037:
038: /**
039: * Verifies if the container-managed transaction in the session bean is
040: * following the JSR 220. The container must handle the different types of
041: * exception in the transaction context. The items covered in this test are:
042: * 13.3
043: * @reference JSR 220-PROPOSED FINAL
044: * @requirement Application Server must be running; the bean .
045: * SFSBContainerTransactionMandatoryApp,
046: * SFSBContainerTransactionMandatoryRollback and
047: * SFSBContainerTransactionMandatoryRuntime must be deployed for
048: * testing stateful session bean. And, the bean
049: * SLSBContainerTransactionMandatoryApp,
050: * SLSBContainerTransactionMandatoryRollback and
051: * SLSBContainerTransactionMandatoryRuntime must be deployed for
052: * testing stateless session bean.
053: * @setup gets the reference of the bean and binds the databases specified in
054: * the EmbeddedTest.
055: * @author Gisele Pinheiro Souza
056: * @author Eduardo Studzinski Estima de Castro
057: */
058: public abstract class TestMandatoryException extends
059: TestContainerTransactionException {
060:
061: /**
062: * Logger.
063: */
064: private static Log logger = LogFactory
065: .getLog(TestMandatoryException.class);
066:
067: /**
068: * Verifies if the container does not use the same transaction when the
069: * other bean has the transaction attribute NOT_SUPPORTED.
070: * @input -
071: * @output the execution without errors.
072: * @throws Exception if an error during the tests occurs.
073: */
074: @Override
075: public void testCallOtherBeanNotSup() throws Exception {
076: UserTransaction utx = ExceptionHandleUtil.getUserTransaction();
077: utx.begin();
078: try {
079: getRuntimeBean().insertTablesUsingAuxBeanNotSup(DATABASE_1,
080: DATABASE_2);
081: fail("The container did not throw the EJBTransactionRolledbackException.");
082: } catch (EJBTransactionRolledbackException e) {
083: logger
084: .debug(
085: "The bean threw an expected error during the execution {0}",
086: e);
087: }
088: // verifies if the container discarded the instance.
089: if (!ExceptionHandleUtil.isDiscarded(getRuntimeBean())) {
090: fail("The bean was not discarded.");
091: }
092:
093: // TODO - verifies if the container log the error.
094:
095: // tries to commit the transaction
096: try {
097: utx.commit();
098: fail("The transaction is marked as rollback. The client cannot make the commit.");
099: } catch (Exception e) {
100: logger.debug("Expected exception {0}", e);
101: }
102:
103: // verifies if the transaction in the bean was rolled back.
104: try {
105: ExceptionHandleUtil.verifyTable(DATABASE_1,
106: ItfContainerTransaction.TABLE);
107: fail("The container did not make a rollback in the transaction.");
108: } catch (SQLException e) {
109: logger.debug("The test threw an expected exception{0}", e);
110: }
111: // verifies if the table in the second bean was destroyed. This table
112: // must not be destroyed because the other bean has the transaction
113: // atttribute NOT_SUPPORTED.
114: try {
115: ExceptionHandleUtil.verifyTable(DATABASE_2,
116: ItfTransactionMisc00.TABLE);
117: } catch (SQLException e) {
118: fail("The container made a rollback in the transaction.");
119: }
120: }
121:
122: /**
123: * Verifies if the container uses the same transaction when the other bean
124: * has the transaction attribute REQUIRED.
125: * @input -
126: * @output the method execution without fails
127: * @throws Exception if an error during the tests occurs.
128: */
129: @Override
130: public void testCallOtherBeanReq() throws Exception {
131: UserTransaction utx = ExceptionHandleUtil.getUserTransaction();
132: utx.begin();
133: try {
134: getRuntimeBean().insertTablesUsingAuxBeanReq(DATABASE_1,
135: DATABASE_2);
136: fail("The container did not throw the EJBException.");
137: } catch (EJBTransactionRolledbackException e) {
138: logger
139: .debug(
140: "The bean threw an expected error during the execution {0}",
141: e);
142: }
143: // verifies if the container discarded the instance.
144: if (!ExceptionHandleUtil.isDiscarded(getRuntimeBean())) {
145: fail("The bean was not discarded.");
146: }
147: // tries to commit the transaction
148: try {
149: utx.commit();
150: fail("The transaction is marked as rollback. The client cannot make the commit.");
151: } catch (Exception e) {
152: logger.debug("Expected exception {0}", e);
153: }
154: // verifies if the transaction in the bean was rolled back.
155: try {
156: ExceptionHandleUtil.verifyTable(DATABASE_1,
157: ItfContainerTransaction.TABLE);
158: fail("The container did not make a rollback in the transaction.");
159: } catch (SQLException e) {
160: logger.debug("The test threw an expected exception{0}", e);
161: }
162: // verifies if the table in the second bean was destroyed. This table
163: // must be destroyed because the two beans are using the same
164: // transaction.
165: try {
166: ExceptionHandleUtil.verifyTable(DATABASE_2,
167: ItfTransactionMisc00.TABLE);
168: fail("The container did not make a rollback in the transaction.");
169: } catch (SQLException e) {
170: logger.debug("The test threw an expected exception{0}", e);
171: }
172: }
173:
174: }
|