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.ejb.EJBHome;
020: import javax.ejb.ObjectNotFoundException;
021: import javax.rmi.PortableRemoteObject;
022:
023: /**
024: * [4] Should be run as the fourth test suite of the ComplexCmpTestClients
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 ComplexEjbObjectTests extends ComplexCmpTestClient {
030:
031: public ComplexEjbObjectTests() {
032: super ("EJBObject.");
033: }
034:
035: protected void setUp() throws Exception {
036: super .setUp();
037: Object obj = initialContext
038: .lookup("client/tests/entity/cmp/ComplexCmpHome");
039: ejbHome = (ComplexCmpHome) PortableRemoteObject.narrow(obj,
040: ComplexCmpHome.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: assertTrue(
074: "Expected (ejbPrimaryKey instanceof ComplexCmpBeanPk) but was instanceof "
075: + ejbPrimaryKey.getClass().getName(),
076: ejbPrimaryKey instanceof ComplexCmpBeanPk);
077: } catch (Exception e) {
078: e.printStackTrace();
079: fail("Received Exception " + e.getClass() + " : "
080: + e.getMessage());
081: }
082: }
083:
084: public void test03_isIdentical() {
085: try {
086: assertTrue("The EJBObjects are not equal", ejbObject
087: .isIdentical(ejbObject));
088: } catch (Exception e) {
089: fail("Received Exception " + e.getClass() + " : "
090: + e.getMessage());
091: }
092: }
093:
094: public void test04_getEjbHome() {
095: try {
096: EJBHome home = ejbObject.getEJBHome();
097: assertNotNull("The EJBHome is null", home);
098: } catch (Exception e) {
099: fail("Received Exception " + e.getClass() + " : "
100: + e.getMessage());
101: }
102: }
103:
104: public void test05_remove() {
105: try {
106: // remove the ejb
107: ejbObject.remove();
108:
109: // verify that the ejb was actually removed
110: try {
111: ejbHome
112: .findByPrimaryKey((ComplexCmpBeanPk) ejbPrimaryKey);
113: fail("Entity was not actually removed");
114: } catch (ObjectNotFoundException e) {
115: }
116:
117: // verify the proxy is dead
118: try {
119: ejbObject.businessMethod("Should throw an exception");
120: assertTrue(
121: "Calling business method after removing the EJBObject does not throw an exception",
122: false);
123: } catch (Exception e) {
124: }
125: } catch (Exception e) {
126: fail("Received Exception " + e.getClass() + " : "
127: + e.getMessage());
128: } finally {
129: ejbObject = null;
130: }
131: }
132: //
133: // Test ejb object methods
134: //===============================
135:
136: }
|