KickJava   Java API By Example, From Geeks To Geeks.

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


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

45 package org.openejb.test.stateless;
46
47 import javax.ejb.EJBObject JavaDoc;
48
49 import org.openejb.test.object.OperationsPolicy;
50
51 /**
52  *
53  * [9] Should be run as the nineth test suite of the BasicStatelessTestClients
54  *
55  * <PRE>
56  * =========================================================================
57  * Operations allowed in the methods of a stateless SessionBean with
58  * container-managed transaction demarcation
59  * =========================================================================
60  *
61  * Bean method | Bean method can perform the following operations
62  * ______________________|__________________________________________________
63  * |
64  * constructor | -
65  * ______________________|__________________________________________________
66  * |
67  * setSessionContext | SessionContext methods:
68  * | - getEJBHome
69  * | JNDI access to java:comp/env
70  * ______________________|__________________________________________________
71  * |
72  * ejbCreate | SessionContext methods:
73  * ejbRemove | - getEJBHome
74  * | - getEJBObject
75  * | JNDI access to java:comp/env
76  * ______________________|__________________________________________________
77  * |
78  * business method | SessionContext methods:
79  * from remote interface | - getEJBHome
80  * | - getCallerPrincipal
81  * | - getRollbackOnly
82  * | - isCallerInRole
83  * | - setRollbackOnly
84  * | - getEJBObject
85  * | JNDI access to java:comp/env
86  * | Resource manager access
87  * | Enterprise bean access
88  * ______________________|__________________________________________________
89  * </PRE>
90  *
91  * @author <a HREF="mailto:david.blevins@visi.com">David Blevins</a>
92  * @author <a HREF="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
93  */

94 public class StatelessAllowedOperationsTests extends BasicStatelessTestClient{
95
96     public StatelessAllowedOperationsTests(){
97         super("AllowedOperations.");
98     }
99
100     protected void setUp() throws Exception JavaDoc{
101         super.setUp();
102         Object JavaDoc obj = initialContext.lookup("client/tests/stateless/BasicStatelessHome");
103         ejbHome = (BasicStatelessHome)javax.rmi.PortableRemoteObject.narrow( obj, BasicStatelessHome.class);
104         ejbObject = ejbHome.create();
105         ejbHandle = ejbObject.getHandle();
106         //setUp_ejbActivate_Passivate();
107

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         ejbObject.businessMethod("activate me please");
117     }
118     
119     private void setUp_ejbActivate_Passivate() throws Exception JavaDoc{
120
121         /* Create more instances to fill the pool size
122          * causing instances to be passivated
123          */

124         EJBObject JavaDoc[] ejbObjects = new EJBObject JavaDoc[10];
125         for (int i=0; i < ejbObjects.length; i++){
126             ejbObjects[i] = ejbHome.create();
127         }
128         ejbObject.businessMethod("activate me please");
129     }
130     
131     protected void tearDown() throws Exception JavaDoc{
132         try {
133             ejbObject.remove();
134         } catch (Exception JavaDoc e){
135             throw e;
136         } finally {
137             super.tearDown();
138         }
139     }
140
141     //=====================================
142
// Test EJBContext allowed operations
143
//
144
/**
145      * <PRE>
146      * Bean method | Bean method can perform the following operations
147      * ______________________|__________________________________________________
148      * |
149      * setSessionContext | SessionContext methods:
150      * | - getEJBHome
151      * | JNDI access to java:comp/env
152      * ______________________|__________________________________________________
153      * </PRE>
154      */

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

182     public void test02_ejbCreate() {
183     // The stateless session bean has container managed transactions
184
// so, the test Context_getUserTransaction should fail, but,
185
// it does not. Someone should see why it does not fail.
186
try {
187             OperationsPolicy policy = new OperationsPolicy();
188             policy.allow( OperationsPolicy.Context_getEJBHome );
189             policy.allow( OperationsPolicy.Context_getEJBObject );
190             policy.allow( OperationsPolicy.JNDI_access_to_java_comp_env );
191             
192             Object JavaDoc expected = policy;
193             Object JavaDoc actual = ejbObject.getAllowedOperationsReport("ejbCreate");
194             
195             assertNotNull("The OperationsPolicy is null", actual );
196             assertEquals( expected, actual );
197         } catch (Exception JavaDoc e){
198             fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
199         }
200     }
201     /**
202      * <PRE>
203      * Bean method | Bean method can perform the following operations
204      * ______________________|__________________________________________________
205      * |
206      * ejbCreate | SessionContext methods:
207      * ejbRemove | - getEJBHome
208      * | - getEJBObject
209      * | JNDI access to java:comp/env
210      * ______________________|__________________________________________________
211      * </PRE>
212      */

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

249     public void TODO_test04_businessMethod(){
250         try {
251             OperationsPolicy policy = new OperationsPolicy();
252             policy.allow( OperationsPolicy.Context_getEJBHome );
253             policy.allow( OperationsPolicy.Context_getCallerPrincipal );
254             policy.allow( OperationsPolicy.Context_getRollbackOnly );
255             policy.allow( OperationsPolicy.Context_isCallerInRole );
256             policy.allow( OperationsPolicy.Context_setRollbackOnly );
257             policy.allow( OperationsPolicy.Context_getEJBObject );
258             policy.allow( OperationsPolicy.JNDI_access_to_java_comp_env );
259             policy.allow( OperationsPolicy.Resource_manager_access );
260             policy.allow( OperationsPolicy.Enterprise_bean_access );
261         
262             Object JavaDoc expected = policy;
263             Object JavaDoc actual = ejbObject.getAllowedOperationsReport("businessMethod");
264         
265             assertNotNull("The OperationsPolicy is null", actual );
266             assertEquals( expected, actual );
267         } catch (Exception JavaDoc e){
268             fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
269         }
270     }
271     //
272
// Test EJBContext allowed operations
273
//=====================================
274
}
275
276
277
Popular Tags