KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > clients > transaction > F_EntityCMT


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: F_EntityCMT.java,v 1.2 2003/09/17 06:50:40 durieuxp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.clients.transaction;
27
28 import javax.naming.NamingException JavaDoc;
29 import javax.rmi.PortableRemoteObject JavaDoc;
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 /**
37  * Test for Bean Managed Transaction entity beans
38  * @author Philippe Durieux
39  */

40 public class F_EntityCMT extends JTestCase {
41
42     private static String JavaDoc BEAN_HOME = "annuairePersonneECHome";
43     protected static PersonneHome ehome = null;
44     String JavaDoc mynum = "63801";
45     String JavaDoc badnum = "99999";
46     String JavaDoc newnum = "12341";
47     String JavaDoc myname = "Phil";
48
49     public F_EntityCMT(String JavaDoc 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 JavaDoc e) {
60                 fail("Cannot get bean Home:" + e);
61             }
62         }
63     }
64
65     /**
66      * Test that rollback will not lost old bean state
67      * - create bean
68      * - make a transaction that change the num and roll it back
69      * - check num has not been changed.
70      */

71     public void testStateAfterRollBack() throws Exception JavaDoc {
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(); // cleaning
78
}
79
80     /**
81      * Test that rollback will not lost old bean state
82      * - access bean
83      * - make a transaction rolled back
84      * - check state has not been changed.
85      */

86     public void testStateAfterRollBackNoTx() throws Exception JavaDoc {
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(); // cleaning
94
}
95
96     /**
97      * Test that rollback will not lost old bean state
98      * - access bean
99      * - make a transaction rolled back
100      * - check state has not been changed.
101      */

102     public void testStateAfterRollBackTx() throws Exception JavaDoc {
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(); // cleaning
112
}
113
114     public static Test suite() {
115         return new TestSuite(F_EntityCMT.class);
116     }
117
118     public static void main (String JavaDoc args[]) {
119         String JavaDoc testtorun = null;
120         // Get args
121
for (int argn = 0; argn < args.length; argn++) {
122             String JavaDoc 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