[jboss-cvs] JBossAS SVN: r90821 - projects/ejb-book/trunk/ch04-firstejb/src/test/java/org/jboss/ejb3/examples/ch04/firstejb.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sun Jul 5 15:14:17 EDT 2009
Author: ALRubinger
Date: 2009-07-05 15:14:17 -0400 (Sun, 05 Jul 2009)
New Revision: 90821
Added:
projects/ejb-book/trunk/ch04-firstejb/src/test/java/org/jboss/ejb3/examples/ch04/firstejb/CalculatorAssertionDelegate.java
projects/ejb-book/trunk/ch04-firstejb/src/test/java/org/jboss/ejb3/examples/ch04/firstejb/MultiViewCalculatorIntegrationTestCase.java
Modified:
projects/ejb-book/trunk/ch04-firstejb/src/test/java/org/jboss/ejb3/examples/ch04/firstejb/CalculatorIntegrationTestCase.java
Log:
[EJBBOOK-7] Split MultiView into its own integration test
Added: projects/ejb-book/trunk/ch04-firstejb/src/test/java/org/jboss/ejb3/examples/ch04/firstejb/CalculatorAssertionDelegate.java
===================================================================
--- projects/ejb-book/trunk/ch04-firstejb/src/test/java/org/jboss/ejb3/examples/ch04/firstejb/CalculatorAssertionDelegate.java (rev 0)
+++ projects/ejb-book/trunk/ch04-firstejb/src/test/java/org/jboss/ejb3/examples/ch04/firstejb/CalculatorAssertionDelegate.java 2009-07-05 19:14:17 UTC (rev 90821)
@@ -0,0 +1,82 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.examples.ch04.firstejb;
+
+import junit.framework.TestCase;
+
+import org.jboss.logging.Logger;
+
+/**
+ * CalculatorAssertionDelegate
+ *
+ * Contains functions to assert that implementations
+ * of {@link CalculatorCommonBusiness} are working
+ * as expected
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+class CalculatorAssertionDelegate
+{
+ // ---------------------------------------------------------------------------||
+ // Class Members -------------------------------------------------------------||
+ // ---------------------------------------------------------------------------||
+
+ /**
+ * Logger
+ */
+ private static final Logger log = Logger.getLogger(CalculatorAssertionDelegate.class);
+
+ // ---------------------------------------------------------------------------||
+ // Functional Methods --------------------------------------------------------||
+ // ---------------------------------------------------------------------------||
+
+ /**
+ * Uses the supplied Calculator instance to test the addition
+ * algorithm
+ */
+ void assertAdditionSucceeds(final CalculatorCommonBusiness calc)
+ {
+ // Initialize
+ final int[] arguments = new int[]
+ {2, 3, 5};
+ final int expectedSum = 10;
+
+ // Add
+ final int actualSum = calc.add(arguments);
+
+ // Test
+ TestCase.assertEquals("Addition did not return the expected result", expectedSum, actualSum);
+
+ // Log
+ final StringBuffer sb = new StringBuffer();
+ sb.append("Obtained expected result, ");
+ sb.append(actualSum);
+ sb.append(", from arguments: ");
+ for (final int arg : arguments)
+ {
+ sb.append(arg);
+ sb.append(" ");
+ }
+ log.info(sb.toString());
+ }
+}
Modified: projects/ejb-book/trunk/ch04-firstejb/src/test/java/org/jboss/ejb3/examples/ch04/firstejb/CalculatorIntegrationTestCase.java
===================================================================
--- projects/ejb-book/trunk/ch04-firstejb/src/test/java/org/jboss/ejb3/examples/ch04/firstejb/CalculatorIntegrationTestCase.java 2009-07-05 18:37:30 UTC (rev 90820)
+++ projects/ejb-book/trunk/ch04-firstejb/src/test/java/org/jboss/ejb3/examples/ch04/firstejb/CalculatorIntegrationTestCase.java 2009-07-05 19:14:17 UTC (rev 90821)
@@ -24,10 +24,7 @@
import javax.naming.Context;
import javax.naming.InitialContext;
-import javax.rmi.PortableRemoteObject;
-import junit.framework.TestCase;
-
import org.jboss.logging.Logger;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -35,7 +32,8 @@
/**
* CalculatorIntegrationTestCase
*
- * Integration tests for the CalculatorEJB
+ * Integration tests for the CalculatorEJB exposing one
+ * remote business view
*
* @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
* @version $Revision: $
@@ -62,27 +60,23 @@
private static CalculatorRemoteBusiness calcRemoteBusiness;
/**
- * The EJB 2.x remote component view of the CalculatorEJB
+ * Delegate for ensuring that the obtained Calculators are working as expected
*/
- private static CalculatorRemote calcRemote;
+ private static CalculatorAssertionDelegate assertionDelegate;
/**
* JNDI Name of the Remote Business Reference
*/
//TODO Use Global JNDI Syntax (not yet supported in JBoss EJB3)
- private static final String JNDI_NAME_CALC_REMOTE_BUSINESS = ManyViewCalculatorBean.class.getSimpleName()
- + "/remote";
+ private static final String JNDI_NAME_CALC_REMOTE_BUSINESS = SimpleCalculatorBean.class.getSimpleName() + "/remote";
- /**
- * JNDI Name of the Remote Home Reference
- */
- //TODO Use Global JNDI Syntax (not yet supported in JBoss EJB3)
- private static final String JNDI_NAME_CALC_REMOTE_HOME = ManyViewCalculatorBean.class.getSimpleName() + "/home";
-
// ---------------------------------------------------------------------------||
// Lifecycle Methods ---------------------------------------------------------||
// ---------------------------------------------------------------------------||
+ /**
+ * Run once before any tests
+ */
@BeforeClass
public static void beforeClass() throws Throwable
{
@@ -92,11 +86,8 @@
// Obtain EJB 3.x Business Reference
calcRemoteBusiness = (CalculatorRemoteBusiness) namingContext.lookup(JNDI_NAME_CALC_REMOTE_BUSINESS);
- // Obtain EJB 2.x Component Reference via Home
- final Object calcRemoteHomeReference = namingContext.lookup(JNDI_NAME_CALC_REMOTE_HOME);
- final CalculatorRemoteHome calcRemoteHome = (CalculatorRemoteHome) PortableRemoteObject.narrow(
- calcRemoteHomeReference, CalculatorRemoteHome.class);
- calcRemote = calcRemoteHome.create();
+ // Create Assertion Delegate
+ assertionDelegate = new CalculatorAssertionDelegate();
}
// ---------------------------------------------------------------------------||
@@ -112,53 +103,7 @@
{
// Test
log.info("Testing remote business reference...");
- this.assertAdditionSucceeds(calcRemoteBusiness);
+ assertionDelegate.assertAdditionSucceeds(calcRemoteBusiness);
}
- /**
- * Ensures that the CalculatorEJB adds as expected,
- * using the EJB 2.x component view
- */
- @Test
- public void testAdditionUsingComponentReference() throws Throwable
- {
- // Test
- log.info("Testing remote component reference...");
- this.assertAdditionSucceeds(calcRemote);
- }
-
- // ---------------------------------------------------------------------------||
- // Internal Helper Methods ---------------------------------------------------||
- // ---------------------------------------------------------------------------||
-
- /**
- * Uses the supplied Calculator instance to test the addition
- * algorithm
- */
- private void assertAdditionSucceeds(final CalculatorCommonBusiness calc)
- {
- // Initialize
- final int[] arguments = new int[]
- {2, 3, 5};
- final int expectedSum = 10;
-
- // Add
- final int actualSum = calc.add(arguments);
-
- // Test
- TestCase.assertEquals("Addition did not return the expected result", expectedSum, actualSum);
-
- // Log
- final StringBuffer sb = new StringBuffer();
- sb.append("Obtained expected result, ");
- sb.append(actualSum);
- sb.append(", from arguments: ");
- for (final int arg : arguments)
- {
- sb.append(arg);
- sb.append(" ");
- }
- log.info(sb.toString());
- }
-
}
Added: projects/ejb-book/trunk/ch04-firstejb/src/test/java/org/jboss/ejb3/examples/ch04/firstejb/MultiViewCalculatorIntegrationTestCase.java
===================================================================
--- projects/ejb-book/trunk/ch04-firstejb/src/test/java/org/jboss/ejb3/examples/ch04/firstejb/MultiViewCalculatorIntegrationTestCase.java (rev 0)
+++ projects/ejb-book/trunk/ch04-firstejb/src/test/java/org/jboss/ejb3/examples/ch04/firstejb/MultiViewCalculatorIntegrationTestCase.java 2009-07-05 19:14:17 UTC (rev 90821)
@@ -0,0 +1,139 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.ejb3.examples.ch04.firstejb;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.rmi.PortableRemoteObject;
+
+import org.jboss.logging.Logger;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * MultiViewCalculatorIntegrationTestCase
+ *
+ * Integration tests for the CalculatorEJB, testing many views
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class MultiViewCalculatorIntegrationTestCase
+{
+ // ---------------------------------------------------------------------------||
+ // Class Members -------------------------------------------------------------||
+ // ---------------------------------------------------------------------------||
+
+ /**
+ * Logger
+ */
+ private static final Logger log = Logger.getLogger(MultiViewCalculatorIntegrationTestCase.class);
+
+ /**
+ * The JNDI Naming Context
+ */
+ private static Context namingContext;
+
+ /**
+ * The EJB 3.x remote business view of the CalculatorEJB
+ */
+ private static CalculatorRemoteBusiness calcRemoteBusiness;
+
+ /**
+ * The EJB 2.x remote component view of the CalculatorEJB
+ */
+ private static CalculatorRemote calcRemote;
+
+ /**
+ * Delegate for ensuring that the obtained Calculators are working as expected
+ */
+ private static CalculatorAssertionDelegate assertionDelegate;
+
+ /**
+ * JNDI Name of the Remote Business Reference
+ */
+ //TODO Use Global JNDI Syntax (not yet supported in JBoss EJB3)
+ private static final String JNDI_NAME_CALC_REMOTE_BUSINESS = ManyViewCalculatorBean.class.getSimpleName()
+ + "/remote";
+
+ /**
+ * JNDI Name of the Remote Home Reference
+ */
+ //TODO Use Global JNDI Syntax (not yet supported in JBoss EJB3)
+ private static final String JNDI_NAME_CALC_REMOTE_HOME = ManyViewCalculatorBean.class.getSimpleName() + "/home";
+
+ // ---------------------------------------------------------------------------||
+ // Lifecycle Methods ---------------------------------------------------------||
+ // ---------------------------------------------------------------------------||
+
+ /**
+ * Run once before any tests
+ */
+ @BeforeClass
+ public static void beforeClass() throws Throwable
+ {
+ // Create the naming context, using jndi.properties on the CP
+ namingContext = new InitialContext();
+
+ // Obtain EJB 3.x Business Reference
+ calcRemoteBusiness = (CalculatorRemoteBusiness) namingContext.lookup(JNDI_NAME_CALC_REMOTE_BUSINESS);
+
+ // Create Assertion Delegate
+ assertionDelegate = new CalculatorAssertionDelegate();
+
+ // Obtain EJB 2.x Component Reference via Home
+ final Object calcRemoteHomeReference = namingContext.lookup(JNDI_NAME_CALC_REMOTE_HOME);
+ final CalculatorRemoteHome calcRemoteHome = (CalculatorRemoteHome) PortableRemoteObject.narrow(
+ calcRemoteHomeReference, CalculatorRemoteHome.class);
+ calcRemote = calcRemoteHome.create();
+ }
+
+ // ---------------------------------------------------------------------------||
+ // Tests ---------------------------------------------------------------------||
+ // ---------------------------------------------------------------------------||
+
+ /**
+ * Ensures that the CalculatorEJB adds as expected,
+ * using the EJB 3.x business view
+ */
+ @Test
+ public void testAdditionUsingBusinessReference() throws Throwable
+ {
+ // Test
+ log.info("Testing remote business reference...");
+ assertionDelegate.assertAdditionSucceeds(calcRemoteBusiness);
+ }
+
+ /**
+ * Ensures that the CalculatorEJB adds as expected,
+ * using the EJB 2.x component view
+ */
+ @Test
+ public void testAdditionUsingComponentReference() throws Throwable
+ {
+ // Test
+ log.info("Testing remote component reference...");
+ assertionDelegate.assertAdditionSucceeds(calcRemote);
+ }
+
+}
More information about the jboss-cvs-commits
mailing list