KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > clients > distribution > F_FrontalCMP2


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

25
26 package org.objectweb.jonas.jtests.clients.distribution;
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.relation.omb.AHomeRemote;
35 import org.objectweb.jonas.jtests.beans.relation.omb.BHomeRemote;
36 import org.objectweb.jonas.jtests.beans.relation.omb.BRemote;
37 import org.objectweb.jonas.jtests.beans.relation.omb.Front;
38 import org.objectweb.jonas.jtests.beans.relation.omb.FrontHome;
39 import org.objectweb.jonas.jtests.util.JTestCase;
40
41 /**
42  * Test a session bean remote accessing CMP2 entities local, with
43  * relationships.
44  * Beans used: relation/omb
45  * @author Philippe Durieux
46  */

47 public class F_FrontalCMP2 extends JTestCase {
48
49     private static String JavaDoc BEAN_HOME_A = "relation_omb_AHome";
50     protected static AHomeRemote ahome = null;
51     private static String JavaDoc BEAN_HOME_B = "relation_omb_BHome";
52     protected static BHomeRemote bhome = null;
53     protected static FrontHome fhome = null;
54
55     public F_FrontalCMP2(String JavaDoc name) {
56         super(name);
57     }
58     
59
60     protected void setUp() {
61         super.setUp();
62         if (fhome == null) {
63             useBeans("omb", false);
64             try {
65                 fhome = (FrontHome) PortableRemoteObject.narrow(ictx.lookup("relation_omb_FrontHome"), FrontHome.class);
66                 ahome = (AHomeRemote) PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME_A), AHomeRemote.class);
67                 bhome = (BHomeRemote) PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME_B), BHomeRemote.class);
68                 assertNotNull(fhome);
69                 assertNotNull(ahome);
70                 assertNotNull(bhome);
71             } catch (NamingException JavaDoc e) {
72                 fail("Cannot get bean home");
73             }
74         }
75     }
76
77     /**
78      * Uses a session bean (inside ejbCreate) to create other beans
79      * and find them in the same transaction.
80      * This mimics a part of code of Bonita.
81      */

82     public void testCreateFind() throws Exception JavaDoc {
83         // actual test
84
Front front = fhome.create("project", "role");
85         // cleaning part
86
BRemote br = bhome.findByName("role", "project");
87         br.remove();
88         ahome.remove("project");
89         front.remove();
90     }
91
92     public static Test suite() {
93         return new TestSuite(F_FrontalCMP2.class);
94     }
95
96     public static void main (String JavaDoc args[]) {
97         String JavaDoc testtorun = null;
98         // Get args
99
for (int argn = 0; argn < args.length; argn++) {
100             String JavaDoc s_arg = args[argn];
101             Integer JavaDoc i_arg;
102             if (s_arg.equals("-n")) {
103                 testtorun = args[++argn];
104             }
105         }
106         if (testtorun == null) {
107             junit.textui.TestRunner.run(suite());
108         } else {
109             junit.textui.TestRunner.run(new F_FrontalCMP2(testtorun));
110         }
111     }
112 }
113
Popular Tags