[jboss-cvs] JBossAS SVN: r89714 - in branches/JBPAPP_4_2_0_GA_CP/ejb3: src/test/org/jboss/ejb3/test and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jun 3 04:10:42 EDT 2009


Author: wolfc
Date: 2009-06-03 04:10:41 -0400 (Wed, 03 Jun 2009)
New Revision: 89714

Added:
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/common/AbstractReplierMDB.java
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1668/
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1668/AbstractTXMDB.java
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1668/TXDefaultMDB.java
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1668/TXNotSupportedMDB.java
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1668/unit/
   branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1668/unit/TXAttributeTestCase.java
Modified:
   branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml
Log:
JBPAPP-1668: unit test

Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml	2009-06-03 07:31:13 UTC (rev 89713)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml	2009-06-03 08:10:41 UTC (rev 89714)
@@ -2185,6 +2185,18 @@
       <build-simple-jar name="jbpapp1224"/>
    </target>
 
+   <target name="jbpapp1668"
+      description="Builds a simple jar files."
+      depends="compile-classes">
+
+      <jar jarfile="${build.lib}/jbpapp1668.jar">
+         <fileset dir="${build.classes}">
+            <include name="org/jboss/ejb3/test/common/*.class"/>
+            <include name="org/jboss/ejb3/test/jbpapp1668/*.class"/>
+         </fileset>
+      </jar>
+   </target>
+
    <target name="jbpapp1951" depends="compile-classes">
       <mkdir dir="${build.lib}"/>
       <jar jarfile="${build.lib}/jbpapp1951.jar">
@@ -3894,6 +3906,7 @@
       jbpapp999,
       jbpapp1186,
       jbpapp1224,
+      jbpapp1668,
       jbpapp1951,
       jbas4489, epcpropagation, jaccpropagation, 
       aspectdomain, ejbcontext, schema, mail, scopedclassloader, dependency, jaxws,
@@ -4543,6 +4556,9 @@
          <param name="test" value="jbpapp1224"/>
       </antcall>
       <antcall target="test" inheritRefs="true">
+         <param name="test" value="jbpapp1668"/>
+      </antcall>
+      <antcall target="test" inheritRefs="true">
          <param name="test" value="jbpapp1951"/>
       </antcall>
    </target>

Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/common/AbstractReplierMDB.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/common/AbstractReplierMDB.java	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/common/AbstractReplierMDB.java	2009-06-03 08:10:41 UTC (rev 89714)
@@ -0,0 +1,104 @@
+/*
+ * 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.test.common;
+
+import java.io.Serializable;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.annotation.Resource;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+
+import org.jboss.logging.Logger;
+
+/**
+ * Sets up a MDB which can reply to messages via sendReply.
+ * 
+ * Make sure that postConstruct are preDestroy are properly executed when overridden.
+ * 
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public abstract class AbstractReplierMDB implements MessageListener
+{
+   private static final Logger log = Logger.getLogger(AbstractReplierMDB.class);
+   
+   @Resource(mappedName="java:/ConnectionFactory")
+   private QueueConnectionFactory factory;
+   
+   private QueueConnection connection;
+   private QueueSession session;
+   private QueueSender sender;
+   
+   /**
+    * Send an object message to the specified destination.
+    * 
+    * @param destination
+    * @param obj
+    * @throws JMSException
+    */
+   protected void sendReply(Destination destination, Serializable obj) throws JMSException
+   {
+      Message message = session.createObjectMessage(obj);
+      sender.send(destination, message);
+   }
+   
+   @PostConstruct
+   public void postConstruct()
+   {
+      try
+      {
+         connection = factory.createQueueConnection();
+         session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+         sender = session.createSender(null);
+      }
+      catch(JMSException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+   
+   @PreDestroy
+   public void preDestroy()
+   {
+      try
+      {
+         if(sender != null)
+            sender.close();
+         if(session != null)
+            session.close();
+         if(connection != null)
+            connection.close();
+      }
+      catch(JMSException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+}

Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1668/AbstractTXMDB.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1668/AbstractTXMDB.java	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1668/AbstractTXMDB.java	2009-06-03 08:10:41 UTC (rev 89714)
@@ -0,0 +1,71 @@
+/*
+ * 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.test.jbpapp1668;
+
+import javax.annotation.Resource;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.transaction.SystemException;
+import javax.transaction.TransactionManager;
+
+import org.jboss.ejb3.test.common.AbstractReplierMDB;
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public abstract class AbstractTXMDB extends AbstractReplierMDB
+{
+   private static final Logger log = Logger.getLogger(AbstractTXMDB.class);
+   
+   // this goes against spec, normally you would use BMT and UserTransaction
+   @Resource(mappedName="java:/TransactionManager")
+   private TransactionManager tm;
+   
+   protected void process(Message message)
+   {
+      try
+      {
+         Destination destination = message.getJMSReplyTo();
+         
+         try
+         {
+            int status = tm.getStatus();
+            
+            log.info("Transaction status " + status);
+            
+            sendReply(destination, status);
+         }
+         catch(SystemException e)
+         {
+            log.warn("Transaction status failed", e);
+            sendReply(destination, e);
+         }
+      }
+      catch(JMSException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+}

Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1668/TXDefaultMDB.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1668/TXDefaultMDB.java	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1668/TXDefaultMDB.java	2009-06-03 08:10:41 UTC (rev 89714)
@@ -0,0 +1,44 @@
+/*
+ * 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.test.jbpapp1668;
+
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.MessageDriven;
+import javax.jms.Message;
+
+/**
+ * Reply the tx status when using default settings.
+ * 
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at MessageDriven(activationConfig = {
+      @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
+      @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/jbpapp1668-default"),
+      @ActivationConfigProperty(propertyName = "maxSession", propertyValue = "3") })
+public class TXDefaultMDB extends AbstractTXMDB
+{
+   public void onMessage(Message message)
+   {
+      process(message);
+   }
+}

Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1668/TXNotSupportedMDB.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1668/TXNotSupportedMDB.java	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1668/TXNotSupportedMDB.java	2009-06-03 08:10:41 UTC (rev 89714)
@@ -0,0 +1,48 @@
+/*
+ * 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.test.jbpapp1668;
+
+import static javax.ejb.TransactionAttributeType.NOT_SUPPORTED;
+
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.MessageDriven;
+import javax.ejb.TransactionAttribute;
+import javax.jms.Message;
+
+/**
+ * Reply the tx status when using NOT_SUPPORTED.
+ * 
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at MessageDriven(activationConfig = {
+      @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
+      @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/jbpapp1668-notx"),
+      @ActivationConfigProperty(propertyName = "maxSession", propertyValue = "3") })
+public class TXNotSupportedMDB extends AbstractTXMDB
+{
+   @TransactionAttribute(NOT_SUPPORTED)
+   public void onMessage(Message message)
+   {
+      process(message);
+   }
+}

Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1668/unit/TXAttributeTestCase.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1668/unit/TXAttributeTestCase.java	                        (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/jbpapp1668/unit/TXAttributeTestCase.java	2009-06-03 08:10:41 UTC (rev 89714)
@@ -0,0 +1,114 @@
+/*
+ * 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.test.jbpapp1668.unit;
+
+import java.io.Serializable;
+
+import javax.jms.DeliveryMode;
+import javax.jms.Message;
+import javax.jms.ObjectMessage;
+import javax.jms.Queue;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.QueueReceiver;
+import javax.jms.QueueSender;
+import javax.jms.QueueSession;
+import javax.jms.TemporaryQueue;
+import javax.jms.TextMessage;
+import javax.transaction.Status;
+
+import junit.framework.Test;
+
+import org.jboss.ejb3.test.common.EJB3TestCase;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class TXAttributeTestCase extends EJB3TestCase
+{
+   public TXAttributeTestCase(String name)
+   {
+      super(name);
+   }
+
+   public Object sendMessage(String queueName, String text) throws Exception
+   {
+      Queue queue = lookup("queue/" + queueName, Queue.class);
+      QueueConnectionFactory factory = getQueueConnectionFactory();
+      QueueConnection conn = factory.createQueueConnection();
+      try
+      {
+         QueueSession session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+         TemporaryQueue replyQueue = session.createTemporaryQueue();
+         QueueReceiver receiver = session.createReceiver(replyQueue);
+         QueueSender sender = session.createSender(queue);
+         conn.start();
+         try
+         {
+            TextMessage msg = session.createTextMessage(text);
+            msg.setJMSReplyTo(replyQueue);
+            msg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
+            msg.setIntProperty("JMS_JBOSS_REDELIVERY_LIMIT", 1);
+      
+            sender.send(msg);
+            
+            Message reply = receiver.receive(5000);
+            assertNotNull(reply);
+            
+            Serializable obj = ((ObjectMessage) reply).getObject();
+            if(obj instanceof Exception)
+               throw (Exception) obj;
+            else
+               return obj;
+         }
+         finally
+         {
+            conn.stop();
+            sender.close();
+            receiver.close();
+            session.close();
+         }
+      }
+      finally
+      {
+         conn.close();
+      }
+   }
+   
+   public void testDefault() throws Exception
+   {
+      Object result = sendMessage("jbpapp1668-default", "testDefault");
+      assertEquals("Wrong transaction status", Status.STATUS_ACTIVE, result);
+   }
+   
+   public void testNotSupported() throws Exception
+   {
+      Object result = sendMessage("jbpapp1668-notx", "testNotSupported");
+      assertEquals("Wrong transaction status", Status.STATUS_NO_TRANSACTION, result);
+   }
+   
+   public static Test suite() throws Exception
+   {
+      return getDeploySetup(TXAttributeTestCase.class, "jbpapp1668.jar");
+   }
+}




More information about the jboss-cvs-commits mailing list