You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by da...@apache.org on 2007/03/15 20:16:55 UTC
svn commit: r518731 [2/2] - in /incubator/openejb/trunk/openejb3:
container/openejb-core/src/main/java/org/apache/openejb/config/
container/openejb-core/src/main/java/org/apache/openejb/core/cmp/
container/openejb-core/src/test/java/org/apache/openejb/...
Added: incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmp/ComplexHomeIntfcTests.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmp/ComplexHomeIntfcTests.java?view=auto&rev=518731
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmp/ComplexHomeIntfcTests.java (added)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmp/ComplexHomeIntfcTests.java Thu Mar 15 12:16:53 2007
@@ -0,0 +1,124 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.test.entity.cmp;
+
+import javax.rmi.PortableRemoteObject;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * [2] Should be run as the second test suite of the ComplexCmpTestClients
+ *
+ * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
+ * @author <a href="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
+ */
+public class ComplexHomeIntfcTests extends ComplexCmpTestClient {
+
+ public ComplexHomeIntfcTests() {
+ super("ComplexPk.");
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ Object obj = initialContext.lookup("client/tests/entity/cmp/ComplexCmpHome");
+ ejbHome = (ComplexCmpHome) PortableRemoteObject.narrow(obj, ComplexCmpHome.class);
+ }
+
+ //===============================
+ // Test home interface methods
+ //
+ public void test01_create() {
+ try {
+ ejbObject = ejbHome.createObject("First Bean");
+ assertNotNull("The EJBObject is null", ejbObject);
+ } catch (Exception e) {
+ fail("Received Exception " + e.getClass() + " : " + e.getMessage());
+ }
+ }
+
+ public void test02_findByPrimaryKey() {
+ try {
+ ejbPrimaryKey = ejbObject.getPrimaryKey();
+ assertTrue("Expected (ejbPrimaryKey instanceof ComplexCmpBeanPk) but was instanceof " + ejbPrimaryKey.getClass().getName(), ejbPrimaryKey instanceof ComplexCmpBeanPk);
+ ejbObject = ejbHome.findByPrimaryKey((ComplexCmpBeanPk) ejbPrimaryKey);
+ assertNotNull("The EJBObject is null", ejbObject);
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("Received Exception " + e.getClass() + " : " + e.getMessage());
+ }
+ }
+
+ public void test03_findByLastName() {
+ Set<ComplexCmpBeanPk> keys = new HashSet<ComplexCmpBeanPk>();
+ try {
+ ejbObject = ejbHome.createObject("David Blevins");
+ ejbPrimaryKey = ejbObject.getPrimaryKey();
+ assertTrue("Expected (ejbPrimaryKey instanceof ComplexCmpBeanPk) but was instanceof " + ejbPrimaryKey.getClass().getName(), ejbPrimaryKey instanceof ComplexCmpBeanPk);
+ keys.add((ComplexCmpBeanPk) ejbObject.getPrimaryKey());
+
+ ejbObject = ejbHome.createObject("Dennis Blevins");
+ ejbPrimaryKey = ejbObject.getPrimaryKey();
+ assertTrue("Expected (ejbPrimaryKey instanceof ComplexCmpBeanPk) but was instanceof " + ejbPrimaryKey.getClass().getName(), ejbPrimaryKey instanceof ComplexCmpBeanPk);
+ keys.add((ComplexCmpBeanPk) ejbObject.getPrimaryKey());
+
+ ejbObject = ejbHome.createObject("Claude Blevins");
+ ejbPrimaryKey = ejbObject.getPrimaryKey();
+ assertTrue("Expected (ejbPrimaryKey instanceof ComplexCmpBeanPk) but was instanceof " + ejbPrimaryKey.getClass().getName(), ejbPrimaryKey instanceof ComplexCmpBeanPk);
+ keys.add((ComplexCmpBeanPk) ejbObject.getPrimaryKey());
+ } catch (Exception e) {
+ fail("Received exception while preparing the test: " + e.getClass() + " : " + e.getMessage());
+ }
+
+ try {
+ Collection objects = ejbHome.findByLastName("Blevins");
+ Set<ComplexCmpBeanPk> foundKeys = new HashSet<ComplexCmpBeanPk>();
+ assertNotNull("The Collection is null", objects);
+ assertEquals("The Collection is not the right size.", keys.size(), objects.size());
+ for (Object object : objects) {
+ ejbObject = (ComplexCmpObject) PortableRemoteObject.narrow(object, ComplexCmpObject.class);
+
+ // This could be problematic, it assumes the order of the collection.
+ ComplexCmpBeanPk foundKey = (ComplexCmpBeanPk) ejbObject.getPrimaryKey();
+ assertTrue("Extra ejb found " + ejbObject.getPrimaryKey(), keys.contains(foundKey));
+ foundKeys.add(foundKey);
+ }
+
+ keys.removeAll(foundKeys);
+ assertEquals("Some keys were not found", Collections.EMPTY_SET, keys);
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("Received Exception " + e.getClass() + " : " + e.getMessage());
+ }
+ }
+
+ public void test04_homeMethod() {
+ try {
+ int expected = 8;
+ int actual = ejbHome.sum(5, 3);
+ assertEquals("home method returned wrong result", expected, actual);
+ } catch (Exception e) {
+ fail("Received Exception " + e.getClass() + " : " + e.getMessage());
+ }
+ }
+ //
+ // Test home interface methods
+ //===============================
+
+}
Added: incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmp/ComplexRemoteIntfcTests.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmp/ComplexRemoteIntfcTests.java?view=auto&rev=518731
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmp/ComplexRemoteIntfcTests.java (added)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmp/ComplexRemoteIntfcTests.java Thu Mar 15 12:16:53 2007
@@ -0,0 +1,122 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.test.entity.cmp;
+
+import javax.rmi.PortableRemoteObject;
+
+/**
+ * [5] Should be run as the fifth test suite of the ComplexCmpTestClients
+ *
+ * @author <a href="mailto:david.blevins@visi.com">David Blevins</a>
+ * @author <a href="mailto:Richard@Monson-Haefel.com">Richard Monson-Haefel</a>
+ */
+public class ComplexRemoteIntfcTests extends ComplexCmpTestClient {
+
+ public ComplexRemoteIntfcTests() {
+ super("RemoteIntfc.");
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ Object obj = initialContext.lookup("client/tests/entity/cmp/ComplexCmpHome");
+ ejbHome = (ComplexCmpHome) PortableRemoteObject.narrow(obj, ComplexCmpHome.class);
+ ejbObject = ejbHome.createObject("Forth Bean");
+ }
+
+ //=================================
+ // Test remote interface methods
+ //
+ public void test01_businessMethod() {
+ try {
+ String expected = "Success";
+ String actual = ejbObject.businessMethod("sseccuS");
+ assertEquals(expected, actual);
+ } catch (Exception e) {
+ fail("Received Exception " + e.getClass() + " : " + e.getMessage());
+ }
+ }
+
+ /**
+ * Throw an application exception and make sure the exception
+ * reaches the bean nicely.
+ */
+ public void test02_throwApplicationException() {
+ try {
+ ejbObject.throwApplicationException();
+ } catch (org.apache.openejb.test.ApplicationException e) {
+ //Good. This is the correct behaviour
+ return;
+ } catch (Throwable e) {
+ fail("Received Exception " + e.getClass() + " : " + e.getMessage());
+ }
+ fail("An ApplicationException should have been thrown.");
+ }
+
+ /**
+ * After an application exception we should still be able to
+ * use our bean
+ */
+ public void test03_invokeAfterApplicationException() {
+ try {
+ String expected = "Success";
+ String actual = ejbObject.businessMethod("sseccuS");
+ assertEquals(expected, actual);
+ } catch (Throwable e) {
+ fail("Received Exception " + e.getClass() + " : " + e.getMessage());
+ }
+ }
+
+ public void test04_throwSystemException() {
+ try {
+ ejbObject.throwSystemException_NullPointer();
+ } catch (java.rmi.RemoteException e) {
+ //Good, so far.
+ Throwable n = e.detail;
+ assertNotNull("Nested exception should not be is null", n);
+ assertTrue("Nested exception should be an instance of NullPointerException, but exception is " + n.getClass().getName(), (n instanceof NullPointerException));
+ return;
+ } catch (Throwable e) {
+ fail("Received Exception " + e.getClass() + " : " + e.getMessage());
+ }
+ fail("A NullPointerException should have been thrown.");
+ }
+
+ /**
+ * After a system exception the intance should be garbage collected
+ * and the remote reference should be invalidated.
+ * <p/>
+ * The Remote Server fails this one, that should be fixed.
+ */
+ public void BUG_test05_invokeAfterSystemException() {
+ try {
+ ejbObject.businessMethod("This refernce is invalid");
+ fail("A java.rmi.NoSuchObjectException should have been thrown.");
+ } catch (java.rmi.NoSuchObjectException e) {
+ // Good.
+ } catch (Throwable e) {
+ fail("Received Exception " + e.getClass() + " : " + e.getMessage());
+ }
+ }
+ //
+ // Test remote interface methods
+ //=================================
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+}