1 25 26 package org.objectweb.jonas.jtests.clients.transaction; 27 28 import javax.naming.NamingException ; 29 import javax.rmi.PortableRemoteObject ; 30 import junit.framework.Test; 31 import junit.framework.TestSuite; 32 import org.objectweb.jonas.jtests.beans.annuaire.Personne; 33 import org.objectweb.jonas.jtests.beans.annuaire.PersonneHome; 34 import org.objectweb.jonas.jtests.util.JTestCase; 35 36 40 public class F_EntityCMT extends JTestCase { 41 42 private static String BEAN_HOME = "annuairePersonneECHome"; 43 protected static PersonneHome ehome = null; 44 String mynum = "63801"; 45 String badnum = "99999"; 46 String newnum = "12341"; 47 String myname = "Phil"; 48 49 public F_EntityCMT(String name) { 50 super(name); 51 } 52 53 protected void setUp() { 54 super.setUp(); 55 if (ehome == null) { 56 useBeans("annuaire", true); 57 try { 58 ehome = (PersonneHome) PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME), PersonneHome.class); 59 } catch (NamingException e) { 60 fail("Cannot get bean Home:" + e); 61 } 62 } 63 } 64 65 71 public void testStateAfterRollBack() throws Exception { 72 Personne acc = ehome.create(myname, mynum); 73 utx.begin(); 74 acc.setNumero(badnum); 75 utx.rollback(); 76 assertEquals(mynum, acc.getNumero()); 77 acc.remove(); } 79 80 86 public void testStateAfterRollBackNoTx() throws Exception { 87 Personne acc = ehome.create(myname, mynum); 88 acc.setNumero(newnum); 89 utx.begin(); 90 acc.setNumero(badnum); 91 utx.rollback(); 92 assertEquals(newnum, acc.getNumero()); 93 acc.remove(); } 95 96 102 public void testStateAfterRollBackTx() throws Exception { 103 Personne acc = ehome.create(myname, mynum); 104 utx.begin(); 105 acc.setNumero(newnum); 106 utx.commit(); 107 utx.begin(); 108 acc.setNumero(badnum); 109 utx.rollback(); 110 assertEquals(newnum, acc.getNumero()); 111 acc.remove(); } 113 114 public static Test suite() { 115 return new TestSuite(F_EntityCMT.class); 116 } 117 118 public static void main (String args[]) { 119 String testtorun = null; 120 for (int argn = 0; argn < args.length; argn++) { 122 String sarg = args[argn]; 123 if (sarg.equals("-n")) { 124 testtorun = args[++argn]; 125 } 126 } 127 if (testtorun == null) { 128 junit.textui.TestRunner.run(suite()); 129 } else { 130 junit.textui.TestRunner.run(new F_EntityCMT(testtorun)); 131 } 132 } 133 } 134 | Popular Tags |