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