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_mnu_CRW_EC2.java 10108 2007-03-28 09:21:26Z durieuxp $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jtests.clients.entity;
027:
028: import java.util.ArrayList;
029: import java.util.Collection;
030: import java.util.Enumeration;
031: import java.util.Hashtable;
032:
033: import javax.naming.NamingException;
034: import javax.rmi.PortableRemoteObject;
035:
036: import junit.framework.Test;
037: import junit.framework.TestSuite;
038:
039: import org.objectweb.jonas.jtests.beans.relation.mnu.AHomeRemote;
040: import org.objectweb.jonas.jtests.beans.relation.mnu.ARemote;
041: import org.objectweb.jonas.jtests.beans.relation.mnu.BHomeRemote;
042: import org.objectweb.jonas.jtests.beans.relation.mnu.BRemote;
043:
044: /**
045: * For testing many-to-many unidirectional relationships
046: * @author Ph Durieux
047: **/
048: public class F_mnu_CRW_EC2 extends A_mnu {
049:
050: private static String BEAN_HOME_A = "relation_mnu_AtxHome";
051: protected static AHomeRemote ahome = null;
052: private static String BEAN_HOME_B = "relation_mnu_BtxHome";
053: protected static BHomeRemote bhome = null;
054:
055: public F_mnu_CRW_EC2(String name) {
056: super (name);
057: }
058:
059: public AHomeRemote getAHome() {
060: if (ahome == null) {
061: try {
062: ahome = (AHomeRemote) PortableRemoteObject.narrow(ictx
063: .lookup(BEAN_HOME_A), AHomeRemote.class);
064: } catch (NamingException e) {
065: fail("Cannot get bean home: " + e.getMessage());
066: }
067: }
068: return ahome;
069: }
070:
071: public BHomeRemote getBHome() {
072: if (bhome == null) {
073: try {
074: bhome = (BHomeRemote) PortableRemoteObject.narrow(ictx
075: .lookup(BEAN_HOME_B), BHomeRemote.class);
076: } catch (NamingException e) {
077: fail("Cannot get bean home: " + e.getMessage());
078: }
079: }
080: return bhome;
081: }
082:
083: public void testRollback() throws Exception {
084: ARemote a = getAHome().findByPrimaryKey("a1");
085: Collection orig = a.retrieveB();
086: int colsz = orig.size();
087:
088: // disassociate and commit
089: utx.begin();
090: a.assignB(new ArrayList());
091: utx.commit();
092: assertEquals("cmr not reset to null", 0, a.retrieveB().size());
093:
094: // revert to original state outside of a user transaction
095: a.assignB(orig);
096:
097: // sync(false) here forces test to pass
098:
099: // retrieveB inside a transaction
100: utx.begin();
101: assertEquals("CMR not reset to original value", colsz, a
102: .retrieveB().size());
103: utx.rollback();
104:
105: // verify that retrieveB returns correct value after rollback
106: try {
107: assertEquals("rollback should not modify this value",
108: colsz, a.retrieveB().size());
109: } finally {
110: // force sync to cleanup
111: sync(true);
112: }
113: checkIsInitialState();
114: }
115:
116: public static Test suite() {
117: return new TestSuite(F_mnu_CRW_EC2.class);
118: }
119:
120: public static void main(String args[]) {
121: String testtorun = null;
122: // Get args
123: for (int argn = 0; argn < args.length; argn++) {
124: String s_arg = args[argn];
125: Integer i_arg;
126: if (s_arg.equals("-n")) {
127: testtorun = args[++argn];
128: }
129: }
130: if (testtorun == null) {
131: junit.textui.TestRunner.run(suite());
132: } else {
133: junit.textui.TestRunner.run(new F_mnu_CRW_EC2(testtorun));
134: }
135: }
136:
137: }
|