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.stateful;
017:
018: import org.apache.openejb.test.object.OperationsPolicy;
019:
020: /**
021: *
022: * [9] Should be run as the nineth test suite of the BasicStatefulTestClients
023: *
024: * <PRE>
025: * =========================================================================
026: * Operations allowed in the methods of a stateful SessionBean with
027: * container-managed transaction demarcation
028: * =========================================================================
029: *
030: * Bean method | Bean method can perform the following operations
031: * ______________________|__________________________________________________
032: * |
033: * constructor | -
034: * ______________________|__________________________________________________
035: * |
036: * setSessionContext | SessionContext methods:
037: * | - getEJBHome
038: * | JNDI access to java:comp/env
039: * ______________________|__________________________________________________
040: * |
041: * ejbCreate | SessionContext methods:
042: * ejbRemove | - getEJBHome
043: * ejbActivate | - getCallerPrincipal
044: * ejbPassivate | - isCallerInRole
045: * | - getEJBObject
046: * | JNDI access to java:comp/env
047: * | Resource manager access
048: * | Enterprise bean access
049: * ______________________|__________________________________________________
050: * |
051: * business method | SessionContext methods:
052: * from remote interface | - getEJBHome
053: * | - getCallerPrincipal
054: * | - getRollbackOnly
055: * | - isCallerInRole
056: * | - setRollbackOnly
057: * | - getEJBObject
058: * | JNDI access to java:comp/env
059: * | Resource manager access
060: * | Enterprise bean access
061: * ______________________|__________________________________________________
062: * |
063: * afterBegin | SessionContext methods:
064: * beforeCompletion | - getEJBHome
065: * | - getCallerPrincipal
066: * | - getRollbackOnly
067: * | - isCallerInRole
068: * | - setRollbackOnly
069: * | - getEJBObject
070: * | JNDI access to java:comp/env
071: * | Resource manager access
072: * | Enterprise bean access
073: * ______________________|__________________________________________________
074: * |
075: * afterCompletion | SessionContext methods:
076: * | - getEJBHome
077: * | - getCallerPrincipal
078: * | - isCallerInRole
079: * | - getEJBObject
080: * | JNDI access to java:comp/env
081: * | Resource manager access
082: * | Enterprise bean access
083: * ______________________|__________________________________________________
084: * </PRE>
085: *
086: * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
087: * @author <a href="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
088: */
089: public class StatefulAllowedOperationsTests extends
090: BasicStatefulTestClient {
091:
092: public StatefulAllowedOperationsTests() {
093: super ("AllowedOperations.");
094: }
095:
096: protected void setUp() throws Exception {
097: super .setUp();
098: Object obj = initialContext
099: .lookup("client/tests/stateful/BasicStatefulHome");
100: ejbHome = (BasicStatefulHome) javax.rmi.PortableRemoteObject
101: .narrow(obj, BasicStatefulHome.class);
102: ejbObject = ejbHome.createObject("Fourth Bean");
103: ejbHandle = ejbObject.getHandle();
104: /* These tests will only work if the specified
105: * method has already been called by the container.
106: *
107: * TO DO:
108: * Implement a little application senario to ensure
109: * that all methods tested for below have been called
110: * by the container.
111: */
112: }
113:
114: protected void tearDown() throws Exception {
115: ejbObject.remove();
116: super .tearDown();
117: }
118:
119: //=====================================
120: // Test EJBContext allowed operations
121: //
122: /**
123: * <PRE>
124: * Bean method | Bean method can perform the following operations
125: * ______________________|__________________________________________________
126: * |
127: * setSessionContext | SessionContext methods:
128: * | - getEJBHome
129: * | JNDI access to java:comp/env
130: * ______________________|__________________________________________________
131: * </PRE>
132: */
133: public void test01_setSessionContext() {
134: try {
135: OperationsPolicy policy = new OperationsPolicy();
136: policy.allow(policy.Context_getEJBHome);
137: policy.allow(policy.JNDI_access_to_java_comp_env);
138:
139: Object expected = policy;
140: Object actual = ejbObject
141: .getAllowedOperationsReport("setSessionContext");
142:
143: assertNotNull("The OperationsPolicy is null", actual);
144: assertEquals(expected, actual);
145: } catch (Exception e) {
146: fail("Received Exception " + e.getClass() + " : "
147: + e.getMessage());
148: }
149:
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: * | JNDI access to java:comp/env
163: * | Resource manager access
164: * | Enterprise bean access
165: * ______________________|__________________________________________________
166: * </PRE>
167: */
168: public void test02_ejbCreate() {
169: try {
170: OperationsPolicy policy = new OperationsPolicy();
171: policy.allow(policy.Context_getEJBHome);
172: policy.allow(policy.Context_getCallerPrincipal);
173: policy.allow(policy.Context_isCallerInRole);
174: policy.allow(policy.Context_getEJBObject);
175: policy.allow(policy.JNDI_access_to_java_comp_env);
176:
177: Object expected = policy;
178: Object actual = ejbObject
179: .getAllowedOperationsReport("ejbCreate");
180:
181: assertNotNull("The OperationsPolicy is null", actual);
182: assertEquals(expected, actual);
183:
184: } catch (Exception e) {
185: fail("Received Exception " + e.getClass() + " : "
186: + e.getMessage());
187: }
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: * | JNDI access to java:comp/env
201: * | Resource manager access
202: * | Enterprise bean access
203: * ______________________|__________________________________________________
204: * </PRE>
205: */
206: public void test03_ejbRemove() {
207: try {
208: /* TO DO: This test needs unique functionality to work */
209: OperationsPolicy policy = new OperationsPolicy();
210: policy.allow(policy.Context_getEJBHome);
211: policy.allow(policy.Context_getCallerPrincipal);
212: policy.allow(policy.Context_isCallerInRole);
213: policy.allow(policy.Context_getEJBObject);
214: policy.allow(policy.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:
223: } catch (Exception e) {
224: fail("Received Exception " + e.getClass() + " : "
225: + e.getMessage());
226: }
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: * | JNDI access to java:comp/env
240: * | Resource manager access
241: * | Enterprise bean access
242: * ______________________|__________________________________________________
243: * </PRE>
244: */
245: public void test04_ejbActivate() {
246: try {
247:
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.JNDI_access_to_java_comp_env);
254:
255: Object expected = policy;
256: Object actual = ejbObject
257: .getAllowedOperationsReport("ejbActivate");
258:
259: assertNotNull("The OperationsPolicy is null", actual);
260: assertEquals(expected, actual);
261:
262: } catch (Exception e) {
263: fail("Received Exception " + e.getClass() + " : "
264: + e.getMessage());
265: }
266: }
267:
268: /**
269: * <PRE>
270: * Bean method | Bean method can perform the following operations
271: * ______________________|__________________________________________________
272: * |
273: * ejbCreate | SessionContext methods:
274: * ejbRemove | - getEJBHome
275: * ejbActivate | - getCallerPrincipal
276: * ejbPassivate | - isCallerInRole
277: * | - getEJBObject
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:
287: OperationsPolicy policy = new OperationsPolicy();
288: policy.allow(policy.Context_getEJBHome);
289: policy.allow(policy.Context_getCallerPrincipal);
290: policy.allow(policy.Context_isCallerInRole);
291: policy.allow(policy.Context_getEJBObject);
292: policy.allow(policy.JNDI_access_to_java_comp_env);
293:
294: Object expected = policy;
295: Object actual = ejbObject
296: .getAllowedOperationsReport("ejbPassivate");
297:
298: assertNotNull("The OperationsPolicy is null", actual);
299: assertEquals(expected, actual);
300:
301: } catch (Exception e) {
302: fail("Received Exception " + e.getClass() + " : "
303: + e.getMessage());
304: }
305: }
306:
307: /**
308: * <PRE>
309: * Bean method | Bean method can perform the following operations
310: * ______________________|__________________________________________________
311: * |
312: * business method | SessionContext methods:
313: * from remote interface | - getEJBHome
314: * | - getCallerPrincipal
315: * | - getRollbackOnly
316: * | - isCallerInRole
317: * | - setRollbackOnly
318: * | - getEJBObject
319: * | JNDI access to java:comp/env
320: * | Resource manager access
321: * | Enterprise bean access
322: * ______________________|__________________________________________________
323: * </PRE>
324: */
325: public void test06_businessMethod() {
326: try {
327: OperationsPolicy policy = new OperationsPolicy();
328: policy.allow(policy.Context_getEJBHome);
329: policy.allow(policy.Context_getCallerPrincipal);
330: policy.allow(policy.Context_getRollbackOnly);
331: policy.allow(policy.Context_isCallerInRole);
332: policy.allow(policy.Context_setRollbackOnly);
333: policy.allow(policy.Context_getEJBObject);
334: policy.allow(policy.JNDI_access_to_java_comp_env);
335:
336: Object expected = policy;
337: Object actual = ejbObject
338: .getAllowedOperationsReport("businessMethod");
339:
340: assertNotNull("The OperationsPolicy is null", actual);
341: assertEquals(expected, actual);
342:
343: } catch (Exception e) {
344: fail("Received Exception " + e.getClass() + " : "
345: + e.getMessage());
346: }
347:
348: }
349:
350: /**
351: * <PRE>
352: * Bean method | Bean method can perform the following operations
353: * ______________________|__________________________________________________
354: * |
355: * afterBegin | SessionContext methods:
356: * beforeCompletion | - getEJBHome
357: * | - getCallerPrincipal
358: * | - getRollbackOnly
359: * | - isCallerInRole
360: * | - setRollbackOnly
361: * | - getEJBObject
362: * | JNDI access to java:comp/env
363: * | Resource manager access
364: * | Enterprise bean access
365: * ______________________|__________________________________________________
366: * </PRE>
367: */
368: public void test07_afterBegin() {
369: try {
370:
371: OperationsPolicy policy = new OperationsPolicy();
372: policy.allow(policy.Context_getEJBHome);
373: policy.allow(policy.Context_getCallerPrincipal);
374: policy.allow(policy.Context_getRollbackOnly);
375: policy.allow(policy.Context_isCallerInRole);
376: policy.allow(policy.Context_setRollbackOnly);
377: policy.allow(policy.Context_getEJBObject);
378: policy.allow(policy.JNDI_access_to_java_comp_env);
379:
380: Object expected = policy;
381: Object actual = ejbObject
382: .getAllowedOperationsReport("afterBegin");
383:
384: assertNotNull("The OperationsPolicy is null", actual);
385: assertEquals(expected, actual);
386:
387: } catch (Exception e) {
388: fail("Received Exception " + e.getClass() + " : "
389: + e.getMessage());
390: }
391: }
392:
393: /**
394: * <PRE>
395: * Bean method | Bean method can perform the following operations
396: * ______________________|__________________________________________________
397: * |
398: * afterBegin | SessionContext methods:
399: * beforeCompletion | - getEJBHome
400: * | - getCallerPrincipal
401: * | - getRollbackOnly
402: * | - isCallerInRole
403: * | - setRollbackOnly
404: * | - getEJBObject
405: * | JNDI access to java:comp/env
406: * | Resource manager access
407: * | Enterprise bean access
408: * ______________________|__________________________________________________
409: * </PRE>
410: */
411: public void test08_beforeCompletion() {
412: try {
413:
414: OperationsPolicy policy = new OperationsPolicy();
415: policy.allow(policy.Context_getEJBHome);
416: policy.allow(policy.Context_getCallerPrincipal);
417: policy.allow(policy.Context_getRollbackOnly);
418: policy.allow(policy.Context_isCallerInRole);
419: policy.allow(policy.Context_setRollbackOnly);
420: policy.allow(policy.Context_getEJBObject);
421: policy.allow(policy.JNDI_access_to_java_comp_env);
422:
423: Object expected = policy;
424: Object actual = ejbObject
425: .getAllowedOperationsReport("beforeCompletion");
426:
427: assertNotNull("The OperationsPolicy is null", actual);
428: assertEquals(expected, actual);
429:
430: } catch (Exception e) {
431: fail("Received Exception " + e.getClass() + " : "
432: + e.getMessage());
433: }
434: }
435:
436: /**
437: * <PRE>
438: * Bean method | Bean method can perform the following operations
439: * ______________________|__________________________________________________
440: * |
441: * afterCompletion | SessionContext methods:
442: * | - getEJBHome
443: * | - getCallerPrincipal
444: * | - isCallerInRole
445: * | - getEJBObject
446: * | JNDI access to java:comp/env
447: * | Resource manager access
448: * | Enterprise bean access
449: * ______________________|__________________________________________________
450: * </PRE>
451: */
452: public void test09_afterCompletion() {
453: try {
454:
455: OperationsPolicy policy = new OperationsPolicy();
456: policy.allow(policy.Context_getEJBHome);
457: policy.allow(policy.Context_getCallerPrincipal);
458: policy.allow(policy.Context_isCallerInRole);
459: policy.allow(policy.Context_getEJBObject);
460: policy.allow(policy.JNDI_access_to_java_comp_env);
461:
462: Object expected = policy;
463: Object actual = ejbObject
464: .getAllowedOperationsReport("afterCompletion");
465:
466: assertNotNull("The OperationsPolicy is null", actual);
467: assertEquals(expected, actual);
468:
469: } catch (Exception e) {
470: fail("Received Exception " + e.getClass() + " : "
471: + e.getMessage());
472: }
473: }
474: //
475: // Test EJBContext allowed operations
476: //=====================================
477: }
|