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