[jboss-cvs] JBossAS SVN: r86292 - in projects/ejb3/examples/trunk/firstejb: src/test/java/org/jboss/ejb3/examples/ch04/firstejb and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Mar 25 06:05:28 EDT 2009
Author: ALRubinger
Date: 2009-03-25 06:05:28 -0400 (Wed, 25 Mar 2009)
New Revision: 86292
Added:
projects/ejb3/examples/trunk/firstejb/src/test/java/org/jboss/ejb3/examples/ch04/firstejb/CalculatorIntegrationTestCase.java
Modified:
projects/ejb3/examples/trunk/firstejb/pom.xml
Log:
Hook in integration tests to ejb3-examples-firstejb
Modified: projects/ejb3/examples/trunk/firstejb/pom.xml
===================================================================
--- projects/ejb3/examples/trunk/firstejb/pom.xml 2009-03-25 09:06:11 UTC (rev 86291)
+++ projects/ejb3/examples/trunk/firstejb/pom.xml 2009-03-25 10:05:28 UTC (rev 86292)
@@ -70,7 +70,7 @@
<skip>false</skip>
<!-- Include jbossall-client.jar on the CP -->
<additionalClasspathElements>
- <additionalClasspathElement>${env.JBOSS_HOME}/client/jbossall-client.jar</additionalClasspathElement>
+ <additionalClasspathElement>${jboss.home}/client/jbossall-client.jar</additionalClasspathElement>
</additionalClasspathElements>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<printSummary>true</printSummary>
@@ -91,7 +91,7 @@
<groupId>org.jboss.maven.plugins.jbossas</groupId>
<artifactId>maven-jboss-as-control-plugin</artifactId>
- <version>0.1.0</version>
+ <version>0.1.2-SNAPSHOT</version>
<!-- Executions -->
<executions>
Added: projects/ejb3/examples/trunk/firstejb/src/test/java/org/jboss/ejb3/examples/ch04/firstejb/CalculatorIntegrationTestCase.java
===================================================================
--- projects/ejb3/examples/trunk/firstejb/src/test/java/org/jboss/ejb3/examples/ch04/firstejb/CalculatorIntegrationTestCase.java (rev 0)
+++ projects/ejb3/examples/trunk/firstejb/src/test/java/org/jboss/ejb3/examples/ch04/firstejb/CalculatorIntegrationTestCase.java 2009-03-25 10:05:28 UTC (rev 86292)
@@ -0,0 +1,158 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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 junit.framework.TestCase;
+
+import org.jboss.logging.Logger;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * CalculatorIntegrationTestCase
+ *
+ * Integration tests for the CalculatorEJB
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class CalculatorIntegrationTestCase
+{
+ // ---------------------------------------------------------------------------||
+ // Class Members -------------------------------------------------------------||
+ // ---------------------------------------------------------------------------||
+
+ /**
+ * Logger
+ */
+ private static final Logger log = Logger.getLogger(CalculatorIntegrationTestCase.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;
+
+ /**
+ * JNDI Name of the Remote Business Reference
+ */
+ private static final String JNDI_NAME_CALC_REMOTE_BUSINESS = ManyViewCalculatorBean.class.getSimpleName()
+ + "/remote";
+
+ /**
+ * JNDI Name of the Remote Home Reference
+ */
+ private static final String JNDI_NAME_CALC_REMOTE_HOME = ManyViewCalculatorBean.class.getSimpleName() + "/home";
+
+ // ---------------------------------------------------------------------------||
+ // Lifecycle Methods ---------------------------------------------------------||
+ // ---------------------------------------------------------------------------||
+
+ @BeforeClass
+ public static void beforeClass() throws Throwable
+ {
+ // Create the naming context, using jndi.properties on the CP
+ namingContext = new InitialContext();
+
+ // Obtain views (vendor-specific)
+ calcRemoteBusiness = (CalculatorRemoteBusiness) namingContext.lookup(JNDI_NAME_CALC_REMOTE_BUSINESS);
+ final CalculatorRemoteHome calcRemoteHome = (CalculatorRemoteHome) namingContext
+ .lookup(JNDI_NAME_CALC_REMOTE_HOME);
+ 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...");
+ this.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(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());
+ }
+
+}
More information about the jboss-cvs-commits
mailing list