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