KickJava   Java API By Example, From Geeks To Geeks.

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


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

45 package org.openejb.test.stateless;
46
47 import org.openejb.test.object.OperationsPolicy;
48
49 /**
50  *
51  * [10] Should be run as the nineth test suite of the BasicStatelessTestClients
52  *
53  * <PRE>
54  * =========================================================================
55  * Operations allowed in the methods of a stateless 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  * | - getEJBObject
73  * | - getUserTransaction
74  * | JNDI access to java:comp/env
75  * ______________________|__________________________________________________
76  * |
77  * business method | SessionContext methods:
78  * from remote interface | - getEJBHome
79  * | - getCallerPrincipal
80  * | - isCallerInRole
81  * | - getEJBObject
82  * | - getUserTransaction
83  * | JNDI access to java:comp/env
84  * | Resource manager access
85  * | Enterprise bean access
86  * ______________________|__________________________________________________
87  * </PRE>
88  *
89  * @author <a HREF="mailto:david.blevins@visi.com">David Blevins</a>
90  * @author <a HREF="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
91  */

92 public class BMTStatelessAllowedOperationsTests extends BasicStatelessTestClient{
93
94     public BMTStatelessAllowedOperationsTests(){
95         super("BMTAllowedOperations.");
96     }
97
98     protected void setUp() throws Exception JavaDoc{
99         super.setUp();
100         Object JavaDoc obj = initialContext.lookup("client/tests/stateless/BeanManagedBasicStatelessHome");
101         ejbHome = (BasicStatelessHome)javax.rmi.PortableRemoteObject.narrow( obj, BasicStatelessHome.class);
102         ejbObject = ejbHome.create();
103         ejbHandle = ejbObject.getHandle();
104         ejbObject.businessMethod("let's go!");
105         /* These tests will only work if the specified
106          * method has already been called by the container.
107          *
108          * TO DO:
109          * Implement a little application senario to ensure
110          * that all methods tested for below have been called
111          * by the container.
112          */

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

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

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

197     public void TODO_test03_ejbRemove(){
198         try{
199             /* TO DO: This test needs unique functionality to work */
200             OperationsPolicy policy = new OperationsPolicy();
201             policy.allow( policy.Context_getEJBHome );
202             policy.allow( policy.Context_getEJBObject );
203             policy.allow( policy.Context_getUserTransaction );
204             policy.allow( policy.JNDI_access_to_java_comp_env );
205         
206             Object JavaDoc expected = policy;
207             Object JavaDoc actual = ejbObject.getAllowedOperationsReport("ejbRemove");
208         
209             assertNotNull("The OperationsPolicy is null", actual );
210             assertEquals( expected, actual );
211         } catch (Exception JavaDoc e){
212             fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
213         }
214     }
215     
216     /**
217      * <PRE>
218      * Bean method | Bean method can perform the following operations
219      * ______________________|__________________________________________________
220      * |
221      * business method | SessionContext methods:
222      * from remote interface | - getEJBHome
223      * | - getCallerPrincipal
224      * | - isCallerInRole
225      * | - getEJBObject
226      * | - getUserTransaction
227      * | JNDI access to java:comp/env
228      * | Resource manager access
229      * | Enterprise bean access
230      * ______________________|__________________________________________________
231      * </PRE>
232      */

233     public void test04_businessMethod(){
234         try{
235             OperationsPolicy policy = new OperationsPolicy();
236             policy.allow( policy.Context_getEJBHome );
237             policy.allow( policy.Context_getCallerPrincipal );
238             policy.allow( policy.Context_isCallerInRole );
239             policy.allow( policy.Context_getEJBObject );
240             policy.allow( policy.Context_getUserTransaction );
241             policy.allow( policy.JNDI_access_to_java_comp_env );
242             policy.allow( policy.Resource_manager_access );
243             policy.allow( policy.Enterprise_bean_access );
244         
245             Object JavaDoc expected = policy;
246             Object JavaDoc actual = ejbObject.getAllowedOperationsReport("businessMethod");
247         
248             assertNotNull("The OperationsPolicy is null", actual );
249             assertEquals( expected, actual );
250         } catch (Exception JavaDoc e){
251             fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
252         }
253     }
254     //
255
// Test EJBContext allowed operations
256
//=====================================
257
}
258
259
260
Popular Tags