001: /**
002: *
003: * Licensed to the Apache Software Foundation (ASF) under one or more
004: * contributor license agreements. See the NOTICE file distributed with
005: * this work for additional information regarding copyright ownership.
006: * The ASF licenses this file to You under the Apache License, Version 2.0
007: * (the "License"); you may not use this file except in compliance with
008: * the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */package org.apache.openejb.test.mdb;
018:
019: import org.apache.openejb.test.object.OperationsPolicy;
020:
021: import javax.jms.Destination;
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 BmtMdbAllowedOperationsTests extends MdbTestClient {
067: protected BasicMdbObject basicMdbObject;
068:
069: public BmtMdbAllowedOperationsTests() {
070: super ("AllowedOperations.");
071: }
072:
073: protected void setUp() throws Exception {
074: super .setUp();
075: Destination destination = (Destination) initialContext
076: .lookup("Basic BMT Mdb Bean");
077: basicMdbObject = MdbProxy.newProxyInstance(
078: BasicMdbObject.class, connectionFactory, destination);
079: basicMdbObject.businessMethod("foo");
080: }
081:
082: protected void tearDown() throws Exception {
083: MdbProxy.destroyProxy(basicMdbObject);
084: super .tearDown();
085: }
086:
087: //=====================================
088: // Test EJBContext allowed operations
089: //
090: /**
091: * <PRE>
092: * Bean method | Bean method can perform the following operations
093: * ______________________|__________________________________________________
094: * |
095: * dependency injection | MessageDrivenContext methods:lookup
096: * methods (e.g., setMes-|
097: * sageDrivenContext) | JNDI access to java:comp/env
098: * ______________________|__________________________________________________
099: * </PRE>
100: */
101: public void test01_setSessionContext() {
102: try {
103: OperationsPolicy policy = new OperationsPolicy();
104: policy.allow(OperationsPolicy.Context_lookup);
105: policy.allow(OperationsPolicy.JNDI_access_to_java_comp_env);
106:
107: Object expected = policy;
108: Object actual = basicMdbObject
109: .getAllowedOperationsReport("setMessageDrivenContext");
110:
111: assertNotNull("The OperationsPolicy is null", actual);
112: assertEquals(expected, actual);
113: } catch (Exception e) {
114: fail("Received Exception " + e.getClass() + " : "
115: + e.getMessage());
116: }
117: }
118:
119: /**
120: * <PRE>
121: * Bean method | Bean method can perform the following operations
122: * ______________________|__________________________________________________
123: * |
124: * ejbCreate | SessionContext methods:
125: * ejbRemove | - getTimerService
126: * | - lookup
127: * | - getUserTransaction,
128: * | JNDI access to java:comp/env
129: * ______________________|__________________________________________________
130: * </PRE>
131: */
132: public void test02_ejbCreate() {
133: try {
134: OperationsPolicy policy = new OperationsPolicy();
135: policy.allow(OperationsPolicy.Context_lookup);
136: policy.allow(OperationsPolicy.Context_getUserTransaction);
137: policy.allow(OperationsPolicy.JNDI_access_to_java_comp_env);
138:
139: Object expected = policy;
140: Object actual = basicMdbObject
141: .getAllowedOperationsReport("ejbCreate");
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: * <PRE>
153: * Bean method | Bean method can perform the following operations
154: * ______________________|__________________________________________________
155: * |
156: * ejbCreate | SessionContext methods:
157: * ejbRemove | - getEJBHome
158: * | - getEJBObject
159: * | - getUserTransaction,
160: * | JNDI access to java:comp/env
161: * ______________________|__________________________________________________
162: * </PRE>
163: */
164: public void TODO_test03_ejbRemove() {
165: try {
166: /* TO DO: This test needs unique functionality to work */
167: OperationsPolicy policy = new OperationsPolicy();
168: policy.allow(OperationsPolicy.Context_getEJBHome);
169: policy.allow(OperationsPolicy.Context_getEJBObject);
170: policy.allow(OperationsPolicy.Context_getUserTransaction);
171: policy.allow(OperationsPolicy.JNDI_access_to_java_comp_env);
172:
173: Object expected = policy;
174: Object actual = basicMdbObject
175: .getAllowedOperationsReport("ejbRemove");
176:
177: assertNotNull("The OperationsPolicy is null", actual);
178: assertEquals(expected, actual);
179: } catch (Exception e) {
180: fail("Received Exception " + e.getClass() + " : "
181: + e.getMessage());
182: }
183: }
184:
185: /**
186: * <PRE>
187: * Bean method | Bean method can perform the following operations
188: * ______________________|__________________________________________________
189: * |
190: * business method | SessionContext methods:
191: * from remote interface | - getCallerPrincipal
192: * | - getUserTransaction,
193: * | - getTimerService
194: * | - lookup
195: * | JNDI access to java:comp/env
196: * | Resource manager access
197: * | Enterprise bean access
198: * | EntityManagerFactory access
199: * ______________________|__________________________________________________
200: * </PRE>
201: */
202: public void test04_businessMethod() {
203: try {
204: OperationsPolicy policy = new OperationsPolicy();
205: policy.allow(OperationsPolicy.Context_getUserTransaction);
206: policy.allow(OperationsPolicy.Context_getCallerPrincipal);
207: policy.allow(OperationsPolicy.Context_lookup);
208: policy.allow(OperationsPolicy.JNDI_access_to_java_comp_env);
209:
210: Object expected = policy;
211: Object actual = basicMdbObject
212: .getAllowedOperationsReport("businessMethod");
213:
214: assertNotNull("The OperationsPolicy is null", actual);
215: assertEquals(expected, actual);
216: } catch (Exception e) {
217: fail("Received Exception " + e.getClass() + " : "
218: + e.getMessage());
219: }
220: }
221: //
222: // Test EJBContext allowed operations
223: //=====================================
224: }
|