KickJava   Java API By Example, From Geeks To Geeks.

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


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: TestMandatoryException.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 javax.ejb.EJBTransactionRolledbackException JavaDoc;
32 import javax.transaction.UserTransaction JavaDoc;
33
34 import org.objectweb.easybeans.log.JLog;
35 import org.objectweb.easybeans.log.JLogFactory;
36 import org.objectweb.easybeans.tests.common.ejbs.base.transaction.ItfContainerTransaction;
37 import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.transaction.ItfTransactionMisc00;
38
39 /**
40  * Verifies if the container-managed transaction in the session bean is
41  * following the JSR 220. The container must handle the different types of
42  * exception in the transaction context. The items covered in this test are:
43  * 13.3
44  * @reference JSR 220-PROPOSED FINAL
45  * @requirement Application Server must be running; the bean .
46  * SFSBContainerTransactionMandatoryApp,
47  * SFSBContainerTransactionMandatoryRollback and
48  * SFSBContainerTransactionMandatoryRuntime must be deployed for
49  * testing stateful session bean. And, the bean
50  * SLSBContainerTransactionMandatoryApp,
51  * SLSBContainerTransactionMandatoryRollback and
52  * SLSBContainerTransactionMandatoryRuntime must be deployed for
53  * testing stateless session bean.
54  * @setup gets the reference of the bean and binds the databases specified in
55  * the EmbeddedTest.
56  * @author Gisele Pinheiro Souza
57  * @author Eduardo Studzinski Estima de Castro
58  */

59 public abstract class TestMandatoryException extends TestContainerTransactionException {
60
61     /**
62      * Logger.
63      */

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

73     @Override JavaDoc
74     public void testCallOtherBeanNotSup() throws Exception JavaDoc {
75         UserTransaction JavaDoc utx = ExceptionHandleUtil.getUserTransaction();
76         utx.begin();
77         try {
78             getRuntimeBean().insertTablesUsingAuxBeanNotSup(DATABASE_1, DATABASE_2);
79             fail("The container did not throw the EJBTransactionRolledbackException.");
80         } catch (EJBTransactionRolledbackException JavaDoc e) {
81             logger.debug("The bean threw an expected error during the execution {0}", e);
82         }
83         // verifies if the container discarded the instance.
84
if (!ExceptionHandleUtil.isDiscarded(getRuntimeBean())) {
85             fail("The bean was not discarded.");
86         }
87
88         // TODO - verifies if the container log the error.
89

90         // tries to commit the transaction
91
try {
92             utx.commit();
93             fail("The transaction is marked as rollback. The client cannot make the commit.");
94         } catch (Exception JavaDoc e) {
95             logger.debug("Expected exception {0}", e);
96         }
97
98         // verifies if the transaction in the bean was rolled back.
99
try {
100             ExceptionHandleUtil.verifyTable(DATABASE_1, ItfContainerTransaction.TABLE);
101             fail("The container did not make a rollback in the transaction.");
102         } catch (SQLException JavaDoc e) {
103             logger.debug("The test threw an expected exception{0}", e);
104         }
105         // verifies if the table in the second bean was destroyed. This table
106
// must not be destroyed because the other bean has the transaction
107
// atttribute NOT_SUPPORTED.
108
try {
109             ExceptionHandleUtil.verifyTable(DATABASE_2, ItfTransactionMisc00.TABLE);
110         } catch (SQLException JavaDoc e) {
111             fail("The container made a rollback in the transaction.");
112         }
113     }
114
115     /**
116      * Verifies if the container uses the same transaction when the other bean
117      * has the transaction attribute REQUIRED.
118      * @input -
119      * @output the method execution without fails
120      * @throws Exception if an error during the tests occurs.
121      */

122     @Override JavaDoc
123     public void testCallOtherBeanReq() throws Exception JavaDoc {
124         UserTransaction JavaDoc utx = ExceptionHandleUtil.getUserTransaction();
125         utx.begin();
126         try {
127             getRuntimeBean().insertTablesUsingAuxBeanReq(DATABASE_1, DATABASE_2);
128             fail("The container did not throw the EJBException.");
129         } catch (EJBTransactionRolledbackException JavaDoc e) {
130             logger.debug("The bean threw an expected error during the execution {0}", e);
131         }
132         // verifies if the container discarded the instance.
133
if (!ExceptionHandleUtil.isDiscarded(getRuntimeBean())) {
134             fail("The bean was not discarded.");
135         }
136         // tries to commit the transaction
137
try {
138             utx.commit();
139             fail("The transaction is marked as rollback. The client cannot make the commit.");
140         } catch (Exception JavaDoc e) {
141             logger.debug("Expected exception {0}", e);
142         }
143         // verifies if the transaction in the bean was rolled back.
144
try {
145             ExceptionHandleUtil.verifyTable(DATABASE_1, ItfContainerTransaction.TABLE);
146             fail("The container did not make a rollback in the transaction.");
147         } catch (SQLException JavaDoc e) {
148             logger.debug("The test threw an expected exception{0}", e);
149         }
150         // verifies if the table in the second bean was destroyed. This table
151
// must be destroyed because the two beans are using the same
152
// transaction.
153
try {
154             ExceptionHandleUtil.verifyTable(DATABASE_2, ItfTransactionMisc00.TABLE);
155             fail("The container did not make a rollback in the transaction.");
156         } catch (SQLException JavaDoc e) {
157             logger.debug("The test threw an expected exception{0}", e);
158         }
159     }
160
161 }
162
Popular Tags