KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > tests > transaction > containermanaged > base > TestRequiredException


1 /**
2  * EasyBeans
3  * Copyright (C) 2006 Bull S.A.S.
4  * Contact: easybeans@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: TestRequiredException.java 980 2006-07-28 13:20:32Z studzine $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.easybeans.tests.transaction.containermanaged.base;
26
27 import static org.testng.Assert.fail;
28
29 import java.sql.SQLException JavaDoc;
30
31 import org.objectweb.easybeans.log.JLog;
32 import org.objectweb.easybeans.log.JLogFactory;
33 import org.objectweb.easybeans.tests.common.ejbs.base.transaction.ItfContainerTransaction;
34 import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.transaction.ItfTransactionMisc00;
35
36 /**
37  * Verifies if the container-managed transaction in the session bean is
38  * following the JSR 220. The container must handle the different types of
39  * exception in the transaction context. The items covered in this test are:
40  * 13.3
41  * @reference JSR 220-PROPOSED FINAL
42  * @requirement Application Server must be running; the bean .
43  * SFSBContainerTransactionRequiredApp,
44  * SFSBContainerTransactionRequiredRollback and
45  * SFSBContainerTransactionRequiredRuntime must be deployed for
46  * testing stateful session bean. And, the bean
47  * SLSBContainerTransactionRequiredApp,
48  * SLSBContainerTransactionRequiredRollback and
49  * SLSBContainerTransactionRequiredRuntime must be deployed for
50  * testing stateless session bean.
51  * @setup gets the reference of the bean and binds the databases specified in
52  * the EmbeddedTest.
53  * @author Gisele Pinheiro Souza
54  * @author Eduardo Studzinski Estima de Castro
55  */

56 public abstract class TestRequiredException extends TestContainerTransactionException {
57
58     /**
59      * Logger.
60      */

61     private static JLog logger = JLogFactory.getLog(TestRequiredException.class);
62
63
64
65     /**
66      * Verifies if the container does not use the same transaction when the
67      * other bean has the transaction attribute NOT_SUPPORTED.The bean method
68      * throws a runtime exception.
69      * @input -
70      * @output the method execution without error
71      * @throws Exception if an error during the tests occurs.
72      */

73     @Override JavaDoc
74     public void testCallOtherBeanNotSup() throws Exception JavaDoc {
75         super.testCallOtherBeanNotSup();
76         verifyOtherBeanNotSupport();
77     }
78
79     /**
80      * Verifies if the container uses the same transaction when the other bean
81      * has the transaction attribute REQUIRED. The bean method
82      * throws a runtime exception.
83      * @input -
84      * @output the method execution without error
85      * @throws Exception if an error during the tests occurs.
86      */

87     @Override JavaDoc
88     public void testCallOtherBeanReq() throws Exception JavaDoc {
89         super.testCallOtherBeanReq();
90         verifyOtherBeanReq();
91     }
92
93     /**
94      * Verifies if the container made a rollback only in the method required.The
95      * method with transaction attribute not_supported must no be in the
96      * transaction context.
97      * @throws Exception if an error occurs.
98      */

99     private void verifyOtherBeanNotSupport() throws Exception JavaDoc {
100         // verifies if the transaction in the bean was rolled back.
101
try {
102             ExceptionHandleUtil.verifyTable(DATABASE_1, ItfContainerTransaction.TABLE);
103             fail("The container did not make a rollback in the transaction.");
104         } catch (SQLException JavaDoc 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, ItfTransactionMisc00.TABLE);
112         } catch (SQLException JavaDoc e) {
113             fail("The container made a rollback in the transaction.");
114         }
115     }
116
117     /**
118      * Verifies if the bean makes a rollback in the both bean method. The
119      * methods have the transaction attribute required, so they must stay in the
120      * same transaction context.
121      * @throws Exception if a problem occurs.
122      */

123     private void verifyOtherBeanReq() throws Exception JavaDoc {
124         // verifies if the transaction in the bean was rolled back.
125
try {
126             ExceptionHandleUtil.verifyTable(DATABASE_1, ItfContainerTransaction.TABLE);
127             fail("The container did not make a rollback in the transaction.");
128         } catch (SQLException JavaDoc e) {
129             logger.debug("The test threw an expected exception {0}", e);
130         }
131         // verifies if the table in the second bean was destroyed. This table
132
// must to be destroyed because the two beans are using the same
133
// transaction.
134
try {
135             ExceptionHandleUtil.verifyTable(DATABASE_2, ItfTransactionMisc00.TABLE);
136             fail("The container did not make a rollback in the transaction.");
137         } catch (SQLException JavaDoc e) {
138             logger.debug("The test threw an expected exception {0}", e);
139         }
140     }
141
142
143 }
144
Popular Tags