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 javax.ejb.EJBHome;
019:
020: /**
021: * [4] Should be run as the fourth test suite of the BasicStatefulTestClients
022: *
023: * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
024: * @author <a href="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
025: */
026: public class StatefulPojoEjbObjectTests extends BasicStatefulTestClient {
027:
028: public StatefulPojoEjbObjectTests() {
029: super ("PojoEJBObject.");
030: }
031:
032: protected void setUp() throws Exception {
033: super .setUp();
034: Object obj = initialContext
035: .lookup("client/tests/stateful/BasicStatefulPojoHome");
036: ejbHome = (BasicStatefulHome) javax.rmi.PortableRemoteObject
037: .narrow(obj, BasicStatefulHome.class);
038: ejbObject = ejbHome.createObject("First Bean");
039: }
040:
041: protected void tearDown() throws Exception {
042: //ejbObject.remove();
043: super .tearDown();
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 Stateful Session Bean identity check.
087: * See EJB3.0 "Core Contracts and Requirements" specification, section 3.4.5.1
088: */
089: public void test03_isIdentical() {
090: BasicStatefulObject otherEJBObject = null;
091: BasicStatefulObject JustAnotherEJBObject = null;
092:
093: try {
094: /*
095: * This EJBObject reference is created to validate the identity if different EJBObject refernces
096: * of the same interface type of the same session bean.
097: */
098: otherEJBObject = ejbHome.createObject("Second bean");
099: JustAnotherEJBObject = ejbHome.createObject("First bean");
100: assertTrue("The EJBObjects are not equal", ejbObject
101: .isIdentical(ejbObject));
102: assertFalse("The EJBObjects are not equal", ejbObject
103: .isIdentical(otherEJBObject));
104: assertFalse("The EJBObjects are not equal", ejbObject
105: .isIdentical(JustAnotherEJBObject));
106: } catch (Exception e) {
107: fail("Received Exception " + e.getClass() + " : "
108: + e.getMessage());
109: }
110: }
111:
112: /**
113: * This test is 2 in 1, it tests calling remove() on an EJBObject reference and then calling a business method on the
114: * same reference after the remove() is successfuly called.
115: */
116: public void test04_remove() {
117: try {
118: ejbObject.remove();
119: try {
120: ejbObject.businessMethod("Should throw an exception");
121: assertTrue(
122: "Calling business method after removing the EJBObject does not throw an exception",
123: false);
124: } catch (Exception e) {
125: assertTrue(true);
126: return;
127: }
128: } catch (Exception e) {
129: fail("Received Exception " + e.getClass() + " : "
130: + e.getMessage());
131: }
132: }
133:
134: /**
135: * See EJB3.0 "Core Contracts and Requirements" specification, section : 3.6.8.3 .
136: */
137: public void test05_getPrimaryKey() {
138: try {
139: Object key = ejbObject.getPrimaryKey();
140: } catch (java.rmi.RemoteException e) {
141: assertTrue(true);
142: return;
143: } catch (Exception e) {
144: fail("A RuntimeException should have been thrown. Received Exception "
145: + e.getClass() + " : " + e.getMessage());
146: }
147: fail("A RuntimeException should have been thrown.");
148: }
149:
150: //
151: // Test ejb object methods
152: //===============================
153:
154: }
|