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