[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("jms/ConnectionFactory", "queue/ProductQueue");
+ <programlisting>MapMessage mapMessage = (MapMessage)
+ jmsConsumeMessageFromQueue("java:/JmsXA", "queue/ProductQueue");
assertEquals("shampoo", mapMessage.getString("product"));</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("jms/ConnectionFactory", "queue/ProductQueue");
+ jmsCreateQueue("java:/JmsXA", "queue/ProductQueue");
}
protected void tearDown() throws Exception {
- jmsRemoveQueue("jms/ConnectionFactory", "queue/ProductQueue");
+ jmsRemoveQueue("java:/JmsXA", "queue/ProductQueue");
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><process name="JMS_text_queue">
+ <programlisting><process name="JmsQueueText">
<start>
<transition to="send message"/>
</start>
<emphasis role="bold"><jms name="send message"
- connection-factory="ConnectionFactory"
+ connection-factory="java:JmsXA"
destination="queue/jbpm-test-queue">
<text>This is the body</text>
<transition to="wait"/>
@@ -1096,56 +1116,38 @@
<state name="wait"/>
</process></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 "queue/jbpm-test-queue".
- The factory used to create a connection to connect to this queue is named "ConnectionFactory".
+ The factory used to create a connection to connect to this queue is named "java:JmsXA".
The payload of the message is the text string "This is the body".
</para>
-
- <programlisting>public void testTextMessage() throws Exception {
- Context context = new InitialContext();
- Connection connection = (Connection)context.lookup("ConnectionFactory");
- connection.start();
- Session session = connection.createSession(false, QueueSession.AUTO_ACKNOWLEDGE);
- Queue queue = (Queue)context.lookup("queue/jbpm-test-queue");
- MessageConsumer messageConsumer = session.createConsumer(queue);
-
- <emphasis role="bold">executionService.startProcessInstanceByKey("JMS_text_queue");
- TextMessage textMessage = (TextMessage)messageConsumer.receive();
- assertEquals("This is the body", 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><process name="JmsQueueObject">
- <programlisting><process name="JMS_object_queue">
-
<start>
<transition to="send message"/>
</start>
<emphasis role="bold"><jms name="send message"
- connection-factory="ConnectionFactory"
+ connection-factory="java:JmsXA"
destination="queue/jbpm-test-queue">
<object expr="${object}"/>
<transition to="wait"/>
@@ -1154,48 +1156,36 @@
<state name="wait"/>
</process></programlisting>
-
<para>
As in the previous case a message will be sent to the queue with the name "queue/jbpm-test-queue".
- Also again a factory used to create a connection to connect to this queue is named "ConnectionFactory".
+ Also again a factory used to create a connection to connect to this queue is named "java:JmsXA".
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<String, Object> variables = new HashMap<String, Object>();
- variables.put("object", "this is the object");
- executionService.startProcessInstanceByKey("JMS_object_queue", variables);
- ObjectMessage objectMessage = (ObjectMessage)messageConsumer.receive();
- assertEquals("this is the object", objectMessage.getObject());</emphasis>
-
- // as before
- ...
-}</programlisting>
+ <programlisting>Map<String, Object> variables = new HashMap<String, Object>();
+variables.put("object", "this is the object");
+executionService.startProcessInstanceByKey("JmsQueueObject", variables);
+ObjectMessage objectMessage = (ObjectMessage)
+ jmsConsumeMessageFromQueue("java:JmsXA", "queue/jbpm-test-queue");
+assertEquals("this is the object", 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><process name="JmsQueueMap">
- <programlisting><process name="JMS_map_queue">
-
<start>
<transition to="send message"/>
</start>
<emphasis role="bold"><jms name="send message"
- connection-factory="ConnectionFactory"
+ connection-factory="java:JmsXA"
destination="queue/jbpm-test-queue">
<map>
<entry>
@@ -1209,27 +1199,18 @@
<state name="wait"/>
</process></programlisting>
-
<para>
Again a message will be sent to the queue with the name "queue/jbpm-test-queue" and the
- factory used to create a connection to connect to this queue is named "ConnectionFactory".
+ factory used to create a connection to connect to this queue is named "java:JmsXA".
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("JMS_map_queue");
- MapMessage mapMessage = (MapMessage)messageConsumer.receive();
- assertTrue(mapMessage.itemExists("x"));
- assertEquals("foo", mapMessage.getObject("x"));</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