KickJava   Java API By Example, From Geeks To Geeks.

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


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: BMTStatefulAllowedOperationsTests.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  * [10] 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  * bean-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  * | - getUserTransaction
76  * | JNDI access to java:comp/env
77  * | Resource manager access
78  * | Enterprise bean access
79  * ______________________|__________________________________________________
80  * |
81  * business method | SessionContext methods:
82  * from remote interface | - getEJBHome
83  * | - getCallerPrincipal
84  * | - isCallerInRole
85  * | - getEJBObject
86  * | - getUserTransaction
87  * | JNDI access to java:comp/env
88  * | Resource manager access
89  * | Enterprise bean access
90  * ______________________|__________________________________________________
91  * </PRE>
92  *
93  * @author <a HREF="mailto:david.blevins@visi.com">David Blevins</a>
94  * @author <a HREF="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
95  */

96 public class BMTStatefulAllowedOperationsTests extends BasicStatefulTestClient{
97
98     public BMTStatefulAllowedOperationsTests(){
99         super("BMTAllowedOperations.");
100     }
101
102     protected void setUp() throws Exception JavaDoc{
103         super.setUp();
104         Object JavaDoc obj = initialContext.lookup("client/tests/stateful/BeanManagedBasicStatefulHome");
105         ejbHome = (BasicStatefulHome)javax.rmi.PortableRemoteObject.narrow( obj, BasicStatefulHome.class);
106         ejbObject = ejbHome.create("Fifth Bean");
107         ejbHandle = ejbObject.getHandle();
108         /* These tests will only work if the specified
109          * method has already been called by the container.
110          *
111          * TO DO:
112          * Implement a little application senario to ensure
113          * that all methods tested for below have been called
114          * by the container.
115          */

116     }
117     
118     protected void tearDown() throws Exception JavaDoc{
119         ejbObject.remove();
120         super.tearDown();
121     }
122
123     //=====================================
124
// Test EJBContext allowed operations
125
//
126
/**
127      * <PRE>
128      * Bean method | Bean method can perform the following operations
129      * ______________________|__________________________________________________
130      * |
131      * setSessionContext | SessionContext methods:
132      * | - getEJBHome
133      * | JNDI access to java:comp/env
134      * ______________________|__________________________________________________
135      * </PRE>
136      */

137     public void test01_setSessionContext(){
138         try{
139         OperationsPolicy policy = new OperationsPolicy();
140         policy.allow( policy.Context_getEJBHome );
141         policy.allow( policy.JNDI_access_to_java_comp_env );
142         
143         Object JavaDoc expected = policy;
144         Object JavaDoc actual = ejbObject.getAllowedOperationsReport("setSessionContext");
145         
146         assertNotNull("The OperationsPolicy is null", actual );
147         assertEquals( expected, actual );
148         } catch (Exception JavaDoc e){
149             fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
150         }
151     }
152     /**
153      * <PRE>
154      * Bean method | Bean method can perform the following operations
155      * ______________________|__________________________________________________
156      * |
157      * ejbCreate | SessionContext methods:
158      * ejbRemove | - getEJBHome
159      * ejbActivate | - getCallerPrincipal
160      * ejbPassivate | - isCallerInRole
161      * | - getEJBObject
162      * | - getUserTransaction
163      * | JNDI access to java:comp/env
164      * | Resource manager access
165      * | Enterprise bean access
166      * ______________________|__________________________________________________
167      * </PRE>
168      */

169     public void test02_ejbCreate(){
170         try{
171         OperationsPolicy policy = new OperationsPolicy();
172         policy.allow( policy.Context_getEJBHome );
173         policy.allow( policy.Context_getCallerPrincipal );
174         policy.allow( policy.Context_isCallerInRole );
175         policy.allow( policy.Context_getEJBObject );
176         policy.allow( policy.Context_getUserTransaction );
177         policy.allow( policy.JNDI_access_to_java_comp_env );
178         policy.allow( policy.Resource_manager_access );
179         policy.allow( policy.Enterprise_bean_access );
180         
181         Object JavaDoc expected = policy;
182         Object JavaDoc actual = ejbObject.getAllowedOperationsReport("ejbCreate");
183         
184         assertNotNull("The OperationsPolicy is null", actual );
185         assertEquals( expected, actual );
186         } catch (Exception JavaDoc e){
187             fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
188         }
189     }
190     /**
191      * <PRE>
192      * Bean method | Bean method can perform the following operations
193      * ______________________|__________________________________________________
194      * |
195      * ejbCreate | SessionContext methods:
196      * ejbRemove | - getEJBHome
197      * ejbActivate | - getCallerPrincipal
198      * ejbPassivate | - isCallerInRole
199      * | - getEJBObject
200      * | - getUserTransaction
201      * | JNDI access to java:comp/env
202      * | Resource manager access
203      * | Enterprise bean access
204      * ______________________|__________________________________________________
205      * </PRE>
206      */

207     public void test03_ejbRemove(){
208         try{
209         /* TO DO: This test needs unique functionality to work */
210         OperationsPolicy policy = new OperationsPolicy();
211         policy.allow( policy.Context_getEJBHome );
212         policy.allow( policy.Context_getCallerPrincipal );
213         policy.allow( policy.Context_isCallerInRole );
214         policy.allow( policy.Context_getEJBObject );
215         policy.allow( policy.Context_getUserTransaction );
216         policy.allow( policy.JNDI_access_to_java_comp_env );
217         policy.allow( policy.Resource_manager_access );
218         policy.allow( policy.Enterprise_bean_access );
219     
220         Object JavaDoc expected = policy;
221         Object JavaDoc actual = ejbObject.getAllowedOperationsReport("ejbRemove");
222     
223         assertNotNull("The OperationsPolicy is null", actual );
224         assertEquals( expected, actual );
225         } catch (Exception JavaDoc e){
226             fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
227         }
228     }
229     /**
230      * <PRE>
231      * Bean method | Bean method can perform the following operations
232      * ______________________|__________________________________________________
233      * |
234      * ejbCreate | SessionContext methods:
235      * ejbRemove | - getEJBHome
236      * ejbActivate | - getCallerPrincipal
237      * ejbPassivate | - isCallerInRole
238      * | - getEJBObject
239      * | - getUserTransaction
240      * | JNDI access to java:comp/env
241      * | Resource manager access
242      * | Enterprise bean access
243      * ______________________|__________________________________________________
244      * </PRE>
245      */

246     public void test04_ejbActivate(){
247         try{
248         OperationsPolicy policy = new OperationsPolicy();
249         policy.allow( policy.Context_getEJBHome );
250         policy.allow( policy.Context_getCallerPrincipal );
251         policy.allow( policy.Context_isCallerInRole );
252         policy.allow( policy.Context_getEJBObject );
253         policy.allow( policy.Context_getUserTransaction );
254         policy.allow( policy.JNDI_access_to_java_comp_env );
255         policy.allow( policy.Resource_manager_access );
256         policy.allow( policy.Enterprise_bean_access );
257         
258         Object JavaDoc expected = policy;
259         Object JavaDoc actual = ejbObject.getAllowedOperationsReport("ejbActivate");
260         
261         assertNotNull("The OperationsPolicy is null", actual );
262         assertEquals( expected, actual );
263         } catch (Exception JavaDoc e){
264             fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
265         }
266     }
267     /**
268      * <PRE>
269      * Bean method | Bean method can perform the following operations
270      * ______________________|__________________________________________________
271      * |
272      * ejbCreate | SessionContext methods:
273      * ejbRemove | - getEJBHome
274      * ejbActivate | - getCallerPrincipal
275      * ejbPassivate | - isCallerInRole
276      * | - getEJBObject
277      * | - getUserTransaction
278      * | JNDI access to java:comp/env
279      * | Resource manager access
280      * | Enterprise bean access
281      * ______________________|__________________________________________________
282      * </PRE>
283      */

284     public void test05_ejbPassivate(){
285         try{
286         OperationsPolicy policy = new OperationsPolicy();
287         policy.allow( policy.Context_getEJBHome );
288         policy.allow( policy.Context_getCallerPrincipal );
289         policy.allow( policy.Context_isCallerInRole );
290         policy.allow( policy.Context_getEJBObject );
291         policy.allow( policy.Context_getUserTransaction );
292         policy.allow( policy.JNDI_access_to_java_comp_env );
293         policy.allow( policy.Resource_manager_access );
294         policy.allow( policy.Enterprise_bean_access );
295         
296         Object JavaDoc expected = policy;
297         Object JavaDoc actual = ejbObject.getAllowedOperationsReport("ejbPassivate");
298         
299         assertNotNull("The OperationsPolicy is null", actual );
300         assertEquals( expected, actual );
301         } catch (Exception JavaDoc e){
302             fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
303         }
304     }
305     
306     /**
307      * <PRE>
308      * Bean method | Bean method can perform the following operations
309      * ______________________|__________________________________________________
310      * |
311      * business method | SessionContext methods:
312      * from remote interface | - getEJBHome
313      * | - getCallerPrincipal
314      * | - isCallerInRole
315      * | - getEJBObject
316      * | - getUserTransaction
317      * | JNDI access to java:comp/env
318      * | Resource manager access
319      * | Enterprise bean access
320      * ______________________|__________________________________________________
321      * </PRE>
322      */

323     public void test06_businessMethod(){
324         try{
325         OperationsPolicy policy = new OperationsPolicy();
326         policy.allow( policy.Context_getEJBHome );
327         policy.allow( policy.Context_getCallerPrincipal );
328         policy.allow( policy.Context_isCallerInRole );
329         policy.allow( policy.Context_getEJBObject );
330         policy.allow( policy.Context_getUserTransaction );
331         policy.allow( policy.JNDI_access_to_java_comp_env );
332         policy.allow( policy.Resource_manager_access );
333         policy.allow( policy.Enterprise_bean_access );
334     
335         Object JavaDoc expected = policy;
336         Object JavaDoc actual = ejbObject.getAllowedOperationsReport("businessMethod");
337     
338         assertNotNull("The OperationsPolicy is null", actual );
339         assertEquals( expected, actual );
340         } catch (Exception JavaDoc e){
341             fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
342         }
343     }
344     //
345
// Test EJBContext allowed operations
346
//=====================================
347
}
348
349
350
Popular Tags