[jboss-cvs] JBossAS SVN: r104597 - in projects/ejb-book/trunk/ch08-statusupdate: src/main/java/org/jboss/ejb3/examples/ch08/statusupdate/mdb and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon May 10 01:43:45 EDT 2010
Author: ALRubinger
Date: 2010-05-10 01:43:44 -0400 (Mon, 10 May 2010)
New Revision: 104597
Added:
projects/ejb-book/trunk/ch08-statusupdate/src/main/resources/hornetq-jms.xml
Removed:
projects/ejb-book/trunk/ch08-statusupdate/src/main/resources/statusupdate-topic-service.xml
Modified:
projects/ejb-book/trunk/ch08-statusupdate/pom.xml
projects/ejb-book/trunk/ch08-statusupdate/src/main/java/org/jboss/ejb3/examples/ch08/statusupdate/mdb/EnvironmentSpecificTwitterClientUtil.java
projects/ejb-book/trunk/ch08-statusupdate/src/main/java/org/jboss/ejb3/examples/ch08/statusupdate/mdb/LoggingStatusUpdateMdb.java
projects/ejb-book/trunk/ch08-statusupdate/src/test/java/org/jboss/ejb3/examples/ch08/statusupdate/mdb/StatusUpdateIntegrationTest.java
projects/ejb-book/trunk/ch08-statusupdate/src/test/java/org/jboss/ejb3/examples/ch08/statusupdate/mdb/TwitterUpdateBlockingTestMdb.java
Log:
[EJBBOOK-15] Update StatusUpdate MDB integration tests to use Arquillian
Modified: projects/ejb-book/trunk/ch08-statusupdate/pom.xml
===================================================================
--- projects/ejb-book/trunk/ch08-statusupdate/pom.xml 2010-05-10 04:18:23 UTC (rev 104596)
+++ projects/ejb-book/trunk/ch08-statusupdate/pom.xml 2010-05-10 05:43:44 UTC (rev 104597)
@@ -44,11 +44,6 @@
<version>${version.org.jboss.jbossas}</version>
</dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- </dependency>
-
<!--
http://yusuke.homeip.net/twitter4j/en/index.html
-->
@@ -59,9 +54,20 @@
</dependency>
<!--
-
Test Dependencies
-->
+ <dependency>
+ <groupId>org.jboss.arquillian.container</groupId>
+ <artifactId>arquillian-jbossas-embedded-60</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.arquillian</groupId>
+ <artifactId>arquillian-junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
</dependencies>
@@ -75,6 +81,9 @@
<!-- Declare the "Integration Test" Profile -->
<id>it</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
<build>
@@ -94,7 +103,7 @@
<additionalClasspathElements>
<additionalClasspathElement>${JBOSS_HOME}/client/jbossws-native-client.jar</additionalClasspathElement>
</additionalClasspathElements>
- <redirectTestOutputToFile>true</redirectTestOutputToFile>
+ <redirectTestOutputToFile>false</redirectTestOutputToFile>
<trimStackTrace>false</trimStackTrace>
<printSummary>true</printSummary>
<includes>
Modified: projects/ejb-book/trunk/ch08-statusupdate/src/main/java/org/jboss/ejb3/examples/ch08/statusupdate/mdb/EnvironmentSpecificTwitterClientUtil.java
===================================================================
--- projects/ejb-book/trunk/ch08-statusupdate/src/main/java/org/jboss/ejb3/examples/ch08/statusupdate/mdb/EnvironmentSpecificTwitterClientUtil.java 2010-05-10 04:18:23 UTC (rev 104596)
+++ projects/ejb-book/trunk/ch08-statusupdate/src/main/java/org/jboss/ejb3/examples/ch08/statusupdate/mdb/EnvironmentSpecificTwitterClientUtil.java 2010-05-10 05:43:44 UTC (rev 104597)
@@ -36,7 +36,7 @@
* @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
* @version $Revision: $
*/
-class EnvironmentSpecificTwitterClientUtil
+public class EnvironmentSpecificTwitterClientUtil
{
//-------------------------------------------------------------------------------------||
Modified: projects/ejb-book/trunk/ch08-statusupdate/src/main/java/org/jboss/ejb3/examples/ch08/statusupdate/mdb/LoggingStatusUpdateMdb.java
===================================================================
--- projects/ejb-book/trunk/ch08-statusupdate/src/main/java/org/jboss/ejb3/examples/ch08/statusupdate/mdb/LoggingStatusUpdateMdb.java 2010-05-10 04:18:23 UTC (rev 104596)
+++ projects/ejb-book/trunk/ch08-statusupdate/src/main/java/org/jboss/ejb3/examples/ch08/statusupdate/mdb/LoggingStatusUpdateMdb.java 2010-05-10 05:43:44 UTC (rev 104597)
@@ -27,7 +27,6 @@
import javax.ejb.MessageDriven;
import javax.jms.MessageListener;
-import org.jboss.ejb3.annotation.Depends;
import org.jboss.ejb3.examples.ch08.statusupdate.api.StatusUpdate;
import org.jboss.ejb3.examples.ch08.statusupdate.api.StatusUpdateConstants;
@@ -45,8 +44,6 @@
{
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = StatusUpdateConstants.TYPE_DESTINATION_STATUSUPDATE),
@ActivationConfigProperty(propertyName = "destination", propertyValue = StatusUpdateConstants.JNDI_NAME_TOPIC_STATUSUPDATE)})
- at Depends(StatusUpdateConstants.OBJECT_NAME_TOPIC_STATUSUPDATE)
-// Dependency matches the name in the topic descriptor XML
public class LoggingStatusUpdateMdb extends StatusUpdateBeanBase implements MessageListener
{
Copied: projects/ejb-book/trunk/ch08-statusupdate/src/main/resources/hornetq-jms.xml (from rev 104587, projects/ejb-book/trunk/ch08-statusupdate/src/main/resources/statusupdate-topic-service.xml)
===================================================================
--- projects/ejb-book/trunk/ch08-statusupdate/src/main/resources/hornetq-jms.xml (rev 0)
+++ projects/ejb-book/trunk/ch08-statusupdate/src/main/resources/hornetq-jms.xml 2010-05-10 05:43:44 UTC (rev 104597)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration xmlns="urn:hornetq"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:hornetq /schema/hornetq-jms.xsd">
+
+ <topic name="StatusUpdate">
+ <entry name="/topic/StatusUpdate" />
+ </topic>
+
+</configuration>
\ No newline at end of file
Deleted: projects/ejb-book/trunk/ch08-statusupdate/src/main/resources/statusupdate-topic-service.xml
===================================================================
--- projects/ejb-book/trunk/ch08-statusupdate/src/main/resources/statusupdate-topic-service.xml 2010-05-10 04:18:23 UTC (rev 104596)
+++ projects/ejb-book/trunk/ch08-statusupdate/src/main/resources/statusupdate-topic-service.xml 2010-05-10 05:43:44 UTC (rev 104597)
@@ -1,9 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<server>
- <mbean code="org.jboss.jms.server.destination.TopicService"
- name="jboss.messaging.destination:service=Topic,name=StatusUpdate"
- xmbean-dd="xmdesc/Topic-xmbean.xml">
- <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
- <depends>jboss.messaging:service=PostOffice</depends>
- </mbean>
-</server>
\ No newline at end of file
Modified: projects/ejb-book/trunk/ch08-statusupdate/src/test/java/org/jboss/ejb3/examples/ch08/statusupdate/mdb/StatusUpdateIntegrationTest.java
===================================================================
--- projects/ejb-book/trunk/ch08-statusupdate/src/test/java/org/jboss/ejb3/examples/ch08/statusupdate/mdb/StatusUpdateIntegrationTest.java 2010-05-10 04:18:23 UTC (rev 104596)
+++ projects/ejb-book/trunk/ch08-statusupdate/src/test/java/org/jboss/ejb3/examples/ch08/statusupdate/mdb/StatusUpdateIntegrationTest.java 2010-05-10 05:43:44 UTC (rev 104597)
@@ -21,12 +21,6 @@
*/
package org.jboss.ejb3.examples.ch08.statusupdate.mdb;
-import java.io.File;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
@@ -40,19 +34,17 @@
import javax.naming.Context;
import javax.naming.InitialContext;
-import junit.framework.TestCase;
-
-import org.jboss.bootstrap.api.lifecycle.LifecycleState;
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.api.RunMode;
+import org.jboss.arquillian.api.RunModeType;
+import org.jboss.arquillian.junit.Arquillian;
import org.jboss.ejb3.examples.ch08.statusupdate.api.StatusUpdate;
import org.jboss.ejb3.examples.ch08.statusupdate.api.StatusUpdateConstants;
-import org.jboss.embedded.api.server.JBossASEmbeddedServer;
-import org.jboss.embedded.api.server.JBossASEmbeddedServerFactory;
-import org.jboss.embedded.api.server.JBossHomeClassLoader;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
-import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.junit.runner.RunWith;
import twitter4j.Twitter;
@@ -64,6 +56,8 @@
* @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
* @version $Revision: $
*/
+ at RunWith(Arquillian.class)
+ at RunMode(RunModeType.LOCAL)
public class StatusUpdateIntegrationTest extends StatusUpdateTestBase
{
@@ -77,16 +71,6 @@
private static final Logger log = Logger.getLogger(StatusUpdateIntegrationTest.class.getName());
/**
- * The server instance
- */
- private static JBossASEmbeddedServer server;
-
- /**
- * The CL of the test as originally loaded
- */
- private static ClassLoader originalClassLoader;
-
- /**
* Name of the archive we'll deploy into the server for testing
*/
private static final String NAME_MDB_ARCHIVE = "statusUpdateEjb.jar";
@@ -94,16 +78,9 @@
/**
* Name of the ClassLoader resource for the deployment descriptor making a new StatusUpdate JMS Topic
*/
- private static final String NAME_RESOURCE_TOPIC_DEPLOYMENT = "statusupdate-topic-service.xml";
+ private static final String NAME_RESOURCE_TOPIC_DEPLOYMENT = "hornetq-jms.xml";
/**
- * Name of the system property for JBOSS_HOME
- * @deprecated EJBBOOK-14
- */
- @Deprecated
- private static final String NAME_SYSPROP_JBOSS_HOME = "jboss.home";
-
- /**
* The JNDI Context
*/
private static Context NAMING_CONTEXT;
@@ -113,6 +90,21 @@
*/
private static final String JNDI_NAME_CONNECTION_FACTORY = "ConnectionFactory";
+ /**
+ * Creates the EJB JAR to be deployed into the server via Arquillian
+ * @return
+ */
+ @Deployment
+ public static JavaArchive getDeployment()
+ {
+ final JavaArchive archive = ShrinkWrap.create(NAME_MDB_ARCHIVE, JavaArchive.class).addClasses(StatusUpdate.class,
+ StatusUpdateConstants.class, LoggingStatusUpdateMdb.class, StatusUpdateBeanBase.class,
+ TwitterUpdateBlockingTestMdb.class, SecurityActions.class, TwitterUpdateMdb.class,
+ EnvironmentSpecificTwitterClientUtil.class).addResource(NAME_RESOURCE_TOPIC_DEPLOYMENT);
+ log.info(archive.toString(true));
+ return archive;
+ }
+
//-------------------------------------------------------------------------------------||
// Lifecycle --------------------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
@@ -120,72 +112,13 @@
/**
* Creates and starts a new JBossAS Server Embedded within this JVM
*/
- //TODO EJBBOOK-15
@BeforeClass
- public static void createAndStartJBossASAndSetNamingContext() throws Exception
+ public static void setNamingContext() throws Exception
{
- // Get JBOSS_HOME
- final URL jbossHome = getJBossHome();
-
- // Get additional binaries which need CL visibility (ie. jboss-embedded-core,
- // which is placed under "target/deps" by the build). These
- // binaries are not presently available under $JBOSS_HOME
- final Set<URL> additionalUrls = new HashSet<URL>();
- final URL source = StatusUpdateIntegrationTest.class.getProtectionDomain().getCodeSource().getLocation();
- final URL target = new URL(source, "..");
- final URL additionalDeps = new URL(target, "deps");
- final File deps = new File(additionalDeps.toURI());
- TestCase.assertTrue("Dependencies location does not exist: " + deps, deps.exists());
- TestCase.assertTrue("Dependencies location is not a directory: " + deps, deps.isDirectory());
- for (final File child : deps.listFiles())
- {
- additionalUrls.add(child.toURI().toURL());
- log.info("Booting with: " + child);
- }
-
- // Make the new ClassLoader
- originalClassLoader = SecurityActions.getThreadContextClassLoader();
- final ClassLoader jbossHomeClassLoader = JBossHomeClassLoader.newInstance(jbossHome, additionalUrls
- .toArray(new URL[]
- {}), originalClassLoader);
-
- // Make Server
- server = JBossASEmbeddedServerFactory.createServer(jbossHomeClassLoader);
- log.info("Created: " + server);
-
- // Start
- log.info("Starting Server: " + server);
-
- // Set TCCL
- SecurityActions.setThreadContextClassLoader(jbossHomeClassLoader);
-
- // Start the Server
- server.start();
-
// Set Naming Context
NAMING_CONTEXT = new InitialContext();
}
- /**
- * Stops the Application Server
- */
- @AfterClass
- public static void stopJBossAS() throws Exception
- {
- if (server != null && server.getState().equals(LifecycleState.STARTED))
- {
- try
- {
- server.shutdown();
- }
- finally
- {
- // Reset the TCCL
- Thread.currentThread().setContextClassLoader(originalClassLoader);
- }
- }
- }
-
//-------------------------------------------------------------------------------------||
// Tests ------------------------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
@@ -209,16 +142,6 @@
return;
}
- // Package up the test MDB, all required classes, and a Topic descriptor
- final JavaArchive archive = ShrinkWrap.create(NAME_MDB_ARCHIVE, JavaArchive.class).addClasses(StatusUpdate.class,
- StatusUpdateConstants.class, LoggingStatusUpdateMdb.class, StatusUpdateBeanBase.class,
- TwitterUpdateBlockingTestMdb.class, SecurityActions.class, TwitterUpdateMdb.class).addResource(
- NAME_RESOURCE_TOPIC_DEPLOYMENT);
-
- // Deploy the archive
- log.info("Deploying archive: " + archive.toString(true));
- server.deploy(archive);
-
// Create a new status
final StatusUpdate newStatus = this.getUniqueStatusUpdate();
@@ -230,7 +153,7 @@
try
{
log.info("Waiting on the MDB...");
- TwitterUpdateBlockingTestMdb.BARRIER.await(10, TimeUnit.SECONDS);
+ TwitterUpdateBlockingTestMdb.LATCH.await(10, TimeUnit.SECONDS);
}
catch (final InterruptedException e)
{
@@ -239,18 +162,11 @@
throw new RuntimeException(
"Thread was interrupted while waiting for MDB processing; should not happen in this test");
}
- catch (final BrokenBarrierException bbe)
- {
- TestCase.fail("The MDB did not process the status update in the allotted time.");
- }
log.info("MDB signaled it's done processing, so we can resume");
// Test
this.assertLastUpdateSentToTwitter(twitterClient, newStatus);
-
- // Undeploy
- server.undeploy(archive);
}
//-------------------------------------------------------------------------------------||
@@ -298,34 +214,4 @@
connection.close();
}
- /**
- * Obtains $JBOSS_HOME from the system property
- *
- * @deprecated EJBBOOK-14
- * @return
- */
- @Deprecated
- private static URL getJBossHome()
- {
- final String sysProp = NAME_SYSPROP_JBOSS_HOME;
- final String jbossHomeString = SecurityActions.getSystemProperty(sysProp);
- if (jbossHomeString == null)
- {
- throw new IllegalStateException("System property \"" + sysProp + "\" must be present in the environment");
- }
- final File jbossHomeFile = new File(jbossHomeString);
- if (!jbossHomeFile.exists())
- {
- throw new IllegalStateException("JBOSS_HOME does not exist: " + jbossHomeFile.getAbsolutePath());
- }
- try
- {
- return jbossHomeFile.toURI().toURL();
- }
- catch (final MalformedURLException murle)
- {
- throw new RuntimeException("Could not get JBOSS_HOME", murle);
- }
- }
-
}
Modified: projects/ejb-book/trunk/ch08-statusupdate/src/test/java/org/jboss/ejb3/examples/ch08/statusupdate/mdb/TwitterUpdateBlockingTestMdb.java
===================================================================
--- projects/ejb-book/trunk/ch08-statusupdate/src/test/java/org/jboss/ejb3/examples/ch08/statusupdate/mdb/TwitterUpdateBlockingTestMdb.java 2010-05-10 04:18:23 UTC (rev 104596)
+++ projects/ejb-book/trunk/ch08-statusupdate/src/test/java/org/jboss/ejb3/examples/ch08/statusupdate/mdb/TwitterUpdateBlockingTestMdb.java 2010-05-10 05:43:44 UTC (rev 104597)
@@ -21,19 +21,18 @@
*/
package org.jboss.ejb3.examples.ch08.statusupdate.mdb;
-import java.util.concurrent.CyclicBarrier;
+import java.util.concurrent.CountDownLatch;
import java.util.logging.Logger;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.MessageListener;
-import org.jboss.ejb3.annotation.Depends;
import org.jboss.ejb3.examples.ch08.statusupdate.api.StatusUpdate;
import org.jboss.ejb3.examples.ch08.statusupdate.api.StatusUpdateConstants;
/**
- * Extends the {@link TwitterUpdateMdb} example to add a barrier to
+ * Extends the {@link TwitterUpdateMdb} example to add a latch to
* be shared in testing only, such that tests can be sure we're done
* processing before they proceed
*
@@ -44,8 +43,6 @@
{
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = StatusUpdateConstants.TYPE_DESTINATION_STATUSUPDATE),
@ActivationConfigProperty(propertyName = "destination", propertyValue = StatusUpdateConstants.JNDI_NAME_TOPIC_STATUSUPDATE)})
- at Depends(StatusUpdateConstants.OBJECT_NAME_TOPIC_STATUSUPDATE)
-// Dependency matches the name in the topic descriptor XML
public class TwitterUpdateBlockingTestMdb extends TwitterUpdateMdb implements MessageListener
{
@@ -59,14 +56,14 @@
private static final Logger log = Logger.getLogger(TwitterUpdateBlockingTestMdb.class.getName());
/**
- * Shared barrier, so tests can wait until the MDB is processed. In POJO
+ * Shared latch, so tests can wait until the MDB is processed. In POJO
* testing this is wholly unnecessary as we've got a single-threaded environment, but
* when testing in an EJB Container running in the *same* JVM as the test, the test
* can use this to wait until the MDB has been invoked, strengthening the integrity
* of the test. It's not recommended to put this piece into a production EJB; instead
* test an extension of your EJB which adds this (and only this) support.
*/
- public static CyclicBarrier BARRIER = new CyclicBarrier(2);
+ public static CountDownLatch LATCH = new CountDownLatch(1);
//-------------------------------------------------------------------------------------||
// Overridden Implementations ---------------------------------------------------------||
@@ -82,11 +79,17 @@
public void updateStatus(final StatusUpdate newStatus) throws IllegalArgumentException, Exception
{
// Call the super implementation
- super.updateStatus(newStatus);
+ try
+ {
+ super.updateStatus(newStatus);
+ }
+ finally
+ {
+ // Count down the latch
+ log.info("Counting down the latch...");
+ LATCH.countDown();
+ }
- // Wait on the barrier
- log.info("Waiting on the barrier...");
- BARRIER.await();
}
}
More information about the jboss-cvs-commits
mailing list