[jboss-cvs] JBossAS SVN: r58448 - in trunk/ejb3: . src/test/org/jboss/ejb3/test src/test/org/jboss/ejb3/test/mdbtopic src/test/org/jboss/ejb3/test/mdbtopic/unit

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Nov 16 06:53:00 EST 2006


Author: wolfc
Date: 2006-11-16 06:52:53 -0500 (Thu, 16 Nov 2006)
New Revision: 58448

Added:
   trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtopic/
   trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtopic/TestStatus.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtopic/TestStatusBean.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtopic/TopicTestMDB.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtopic/unit/
   trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtopic/unit/TopicMDBUnitTestCase.java
Modified:
   trunk/ejb3/build-test.xml
Log:
simple topic MDB unit test

Modified: trunk/ejb3/build-test.xml
===================================================================
--- trunk/ejb3/build-test.xml	2006-11-16 11:52:06 UTC (rev 58447)
+++ trunk/ejb3/build-test.xml	2006-11-16 11:52:53 UTC (rev 58448)
@@ -2302,6 +2302,37 @@
       </copy>
    </target>
 
+   <target name="mdbtopic"
+      description="Builds all jar files."
+      depends="compile-classes">
+
+      <mkdir dir="${build.lib}"/>
+
+      <jar jarfile="${build.lib}/mdbtopic-test.jar">
+         <fileset dir="${build.classes}">
+            <include name="org/jboss/ejb3/test/mdbtopic/*.class"/>
+            <include name="org/jboss/ejb3/test/mdbtopic/unit/*.class"/>
+         </fileset>
+         <!--
+         <fileset dir="${resources}/test/mdb">
+            <include name="users.properties"/>
+            <include name="roles.properties"/>
+         </fileset>
+         <fileset dir="${resources}/test/mdb">
+            <include name="META-INF/*.xml"/>
+         </fileset>
+         -->
+      </jar>
+      
+      <!--
+      <copy todir="${build.lib}/embeddable/standalone">
+         <fileset dir="${build.lib}">
+            <include name="mdbtopic-test.jar"/>
+         </fileset>
+      </copy>
+      -->
+   </target>
+
    <target name="concurrent"
       description="Builds all jar files."
       depends="compile-classes">

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtopic/TestStatus.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtopic/TestStatus.java	2006-11-16 11:52:06 UTC (rev 58447)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtopic/TestStatus.java	2006-11-16 11:52:53 UTC (rev 58448)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, 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.mdbtopic;
+
+
+
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 58399 $
+ */
+public interface TestStatus
+{
+   void clear();
+
+   int queueFired();
+   
+   int overrideQueueFired();
+   
+   int nondurableQueueFired();
+   
+   int defaultedQueueFired();
+   
+   int overrideDefaultedQueueFired();
+
+   int topicFired();
+   
+   int bmtQueueRan();
+   
+   int cmtQueueRan();
+   
+   int messageCount();
+
+   boolean interceptedTopic();
+
+   boolean interceptedQueue();
+
+   boolean postConstruct();
+
+   boolean preDestroy();
+   
+}

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtopic/TestStatusBean.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtopic/TestStatusBean.java	2006-11-16 11:52:06 UTC (rev 58447)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtopic/TestStatusBean.java	2006-11-16 11:52:53 UTC (rev 58448)
@@ -0,0 +1,137 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, 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.mdbtopic;
+
+import javax.ejb.Stateless;
+import javax.ejb.Remote;
+
+import org.jboss.logging.Logger;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 58399 $
+ */
+ at Stateless
+ at Remote(TestStatus.class)
+public class TestStatusBean implements TestStatus
+{
+   @SuppressWarnings("unused")
+   private static final Logger log = Logger.getLogger(TestStatusBean.class);
+   
+   public static int queueRan = 0;
+   public static int overrideQueueRan = 0;
+   public static int defaultedQueueRan = 0;
+   public static int overrideDefaultedQueueRan = 0;
+   public static int nondurableQueueRan = 0;
+   public static int topicRan = 0;
+   public static int bmtQueueRan = 0;
+   static int cmtQueueRan = 0;
+   public static int messageCount = 0;
+   public static boolean interceptedTopic = false;
+   public static boolean interceptedQueue = false;
+   public static boolean postConstruct = false;
+   public static boolean preDestroy = false;
+
+   public void clear()
+   {
+      queueRan = 0;
+      topicRan = 0;
+      bmtQueueRan = 0;
+      cmtQueueRan = 0;
+      overrideQueueRan = 0;
+      defaultedQueueRan = 0;
+      overrideDefaultedQueueRan = 0;
+      messageCount = 0;
+      nondurableQueueRan = 0;
+      interceptedTopic = false;
+      interceptedQueue = false;
+      postConstruct = false;
+      preDestroy = false;
+   }
+
+   public int queueFired()
+   {
+      return queueRan;
+   }
+   
+   public int overrideQueueFired()
+   {
+      return overrideQueueRan;
+   }
+   
+   public int overrideDefaultedQueueFired()
+   {
+      return overrideDefaultedQueueRan;
+   }
+   
+   public int defaultedQueueFired()
+   {
+      return defaultedQueueRan;
+   }
+   
+   public int nondurableQueueFired()
+   {
+      return nondurableQueueRan;
+   }
+
+   public int topicFired()
+   {
+      return topicRan;
+   }
+   
+   public int bmtQueueRan()
+   {
+      return bmtQueueRan;
+   }
+
+   public int cmtQueueRan()
+   {
+      return cmtQueueRan;
+   }
+   
+   public boolean interceptedTopic()
+   {
+      return interceptedTopic;
+   }
+
+   public boolean interceptedQueue()
+   {
+      return interceptedQueue;
+   }
+
+   public boolean postConstruct()
+   {
+      return postConstruct;
+   }
+
+   public boolean preDestroy()
+   {
+      return preDestroy;
+   }
+   
+   public int messageCount()
+   {
+      return messageCount;
+   }
+}

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtopic/TopicTestMDB.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtopic/TopicTestMDB.java	2006-11-16 11:52:06 UTC (rev 58447)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtopic/TopicTestMDB.java	2006-11-16 11:52:53 UTC (rev 58448)
@@ -0,0 +1,62 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, 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.mdbtopic;
+
+import javax.annotation.Resource;
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.MessageDriven;
+import javax.ejb.MessageDrivenContext;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 1.11 $
+ */
+ at MessageDriven(activationConfig =
+        {
+        @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Topic"),
+        @ActivationConfigProperty(propertyName="destination", propertyValue="topic/mdbtest"),
+        @ActivationConfigProperty(propertyName="subscriptionDurability", propertyValue="Durable"),
+        @ActivationConfigProperty(propertyName="subscriptionName", propertyValue="topicmdb")
+        })
+public class TopicTestMDB implements MessageListener
+{
+   @Resource MessageDrivenContext ctx;
+   public void onMessage(Message recvMsg)
+   {
+      if (ctx == null) throw new RuntimeException("FAILED ON CTX LOOKUP");
+      TestStatusBean.topicRan++;
+      System.out.println("*** TopicTestMDB onMessage " + TestStatusBean.topicRan + " " + recvMsg);
+   }
+
+   @AroundInvoke
+   public Object intercept(InvocationContext ctx) throws Exception
+   {
+      TestStatusBean.interceptedTopic = true;
+      return ctx.proceed();
+   }
+}

Added: trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtopic/unit/TopicMDBUnitTestCase.java
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtopic/unit/TopicMDBUnitTestCase.java	2006-11-16 11:52:06 UTC (rev 58447)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/mdbtopic/unit/TopicMDBUnitTestCase.java	2006-11-16 11:52:53 UTC (rev 58448)
@@ -0,0 +1,127 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, 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.mdbtopic.unit;
+
+import javax.jms.MessageProducer;
+import javax.jms.QueueSession;
+import javax.jms.TextMessage;
+import javax.jms.Topic;
+import javax.jms.TopicConnection;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.TopicSession;
+import javax.naming.NamingException;
+
+import junit.framework.Test;
+
+import org.jboss.ejb3.test.mdbtopic.TestStatus;
+//import org.jboss.ejb3.test.mdb.TestStatus; // makes StackOverflowErrors
+import org.jboss.logging.Logger;
+import org.jboss.test.JBossTestCase;
+
+/**
+ * Sample client for the jboss container.
+ * 
+ * @author <a href="mailto:bill at burkecentral.com">Bill Burke</a>
+ * @version $Id: MDBUnitTestCase.java 58403 2006-11-15 17:14:37 +0100 (Wed, 15 Nov 2006) wolfc $
+ */
+public class TopicMDBUnitTestCase extends JBossTestCase
+{
+   @SuppressWarnings("unused")
+   private static final Logger log = Logger.getLogger(TopicMDBUnitTestCase.class);
+
+   static boolean deployed = false;
+
+   static int test = 0;
+
+   public TopicMDBUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testTopic() throws Exception
+   {
+      TestStatus status = (TestStatus) getInitialContext().lookup("TestStatusBean/remote");
+      clear(status);
+      TopicConnection cnn = null;
+      MessageProducer sender = null;
+      TopicSession session = null;
+
+      Topic topic = (Topic) getInitialContext().lookup("topic/mdbtest");
+      TopicConnectionFactory factory = getTopicConnectionFactory();
+      cnn = factory.createTopicConnection();
+      session = cnn.createTopicSession(false, QueueSession.AUTO_ACKNOWLEDGE);
+
+      TextMessage msg = session.createTextMessage("Hello World");
+
+      sender = session.createProducer(topic);
+      sender.send(msg);
+      session.close();
+      cnn.close();
+
+      Thread.sleep(2000);
+      assertEquals(1, status.topicFired());
+      assertTrue(status.interceptedTopic());
+      assertFalse(status.postConstruct());
+      assertFalse(status.preDestroy());
+   }
+
+   private TopicConnectionFactory getTopicConnectionFactory()
+         throws Exception
+   {
+      try
+      {
+         return (TopicConnectionFactory) getInitialContext().lookup("ConnectionFactory");
+      }
+      catch (NamingException e)
+      {
+         return (TopicConnectionFactory) getInitialContext().lookup("java:/ConnectionFactory");
+      }
+   }
+
+   private void clear(TestStatus status)
+   {
+      status.clear();
+      assertEquals(0, status.bmtQueueRan());
+      assertEquals(0, status.defaultedQueueFired());
+      assertEquals(0, status.messageCount());
+      assertEquals(0, status.nondurableQueueFired());
+      assertEquals(0, status.overrideDefaultedQueueFired());
+      assertEquals(0, status.overrideQueueFired());
+      assertEquals(0, status.queueFired());
+      assertEquals(0, status.topicFired());
+      assertFalse(status.interceptedQueue());
+      assertFalse(status.interceptedTopic());
+      assertFalse(status.postConstruct());
+      assertFalse(status.preDestroy());
+   }
+
+//   protected InitialContext getInitialContext() throws Exception
+//   {
+//      return InitialContextFactory.getInitialContext();
+//   }
+//
+   public static Test suite() throws Exception
+   {
+      return getDeploySetup(TopicMDBUnitTestCase.class, "mdbtopic-test.jar");
+   }
+
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list