[jboss-cvs] JBossAS SVN: r114670 - in branches/JBPAPP_5/testsuite: src/main/org/jboss/test/mdb/bean and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jan 20 07:56:17 EST 2014


Author: jmartisk
Date: 2014-01-20 07:56:16 -0500 (Mon, 20 Jan 2014)
New Revision: 114670

Added:
   branches/JBPAPP_5/testsuite/src/main/org/jboss/test/mdb/bean/SubstitutionQueueBean.java
   branches/JBPAPP_5/testsuite/src/main/org/jboss/test/mdb/bean/SubstitutionQueueWithAutocreateBean.java
   branches/JBPAPP_5/testsuite/src/resources/mdb/autocreate/
   branches/JBPAPP_5/testsuite/src/resources/mdb/autocreate/META-INF/
   branches/JBPAPP_5/testsuite/src/resources/mdb/autocreate/META-INF/jboss.xml
   branches/JBPAPP_5/testsuite/src/resources/mdb/mdb-substitution-system-properties-service.xml
Modified:
   branches/JBPAPP_5/testsuite/imports/sections/mdb.xml
   branches/JBPAPP_5/testsuite/src/main/org/jboss/test/mdb/test/MDBUnitTestCase.java
   branches/JBPAPP_5/testsuite/src/main/org/jboss/test/util/jms/JMSDestinationsUtil.java
Log:
[JBQA-8617] tests for MDB property substitution

Modified: branches/JBPAPP_5/testsuite/imports/sections/mdb.xml
===================================================================
--- branches/JBPAPP_5/testsuite/imports/sections/mdb.xml	2014-01-20 11:18:20 UTC (rev 114669)
+++ branches/JBPAPP_5/testsuite/imports/sections/mdb.xml	2014-01-20 12:56:16 UTC (rev 114670)
@@ -25,7 +25,13 @@
          <!-- <fileset dir="${build.resources}/mdb">
             <include name="**/*.xml"/>
          </fileset> -->
+          <fileset dir="${build.resources}/mdb/autocreate">
+              <include name="META-INF/jboss.xml"/>
+          </fileset>
       </jar>
+
+       <!-- prepare system-properties-service.xml needed for MDBUnitTestCase -->
+       <copy file="${build.resources}/mdb/mdb-substitution-system-properties-service.xml" todir="${build.lib}"/>
    </target>
 
    <!-- messagedriven test -->

Added: branches/JBPAPP_5/testsuite/src/main/org/jboss/test/mdb/bean/SubstitutionQueueBean.java
===================================================================
--- branches/JBPAPP_5/testsuite/src/main/org/jboss/test/mdb/bean/SubstitutionQueueBean.java	                        (rev 0)
+++ branches/JBPAPP_5/testsuite/src/main/org/jboss/test/mdb/bean/SubstitutionQueueBean.java	2014-01-20 12:56:16 UTC (rev 114670)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2013, Red Hat, Inc., 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.test.mdb.bean;
+
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.EJBException;
+import javax.ejb.MessageDriven;
+import javax.ejb.MessageDrivenBean;
+import javax.ejb.MessageDrivenContext;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+
+import org.jboss.ejb3.annotation.Depends;
+import org.jboss.ejb3.annotation.ResourceAdapter;
+import org.jboss.logging.Logger;
+
+
+/**
+ * @author wangchao
+ * Test MDB annotation properties substitution destinationType, destination
+ * Values depend on system properties injected from system-properties-service.xml
+ */
+ at MessageDriven(name = "SubstitutionQueueBean", activationConfig = {
+        @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
+        @ActivationConfigProperty(propertyName = "destination", propertyValue = "${destination:queue/testSubstitutionQueue}"),
+        @ActivationConfigProperty(propertyName = "messageSelector", propertyValue = "toEntity = '${myEntity}'"),
+        @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge") })
+ at ResourceAdapter("${resource.adapter}")
+ at Depends("jboss:type=Service,name=MDBSystemProperties")
+public class SubstitutionQueueBean implements MessageDrivenBean, MessageListener {
+    private static final Logger log = Logger.getLogger(SubstitutionQueueBean.class);
+
+    private MessageDrivenContext ctx = null;
+
+    public SubstitutionQueueBean() {
+
+    }
+
+    public void setMessageDrivenContext(MessageDrivenContext ctx) throws EJBException {
+        this.ctx = ctx;
+    }
+
+    public void ejbCreate() {
+    }
+
+    public void ejbRemove() {
+        ctx = null;
+    }
+
+    @Override
+    public void onMessage(Message message) {
+        log.debug("DEBUG: SubstitutionQueueBean got message " + message.toString());
+    }
+}

Added: branches/JBPAPP_5/testsuite/src/main/org/jboss/test/mdb/bean/SubstitutionQueueWithAutocreateBean.java
===================================================================
--- branches/JBPAPP_5/testsuite/src/main/org/jboss/test/mdb/bean/SubstitutionQueueWithAutocreateBean.java	                        (rev 0)
+++ branches/JBPAPP_5/testsuite/src/main/org/jboss/test/mdb/bean/SubstitutionQueueWithAutocreateBean.java	2014-01-20 12:56:16 UTC (rev 114670)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2013, Red Hat, Inc., 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.test.mdb.bean;
+
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.EJBException;
+import javax.ejb.MessageDriven;
+import javax.ejb.MessageDrivenBean;
+import javax.ejb.MessageDrivenContext;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+
+import org.jboss.ejb3.annotation.Depends;
+import org.jboss.ejb3.annotation.ResourceAdapter;
+import org.jboss.logging.Logger;
+
+
+/**
+ * @author wangchao, jmartisk
+ * Test MDB annotation properties substitution - destination
+ * Values depend on system properties injected from system-properties-service.xml
+ * The queue is created automatically thanks to jboss.xml descriptor
+ */
+ at MessageDriven(name = "SubstitutionQueueWithAutocreateBean", activationConfig = {
+        @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
+        @ActivationConfigProperty(propertyName = "destination", propertyValue = "${queue.autocreate.name}"),
+        @ActivationConfigProperty(propertyName = "messageSelector", propertyValue = "toEntity = 'LOC'"),
+        @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge") })
+//@Depends("jboss:type=Service,name=MDBSystemProperties")
+public class SubstitutionQueueWithAutocreateBean implements MessageDrivenBean, MessageListener {
+    private static final Logger log = Logger.getLogger(SubstitutionQueueWithAutocreateBean.class);
+
+    private MessageDrivenContext ctx = null;
+
+    public SubstitutionQueueWithAutocreateBean() {
+
+    }
+
+    public void setMessageDrivenContext(MessageDrivenContext ctx) throws EJBException {
+        this.ctx = ctx;
+    }
+
+    public void ejbCreate() {
+    }
+
+    public void ejbRemove() {
+        ctx = null;
+    }
+
+    @Override
+    public void onMessage(Message message) {
+        log.debug("DEBUG: SubstitutionQueueBean got message " + message.toString());
+    }
+}

Modified: branches/JBPAPP_5/testsuite/src/main/org/jboss/test/mdb/test/MDBUnitTestCase.java
===================================================================
--- branches/JBPAPP_5/testsuite/src/main/org/jboss/test/mdb/test/MDBUnitTestCase.java	2014-01-20 11:18:20 UTC (rev 114669)
+++ branches/JBPAPP_5/testsuite/src/main/org/jboss/test/mdb/test/MDBUnitTestCase.java	2014-01-20 12:56:16 UTC (rev 114670)
@@ -50,7 +50,7 @@
  * Some simple tests of MDB. These could be much more elaborated.
  * These are also largely useless as they don't validate that the mdb
  * actually gets the messages.
- * 
+ *
  * In the future at least the following tests should be done some how:
  * <ol>
  * <li>Queue
@@ -63,10 +63,10 @@
  * <li>User and password login
  * <li>Al the stuff with the context
  * </ol>
- * 
+ *
  * <p>
  * Created: Fri Dec 29 16:53:26 2000
- * 
+ *
  * @author <a href="mailto:peter.antman at tim.se">Peter Antman</a>
  * @author <a href="mailto:jason at planet57.com">Jason Dillon</a>
  * @author <a href="mailto:d_jencks at users.sourceforge.net">David Jencks</a>
@@ -166,6 +166,43 @@
       sender.close();
    }
 
+   public void testMDBPropertySubstitution() throws Exception {
+       printHeader();
+       QueueSession session = getQueueSession();
+       Queue queue = (Queue) getInitialContext().lookup(dest);
+       QueueSender sender = session.createSender(queue);
+
+       getLog().debug("TestMDBPropertySubstitution: " + dest + " Sending 10 messages 1-10");
+       for (int i = 1; i < 6; i++) {
+           TextMessage message = session.createTextMessage();
+           message.setText("Queue Message " + dest + " nr " + i);
+           message.setStringProperty("toEntity", "LOC");
+           sender.send(queue, message);
+       }
+
+       sender.close();
+   }
+
+    /**
+     * Property substition for a MDB using a Queue which is autocreated using jboss.xml
+     */
+    public void testMDBPropertySubstitutionAutocreate() throws Exception {
+        printHeader();
+        QueueSession session = getQueueSession();
+        Queue queue = (Queue) getInitialContext().lookup(dest);
+        QueueSender sender = session.createSender(queue);
+
+        getLog().debug("TestMDBPropertySubstitution: " + dest + " Sending 10 messages 1-10");
+        for (int i = 1; i < 6; i++) {
+            TextMessage message = session.createTextMessage();
+            message.setText("Queue Message " + dest + " nr " + i);
+            message.setStringProperty("toEntity", "LOC");
+            sender.send(queue, message);
+        }
+
+        sender.close();
+    }
+
    /**
     * Test sending messages to Queue testQueue
     */
@@ -263,6 +300,8 @@
             "testNoTopicConstructionForAlreadyExists", ""));
       suite.addTest(new MDBUnitTestCase("testObjectMessage", "queue/testObjectMessage"));
       suite.addTest(new MDBUnitTestCase("testQueue", "queue/testQueue"));
+      suite.addTest(new MDBUnitTestCase("testMDBPropertySubstitution", "queue/testSubstitutionQueue"));
+      suite.addTest(new MDBUnitTestCase("testMDBPropertySubstitutionAutocreate", "queue/autocreate"));
       suite.addTest(new MDBUnitTestCase("testTopic", "topic/testTopic"));
       suite.addTest(new MDBUnitTestCase("testTopic", "topic/testDurableTopic"));
       suite.addTest(new MDBUnitTestCase("testQueue", "queue/ex"));
@@ -272,7 +311,7 @@
 
       Test wrapper = new JBossTestSetup(suite)
       {
-         
+
          ClassLoader loader = Thread.currentThread().getContextClassLoader();
 
          protected void setUp() throws Exception
@@ -280,6 +319,7 @@
             super.setUp();
             JMSDestinationsUtil.setupBasicDestinations();
             JMSDestinationsUtil.deployQueue("testObjectMessage");
+            deploy("mdb-substitution-system-properties-service.xml");
             deploy("mdb.jar");
          }
 
@@ -295,6 +335,14 @@
             {
                getLog().warn("Unable to undeploy mdb.jar", ignored);
             }
+            try
+            {
+               undeploy("mdb-substitution-system-properties-service.xml");
+            }
+            catch (Exception ignored)
+            {
+               getLog().warn("Unable to undeploy mdb-substitution-system-properties-service.xml", ignored);
+            }
             JMSDestinationsUtil.destroyDestinations();
             MDBUnitTestCase.undeployDestinations();
          }

Modified: branches/JBPAPP_5/testsuite/src/main/org/jboss/test/util/jms/JMSDestinationsUtil.java
===================================================================
--- branches/JBPAPP_5/testsuite/src/main/org/jboss/test/util/jms/JMSDestinationsUtil.java	2014-01-20 11:18:20 UTC (rev 114669)
+++ branches/JBPAPP_5/testsuite/src/main/org/jboss/test/util/jms/JMSDestinationsUtil.java	2014-01-20 12:56:16 UTC (rev 114670)
@@ -53,6 +53,11 @@
             new TestRole("publisher", true, true, true),
             new TestRole("durpublisher", true, true, true)});
       
+      admin.createQueue("testSubstitutionQueue", new TestRole[]{
+              new TestRole("guest", true, true, true),
+              new TestRole("publisher", true, true, true),
+              new TestRole("durpublisher", true, true, true)});
+      
       admin.createQueue("A", new TestRole("guest", true, true, true));
       admin.createQueue("B", new TestRole("guest", true, true, true));
       admin.createQueue("C", new TestRole("guest", true, true, true));

Added: branches/JBPAPP_5/testsuite/src/resources/mdb/autocreate/META-INF/jboss.xml
===================================================================
(Binary files differ)


Property changes on: branches/JBPAPP_5/testsuite/src/resources/mdb/autocreate/META-INF/jboss.xml
___________________________________________________________________
Added: svn:mime-type
   + application/xml

Added: branches/JBPAPP_5/testsuite/src/resources/mdb/mdb-substitution-system-properties-service.xml
===================================================================
(Binary files differ)


Property changes on: branches/JBPAPP_5/testsuite/src/resources/mdb/mdb-substitution-system-properties-service.xml
___________________________________________________________________
Added: svn:mime-type
   + application/xml



More information about the jboss-cvs-commits mailing list