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.stateless;
017:
018: import javax.ejb.EJBHome;
019:
020: /**
021: * This class tests that all javax.ejb.EJBObject methods work as expected on the EJB 2.1 compatible remote interface
022: * of an ejb3 stateless bean.
023: * <br>
024: * [4] Should be run as the fourth test suite of the BasicStatelessTestClients
025: *
026: * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
027: * @author <a href="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
028: * @version $Rev: 607077 $ $Date: 2007-12-27 06:55:23 -0800 $
029: */
030: public class StatelessPojoEjbObjectTests extends
031: BasicStatelessTestClient {
032:
033: public StatelessPojoEjbObjectTests() {
034: super ("PojoEJBObject.");
035: }
036:
037: protected void setUp() throws Exception {
038: super .setUp();
039: Object obj = initialContext
040: .lookup("client/tests/stateless/BasicStatelessPojoHome");
041: ejbHome = (BasicStatelessHome) javax.rmi.PortableRemoteObject
042: .narrow(obj, BasicStatelessHome.class);
043: ejbObject = ejbHome.createObject();
044: }
045:
046: // ===============================
047: // Start EJBObject methods test
048: //
049:
050: /**
051: * According to the EJB3.0 "Core Contracts and Requirements" specs, section
052: * 3.6.4, a session EJBObject supports:
053: * 1. Get the session object's remote home interface.
054: * 2. Get the session object's handle.
055: * 3. Test if the session object is identical with another session object.
056: * 4. Remove the session object.
057: */
058:
059: /**
060: * A method to test retrieving the EJBHome interface of a session bean using its EJBObject reference.
061: */
062: public void test01_getEjbHome() {
063: try {
064: EJBHome home = ejbObject.getEJBHome();
065: assertNotNull("The EJBHome is null", home);
066: } catch (Exception e) {
067: fail("Received Exception " + e.getClass() + " : "
068: + e.getMessage());
069: }
070: }
071:
072: /**
073: * A method to test retrieving a Handle of a session bean using its EJBObject reference.
074: */
075: public void test02_getHandle() {
076: try {
077: ejbHandle = ejbObject.getHandle();
078: assertNotNull("The Handle is null", ejbHandle);
079: } catch (Exception e) {
080: fail("Received Exception " + e.getClass() + " : "
081: + e.getMessage());
082: }
083: }
084:
085: /**
086: * A method to test the implementation of Stateless Session Bean identity check.
087: * See EJB3.0 "Core Contracts and Requirements" specification, section 3.4.5.2
088: */
089: public void test03_isIdentical() {
090: BasicStatelessObject otherEJBObject = null;
091: try {
092: /**
093: * This EJBObject reference is created to validate the identity if different EJBObject references
094: * of the same interface type of the same session bean.
095: */
096: otherEJBObject = ejbHome.createObject();
097: assertTrue("The EJBObjects are not identical", ejbObject
098: .isIdentical(ejbObject));
099: assertTrue(
100: "The EJBObject and the OtherEJBObject are not identical",
101: ejbObject.isIdentical(otherEJBObject));
102: } catch (Exception e) {
103: fail("Received Exception " + e.getClass() + " : "
104: + e.getMessage());
105: }
106: }
107:
108: /**
109: * This test is 2 in 1, it tests calling remove() on an EJBObject reference and then calling a business method on the
110: * same reference after the remove() is successfuly called.
111: */
112: public void test04_remove() {
113: try {
114: ejbObject.remove();
115: // you can't really remove a stateless handle
116: ejbObject.businessMethod("Should not throw an exception");
117: } catch (Exception e) {
118: fail("Received Exception " + e.getClass() + " : "
119: + e.getMessage());
120: }
121: }
122:
123: /**
124: * See EJB3.0 "Core Contracts and Requirements" specification, section : 3.6.8.3 .
125: */
126: public void test05_getPrimaryKey() {
127: try {
128: Object key = ejbObject.getPrimaryKey();
129: } catch (java.rmi.RemoteException e) {
130: assertTrue(true);
131: return;
132: } catch (Exception e) {
133: fail("A RuntimeException should have been thrown. Received Exception "
134: + e.getClass() + " : " + e.getMessage());
135: }
136: fail("A RuntimeException should have been thrown.");
137: }
138:
139: //
140: // End EJBObject methods test
141: // ===============================
142: }
|