001: /**
002: *
003: * Licensed to the Apache Software Foundation (ASF) under one or more
004: * contributor license agreements. See the NOTICE file distributed with
005: * this work for additional information regarding copyright ownership.
006: * The ASF licenses this file to You under the Apache License, Version 2.0
007: * (the "License"); you may not use this file except in compliance with
008: * the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */package org.apache.openejb.test.entity.cmp;
018:
019: import javax.rmi.PortableRemoteObject;
020: import javax.ejb.EJBHome;
021: import javax.ejb.ObjectNotFoundException;
022:
023: /**
024: * [4] Should be run as the fourth test suite of the UnknownCmpTestClients
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: */
029: public class UnknownEjbObjectTests extends UnknownCmpTestClient {
030:
031: public UnknownEjbObjectTests() {
032: super ("EJBObject.");
033: }
034:
035: protected void setUp() throws Exception {
036: super .setUp();
037: Object obj = initialContext
038: .lookup("client/tests/entity/cmp/UnknownCmpHome");
039: ejbHome = (UnknownCmpHome) PortableRemoteObject.narrow(obj,
040: UnknownCmpHome.class);
041: ejbObject = ejbHome.createObject("Third Bean");
042: }
043:
044: protected void tearDown() throws Exception {
045: // set to null by test05_remove() method
046: if (ejbObject != null) {
047: try {
048: ejbObject.remove();
049: } catch (Exception e) {
050: throw e;
051: }
052: }
053: super .tearDown();
054: }
055:
056: //===============================
057: // Test ejb object methods
058: //
059: public void test01_getHandle() {
060: try {
061: ejbHandle = ejbObject.getHandle();
062: assertNotNull("The Handle is null", ejbHandle);
063: } catch (Exception e) {
064: fail("Received Exception " + e.getClass() + " : "
065: + e.getMessage());
066: }
067: }
068:
069: public void test02_getPrimaryKey() {
070: try {
071: ejbPrimaryKey = ejbObject.getPrimaryKey();
072: assertNotNull("The primary key is null", ejbPrimaryKey);
073: } catch (Exception e) {
074: e.printStackTrace();
075: fail("Received Exception " + e.getClass() + " : "
076: + e.getMessage());
077: }
078: }
079:
080: public void test03_isIdentical() {
081: try {
082: assertTrue("The EJBObjects are not equal", ejbObject
083: .isIdentical(ejbObject));
084: } catch (Exception e) {
085: fail("Received Exception " + e.getClass() + " : "
086: + e.getMessage());
087: }
088: }
089:
090: public void test04_getEjbHome() {
091: try {
092: EJBHome home = ejbObject.getEJBHome();
093: assertNotNull("The EJBHome is null", home);
094: } catch (Exception e) {
095: fail("Received Exception " + e.getClass() + " : "
096: + e.getMessage());
097: }
098: }
099:
100: public void test05_remove() {
101: try {
102: // remove the ejb
103: ejbObject.remove();
104:
105: // verify that the ejb was actually removed
106: try {
107: ejbHome.findByPrimaryKey(ejbPrimaryKey);
108: fail("Entity was not actually removed");
109: } catch (ObjectNotFoundException e) {
110: }
111:
112: // verify the proxy is dead
113: try {
114: ejbObject.businessMethod("Should throw an exception");
115: assertTrue(
116: "Calling business method after removing the EJBObject does not throw an exception",
117: false);
118: } catch (Exception e) {
119: }
120: } catch (Exception e) {
121: fail("Received Exception " + e.getClass() + " : "
122: + e.getMessage());
123: } finally {
124: ejbObject = null;
125: }
126: }
127: //
128: // Test ejb object methods
129: //===============================
130:
131: }
|