[jboss-cvs] JBossAS SVN: r63240 - in trunk/ejb3: src/resources/test and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue May 29 05:25:09 EDT 2007
Author: wolfc
Date: 2007-05-29 05:25:08 -0400 (Tue, 29 May 2007)
New Revision: 63240
Added:
trunk/ejb3/src/resources/test/ejbthree973/
trunk/ejb3/src/resources/test/ejbthree973/ejbthree973test-service.xml
trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree973/WhoAmIMDB.java
Modified:
trunk/ejb3/build-test.xml
trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree973/unit/AnonymousCallerPrincipalTestCase.java
Log:
EJBTHREE-973: unit test MDB
Modified: trunk/ejb3/build-test.xml
===================================================================
--- trunk/ejb3/build-test.xml 2007-05-29 08:31:49 UTC (rev 63239)
+++ trunk/ejb3/build-test.xml 2007-05-29 09:25:08 UTC (rev 63240)
@@ -2006,6 +2006,12 @@
depends="compile-classes">
<build-simple-jar name="ejbthree973"/>
+
+ <copy todir="${build.lib}">
+ <fileset dir="${resources}/test/ejbthree973">
+ <include name="*.xml"/>
+ </fileset>
+ </copy>
</target>
<target name="jaxws"
Added: trunk/ejb3/src/resources/test/ejbthree973/ejbthree973test-service.xml
===================================================================
--- trunk/ejb3/src/resources/test/ejbthree973/ejbthree973test-service.xml (rev 0)
+++ trunk/ejb3/src/resources/test/ejbthree973/ejbthree973test-service.xml 2007-05-29 09:25:08 UTC (rev 63240)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<server>
+ <mbean code="org.jboss.mq.server.jmx.Queue"
+ name="jboss.mq.destination:service=Queue,name=whoAmI">
+ <attribute name="JNDIName">queue/whoAmI</attribute>
+ <depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends>
+ </mbean>
+</server>
\ No newline at end of file
Property changes on: trunk/ejb3/src/resources/test/ejbthree973/ejbthree973test-service.xml
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Added: trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree973/WhoAmIMDB.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree973/WhoAmIMDB.java (rev 0)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree973/WhoAmIMDB.java 2007-05-29 09:25:08 UTC (rev 63240)
@@ -0,0 +1,112 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.test.ejbthree973;
+
+import javax.annotation.Resource;
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.MessageDriven;
+import javax.ejb.MessageDrivenContext;
+import javax.jms.DeliveryMode;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+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 org.jboss.annotation.security.SecurityDomain;
+
+/**
+ * Report the caller principal.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at MessageDriven(activationConfig = {
+ @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue"),
+ @ActivationConfigProperty(propertyName="destination", propertyValue="queue/whoAmI")
+ })
+ at SecurityDomain(value="", unauthenticatedPrincipal="anonymous")
+public class WhoAmIMDB implements MessageListener
+{
+ @Resource
+ private MessageDrivenContext ctx;
+
+ @Resource(mappedName="java:/ConnectionFactory")
+ private QueueConnectionFactory qFactory;
+
+ public void onMessage(Message message)
+ {
+ try
+ {
+ try
+ {
+ sendOptionalReply(message, ctx.getCallerPrincipal().getName());
+ }
+ catch(IllegalStateException e)
+ {
+ sendReplyOrThrow(message, e);
+ }
+ }
+ catch(JMSException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private void sendOptionalReply(Message message, String replyText) throws JMSException
+ {
+ // ignore if no reply is wanted
+ if(message.getJMSReplyTo() == null)
+ return;
+
+ sendReply((Queue) message.getJMSReplyTo(), message.getJMSCorrelationID(), replyText);
+ }
+
+ private void sendReply(Queue destination, String messageID, String text) throws JMSException
+ {
+ QueueConnection conn = qFactory.createQueueConnection();
+ try
+ {
+ QueueSession session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+ QueueSender sender = session.createSender(destination);
+ TextMessage message = session.createTextMessage(text);
+ message.setJMSCorrelationID(messageID);
+ sender.send(message, DeliveryMode.NON_PERSISTENT, 4, 500);
+ }
+ finally
+ {
+ conn.close();
+ }
+ }
+
+ private void sendReplyOrThrow(Message message, RuntimeException e) throws JMSException
+ {
+ if(message.getJMSReplyTo() == null)
+ throw e;
+
+ sendOptionalReply(message, e.getClass().getName());
+ }
+}
Property changes on: trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree973/WhoAmIMDB.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Modified: trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree973/unit/AnonymousCallerPrincipalTestCase.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree973/unit/AnonymousCallerPrincipalTestCase.java 2007-05-29 08:31:49 UTC (rev 63239)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/ejbthree973/unit/AnonymousCallerPrincipalTestCase.java 2007-05-29 09:25:08 UTC (rev 63240)
@@ -21,6 +21,15 @@
*/
package org.jboss.ejb3.test.ejbthree973.unit;
+import javax.jms.DeliveryMode;
+import javax.jms.MessageConsumer;
+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 junit.framework.Test;
import org.jboss.ejb3.test.ejbthree973.WhoAmI;
@@ -65,8 +74,38 @@
assertEquals("anonymous", actual);
}
+ public void testMDB() throws Exception
+ {
+ QueueConnectionFactory qFactory = (QueueConnectionFactory) getInitialContext().lookup("ConnectionFactory");
+ QueueConnection conn = qFactory.createQueueConnection();
+ try
+ {
+ QueueSession session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+
+ Queue replyQueue = session.createTemporaryQueue();
+ MessageConsumer consumer = session.createConsumer(replyQueue);
+ conn.start();
+
+ Queue sendQueue = (Queue) getInitialContext().lookup("queue/whoAmI");
+ QueueSender sender = session.createSender(sendQueue);
+ TextMessage message = session.createTextMessage("Hello world");
+ message.setJMSReplyTo(replyQueue);
+ sender.send(message, DeliveryMode.NON_PERSISTENT, 4, 500);
+
+ TextMessage reply = (TextMessage) consumer.receive(1000);
+ assertNotNull("No reply received", reply);
+ assertEquals("anonymous", reply.getText());
+
+ conn.stop();
+ }
+ finally
+ {
+ conn.close();
+ }
+ }
+
public static Test suite() throws Exception
{
- return getDeploySetup(AnonymousCallerPrincipalTestCase.class, "ejbthree973.jar");
+ return getDeploySetup(AnonymousCallerPrincipalTestCase.class, "ejbthree973test-service.xml,ejbthree973.jar");
}
}
More information about the jboss-cvs-commits
mailing list