[jbpm-commits] JBoss JBPM SVN: r6037 - in jbpm4/trunk/modules: test-base/src/main/java/org/jbpm/test and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Dec 23 10:18:08 EST 2009


Author: tom.baeyens at jboss.com
Date: 2009-12-23 10:18:07 -0500 (Wed, 23 Dec 2009)
New Revision: 6037

Modified:
   jbpm4/trunk/modules/devguide/src/main/docbook/en/modules/ch02-Incubation.xml
   jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/JbpmTestCase.java
   jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/JmsTopicListener.java
   jbpm4/trunk/modules/test-enterprise/test-enterprise-suite/src/test/java/org/jbpm/test/jms/QueueExceptionTest.java
   jbpm4/trunk/modules/test-enterprise/test-enterprise-suite/src/test/java/org/jbpm/test/jms/QueueMapMessageTest.java
   jbpm4/trunk/modules/test-enterprise/test-enterprise-suite/src/test/java/org/jbpm/test/jms/QueueObjectMessageTest.java
   jbpm4/trunk/modules/test-enterprise/test-enterprise-suite/src/test/java/org/jbpm/test/jms/QueueTextMessageTest.java
Log:
JBPM-2695 jms docs refinements

Modified: jbpm4/trunk/modules/devguide/src/main/docbook/en/modules/ch02-Incubation.xml
===================================================================
--- jbpm4/trunk/modules/devguide/src/main/docbook/en/modules/ch02-Incubation.xml	2009-12-23 15:17:13 UTC (rev 6036)
+++ jbpm4/trunk/modules/devguide/src/main/docbook/en/modules/ch02-Incubation.xml	2009-12-23 15:18:07 UTC (rev 6037)
@@ -953,18 +953,36 @@
             <entry>connection-factory</entry>
             <entry>jndi name</entry>
             <entry></entry>
-            <entry>true</entry>
-            <entry>the jndi name of the jms connection factory.  
+            <entry><emphasis role="bold">required</emphasis></entry>
+            <entry>the JNDI name of the jms connection factory.  
             </entry>
           </row>
           <row>
             <entry>destination</entry>
             <entry>jndi name</entry>
             <entry></entry>
+            <entry><emphasis role="bold">required</emphasis></entry>
+            <entry>the JNDI name of the jms queue or topic.  
+            </entry>
+          </row>
+          <row>
+            <entry>transacted</entry>
+            <entry>boolean: {true, false}</entry>
             <entry>true</entry>
-            <entry>the jndi name of the jms queue or topic.  
+            <entry>optional</entry>
+            <entry>Specifies if JMS message send should happen transactional.
+            @see QueueConnection.createQueueSession(boolean transactional, int acknowledgeMode)  
             </entry>
           </row>
+          <row>
+            <entry>acknowledge</entry>
+            <entry>{ auto | client | dups-ok }</entry>
+            <entry>auto</entry>
+            <entry>optional</entry>
+            <entry>Specifies the acknowledge mode
+            <ulink url="http://java.sun.com/javaee/5/docs/api/javax/jms/QueueConnection.html#createQueueSession(boolean,%20int)">@see QueueConnection.createQueueSession(boolean transactional, int acknowledgeMode)</ulink>  
+            </entry>
+          </row>
         </tbody>
       </tgroup>
     </table>
@@ -1042,13 +1060,17 @@
       <para>Following test helper methods are based solely on plain JMS apis and hence they work in 
       a standalone environment as well as in an appserver environment:</para>
       <itemizedlist>
-        <listitem>Object jmsConsumeMessageFromQueue(String connectionFactoryJndiName, String queueJndiName)</listitem>
-        <listitem>TODO jmsStartTopicListener(String connectionFactoryJndiName, String topicJndiName)</listitem>
-        <listitem>void jmsStopTopicListener(String connectionFactoryJndiName, String topicJndiName)</listitem>
+        <listitem>JbpmTestCase.jmsConsumeMessageFromQueue(String connectionFactoryJndiName, String queueJndiName)</listitem>
+        <listitem>JbpmTestCase.jmsConsumeMessageFromQueue(String connectionFactoryJndiName, String queueJndiName, boolean transacted, int acknowledgeMode, long timeout)</listitem>
+        <listitem>JbpmTestCase.jmsStartTopicListener(String connectionFactoryJndiName, String topicJndiName)</listitem>
+        <listitem>JbpmTestCase.jmsStartTopicListener(String connectionFactoryJndiName, String topicJndiName, boolean transacted, int acknowledgeMode)</listitem>
+        <listitem>JmsTopicListener.getNextMesssage(long timeout)</listitem>
+        <listitem>JmsTopicListener.stop()</listitem>
       </itemizedlist>
       <para>For example, after the process execution has executed the <literal>jms</literal> activity, 
       messages can be asserted like this:</para>
-      <programlisting>MapMessage mapMessage = (MapMessage) jmsConsumeMessageFromQueue(&quot;jms/ConnectionFactory&quot;, &quot;queue/ProductQueue&quot;);
+      <programlisting>MapMessage mapMessage = (MapMessage) 
+  jmsConsumeMessageFromQueue(&quot;java:/JmsXA&quot;, &quot;queue/ProductQueue&quot;);
 assertEquals(&quot;shampoo&quot;, mapMessage.getString(&quot;product&quot;));</programlisting>
       <para>The following jms helper methods are based on mockrunner and hence they only work in a standalone 
       environment:</para>
@@ -1062,32 +1084,30 @@
       <para>For example, a queue can be created and removed in the setup and tearDown methods of a test like this:</para>
       <programlisting>protected void setUp() throws Exception {
   super.setUp();
-  jmsCreateQueue(&quot;jms/ConnectionFactory&quot;, &quot;queue/ProductQueue&quot;);
+  jmsCreateQueue(&quot;java:/JmsXA&quot;, &quot;queue/ProductQueue&quot;);
 }
 
 protected void tearDown() throws Exception {
-  jmsRemoveQueue(&quot;jms/ConnectionFactory&quot;, &quot;queue/ProductQueue&quot;);
+  jmsRemoveQueue(&quot;java:/JmsXA&quot;, &quot;queue/ProductQueue&quot;);
   super.tearDown();
 }</programlisting>
     </section>
       
-    <section id="jms.text">
+    <section id="testmessages">
       <title>Text messages</title>
-      
       <para>
         The first possibility of sending JMS messages is to use text as its payload. In this case a JMS
         <literal>TextMessage</literal> will be created and sent to the specified destination.
         Consider the following process definition:
       </para>
-      
-      <programlisting>&lt;process name=&quot;JMS_text_queue&quot;&gt;
+      <programlisting>&lt;process name=&quot;JmsQueueText&quot;&gt;
 
   &lt;start&gt;
     &lt;transition to=&quot;send message&quot;/&gt;
   &lt;/start&gt;
 
   <emphasis role="bold">&lt;jms name=&quot;send message&quot;
-       connection-factory=&quot;ConnectionFactory&quot;
+       connection-factory=&quot;java:JmsXA&quot;
        destination=&quot;queue/jbpm-test-queue&quot;&gt;
     &lt;text&gt;This is the body&lt;/text&gt;
     &lt;transition to=&quot;wait&quot;/&gt;
@@ -1096,56 +1116,38 @@
   &lt;state name=&quot;wait&quot;/&gt;
 
 &lt;/process&gt;</programlisting>
-
       <para>
         As you may expect and as is shown in the following test case starting this process will cause
         the JMS node to send a message to the queue with the name &quot;queue/jbpm-test-queue&quot;.
-        The factory used to create a connection to connect to this queue is named &quot;ConnectionFactory&quot;.
+        The factory used to create a connection to connect to this queue is named &quot;java:JmsXA&quot;.
         The payload of the message is the text string &quot;This is the body&quot;.
       </para>
-      
-      <programlisting>public void testTextMessage() throws Exception {  
-  Context context = new InitialContext();
-  Connection connection = (Connection)context.lookup(&quot;ConnectionFactory&quot;);
-  connection.start();
-  Session session = connection.createSession(false, QueueSession.AUTO_ACKNOWLEDGE);
-  Queue queue = (Queue)context.lookup(&quot;queue/jbpm-test-queue&quot;);
-  MessageConsumer messageConsumer = session.createConsumer(queue);
-    
-  <emphasis role="bold">executionService.startProcessInstanceByKey(&quot;JMS_text_queue&quot;);
-  TextMessage textMessage = (TextMessage)messageConsumer.receive();
-  assertEquals(&quot;This is the body&quot;, textMessage.getText());</emphasis>
-   
-  connection.stop();
-  session.close();
-  connection.close();
-}</programlisting>
+      <programlisting>executionService.startProcessInstanceByKey("JmsQueueText");
 
+TextMessage textMessage = (TextMessage) 
+  jmsConsumeMessageFromQueue("java:JmsXA", "queue/jbpm-test-queue");
+assertEquals("This is the body", textMessage.getText());</programlisting>
       <para>
         The relevant code is shown above in boldface. The rest of the method is boilerplate code needed to
         setup a message consumer. We will omit this code in the subsequent examples.
       </para>
-
     </section>
     
-    <section id="jms.object">
-    
+    <section id="objectmessages">
       <title>Object messages</title>
-      
       <para>
         The second possibility is to use a serializable object as the payload of the message. In this case a
         JMS <literal>ObjectMessage</literal> will be created and sent to the specified destination.
         Consider the following process definition:
       </para>
+      <programlisting>&lt;process name=&quot;JmsQueueObject&quot;&gt;
 
-      <programlisting>&lt;process name=&quot;JMS_object_queue&quot;&gt;
-
   &lt;start&gt;
     &lt;transition to=&quot;send message&quot;/&gt;
   &lt;/start&gt;
 
   <emphasis role="bold">&lt;jms name=&quot;send message&quot;
-       connection-factory=&quot;ConnectionFactory&quot;
+       connection-factory=&quot;java:JmsXA&quot;
        destination=&quot;queue/jbpm-test-queue&quot;&gt;
     &lt;object expr=&quot;${object}&quot;/&gt;
     &lt;transition to=&quot;wait&quot;/&gt;
@@ -1154,48 +1156,36 @@
   &lt;state name=&quot;wait&quot;/&gt;
 
 &lt;/process&gt;</programlisting>
-    
       <para>
         As in the previous case a message will be sent to the queue with the name &quot;queue/jbpm-test-queue&quot;.
-        Also again a factory used to create a connection to connect to this queue is named &quot;ConnectionFactory&quot;.
+        Also again a factory used to create a connection to connect to this queue is named &quot;java:JmsXA&quot;.
         But in this case the payload of the message is the serializable object that is obtained by 
         evaluating the expression specified by the <literal>expr</literal> attribute. This is illustrated in the test case below.
       </para>
-      
-      <programlisting>public void testQueueMessage() throws Exception 
-{  
-  // as before
-  ...  
-  <emphasis role="bold">Map&lt;String, Object&gt; variables = new HashMap&lt;String, Object&gt;();
-  variables.put(&quot;object&quot;, &quot;this is the object&quot;);
-  executionService.startProcessInstanceByKey(&quot;JMS_object_queue&quot;, variables);
-  ObjectMessage objectMessage = (ObjectMessage)messageConsumer.receive();
-  assertEquals(&quot;this is the object&quot;, objectMessage.getObject());</emphasis>
-  
-  // as before
-  ...
-}</programlisting>
+      <programlisting>Map&lt;String, Object&gt; variables = new HashMap&lt;String, Object&gt;();
+variables.put(&quot;object&quot;, &quot;this is the object&quot;);
+executionService.startProcessInstanceByKey(&quot;JmsQueueObject&quot;, variables);
 
+ObjectMessage objectMessage = (ObjectMessage) 
+  jmsConsumeMessageFromQueue(&quot;java:JmsXA&quot;, &quot;queue/jbpm-test-queue&quot;);
+assertEquals(&quot;this is the object&quot;, objectMessage.getObject());</programlisting>
     </section>
     
-    <section id="jms.map">
-    
+    <section id="mapmessages">
       <title>Map messages</title>
-      
       <para>
         In this third possibility the payload is constituted by the key-value entries of a map. This time a
         JMS <literal>MapMessage</literal> will be created and sent to the specified destination.
         Consider the following process definition:
       </para>
+      <programlisting>&lt;process name=&quot;JmsQueueMap&quot;&gt;
 
-      <programlisting>&lt;process name=&quot;JMS_map_queue&quot;&gt;
-
   &lt;start&gt;
     &lt;transition to=&quot;send message&quot;/&gt;
   &lt;/start&gt;
 
   <emphasis role="bold">&lt;jms name=&quot;send message&quot;
-       connection-factory=&quot;ConnectionFactory&quot;
+       connection-factory=&quot;java:JmsXA&quot;
        destination=&quot;queue/jbpm-test-queue&quot;&gt;
     &lt;map&gt;
       &lt;entry&gt;
@@ -1209,27 +1199,18 @@
   &lt;state name=&quot;wait&quot;/&gt;
 
 &lt;/process&gt;</programlisting>
-
       <para>
         Again a message will be sent to the queue with the name &quot;queue/jbpm-test-queue&quot; and the 
-        factory used to create a connection to connect to this queue is named &quot;ConnectionFactory&quot;.
+        factory used to create a connection to connect to this queue is named &quot;java:JmsXA&quot;.
         In this case the payload of the message are the specified key-value pairs of the map. 
         It is illustrated in the test case below.
       </para>
-      
-      <programlisting>public void testMapMessage() throws Exception 
-{  
-  // as before
-  ...  
-  <emphasis role="bold">executionService.startProcessInstanceByKey(&quot;JMS_map_queue&quot;);
-  MapMessage mapMessage = (MapMessage)messageConsumer.receive();
-  assertTrue(mapMessage.itemExists(&quot;x&quot;));
-  assertEquals(&quot;foo&quot;, mapMessage.getObject(&quot;x&quot;));</emphasis>
-  
-  // as before
-  ...
-}</programlisting>
+      <programlisting>executionService.startProcessInstanceByKey("JmsQueueMap");
 
+MapMessage mapMessage = (MapMessage) 
+  jmsConsumeMessageFromQueue("java:JmsXA", "queue/jbpm-test-queue");
+assertTrue(mapMessage.itemExists("x"));
+assertEquals("foo", mapMessage.getObject("x"));</programlisting>
     </section>
     
   </section>  

Modified: jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/JbpmTestCase.java
===================================================================
--- jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/JbpmTestCase.java	2009-12-23 15:17:13 UTC (rev 6036)
+++ jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/JbpmTestCase.java	2009-12-23 15:18:07 UTC (rev 6037)
@@ -135,9 +135,13 @@
   }
 
   public static JmsTopicListener jmsStartTopicListener(String connectionFactoryJndiName, String topicJndiName) {
-    return new JmsTopicListener(connectionFactoryJndiName, topicJndiName);
+    return jmsStartTopicListener(connectionFactoryJndiName, topicJndiName, true, 1);
   }
 
+  public static JmsTopicListener jmsStartTopicListener(String connectionFactoryJndiName, String topicJndiName, boolean transacted, int acknowledgeMode) {
+    return new JmsTopicListener(connectionFactoryJndiName, topicJndiName, transacted, acknowledgeMode);
+  }
+
   public static void jmsRemoveTopic(String connectionFactoryJndiName, String topicJndiName) {
     JmsExtensions.removeTopic(connectionFactoryJndiName, topicJndiName);
   }

Modified: jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/JmsTopicListener.java
===================================================================
--- jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/JmsTopicListener.java	2009-12-23 15:17:13 UTC (rev 6036)
+++ jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/JmsTopicListener.java	2009-12-23 15:18:07 UTC (rev 6037)
@@ -29,7 +29,6 @@
 
 import javax.jms.Message;
 import javax.jms.MessageListener;
-import javax.jms.QueueSession;
 import javax.jms.Topic;
 import javax.jms.TopicConnection;
 import javax.jms.TopicConnectionFactory;
@@ -52,6 +51,9 @@
   static Map<Object, JmsTopicListener> topicListeners = new HashMap<Object, JmsTopicListener>();
   
   String topicJndiName = null;
+  String connectionFactoryJndiName = null;
+  boolean transacted;
+  int acknowledgeMode;
   TopicConnectionFactory topicConnectionFactory = null;
   Topic topic = null;
   TopicConnection topicConnection = null;
@@ -71,21 +73,24 @@
     return topicListeners.get(createJmsTopicListenerKey(connectionFactoryJndiName, topicJndiName));
   }
 
-  JmsTopicListener(String connectionFactoryJndiName, String topicJndiName) {
-    start(connectionFactoryJndiName, topicJndiName);
+  JmsTopicListener(String connectionFactoryJndiName, String topicJndiName, boolean transacted, int acknowledgeMode) {
+    this.connectionFactoryJndiName = connectionFactoryJndiName;
+    this.topicJndiName = topicJndiName;
+    this.transacted = transacted;
+    this.acknowledgeMode = acknowledgeMode;
     topicListeners.put(createJmsTopicListenerKey(connectionFactoryJndiName, topicJndiName), this);
+    start();
   }
 
-  void start(String connectionFactoryJndiName, String topicJndiName) {
+  void start() {
     try {
       messages = Collections.synchronizedList(new ArrayList<Message>());
-      this.topicJndiName = topicJndiName;
 
       InitialContext context = new InitialContext();
       topicConnectionFactory = (TopicConnectionFactory) context.lookup(connectionFactoryJndiName);
       topic = (Topic) context.lookup(topicJndiName);
       topicConnection = topicConnectionFactory.createTopicConnection();
-      topicSession = topicConnection.createTopicSession(true, QueueSession.AUTO_ACKNOWLEDGE);
+      topicSession = topicConnection.createTopicSession(transacted, acknowledgeMode);
       topicSubscriber = topicSession.createSubscriber(topic);
       topicSubscriber.setMessageListener(new Listener());
 

Modified: jbpm4/trunk/modules/test-enterprise/test-enterprise-suite/src/test/java/org/jbpm/test/jms/QueueExceptionTest.java
===================================================================
--- jbpm4/trunk/modules/test-enterprise/test-enterprise-suite/src/test/java/org/jbpm/test/jms/QueueExceptionTest.java	2009-12-23 15:17:13 UTC (rev 6036)
+++ jbpm4/trunk/modules/test-enterprise/test-enterprise-suite/src/test/java/org/jbpm/test/jms/QueueExceptionTest.java	2009-12-23 15:18:07 UTC (rev 6037)
@@ -45,7 +45,7 @@
         .deploy());  
   }
   
-  public void testQueueMessage() throws Exception {
+  public void testQueueMessageException() throws Exception {
     try {
       executionService.startProcessInstanceByKey("JmsQueueException");
       fail("expected exception");

Modified: jbpm4/trunk/modules/test-enterprise/test-enterprise-suite/src/test/java/org/jbpm/test/jms/QueueMapMessageTest.java
===================================================================
--- jbpm4/trunk/modules/test-enterprise/test-enterprise-suite/src/test/java/org/jbpm/test/jms/QueueMapMessageTest.java	2009-12-23 15:17:13 UTC (rev 6036)
+++ jbpm4/trunk/modules/test-enterprise/test-enterprise-suite/src/test/java/org/jbpm/test/jms/QueueMapMessageTest.java	2009-12-23 15:18:07 UTC (rev 6037)
@@ -42,7 +42,7 @@
     registerDeployment(repositoryService.createDeployment().addResourceFromClasspath("org/jbpm/test/jms/queue.map.process.jpdl.xml").deploy());
   }
 
-  public void testJmsText() throws Exception {
+  public void testQueueMapMessage() throws Exception {
     executionService.startProcessInstanceByKey("JmsQueueMap");
     MapMessage mapMessage = (MapMessage) jmsConsumeMessageFromQueue("java:JmsXA", "queue/jbpm-test-queue");
     assertTrue(mapMessage.itemExists("x"));

Modified: jbpm4/trunk/modules/test-enterprise/test-enterprise-suite/src/test/java/org/jbpm/test/jms/QueueObjectMessageTest.java
===================================================================
--- jbpm4/trunk/modules/test-enterprise/test-enterprise-suite/src/test/java/org/jbpm/test/jms/QueueObjectMessageTest.java	2009-12-23 15:17:13 UTC (rev 6036)
+++ jbpm4/trunk/modules/test-enterprise/test-enterprise-suite/src/test/java/org/jbpm/test/jms/QueueObjectMessageTest.java	2009-12-23 15:18:07 UTC (rev 6037)
@@ -47,7 +47,7 @@
         .deploy());
   }
 
-  public void testQueueMessage() throws Exception {
+  public void testQueueObjectMessage() throws Exception {
     Map<String, Object> variables = new HashMap<String, Object>();
     variables.put("object", "this is the object");
     executionService.startProcessInstanceByKey("JmsQueueObject", variables);

Modified: jbpm4/trunk/modules/test-enterprise/test-enterprise-suite/src/test/java/org/jbpm/test/jms/QueueTextMessageTest.java
===================================================================
--- jbpm4/trunk/modules/test-enterprise/test-enterprise-suite/src/test/java/org/jbpm/test/jms/QueueTextMessageTest.java	2009-12-23 15:17:13 UTC (rev 6036)
+++ jbpm4/trunk/modules/test-enterprise/test-enterprise-suite/src/test/java/org/jbpm/test/jms/QueueTextMessageTest.java	2009-12-23 15:18:07 UTC (rev 6037)
@@ -43,7 +43,7 @@
         .deploy());  
   }
   
-  public void testQueueMessage() throws Exception {
+  public void testQueueTextMessage() throws Exception {
     executionService.startProcessInstanceByKey("JmsQueueText");
     TextMessage textMessage = (TextMessage) jmsConsumeMessageFromQueue("java:JmsXA", "queue/jbpm-test-queue");
     assertEquals("This is the body", textMessage.getText());



More information about the jbpm-commits mailing list