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.rmi.PortableRemoteObject;
020: import javax.ejb.EJBMetaData;
021: import javax.ejb.ObjectNotFoundException;
022:
023: /**
024: * [3] Should be run as the third test suite of the UnknownCmpTestClients
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 UnknownEjbHomeTests extends UnknownCmpTestClient {
030:
031: public UnknownEjbHomeTests() {
032: super ("EJBHome.");
033: }
034:
035: protected void setUp() throws Exception {
036: super .setUp();
037: Object obj = initialContext
038: .lookup("client/tests/entity/cmp/UnknownCmpHome");
039: ejbHome = (UnknownCmpHome) PortableRemoteObject.narrow(obj,
040: UnknownCmpHome.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.findByPrimaryKey(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.findByPrimaryKey(ejbPrimaryKey);
106: fail("Entity was not actually removed");
107: } catch (ObjectNotFoundException e) {
108: }
109:
110: // verify the proxy is dead
111: try {
112: ejbObject.businessMethod("Should throw an exception");
113: assertTrue(
114: "Calling business method after removing the EJBObject does not throw an exception",
115: false);
116: } catch (Exception e) {
117: }
118:
119: // create a new ejb for the next test
120: ejbObject = ejbHome.createObject("Second Bean");
121: ejbPrimaryKey = ejbObject.getPrimaryKey();
122: } catch (Exception e) {
123: e.printStackTrace();
124: fail("Received Exception " + e.getClass() + " : "
125: + e.getMessage());
126: }
127: }
128:
129: public void test05_ejbHomeMethod() {
130: try {
131: assertEquals(8 + 9, ejbHome.sum(8, 9));
132: } catch (Throwable e) {
133: e.printStackTrace();
134: fail("Received Exception " + e.getClass() + " : "
135: + e.getMessage());
136: }
137: }
138: //
139: // Test ejb home methods
140: //===============================
141: }
|