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_ContManagedTx.java 6437 2005-03-17 15:21:44Z 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 javax.transaction.RollbackException;
031: import junit.framework.Test;
032: import junit.framework.TestSuite;
033: import org.objectweb.jonas.jtests.beans.transacted.Simple;
034: import org.objectweb.jonas.jtests.beans.transacted.SimpleSHome;
035: import org.objectweb.jonas.jtests.beans.transacted.SynchroSimple;
036: import org.objectweb.jonas.jtests.util.JTestCase;
037:
038: /**
039: * Test for Bean Managed Transaction beans
040: */
041: public class F_ContManagedTx extends JTestCase {
042:
043: private static String BEAN_HOME = "transactedSimpleSYHome";
044: protected static SimpleSHome home = null;
045:
046: public F_ContManagedTx(String name) {
047: super (name);
048: }
049:
050: protected void setUp() {
051: super .setUp();
052: useBeans("transacted", true);
053: if (home == null) {
054: try {
055: home = (SimpleSHome) PortableRemoteObject.narrow(ictx
056: .lookup(BEAN_HOME), SimpleSHome.class);
057: } catch (NamingException e) {
058: fail("Cannot get Home:" + e);
059: }
060: }
061: }
062:
063: /**
064: * Test rollback only in beforeCompletion
065: * See EJB 2.1 spec 7.5.4
066: */
067: public void testRollBackInBeforeCompletion() throws Exception {
068: SynchroSimple ss = (SynchroSimple) PortableRemoteObject.narrow(
069: home.create(), SynchroSimple.class);
070:
071: utx.begin();
072: ss.setRollbackOnly();
073: try {
074: utx.commit();
075: fail("transaction should be rolled back");
076: } catch (RollbackException e) {
077: } finally {
078: ss.remove(); // cleaning
079: }
080: }
081:
082: public static Test suite() {
083: return new TestSuite(F_ContManagedTx.class);
084: }
085:
086: public static void main(String args[]) {
087: String testtorun = null;
088: // Get args
089: for (int argn = 0; argn < args.length; argn++) {
090: String sarg = args[argn];
091: if (sarg.equals("-n")) {
092: testtorun = args[++argn];
093: }
094: }
095: if (testtorun == null) {
096: junit.textui.TestRunner.run(suite());
097: } else {
098: junit.textui.TestRunner.run(new F_ContManagedTx(testtorun));
099: }
100: }
101: }
|