KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openejb > test > stateful > StatefulAllowedOperationsTests


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: StatefulAllowedOperationsTests.java 1096 2004-03-26 21:41:16Z dblevins $
44  */

45 package org.openejb.test.stateful;
46
47 import org.openejb.test.object.OperationsPolicy;
48
49 /**
50  *
51  * [9] Should be run as the nineth test suite of the BasicStatefulTestClients
52  *
53  * <PRE>
54  * =========================================================================
55  * Operations allowed in the methods of a stateful SessionBean with
56  * container-managed transaction demarcation
57  * =========================================================================
58  *
59  * Bean method | Bean method can perform the following operations
60  * ______________________|__________________________________________________
61  * |
62  * constructor | -
63  * ______________________|__________________________________________________
64  * |
65  * setSessionContext | SessionContext methods:
66  * | - getEJBHome
67  * | JNDI access to java:comp/env
68  * ______________________|__________________________________________________
69  * |
70  * ejbCreate | SessionContext methods:
71  * ejbRemove | - getEJBHome
72  * ejbActivate | - getCallerPrincipal
73  * ejbPassivate | - isCallerInRole
74  * | - getEJBObject
75  * | JNDI access to java:comp/env
76  * | Resource manager access
77  * | Enterprise bean access
78  * ______________________|__________________________________________________
79  * |
80  * business method | SessionContext methods:
81  * from remote interface | - getEJBHome
82  * | - getCallerPrincipal
83  * | - getRollbackOnly
84  * | - isCallerInRole
85  * | - setRollbackOnly
86  * | - getEJBObject
87  * | JNDI access to java:comp/env
88  * | Resource manager access
89  * | Enterprise bean access
90  * ______________________|__________________________________________________
91  * |
92  * afterBegin | SessionContext methods:
93  * beforeCompletion | - getEJBHome
94  * | - getCallerPrincipal
95  * | - getRollbackOnly
96  * | - isCallerInRole
97  * | - setRollbackOnly
98  * | - getEJBObject
99  * | JNDI access to java:comp/env
100  * | Resource manager access
101  * | Enterprise bean access
102  * ______________________|__________________________________________________
103  * |
104  * afterCompletion | SessionContext methods:
105  * | - getEJBHome
106  * | - getCallerPrincipal
107  * | - isCallerInRole
108  * | - getEJBObject
109  * | JNDI access to java:comp/env
110  * | Resource manager access
111  * | Enterprise bean access
112  * ______________________|__________________________________________________
113  * </PRE>
114  *
115  * @author <a HREF="mailto:david.blevins@visi.com">David Blevins</a>
116  * @author <a HREF="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
117  */

118 public class StatefulAllowedOperationsTests extends BasicStatefulTestClient{
119
120     public StatefulAllowedOperationsTests(){
121         super("AllowedOperations.");
122     }
123
124     protected void setUp() throws Exception JavaDoc{
125         super.setUp();
126         Object JavaDoc obj = initialContext.lookup("client/tests/stateful/BasicStatefulHome");
127         ejbHome = (BasicStatefulHome)javax.rmi.PortableRemoteObject.narrow( obj, BasicStatefulHome.class);
128         ejbObject = ejbHome.create("Fourth Bean");
129         ejbHandle = ejbObject.getHandle();
130         /* These tests will only work if the specified
131          * method has already been called by the container.
132          *
133          * TO DO:
134          * Implement a little application senario to ensure
135          * that all methods tested for below have been called
136          * by the container.
137          */

138     }
139     
140     protected void tearDown() throws Exception JavaDoc{
141         ejbObject.remove();
142         super.tearDown();
143     }
144
145     //=====================================
146
// Test EJBContext allowed operations
147
//
148
/**
149      * <PRE>
150      * Bean method | Bean method can perform the following operations
151      * ______________________|__________________________________________________
152      * |
153      * setSessionContext | SessionContext methods:
154      * | - getEJBHome
155      * | JNDI access to java:comp/env
156      * ______________________|__________________________________________________
157      * </PRE>
158      */

159     public void test01_setSessionContext(){
160         try{
161         OperationsPolicy policy = new OperationsPolicy();
162         policy.allow( policy.Context_getEJBHome );
163         policy.allow( policy.JNDI_access_to_java_comp_env );
164         
165         Object JavaDoc expected = policy;
166         Object JavaDoc actual = ejbObject.getAllowedOperationsReport("setSessionContext");
167         
168         assertNotNull("The OperationsPolicy is null", actual );
169         assertEquals( expected, actual );
170         } catch (Exception JavaDoc e){
171             fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
172         }
173         
174     }
175     /**
176      * <PRE>
177      * Bean method | Bean method can perform the following operations
178      * ______________________|__________________________________________________
179      * |
180      * ejbCreate | SessionContext methods:
181      * ejbRemove | - getEJBHome
182      * ejbActivate | - getCallerPrincipal
183      * ejbPassivate | - isCallerInRole
184      * | - getEJBObject
185      * | JNDI access to java:comp/env
186      * | Resource manager access
187      * | Enterprise bean access
188      * ______________________|__________________________________________________
189      * </PRE>
190      */

191     public void test02_ejbCreate(){
192         try{
193         OperationsPolicy policy = new OperationsPolicy();
194         policy.allow( policy.Context_getEJBHome );
195         policy.allow( policy.Context_getCallerPrincipal );
196         policy.allow( policy.Context_isCallerInRole );
197         policy.allow( policy.Context_getEJBObject );
198         policy.allow( policy.JNDI_access_to_java_comp_env );
199         policy.allow( policy.Resource_manager_access );
200         policy.allow( policy.Enterprise_bean_access );
201         
202         Object JavaDoc expected = policy;
203         Object JavaDoc actual = ejbObject.getAllowedOperationsReport("ejbCreate");
204         
205         assertNotNull("The OperationsPolicy is null", actual );
206         assertEquals( expected, actual );
207         
208         } catch (Exception JavaDoc e){
209             fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
210         }
211     }
212     /**
213      * <PRE>
214      * Bean method | Bean method can perform the following operations
215      * ______________________|__________________________________________________
216      * |
217      * ejbCreate | SessionContext methods:
218      * ejbRemove | - getEJBHome
219      * ejbActivate | - getCallerPrincipal
220      * ejbPassivate | - isCallerInRole
221      * | - getEJBObject
222      * | JNDI access to java:comp/env
223      * | Resource manager access
224      * | Enterprise bean access
225      * ______________________|__________________________________________________
226      * </PRE>
227      */

228     public void test03_ejbRemove(){
229         try{
230         /* TO DO: This test needs unique functionality to work */
231         OperationsPolicy policy = new OperationsPolicy();
232         policy.allow( policy.Context_getEJBHome );
233         policy.allow( policy.Context_getCallerPrincipal );
234         policy.allow( policy.Context_isCallerInRole );
235         policy.allow( policy.Context_getEJBObject );
236         policy.allow( policy.JNDI_access_to_java_comp_env );
237         policy.allow( policy.Resource_manager_access );
238         policy.allow( policy.Enterprise_bean_access );
239     
240         Object JavaDoc expected = policy;
241         Object JavaDoc actual = ejbObject.getAllowedOperationsReport("ejbRemove");
242     
243         assertNotNull("The OperationsPolicy is null", actual );
244         assertEquals( expected, actual );
245
246         } catch (Exception JavaDoc e){
247             fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
248         }
249     }
250     /**
251      * <PRE>
252      * Bean method | Bean method can perform the following operations
253      * ______________________|__________________________________________________
254      * |
255      * ejbCreate | SessionContext methods:
256      * ejbRemove | - getEJBHome
257      * ejbActivate | - getCallerPrincipal
258      * ejbPassivate | - isCallerInRole
259      * | - getEJBObject
260      * | JNDI access to java:comp/env
261      * | Resource manager access
262      * | Enterprise bean access
263      * ______________________|__________________________________________________
264      * </PRE>
265      */

266     public void test04_ejbActivate(){
267         try{
268             
269         OperationsPolicy policy = new OperationsPolicy();
270         policy.allow( policy.Context_getEJBHome );
271         policy.allow( policy.Context_getCallerPrincipal );
272         policy.allow( policy.Context_isCallerInRole );
273         policy.allow( policy.Context_getEJBObject );
274         policy.allow( policy.JNDI_access_to_java_comp_env );
275         policy.allow( policy.Resource_manager_access );
276         policy.allow( policy.Enterprise_bean_access );
277         
278         Object JavaDoc expected = policy;
279         Object JavaDoc actual = ejbObject.getAllowedOperationsReport("ejbActivate");
280         
281         assertNotNull("The OperationsPolicy is null", actual );
282         assertEquals( expected, actual );
283  
284         } catch (Exception JavaDoc e){
285             fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
286         }
287     }
288     /**
289      * <PRE>
290      * Bean method | Bean method can perform the following operations
291      * ______________________|__________________________________________________
292      * |
293      * ejbCreate | SessionContext methods:
294      * ejbRemove | - getEJBHome
295      * ejbActivate | - getCallerPrincipal
296      * ejbPassivate | - isCallerInRole
297      * | - getEJBObject
298      * | JNDI access to java:comp/env
299      * | Resource manager access
300      * | Enterprise bean access
301      * ______________________|__________________________________________________
302      * </PRE>
303      */

304     public void test05_ejbPassivate(){
305         try{
306             
307         OperationsPolicy policy = new OperationsPolicy();
308         policy.allow( policy.Context_getEJBHome );
309         policy.allow( policy.Context_getCallerPrincipal );
310         policy.allow( policy.Context_isCallerInRole );
311         policy.allow( policy.Context_getEJBObject );
312         policy.allow( policy.JNDI_access_to_java_comp_env );
313         policy.allow( policy.Resource_manager_access );
314         policy.allow( policy.Enterprise_bean_access );
315         
316         Object JavaDoc expected = policy;
317         Object JavaDoc actual = ejbObject.getAllowedOperationsReport("ejbPassivate");
318         
319         assertNotNull("The OperationsPolicy is null", actual );
320         assertEquals( expected, actual );
321   
322         } catch (Exception JavaDoc e){
323             fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
324         }
325     }
326     
327     /**
328      * <PRE>
329      * Bean method | Bean method can perform the following operations
330      * ______________________|__________________________________________________
331      * |
332      * business method | SessionContext methods:
333      * from remote interface | - getEJBHome
334      * | - getCallerPrincipal
335      * | - getRollbackOnly
336      * | - isCallerInRole
337      * | - setRollbackOnly
338      * | - getEJBObject
339      * | JNDI access to java:comp/env
340      * | Resource manager access
341      * | Enterprise bean access
342      * ______________________|__________________________________________________
343      * </PRE>
344      */

345     public void test06_businessMethod(){
346       try{
347         OperationsPolicy policy = new OperationsPolicy();
348         policy.allow( policy.Context_getEJBHome );
349         policy.allow( policy.Context_getCallerPrincipal );
350         policy.allow( policy.Context_getRollbackOnly );
351         policy.allow( policy.Context_isCallerInRole );
352         policy.allow( policy.Context_setRollbackOnly );
353         policy.allow( policy.Context_getEJBObject );
354         policy.allow( policy.JNDI_access_to_java_comp_env );
355         policy.allow( policy.Resource_manager_access );
356         policy.allow( policy.Enterprise_bean_access );
357     
358         Object JavaDoc expected = policy;
359         Object JavaDoc actual = ejbObject.getAllowedOperationsReport("businessMethod");
360     
361         assertNotNull("The OperationsPolicy is null", actual );
362         assertEquals( expected, actual );
363         
364         } catch (Exception JavaDoc e){
365             fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
366         }
367         
368     }
369     /**
370      * <PRE>
371      * Bean method | Bean method can perform the following operations
372      * ______________________|__________________________________________________
373      * |
374      * afterBegin | SessionContext methods:
375      * beforeCompletion | - getEJBHome
376      * | - getCallerPrincipal
377      * | - getRollbackOnly
378      * | - isCallerInRole
379      * | - setRollbackOnly
380      * | - getEJBObject
381      * | JNDI access to java:comp/env
382      * | Resource manager access
383      * | Enterprise bean access
384      * ______________________|__________________________________________________
385      * </PRE>
386      */

387     public void test07_afterBegin(){
388         try{
389             
390         OperationsPolicy policy = new OperationsPolicy();
391         policy.allow( policy.Context_getEJBHome );
392         policy.allow( policy.Context_getCallerPrincipal );
393         policy.allow( policy.Context_getRollbackOnly );
394         policy.allow( policy.Context_isCallerInRole );
395         policy.allow( policy.Context_setRollbackOnly );
396         policy.allow( policy.Context_getEJBObject );
397         policy.allow( policy.JNDI_access_to_java_comp_env );
398         policy.allow( policy.Resource_manager_access );
399         policy.allow( policy.Enterprise_bean_access );
400     
401         Object JavaDoc expected = policy;
402         Object JavaDoc actual = ejbObject.getAllowedOperationsReport("afterBegin");
403     
404         assertNotNull("The OperationsPolicy is null", actual );
405         assertEquals( expected, actual );
406
407         } catch (Exception JavaDoc e){
408             fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
409         }
410     }
411     
412     /**
413      * <PRE>
414      * Bean method | Bean method can perform the following operations
415      * ______________________|__________________________________________________
416      * |
417      * afterBegin | SessionContext methods:
418      * beforeCompletion | - getEJBHome
419      * | - getCallerPrincipal
420      * | - getRollbackOnly
421      * | - isCallerInRole
422      * | - setRollbackOnly
423      * | - getEJBObject
424      * | JNDI access to java:comp/env
425      * | Resource manager access
426      * | Enterprise bean access
427      * ______________________|__________________________________________________
428      * </PRE>
429      */

430     public void test08_beforeCompletion(){
431         try{
432             
433         OperationsPolicy policy = new OperationsPolicy();
434         policy.allow( policy.Context_getEJBHome );
435         policy.allow( policy.Context_getCallerPrincipal );
436         policy.allow( policy.Context_getRollbackOnly );
437         policy.allow( policy.Context_isCallerInRole );
438         policy.allow( policy.Context_setRollbackOnly );
439         policy.allow( policy.Context_getEJBObject );
440         policy.allow( policy.JNDI_access_to_java_comp_env );
441         policy.allow( policy.Resource_manager_access );
442         policy.allow( policy.Enterprise_bean_access );
443     
444         Object JavaDoc expected = policy;
445         Object JavaDoc actual = ejbObject.getAllowedOperationsReport("beforeCompletion");
446     
447         assertNotNull("The OperationsPolicy is null", actual );
448         assertEquals( expected, actual );
449  
450         } catch (Exception JavaDoc e){
451             fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
452         }
453     }
454     /**
455      * <PRE>
456      * Bean method | Bean method can perform the following operations
457      * ______________________|__________________________________________________
458      * |
459      * afterCompletion | SessionContext methods:
460      * | - getEJBHome
461      * | - getCallerPrincipal
462      * | - isCallerInRole
463      * | - getEJBObject
464      * | JNDI access to java:comp/env
465      * | Resource manager access
466      * | Enterprise bean access
467      * ______________________|__________________________________________________
468      * </PRE>
469      */

470     public void test09_afterCompletion(){
471         try{
472             
473         OperationsPolicy policy = new OperationsPolicy();
474         policy.allow( policy.Context_getEJBHome );
475         policy.allow( policy.Context_getCallerPrincipal );
476         policy.allow( policy.Context_isCallerInRole );
477         policy.allow( policy.Context_getEJBObject );
478         policy.allow( policy.JNDI_access_to_java_comp_env );
479         policy.allow( policy.Resource_manager_access );
480         policy.allow( policy.Enterprise_bean_access );
481         
482         Object JavaDoc expected = policy;
483         Object JavaDoc actual = ejbObject.getAllowedOperationsReport("afterCompletion");
484         
485         assertNotNull("The OperationsPolicy is null", actual );
486         assertEquals( expected, actual );
487  
488         } catch (Exception JavaDoc e){
489             fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
490         }
491     }
492     //
493
// Test EJBContext allowed operations
494
//=====================================
495
}
496
497
498
Popular Tags