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.EJBMetaData;
020: import javax.ejb.ObjectNotFoundException;
021: import javax.rmi.PortableRemoteObject;
022:
023: /**
024: * [3] Should be run as the third 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 ComplexEjbHomeTests extends ComplexCmpTestClient {
030:
031: public ComplexEjbHomeTests() {
032: super ("EJBHome.");
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("Second Bean");
042: ejbPrimaryKey = ejbObject.getPrimaryKey();
043: }
044:
045: //===============================
046: // Test ejb home methods
047: //
048: public void test01_getEJBMetaData() {
049: try {
050: EJBMetaData ejbMetaData = ejbHome.getEJBMetaData();
051: assertNotNull("The EJBMetaData is null", ejbMetaData);
052: } catch (Exception e) {
053: fail("Received Exception " + e.getClass() + " : "
054: + e.getMessage());
055: }
056: }
057:
058: public void test02_getHomeHandle() {
059: try {
060: ejbHomeHandle = ejbHome.getHomeHandle();
061: assertNotNull("The HomeHandle is null", ejbHomeHandle);
062: } catch (Exception e) {
063: fail("Received Exception " + e.getClass() + " : "
064: + e.getMessage());
065: }
066: }
067:
068: public void test03_removeByPrimaryKey() {
069: try {
070: // remove the ejb
071: ejbHome.remove(ejbPrimaryKey);
072:
073: // verify that the ejb was actually removed
074: try {
075: ejbHome
076: .findByPrimaryKey((ComplexCmpBeanPk) ejbPrimaryKey);
077: fail("Entity was not actually removed");
078: } catch (ObjectNotFoundException e) {
079: }
080:
081: // verify the proxy is dead
082: try {
083: ejbObject.businessMethod("Should throw an exception");
084: assertTrue(
085: "Calling business method after removing the EJBObject does not throw an exception",
086: false);
087: } catch (Exception e) {
088: }
089:
090: // create a new ejb for the next test
091: ejbObject = ejbHome.createObject("Second Bean");
092: ejbPrimaryKey = ejbObject.getPrimaryKey();
093: } catch (Exception e) {
094: fail("Received Exception " + e.getClass() + " : "
095: + e.getMessage());
096: }
097: }
098:
099: public void test04_removeByPrimaryHandle() {
100: try {
101: // remove the ejb
102: ejbHome.remove(ejbObject.getHandle());
103:
104: // verify that the ejb was actually removed
105: try {
106: ejbHome
107: .findByPrimaryKey((ComplexCmpBeanPk) ejbPrimaryKey);
108: fail("Entity was not actually removed");
109: } catch (ObjectNotFoundException e) {
110: }
111:
112: // verify the proxy is dead
113: try {
114: ejbObject.businessMethod("Should throw an exception");
115: assertTrue(
116: "Calling business method after removing the EJBObject does not throw an exception",
117: false);
118: } catch (Exception e) {
119: }
120:
121: // create a new ejb for the next test
122: ejbObject = ejbHome.createObject("Second Bean");
123: ejbPrimaryKey = ejbObject.getPrimaryKey();
124: } catch (Exception e) {
125: e.printStackTrace();
126: fail("Received Exception " + e.getClass() + " : "
127: + e.getMessage());
128: }
129: }
130:
131: public void test05_ejbHomeMethod() {
132: try {
133: assertEquals(8 + 9, ejbHome.sum(8, 9));
134: } catch (Throwable e) {
135: e.printStackTrace();
136: fail("Received Exception " + e.getClass() + " : "
137: + e.getMessage());
138: }
139: }
140: //
141: // Test ejb home methods
142: //===============================
143: }
|