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 MdbAllowedOperationsTests extends MdbTestClient {
067: protected BasicMdbObject basicMdbObject;
068:
069: public MdbAllowedOperationsTests() {
070: super ("AllowedOperations.");
071: }
072:
073: protected void setUp() throws Exception {
074: super .setUp();
075: Destination destination = (Destination) initialContext
076: .lookup("client/tests/messagedriven/mdb/BasicMdb");
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: * | JNDI access to java:comp/env
128: * ______________________|__________________________________________________
129: * </PRE>
130: */
131: public void test02_ejbCreate() {
132: try {
133: OperationsPolicy policy = new OperationsPolicy();
134: policy.allow(OperationsPolicy.Context_lookup);
135: policy.allow(OperationsPolicy.JNDI_access_to_java_comp_env);
136:
137: Object expected = policy;
138: Object actual = basicMdbObject
139: .getAllowedOperationsReport("ejbCreate");
140:
141: assertNotNull("The OperationsPolicy is null", actual);
142: assertEquals(expected, actual);
143: } catch (Exception e) {
144: fail("Received Exception " + e.getClass() + " : "
145: + e.getMessage());
146: }
147: }
148:
149: /**
150: * <PRE>
151: * Bean method | Bean method can perform the following operations
152: * ______________________|__________________________________________________
153: * |
154: * ejbCreate | SessionContext methods:
155: * ejbRemove | - getEJBHome
156: * | - getEJBObject
157: * | JNDI access to java:comp/env
158: * ______________________|__________________________________________________
159: * </PRE>
160: */
161: public void TODO_test03_ejbRemove() {
162: try {
163: /* TO DO: This test needs unique functionality to work */
164: OperationsPolicy policy = new OperationsPolicy();
165: policy.allow(OperationsPolicy.Context_getEJBHome);
166: policy.allow(OperationsPolicy.Context_getEJBObject);
167: policy.allow(OperationsPolicy.JNDI_access_to_java_comp_env);
168:
169: Object expected = policy;
170: Object actual = basicMdbObject
171: .getAllowedOperationsReport("ejbRemove");
172:
173: assertNotNull("The OperationsPolicy is null", actual);
174: assertEquals(expected, actual);
175: } catch (Exception e) {
176: fail("Received Exception " + e.getClass() + " : "
177: + e.getMessage());
178: }
179: }
180:
181: /**
182: * <PRE>
183: * Bean method | Bean method can perform the following operations
184: * ______________________|__________________________________________________
185: * |
186: * business method | SessionContext methods:
187: * from remote interface | - getRollbackOnly
188: * | - setRollbackOnly
189: * | - getCallerPrincipal
190: * | - getTimerService
191: * | - lookup
192: * | JNDI access to java:comp/env
193: * | Resource manager access
194: * | Enterprise bean access
195: * | EntityManagerFactory access
196: * ______________________|__________________________________________________
197: * </PRE>
198: */
199: public void TODO_test04_businessMethod() {
200: try {
201: OperationsPolicy policy = new OperationsPolicy();
202: policy.allow(OperationsPolicy.Context_getRollbackOnly);
203: // policy.allow( OperationsPolicy.Context_setRollbackOnly );
204: policy.allow(OperationsPolicy.Context_getCallerPrincipal);
205: policy.allow(OperationsPolicy.Context_lookup);
206: policy.allow(OperationsPolicy.JNDI_access_to_java_comp_env);
207:
208: Object expected = policy;
209: Object actual = basicMdbObject
210: .getAllowedOperationsReport("businessMethod");
211:
212: assertNotNull("The OperationsPolicy is null", actual);
213: assertEquals(expected, actual);
214: } catch (Exception e) {
215: fail("Received Exception " + e.getClass() + " : "
216: + e.getMessage());
217: }
218: }
219: //
220: // Test EJBContext allowed operations
221: //=====================================
222: }
|