001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.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:
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jtests.clients.transaction;
027:
028: import java.rmi.RemoteException;
029:
030: import org.objectweb.jonas.jtests.beans.transacted.Simple;
031: import org.objectweb.jonas.jtests.util.JTestCase;
032:
033: /**
034: * Transactional attribute test cases
035: * tests here are common to entity and session beans.
036: * beans used : transacted
037: * @author Ph.Coq, Ph.Durieux (jonas team)
038: */
039: public abstract class B_TxAttribute extends JTestCase {
040:
041: /**
042: * constructor
043: * @param name name of the test suite.
044: */
045: public B_TxAttribute(String name) {
046: super (name);
047: }
048:
049: /**
050: * Sets up the fixture, here load the beans if not loaded yet.
051: * This method is called before a test is executed.
052: */
053: protected void setUp() {
054: super .setUp();
055: useBeans("transacted", true);
056: }
057:
058: /**
059: * Get an instance of the bean.
060: * This method depends on the home used to get it.
061: * For entity bean, the arg is used to get a particular instance.
062: * For session beans, we get any session bean from the pool.
063: */
064: public abstract Simple getSimple(int i) throws Exception;
065:
066: // --------------------------------------------------------------------
067: // test cases
068: // --------------------------------------------------------------------
069:
070: /**
071: * Test of NotSupported attribute
072: * A business method with NotSupported is called outside TX
073: * this method returns if the thread is associated to a transaction
074: *
075: * the expected value is false
076: */
077: public void testSimpleOptNotSupportedRemove() throws Exception {
078:
079: Simple s = getSimple(10);
080: assertEquals(false, s.opwith_notsupported());
081: s.remove();
082:
083: }
084:
085: /**
086: * Test of RequiresNew attribute
087: * A business method with RequiresNew is called outside TX
088: * this method returns if the thread is associated to a transaction
089: *
090: * the expected value is true
091: */
092: public void testGetSimpleOptRequiresNewRemove() throws Exception {
093:
094: Simple s = getSimple(11);
095: assertEquals(true, s.opwith_requires_new());
096: s.remove();
097:
098: }
099:
100: /**
101: * Test of Required attribute
102: * A business method with Required is called outside TX
103: * this method returns if the thread is associated to a transaction
104: *
105: * the expected value is true
106: */
107: public void testGetSimpleOptRequiredRemove() throws Exception {
108:
109: Simple s = getSimple(12);
110: assertEquals(true, s.opwith_required());
111: s.remove();
112: }
113:
114: /**
115: * Test of RequiresNew attribute
116: * A business method with RequiresNew is called inside TX
117: * this method returns if the thread is associated to a transaction
118: *
119: * the expected value is true
120: */
121: public void testGetSimpleOptRequiresNewRemoveInTx()
122: throws Exception {
123: Simple s = getSimple(21);
124: utx.begin();
125: try {
126: assertEquals(true, s.opwith_requires_new());
127: } finally {
128: utx.rollback();
129: s.remove();
130: }
131: }
132:
133: /**
134: * Test of Required attribute
135: * A business method with Required is called inside TX
136: * this method returns if the thread is associated to a transaction
137: *
138: * the expected value is true
139: */
140: public void testGetSimpleOptRequiredRemoveInTx() throws Exception {
141:
142: Simple s = getSimple(22);
143: utx.begin();
144: try {
145: assertEquals(true, s.opwith_required());
146: } finally {
147: utx.rollback();
148: s.remove();
149: }
150:
151: }
152:
153: /**
154: * Test of Mandatory attribute
155: * A business method with Mandatory is called inside TX
156: * this method returns if the thread is associated to a transaction
157: *
158: * the expected value is true
159: */
160: public void testMandatoryTx() throws Exception {
161:
162: Simple s = getSimple(23);
163: utx.begin();
164: try {
165: assertEquals(true, s.opwith_mandatory());
166: } finally {
167: utx.rollback();
168: s.remove();
169: }
170: }
171:
172: /**
173: * Test of Never attribute
174: * A business method with Mandatory is called inside TX
175: * this method returns if the thread is associated to a transaction
176: *
177: * A java.rmi.RemoteException must be received
178: */
179: public void testNeverTx() throws Exception {
180:
181: Simple s = getSimple(24);
182: utx.begin();
183: try {
184: s.opwith_never();
185: fail("never: should raise exception");
186: } catch (RemoteException e) {
187: } finally {
188: utx.rollback();
189: s.remove();
190: }
191: }
192:
193: /**
194: * Test of Supports attribute
195: * A business method with Supports is called inside TX
196: * this method returns if the thread is associated to a transaction
197: *
198: * the expected value is true
199: */
200: public void testSupportsTx() throws Exception {
201:
202: Simple s = getSimple(25);
203: utx.begin();
204: try {
205: assertEquals(true, s.opwith_supports());
206: } finally {
207: utx.rollback();
208: s.remove();
209: }
210:
211: }
212:
213: /**
214: * Test the sequence of several calls to methods
215: * with different transactional contexts
216: */
217: public void testNoTx() throws Exception {
218:
219: Simple s = getSimple(1);
220: assertEquals(false, s.opwith_notsupported());
221: assertEquals(true, s.opwith_requires_new());
222: assertEquals(true, s.opwith_required());
223: assertEquals(false, s.opwith_never());
224: assertEquals(false, s.opwith_supports());
225: s.remove();
226: }
227:
228: }
|