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.UnknownCmpHome;
020:
021: import javax.ejb.EJBHome;
022: import javax.ejb.ObjectNotFoundException;
023:
024: /**
025: * [4] Should be run as the fourth test suite of the BasicCmpTestClients
026: */
027: public class Unknown2EjbObjectTests extends UnknownCmp2TestClient {
028:
029: public Unknown2EjbObjectTests() {
030: super ("EJBObject.");
031: }
032:
033: protected void setUp() throws Exception {
034: super .setUp();
035: Object obj = initialContext
036: .lookup("client/tests/entity/cmp2/UnknownCmpHome");
037: ejbHome = (UnknownCmpHome) javax.rmi.PortableRemoteObject
038: .narrow(obj, UnknownCmpHome.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 = 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(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: }
|