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: F_TxAttributeEB.java 3313 2003-09-17 08:56:40Z durieuxp $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jtests.clients.transaction;
027:
028: import javax.naming.NamingException;
029: import javax.rmi.PortableRemoteObject;
030: import junit.framework.Test;
031: import junit.framework.TestSuite;
032: import org.objectweb.jonas.jtests.beans.transacted.Simple;
033: import org.objectweb.jonas.jtests.beans.transacted.SimpleEHome;
034:
035: /**
036: * TxAttribute tests on on entity bean
037: */
038: public class F_TxAttributeEB extends A_TxAttributeEntity {
039:
040: private static String BEAN_HOME = "transactedSimpleEBHome";
041: protected static SimpleEHome home = null;
042:
043: public F_TxAttributeEB(String name) {
044: super (name);
045: }
046:
047: // --------------------------------------------------------------------
048: // tests on finder methods
049: // These tests are specific to BMP because there is no ejb<Find> methods
050: // in CMP.
051: // ---------------------------------------------------------------------
052:
053: /**
054: * Test NotSupported transactional attributes on finder method
055: * the finder method is called outside TX
056: */
057: public void testFinderNotSupported() throws Exception {
058:
059: getHome().finder_notsupported();
060: }
061:
062: /**
063: * Test NotSupported transactional attributes on finder method
064: * the finder method is called inside TX
065: */
066: public void testFinderNotSupportedTx() throws Exception {
067:
068: utx.begin();
069: try {
070: getHome().finder_notsupported();
071: } finally {
072: utx.rollback();
073: }
074: }
075:
076: /**
077: * Test required transactional attributes on finder method
078: * the finder method is called outside TX
079: */
080: public void testFinderRequired() throws Exception {
081:
082: getHome().finder_required();
083: }
084:
085: /**
086: * Test Required transactional attributes on finder method
087: * the finder method is called inside TX
088: */
089: public void testFinderRequiredTx() throws Exception {
090:
091: utx.begin();
092: try {
093: getHome().finder_required();
094: } finally {
095: utx.rollback();
096: }
097: }
098:
099: /**
100: * Test supports transactional attributes on finder method
101: * the finder method is called outside TX
102: * the finder method is called with false that mean that the method must not be associated
103: * to a transaction
104: */
105: public void testFinderSupports() throws Exception {
106:
107: getHome().finder_supports(false);
108: }
109:
110: /**
111: * Test supports transactional attributes on finder method
112: * the finder method is called inside TX
113: * the finder method is called with true that mean that the method must be associated
114: * to a transaction
115: */
116: public void testFinderSupportsTx() throws Exception {
117: utx.begin();
118: try {
119: getHome().finder_supports(true);
120: } finally {
121: utx.rollback();
122: }
123: }
124:
125: /**
126: * Test requiresNew transactional attributes on finder method
127: * the finder method is called outside TX
128: */
129: public void testFinderRequiresNew() throws Exception {
130:
131: getHome().finder_requiresnew();
132: }
133:
134: /**
135: * Test RequiresNew transactional attributes on finder method
136: * the finder method is called inside TX
137: */
138: public void testFinderRequiresNewTx() throws Exception {
139:
140: utx.begin();
141: try {
142: getHome().finder_requiresnew();
143: } finally {
144: utx.rollback();
145: }
146: }
147:
148: /**
149: * Test Mandatory transactional attributes on finder method
150: * the finder method is called outside TX
151: * TransactionRequiredException must be received
152: */
153: public void testFinderMandatory() throws Exception {
154: try {
155: getHome().finder_mandatory();
156: fail("mandatory: should raise exception");
157: } catch (javax.transaction.TransactionRequiredException e) {
158: } catch (java.rmi.RemoteException e) {
159: assertTrue(e.detail instanceof javax.transaction.TransactionRequiredException);
160: }
161: }
162:
163: /**
164: * Test Mandatory transactional attributes on finder method
165: * the finder method is called inside TX
166: */
167: public void testFinderMandatoryTx() throws Exception {
168:
169: utx.begin();
170: try {
171: getHome().finder_mandatory();
172: } finally {
173: utx.rollback();
174: }
175: }
176:
177: /**
178: * Test Never transactional attributes on finder method
179: * the finder method is called outside TX
180: */
181: public void testFinderNever() throws Exception {
182:
183: getHome().finder_never();
184: }
185:
186: /**
187: * Test Never transactional attributes on finder method
188: * the finder method is called inside TX
189: */
190: public void testFinderNeverTx() throws Exception {
191: utx.begin();
192: try {
193: getHome().finder_never();
194: fail("never: should raise exception");
195: } catch (java.rmi.RemoteException e) {
196: } finally {
197: utx.rollback();
198: }
199: }
200:
201: // -----------------------------------------------------------------
202: // Methods for Suite handling
203: // -----------------------------------------------------------------
204:
205: protected SimpleEHome getHome() {
206: if (home == null) {
207: try {
208: home = (SimpleEHome) PortableRemoteObject.narrow(ictx
209: .lookup(BEAN_HOME), SimpleEHome.class);
210: } catch (NamingException e) {
211: fail("Cannot get bean home");
212: }
213: }
214: return home;
215: }
216:
217: /**
218: * Create a bean and return it.
219: */
220: public Simple getSimple(int i) throws Exception {
221: return getHome().create(i);
222: }
223:
224: /**
225: * This suite is all BMP test cases
226: */
227: public static Test suite() {
228: return new TestSuite(F_TxAttributeEB.class);
229: }
230:
231: public static void main(String args[]) {
232: String testtorun = null;
233: // Get args
234: for (int argn = 0; argn < args.length; argn++) {
235: String sarg = args[argn];
236: if (sarg.equals("-n")) {
237: testtorun = args[++argn];
238: }
239: }
240: if (testtorun == null) {
241: junit.textui.TestRunner.run(suite());
242: } else {
243: junit.textui.TestRunner.run(new F_TxAttributeEB(testtorun));
244: }
245: }
246: }
|