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.EJBMetaData;
019: import javax.ejb.RemoveException;
020:
021: /**
022: * [3] Should be run as the third test suite of the BasicStatefulTestClients
023: *
024: * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
025: * @author <a href="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
026: */
027: public class StatefulPojoEjbHomeTests extends BasicStatefulTestClient {
028:
029: public StatefulPojoEjbHomeTests() {
030: super ("EJBHome.");
031: }
032:
033: protected void setUp() throws Exception {
034: super .setUp();
035: Object obj = initialContext
036: .lookup("client/tests/stateful/BasicStatefulPojoHome");
037: ejbHome = (BasicStatefulHome) javax.rmi.PortableRemoteObject
038: .narrow(obj, BasicStatefulHome.class);
039: }
040:
041: //===============================
042: // Test ejb home methods
043: //
044: public void test01_getEJBMetaData() {
045: try {
046: EJBMetaData ejbMetaData = ejbHome.getEJBMetaData();
047: assertNotNull("The EJBMetaData is null", ejbMetaData);
048: } catch (Exception e) {
049: fail("Received Exception " + e.getClass() + " : "
050: + e.getMessage());
051: }
052: }
053:
054: public void test02_getHomeHandle() {
055: try {
056: ejbHomeHandle = ejbHome.getHomeHandle();
057: assertNotNull("The HomeHandle is null", ejbHomeHandle);
058: } catch (Exception e) {
059: fail("Received Exception " + e.getClass() + " : "
060: + e.getMessage());
061: }
062: }
063:
064: /**
065: * ------------------------------------
066: * 5.3.2 Removing a session object
067: * A client may remove a session object using the remove() method on the javax.ejb.EJBObject
068: * interface, or the remove(Handle handle) method of the javax.ejb.EJBHome interface.
069: *
070: * Because session objects do not have primary keys that are accessible to clients, invoking the
071: * javax.ejb.EJBHome.remove(Object primaryKey) method on a session results in the
072: * javax.ejb.RemoveException.
073: *
074: * ------------------------------------
075: * 5.5 Session object identity
076: *
077: * Session objects are intended to be private resources used only by the
078: * client that created them. For this reason, session objects, from the
079: * client's perspective, appear anonymous. In contrast to entity objects,
080: * which expose their identity as a primary key, session objects hide their
081: * identity. As a result, the EJBObject.getPrimaryKey() and
082: * EJBHome.remove(Object primaryKey) methods result in a java.rmi.RemoteException
083: * if called on a session bean. If the EJBMetaData.getPrimaryKeyClass()
084: * method is invoked on a EJBMetaData object for a Session bean, the method throws
085: * the java.lang.RuntimeException.
086: * ------------------------------------
087: *
088: * Sections 5.3.2 and 5.5 conflict. 5.3.2 says to throw javax.ejb.RemoveException, 5.5 says to
089: * throw java.rmi.RemoteException.
090: *
091: * For now, we are going with java.rmi.RemoteException.
092: * =====================================================================================================
093: * TODO - MNour: Please add related sections from EJB3.0 Core contracts and requirements specification
094: * (Sections: 3.6.2.2, 3.6.3.2 and 3.6.5)
095: */
096: public void test03_removeByPrimaryKey() {
097: try {
098: ejbHome.remove("primaryKey");
099: } catch (RemoveException e) {
100: assertTrue(true);
101: return;
102: } catch (Exception e) {
103: fail("Received Exception " + e.getClass()
104: + " instead of javax.ejb.RemoveException : "
105: + e.getMessage());
106: }
107: assertTrue("javax.ejb.RemoveException should have been thrown",
108: false);
109: }
110: //
111: // Test ejb home methods
112: //===============================
113: }
|