001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.openejb.test.stateless;
017:
018: import org.apache.openejb.test.object.OperationsPolicy;
019: import org.apache.openejb.test.beans.TimerSync;
020:
021: /**
022: *
023: * [10] Should be run as the nineth test suite of the BasicStatelessTestClients
024: *
025: * <PRE>
026: * =========================================================================
027: * Operations allowed in the methods of a stateless SessionBean with
028: * bean-managed transaction demarcation
029: * =========================================================================
030: *
031: * Bean method | Bean method can perform the following operations
032: * ______________________|__________________________________________________
033: * |
034: * constructor | -
035: * ______________________|__________________________________________________
036: * |
037: * setSessionContext | SessionContext methods:
038: * | - getEJBHome
039: * | JNDI access to java:comp/env
040: * ______________________|__________________________________________________
041: * |
042: * ejbCreate | SessionContext methods:
043: * ejbRemove | - getEJBHome
044: * | - getEJBObject
045: * | - getUserTransaction
046: * | JNDI access to java:comp/env
047: * ______________________|__________________________________________________
048: * |
049: * business method | SessionContext methods:
050: * from remote interface | - getEJBHome
051: * | - getCallerPrincipal
052: * | - isCallerInRole
053: * | - getEJBObject
054: * | - getUserTransaction
055: * | JNDI access to java:comp/env
056: * | Resource manager access
057: * | Enterprise bean access
058: * ______________________|__________________________________________________
059: * </PRE>
060: *
061: * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
062: * @author <a href="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
063: */
064: public class BMTStatelessAllowedOperationsTests extends
065: BasicStatelessTestClient {
066: protected TimerSync timerSync;
067:
068: public BMTStatelessAllowedOperationsTests() {
069: super ("BMTAllowedOperations.");
070: }
071:
072: protected void setUp() throws Exception {
073: super .setUp();
074: Object obj = initialContext
075: .lookup("client/tests/stateless/BeanManagedBasicStatelessHome");
076: ejbHome = (BasicStatelessHome) javax.rmi.PortableRemoteObject
077: .narrow(obj, BasicStatelessHome.class);
078: ejbObject = ejbHome.createObject();
079: ejbHandle = ejbObject.getHandle();
080: timerSync = (TimerSync) initialContext
081: .lookup("TimerSyncBeanBusinessRemote");
082:
083: /* These tests will only work if the specified
084: * method has already been called by the container.
085: *
086: * TO DO:
087: * Implement a little application senario to ensure
088: * that all methods tested for below have been called
089: * by the container.
090: */
091: ejbObject.businessMethod("let's go!");
092: }
093:
094: protected void tearDown() throws Exception {
095: try {
096: ejbObject.remove();
097: } catch (Exception e) {
098: throw e;
099: } finally {
100: super .tearDown();
101: }
102: }
103:
104: //=====================================
105: // Test EJBContext allowed operations
106: //
107: /**
108: * <PRE>
109: * Bean method | Bean method can perform the following operations
110: * ______________________|__________________________________________________
111: * |
112: * setSessionContext | SessionContext methods:
113: * | - getEJBHome
114: * | - lookup
115: * | JNDI access to java:comp/env
116: * ______________________|__________________________________________________
117: * </PRE>
118: */
119: public void test01_setSessionContext() {
120: try {
121: OperationsPolicy policy = new OperationsPolicy();
122: policy.allow(policy.Context_getEJBHome);
123: policy.allow(policy.Context_lookup);
124: policy.allow(policy.JNDI_access_to_java_comp_env);
125:
126: Object expected = policy;
127: Object actual = ejbObject
128: .getAllowedOperationsReport("setSessionContext");
129:
130: assertNotNull("The OperationsPolicy is null", actual);
131: assertEquals(expected, actual);
132: } catch (Exception e) {
133: fail("Received Exception " + e.getClass() + " : "
134: + e.getMessage());
135: }
136: }
137:
138: /**
139: * <PRE>
140: * Bean method | Bean method can perform the following operations
141: * ______________________|__________________________________________________
142: * |
143: * ejbCreate | SessionContext methods:
144: * ejbRemove | - getEJBHome
145: * | - getEJBObject
146: * | - getUserTransaction
147: * | - getTimerService
148: * | - lookup
149: * | JNDI access to java:comp/env
150: * ______________________|__________________________________________________
151: * </PRE>
152: */
153: public void test02_ejbCreate() {
154: try {
155: OperationsPolicy policy = new OperationsPolicy();
156: policy.allow(policy.Context_getEJBHome);
157: policy.allow(policy.Context_getEJBObject);
158: policy.allow(policy.Context_getUserTransaction);
159: policy.allow(policy.Context_getTimerService);
160: policy.allow(policy.Context_lookup);
161: policy.allow(policy.JNDI_access_to_java_comp_env);
162:
163: Object expected = policy;
164: Object actual = ejbObject
165: .getAllowedOperationsReport("ejbCreate");
166:
167: assertNotNull("The OperationsPolicy is null", actual);
168: assertEquals(expected, actual);
169: } catch (Exception e) {
170: fail("Received Exception " + e.getClass() + " : "
171: + 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: * | - getEJBObject
183: * | - getUserTransaction
184: * | - getTimerService
185: * | - lookup
186: * | JNDI access to java:comp/env
187: * ______________________|__________________________________________________
188: * </PRE>
189: */
190: public void TODO_test03_ejbRemove() {
191: try {
192: /* TO DO: This test needs unique functionality to work */
193: OperationsPolicy policy = new OperationsPolicy();
194: policy.allow(policy.Context_getEJBHome);
195: policy.allow(policy.Context_getEJBObject);
196: policy.allow(policy.Context_getUserTransaction);
197: policy.allow(policy.Context_getTimerService);
198: policy.allow(policy.Context_lookup);
199: policy.allow(policy.JNDI_access_to_java_comp_env);
200:
201: Object expected = policy;
202: Object actual = ejbObject
203: .getAllowedOperationsReport("ejbRemove");
204:
205: assertNotNull("The OperationsPolicy is null", actual);
206: assertEquals(expected, actual);
207: } catch (Exception e) {
208: fail("Received Exception " + e.getClass() + " : "
209: + e.getMessage());
210: }
211: }
212:
213: /**
214: * <PRE>
215: * Bean method | Bean method can perform the following operations
216: * ______________________|__________________________________________________
217: * |
218: * business method | SessionContext methods:
219: * from remote interface | - getEJBHome
220: * | - getCallerPrincipal
221: * | - isCallerInRole
222: * | - getEJBObject
223: * | - getUserTransaction
224: * | - getTimerService
225: * | - lookup
226: * | JNDI access to java:comp/env
227: * | Resource manager access
228: * | Enterprise bean access
229: * ______________________|__________________________________________________
230: * </PRE>
231: */
232: public void test04_businessMethod() {
233: try {
234: OperationsPolicy policy = new OperationsPolicy();
235: policy.allow(policy.Context_getEJBHome);
236: policy.allow(policy.Context_getCallerPrincipal);
237: policy.allow(policy.Context_isCallerInRole);
238: policy.allow(policy.Context_getEJBObject);
239: policy.allow(policy.Context_getUserTransaction);
240: policy.allow(policy.Context_getTimerService);
241: policy.allow(policy.Context_lookup);
242: policy.allow(policy.JNDI_access_to_java_comp_env);
243:
244: Object expected = policy;
245: Object actual = ejbObject
246: .getAllowedOperationsReport("businessMethod");
247:
248: assertNotNull("The OperationsPolicy is null", actual);
249: assertEquals(expected, actual);
250: } catch (Exception e) {
251: fail("Received Exception " + e.getClass() + " : "
252: + e.getMessage());
253: }
254: }
255:
256: public void _test05_ejbTimeout() {
257: try {
258: ejbObject
259: .scheduleTimer("BmtStatelessAllowedOperationsTests");
260: timerSync.waitFor("BmtStatelessAllowedOperationsTests");
261:
262: OperationsPolicy policy = new OperationsPolicy();
263: policy.allow(policy.Context_getEJBHome);
264: policy.allow(policy.Context_getCallerPrincipal);
265: policy.allow(policy.Context_isCallerInRole);
266: policy.allow(policy.Context_getEJBObject);
267: policy.allow(policy.Context_getUserTransaction);
268: policy.allow(policy.Context_getTimerService);
269: policy.allow(policy.Context_lookup);
270: policy.allow(policy.JNDI_access_to_java_comp_env);
271:
272: Object expected = policy;
273: Object actual = ejbObject
274: .getAllowedOperationsReport("ejbTimeout");
275:
276: assertNotNull("The OperationsPolicy is null", actual);
277: assertEquals(expected, actual);
278: } catch (Exception e) {
279: fail("Received Exception " + e.getClass() + " : "
280: + e.getMessage());
281: }
282: }
283: //
284: // Test EJBContext allowed operations
285: //=====================================
286: }
|