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.cmp;
017:
018: /**
019: * [2] Should be run as the second test suite of the BasicCmpTestClients
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 CmpHomeIntfcTests extends BasicCmpTestClient {
025:
026: public CmpHomeIntfcTests() {
027: super ("HomeIntfc.");
028: }
029:
030: protected void setUp() throws Exception {
031: super .setUp();
032: Object obj = initialContext
033: .lookup("client/tests/entity/cmp/BasicCmpHome");
034: ejbHome = (BasicCmpHome) javax.rmi.PortableRemoteObject.narrow(
035: obj, BasicCmpHome.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: e.printStackTrace();
059: fail("Received Exception " + e.getClass() + " : "
060: + e.getMessage());
061: }
062: }
063:
064: public void test03_findByLastName() {
065: Integer[] keys = new Integer[3];
066: try {
067: ejbObject = ejbHome.createObject("David Blevins");
068: keys[0] = (Integer) ejbObject.getPrimaryKey();
069:
070: ejbObject = ejbHome.createObject("Dennis Blevins");
071: keys[1] = (Integer) ejbObject.getPrimaryKey();
072:
073: ejbObject = ejbHome.createObject("Claude Blevins");
074: keys[2] = (Integer) ejbObject.getPrimaryKey();
075: } catch (Exception e) {
076: fail("Received exception while preparing the test: "
077: + e.getClass() + " : " + e.getMessage());
078: }
079:
080: try {
081: java.util.Collection objects = ejbHome
082: .findByLastName("Blevins");
083: assertNotNull("The Collection is null", objects);
084: assertEquals("The Collection is not the right size.",
085: keys.length, objects.size());
086: Object[] objs = objects.toArray();
087: for (int i = 0; i < objs.length; i++) {
088: ejbObject = (BasicCmpObject) javax.rmi.PortableRemoteObject
089: .narrow(objs[i], BasicCmpObject.class);
090: // This could be problematic, it assumes the order of the collection.
091: assertEquals("The primary keys are not equal.",
092: keys[i], ejbObject.getPrimaryKey());
093: }
094: } catch (Exception e) {
095: fail("Received Exception " + e.getClass() + " : "
096: + e.getMessage());
097: }
098: }
099:
100: public void test04_homeMethod() {
101: try {
102: int expected = 8;
103: int actual = ejbHome.sum(5, 3);
104: assertEquals("home method returned wrong result", expected,
105: actual);
106: } catch (Exception e) {
107: fail("Received Exception " + e.getClass() + " : "
108: + e.getMessage());
109: }
110: }
111: //
112: // Test home interface methods
113: //===============================
114:
115: }
|