KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > clients > entity > F_IsModified


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_IsModified.java,v 1.3 2004/03/19 11:57:15 benoitf Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.clients.entity;
27
28 import javax.naming.NamingException JavaDoc;
29 import javax.rmi.PortableRemoteObject JavaDoc;
30
31 import junit.framework.Test;
32 import junit.framework.TestSuite;
33
34 import org.objectweb.jonas.jtests.beans.annuaire.Personne;
35 import org.objectweb.jonas.jtests.beans.annuaire.PersonneHome;
36 import org.objectweb.jonas.jtests.util.JTestCase;
37
38 /**
39  * This test isModified feature on entity bean CMP.
40  * Beans used: annuaire
41  * @author Philippe Coq, Philippe Durieux (jonas team)
42  */

43 public class F_IsModified extends JTestCase {
44
45     private static String JavaDoc BEAN_HOME = "annuairePersonneECHome";
46     protected static PersonneHome ehome = null;
47     String JavaDoc mynum = "63800";
48     String JavaDoc myname = "Max";
49
50     public F_IsModified(String JavaDoc name) {
51     super(name);
52     }
53
54     protected void setUp() {
55     super.setUp();
56     if (ehome == null) {
57         useBeans("annuaire", true);
58         try {
59         ehome = (PersonneHome) PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME), PersonneHome.class);
60         } catch (NamingException JavaDoc e) {
61         fail("Cannot get bean home");
62         }
63     }
64     }
65
66     /**
67      * test that readonly methods does not trigger ejbStore
68      */

69     public void testNotModified() throws Exception JavaDoc {
70
71     Personne acc = ehome.create(myname, mynum);
72
73     // readonly transaction
74
acc.reset();
75     utx.begin();
76     acc.getNom();
77     assertTrue(! acc.isDirty());
78     utx.commit();
79     assertTrue(! acc.ejbStoreCalled());
80     assertTrue(acc.isModifiedCalled());
81
82     acc.remove();
83     }
84
85     /**
86      * test that write methods do trigger ejbStore
87      */

88     public void testModified() throws Exception JavaDoc {
89
90     Personne acc = ehome.create(myname, mynum);
91     String JavaDoc os = "100";
92
93     // write transaction
94
acc.reset();
95     utx.begin();
96     acc.setNumero(os);
97     assertTrue(acc.isDirty());
98     utx.commit();
99     assertTrue(acc.ejbStoreCalled());
100     assertTrue(acc.isModifiedCalled());
101
102     String JavaDoc ns = acc.getNumero();
103     assertTrue(ns.equals(os));
104     assertTrue(! acc.isDirty());
105
106     acc.remove();
107     }
108
109     public static Test suite() {
110     return new TestSuite(F_IsModified.class);
111     }
112
113     public static void main (String JavaDoc args[]) {
114     String JavaDoc testtorun = null;
115     // Get args
116
for (int argn = 0; argn < args.length; argn++) {
117         String JavaDoc s_arg = args[argn];
118         Integer JavaDoc i_arg;
119         if (s_arg.equals("-n")) {
120         testtorun = args[++argn];
121         }
122     }
123     if (testtorun == null) {
124         junit.textui.TestRunner.run(suite());
125     } else {
126         junit.textui.TestRunner.run(new F_IsModified(testtorun));
127     }
128     }
129 }
130
Popular Tags