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