01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.openejb.test.entity.cmp2;
17:
18: import org.apache.openejb.test.entity.cmp.BasicCmpHome;
19: import org.apache.openejb.test.entity.cmp.BasicCmpObject;
20:
21: /**
22: * [2] Should be run as the second test suite of the BasicCmpTestClients
23: */
24: public class Cmp2HomeIntfcTests extends BasicCmp2TestClient {
25:
26: public Cmp2HomeIntfcTests() {
27: super ("HomeIntfc.");
28: }
29:
30: protected void setUp() throws Exception {
31: super .setUp();
32: Object obj = initialContext
33: .lookup("client/tests/entity/cmp2/BasicCmpHome");
34: ejbHome = (BasicCmpHome) javax.rmi.PortableRemoteObject.narrow(
35: obj, BasicCmpHome.class);
36: }
37:
38: //===============================
39: // Test home interface methods
40: //
41: public void test01_create() throws Exception {
42: ejbObject = ejbHome.createObject("First Bean");
43: assertNotNull("The EJBObject is null", ejbObject);
44: }
45:
46: public void test02_findByPrimaryKey() throws Exception {
47: ejbPrimaryKey = ejbObject.getPrimaryKey();
48: ejbObject = ejbHome.findByPrimaryKey((Integer) ejbPrimaryKey);
49: assertNotNull("The EJBObject is null", ejbObject);
50: }
51:
52: public void test03_findByLastName() throws Exception {
53: Integer[] keys = new Integer[3];
54: ejbObject = ejbHome.createObject("David Blevins");
55: keys[0] = (Integer) ejbObject.getPrimaryKey();
56:
57: ejbObject = ejbHome.createObject("Dennis Blevins");
58: keys[1] = (Integer) ejbObject.getPrimaryKey();
59:
60: ejbObject = ejbHome.createObject("Claude Blevins");
61: keys[2] = (Integer) ejbObject.getPrimaryKey();
62:
63: java.util.Collection objects = ejbHome
64: .findByLastName("Blevins");
65: assertNotNull("The Collection is null", objects);
66: assertEquals("The Collection is not the right size.",
67: keys.length, objects.size());
68: Object[] objs = objects.toArray();
69: for (int i = 0; i < objs.length; i++) {
70: ejbObject = (BasicCmpObject) javax.rmi.PortableRemoteObject
71: .narrow(objs[i], BasicCmpObject.class);
72: // This could be problematic, it assumes the order of the collection.
73: assertEquals("The primary keys are not equal.", keys[i],
74: ejbObject.getPrimaryKey());
75: }
76: }
77:
78: public void test04_homeMethod() {
79: try {
80: int expected = 8;
81: int actual = ejbHome.sum(5, 3);
82: assertEquals("home method returned wrong result", expected,
83: actual);
84: } catch (Exception e) {
85: fail("Received Exception " + e.getClass() + " : "
86: + e.getMessage());
87: }
88: }
89: //
90: // Test home interface methods
91: //===============================
92:
93: }
|