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