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.entity.bmp;
017:
018: import org.apache.openejb.test.object.OperationsPolicy;
019:
020: import javax.rmi.PortableRemoteObject;
021:
022: /**
023: * [9] Should be run as the nineth test suite of the BasicBmpTestClients
024: *
025: * <PRE>
026: * =========================================================================
027: * Operations allowed in the methods of an entity bean
028: * =========================================================================
029: *
030: * Bean method | Bean method can perform the following operations
031: * ______________________|__________________________________________________
032: * |
033: * constructor | -
034: * ______________________|__________________________________________________
035: * |
036: * setEntityContext | EntityContext methods:
037: * unsetEntityContext | - getEJBHome
038: * | JNDI access to java:comp/env
039: * ______________________|__________________________________________________
040: * |
041: * ejbCreate | EntityContext methods:
042: * | - getEJBHome
043: * | - getCallerPrincipal
044: * | - getRollbackOnly
045: * | - isCallerInRole
046: * | - setRollbackOnly
047: * | JNDI access to java:comp/env
048: * | Resource manager access
049: * | Enterprise bean access
050: * ______________________|__________________________________________________
051: * |
052: * ejbPostCreate | EntityContext methods:
053: * | - getEJBHome
054: * | - getCallerPrincipal
055: * | - getRollbackOnly
056: * | - isCallerInRole
057: * | - setRollbackOnly
058: * | - getEJBObject
059: * | - getPrimaryKey
060: * | JNDI access to java:comp/env
061: * | Resource manager access
062: * | Enterprise bean access
063: * ______________________|__________________________________________________
064: * |
065: * ejbRemove | EntityContext methods:
066: * | - getEJBHome
067: * | - getCallerPrincipal
068: * | - getRollbackOnly
069: * | - isCallerInRole
070: * | - setRollbackOnly
071: * | - getEJBObject
072: * | - getPrimaryKey
073: * | JNDI access to java:comp/env
074: * | Resource manager access
075: * | Enterprise bean access
076: * ______________________|__________________________________________________
077: * |
078: * ejbFind* | EntityContext methods:
079: * ejbSelect* | - getEJBHome
080: * ejbHome | - getCallerPrincipal
081: * | - getRollbackOnly
082: * | - isCallerInRole
083: * | - setRollbackOnly
084: * | JNDI access to java:comp/env
085: * | Resource manager access
086: * | Enterprise bean access
087: * ______________________|__________________________________________________
088: * |
089: * ejbSelectInEntity* | EntityContext methods:
090: * | - getEJBHome
091: * | - getCallerPrincipal
092: * | - getRollbackOnly
093: * | - isCallerInRole
094: * | - setRollbackOnly
095: * | - getEJBObject
096: * | - getPrimaryKey
097: * | JNDI access to java:comp/env
098: * | Resource manager access
099: * | Enterprise bean access
100: * ______________________|__________________________________________________
101: * |
102: * ejbActivate | EntityContext methods:
103: * ejbPassivate | - getEJBHome
104: * | - getEJBObject
105: * | - getPrimaryKey
106: * | JNDI access to java:comp/env
107: * ______________________|__________________________________________________
108: * |
109: * ejbLoad | EntityContext methods:
110: * ejbStore | - getEJBHome
111: * | - getCallerPrincipal
112: * | - getRollbackOnly
113: * | - isCallerInRole
114: * | - setRollbackOnly
115: * | - getEJBObject
116: * | - getPrimaryKey
117: * | JNDI access to java:comp/env
118: * | Resource manager access
119: * | Enterprise bean access
120: * ______________________|__________________________________________________
121: * |
122: * business method | EntityContext methods:
123: * from remote interface | - getEJBHome
124: * | - getCallerPrincipal
125: * | - getRollbackOnly
126: * | - isCallerInRole
127: * | - setRollbackOnly
128: * | - getEJBObject
129: * | - getPrimaryKey
130: * | JNDI access to java:comp/env
131: * | Resource manager access
132: * | Enterprise bean access
133: * ______________________|__________________________________________________
134: * </PRE>
135: *
136: * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
137: * @author <a href="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
138: */
139: public class BmpAllowedOperationsTests extends BasicBmpTestClient {
140:
141: public BmpAllowedOperationsTests() {
142: super ("AllowedOperations.");
143: }
144:
145: protected void setUp() throws Exception {
146: super .setUp();
147: Object obj = initialContext
148: .lookup("client/tests/entity/bmp/allowed_operations/EntityHome");
149: ejbHome = (BasicBmpHome) PortableRemoteObject.narrow(obj,
150: BasicBmpHome.class);
151: ejbObject = ejbHome.createObject("Fourth Bean");
152: ejbHandle = ejbObject.getHandle();
153: /* These tests will only work if the specified
154: * method has already been called by the container.
155: *
156: * TO DO:
157: * Implement a little application senario to ensure
158: * that all methods tested for below have been called
159: * by the container.
160: */
161: doScenario();
162:
163: }
164:
165: protected void tearDown() throws Exception {
166: ejbObject.remove();
167: super .tearDown();
168: }
169:
170: /**
171: * This method ensures that all thee bean methods have been invoked for correct behaviour
172: * of the tests.
173: *
174: */
175: private void doScenario() throws Exception {
176:
177: // Call the business method
178: ejbObject.businessMethod("Reverse Me");
179:
180: ejbHome.findByPrimaryKey(null);
181:
182: ejbHome.sum(1, 2);
183:
184: ejbObject = (BasicBmpObject) PortableRemoteObject.narrow(
185: ejbHandle.getEJBObject(), BasicBmpObject.class);
186:
187: ejbHome.findByPrimaryKey((Integer) ejbObject.getPrimaryKey());
188: ejbHome.remove(ejbObject.getPrimaryKey());
189:
190: ejbObject = ejbHome.createObject("Fourth Bean");
191: ejbHome.findEmptyCollection();
192: }
193:
194: //=====================================
195: // Test EJBContext allowed operations
196: //
197: /**
198: * <PRE>
199: * Bean method | Bean method can perform the following operations
200: * ______________________|__________________________________________________
201: * |
202: * setEntityContext | EntityContext methods:
203: * unsetEntityContext | - getEJBHome
204: * | JNDI access to java:comp/env
205: * ______________________|__________________________________________________
206: * </PRE>
207: */
208: public void test01_setEntityContext() {
209: try {
210:
211: OperationsPolicy policy = new OperationsPolicy();
212: policy.allow(OperationsPolicy.Context_getEJBHome);
213: policy.allow(OperationsPolicy.JNDI_access_to_java_comp_env);
214:
215: Object expected = policy;
216: Object actual = ejbObject
217: .getAllowedOperationsReport("setEntityContext");
218:
219: assertNotNull("The OpperationsPolicy is null", actual);
220: assertEquals(expected, actual);
221:
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: * setEntityContext | EntityContext methods:
234: * unsetEntityContext | - getEJBHome
235: * | JNDI access to java:comp/env
236: * ______________________|__________________________________________________
237: * </PRE>
238: */
239: public void TODO_test02_unsetEntityContext() {
240: try {
241:
242: /* TO DO: This test needs unique functionality to work */
243: OperationsPolicy policy = new OperationsPolicy();
244: policy.allow(OperationsPolicy.Context_getEJBHome);
245: policy.allow(OperationsPolicy.JNDI_access_to_java_comp_env);
246:
247: Object expected = policy;
248: Object actual = ejbObject
249: .getAllowedOperationsReport("unsetEntityContext");
250:
251: assertNotNull("The OpperationsPolicy is null", actual);
252: assertEquals(expected, actual);
253:
254: } catch (Exception e) {
255: fail("Received Exception " + e.getClass() + " : "
256: + e.getMessage());
257: }
258: }
259:
260: /**
261: * <PRE>
262: * Bean method | Bean method can perform the following operations
263: * ______________________|__________________________________________________
264: * |
265: * ejbCreate | EntityContext methods:
266: * | - getEJBHome
267: * | - getCallerPrincipal
268: * | - getRollbackOnly
269: * | - isCallerInRole
270: * | - setRollbackOnly
271: * | JNDI access to java:comp/env
272: * | Resource manager access
273: * | Enterprise bean access
274: * ______________________|__________________________________________________
275: * </PRE>
276: */
277: public void test03_ejbCreate() {
278: try {
279:
280: OperationsPolicy policy = new OperationsPolicy();
281: policy.allow(OperationsPolicy.Context_getEJBHome);
282: policy.allow(OperationsPolicy.Context_getCallerPrincipal);
283: //TODO:0:policy.allow( OperationsPolicy.Context_getRollbackOnly );
284: policy.allow(OperationsPolicy.Context_isCallerInRole);
285: //TODO:0:policy.allow( OperationsPolicy.Context_setRollbackOnly );
286: policy.allow(OperationsPolicy.JNDI_access_to_java_comp_env);
287:
288: Object expected = policy;
289: Object actual = ejbObject
290: .getAllowedOperationsReport("ejbCreate");
291:
292: assertNotNull("The OpperationsPolicy is null", actual);
293: assertEquals(expected, actual);
294:
295: } catch (Exception e) {
296: fail("Received Exception " + e.getClass() + " : "
297: + e.getMessage());
298: }
299: }
300:
301: /**
302: * <PRE>
303: * Bean method | Bean method can perform the following operations
304: * ______________________|__________________________________________________
305: * |
306: * ejbPostCreate | EntityContext methods:
307: * | - getEJBHome
308: * | - getCallerPrincipal
309: * | - getRollbackOnly
310: * | - isCallerInRole
311: * | - setRollbackOnly
312: * | - getEJBObject
313: * | - getPrimaryKey
314: * | JNDI access to java:comp/env
315: * | Resource manager access
316: * | Enterprise bean access
317: * ______________________|__________________________________________________
318: * </PRE>
319: */
320: public void test04_ejbPostCreate() {
321: try {
322:
323: OperationsPolicy policy = new OperationsPolicy();
324: policy.allow(OperationsPolicy.Context_getEJBHome);
325: policy.allow(OperationsPolicy.Context_getCallerPrincipal);
326: //TODO:0:policy.allow( OperationsPolicy.Context_getRollbackOnly );
327: policy.allow(OperationsPolicy.Context_isCallerInRole);
328: //TODO:0:policy.allow( OperationsPolicy.Context_setRollbackOnly );
329: policy.allow(OperationsPolicy.Context_getEJBObject);
330: policy.allow(OperationsPolicy.Context_getPrimaryKey);
331: policy.allow(OperationsPolicy.JNDI_access_to_java_comp_env);
332:
333: Object expected = policy;
334: Object actual = ejbObject
335: .getAllowedOperationsReport("ejbPostCreate");
336:
337: assertNotNull("The OpperationsPolicy is null", actual);
338: assertEquals(expected, actual);
339:
340: } catch (Exception e) {
341: fail("Received Exception " + e.getClass() + " : "
342: + e.getMessage());
343: }
344: }
345:
346: /**
347: * <PRE>
348: * Bean method | Bean method can perform the following operations
349: * ______________________|__________________________________________________
350: * |
351: * ejbRemove | EntityContext methods:
352: * | - getEJBHome
353: * | - getCallerPrincipal
354: * | - getRollbackOnly
355: * | - isCallerInRole
356: * | - setRollbackOnly
357: * | - getEJBObject
358: * | - getPrimaryKey
359: * | JNDI access to java:comp/env
360: * | Resource manager access
361: * | Enterprise bean access
362: * ______________________|__________________________________________________
363: * </PRE>
364: */
365: public void test05_ejbRemove() {
366: try {
367:
368: OperationsPolicy policy = new OperationsPolicy();
369: policy.allow(OperationsPolicy.Context_getEJBHome);
370: policy.allow(OperationsPolicy.Context_getCallerPrincipal);
371: //TODO:0:policy.allow( OperationsPolicy.Context_getRollbackOnly );
372: policy.allow(OperationsPolicy.Context_isCallerInRole);
373: //TODO:0:policy.allow( OperationsPolicy.Context_setRollbackOnly );
374: policy.allow(OperationsPolicy.Context_getEJBObject);
375: policy.allow(OperationsPolicy.Context_getPrimaryKey);
376: policy.allow(OperationsPolicy.JNDI_access_to_java_comp_env);
377:
378: Object expected = policy;
379: Object actual = ejbObject
380: .getAllowedOperationsReport("ejbRemove");
381:
382: assertNotNull("The OpperationsPolicy is null", actual);
383: assertEquals(expected, actual);
384:
385: } catch (Exception e) {
386: fail("Received Exception " + e.getClass() + " : "
387: + e.getMessage());
388: }
389: }
390:
391: /**
392: * <PRE>
393: * Bean method | Bean method can perform the following operations
394: * ______________________|__________________________________________________
395: * |
396: * ejbFind* | EntityContext methods:
397: * ejbSelect* | - getEJBHome
398: * ejbHome | - getCallerPrincipal
399: * | - getRollbackOnly
400: * | - isCallerInRole
401: * | - setRollbackOnly
402: * | JNDI access to java:comp/env
403: * | Resource manager access
404: * | Enterprise bean access
405: * ______________________|__________________________________________________
406: * </PRE>
407: */
408: public void test06_ejbFind() {
409: try {
410:
411: OperationsPolicy policy = new OperationsPolicy();
412: policy.allow(OperationsPolicy.Context_getEJBHome);
413: policy.allow(OperationsPolicy.Context_getCallerPrincipal);
414: //TODO:0:policy.allow( OperationsPolicy.Context_getRollbackOnly );
415: policy.allow(OperationsPolicy.Context_isCallerInRole);
416: //TODO:0:policy.allow( OperationsPolicy.Context_setRollbackOnly );
417: policy.allow(OperationsPolicy.JNDI_access_to_java_comp_env);
418:
419: Object expected = policy;
420: Object actual = ejbObject
421: .getAllowedOperationsReport("ejbFind");
422:
423: assertNotNull("The OpperationsPolicy is null", actual);
424: assertEquals(expected, actual);
425:
426: } catch (Exception e) {
427: fail("Received Exception " + e.getClass() + " : "
428: + e.getMessage());
429: }
430: }
431:
432: /**
433: * <PRE>
434: * Bean method | Bean method can perform the following operations
435: * ______________________|__________________________________________________
436: * |
437: * ejbFind* | EntityContext methods:
438: * ejbSelect* | - getEJBHome
439: * ejbHome | - getCallerPrincipal
440: * | - getRollbackOnly
441: * | - isCallerInRole
442: * | - setRollbackOnly
443: * | JNDI access to java:comp/env
444: * | Resource manager access
445: * | Enterprise bean access
446: * ______________________|__________________________________________________
447: * </PRE>
448: */
449: public void test08_ejbHome() {
450: try {
451:
452: OperationsPolicy policy = new OperationsPolicy();
453: policy.allow(OperationsPolicy.Context_getEJBHome);
454: policy.allow(OperationsPolicy.Context_getCallerPrincipal);
455: //TODO:0:policy.allow( OperationsPolicy.Context_getRollbackOnly );
456: policy.allow(OperationsPolicy.Context_isCallerInRole);
457: //TODO:0:policy.allow( OperationsPolicy.Context_setRollbackOnly );
458: policy.allow(OperationsPolicy.JNDI_access_to_java_comp_env);
459:
460: Object expected = policy;
461: Object actual = ejbObject
462: .getAllowedOperationsReport("ejbHome");
463:
464: assertNotNull("The OpperationsPolicy is null", actual);
465: assertEquals(expected, actual);
466:
467: } catch (Exception e) {
468: fail("Received Exception " + e.getClass() + " : "
469: + e.getMessage());
470: }
471: }
472:
473: /**
474: * <PRE>
475: * Bean method | Bean method can perform the following operations
476: * ______________________|__________________________________________________
477: * |
478: * ejbActivate | EntityContext methods:
479: * ejbPassivate | - getEJBHome
480: * | - getEJBObject
481: * | - getPrimaryKey
482: * | JNDI access to java:comp/env
483: * ______________________|__________________________________________________
484: * </PRE>
485: */
486: public void test10_ejbActivate() {
487: try {
488:
489: OperationsPolicy policy = new OperationsPolicy();
490: policy.allow(OperationsPolicy.Context_getEJBHome);
491: policy.allow(OperationsPolicy.Context_getEJBObject);
492: policy.allow(OperationsPolicy.Context_getPrimaryKey);
493: policy.allow(OperationsPolicy.JNDI_access_to_java_comp_env);
494:
495: Object expected = policy;
496: Object actual = ejbObject
497: .getAllowedOperationsReport("ejbActivate");
498:
499: assertNotNull("The OpperationsPolicy is null", actual);
500: assertEquals(expected, actual);
501:
502: } catch (Exception e) {
503: fail("Received Exception " + e.getClass() + " : "
504: + e.getMessage());
505: }
506: }
507:
508: /**
509: * <PRE>
510: * Bean method | Bean method can perform the following operations
511: * ______________________|__________________________________________________
512: * |
513: * ejbActivate | EntityContext methods:
514: * ejbPassivate | - getEJBHome
515: * | - getEJBObject
516: * | - getPrimaryKey
517: * | JNDI access to java:comp/env
518: * ______________________|__________________________________________________
519: * </PRE>
520: */
521: public void test11_ejbPassivate() {
522: try {
523:
524: OperationsPolicy policy = new OperationsPolicy();
525: policy.allow(OperationsPolicy.Context_getEJBHome);
526: policy.allow(OperationsPolicy.Context_getEJBObject);
527: policy.allow(OperationsPolicy.Context_getPrimaryKey);
528: policy.allow(OperationsPolicy.JNDI_access_to_java_comp_env);
529:
530: Object expected = policy;
531: Object actual = ejbObject
532: .getAllowedOperationsReport("ejbPassivate");
533:
534: assertNotNull("The OpperationsPolicy is null", actual);
535: assertEquals(expected, actual);
536:
537: } catch (Exception e) {
538: fail("Received Exception " + e.getClass() + " : "
539: + e.getMessage());
540: }
541: }
542:
543: /**
544: * <PRE>
545: * Bean method | Bean method can perform the following operations
546: * ______________________|__________________________________________________
547: * |
548: * ejbLoad | EntityContext methods:
549: * ejbStore | - getEJBHome
550: * | - getCallerPrincipal
551: * | - getRollbackOnly
552: * | - isCallerInRole
553: * | - setRollbackOnly
554: * | - getEJBObject
555: * | - getPrimaryKey
556: * | JNDI access to java:comp/env
557: * | Resource manager access
558: * | Enterprise bean access
559: * ______________________|__________________________________________________
560: * </PRE>
561: */
562: public void test12_ejbLoad() {
563: try {
564:
565: OperationsPolicy policy = new OperationsPolicy();
566: policy.allow(OperationsPolicy.Context_getEJBHome);
567: policy.allow(OperationsPolicy.Context_getCallerPrincipal);
568: //TODO:0:policy.allow( OperationsPolicy.Context_getRollbackOnly );
569: policy.allow(OperationsPolicy.Context_isCallerInRole);
570: //TODO:0:policy.allow( OperationsPolicy.Context_setRollbackOnly );
571: policy.allow(OperationsPolicy.Context_getEJBObject);
572: policy.allow(OperationsPolicy.Context_getPrimaryKey);
573: policy.allow(OperationsPolicy.JNDI_access_to_java_comp_env);
574:
575: Object expected = policy;
576: Object actual = ejbObject
577: .getAllowedOperationsReport("ejbLoad");
578:
579: assertNotNull("The OpperationsPolicy is null", actual);
580: assertEquals(expected, actual);
581:
582: } catch (Exception e) {
583: fail("Received Exception " + e.getClass() + " : "
584: + e.getMessage());
585: }
586: }
587:
588: /**
589: * <PRE>
590: * Bean method | Bean method can perform the following operations
591: * ______________________|__________________________________________________
592: * |
593: * ejbLoad | EntityContext methods:
594: * ejbStore | - getEJBHome
595: * | - getCallerPrincipal
596: * | - getRollbackOnly
597: * | - isCallerInRole
598: * | - setRollbackOnly
599: * | - getEJBObject
600: * | - getPrimaryKey
601: * | JNDI access to java:comp/env
602: * | Resource manager access
603: * | Enterprise bean access
604: * ______________________|__________________________________________________
605: * </PRE>
606: */
607: public void test13_ejbStore() {
608: try {
609:
610: OperationsPolicy policy = new OperationsPolicy();
611: policy.allow(OperationsPolicy.Context_getEJBHome);
612: policy.allow(OperationsPolicy.Context_getCallerPrincipal);
613: //TODO:0:policy.allow( OperationsPolicy.Context_getRollbackOnly );
614: policy.allow(OperationsPolicy.Context_isCallerInRole);
615: //TODO:0:policy.allow( OperationsPolicy.Context_setRollbackOnly );
616: policy.allow(OperationsPolicy.Context_getEJBObject);
617: policy.allow(OperationsPolicy.Context_getPrimaryKey);
618: policy.allow(OperationsPolicy.JNDI_access_to_java_comp_env);
619:
620: Object expected = policy;
621: Object actual = ejbObject
622: .getAllowedOperationsReport("ejbStore");
623:
624: assertNotNull("The OperationsPolicy returned is null",
625: actual);
626: assertEquals(expected, actual);
627:
628: } catch (Exception e) {
629: fail("Received Exception " + e.getClass() + " : "
630: + e.getMessage());
631: }
632: }
633:
634: /**
635: * <PRE>
636: * Bean method | Bean method can perform the following operations
637: * ______________________|__________________________________________________
638: * |
639: * business method | EntityContext methods:
640: * from remote interface | - getEJBHome
641: * | - getCallerPrincipal
642: * | - getRollbackOnly
643: * | - isCallerInRole
644: * | - setRollbackOnly
645: * | - getEJBObject
646: * | - getPrimaryKey
647: * | JNDI access to java:comp/env
648: * | Resource manager access
649: * | Enterprise bean access
650: * ______________________|__________________________________________________
651: * </PRE>
652: */
653: public void test14_businessMethod() {
654: try {
655:
656: OperationsPolicy policy = new OperationsPolicy();
657: policy.allow(OperationsPolicy.Context_getEJBHome);
658: policy.allow(OperationsPolicy.Context_getCallerPrincipal);
659: //TODO:0:policy.allow( OperationsPolicy.Context_getRollbackOnly );
660: policy.allow(OperationsPolicy.Context_isCallerInRole);
661: //TODO:0:policy.allow( OperationsPolicy.Context_setRollbackOnly );
662: policy.allow(OperationsPolicy.Context_getEJBObject);
663: policy.allow(OperationsPolicy.Context_getPrimaryKey);
664: policy.allow(OperationsPolicy.JNDI_access_to_java_comp_env);
665:
666: Object expected = policy;
667: Object actual = ejbObject
668: .getAllowedOperationsReport("businessMethod");
669:
670: assertNotNull("The OpperationsPolicy is null", actual);
671: assertEquals(expected, actual);
672:
673: } catch (Exception e) {
674: fail("Received Exception " + e.getClass() + " : "
675: + e.getMessage());
676: }
677: }
678: //
679: // Test EJBContext allowed operations
680: //=====================================
681: }
|