KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openejb > test > stateless > EncStatelessBean


1 /**
2  * Redistribution and use of this software and associated documentation
3  * ("Software"), with or without modification, are permitted provided
4  * that the following conditions are met:
5  *
6  * 1. Redistributions of source code must retain copyright
7  * statements and notices. Redistributions must also contain a
8  * copy of this document.
9  *
10  * 2. Redistributions in binary form must reproduce the
11  * above copyright notice, this list of conditions and the
12  * following disclaimer in the documentation and/or other
13  * materials provided with the distribution.
14  *
15  * 3. The name "Exolab" must not be used to endorse or promote
16  * products derived from this Software without prior written
17  * permission of Exoffice Technologies. For written permission,
18  * please contact info@exolab.org.
19  *
20  * 4. Products derived from this Software may not be called "Exolab"
21  * nor may "Exolab" appear in their names without prior written
22  * permission of Exoffice Technologies. Exolab is a registered
23  * trademark of Exoffice Technologies.
24  *
25  * 5. Due credit should be given to the Exolab Project
26  * (http://www.exolab.org/).
27  *
28  * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
29  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32  * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39  * OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  * Copyright 1999 (C) Exoffice Technologies Inc. All Rights Reserved.
42  *
43  * $Id: EncStatelessBean.java 1096 2004-03-26 21:41:16Z dblevins $
44  */

45 package org.openejb.test.stateless;
46
47 import java.rmi.RemoteException JavaDoc;
48
49 import javax.ejb.EJBException JavaDoc;
50 import javax.ejb.SessionContext JavaDoc;
51 import javax.naming.InitialContext JavaDoc;
52
53 import junit.framework.Assert;
54 import junit.framework.AssertionFailedError;
55
56 import org.openejb.test.TestFailureException;
57 import org.openejb.test.entity.bmp.BasicBmpHome;
58 import org.openejb.test.entity.bmp.BasicBmpObject;
59 import org.openejb.test.stateful.BasicStatefulHome;
60 import org.openejb.test.stateful.BasicStatefulObject;
61
62 /**
63  *
64  * @author <a HREF="mailto:david.blevins@visi.com">David Blevins</a>
65  * @author <a HREF="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
66  */

67 public class EncStatelessBean implements javax.ejb.SessionBean JavaDoc{
68     
69     private String JavaDoc name;
70     private SessionContext JavaDoc ejbContext;
71     
72     
73     //=============================
74
// Home interface methods
75
//
76
//
77
// Home interface methods
78
//=============================
79

80
81     //=============================
82
// Remote interface methods
83
//
84
public void lookupEntityBean() throws TestFailureException{
85         try{
86             try{
87             InitialContext JavaDoc ctx = new InitialContext JavaDoc();
88             Assert.assertNotNull("The InitialContext is null", ctx );
89             
90             BasicBmpHome home = (BasicBmpHome) javax.rmi.PortableRemoteObject.narrow( ctx.lookup("java:comp/env/stateless/beanReferences/bmp_entity"), BasicBmpHome.class );
91             Assert.assertNotNull("The EJBHome looked up is null",home);
92
93             BasicBmpObject object = home.create("Enc Bean");
94             Assert.assertNotNull("The EJBObject is null", object );
95             } catch (Exception JavaDoc e){
96                 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
97             }
98         } catch (AssertionFailedError afe){
99             throw new TestFailureException(afe);
100         }
101     }
102     
103     public void lookupStatefulBean() throws TestFailureException{
104         try{
105             try{
106             InitialContext JavaDoc ctx = new InitialContext JavaDoc();
107             Assert.assertNotNull("The InitialContext is null", ctx );
108             
109             BasicStatefulHome home = (BasicStatefulHome) javax.rmi.PortableRemoteObject.narrow( ctx.lookup("java:comp/env/stateless/beanReferences/stateful"), BasicStatefulHome.class );
110             Assert.assertNotNull("The EJBHome looked up is null",home);
111
112             BasicStatefulObject object = home.create("Enc Bean");
113             Assert.assertNotNull("The EJBObject is null", object );
114             } catch (Exception JavaDoc e){
115                 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
116             }
117         } catch (AssertionFailedError afe){
118             throw new TestFailureException(afe);
119         }
120     }
121     
122     public void lookupStatelessBean() throws TestFailureException{
123         try{
124             try{
125             InitialContext JavaDoc ctx = new InitialContext JavaDoc();
126             Assert.assertNotNull("The InitialContext is null", ctx );
127             
128             BasicStatelessHome home = (BasicStatelessHome) javax.rmi.PortableRemoteObject.narrow( ctx.lookup("java:comp/env/stateless/beanReferences/stateless"), BasicStatelessHome.class );
129             Assert.assertNotNull("The EJBHome looked up is null",home);
130
131             BasicStatelessObject object = home.create();
132             Assert.assertNotNull("The EJBObject is null", object );
133             } catch (Exception JavaDoc e){
134                 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
135             }
136         } catch (AssertionFailedError afe){
137             throw new TestFailureException(afe);
138         }
139     }
140
141     public void lookupStringEntry() throws TestFailureException{
142         try{
143             try{
144             InitialContext JavaDoc ctx = new InitialContext JavaDoc();
145             Assert.assertNotNull("The InitialContext is null", ctx );
146
147             String JavaDoc expected = new String JavaDoc("1");
148             String JavaDoc actual = (String JavaDoc)ctx.lookup("java:comp/env/stateless/references/String");
149             
150             Assert.assertNotNull("The String looked up is null", actual );
151             Assert.assertEquals(expected, actual );
152
153             } catch (Exception JavaDoc e){
154                 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
155             }
156         } catch (AssertionFailedError afe){
157             throw new TestFailureException(afe);
158         }
159     }
160     
161     public void lookupDoubleEntry() throws TestFailureException{
162         try{
163             try{
164             InitialContext JavaDoc ctx = new InitialContext JavaDoc();
165             Assert.assertNotNull("The InitialContext is null", ctx );
166             
167             Double JavaDoc expected = new Double JavaDoc(1.0D);
168             Double JavaDoc actual = (Double JavaDoc)ctx.lookup("java:comp/env/stateless/references/Double");
169             
170             Assert.assertNotNull("The Double looked up is null", actual );
171             Assert.assertEquals(expected, actual );
172
173             } catch (Exception JavaDoc e){
174                 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
175             }
176         } catch (AssertionFailedError afe){
177             throw new TestFailureException(afe);
178         }
179     }
180     
181     public void lookupLongEntry() throws TestFailureException{
182         try{
183             try{
184             InitialContext JavaDoc ctx = new InitialContext JavaDoc();
185             Assert.assertNotNull("The InitialContext is null", ctx );
186             
187             Long JavaDoc expected = new Long JavaDoc(1L);
188             Long JavaDoc actual = (Long JavaDoc)ctx.lookup("java:comp/env/stateless/references/Long");
189             
190             Assert.assertNotNull("The Long looked up is null", actual );
191             Assert.assertEquals(expected, actual );
192
193             } catch (Exception JavaDoc e){
194                 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
195             }
196         } catch (AssertionFailedError afe){
197             throw new TestFailureException(afe);
198         }
199     }
200     
201     public void lookupFloatEntry() throws TestFailureException{
202         try{
203             try{
204             InitialContext JavaDoc ctx = new InitialContext JavaDoc();
205             Assert.assertNotNull("The InitialContext is null", ctx );
206             
207             Float JavaDoc expected = new Float JavaDoc(1.0F);
208             Float JavaDoc actual = (Float JavaDoc)ctx.lookup("java:comp/env/stateless/references/Float");
209             
210             Assert.assertNotNull("The Float looked up is null", actual );
211             Assert.assertEquals(expected, actual );
212
213             } catch (Exception JavaDoc e){
214                 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
215             }
216         } catch (AssertionFailedError afe){
217             throw new TestFailureException(afe);
218         }
219     }
220     
221     public void lookupIntegerEntry() throws TestFailureException{
222         try{
223             try{
224             InitialContext JavaDoc ctx = new InitialContext JavaDoc();
225             Assert.assertNotNull("The InitialContext is null", ctx );
226             
227             Integer JavaDoc expected = new Integer JavaDoc(1);
228             Integer JavaDoc actual = (Integer JavaDoc)ctx.lookup("java:comp/env/stateless/references/Integer");
229             
230             Assert.assertNotNull("The Integer looked up is null", actual );
231             Assert.assertEquals(expected, actual );
232
233             } catch (Exception JavaDoc e){
234                 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
235             }
236         } catch (AssertionFailedError afe){
237             throw new TestFailureException(afe);
238         }
239     }
240     
241     public void lookupShortEntry() throws TestFailureException{
242         try{
243             try{
244             InitialContext JavaDoc ctx = new InitialContext JavaDoc();
245             Assert.assertNotNull("The InitialContext is null", ctx );
246             
247             Short JavaDoc expected = new Short JavaDoc((short)1);
248             Short JavaDoc actual = (Short JavaDoc)ctx.lookup("java:comp/env/stateless/references/Short");
249             
250             Assert.assertNotNull("The Short looked up is null", actual );
251             Assert.assertEquals(expected, actual );
252
253             } catch (Exception JavaDoc e){
254                 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
255             }
256         } catch (AssertionFailedError afe){
257             throw new TestFailureException(afe);
258         }
259     }
260     
261     public void lookupBooleanEntry() throws TestFailureException{
262         try{
263             try{
264             InitialContext JavaDoc ctx = new InitialContext JavaDoc();
265             Assert.assertNotNull("The InitialContext is null", ctx );
266             
267             Boolean JavaDoc expected = new Boolean JavaDoc(true);
268             Boolean JavaDoc actual = (Boolean JavaDoc)ctx.lookup("java:comp/env/stateless/references/Boolean");
269             
270             Assert.assertNotNull("The Boolean looked up is null", actual );
271             Assert.assertEquals(expected, actual );
272
273             } catch (Exception JavaDoc e){
274                 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
275             }
276         } catch (AssertionFailedError afe){
277             throw new TestFailureException(afe);
278         }
279     }
280     
281     public void lookupByteEntry() throws TestFailureException{
282         try{
283             try{
284             InitialContext JavaDoc ctx = new InitialContext JavaDoc();
285             Assert.assertNotNull("The InitialContext is null", ctx );
286             
287             Byte JavaDoc expected = new Byte JavaDoc((byte)1);
288             Byte JavaDoc actual = (Byte JavaDoc)ctx.lookup("java:comp/env/stateless/references/Byte");
289             
290             Assert.assertNotNull("The Byte looked up is null", actual );
291             Assert.assertEquals(expected, actual );
292
293             } catch (Exception JavaDoc e){
294                 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
295             }
296         } catch (AssertionFailedError afe){
297             throw new TestFailureException(afe);
298         }
299     }
300
301     public void lookupResource() throws TestFailureException{
302         try{
303             try{
304             InitialContext JavaDoc ctx = new InitialContext JavaDoc();
305             Assert.assertNotNull("The InitialContext is null", ctx );
306             } catch (Exception JavaDoc e){
307                 Assert.fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
308             }
309         } catch (AssertionFailedError afe){
310             throw new TestFailureException(afe);
311         }
312     }
313
314     //
315
// Remote interface methods
316
//=============================
317

318
319     //================================
320
// SessionBean interface methods
321
//
322
/**
323      * Set the associated session context. The container calls this method
324      * after the instance creation.
325      */

326     public void setSessionContext(SessionContext JavaDoc ctx) throws EJBException JavaDoc,RemoteException JavaDoc {
327         ejbContext = ctx;
328     }
329     /**
330      *
331      * @param name
332      * @exception javax.ejb.CreateException
333      */

334     public void ejbCreate() throws javax.ejb.CreateException JavaDoc{
335         this.name = "nameless automaton";
336     }
337     /**
338      * A container invokes this method before it ends the life of the session
339      * object. This happens as a result of a client's invoking a remove
340      * operation, or when a container decides to terminate the session object
341      * after a timeout.
342      */

343     public void ejbRemove() throws EJBException JavaDoc,RemoteException JavaDoc {
344     }
345
346     /**
347      * The activate method is called when the instance is activated
348      * from its "passive" state. The instance should acquire any resource
349      * that it has released earlier in the ejbPassivate() method.
350      */

351     public void ejbActivate() throws EJBException JavaDoc,RemoteException JavaDoc {
352         // Should never called.
353
}
354     /**
355      * The passivate method is called before the instance enters
356      * the "passive" state. The instance should release any resources that
357      * it can re-acquire later in the ejbActivate() method.
358      */

359     public void ejbPassivate() throws EJBException JavaDoc,RemoteException JavaDoc {
360         // Should never called.
361
}
362
363     //
364
// SessionBean interface methods
365
//================================
366
}
367
Popular Tags