KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > clients > session > F_ClientViewSF


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_ClientViewSF.java,v 1.10 2005/07/26 15:11:53 durieuxp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.clients.session;
27
28 import junit.framework.Test;
29 import junit.framework.TestSuite;
30 import javax.rmi.PortableRemoteObject JavaDoc;
31 import org.objectweb.jonas.jtests.beans.local.Target;
32 import org.objectweb.jonas.jtests.beans.local.TargetSFHome;
33 import org.objectweb.jonas.jtests.beans.local.TargetSLHome;
34
35
36 /**
37  * testcases specifics for stateful session beans must be here
38  *
39  * - isIdentical, create<Method>
40  */

41 public class F_ClientViewSF extends A_ClientView {
42
43     protected static String JavaDoc BEAN_HOME = "EJB/localTargetSFHome";
44     protected static TargetSFHome home = null;
45
46     public F_ClientViewSF(String JavaDoc name) {
47         super(name);
48     }
49
50     /**
51      * test EJBObject.isIdentical on two beans
52      * @see Spec EJB2.0 6.9.1
53      */

54     public void testIsIdenticalOnBeans() throws Exception JavaDoc {
55         Target tr1 = (Target) getHome().create();
56         Target tr2 = (Target) getHome().create();
57         assertTrue(!tr1.isIdentical(tr2));
58         tr1.remove();
59         tr2.remove();
60     }
61
62     /**
63      * test create with parameters
64      */

65     public void testCreateWithParameter() throws Exception JavaDoc {
66         String JavaDoc s1 = "String1";
67         TargetSFHome tsfh = (TargetSFHome)getHome();
68         Target tr = tsfh.create(s1, 1000);
69         assertEquals(tr.getString(), s1);
70         assertEquals(tr.getNumber(), 1000);
71         assertTrue(!tr.isCreatedViaCreateXX());
72         tr.remove();
73     }
74
75     /**
76      * test create<METHOD>
77      *
78      */

79     public void testCreateMethod() throws Exception JavaDoc {
80         String JavaDoc s2 = "String2";
81         TargetSFHome tsfh = (TargetSFHome)getHome();
82         Target tr = tsfh.createXX(s2,2000);
83         assertEquals(tr.getString(),s2);
84         assertEquals(tr.getNumber(),2000);
85         assertTrue(tr.isCreatedViaCreateXX());
86         tr.remove();
87     }
88
89     /**
90      * Test for stateful session bean serialization
91      */

92     public void testSerialization() throws Exception JavaDoc {
93         final int tnb1 = 30;
94         final int tnb2 = 20;
95         Target [] tarray1 = new Target[tnb1];
96         Target [] tarray2 = new Target[tnb2];
97         TargetSFHome tsfh = (TargetSFHome)getHome();
98         for (int i = 0; i < tnb1; i++) {
99             tarray1[i] = tsfh.create("seri", i);
100         }
101         for (int i = 0; i < tnb1; i++) {
102             assertEquals(tarray1[i].getNumber(), i);
103         }
104         for (int i = 0; i < tnb2; i++) {
105             tarray2[i] = tsfh.create("seri", i);
106         }
107         for (int i = 0; i < tnb2; i++) {
108             assertEquals(tarray2[i].getNumber(), i);
109         }
110         for (int i = 0; i < tnb1; i++) {
111             assertEquals(tarray1[i].getNumber(), i);
112         }
113         for (int i = 0; i < tnb2; i++) {
114             tarray2[i].remove();
115         }
116         for (int i = 0; i < tnb1; i++) {
117             tarray1[i].remove();
118         }
119     }
120
121
122     /**
123      * init environment:
124      */

125     protected void setUp() {
126         super.setUp();
127         useBeans("local", false);
128     }
129
130     public TargetSLHome getHome() throws Exception JavaDoc {
131         if (home == null) {
132             home = (TargetSFHome) PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME),TargetSFHome.class) ;
133         }
134         assertTrue(home != null);
135         return home;
136     }
137
138     public static Test suite() {
139         return new TestSuite(F_ClientViewSF.class);
140     }
141
142
143
144     public static void main (String JavaDoc args[]) throws Exception JavaDoc {
145         String JavaDoc testtorun = null;
146         // Get args
147
for (int argn = 0; argn < args.length; argn++) {
148             String JavaDoc s_arg = args[argn];
149             Integer JavaDoc i_arg;
150             if (s_arg.equals("-n")) {
151                 testtorun = args[++argn];
152             }
153         }
154         if (testtorun == null) {
155             junit.textui.TestRunner.run(suite());
156         } else {
157             junit.textui.TestRunner.run(new F_ClientViewSF(testtorun));
158
159         }
160     }
161 }
162
Popular Tags