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_IsModified.java 4406 2004-03-19 11:57:20Z benoitf $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jtests.clients.entity;
027:
028: import javax.naming.NamingException;
029: import javax.rmi.PortableRemoteObject;
030:
031: import junit.framework.Test;
032: import junit.framework.TestSuite;
033:
034: import org.objectweb.jonas.jtests.beans.annuaire.Personne;
035: import org.objectweb.jonas.jtests.beans.annuaire.PersonneHome;
036: import org.objectweb.jonas.jtests.util.JTestCase;
037:
038: /**
039: * This test isModified feature on entity bean CMP.
040: * Beans used: annuaire
041: * @author Philippe Coq, Philippe Durieux (jonas team)
042: */
043: public class F_IsModified extends JTestCase {
044:
045: private static String BEAN_HOME = "annuairePersonneECHome";
046: protected static PersonneHome ehome = null;
047: String mynum = "63800";
048: String myname = "Max";
049:
050: public F_IsModified(String name) {
051: super (name);
052: }
053:
054: protected void setUp() {
055: super .setUp();
056: if (ehome == null) {
057: useBeans("annuaire", true);
058: try {
059: ehome = (PersonneHome) PortableRemoteObject.narrow(ictx
060: .lookup(BEAN_HOME), PersonneHome.class);
061: } catch (NamingException e) {
062: fail("Cannot get bean home");
063: }
064: }
065: }
066:
067: /**
068: * test that readonly methods does not trigger ejbStore
069: */
070: public void testNotModified() throws Exception {
071:
072: Personne acc = ehome.create(myname, mynum);
073:
074: // readonly transaction
075: acc.reset();
076: utx.begin();
077: acc.getNom();
078: assertTrue(!acc.isDirty());
079: utx.commit();
080: assertTrue(!acc.ejbStoreCalled());
081: assertTrue(acc.isModifiedCalled());
082:
083: acc.remove();
084: }
085:
086: /**
087: * test that write methods do trigger ejbStore
088: */
089: public void testModified() throws Exception {
090:
091: Personne acc = ehome.create(myname, mynum);
092: String os = "100";
093:
094: // write transaction
095: acc.reset();
096: utx.begin();
097: acc.setNumero(os);
098: assertTrue(acc.isDirty());
099: utx.commit();
100: assertTrue(acc.ejbStoreCalled());
101: assertTrue(acc.isModifiedCalled());
102:
103: String ns = acc.getNumero();
104: assertTrue(ns.equals(os));
105: assertTrue(!acc.isDirty());
106:
107: acc.remove();
108: }
109:
110: public static Test suite() {
111: return new TestSuite(F_IsModified.class);
112: }
113:
114: public static void main(String args[]) {
115: String testtorun = null;
116: // Get args
117: for (int argn = 0; argn < args.length; argn++) {
118: String s_arg = args[argn];
119: Integer i_arg;
120: if (s_arg.equals("-n")) {
121: testtorun = args[++argn];
122: }
123: }
124: if (testtorun == null) {
125: junit.textui.TestRunner.run(suite());
126: } else {
127: junit.textui.TestRunner.run(new F_IsModified(testtorun));
128: }
129: }
130: }
|