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.entity.cmp2;
017:
018: import javax.ejb.EJBHome;
019: import javax.ejb.ObjectNotFoundException;
020:
021: import org.apache.openejb.test.entity.cmp.BasicCmpHome;
022:
023: /**
024: * [4] Should be run as the fourth test suite of the BasicCmpTestClients
025: */
026: public class Cmp2EjbObjectTests extends BasicCmp2TestClient {
027:
028: public Cmp2EjbObjectTests() {
029: super ("EJBObject.");
030: }
031:
032: protected void setUp() throws Exception {
033: super .setUp();
034: Object obj = initialContext
035: .lookup("client/tests/entity/cmp2/BasicCmpHome");
036: ejbHome = (BasicCmpHome) javax.rmi.PortableRemoteObject.narrow(
037: obj, BasicCmpHome.class);
038: ejbObject = ejbHome.createObject("Third Bean");
039: }
040:
041: protected void tearDown() throws Exception {
042: if (ejbObject != null) {// set to null by test05_remove() method
043: try {
044: ejbObject.remove();
045: } catch (Exception e) {
046: throw e;
047: }
048: }
049: super .tearDown();
050: }
051:
052: //===============================
053: // Test ejb object methods
054: //
055: public void test01_getHandle() {
056: try {
057: ejbHandle = ejbObject.getHandle();
058: assertNotNull("The Handle is null", ejbHandle);
059: } catch (Exception e) {
060: fail("Received Exception " + e.getClass() + " : "
061: + e.getMessage());
062: }
063: }
064:
065: public void test02_getPrimaryKey() {
066: try {
067: ejbPrimaryKey = ejbObject.getPrimaryKey();
068: assertNotNull("The primary key is null", ejbPrimaryKey);
069: } catch (Exception e) {
070: e.printStackTrace();
071: fail("Received Exception " + e.getClass() + " : "
072: + e.getMessage());
073: }
074: }
075:
076: public void test03_isIdentical() {
077: try {
078: assertTrue("The EJBObjects are not equal", ejbObject
079: .isIdentical(ejbObject));
080: } catch (Exception e) {
081: fail("Received Exception " + e.getClass() + " : "
082: + e.getMessage());
083: }
084: }
085:
086: public void test04_getEjbHome() {
087: try {
088: EJBHome home = ejbObject.getEJBHome();
089: assertNotNull("The EJBHome is null", home);
090: } catch (Exception e) {
091: fail("Received Exception " + e.getClass() + " : "
092: + e.getMessage());
093: }
094: }
095:
096: public void test05_remove() {
097: try {
098: // remove the ejb
099: ejbObject.remove();
100:
101: // verify that the ejb was actually removed
102: try {
103: ejbHome.findByPrimaryKey((Integer) ejbPrimaryKey);
104: fail("Entity was not actually removed");
105: } catch (ObjectNotFoundException e) {
106: }
107:
108: // verify the proxy is dead
109: try {
110: ejbObject.businessMethod("Should throw an exception");
111: assertTrue(
112: "Calling business method after removing the EJBObject does not throw an exception",
113: false);
114: } catch (Exception e) {
115: }
116: } catch (Exception e) {
117: fail("Received Exception " + e.getClass() + " : "
118: + e.getMessage());
119: } finally {
120: ejbObject = null;
121: }
122: }
123: //
124: // Test ejb object methods
125: //===============================
126:
127: }
|