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: TestRequiredException.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 org.ow2.easybeans.tests.common.ejbs.base.transaction.ItfContainerTransaction;
031: import org.ow2.easybeans.tests.common.ejbs.stateless.containermanaged.transaction.ItfTransactionMisc00;
032: import org.ow2.util.log.Log;
033: import org.ow2.util.log.LogFactory;
034:
035: /**
036: * Verifies if the container-managed transaction in the session bean is
037: * following the JSR 220. The container must handle the different types of
038: * exception in the transaction context. The items covered in this test are:
039: * 13.3
040: * @reference JSR 220-PROPOSED FINAL
041: * @requirement Application Server must be running; the bean .
042: * SFSBContainerTransactionRequiredApp,
043: * SFSBContainerTransactionRequiredRollback and
044: * SFSBContainerTransactionRequiredRuntime must be deployed for
045: * testing stateful session bean. And, the bean
046: * SLSBContainerTransactionRequiredApp,
047: * SLSBContainerTransactionRequiredRollback and
048: * SLSBContainerTransactionRequiredRuntime must be deployed for
049: * testing stateless session bean.
050: * @setup gets the reference of the bean and binds the databases specified in
051: * the EmbeddedTest.
052: * @author Gisele Pinheiro Souza
053: * @author Eduardo Studzinski Estima de Castro
054: */
055: public abstract class TestRequiredException extends
056: TestContainerTransactionException {
057:
058: /**
059: * Logger.
060: */
061: private static Log logger = LogFactory
062: .getLog(TestRequiredException.class);
063:
064: /**
065: * Verifies if the container does not use the same transaction when the
066: * other bean has the transaction attribute NOT_SUPPORTED.The bean method
067: * throws a runtime exception.
068: * @input -
069: * @output the method execution without error
070: * @throws Exception if an error during the tests occurs.
071: */
072: @Override
073: public void testCallOtherBeanNotSup() throws Exception {
074: super .testCallOtherBeanNotSup();
075: verifyOtherBeanNotSupport();
076: }
077:
078: /**
079: * Verifies if the container uses the same transaction when the other bean
080: * has the transaction attribute REQUIRED. The bean method
081: * throws a runtime exception.
082: * @input -
083: * @output the method execution without error
084: * @throws Exception if an error during the tests occurs.
085: */
086: @Override
087: public void testCallOtherBeanReq() throws Exception {
088: super .testCallOtherBeanReq();
089: verifyOtherBeanReq();
090: }
091:
092: /**
093: * Verifies if the container made a rollback only in the method required.The
094: * method with transaction attribute not_supported must no be in the
095: * transaction context.
096: * @throws Exception if an error occurs.
097: */
098: private void verifyOtherBeanNotSupport() throws Exception {
099: // verifies if the transaction in the bean was rolled back.
100: try {
101: ExceptionHandleUtil.verifyTable(DATABASE_1,
102: ItfContainerTransaction.TABLE);
103: fail("The container did not make a rollback in the transaction.");
104: } catch (SQLException e) {
105: logger.debug("The test threw an expected exception {0}", e);
106: }
107: // verifies if the table in the second bean was destroyed. This table
108: // must not to be destroyed because the other bean has the transaction
109: // atttribute NOT_SUPPORTED.
110: try {
111: ExceptionHandleUtil.verifyTable(DATABASE_2,
112: ItfTransactionMisc00.TABLE);
113: } catch (SQLException e) {
114: fail("The container made a rollback in the transaction.");
115: }
116: }
117:
118: /**
119: * Verifies if the bean makes a rollback in the both bean method. The
120: * methods have the transaction attribute required, so they must stay in the
121: * same transaction context.
122: * @throws Exception if a problem occurs.
123: */
124: private void verifyOtherBeanReq() throws Exception {
125: // verifies if the transaction in the bean was rolled back.
126: try {
127: ExceptionHandleUtil.verifyTable(DATABASE_1,
128: ItfContainerTransaction.TABLE);
129: fail("The container did not make a rollback in the transaction.");
130: } catch (SQLException e) {
131: logger.debug("The test threw an expected exception {0}", e);
132: }
133: // verifies if the table in the second bean was destroyed. This table
134: // must to be destroyed because the two beans are using the same
135: // transaction.
136: try {
137: ExceptionHandleUtil.verifyTable(DATABASE_2,
138: ItfTransactionMisc00.TABLE);
139: fail("The container did not make a rollback in the transaction.");
140: } catch (SQLException e) {
141: logger.debug("The test threw an expected exception {0}", e);
142: }
143: }
144:
145: }
|