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_EntityCMT.java 3311 2003-09-17 06:50:41Z 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.annuaire.Personne;
033: import org.objectweb.jonas.jtests.beans.annuaire.PersonneHome;
034: import org.objectweb.jonas.jtests.util.JTestCase;
035:
036: /**
037: * Test for Bean Managed Transaction entity beans
038: * @author Philippe Durieux
039: */
040: public class F_EntityCMT extends JTestCase {
041:
042: private static String BEAN_HOME = "annuairePersonneECHome";
043: protected static PersonneHome ehome = null;
044: String mynum = "63801";
045: String badnum = "99999";
046: String newnum = "12341";
047: String myname = "Phil";
048:
049: public F_EntityCMT(String name) {
050: super (name);
051: }
052:
053: protected void setUp() {
054: super .setUp();
055: if (ehome == null) {
056: useBeans("annuaire", true);
057: try {
058: ehome = (PersonneHome) PortableRemoteObject.narrow(ictx
059: .lookup(BEAN_HOME), PersonneHome.class);
060: } catch (NamingException e) {
061: fail("Cannot get bean Home:" + e);
062: }
063: }
064: }
065:
066: /**
067: * Test that rollback will not lost old bean state
068: * - create bean
069: * - make a transaction that change the num and roll it back
070: * - check num has not been changed.
071: */
072: public void testStateAfterRollBack() throws Exception {
073: Personne acc = ehome.create(myname, mynum);
074: utx.begin();
075: acc.setNumero(badnum);
076: utx.rollback();
077: assertEquals(mynum, acc.getNumero());
078: acc.remove(); // cleaning
079: }
080:
081: /**
082: * Test that rollback will not lost old bean state
083: * - access bean
084: * - make a transaction rolled back
085: * - check state has not been changed.
086: */
087: public void testStateAfterRollBackNoTx() throws Exception {
088: Personne acc = ehome.create(myname, mynum);
089: acc.setNumero(newnum);
090: utx.begin();
091: acc.setNumero(badnum);
092: utx.rollback();
093: assertEquals(newnum, acc.getNumero());
094: acc.remove(); // cleaning
095: }
096:
097: /**
098: * Test that rollback will not lost old bean state
099: * - access bean
100: * - make a transaction rolled back
101: * - check state has not been changed.
102: */
103: public void testStateAfterRollBackTx() throws Exception {
104: Personne acc = ehome.create(myname, mynum);
105: utx.begin();
106: acc.setNumero(newnum);
107: utx.commit();
108: utx.begin();
109: acc.setNumero(badnum);
110: utx.rollback();
111: assertEquals(newnum, acc.getNumero());
112: acc.remove(); // cleaning
113: }
114:
115: public static Test suite() {
116: return new TestSuite(F_EntityCMT.class);
117: }
118:
119: public static void main(String args[]) {
120: String testtorun = null;
121: // Get args
122: for (int argn = 0; argn < args.length; argn++) {
123: String sarg = args[argn];
124: if (sarg.equals("-n")) {
125: testtorun = args[++argn];
126: }
127: }
128: if (testtorun == null) {
129: junit.textui.TestRunner.run(suite());
130: } else {
131: junit.textui.TestRunner.run(new F_EntityCMT(testtorun));
132: }
133: }
134: }
|