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: * [10] 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: * bean-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: * | - getUserTransaction
047: * | JNDI access to java:comp/env
048: * | Resource manager access
049: * | Enterprise bean access
050: * ______________________|__________________________________________________
051: * |
052: * business method | SessionContext methods:
053: * from remote interface | - getEJBHome
054: * | - getCallerPrincipal
055: * | - isCallerInRole
056: * | - getEJBObject
057: * | - getUserTransaction
058: * | JNDI access to java:comp/env
059: * | Resource manager access
060: * | Enterprise bean access
061: * ______________________|__________________________________________________
062: * </PRE>
063: *
064: * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
065: * @author <a href="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
066: */
067: public class BMTStatefulAllowedOperationsTests extends
068: BasicStatefulTestClient {
069:
070: public BMTStatefulAllowedOperationsTests() {
071: super ("BMTAllowedOperations.");
072: }
073:
074: protected void setUp() throws Exception {
075: super .setUp();
076: Object obj = initialContext
077: .lookup("client/tests/stateful/BeanManagedBasicStatefulHome");
078: ejbHome = (BasicStatefulHome) javax.rmi.PortableRemoteObject
079: .narrow(obj, BasicStatefulHome.class);
080: ejbObject = ejbHome.createObject("Fifth Bean");
081: ejbHandle = ejbObject.getHandle();
082: /* These tests will only work if the specified
083: * method has already been called by the container.
084: *
085: * TO DO:
086: * Implement a little application senario to ensure
087: * that all methods tested for below have been called
088: * by the container.
089: */
090: }
091:
092: protected void tearDown() throws Exception {
093: ejbObject.remove();
094: super .tearDown();
095: }
096:
097: //=====================================
098: // Test EJBContext allowed operations
099: //
100: /**
101: * <PRE>
102: * Bean method | Bean method can perform the following operations
103: * ______________________|__________________________________________________
104: * |
105: * setSessionContext | SessionContext methods:
106: * | - getEJBHome
107: * | JNDI access to java:comp/env
108: * ______________________|__________________________________________________
109: * </PRE>
110: */
111: public void test01_setSessionContext() {
112: try {
113: OperationsPolicy policy = new OperationsPolicy();
114: policy.allow(policy.Context_getEJBHome);
115: policy.allow(policy.JNDI_access_to_java_comp_env);
116:
117: Object expected = policy;
118: Object actual = ejbObject
119: .getAllowedOperationsReport("setSessionContext");
120:
121: assertNotNull("The OperationsPolicy is null", actual);
122: assertEquals(expected, actual);
123: } catch (Exception e) {
124: fail("Received Exception " + e.getClass() + " : "
125: + e.getMessage());
126: }
127: }
128:
129: /**
130: * <PRE>
131: * Bean method | Bean method can perform the following operations
132: * ______________________|__________________________________________________
133: * |
134: * ejbCreate | SessionContext methods:
135: * ejbRemove | - getEJBHome
136: * ejbActivate | - getCallerPrincipal
137: * ejbPassivate | - isCallerInRole
138: * | - getEJBObject
139: * | - getUserTransaction
140: * | JNDI access to java:comp/env
141: * | Resource manager access
142: * | Enterprise bean access
143: * ______________________|__________________________________________________
144: * </PRE>
145: */
146: public void test02_ejbCreate() {
147: try {
148: OperationsPolicy policy = new OperationsPolicy();
149: policy.allow(policy.Context_getEJBHome);
150: policy.allow(policy.Context_getCallerPrincipal);
151: policy.allow(policy.Context_isCallerInRole);
152: policy.allow(policy.Context_getEJBObject);
153: policy.allow(policy.Context_getUserTransaction);
154: policy.allow(policy.JNDI_access_to_java_comp_env);
155:
156: Object expected = policy;
157: Object actual = ejbObject
158: .getAllowedOperationsReport("ejbCreate");
159:
160: assertNotNull("The OperationsPolicy is null", actual);
161: assertEquals(expected, actual);
162: } catch (Exception e) {
163: fail("Received Exception " + e.getClass() + " : "
164: + e.getMessage());
165: }
166: }
167:
168: /**
169: * <PRE>
170: * Bean method | Bean method can perform the following operations
171: * ______________________|__________________________________________________
172: * |
173: * ejbCreate | SessionContext methods:
174: * ejbRemove | - getEJBHome
175: * ejbActivate | - getCallerPrincipal
176: * ejbPassivate | - isCallerInRole
177: * | - getEJBObject
178: * | - getUserTransaction
179: * | JNDI access to java:comp/env
180: * | Resource manager access
181: * | Enterprise bean access
182: * ______________________|__________________________________________________
183: * </PRE>
184: */
185: public void test03_ejbRemove() {
186: try {
187: /* TO DO: This test needs unique functionality to work */
188: OperationsPolicy policy = new OperationsPolicy();
189: policy.allow(policy.Context_getEJBHome);
190: policy.allow(policy.Context_getCallerPrincipal);
191: policy.allow(policy.Context_isCallerInRole);
192: policy.allow(policy.Context_getEJBObject);
193: policy.allow(policy.Context_getUserTransaction);
194: policy.allow(policy.JNDI_access_to_java_comp_env);
195:
196: Object expected = policy;
197: Object actual = ejbObject
198: .getAllowedOperationsReport("ejbRemove");
199:
200: assertNotNull("The OperationsPolicy is null", actual);
201: assertEquals(expected, actual);
202: } catch (Exception e) {
203: fail("Received Exception " + e.getClass() + " : "
204: + e.getMessage());
205: }
206: }
207:
208: /**
209: * <PRE>
210: * Bean method | Bean method can perform the following operations
211: * ______________________|__________________________________________________
212: * |
213: * ejbCreate | SessionContext methods:
214: * ejbRemove | - getEJBHome
215: * ejbActivate | - getCallerPrincipal
216: * ejbPassivate | - isCallerInRole
217: * | - getEJBObject
218: * | - getUserTransaction
219: * | JNDI access to java:comp/env
220: * | Resource manager access
221: * | Enterprise bean access
222: * ______________________|__________________________________________________
223: * </PRE>
224: */
225: public void test04_ejbActivate() {
226: try {
227: OperationsPolicy policy = new OperationsPolicy();
228: policy.allow(policy.Context_getEJBHome);
229: policy.allow(policy.Context_getCallerPrincipal);
230: policy.allow(policy.Context_isCallerInRole);
231: policy.allow(policy.Context_getEJBObject);
232: policy.allow(policy.Context_getUserTransaction);
233: policy.allow(policy.JNDI_access_to_java_comp_env);
234:
235: Object expected = policy;
236: Object actual = ejbObject
237: .getAllowedOperationsReport("ejbActivate");
238:
239: assertNotNull("The OperationsPolicy is null", actual);
240: assertEquals(expected, actual);
241: } catch (Exception e) {
242: fail("Received Exception " + e.getClass() + " : "
243: + e.getMessage());
244: }
245: }
246:
247: /**
248: * <PRE>
249: * Bean method | Bean method can perform the following operations
250: * ______________________|__________________________________________________
251: * |
252: * ejbCreate | SessionContext methods:
253: * ejbRemove | - getEJBHome
254: * ejbActivate | - getCallerPrincipal
255: * ejbPassivate | - isCallerInRole
256: * | - getEJBObject
257: * | - getUserTransaction
258: * | JNDI access to java:comp/env
259: * | Resource manager access
260: * | Enterprise bean access
261: * ______________________|__________________________________________________
262: * </PRE>
263: */
264: public void test05_ejbPassivate() {
265: try {
266: OperationsPolicy policy = new OperationsPolicy();
267: policy.allow(policy.Context_getEJBHome);
268: policy.allow(policy.Context_getCallerPrincipal);
269: policy.allow(policy.Context_isCallerInRole);
270: policy.allow(policy.Context_getEJBObject);
271: policy.allow(policy.Context_getUserTransaction);
272: policy.allow(policy.JNDI_access_to_java_comp_env);
273:
274: Object expected = policy;
275: Object actual = ejbObject
276: .getAllowedOperationsReport("ejbPassivate");
277:
278: assertNotNull("The OperationsPolicy is null", actual);
279: assertEquals(expected, actual);
280: } catch (Exception e) {
281: fail("Received Exception " + e.getClass() + " : "
282: + e.getMessage());
283: }
284: }
285:
286: /**
287: * <PRE>
288: * Bean method | Bean method can perform the following operations
289: * ______________________|__________________________________________________
290: * |
291: * business method | SessionContext methods:
292: * from remote interface | - getEJBHome
293: * | - getCallerPrincipal
294: * | - isCallerInRole
295: * | - getEJBObject
296: * | - getUserTransaction
297: * | JNDI access to java:comp/env
298: * | Resource manager access
299: * | Enterprise bean access
300: * ______________________|__________________________________________________
301: * </PRE>
302: */
303: public void test06_businessMethod() {
304: try {
305: OperationsPolicy policy = new OperationsPolicy();
306: policy.allow(policy.Context_getEJBHome);
307: policy.allow(policy.Context_getCallerPrincipal);
308: policy.allow(policy.Context_isCallerInRole);
309: policy.allow(policy.Context_getEJBObject);
310: policy.allow(policy.Context_getUserTransaction);
311: policy.allow(policy.JNDI_access_to_java_comp_env);
312:
313: Object expected = policy;
314: Object actual = ejbObject
315: .getAllowedOperationsReport("businessMethod");
316:
317: assertNotNull("The OperationsPolicy is null", actual);
318: assertEquals(expected, actual);
319: } catch (Exception e) {
320: fail("Received Exception " + e.getClass() + " : "
321: + e.getMessage());
322: }
323: }
324: //
325: // Test EJBContext allowed operations
326: //=====================================
327: }
|