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.bmp;
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 BasicBmpTestClients
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 BmpEjbHomeTests extends BasicBmpTestClient {
028:
029: public BmpEjbHomeTests() {
030: super ("EJBHome.");
031: }
032:
033: protected void setUp() throws Exception {
034: super .setUp();
035: Object obj = initialContext
036: .lookup("client/tests/entity/bmp/BasicBmpHome");
037: ejbHome = (BasicBmpHome) javax.rmi.PortableRemoteObject.narrow(
038: obj, BasicBmpHome.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: e.printStackTrace();
092: fail("Received Exception " + e.getClass() + " : "
093: + e.getMessage());
094: }
095: }
096:
097: public void test04_removeByPrimaryHandle() {
098: try {
099: // remove the ejb
100: ejbHome.remove(ejbObject.getHandle());
101:
102: // verify that the ejb was actually removed
103: try {
104: ejbHome.findByPrimaryKey((Integer) ejbPrimaryKey);
105: fail("Entity was not actually removed");
106: } catch (ObjectNotFoundException e) {
107: }
108:
109: // verify the proxy is dead
110: try {
111: ejbObject.businessMethod("Should throw an exception");
112: assertTrue(
113: "Calling business method after removing the EJBObject does not throw an exception",
114: false);
115: } catch (Exception e) {
116: }
117:
118: // create a new ejb for the next test
119: ejbObject = ejbHome.createObject("Second Bean");
120: ejbPrimaryKey = ejbObject.getPrimaryKey();
121: } catch (Exception e) {
122: e.printStackTrace();
123: fail("Received Exception " + e.getClass() + " : "
124: + e.getMessage());
125: }
126: }
127:
128: public void test05_ejbHomeMethod() {
129: try {
130: assertEquals(8 + 9, ejbHome.sum(8, 9));
131: } catch (Throwable e) {
132: e.printStackTrace();
133: fail("Received Exception " + e.getClass() + " : "
134: + e.getMessage());
135: }
136: }
137: //
138: // Test ejb home methods
139: //===============================
140: }
|