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 java.rmi.RemoteException;
019:
020: import javax.ejb.EJBHome;
021:
022: /**
023: * [4] Should be run as the fourth test suite of the BasicStatefulTestClients
024: *
025: * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
026: * @author <a href="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
027: */
028: public class StatefulEjbObjectTests extends BasicStatefulTestClient {
029:
030: public StatefulEjbObjectTests() {
031: super ("EJBObject.");
032: }
033:
034: protected void setUp() throws Exception {
035: super .setUp();
036: Object obj = initialContext
037: .lookup("client/tests/stateful/BasicStatefulHome");
038: ejbHome = (BasicStatefulHome) javax.rmi.PortableRemoteObject
039: .narrow(obj, BasicStatefulHome.class);
040: ejbObject = ejbHome.createObject("Second Bean");
041: }
042:
043: protected void tearDown() throws Exception {
044: //ejbObject.remove();
045: super .tearDown();
046: }
047:
048: //===============================
049: // Test ejb object methods
050: //
051: public void test01_getHandle() {
052: try {
053: ejbHandle = ejbObject.getHandle();
054: assertNotNull("The Handle is null", ejbHandle);
055: } catch (Exception e) {
056: fail("Received Exception " + e.getClass() + " : "
057: + e.getMessage());
058: }
059: }
060:
061: public void test02_isIdentical() {
062: try {
063: assertTrue("The EJBObjects are not equal", ejbObject
064: .isIdentical(ejbObject));
065: } catch (Exception e) {
066: fail("Received Exception " + e.getClass() + " : "
067: + e.getMessage());
068: }
069: }
070:
071: public void test03_getEjbHome() {
072: try {
073: EJBHome home = ejbObject.getEJBHome();
074: assertNotNull("The EJBHome is null", home);
075: } catch (Exception e) {
076: fail("Received Exception " + e.getClass() + " : "
077: + e.getMessage());
078: }
079: }
080:
081: /**
082: * 5.5 Session object identity
083: *
084: * Session objects are intended to be private resources used only by the
085: * client that created them. For this reason, session objects, from the
086: * client's perspective, appear anonymous. In contrast to entity objects,
087: * which expose their identity as a primary key, session objects hide their
088: * identity. As a result, the EJBObject.getPrimaryKey() and
089: * EJBHome.remove(Object primaryKey) methods result in a java.rmi.RemoteException
090: * if called on a session bean. If the EJBMetaData.getPrimaryKeyClass()
091: * method is invoked on a EJBMetaData object for a Session bean, the method throws
092: * the java.lang.RuntimeException.
093: */
094: public void test04_getPrimaryKey() {
095: try {
096: Object key = ejbObject.getPrimaryKey();
097: } catch (java.rmi.RemoteException e) {
098: assertTrue(true);
099: return;
100: } catch (Exception e) {
101: fail("A RuntimeException should have been thrown. Received Exception "
102: + e.getClass() + " : " + e.getMessage());
103: }
104: fail("A RuntimeException should have been thrown.");
105: }
106:
107: //
108: // Test ejb remoce methods
109: //===============================
110: public void test05_remove() {
111: String str = null;
112: try {
113: str = ejbObject.remove("Hello");
114: } catch (RemoteException e) {
115: // TODO Auto-generated catch block
116: e.printStackTrace();
117: }
118: assertEquals("Hello", str);
119: }
120:
121: public void test06_remove() {
122: try {
123: ejbObject.remove();
124: try {
125: ejbObject.businessMethod("Should throw an exception");
126: assertTrue(
127: "Calling business method after removing the EJBObject does not throw an exception",
128: false);
129: } catch (Exception e) {
130: assertTrue(true);
131: return;
132: }
133: } catch (Exception e) {
134: fail("Received Exception " + e.getClass() + " : "
135: + e.getMessage());
136: }
137: }
138:
139: }
|