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