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.cmp2;
018:
019: import org.apache.openejb.test.entity.cmp.ComplexCmpBeanPk;
020: import org.apache.openejb.test.entity.cmp.ComplexCmpHome;
021: import org.apache.openejb.test.entity.cmp.ComplexCmpObject;
022:
023: import javax.rmi.PortableRemoteObject;
024: import java.util.Collection;
025: import java.util.Collections;
026: import java.util.HashSet;
027: import java.util.Set;
028:
029: /**
030: * [2] Should be run as the second test suite of the BasicCmpTestClients
031: */
032: public class Complex2HomeIntfcTests extends ComplexCmp2TestClient {
033: public Complex2HomeIntfcTests() {
034: super ("HomeIntfc.");
035: }
036:
037: protected void setUp() throws Exception {
038: super .setUp();
039: Object obj = initialContext
040: .lookup("client/tests/entity/cmp2/ComplexCmpHome");
041: ejbHome = (ComplexCmpHome) javax.rmi.PortableRemoteObject
042: .narrow(obj, ComplexCmpHome.class);
043: }
044:
045: //===============================
046: // Test home interface methods
047: //
048: public void test01_create() throws Exception {
049: ejbObject = ejbHome.createObject("First Bean");
050: assertNotNull("The EJBObject is null", ejbObject);
051: }
052:
053: public void test02_findByPrimaryKey() throws Exception {
054: ejbPrimaryKey = ejbObject.getPrimaryKey();
055: assertTrue(
056: "Expected (ejbPrimaryKey instanceof ComplexCmpBeanPk) but was instanceof "
057: + ejbPrimaryKey.getClass().getName(),
058: ejbPrimaryKey instanceof ComplexCmpBeanPk);
059: ejbObject = ejbHome
060: .findByPrimaryKey((ComplexCmpBeanPk) ejbPrimaryKey);
061: assertNotNull("The EJBObject is null", ejbObject);
062: }
063:
064: public void test03_findByLastName() throws Exception {
065: Set<ComplexCmpBeanPk> keys = new HashSet<ComplexCmpBeanPk>();
066: try {
067: ejbObject = ejbHome.createObject("David Blevins");
068: ejbPrimaryKey = ejbObject.getPrimaryKey();
069: assertTrue(
070: "Expected (ejbPrimaryKey instanceof ComplexCmpBeanPk) but was instanceof "
071: + ejbPrimaryKey.getClass().getName(),
072: ejbPrimaryKey instanceof ComplexCmpBeanPk);
073: keys.add((ComplexCmpBeanPk) ejbObject.getPrimaryKey());
074:
075: ejbObject = ejbHome.createObject("Dennis Blevins");
076: ejbPrimaryKey = ejbObject.getPrimaryKey();
077: assertTrue(
078: "Expected (ejbPrimaryKey instanceof ComplexCmpBeanPk) but was instanceof "
079: + ejbPrimaryKey.getClass().getName(),
080: ejbPrimaryKey instanceof ComplexCmpBeanPk);
081: keys.add((ComplexCmpBeanPk) ejbObject.getPrimaryKey());
082:
083: ejbObject = ejbHome.createObject("Claude Blevins");
084: ejbPrimaryKey = ejbObject.getPrimaryKey();
085: assertTrue(
086: "Expected (ejbPrimaryKey instanceof ComplexCmpBeanPk) but was instanceof "
087: + ejbPrimaryKey.getClass().getName(),
088: ejbPrimaryKey instanceof ComplexCmpBeanPk);
089: keys.add((ComplexCmpBeanPk) ejbObject.getPrimaryKey());
090: } catch (Exception e) {
091: fail("Received exception while preparing the test: "
092: + e.getClass() + " : " + e.getMessage());
093: }
094:
095: try {
096: Collection objects = ejbHome.findByLastName("Blevins");
097: Set<ComplexCmpBeanPk> foundKeys = new HashSet<ComplexCmpBeanPk>();
098: assertNotNull("The Collection is null", objects);
099: assertEquals("The Collection is not the right size.", keys
100: .size(), objects.size());
101: for (Object object : objects) {
102: ejbObject = (ComplexCmpObject) PortableRemoteObject
103: .narrow(object, ComplexCmpObject.class);
104:
105: // This could be problematic, it assumes the order of the collection.
106: ComplexCmpBeanPk foundKey = (ComplexCmpBeanPk) ejbObject
107: .getPrimaryKey();
108: assertTrue("Extra ejb found "
109: + ejbObject.getPrimaryKey(), keys
110: .contains(foundKey));
111: foundKeys.add(foundKey);
112: }
113:
114: keys.removeAll(foundKeys);
115: assertEquals("Some keys were not found",
116: Collections.EMPTY_SET, keys);
117: } catch (Exception e) {
118: e.printStackTrace();
119: fail("Received Exception " + e.getClass() + " : "
120: + e.getMessage());
121: }
122: }
123:
124: public void test04_homeMethod() {
125: try {
126: int expected = 8;
127: int actual = ejbHome.sum(5, 3);
128: assertEquals("home method returned wrong result", expected,
129: actual);
130: } catch (Exception e) {
131: fail("Received Exception " + e.getClass() + " : "
132: + e.getMessage());
133: }
134: }
135: //
136: // Test home interface methods
137: //===============================
138:
139: }
|