KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > clients > local > A_ClientView


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

25
26 package org.objectweb.jonas.jtests.clients.local;
27
28 import javax.ejb.EJBException JavaDoc;
29 import javax.ejb.NoSuchObjectLocalException JavaDoc;
30 import javax.ejb.RemoveException JavaDoc;
31 import javax.rmi.PortableRemoteObject JavaDoc;
32
33 import org.objectweb.jonas.jtests.beans.local.TargetLocal;
34 import org.objectweb.jonas.jtests.beans.local.TargetSLHome;
35 import org.objectweb.jonas.jtests.beans.local.TargetSLLocalHome;
36 import org.objectweb.jonas.jtests.util.JTestCase;
37
38 /**
39  * This Class defines Test cases that can be run either SF or SL bean.
40  * These tests are related to the "Client View of a Session Bean"
41  * A session bean that supports both Local & Remote interface is used
42  * (TargetSL oe TargetSF in beans/local)
43  * Here are testcases taht must be run remotly
44  * @see EJB2.0 specification Chapter 6.
45  * @author Ph Coq, Ph Durieux
46  */

47
48 public abstract class A_ClientView extends JTestCase {
49
50     public A_ClientView(String JavaDoc name) {
51     super(name);
52     }
53
54
55
56    /**
57      * @return TargetSLLocalHome
58      */

59     public abstract TargetSLLocalHome getLocalHome() throws Exception JavaDoc;
60
61
62
63     /**
64      * Lookup a LocalHome Object
65      *
66      * This test verify that we can look up a LocalHome Object
67      * via the root context
68      */

69
70     public void testLocalLookup() throws Exception JavaDoc {
71     TargetSLLocalHome h = null;
72         h = getLocalHome();
73     assertTrue(h != null);
74     }
75
76
77     /**
78      * EJB Reference
79      *
80      * This test verify that we can look up a Home Object of a bean in the same ejbjar file
81      * via the java:comp/env subcontext using an ejb-reference contains an ejb-link.
82      */

83     public void testEjbRef() throws Exception JavaDoc {
84
85     TargetSLHome home = null;
86     String JavaDoc bName = "java:comp/env/ejb/targetremotelink";
87         home = (TargetSLHome) PortableRemoteObject.narrow(ictx.lookup(bName), TargetSLHome.class);
88     assertTrue(home != null);
89     }
90
91     /**
92      * EJB Reference
93      *
94      * This test verify that we can look up a Home Object of a bean (in the same ejbjar file)
95      * via the java:comp/env subcontext using an ejb-reference with a jonas-ejb-reference.
96      */

97     public void testEjbRefWithJonasEjbRef() throws Exception JavaDoc {
98
99     TargetSLHome home = null;
100     String JavaDoc bName = "java:comp/env/ejb/targetremotenolink";
101         home = (TargetSLHome) PortableRemoteObject.narrow(ictx.lookup(bName), TargetSLHome.class);
102     assertTrue(home != null);
103     }
104
105
106    /**
107      * EJBLocal Reference
108      *
109      * This test verify that we can look up a LocalHome Object
110      * via the java:comp/env subcontext
111      */

112
113     public void testEjbLocalRef() throws Exception JavaDoc {
114
115     TargetSLLocalHome home = null;
116     String JavaDoc bName = "java:comp/env/ejb/targetlocal";
117         home = (TargetSLLocalHome) ictx.lookup(bName);
118     assertTrue(home != null);
119     }
120
121
122
123    /**
124      * This test verify we can create a Local session bean and remove it
125      */

126     public void testLocalCreateRemove() throws Exception JavaDoc {
127     TargetLocal tl = getLocalHome().create();
128     tl.remove();
129     }
130
131
132     /**
133      * This test verify we can create a Local session , access to the bean
134      * via its local interface and remove it
135      * It verifies we cannot access to the bean after remove
136      */

137     public void testLocalBusinessMethod1() throws Exception JavaDoc {
138         TargetLocal tl = getLocalHome().create();
139     assertEquals(20, tl.getTwenty());
140     tl.remove();
141         try {
142             tl.lmethod2("Bye");
143             fail("NoSuchObjectLocalException must be raised");
144         } catch (NoSuchObjectLocalException JavaDoc e) {
145         }
146     }
147
148
149     /**
150      * Same test than testLocalBusinessMethod1 but two calls to businessmethod
151      */

152     public void testLocalBusinessMethod2() throws Exception JavaDoc {
153         TargetLocal tl = getLocalHome().create();
154     assertEquals(20, tl.getTwenty());
155         assertEquals(20, tl.getTwenty());
156     tl.remove();
157     }
158
159    /**
160      * test 3 Local Business Methods
161      */

162     public void testLocalBusinessMethod3() throws Exception JavaDoc {
163         TargetLocal tl = getLocalHome().create();
164     assertEquals(20, tl.getTwenty());
165         tl.lmethod2("Hello");
166         assertEquals(20, tl.getTwenty());
167     tl.remove();
168     }
169
170  
171    /**
172      * test EJBLocalObject.isIdentical on the same bean
173      */

174     public void testLocalIsIdenticalOnSameBean() throws Exception JavaDoc {
175     TargetLocal tl = getLocalHome().create();
176     assertTrue(tl.isIdentical(tl));
177     tl.remove();
178     }
179
180
181     /**
182      * test EJBLocalObject.getPrimary Key
183      * This test verify that an EJB Exception must be catched
184      */

185     public void testLocalGetPrimaryKey() throws Exception JavaDoc {
186     TargetLocal tl = getLocalHome().create();
187     try {
188         tl.getPrimaryKey();
189         fail("getPrimaryKey should raise EJBException on a session bean");
190     } catch (EJBException JavaDoc e) {
191     } finally {
192         tl.remove();
193     }
194     }
195
196
197
198    /**
199      * test that EJBLocalHome.remove(pk) should raise EJBException (API) or
200      * RemoveException (spec EJB 2.0 6.3.2)
201      */

202     public void testLocalRemoveByPK() throws Exception JavaDoc {
203     Object JavaDoc pk = null;
204     try {
205         getLocalHome().remove(pk);
206             fail("getPrimaryKey should raise Exception on a session bean");
207     } catch (EJBException JavaDoc e) {
208     } catch (RemoveException JavaDoc e) {
209     }
210     }
211
212
213 }
214
Popular Tags