KickJava   Java API By Example, From Geeks To Geeks.

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


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_Frontal.java,v 1.12 2004/08/20 14:55:05 durieuxp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.clients.distribution;
27
28 import java.rmi.NoSuchObjectException JavaDoc;
29 import javax.naming.NamingException JavaDoc;
30 import javax.rmi.PortableRemoteObject JavaDoc;
31
32 import junit.framework.Test;
33 import junit.framework.TestSuite;
34
35 import org.objectweb.carol.util.perfs.CarolJRMPPerformanceHelper;
36 import org.objectweb.jonas.jtests.beans.folder.File;
37 import org.objectweb.jonas.jtests.beans.folder.Folder;
38 import org.objectweb.jonas.jtests.beans.folder.FolderHome;
39 import org.objectweb.jonas.jtests.util.JTestCase;
40
41 /**
42  * Test a session bean remote accessing entities local.
43  * Beans used: folder
44  * @author Philippe Durieux
45  */

46 public class F_Frontal extends JTestCase {
47
48     protected static FolderHome fhome = null;
49     protected Folder folder = null;
50
51     public F_Frontal(String JavaDoc name) {
52         super(name);
53     }
54
55     protected void setUp() {
56         super.setUp();
57         if (fhome == null) {
58             useBeans("folder", true);
59             try {
60                 fhome = (FolderHome) PortableRemoteObject.narrow(ictx.lookup("FolderSYHome"), FolderHome.class);
61                 assertNotNull(fhome);
62             } catch (NamingException JavaDoc e) {
63                 fail("Cannot get bean home");
64             }
65         }
66         if (folder == null) {
67             try {
68                 folder = fhome.create();
69                 assertNotNull(folder);
70             } catch (Exception JavaDoc e) {
71                 fail("Cannot create folder session " + e);
72             }
73         }
74     }
75
76     public void testSetRollbackOnly() throws Exception JavaDoc {
77         Folder f1 = fhome.createForRollback();
78         f1.getIntTS(2);
79         f1.remove();
80     }
81
82     /**
83      * create 1 entity and remove it by its remote reference.
84      */

85     public void testCreate1F() throws Exception JavaDoc {
86         File f = folder.newFile("file1");
87         assertNotNull(f);
88         f.remove();
89     }
90
91     public void testAccessOnRemovedEntity() throws Exception JavaDoc {
92         File f = folder.newFile("file1");
93         File f2 = folder.getFile("file1");
94         f2.remove();
95         try {
96             f.getName();
97             fail("Should not access deleted object");
98         } catch (NoSuchObjectException JavaDoc e) {
99         } catch (Exception JavaDoc e) {
100             fail("Bab Exception:" + e);
101         }
102     }
103
104     /**
105      * print serialized form of the reference
106      */

107     public void testSerializedReference() throws Exception JavaDoc {
108         String JavaDoc mfolder = CarolJRMPPerformanceHelper.getMarshalBytes(folder);
109         //System.out.println("Marshalled Ref = " + mfolder);
110
}
111
112     /**
113      * send a reference as argument
114      */

115     public void testSendRef() throws Exception JavaDoc {
116         for (int i = 0; i < 20; i++) {
117             folder.sendRef(folder);
118         }
119     }
120
121     /**
122      * send an int as argument
123      */

124     public void testSendInt() throws Exception JavaDoc {
125         for (int i = 0; i < 20; i++) {
126             folder.sendInt(1);
127         }
128     }
129
130     /**
131      * send and get a reference as argument
132      */

133     public void testGetRef() throws Exception JavaDoc {
134         for (int i = 0; i < 20; i++) {
135             folder.getRef(folder);
136         }
137     }
138
139     /**
140      * send and get an int as argument
141      */

142     public void testGetInt() throws Exception JavaDoc {
143         for (int i = 0; i < 20; i++) {
144             folder.getInt(1);
145         }
146     }
147
148     /**
149      * send a reference as argument
150      */

151     public void testSendRefTS() throws Exception JavaDoc {
152         for (int i = 0; i < 20; i++) {
153             folder.sendRefTS(folder);
154         }
155     }
156
157     /**
158      * send an int as argument
159      */

160     public void testSendIntTS() throws Exception JavaDoc {
161         for (int i = 0; i < 20; i++) {
162             folder.sendIntTS(1);
163         }
164     }
165
166     /**
167      * send and get a reference as argument
168      */

169     public void testGetRefTS() throws Exception JavaDoc {
170         for (int i = 0; i < 20; i++) {
171             folder.getRefTS(folder);
172         }
173     }
174
175     /**
176      * send and get an int as argument
177      */

178     public void testGetIntTS() throws Exception JavaDoc {
179         for (int i = 0; i < 20; i++) {
180             folder.getIntTS(1);
181         }
182     }
183
184     public static Test suite() {
185         return new TestSuite(F_Frontal.class);
186     }
187
188     public static void main (String JavaDoc args[]) {
189         String JavaDoc testtorun = null;
190         // Get args
191
for (int argn = 0; argn < args.length; argn++) {
192             String JavaDoc s_arg = args[argn];
193             Integer JavaDoc i_arg;
194             if (s_arg.equals("-n")) {
195                 testtorun = args[++argn];
196             }
197         }
198         if (testtorun == null) {
199             junit.textui.TestRunner.run(suite());
200         } else {
201             junit.textui.TestRunner.run(new F_Frontal(testtorun));
202         }
203     }
204 }
205
Popular Tags