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: /**
019: * [2] Should be run as the second test suite of the BasicBmpTestClients
020: *
021: * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
022: * @author <a href="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
023: */
024: public class BmpHomeIntfcTests extends BasicBmpTestClient {
025:
026: public BmpHomeIntfcTests() {
027: super ("HomeIntfc.");
028: }
029:
030: protected void setUp() throws Exception {
031: super .setUp();
032: Object obj = initialContext
033: .lookup("client/tests/entity/bmp/BasicBmpHome");
034: ejbHome = (BasicBmpHome) javax.rmi.PortableRemoteObject.narrow(
035: obj, BasicBmpHome.class);
036: }
037:
038: //===============================
039: // Test home interface methods
040: //
041: public void test01_create() {
042: try {
043: ejbObject = ejbHome.createObject("First Bean");
044: assertNotNull("The EJBObject is null", ejbObject);
045: } catch (Exception e) {
046: fail("Received Exception " + e.getClass() + " : "
047: + e.getMessage());
048: }
049: }
050:
051: public void test02_findByPrimaryKey() {
052: try {
053: ejbPrimaryKey = ejbObject.getPrimaryKey();
054: ejbObject = ejbHome
055: .findByPrimaryKey((Integer) ejbPrimaryKey);
056: assertNotNull("The EJBObject is null", ejbObject);
057: } catch (Exception e) {
058: fail("Received Exception " + e.getClass() + " : "
059: + e.getMessage());
060: }
061: }
062:
063: public void test03_findByLastName() {
064: Integer[] keys = new Integer[3];
065: try {
066: ejbObject = ejbHome.createObject("David Blevins");
067: keys[0] = (Integer) ejbObject.getPrimaryKey();
068:
069: ejbObject = ejbHome.createObject("Dennis Blevins");
070: keys[1] = (Integer) ejbObject.getPrimaryKey();
071:
072: ejbObject = ejbHome.createObject("Claude Blevins");
073: keys[2] = (Integer) ejbObject.getPrimaryKey();
074: } catch (Exception e) {
075: fail("Received exception while preparing the test: "
076: + e.getClass() + " : " + e.getMessage());
077: }
078:
079: try {
080: java.util.Collection objects = ejbHome
081: .findByLastName("Blevins");
082: assertNotNull("The Collection is null", objects);
083: assertEquals("The Collection is not the right size.",
084: keys.length, objects.size());
085: Object[] objs = objects.toArray();
086: for (int i = 0; i < objs.length; i++) {
087: ejbObject = (BasicBmpObject) javax.rmi.PortableRemoteObject
088: .narrow(objs[i], BasicBmpObject.class);
089: // This could be problematic, it assumes the order of the collection.
090: assertEquals("The primary keys are not equal.",
091: keys[i], ejbObject.getPrimaryKey());
092: }
093: } catch (Exception e) {
094: fail("Received Exception " + e.getClass() + " : "
095: + e.getMessage());
096: }
097: }
098:
099: public void test04_findEmptyEnumeration() {
100: try {
101: java.util.Enumeration emptyEnumeration = ejbHome
102: .findEmptyEnumeration();
103: assertNotNull("The enumeration is null", emptyEnumeration);
104: assertFalse("The enumeration is not empty",
105: emptyEnumeration.hasMoreElements());
106: } catch (Exception e) {
107: fail("Received Exception " + e.getClass() + " : "
108: + e.getMessage());
109: }
110: }
111:
112: public void test05_homeMethod() {
113: try {
114: int expected = 8;
115: int actual = ejbHome.sum(5, 3);
116: assertEquals("home method returned wrong result", expected,
117: actual);
118: } catch (Exception e) {
119: fail("Received Exception " + e.getClass() + " : "
120: + e.getMessage());
121: }
122: }
123: }
|