KickJava   Java API By Example, From Geeks To Geeks.

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


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: TestMandatory.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.assertFalse;
28 import static org.testng.Assert.fail;
29
30 import javax.transaction.UserTransaction JavaDoc;
31
32 import org.objectweb.easybeans.log.JLog;
33 import org.objectweb.easybeans.log.JLogFactory;
34 import org.objectweb.easybeans.tests.common.ejbs.base.transaction.ItfContainerTransaction;
35 import org.objectweb.easybeans.tests.common.exception.TransactionException;
36
37 /**
38  * Verifies if the container-managed transaction in the session bean is
39  * following the JSR 220.The items covered in this test are: 12.6.2.5.
40  * @reference JSR 220-PROPOSED FINAL
41  * @requirement Application Server must be running; the bean .
42  * objectweb.easybeans.tests.common.ejbs.stateful.containermanaged.SFSBContainerTransactionMandatory
43  * must be deployed for testing stateful session bean. And, the
44  * bean
45  * objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.SLSBContainerTransactionMandatory
46  * must be deployed for testing stateless session bean.
47  * @setup gets the reference of the bean and binds the databases specified in
48  * the EmbeddedTest.
49  * @author Gisele Pinheiro Souza
50  * @author Eduardo Studzinski Estima de Castro
51  */

52 public class TestMandatory extends TestContainerTransactionBase {
53
54     /**
55      * Logger.
56      */

57     private static JLog logger = JLogFactory.getLog(TestMandatory.class);
58
59     /**
60      * Verifies if the container uses the same transaction that the client. The
61      * client rollback must to force a bean rollback, because the both use the
62      * same transaction.
63      * @input -
64      * @output a SQLException because the table must not be created.
65      * @throws Exception if an error during the tests occurs.
66      */

67     @Override JavaDoc
68     public void testUsingClientTrans() throws Exception JavaDoc {
69         super.testUsingClientTrans();
70     }
71
72     /**
73      * Calls a setRollbackOnly and after inserts two tables. The container must
74      * do a roll back before the method invocation completes. So, the tables
75      * must not be created and a SQLException must be thrown when the test tries
76      * to verify if the table exists.
77      * @input -
78      * @output an exception when the method verifies if the table exists.
79      * @throws Exception if an error occurs during the tests.
80      */

81     public void testSetRollbackOnlyWithUserTransaction() throws Exception JavaDoc {
82         UserTransaction JavaDoc utx = getUserTransaction();
83         utx.begin();
84         try {
85             ItfContainerTransaction sfsbContainerTransaction = getBean();
86             // calls the setRollbackOnly
87
try {
88                 sfsbContainerTransaction.setRollbackOnly(DATABASE_1, DATABASE_2);
89             } catch (TransactionException e) {
90                 throw e.getParentException();
91             }
92             // tries to commit the transaction
93
try {
94                 utx.commit();
95                 fail("The transaction is marked as rollback. The client cannot make the commit.");
96             } catch (Exception JavaDoc e) {
97                 logger.debug("Expected exception {0}", e);
98             }
99         } finally {
100             assertFalse(transactionIsActive(),
101                     "There was an exception in the server side. The container is using the same transaction "
102                             + "that the client, so the cointainer should rollback the transaction.");
103         }
104     }
105
106     /**
107      * Calls the getRollbackOnly that must throw an exception for this type of
108      * transaction attribute.The EJBTransactionRequiredException is thrown,
109      * because the setRollbackOnly will be called without an transaction
110      * context.
111      * @input -
112      * @output an exception when the method call a method without a transaction
113      * context.
114      * @throws Exception if an error occurs during the tests.
115      */

116     public void testSetRollbackOnlyWithoutUserTransaction() throws Exception JavaDoc {
117         try {
118             testSetRollbackOnly();
119         } finally {
120             assertFalse(transactionIsActive(),
121                     "There was an exception in the server side. The container is using the same transaction "
122                             + "that the client, so the cointainer should rollback the transaction.");
123         }
124     }
125
126     /**
127      * Calls the getRollbackOnly that must not throw any exception for this type
128      * of transaction attribute.
129      * @input -
130      * @output the method execution without error.
131      * @throws Exception if an error occurs during the tests.
132      */

133     public void testGetRollbackOnlyWithUserTransaction() throws Exception JavaDoc {
134         UserTransaction JavaDoc utx = getUserTransaction();
135
136         utx.begin();
137         testGetRollbackOnly();
138         utx.commit();
139     }
140
141     /**
142      * Calls the getRollbackOnly that must throw an exception for this type of
143      * transaction attribute.The EJBTransactionRequiredException is thrown,
144      * because the setRollbackOnly will be called without an transaction
145      * context.
146      * @input -
147      * @output an exception when the method call a method without a transaction
148      * context.
149      * @throws Exception if an error occurs during the tests.
150      */

151     public void testGetRollbackOnlyWithoutUserTransaction() throws Exception JavaDoc {
152         testGetRollbackOnly();
153
154     }
155
156     /**
157      * @see org.objectweb.easybeans.tests.common.interfaces.ItfTestContainerManaged#testGetUserTransactionWithEJBContext()
158      * @throws Exception if an error occurs during the tests.
159      */

160     @Override JavaDoc
161     public void testGetUserTransactionWithEJBContext() throws Exception JavaDoc {
162         UserTransaction JavaDoc utx = getUserTransaction();
163         utx.begin();
164         try {
165             super.testGetUserTransactionWithEJBContext();
166         } finally {
167             utx.rollback();
168         }
169     }
170
171     /**
172      * @see org.objectweb.easybeans.tests.common.interfaces.ItfTestContainerManaged#testGetUserTransactionWithLookup()
173      * @throws Exception if an error occurs during the tests.
174      */

175     @Override JavaDoc
176     public void testGetUserTransactionWithLookup() throws Exception JavaDoc {
177         UserTransaction JavaDoc utx = getUserTransaction();
178         utx.begin();
179         try {
180             super.testGetUserTransactionWithLookup();
181         } finally {
182             utx.rollback();
183         }
184     }
185
186 }
187
Popular Tags