[jboss-cvs] JBossAS SVN: r91330 - in projects/embedded/trunk: testsuite-full-dep/src/test/java/org/jboss and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Jul 16 00:34:57 EDT 2009
Author: ALRubinger
Date: 2009-07-16 00:34:55 -0400 (Thu, 16 Jul 2009)
New Revision: 91330
Added:
projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/embedded/testsuite/fulldep/ejb3/mdb/
projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/embedded/testsuite/fulldep/ejb3/mdb/MessageStoringMdb.java
projects/embedded/trunk/testsuite-full-dep/src/test/resources/queues/
projects/embedded/trunk/testsuite-full-dep/src/test/resources/queues/mdb-queue-service.xml
Modified:
projects/embedded/trunk/core/pom.xml
projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/ServerTestCase.java
Log:
[EMB-32] EJB3 MDB - JMS Queue working now Embedded, added explicit dependency on jboss-messaging to fix
Modified: projects/embedded/trunk/core/pom.xml
===================================================================
--- projects/embedded/trunk/core/pom.xml 2009-07-16 04:28:03 UTC (rev 91329)
+++ projects/embedded/trunk/core/pom.xml 2009-07-16 04:34:55 UTC (rev 91330)
@@ -36,6 +36,7 @@
-->
<version.jboss.web>2.1.3.GA</version.jboss.web>
+ <version.jboss.messaging>1.4.3.GA</version.jboss.messaging>
</properties>
@@ -82,6 +83,11 @@
<artifactId>jasper-jdt</artifactId>
<version>${version.jboss.web}</version>
</dependency>
+ <dependency>
+ <groupId>jboss.messaging</groupId>
+ <artifactId>jboss-messaging</artifactId>
+ <version>${version.jboss.messaging}</version>
+ </dependency>
</dependencies>
Modified: projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/ServerTestCase.java
===================================================================
--- projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/ServerTestCase.java 2009-07-16 04:28:03 UTC (rev 91329)
+++ projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/ServerTestCase.java 2009-07-16 04:34:55 UTC (rev 91330)
@@ -28,7 +28,16 @@
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+import javax.jms.TextMessage;
+import javax.naming.Context;
import javax.naming.InitialContext;
import junit.framework.Assert;
@@ -48,6 +57,7 @@
import org.jboss.embedded.core.incubation.virtual.spi.vfs.VirtualVfsArchive;
import org.jboss.embedded.core.server.JBossASEmbeddedServer;
import org.jboss.embedded.core.server.JBossASEmbeddedServerImpl;
+import org.jboss.embedded.testsuite.fulldep.ejb3.mdb.MessageStoringMdb;
import org.jboss.embedded.testsuite.fulldep.ejb3.slsb.OutputBean;
import org.jboss.embedded.testsuite.fulldep.ejb3.slsb.OutputLocalBusiness;
import org.jboss.embedded.testsuite.fulldep.servlet.JspForwardingServlet;
@@ -116,6 +126,16 @@
private static final String PATH_ACTUAL_WEB_XML = "webxml/servletForwardingToJsp.xml";
/**
+ * Filename of a test queue *-service.xml
+ */
+ private static final String FILENAME_QUEUE_SERVICE_XML = "mdb-queue-service.xml";
+
+ /**
+ * Path, relative to the resources base, of a test queue *-service.xml
+ */
+ private static final String PATH_QUEUE_SERVICE_XML = "queues/" + FILENAME_QUEUE_SERVICE_XML;
+
+ /**
* Path, relative to the resources base, of a test JSP
*/
private static final String PATH_JSP = "jsp/requestParamEcho.jsp";
@@ -125,6 +145,16 @@
*/
private static final char SEPARATOR = '/';
+ /**
+ * The JNDI Context
+ */
+ private static Context NAMING_CONTEXT;
+
+ /**
+ * Name of the Queue Connection Factory in JNDI
+ */
+ private static final String JNDI_NAME_CONNECTION_FACTORY = "ConnectionFactory";
+
//-------------------------------------------------------------------------------||
// Lifecycle --------------------------------------------------------------------||
//-------------------------------------------------------------------------------||
@@ -135,7 +165,7 @@
* precedence to the system property
*/
@BeforeClass
- public static void startEmbedddedAS() throws Exception
+ public static void startEmbedddedASAndSetNamingContext() throws Exception
{
// Make Server (will pull JBOSS_HOME from env var or sys prop)
server = new JBossASEmbeddedServerImpl();
@@ -145,6 +175,9 @@
log.info("Starting Server: " + server);
server.start();
log.info("...started.");
+
+ // Set Naming Context
+ NAMING_CONTEXT = new InitialContext();
}
/**
@@ -188,8 +221,7 @@
server.deploy(deployment);
// Test
- final OutputLocalBusiness bean = (OutputLocalBusiness) new InitialContext().lookup(OutputBean.class
- .getSimpleName()
+ final OutputLocalBusiness bean = (OutputLocalBusiness) NAMING_CONTEXT.lookup(OutputBean.class.getSimpleName()
+ "/local");;
final String output = bean.getOutput();
log.info("Got output: " + output);
@@ -237,7 +269,7 @@
final HttpClient client = new DefaultHttpClient();
// Make an HTTP Request
- final String echoValue = "EmbeddedRules";
+ final String echoValue = "EmbeddedBiatch";
final List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("jsp", PATH_JSP));
params.add(new BasicNameValuePair("echo", echoValue));
@@ -261,11 +293,110 @@
Assert.assertEquals(echoValue, line);
}
+ /**
+ * Tests virtual deployment of a JMS Queue with EJB3 MDB Listener
+ *
+ * The MDB will simply store the text of the message in a publicly-accessible
+ * static field
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testVirtualJmsAndMdb() throws Exception
+ {
+ // Log
+ log.info("testVirtualJmsAndMdb");
+
+ // Create a virtual archive for the MDB deployment
+ final VirtualVfsArchive deployment = new VirtualVfsArchiveImpl("mdb.jar").addClass(MessageStoringMdb.class)
+ .addResource(new URL(this.getBase(), PATH_QUEUE_SERVICE_XML), FILENAME_QUEUE_SERVICE_XML);
+
+ // Deploy
+ log.info(deployment.toString(true));
+ server.deploy(deployment);
+
+ // Define a String message to send
+ final String message = "From in-JVM Test Message";
+
+ // Send the message
+ this.sendTextMessageToQueue(message, MessageStoringMdb.NAME_QUEUE);
+
+ // Wait on the MDB to process
+ try
+ {
+ MessageStoringMdb.BARRIER.await(10, TimeUnit.SECONDS);
+ }
+ catch (final InterruptedException e)
+ {
+ // Clear the flag
+ Thread.interrupted();
+ // Throw up
+ throw e;
+ }
+ catch (final TimeoutException e)
+ {
+ TestCase.fail("The MDB did not process the message in the allotted time");
+ }
+
+ // Get the contents of the String from the MDB
+ final String received = MessageStoringMdb.LAST_MESSAGE_CONTENTS;
+
+ // Ensure equal
+ Assert.assertEquals("The test message received was not as expected", message, received);
+
+ }
+
//-------------------------------------------------------------------------------------||
// Internal Helper Methods ------------------------------------------------------------||
//-------------------------------------------------------------------------------------||
/**
+ * Sends a JMS {@link TextMessage} containing the specified contents to the
+ * queue of the specified name
+ *
+ * @param contents
+ * @param queueName
+ * @throws Exception
+ * @throws IllegalArgumentException If either argument is not provided
+ */
+ private void sendTextMessageToQueue(final String contents, final String queueName) throws Exception,
+ IllegalArgumentException
+ {
+ // Precondition check
+ if (contents == null || contents.length() == 0)
+ {
+ throw new IllegalArgumentException("contents must be provided");
+ }
+ if (queueName == null || queueName.length() == 0)
+ {
+ throw new IllegalArgumentException("queueName must be provided");
+ }
+
+ // Get the queue from JNDI
+ final Queue queue = (Queue) NAMING_CONTEXT.lookup(queueName);
+
+ // Get the ConnectionFactory from JNDI
+ final QueueConnectionFactory factory = (QueueConnectionFactory) NAMING_CONTEXT
+ .lookup(JNDI_NAME_CONNECTION_FACTORY);
+
+ // Make a Connection
+ final QueueConnection connection = factory.createQueueConnection();
+ final QueueSession sendSession = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+
+ // Make the message
+ final TextMessage message = sendSession.createTextMessage(contents);
+
+ // Send the message
+ final QueueSender sender = sendSession.createSender(queue);
+ sender.send(message);
+ log.info("Sent message " + message + " with contents: " + contents);
+
+ // Clean up
+ sendSession.close();
+ connection.close();
+ }
+
+ /**
* Obtains the test resources base
*/
private URL getBase() throws Exception
Added: projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/embedded/testsuite/fulldep/ejb3/mdb/MessageStoringMdb.java
===================================================================
--- projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/embedded/testsuite/fulldep/ejb3/mdb/MessageStoringMdb.java (rev 0)
+++ projects/embedded/trunk/testsuite-full-dep/src/test/java/org/jboss/embedded/testsuite/fulldep/ejb3/mdb/MessageStoringMdb.java 2009-07-16 04:34:55 UTC (rev 91330)
@@ -0,0 +1,135 @@
+/*
+ * 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.embedded.testsuite.fulldep.ejb3.mdb;
+
+import java.util.concurrent.BrokenBarrierException;
+import java.util.concurrent.CyclicBarrier;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.MessageDriven;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.TextMessage;
+
+import org.jboss.logging.Logger;
+
+/**
+ * MessageStoringMdb
+ *
+ * A message-driven bean which stores the contents of a text
+ * message into a publicly-available static field.
+ *
+ * Here we control the test environment
+ * so we'll permit this clash of design paradigms. Don't
+ * try this at home, kids.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at MessageDriven(activationConfig =
+{@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
+ @ActivationConfigProperty(propertyName = "destination", propertyValue = MessageStoringMdb.NAME_QUEUE)})
+public class MessageStoringMdb implements MessageListener
+{
+ //-------------------------------------------------------------------------------------||
+ // Class Members ----------------------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /**
+ * Logger
+ */
+ private static final Logger log = Logger.getLogger(MessageStoringMdb.class);
+
+ /**
+ * Exposed contents of the last message received, volatile
+ * so the thread visibility from the test will always get the
+ * right value
+ */
+ public volatile static String LAST_MESSAGE_CONTENTS = null;
+
+ /**
+ * Shared barrier, so tests can wait until the MDB is processed
+ */
+ public static CyclicBarrier BARRIER = new CyclicBarrier(2);
+
+ /**
+ * Name of the queue upon which we'll listen
+ */
+ public static final String NAME_QUEUE = "queue/EmbeddedQueue";
+
+ //-------------------------------------------------------------------------------------||
+ // Required Implementations -----------------------------------------------------------||
+ //-------------------------------------------------------------------------------------||
+
+ /* (non-Javadoc)
+ * @see javax.jms.MessageListener#onMessage(javax.jms.Message)
+ */
+ @Override
+ public void onMessage(final Message message)
+ {
+ // Log
+ log.info("Received: " + message);
+
+ // Cast
+ final TextMessage notSms = (TextMessage) message;
+
+ // Obtain contents
+ final String contents;
+ try
+ {
+ contents = notSms.getText();
+ }
+ catch (final JMSException jmse)
+ {
+ throw new RuntimeException("Could not obtain contents of message: " + notSms, jmse);
+ }
+
+ // Store contents
+ LAST_MESSAGE_CONTENTS = contents;
+
+ // Announce to the barrier we're here, and block on the test
+ // (so that the test can block as well and know when we're done;
+ // we should really be the second ones here)
+ try
+ {
+ BARRIER.await(2, TimeUnit.SECONDS);
+ }
+ catch (final InterruptedException e)
+ {
+ // Clear the flag
+ Thread.interrupted();
+ // Throw up
+ throw new RuntimeException("Unexpected interruption", e);
+ }
+ catch (final BrokenBarrierException e)
+ {
+ throw new RuntimeException(e);
+ }
+ catch (final TimeoutException e)
+ {
+ throw new RuntimeException("The test did not call upon the barrier in the allotted time", e);
+ }
+ }
+}
Added: projects/embedded/trunk/testsuite-full-dep/src/test/resources/queues/mdb-queue-service.xml
===================================================================
--- projects/embedded/trunk/testsuite-full-dep/src/test/resources/queues/mdb-queue-service.xml (rev 0)
+++ projects/embedded/trunk/testsuite-full-dep/src/test/resources/queues/mdb-queue-service.xml 2009-07-16 04:34:55 UTC (rev 91330)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<server>
+ <mbean code="org.jboss.jms.server.destination.QueueService"
+ name="jboss.messaging.destination:service=Queue,name=EmbeddedQueue"
+ xmbean-dd="xmdesc/Queue-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
More information about the jboss-cvs-commits
mailing list