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_FrontalCMP2.java 7497 2005-10-13 07:53:22Z durieuxp $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jtests.clients.distribution;
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.relation.omb.AHomeRemote;
035: import org.objectweb.jonas.jtests.beans.relation.omb.BHomeRemote;
036: import org.objectweb.jonas.jtests.beans.relation.omb.BRemote;
037: import org.objectweb.jonas.jtests.beans.relation.omb.Front;
038: import org.objectweb.jonas.jtests.beans.relation.omb.FrontHome;
039: import org.objectweb.jonas.jtests.util.JTestCase;
040:
041: /**
042: * Test a session bean remote accessing CMP2 entities local, with
043: * relationships.
044: * Beans used: relation/omb
045: * @author Philippe Durieux
046: */
047: public class F_FrontalCMP2 extends JTestCase {
048:
049: private static String BEAN_HOME_A = "relation_omb_AHome";
050: protected static AHomeRemote ahome = null;
051: private static String BEAN_HOME_B = "relation_omb_BHome";
052: protected static BHomeRemote bhome = null;
053: protected static FrontHome fhome = null;
054:
055: public F_FrontalCMP2(String name) {
056: super (name);
057: }
058:
059: protected void setUp() {
060: super .setUp();
061: if (fhome == null) {
062: useBeans("omb", false);
063: try {
064: fhome = (FrontHome) PortableRemoteObject.narrow(ictx
065: .lookup("relation_omb_FrontHome"),
066: FrontHome.class);
067: ahome = (AHomeRemote) PortableRemoteObject.narrow(ictx
068: .lookup(BEAN_HOME_A), AHomeRemote.class);
069: bhome = (BHomeRemote) PortableRemoteObject.narrow(ictx
070: .lookup(BEAN_HOME_B), BHomeRemote.class);
071: assertNotNull(fhome);
072: assertNotNull(ahome);
073: assertNotNull(bhome);
074: } catch (NamingException e) {
075: fail("Cannot get bean home");
076: }
077: }
078: }
079:
080: /**
081: * Uses a session bean (inside ejbCreate) to create other beans
082: * and find them in the same transaction.
083: * This mimics a part of code of Bonita.
084: */
085: public void testCreateFind() throws Exception {
086: // actual test
087: Front front = fhome.create("project", "role");
088: // cleaning part
089: BRemote br = bhome.findByName("role", "project");
090: br.remove();
091: ahome.remove("project");
092: front.remove();
093: }
094:
095: /**
096: * Test for stateful session bean serialization
097: */
098: public void testSerialization() throws Exception {
099: final int tnb1 = 8;
100: Front[] tarray1 = new Front[tnb1];
101: for (int i = 0; i < tnb1; i++) {
102: tarray1[i] = fhome.create("seri" + i, "num" + i);
103: }
104: for (int i = 0; i < tnb1; i++) {
105: tarray1[i].remove();
106: }
107: }
108:
109: public static Test suite() {
110: return new TestSuite(F_FrontalCMP2.class);
111: }
112:
113: public static void main(String args[]) {
114: String testtorun = null;
115: // Get args
116: for (int argn = 0; argn < args.length; argn++) {
117: String s_arg = args[argn];
118: Integer 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_FrontalCMP2(testtorun));
127: }
128: }
129: }
|