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