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 javax.ejb.EJBObject;
019:
020: import org.apache.openejb.test.object.OperationsPolicy;
021: import org.apache.openejb.test.beans.TimerSync;
022:
023: /**
024: *
025: * [9] Should be run as the nineth test suite of the BasicStatelessTestClients
026: *
027: * <PRE>
028: * =========================================================================
029: * Operations allowed in the methods of a stateless SessionBean with
030: * container-managed transaction demarcation
031: * =========================================================================
032: *
033: * Bean method | Bean method can perform the following operations
034: * ______________________|__________________________________________________
035: * |
036: * constructor | -
037: * ______________________|__________________________________________________
038: * |
039: * setSessionContext | SessionContext methods:
040: * | - getEJBHome
041: * | JNDI access to java:comp/env
042: * ______________________|__________________________________________________
043: * |
044: * ejbCreate | SessionContext methods:
045: * ejbRemove | - getEJBHome
046: * | - getEJBObject
047: * | JNDI access to java:comp/env
048: * ______________________|__________________________________________________
049: * |
050: * business method | SessionContext methods:
051: * from remote interface | - getEJBHome
052: * | - getCallerPrincipal
053: * | - getRollbackOnly
054: * | - isCallerInRole
055: * | - setRollbackOnly
056: * | - getEJBObject
057: * | JNDI access to java:comp/env
058: * | Resource manager access
059: * | Enterprise bean access
060: * ______________________|__________________________________________________
061: * </PRE>
062: *
063: * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
064: * @author <a href="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
065: */
066: public class StatelessAllowedOperationsTests extends
067: BasicStatelessTestClient {
068: protected TimerSync timerSync;
069:
070: public StatelessAllowedOperationsTests() {
071: super ("AllowedOperations.");
072: }
073:
074: protected void setUp() throws Exception {
075: super .setUp();
076: Object obj = initialContext
077: .lookup("client/tests/stateless/BasicStatelessHome");
078: ejbHome = (BasicStatelessHome) javax.rmi.PortableRemoteObject
079: .narrow(obj, BasicStatelessHome.class);
080: ejbObject = ejbHome.createObject();
081: ejbHandle = ejbObject.getHandle();
082: timerSync = (TimerSync) initialContext
083: .lookup("TimerSyncBeanBusinessRemote");
084:
085: //setUp_ejbActivate_Passivate();
086:
087: /* These tests will only work if the specified
088: * method has already been called by the container.
089: *
090: * TO DO:
091: * Implement a little application senario to ensure
092: * that all methods tested for below have been called
093: * by the container.
094: */
095: ejbObject.businessMethod("activate me please");
096: }
097:
098: private void setUp_ejbActivate_Passivate() throws Exception {
099:
100: /* Create more instances to fill the pool size
101: * causing instances to be passivated
102: */
103: EJBObject[] ejbObjects = new EJBObject[10];
104: for (int i = 0; i < ejbObjects.length; i++) {
105: ejbObjects[i] = ejbHome.createObject();
106: }
107: ejbObject.businessMethod("activate me please");
108: }
109:
110: protected void tearDown() throws Exception {
111: try {
112: ejbObject.remove();
113: } catch (Exception e) {
114: throw e;
115: } finally {
116: super .tearDown();
117: }
118: }
119:
120: //=====================================
121: // Test EJBContext allowed operations
122: //
123: /**
124: * <PRE>
125: * Bean method | Bean method can perform the following operations
126: * ______________________|__________________________________________________
127: * |
128: * setSessionContext | SessionContext methods:
129: * | - getEJBHome
130: * | - lookup
131: * | JNDI access to java:comp/env
132: * ______________________|__________________________________________________
133: * </PRE>
134: */
135: public void test01_setSessionContext() {
136: try {
137: OperationsPolicy policy = new OperationsPolicy();
138: policy.allow(OperationsPolicy.Context_getEJBHome);
139: policy.allow(OperationsPolicy.Context_lookup);
140: policy.allow(OperationsPolicy.JNDI_access_to_java_comp_env);
141:
142: Object expected = policy;
143: Object actual = ejbObject
144: .getAllowedOperationsReport("setSessionContext");
145:
146: assertNotNull("The OperationsPolicy is null", actual);
147: assertEquals(expected, actual);
148: } catch (Exception e) {
149: fail("Received Exception " + e.getClass() + " : "
150: + e.getMessage());
151: }
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: * | - getTimerService
163: * | - lookup
164: * | JNDI access to java:comp/env
165: * ______________________|__________________________________________________
166: * </PRE>
167: */
168: public void test02_ejbCreate() {
169: // The stateless session bean has container managed transactions
170: // so, the test Context_getUserTransaction should fail, but,
171: // it does not. Someone should see why it does not fail.
172: try {
173: OperationsPolicy policy = new OperationsPolicy();
174: policy.allow(OperationsPolicy.Context_getEJBHome);
175: policy.allow(OperationsPolicy.Context_getEJBObject);
176: policy.allow(OperationsPolicy.Context_getTimerService);
177: policy.allow(OperationsPolicy.Context_lookup);
178: policy.allow(OperationsPolicy.JNDI_access_to_java_comp_env);
179:
180: Object expected = policy;
181: Object actual = ejbObject
182: .getAllowedOperationsReport("ejbCreate");
183:
184: assertNotNull("The OperationsPolicy is null", actual);
185: assertEquals(expected, actual);
186: } catch (Exception e) {
187: fail("Received Exception " + e.getClass() + " : "
188: + e.getMessage());
189: }
190: }
191:
192: /**
193: * <PRE>
194: * Bean method | Bean method can perform the following operations
195: * ______________________|__________________________________________________
196: * |
197: * ejbCreate | SessionContext methods:
198: * ejbRemove | - getEJBHome
199: * | - getEJBObject
200: * | - getTimerService
201: * | - lookup
202: * | JNDI access to java:comp/env
203: * ______________________|__________________________________________________
204: * </PRE>
205: */
206: public void TODO_test03_ejbRemove() {
207: try {
208: /* TO DO: This test needs unique functionality to work */
209: OperationsPolicy policy = new OperationsPolicy();
210: policy.allow(OperationsPolicy.Context_getEJBHome);
211: policy.allow(OperationsPolicy.Context_getEJBObject);
212: policy.allow(OperationsPolicy.Context_getTimerService);
213: policy.allow(OperationsPolicy.Context_lookup);
214: policy.allow(OperationsPolicy.JNDI_access_to_java_comp_env);
215:
216: Object expected = policy;
217: Object actual = ejbObject
218: .getAllowedOperationsReport("ejbRemove");
219:
220: assertNotNull("The OperationsPolicy is null", actual);
221: assertEquals(expected, actual);
222: } catch (Exception e) {
223: fail("Received Exception " + e.getClass() + " : "
224: + e.getMessage());
225: }
226: }
227:
228: /**
229: * <PRE>
230: * Bean method | Bean method can perform the following operations
231: * ______________________|__________________________________________________
232: * |
233: * business method | SessionContext methods:
234: * from remote interface | - getEJBHome
235: * | - getCallerPrincipal
236: * | - getRollbackOnly
237: * | - isCallerInRole
238: * | - setRollbackOnly
239: * | - getEJBObject
240: * | - getTimerService
241: * | - lookup
242: * | JNDI access to java:comp/env
243: * | Resource manager access
244: * | Enterprise bean access
245: * ______________________|__________________________________________________
246: * </PRE>
247: */
248: public void test04_businessMethod() {
249: try {
250: OperationsPolicy policy = new OperationsPolicy();
251: policy.allow(OperationsPolicy.Context_getEJBHome);
252: policy.allow(OperationsPolicy.Context_getCallerPrincipal);
253: policy.allow(OperationsPolicy.Context_getRollbackOnly);
254: policy.allow(OperationsPolicy.Context_setRollbackOnly);
255: policy.allow(OperationsPolicy.Context_isCallerInRole);
256: policy.allow(OperationsPolicy.Context_getEJBObject);
257: policy.allow(OperationsPolicy.Context_getTimerService);
258: policy.allow(OperationsPolicy.Context_lookup);
259: policy.allow(OperationsPolicy.JNDI_access_to_java_comp_env);
260:
261: Object expected = policy;
262: Object actual = ejbObject
263: .getAllowedOperationsReport("businessMethod");
264:
265: assertNotNull("The OperationsPolicy is null", actual);
266: assertEquals(expected, actual);
267: } catch (Exception e) {
268: fail("Received Exception " + e.getClass() + " : "
269: + e.getMessage());
270: }
271: }
272:
273: public void _test05_ejbTimeout() {
274: try {
275: ejbObject.scheduleTimer("StatelessAllowedOperationsTests");
276: timerSync.waitFor("StatelessAllowedOperationsTests");
277:
278: OperationsPolicy policy = new OperationsPolicy();
279: policy.allow(OperationsPolicy.Context_getEJBHome);
280: policy.allow(OperationsPolicy.Context_getCallerPrincipal);
281: policy.allow(OperationsPolicy.Context_getRollbackOnly);
282: policy.allow(OperationsPolicy.Context_setRollbackOnly);
283: policy.allow(OperationsPolicy.Context_isCallerInRole);
284: policy.allow(OperationsPolicy.Context_getEJBObject);
285: policy.allow(OperationsPolicy.Context_getTimerService);
286: policy.allow(OperationsPolicy.Context_lookup);
287: policy.allow(OperationsPolicy.JNDI_access_to_java_comp_env);
288:
289: Object expected = policy;
290: Object actual = ejbObject
291: .getAllowedOperationsReport("ejbTimeout");
292:
293: assertNotNull("The OperationsPolicy is null", actual);
294: assertEquals(expected, actual);
295: } catch (Exception e) {
296: fail("Received Exception " + e.getClass() + " : "
297: + e.getMessage());
298: }
299: }
300: //
301: // Test EJBContext allowed operations
302: //=====================================
303: }
|