.
+ */
+
+package jms.conform.message.headers;
+
+import javax.jms.DeliveryMode;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.Queue;
+import javax.jms.TemporaryQueue;
+
+import org.junit.jupiter.api.Test;
+
+import jms.admin.Admin;
+import jms.framework.PTPTestCase;
+import jms.framework.TestConfig;
+
+
+/**
+ * Test the headers of a message
+ */
+public class MessageHeaderTest extends PTPTestCase {
+
+ /**
+ * Test that the MessageProducer.setPriority()
changes
+ * effectively priority of the message.
+ */
+ @Test
+ public void testJMSPriority_2() {
+ try {
+ Message message = senderSession.createMessage();
+ sender.send(message);
+ sender.setPriority(9);
+ sender.send(message);
+ assertEquals(
+ "3.4.9 After completion of the send it holds the value specified by the "
+ + "method sending the message.\n", 9, message.getJMSPriority());
+
+ Message msg = receiver.receive(TestConfig.TIMEOUT);
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test that the priority set by Message.setJMSPriority()
is
+ * ignored when a message is sent and that it holds the value specified when
+ * sending the message (i.e. Message.DEFAULT_PRIORITY
in this
+ * test).
+ */
+ @Test
+ public void testJMSPriority_1() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setJMSPriority(0);
+ sender.send(message);
+ assertTrue("3.4.9 When a message is sent this value is ignored.\n",
+ message.getJMSPriority() != 0);
+ assertEquals(
+ "3.4.9 After completion of the send it holds the value specified by the "
+ + "method sending the message.\n", Message.DEFAULT_PRIORITY,
+ message.getJMSPriority());
+
+ Message msg = receiver.receive(TestConfig.TIMEOUT);
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test that the value of the
+ * JMSExpiration header field is the same
+ * for the sent message and the received one.
+ */
+ @Test
+ public void testJMSExpiration() {
+ try {
+ Message message = senderSession.createMessage();
+ sender.send(message);
+
+ Message msg = receiver.receive(TestConfig.TIMEOUT);
+ assertEquals(
+ "3.4.9 When a message is received its JMSExpiration header field contains this same "
+ + "value [i.e. set on return of the send method].\n", message
+ .getJMSExpiration(), msg.getJMSExpiration());
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test that the JMSMessageID
is set by the provider when the
+ * send
method returns and that it starts with
+ * "ID:"
.
+ */
+ @Test
+ public void testJMSMessageID_2() {
+ try {
+ Message message = senderSession.createMessage();
+ sender.send(message);
+ assertTrue(
+ "3.4.3 When the send method returns it contains a provider-assigned value.\n",
+ message.getJMSMessageID() != null);
+ assertTrue(
+ "3.4.3 All JMSMessageID values must start with the prefix 'ID:'.\n",
+ message.getJMSMessageID().startsWith("ID:"));
+
+ Message msg = receiver.receive(TestConfig.TIMEOUT);
+ assertTrue(
+ "3.4.3 All JMSMessageID values must start with the prefix 'ID:'.\n",
+ msg.getJMSMessageID().startsWith("ID:"));
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test that the JMSMessageID
header field value is ignored
+ * when the message is sent.
+ */
+ @Test
+ public void testJMSMessageID_1() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setJMSMessageID("ID:foo");
+ sender.send(message);
+ assertTrue("3.4.3 When a message is sent this value is ignored.\n",
+ message.getJMSMessageID() != "ID:foo");
+ Message msg = receiver.receive(TestConfig.TIMEOUT);
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test that the JMSDeliveryMode
header field value is ignored
+ * when the message is sent and that it holds the value specified by the
+ * sending method (i.e. Message.DEFAULT_DELIVERY_MODE
in this
+ * test when the message is received.
+ */
+ @Test
+ public void testJMSDeliveryMode() {
+ try {
+ // sender has been created with the DEFAULT_DELIVERY_MODE which is
+ // PERSISTENT
+ assertEquals(DeliveryMode.PERSISTENT, sender.getDeliveryMode());
+ Message message = senderSession.createMessage();
+ // send a message specfiying NON_PERSISTENT for the JMSDeliveryMode header
+ // field
+ message.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
+ sender.send(message);
+ assertTrue("3.4.2 When a message is sent this value is ignored", message
+ .getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT);
+ assertEquals(
+ "3.4.2 After completion of the send it holds the delivery mode specified "
+ + "by the sending method (persistent by default).\n",
+ Message.DEFAULT_DELIVERY_MODE, message.getJMSDeliveryMode());
+
+ Message msg = receiver.receive(TestConfig.TIMEOUT);
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test that the JMSDestination
header field value is ignored
+ * when the message is sent and that after completion of the sending method,
+ * it holds the Destination
specified by the sending method.
+ * Also test that the value of the header on the received message is the same
+ * that on the sent message.
+ */
+ @Test
+ public void testJMSDestination() {
+ try {
+ Admin admin = getJoramAdmin();
+ admin.createQueue("anotherQueue");
+ Queue anotherQueue = admin.createQueue("anotherQueue");
+ assertTrue(anotherQueue != senderQueue);
+
+ // set the JMSDestination header field to the anotherQueue Destination
+ Message message = senderSession.createMessage();
+ message.setJMSDestination(anotherQueue);
+ sender.send(message);
+ assertTrue("3.4.1 When a message is sent this value is ignored.\n",
+ message.getJMSDestination() != anotherQueue);
+ assertEquals(
+ "3.4.1 After completion of the send it holds the destination object specified "
+ + "by the sending method.\n", senderQueue, message
+ .getJMSDestination());
+
+ Message msg = receiver.receive(TestConfig.TIMEOUT);
+ assertEquals(
+ "3.4.1 When a message is received, its destination value must be equivalent "
+ + " to the value assigned when it was sent.\n", ((Queue) message
+ .getJMSDestination()).getQueueName(), ((Queue) msg
+ .getJMSDestination()).getQueueName());
+
+ admin.deleteQueue(anotherQueue);
+ } catch (Exception e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test that a Destination
set by the
+ * setJMSReplyTo()
method on a sended message corresponds to
+ * the Destination
get by the
getJMSReplyTo()
+ * method.
+ */
+ @Test
+ public void testJMSReplyTo_1() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setJMSReplyTo(senderQueue);
+ sender.send(message);
+
+ Message msg = receiver.receive(TestConfig.TIMEOUT);
+ Destination dest = msg.getJMSDestination();//getJMSReplyTo();
+ assertTrue("JMS ReplyTo header field should be a Queue",
+ dest instanceof Queue);
+ Queue replyTo = (Queue) dest;
+ assertEquals(
+ "JMS ReplyTo header field should be equals to the sender queue",
+ ((Queue) replyTo).getQueueName(),
+ ((Queue) senderQueue).getQueueName());
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test that if the JMS ReplyTo header field has been set as a
+ * TemporaryQueue
, it will be rightly get also as a
+ * TemporaryQueue
(and not only as a Queue
).
+ */
+ @Test
+ public void testJMSReplyTo_2() {
+ try {
+ TemporaryQueue tempQueue = senderSession.createTemporaryQueue();
+ Message message = senderSession.createMessage();
+ message.setJMSReplyTo(tempQueue);
+ sender.send(message);
+
+ Message msg = receiver.receive(TestConfig.TIMEOUT);
+ Destination dest = msg.getJMSReplyTo();
+ assertTrue("JMS ReplyTo header field should be a TemporaryQueue",
+ dest instanceof TemporaryQueue);
+ Queue replyTo = (Queue) dest;
+ assertEquals(
+ "JMS ReplyTo header field should be equals to the temporary queue",
+ ((Queue) replyTo).getQueueName(), ((Queue) tempQueue).getQueueName());
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/conform/message/properties/JMSXPropertyTest.java b/joram/joram/client/jms/src/test/java/jms/conform/message/properties/JMSXPropertyTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..eaa3d4dc6339c2fa6c805643941b7564698bacde
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/conform/message/properties/JMSXPropertyTest.java
@@ -0,0 +1,197 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2002 - 2007 ScalAgent Distributed Technologies
+ * Copyright (C) 2002 INRIA
+ * Contact: joram-team@objectweb.org
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s): Jeff Mesnil (Inria)
+ * Contributor(s): Nicolas Tachker (ScalAgent D.T.)
+ */
+
+package jms.conform.message.properties;
+
+import java.util.Enumeration;
+
+import javax.jms.ConnectionMetaData;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.TextMessage;
+
+import org.junit.jupiter.api.Test;
+
+import jms.framework.PTPTestCase;
+import jms.framework.TestConfig;
+
+
+/**
+ * Test the JMSX defined properties.
+ * See JMS Specification, 3.5.9 JMS Defined Properties
+ */
+public class JMSXPropertyTest extends PTPTestCase {
+
+ /**
+ * Test that the JMSX property JMSXGroupID
is supported.
+ */
+ @Test
+ public void testSupportsJMSXGroupID() {
+ try {
+ boolean found = false;
+ ConnectionMetaData metaData = senderConnection.getMetaData();
+ Enumeration e = metaData.getJMSXPropertyNames();
+ while (e.hasMoreElements()) {
+ String jmsxPropertyName = (String) e.nextElement();
+ if (jmsxPropertyName.equals("JMSXGroupID")) {
+ found = true;
+ }
+ }
+ assertTrue("JMSXGroupID property is not supported", found);
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test that the JMSX property JMSXGroupID
works
+ */
+ @Test
+ public void testJMSXGroupID_1() {
+ try {
+ String groupID = "testSupportsJMSXGroupID_1:group";
+ TextMessage message = senderSession.createTextMessage();
+ message.setStringProperty("JMSXGroupID", groupID);
+ message.setText("testSupportsJMSXGroupID_1");
+ sender.send(message);
+
+ Message m = receiver.receive(TestConfig.TIMEOUT);
+ assertTrue(m instanceof TextMessage);
+ TextMessage msg = (TextMessage) m;
+ assertEquals(groupID, msg.getStringProperty("JMSXGroupID"));
+ assertEquals("testSupportsJMSXGroupID_1", msg.getText());
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test that the JMSX property JMSXGroupSeq
is supported.
+ */
+ @Test
+ public void testSupportsJMSXGroupSeq() {
+ try {
+ boolean found = false;
+ ConnectionMetaData metaData = senderConnection.getMetaData();
+ Enumeration e = metaData.getJMSXPropertyNames();
+ while (e.hasMoreElements()) {
+ String jmsxPropertyName = (String) e.nextElement();
+ if (jmsxPropertyName.equals("JMSXGroupSeq")) {
+ found = true;
+ }
+ }
+ assertTrue("JMSXGroupSeq property is not supported", found);
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test that the JMSX property JMSXDeliveryCount
is supported.
+ */
+ @Test
+ public void testSupportsJMSXDeliveryCount() {
+ try {
+ boolean found = false;
+ ConnectionMetaData metaData = senderConnection.getMetaData();
+ Enumeration e = metaData.getJMSXPropertyNames();
+ while (e.hasMoreElements()) {
+ String jmsxPropertyName = (String) e.nextElement();
+ if (jmsxPropertyName.equals("JMSXDeliveryCount")) {
+ found = true;
+ }
+ }
+ assertTrue("JMSXDeliveryCount property is not supported", found);
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test that the JMSX property JMSXDeliveryCount
works.
+ */
+ @Test
+ public void testJMSXDeliveryCount() {
+ try {
+ senderConnection.stop();
+ // senderSession has been created as non transacted
+ // we create it again but as a transacted session
+ senderSession = senderConnection.createQueueSession(true, 0);
+ assertEquals(true, senderSession.getTransacted());
+ // we create again the sender
+ sender = senderSession.createSender(senderQueue);
+ senderConnection.start();
+
+ receiverConnection.stop();
+ // receiverSession has been created as non transacted
+ // we create it again but as a transacted session
+ receiverSession = receiverConnection.createQueueSession(true, 0);
+ assertEquals(true, receiverSession.getTransacted());
+ // we create again the receiver
+ receiver = receiverSession.createReceiver(receiverQueue);
+ receiverConnection.start();
+
+ // we send a message...
+ TextMessage message = senderSession.createTextMessage();
+ message.setText("testJMSXDeliveryCount");
+ sender.send(message);
+ // ... and commit the *producer* transaction
+ senderSession.commit();
+
+ // we receive a message...
+ Message m = receiver.receive(TestConfig.TIMEOUT);
+ assertTrue(m != null);
+ assertTrue(m instanceof TextMessage);
+ TextMessage msg = (TextMessage) m;
+ // ... which is the one which was sent...
+ assertEquals("testJMSXDeliveryCount", msg.getText());
+ // ...and has not been redelivered
+ assertEquals(false, msg.getJMSRedelivered());
+ // ... so it has been delivered once
+ int jmsxDeliveryCount = msg.getIntProperty("JMSXDeliveryCount");
+ assertEquals(1, jmsxDeliveryCount);
+ // we rollback the *consumer* transaction
+ receiverSession.rollback();
+
+ // we receive again a message
+ m = receiver.receive(TestConfig.TIMEOUT);
+ assertTrue(m != null);
+ assertTrue(m instanceof TextMessage);
+ msg = (TextMessage) m;
+ // ... which is still the one which was sent...
+ assertEquals("testJMSXDeliveryCount", msg.getText());
+ // .. but this time, it has been redelivered
+ assertEquals(true, msg.getJMSRedelivered());
+ // ... so it has been delivered a second time
+ jmsxDeliveryCount = msg.getIntProperty("JMSXDeliveryCount");
+ assertEquals(2, jmsxDeliveryCount);
+ } catch (JMSException e) {
+ fail(e);
+ } catch (Exception e) {
+ fail(e);
+ }
+ }
+
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/conform/message/properties/MessagePropertyConversionTest.java b/joram/joram/client/jms/src/test/java/jms/conform/message/properties/MessagePropertyConversionTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..09c7c416c071d01c4a1566e7f93ed1900964654b
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/conform/message/properties/MessagePropertyConversionTest.java
@@ -0,0 +1,1282 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2002 - 2007 ScalAgent Distributed Technologies
+ * Copyright (C) 2002 INRIA
+ * Contact: joram-team@objectweb.org
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s): Jeff Mesnil (Inria)
+ * Contributor(s): Nicolas Tachker (ScalAgent D.T.)
+ */
+
+package jms.conform.message.properties;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageFormatException;
+
+import org.junit.jupiter.api.Test;
+
+import jms.framework.PTPTestCase;
+
+
+/**
+ * Test the conversion of primitive types for the javax.jms.Message
+ * properties.
+ * See JMS Specification, 3.5.4 Property Value Conversion and the corresponding
+ * table (p.33-34).
+ * The method name testXXX2YYY
means that we test if a property
+ * which has been set as a XXX
type can be read as a
+ * YYY
type, where XXX
and YYY
can
+ * be boolean, byte, short, long, float
+ * double
or
+ * String
.
+ *
+ *
+ * ---------------------------------------------------------------|
+ * | boolean | byte | short | int | long | float | double | String|
+ * |-----------------------------------------------------------------------|
+ * |boolean | X X |
+ * |byte | X X X X X |
+ * |short | X X X X |
+ * |int | X X X |
+ * |long | X X |
+ * |float | X X X |
+ * |double | X X |
+ * |String | Y Y Y Y Y Y Y X |
+ * |-----------------------------------------------------------------------|
+ *
+ *
+ * A value set as the row type can be read as the column type.
+ * The unmarked cases must throw a javax.jms.MessageFormatException
+ *
+ * The cases marked with a Y should throw a
+ * java.lang.MessageFormatException
if the
+ * String is not a correct representation of the column type (otherwise, it
+ * returns the property).
+ */
+public class MessagePropertyConversionTest extends PTPTestCase {
+
+ /**
+ * if a property is set as a java.lang.String
, it can also be
+ * read as a java.lang.String
.
+ */
+ @Test
+ public void testString2String() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setStringProperty("pi", "3.14159");
+ assertEquals("3.14159", message.getStringProperty("pi"));
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a java.lang.String
, to get it as a
+ * double
throws a java.lang.NuberFormatException
+ * if the String
is not a correct representation for a
+ * double
(e.g. "not a number"
).
+ */
+ @Test
+ public void testString2Double_2() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setStringProperty("pi", "not_a_number");
+ message.getDoubleProperty("pi");
+ fail("3.5.4 The String to numeric conversions must throw the java.lang.NumberFormatException "
+ + " if the numeric's valueOf() method does not accept the String value as a valid representation.\n");
+ } catch (java.lang.NumberFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a java.lang.String
, it can also be
+ * read as a double
as long as the String
is a
+ * correct representation of a double
(e.g.
+ * "3.14159"
).
+ */
+ @Test
+ public void testString2Double_1() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setStringProperty("pi", "3.14159");
+ assertEquals(3.14159, message.getDoubleProperty("pi"), 0);
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a java.lang.String
, to get it as a
+ * float
throws a java.lang.NuberFormatException
+ * if the String
is not a correct representation for a
+ * float
(e.g. "not_a_number"
).
+ */
+ @Test
+ public void testString2Float_2() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setStringProperty("pi", "not_a_number");
+ message.getFloatProperty("pi");
+ fail("3.5.4 The String to numeric conversions must throw the java.lang.NumberFormatException "
+ + " if the numeric's valueOf() method does not accept the String value as a valid representation.\n");
+ } catch (java.lang.NumberFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a java.lang.String
, it can also be
+ * read as a float
as long as the String
is a
+ * correct representation of a float
(e.g.
+ * "3.14159"
).
+ */
+ @Test
+ public void testString2Float_1() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setStringProperty("pi", "3.14159");
+ assertEquals(3.14159F, message.getFloatProperty("pi"), 0);
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a java.lang.String
, to get it as a
+ * long
throws a java.lang.NuberFormatException
+ * if the String
is not a correct representation for a
+ * long
(e.g. "3.14159"
).
+ */
+ @Test
+ public void testString2Long_2() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setStringProperty("pi", "3.14159");
+ message.getLongProperty("pi");
+ fail("3.5.4 The String to numeric conversions must throw the java.lang.NumberFormatException "
+ + " if the numeric's valueOf() method does not accept the String value as a valid representation.\n");
+ } catch (java.lang.NumberFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a java.lang.String
, it can also be
+ * read as a long
as long as the String
is a
+ * correct representation of a long
(e.g. "0"
).
+ */
+ @Test
+ public void testString2Long_1() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setStringProperty("prop", "0");
+ assertEquals((long) 0, message.getLongProperty("prop"));
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a java.lang.String
, to get it as a
+ * int
throws a java.lang.NuberFormatException
+ * if the String
is not a correct representation for a
+ * int
(e.g. "3.14159"
).
+ */
+ @Test
+ public void testString2Int_2() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setStringProperty("pi", "3.14159");
+ message.getIntProperty("pi");
+ fail("3.5.4 The String to numeric conversions must throw the java.lang.NumberFormatException "
+ + " if the numeric's valueOf() method does not accept the String value as a valid representation.\n");
+ } catch (java.lang.NumberFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a java.lang.String
, it can also be
+ * read as a int
as long as the String
is a
+ * correct representation of a int
(e.g. "0"
).
+ */
+ @Test
+ public void testString2Int_1() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setStringProperty("prop", "0");
+ assertEquals((int) 0, message.getIntProperty("prop"));
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a java.lang.String
, to get it as a
+ * short
throws a java.lang.NuberFormatException
+ * if the String
is not a correct representation for a
+ * short
(e.g. "3.14159"
).
+ */
+ @Test
+ public void testString2Short_2() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setStringProperty("pi", "3.14159");
+ message.getShortProperty("pi");
+ fail("3.5.4 The String to numeric conversions must throw the java.lang.NumberFormatException "
+ + " if the numeric's valueOf() method does not accept the String value as a valid representation.\n");
+ } catch (java.lang.NumberFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a java.lang.String
, it can also be
+ * read as a short
as long as the String
is a
+ * correct representation of a short
(e.g. "0"
).
+ */
+ @Test
+ public void testString2Short_1() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setStringProperty("prop", "0");
+ assertEquals((short) 0, message.getShortProperty("prop"));
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a java.lang.String
, to get it as a
+ * byte
throws a java.lang.NuberFormatException
+ * if the String
is not a correct representation for a
+ * byte
(e.g. "3.14159"
).
+ */
+ @Test
+ public void testString2Byte_2() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setStringProperty("pi", "3.14159");
+ message.getByteProperty("pi");
+ fail("3.5.4 The String to numeric conversions must throw the java.lang.NumberFormatException "
+ + " if the numeric's valueOf() method does not accept the String value as a valid representation.\n");
+ } catch (java.lang.NumberFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a java.lang.String
, it can also be
+ * read as a byte
if the String
is a correct
+ * representation of a byte
(e.g. "0"
).
+ */
+ @Test
+ public void testString2Byte_1() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setStringProperty("prop", "0");
+ assertEquals((byte) 0, message.getByteProperty("prop"));
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a java.lang.String
, to get it as a
+ * boolean
returns true
if the property is not
+ * null and is equal, ignoring case, to the string "true" (.eg. "True" is ok),
+ * else it returns false
(e.g. "test")
+ */
+ @Test
+ public void testString2Boolean_2() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setStringProperty("prop", "test");
+ assertEquals(false, message.getBooleanProperty("prop"));
+ } catch (MessageFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a java.lang.String
, it can also be
+ * read as a boolean
if the String
is a correct
+ * representation of a boolean
(e.g. "true"
).
+ */
+ @Test
+ public void testString2Boolean_1() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setStringProperty("prop", "true");
+ assertEquals(true, message.getBooleanProperty("prop"));
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a double
, it can also be read as a
+ * java.lang.String
.
+ */
+ @Test
+ public void testDouble2String() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setDoubleProperty("prop", 127.0);
+ assertEquals("127.0", message.getStringProperty("prop"));
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a double
, it can also be read as a
+ * double
.
+ */
+ @Test
+ public void testDouble2Double() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setDoubleProperty("prop", 127.0);
+ assertEquals(127.0, message.getDoubleProperty("prop"), 0);
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a double
, to get is as a
+ * float
throws a javax.jms.MessageFormatException
.
+ */
+ @Test
+ public void testDouble2Float() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setDoubleProperty("prop", 127.0);
+ message.getFloatProperty("prop");
+ fail("3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
+ } catch (MessageFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a double
, to get is as a
+ * long
throws a javax.jms.MessageFormatException
.
+ */
+ @Test
+ public void testDouble2Long() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setDoubleProperty("prop", 127.0);
+ message.getLongProperty("prop");
+ fail("3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
+ } catch (MessageFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a double
, to get is as an
+ * int
throws a javax.jms.MessageFormatException
.
+ */
+ @Test
+ public void testDouble2Int() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setDoubleProperty("prop", 127.0);
+ message.getIntProperty("prop");
+ fail("3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
+ } catch (MessageFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a double
, to get is as a
+ * short
throws a javax.jms.MessageFormatException
.
+ */
+ @Test
+ public void testDouble2Short() {
+ try {
+ Message message = senderSession.createMessage();
+ // store a value that can't be converted to short
+ message.setDoubleProperty("prop", 127.0);
+ message.getShortProperty("prop");
+ fail("3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
+ } catch (MessageFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a double
, to get is as a
+ * byte
throws a javax.jms.MessageFormatException
.
+ */
+ @Test
+ public void testDouble2Byte() {
+ try {
+ Message message = senderSession.createMessage();
+ // store a value that can't be converted to byte
+ message.setDoubleProperty("prop", 127.0);
+ message.getByteProperty("prop");
+ fail("3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
+ } catch (MessageFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a double
, to get is as a
+ * boolean
throws a
+ * javax.jms.MessageFormatException
.
+ */
+ @Test
+ public void testDouble2Boolean() {
+ try {
+ Message message = senderSession.createMessage();
+ // store a value that can be converted to boolean
+ message.setDoubleProperty("prop", 127.0);
+ message.getBooleanProperty("prop");
+ fail("3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
+ } catch (MessageFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a float
, it can also be read as a
+ * String
.
+ */
+ @Test
+ public void testFloat2String() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setFloatProperty("prop", 127.0F);
+ assertEquals("127.0", message.getStringProperty("prop"));
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a float
, it can also be read as a
+ * double
.
+ */
+ @Test
+ public void testFloat2Double() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setFloatProperty("prop", 127.0F);
+ assertEquals(127.0, message.getDoubleProperty("prop"), 0);
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a float
, it can also be read as a
+ * float
.
+ */
+ @Test
+ public void testFloat2Float() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setFloatProperty("prop", 127.0F);
+ assertEquals(127.0F, message.getFloatProperty("prop"), 0);
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a float
, to get is as a
+ * long
throws a javax.jms.MessageFormatException
.
+ */
+ @Test
+ public void testFloat2Long() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setFloatProperty("prop", 127.0F);
+ message.getLongProperty("prop");
+ fail("3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
+ } catch (MessageFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a float
, to get is as a
+ * int
throws a javax.jms.MessageFormatException
.
+ */
+ @Test
+ public void testFloat2Int() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setFloatProperty("prop", 127.0F);
+ message.getIntProperty("prop");
+ fail("3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
+ } catch (MessageFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a float
, to get is as a
+ * short
throws a javax.jms.MessageFormatException
.
+ */
+ @Test
+ public void testFloat2Short() {
+ try {
+ Message message = senderSession.createMessage();
+ // store a value that can't be converted to short
+ message.setFloatProperty("prop", 127.0F);
+ message.getShortProperty("prop");
+ fail("3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
+ } catch (MessageFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a float
, to get is as a
+ * byte
throws a javax.jms.MessageFormatException
.
+ */
+ @Test
+ public void testFloat2Byte() {
+ try {
+ Message message = senderSession.createMessage();
+ // store a value that can't be converted to byte
+ message.setFloatProperty("prop", 127.0F);
+ message.getByteProperty("prop");
+ fail("3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
+ } catch (MessageFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a float
, to get is as a
+ * boolean
throws a
+ * javax.jms.MessageFormatException
.
+ */
+ @Test
+ public void testFloat2Boolean() {
+ try {
+ Message message = senderSession.createMessage();
+ // store a value that can be converted to boolean
+ message.setFloatProperty("prop", 127.0F);
+ message.getBooleanProperty("prop");
+ fail("3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
+ } catch (MessageFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a long
, it can also be read as a
+ * String
.
+ */
+ @Test
+ public void testLong2String() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setLongProperty("prop", 127L);
+ assertEquals("127", message.getStringProperty("prop"));
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a long
, to get is as a
+ * double
throws a
+ * javax.jms.MessageFormatException
.
+ */
+ @Test
+ public void testLong2Double() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setLongProperty("prop", 127L);
+ message.getDoubleProperty("prop");
+ fail("3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
+ } catch (MessageFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a long
, to get is as a
+ * float
throws a javax.jms.MessageFormatException
.
+ */
+ @Test
+ public void testLong2Float() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setLongProperty("prop", 127L);
+ message.getFloatProperty("prop");
+ fail("3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
+ } catch (MessageFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a long
, it can also be read as a
+ * long
.
+ */
+ @Test
+ public void testLong2Long() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setLongProperty("prop", 127L);
+ assertEquals(127L, message.getLongProperty("prop"));
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a long
, to get is as an
+ * int
throws a javax.jms.MessageFormatException
.
+ */
+ @Test
+ public void testLong2Int() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setLongProperty("prop", 127L);
+ message.getIntProperty("prop");
+ fail("3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
+ } catch (MessageFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a long
, to get is as a
+ * short
throws a javax.jms.MessageFormatException
.
+ */
+ @Test
+ public void testLong2Short() {
+ try {
+ Message message = senderSession.createMessage();
+ // store a value that can't be converted to short
+ message.setLongProperty("prop", 127L);
+ message.getShortProperty("prop");
+ fail("3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
+ } catch (MessageFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a long
, to get is as a
+ * byte
throws a javax.jms.MessageFormatException
.
+ */
+ @Test
+ public void testLong2Byte() {
+ try {
+ Message message = senderSession.createMessage();
+ // store a value that can't be converted to byte
+ message.setLongProperty("prop", 127L);
+ message.getByteProperty("prop");
+ fail("3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
+ } catch (MessageFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a long
, to get is as a
+ * boolean
throws a
+ * javax.jms.MessageFormatException
.
+ */
+ @Test
+ public void testLong2Boolean() {
+ try {
+ Message message = senderSession.createMessage();
+ // store a value that can be converted to boolean
+ message.setLongProperty("prop", 127L);
+ message.getBooleanProperty("prop");
+ fail("3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
+ } catch (MessageFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as an int
, it can also be read as a
+ * String
.
+ */
+ @Test
+ public void testInt2String() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setIntProperty("prop", (int) 127);
+ assertEquals("127", message.getStringProperty("prop"));
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a int
, to get is as a
+ * double
throws a
+ * javax.jms.MessageFormatException
.
+ */
+ @Test
+ public void testInt2Double() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setIntProperty("prop", (int) 127);
+ message.getDoubleProperty("prop");
+ fail("3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
+ } catch (MessageFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a int
, to get is as a
+ * float
throws a javax.jms.MessageFormatException
.
+ */
+ @Test
+ public void testInt2Float() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setIntProperty("prop", (int) 127);
+ message.getFloatProperty("prop");
+ fail("3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
+ } catch (MessageFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as an int
, it can also be read as a
+ * long
.
+ */
+ @Test
+ public void testInt2Long() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setIntProperty("prop", (int) 127);
+ assertEquals(127L, message.getLongProperty("prop"));
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as an int
, it can also be read as an
+ * int
.
+ */
+ @Test
+ public void testInt2Int() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setIntProperty("prop", (int) 127);
+ assertEquals((int) 127, message.getIntProperty("prop"));
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a int
, to get is as a
+ * short
throws a javax.jms.MessageFormatException
.
+ */
+ @Test
+ public void testInt2Short() {
+ try {
+ Message message = senderSession.createMessage();
+ // store a value that can't be converted to short
+ message.setIntProperty("prop", Integer.MAX_VALUE);
+ message.getShortProperty("prop");
+ fail("3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
+ } catch (MessageFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a int
, to get is as a
+ * byte
throws a javax.jms.MessageFormatException
.
+ */
+ @Test
+ public void testInt2Byte() {
+ try {
+ Message message = senderSession.createMessage();
+ // store a value that can't be converted to byte
+ message.setIntProperty("prop", Integer.MAX_VALUE);
+ message.getByteProperty("prop");
+ fail("3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
+ } catch (MessageFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a int
, to get is as a
+ * boolean
throws a
+ * javax.jms.MessageFormatException
.
+ */
+ @Test
+ public void testInt2Boolean() {
+ try {
+ Message message = senderSession.createMessage();
+ // store a value that can be converted to boolean
+ message.setIntProperty("prop", Integer.MAX_VALUE);
+ message.getBooleanProperty("prop");
+ fail("3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
+ } catch (MessageFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a short
, it can also be read as a
+ * String
.
+ */
+ @Test
+ public void testShort2String() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setShortProperty("prop", (short) 127);
+ assertEquals("127", message.getStringProperty("prop"));
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a short
, to get is as a
+ * double
throws a
+ * javax.jms.MessageFormatException
.
+ */
+ @Test
+ public void testShort2Double() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setShortProperty("prop", (short) 127);
+ message.getDoubleProperty("prop");
+ fail("3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
+ } catch (MessageFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a short
, to get is as a
+ * float
throws a javax.jms.MessageFormatException
.
+ */
+ @Test
+ public void testShort2Float() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setShortProperty("prop", (short) 127);
+ message.getFloatProperty("prop");
+ fail("3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
+ } catch (MessageFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a short
, it can also be read as a
+ * long
.
+ */
+ @Test
+ public void testShort2Long() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setShortProperty("prop", (short) 127);
+ assertEquals(127L, message.getLongProperty("prop"));
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a short
, it can also be read as an
+ * int
.
+ */
+ @Test
+ public void testShort2Int() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setShortProperty("prop", (short) 127);
+ assertEquals((int) 127, message.getIntProperty("prop"));
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a short
, it can also be read as a
+ * short
.
+ */
+ @Test
+ public void testShort2Short() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setShortProperty("prop", (short) 127);
+ assertEquals((short) 127, message.getShortProperty("prop"));
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a short
, to get is as a
+ * byte
throws a javax.jms.MessageFormatException
.
+ */
+ @Test
+ public void testShort2Byte() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setShortProperty("prop", (short) 127);
+ message.getByteProperty("prop");
+ fail("3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
+ } catch (MessageFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a short
, to get is as a
+ * boolean
throws a
+ * javax.jms.MessageFormatException
.
+ */
+ @Test
+ public void testShort2Boolean() {
+ try {
+ Message message = senderSession.createMessage();
+ // store a value that can't be converted to boolean
+ message.setShortProperty("prop", (short) 127);
+ message.getBooleanProperty("prop");
+ fail("3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
+ } catch (MessageFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a byte
, it can also be read as a
+ * String
.
+ */
+ @Test
+ public void testByte2String() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setByteProperty("prop", (byte) 127);
+ assertEquals("127", message.getStringProperty("prop"));
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a byte
, to get is as a
+ * double
throws a
+ * javax.jms.MessageFormatException
.
+ */
+ @Test
+ public void testByte2Double() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setByteProperty("prop", (byte) 127);
+ message.getDoubleProperty("prop");
+ fail("3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
+ } catch (MessageFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a byte
, to get is as a
+ * float
throws a javax.jms.MessageFormatException
.
+ */
+ @Test
+ public void testByte2Float() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setByteProperty("prop", (byte) 127);
+ message.getFloatProperty("prop");
+ fail("3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
+ } catch (MessageFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a byte
, it can also be read as a
+ * long
.
+ */
+ @Test
+ public void testByte2Long() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setByteProperty("prop", (byte) 127);
+ assertEquals(127L, message.getLongProperty("prop"));
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a byte
, it can also be read as an
+ * int
.
+ */
+ @Test
+ public void testByte2Int() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setByteProperty("prop", (byte) 127);
+ assertEquals((int) 127, message.getIntProperty("prop"));
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a byte
, it can also be read as a
+ * short
.
+ */
+ @Test
+ public void testByte2Short() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setByteProperty("prop", (byte) 127);
+ assertEquals((short) 127, message.getShortProperty("prop"));
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a byte
, it can also be read as a
+ * byte
.
+ */
+ @Test
+ public void testByte2Byte() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setByteProperty("prop", (byte) 127);
+ assertEquals((byte) 127, message.getByteProperty("prop"));
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a byte
, to get is as a
+ * boolean
throws a
+ * javax.jms.MessageFormatException
.
+ */
+ @Test
+ public void testByte2Boolean() {
+ try {
+ Message message = senderSession.createMessage();
+ // store a value that can't be converted to boolean
+ message.setByteProperty("prop", (byte) 127);
+ message.getBooleanProperty("prop");
+ fail("3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
+ } catch (MessageFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a boolean
, it can also be read as a
+ * String
.
+ */
+ @Test
+ public void testBoolean2String() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setBooleanProperty("prop", true);
+ assertEquals("true", message.getStringProperty("prop"));
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a boolean
, to get is as a
+ * double
throws a
+ * javax.jms.MessageFormatException
.
+ */
+ @Test
+ public void testBoolean2Double() {
+ try {
+ Message message = senderSession.createMessage();
+ // store a value that can't be converted to double
+ message.setBooleanProperty("prop", true);
+ message.getDoubleProperty("prop");
+ fail("3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
+ } catch (MessageFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a boolean
, to get is as a
+ * float
throws a javax.jms.MessageFormatException
.
+ */
+ @Test
+ public void testBoolean2Float() {
+ try {
+ Message message = senderSession.createMessage();
+ // store a value that can't be converted to float
+ message.setBooleanProperty("prop", true);
+ message.getFloatProperty("prop");
+ fail("3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
+ } catch (MessageFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a boolean
, to get is as a
+ * long
throws a javax.jms.MessageFormatException
.
+ */
+ @Test
+ public void testBoolean2Long() {
+ try {
+ Message message = senderSession.createMessage();
+ // store a value that can't be converted to long
+ message.setBooleanProperty("prop", true);
+ message.getLongProperty("prop");
+ fail("3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
+ } catch (MessageFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a boolean
, to get is as a
+ * int
throws a javax.jms.MessageFormatException
.
+ */
+ @Test
+ public void testBoolean2Int() {
+ try {
+ Message message = senderSession.createMessage();
+ // store a value that can't be converted to int
+ message.setBooleanProperty("prop", true);
+ message.getIntProperty("prop");
+ fail("3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
+ } catch (MessageFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a boolean
, to get is as a
+ * short
throws a javax.jms.MessageFormatException
.
+ */
+ @Test
+ public void testBoolean2Short() {
+ try {
+ Message message = senderSession.createMessage();
+ // store a value that can't be converted to short
+ message.setBooleanProperty("prop", true);
+ message.getShortProperty("prop");
+ fail("3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
+ } catch (MessageFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a boolean
, to get is as a
+ * byte
throws a javax.jms.MessageFormatException
.
+ */
+ @Test
+ public void testBoolean2Byte() {
+ try {
+ Message message = senderSession.createMessage();
+ // store a value that can't be converted to byte
+ message.setBooleanProperty("prop", true);
+ message.getByteProperty("prop");
+ fail("3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
+ } catch (MessageFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * if a property is set as a boolean
, it can also be read as a
+ * boolean
.
+ */
+ @Test
+ public void testBoolean2Boolean() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setBooleanProperty("prop", true);
+ assertEquals(true, message.getBooleanProperty("prop"));
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/conform/message/properties/MessagePropertyTest.java b/joram/joram/client/jms/src/test/java/jms/conform/message/properties/MessagePropertyTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..716d4655ec040c3145dd31a91871906a412d6407
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/conform/message/properties/MessagePropertyTest.java
@@ -0,0 +1,307 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2002 - 2007 ScalAgent Distributed Technologies
+ * Copyright (C) 2002 INRIA
+ * Contact: joram-team@objectweb.org
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s): Jeff Mesnil (Inria)
+ * Contributor(s): Nicolas Tachker (ScalAgent D.T.)
+ */
+
+package jms.conform.message.properties;
+
+import java.util.Enumeration;
+import java.util.Vector;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageFormatException;
+import javax.jms.TextMessage;
+
+import org.junit.jupiter.api.Test;
+
+import jms.framework.PTPTestCase;
+
+
+/**
+ * Test the javax.jms.Message
properties.
+ * See JMS Specification, 3.5 Message Properties (p.32-37)
+ */
+public class MessagePropertyTest extends PTPTestCase {
+
+ /**
+ * Test that any other class than Boolean, Byte, Short, Integer, Long,
+ * Float, Double
+ * and String
used in the
+ * Message.setObjectProperty()
method throws a
+ * javax.jms.MessageFormatException
.
+ */
+ @Test
+ public void testSetObjectProperty_2() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setObjectProperty("prop", new Vector());
+ fail("3.5.5 An attempt to use any other class [than Boolean, Byte,...,String] must throw "
+ + "a JMS MessageFormatException.\n");
+ } catch (MessageFormatException e) {
+ } catch (JMSException e) {
+ fail("Should throw a javax.jms.MessageFormatException, not a " + e);
+ }
+ }
+
+ /**
+ * if a property is set as a Float
with the
+ * Message.setObjectProperty()
method, it can be retrieve
+ * directly as a double
by
+ * Message.getFloatProperty()
+ */
+ @Test
+ public void testSetObjectProperty_1() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setObjectProperty("pi", new Float(3.14159f));
+ assertEquals(3.14159f, message.getFloatProperty("pi"), 0);
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test that a null
value is returned by the
+ * Message.getObjectProperty()
method if a property by the
+ * specified name does not exits.
+ */
+ @Test
+ public void testGetObjectProperty() {
+ try {
+ Message message = senderSession.createMessage();
+ assertEquals(
+ "3.5.5 A null value is returned [by the getObjectProperty method] if a property by the specified "
+ + "name does not exits.\n", null, message
+ .getObjectProperty("prop"));
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test that a null
value is returned by the
+ * Message.getStringProperty()
method if a property by the
+ * specified name does not exits.
+ */
+ @Test
+ public void testGetStringProperty() {
+ try {
+ Message message = senderSession.createMessage();
+ assertEquals(
+ "3.5.5 A null value is returned [by the getStringProperty method] if a property by the specified "
+ + "name does not exits.\n", null, message
+ .getStringProperty("prop"));
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test that an attempt to get a double
property which does not
+ * exist throw a java.lang.NullPointerException
+ */
+ @Test
+ public void testGetDoubleProperty() {
+ try {
+ Message message = senderSession.createMessage();
+ message.getDoubleProperty("prop");
+ fail("Should raise a NullPointerException.\n");
+ } catch (NullPointerException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test that an attempt to get a float
property which does not
+ * exist throw a java.lang.NullPointerException
+ */
+ @Test
+ public void testGetFloatProperty() {
+ try {
+ Message message = senderSession.createMessage();
+ message.getFloatProperty("prop");
+ fail("Should raise a NullPointerException.\n");
+ } catch (NullPointerException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test that an attempt to get a long
property which does not
+ * exist throw a java.lang.NumberFormatException
+ */
+ @Test
+ public void testGetLongProperty() {
+ try {
+ Message message = senderSession.createMessage();
+ message.getLongProperty("prop");
+ fail("Should raise a NumberFormatException.\n");
+ } catch (NumberFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test that an attempt to get a int
property which does not
+ * exist throw a java.lang.NumberFormatException
+ */
+ @Test
+ public void testGetIntProperty() {
+ try {
+ Message message = senderSession.createMessage();
+ message.getIntProperty("prop");
+ fail("Should raise a NumberFormatException.\n");
+ } catch (NumberFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test that an attempt to get a short
property which does not
+ * exist throw a java.lang.NumberFormatException
+ */
+ @Test
+ public void testGetShortProperty() {
+ try {
+ Message message = senderSession.createMessage();
+ message.getShortProperty("prop");
+ fail("Should raise a NumberFormatException.\n");
+ } catch (NumberFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test that an attempt to get a byte
property which does not
+ * exist throw a java.lang.NumberFormatException
+ */
+ @Test
+ public void testGetByteProperty() {
+ try {
+ Message message = senderSession.createMessage();
+ message.getByteProperty("prop");
+ fail("Should raise a NumberFormatException.\n");
+ } catch (NumberFormatException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test that an attempt to get a boolean
property which does
+ * not exist returns false
+ */
+ @Test
+ public void testGetBooleanProperty() {
+ try {
+ Message message = senderSession.createMessage();
+ assertEquals(false, message.getBooleanProperty("prop"));
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test that the Message.getPropertyNames()
method does not
+ * return the name of the JMS standard header fields (e.g.
+ * JMSCorrelationID
.
+ */
+ @Test
+ public void testGetPropertyNames() {
+ try {
+ Message message = senderSession.createMessage();
+ message.setJMSCorrelationID("foo");
+ Enumeration e = message.getPropertyNames();
+ assertTrue(
+ "3.5.6 The getPropertyNames method does not return the names of "
+ + "the JMS standard header field [e.g. JMSCorrelationID].\n", !e
+ .hasMoreElements());
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test that the Message.getPropertyNames()
method returns an
+ * empty java.util.Enumeration
if there is no properties.
+ *
+ * If there are some, test that it properly return their names.
+ */
+ @Test
+ public void testPropertyIteration() {
+ try {
+ Message message = senderSession.createMessage();
+ Enumeration e = message.getPropertyNames();
+ assertTrue("No property yet defined.\n", !e.hasMoreElements());
+ message.setDoubleProperty("pi", 3.14159);
+ e = message.getPropertyNames();
+ assertEquals("One property defined of name 'pi'.\n", "pi", (String) e
+ .nextElement());
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test that the Message.clearProperties()
method does not
+ * clear the value of the Message's body.
+ */
+ @Test
+ public void testClearProperties_2() {
+ try {
+ TextMessage message = senderSession.createTextMessage();
+ message.setText("foo");
+ message.clearProperties();
+ assertEquals(
+ "3.5.7 Clearing a message's property entries does not clear the value of its body.\n",
+ "foo", message.getText());
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test that the Message.clearProperties()
method deletes all
+ * the properties of the Message.
+ */
+ @Test
+ public void testClearProperties_1() {
+ try {
+ TextMessage message = senderSession.createTextMessage();
+ message.setStringProperty("prop", "foo");
+ message.clearProperties();
+ assertEquals(
+ "3.5.7 A message's properties are deleted by the clearProperties method.\n",
+ null, message.getStringProperty("prop"));
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/conform/queue/QueueBrowserTest.java b/joram/joram/client/jms/src/test/java/jms/conform/queue/QueueBrowserTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..1411fd8c00ec28b212e81432a60e4fab7e2bf91e
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/conform/queue/QueueBrowserTest.java
@@ -0,0 +1,167 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2002 - 2007 ScalAgent Distributed Technologies
+ * Copyright (C) 2002 INRIA
+ * Contact: joram-team@objectweb.org
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s): Jeff Mesnil (Inria)
+ * Contributor(s): Nicolas Tachker (ScalAgent D.T.)
+ */
+
+package jms.conform.queue;
+
+import java.util.Enumeration;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.QueueBrowser;
+import javax.jms.TextMessage;
+
+import org.junit.jupiter.api.Test;
+
+import jms.framework.PTPTestCase;
+import jms.framework.TestConfig;
+
+
+/**
+ * Test the javax.jms.QueueBrowser
features.
+ */
+public class QueueBrowserTest extends PTPTestCase {
+
+ /**
+ * The QueueBrowser
of the receiver's session
+ */
+ protected QueueBrowser receiverBrowser;
+
+ /**
+ * The QueueBrowser
of the sender's session
+ */
+ protected QueueBrowser senderBrowser;
+
+ /**
+ * Test the QueueBrowser
of the sender.
+ */
+ @Test
+ public void testSenderBrowser() {
+ try {
+ TextMessage message_1 = senderSession.createTextMessage();
+ message_1.setText("testBrowser:message_1");
+ TextMessage message_2 = senderSession.createTextMessage();
+ message_2.setText("testBrowser:message_2");
+
+ // send two messages...
+ sender.send(message_1);
+ sender.send(message_2);
+
+ // ask the browser to browse the sender's session
+ Enumeration enumeration = senderBrowser.getEnumeration();
+ int count = 0;
+ while (enumeration.hasMoreElements()) {
+ // one more message in the queue
+ count++;
+ // check that the message in the queue is one of the two which where
+ // sent
+ Object obj = enumeration.nextElement();
+ assertTrue(obj instanceof TextMessage);
+ TextMessage msg = (TextMessage) obj;
+ assertTrue(msg.getText().startsWith("testBrowser:message_"));
+ }
+ // check that there is effectively 2 messages in the queue
+ assertEquals(2, count);
+
+ // receive the first message...
+ Message m = receiver.receive(TestConfig.TIMEOUT);
+ // ... and check it is the first which was sent.
+ assertTrue(m instanceof TextMessage);
+ TextMessage msg = (TextMessage) m;
+ assertEquals("testBrowser:message_1", msg.getText());
+
+ // receive the second message...
+ m = receiver.receive(TestConfig.TIMEOUT);
+ // ... and check it is the second which was sent.
+ assertTrue(m instanceof TextMessage);
+ msg = (TextMessage) m;
+ assertEquals("testBrowser:message_2", msg.getText());
+
+ // ask the browser to browse the sender's session
+ enumeration = receiverBrowser.getEnumeration();
+ // check that there is no messages in the queue
+ // (the two messages have been acknowledged and so removed
+ // from the queue)
+ assertTrue(!enumeration.hasMoreElements());
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test that a QueueBrowser created with a message selector
+ * browses only the messages matching this selector.
+ */
+ @Test
+ public void testBrowserWithMessageSelector() {
+ try {
+ senderBrowser = senderSession.createBrowser(senderQueue, "pi = 3.14159");
+
+ TextMessage message_1 = senderSession.createTextMessage();
+ message_1.setText("testBrowserWithMessageSelector:message_1");
+ TextMessage message_2 = senderSession.createTextMessage();
+ message_2.setDoubleProperty("pi", 3.14159);
+ message_2.setText("testBrowserWithMessageSelector:message_2");
+
+ sender.send(message_1);
+ sender.send(message_2);
+
+ Enumeration enumeration = senderBrowser.getEnumeration();
+ int count = 0;
+ while (enumeration.hasMoreElements()) {
+ count++;
+ Object obj = enumeration.nextElement();
+ assertTrue(obj instanceof TextMessage);
+ TextMessage msg = (TextMessage) obj;
+ assertEquals("testBrowserWithMessageSelector:message_2", msg.getText());
+ }
+ assertEquals(1, count);
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ public void setUp() {
+ try {
+ super.setUp();
+ receiverBrowser = receiverSession.createBrowser(receiverQueue);
+ senderBrowser = senderSession.createBrowser(senderQueue);
+ } catch (JMSException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void tearDown() {
+ try {
+ receiverBrowser.close();
+ senderBrowser.close();
+ super.tearDown();
+ } catch (JMSException e) {
+ e.printStackTrace();
+ } finally {
+ receiverBrowser = null;
+ senderBrowser = null;
+ }
+ }
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/conform/queue/TemporaryQueueTest.java b/joram/joram/client/jms/src/test/java/jms/conform/queue/TemporaryQueueTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..3009e0f1fb8488a5fe46f0b763c4a07fe7a8a083
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/conform/queue/TemporaryQueueTest.java
@@ -0,0 +1,79 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2002 - 2007 ScalAgent Distributed Technologies
+ * Copyright (C) 2002 INRIA
+ * Contact: joram-team@objectweb.org
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s): Jeff Mesnil (Inria)
+ * Contributor(s): Nicolas Tachker (ScalAgent D.T.)
+ */
+
+package jms.conform.queue;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.QueueReceiver;
+import javax.jms.TemporaryQueue;
+import javax.jms.TextMessage;
+
+import org.junit.jupiter.api.Test;
+
+import jms.framework.PTPTestCase;
+import jms.framework.TestConfig;
+
+
+/**
+ * Test the javax.jms.TemporaryQueue
features.
+ */
+public class TemporaryQueueTest extends PTPTestCase {
+
+ private TemporaryQueue tempQueue;
+ private QueueReceiver tempReceiver;
+
+ /**
+ * Test a TemporaryQueue
+ */
+ @Test
+ public void testTemporaryQueue() {
+ try {
+ // we stop both sender and receiver connections
+ senderConnection.stop();
+ receiverConnection.stop();
+ // we create a temporary queue to receive messages
+ tempQueue = receiverSession.createTemporaryQueue();
+ // we recreate the sender because it has been
+ // already created with a Destination as parameter
+ sender = senderSession.createSender(null);
+ // we create a receiver on the temporary queue
+ tempReceiver = receiverSession.createReceiver(tempQueue);
+ receiverConnection.start();
+ senderConnection.start();
+
+ TextMessage message = senderSession.createTextMessage();
+ message.setText("testTemporaryQueue");
+ sender.send(tempQueue, message);
+
+ Message m = tempReceiver.receive(TestConfig.TIMEOUT);
+ assertTrue(m instanceof TextMessage);
+ TextMessage msg = (TextMessage) m;
+ assertEquals("testTemporaryQueue", msg.getText());
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/conform/selector/SelectorSyntaxTest.java b/joram/joram/client/jms/src/test/java/jms/conform/selector/SelectorSyntaxTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..7c08fd74f58d740faedc138464f719d3b4a8841a
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/conform/selector/SelectorSyntaxTest.java
@@ -0,0 +1,382 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2002 - 2007 ScalAgent Distributed Technologies
+ * Copyright (C) 2002 INRIA
+ * Contact: joram-team@objectweb.org
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s): Jeff Mesnil (Inria)
+ * Contributor(s): Nicolas Tachker (ScalAgent D.T.)
+ */
+
+package jms.conform.selector;
+
+import javax.jms.InvalidSelectorException;
+import javax.jms.JMSException;
+
+import org.junit.jupiter.api.Test;
+
+import jms.framework.PTPTestCase;
+
+
+/**
+ * Test the syntax of of message selector of JMS
+ */
+public class SelectorSyntaxTest extends PTPTestCase {
+
+ /**
+ * Test that identifiers that start with a valid Java identifier start
+ * character are valid. A valid identifier means that the method
+ * Character.isJavaIdentifierStart
returns true
+ * for this identifier first character.
+ *
+ * @see Character.isJavaIdentifierStart(char)
+ */
+ @Test
+ public void testValidIdentifiersStart() {
+ String identifier = null;
+ try {
+ identifier = "_correct";
+ assertTrue(identifier
+ + " starts with an invalid Java identifier start character",
+ Character.isJavaIdentifierStart(identifier.charAt(0)));
+ receiver = receiverSession.createReceiver(receiverQueue, identifier
+ + " IS NULL");
+
+ identifier = "$correct";
+ assertTrue(identifier
+ + " starts with an invalid Java identifier start character",
+ Character.isJavaIdentifierStart(identifier.charAt(0)));
+ receiver = receiverSession.createReceiver(receiverQueue, identifier
+ + " IS NULL");
+ } catch (JMSException e) {
+ fail(identifier + " is a correct identifier. \n" + e);
+ }
+ }
+
+ /**
+ * Test that identifiers that start with an invalid Java identifier start
+ * character are invalid.
+ *
+ * @see #testValidIdentifiersStart()
+ */
+ @Test
+ public void testInvalidIdentifiersStart() {
+ String identifier = null;
+ try {
+ identifier = "1uncorrect";
+
+ assertTrue(identifier
+ + " starts with an invalid Java identifier start character",
+ !Character.isJavaIdentifierStart(identifier.charAt(0)));
+ receiver = receiverSession.createReceiver(receiverQueue, identifier
+ + " IS NULL");
+ fail(identifier
+ + " starts with an invalid Java identifier start character");
+ } catch (JMSException e) {
+ }
+
+ try {
+ identifier = "%uncorrect";
+
+ assertTrue(identifier
+ + " starts with an invalid Java identifier start character",
+ !Character.isJavaIdentifierStart(identifier.charAt(0)));
+ receiver = receiverSession.createReceiver(receiverQueue, identifier
+ + " IS NULL");
+ fail(identifier
+ + " starts with an invalid Java identifier start character");
+ } catch (JMSException e) {
+ }
+
+ }
+
+ /**
+ * Test that message selector can be an empty string.
+ */
+ @Test
+ public void testEmptyStringAsSelector() {
+ try {
+ receiver = receiverSession.createReceiver(receiverQueue, "");
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test that identifiers can't be NULL
.
+ */
+ @Test
+ public void testIdentifierNULL() {
+ try {
+ receiver = receiverSession.createReceiver(receiverQueue, "NULL = ZERO");
+ fail("NULL is not a valid identifier");
+ } catch (InvalidSelectorException e) {
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test that identifiers can't be TRUE
.
+ */
+ @Test
+ public void testIdentifierTRUE() {
+ try {
+ receiver = receiverSession.createReceiver(receiverQueue, "TRUE > 0");
+ fail("TRUE is not a valid identifier");
+ } catch (JMSException e) {
+ }
+ }
+
+ /**
+ * Test that identifiers can't be FALSE
.
+ */
+ @Test
+ public void testIdentifierFALSE() {
+ try {
+ receiver = receiverSession.createReceiver(receiverQueue, "FALSE > 0");
+ fail("FALSE is not a valid identifier");
+ } catch (JMSException e) {
+ }
+ }
+
+ /**
+ * Test that identifiers can't be NOT
.
+ */
+ @Test
+ public void testIdentifierNOT() {
+ try {
+ receiver = receiverSession.createReceiver(receiverQueue, "NOT > 0");
+ fail("NOT is not a valid identifier");
+ } catch (JMSException e) {
+ }
+ }
+
+ /**
+ * Test that identifiers can't be AND
.
+ */
+ @Test
+ public void testIdentifierAND() {
+ try {
+ receiver = receiverSession.createReceiver(receiverQueue, "AND > 0");
+ fail("AND is not a valid identifier");
+ } catch (JMSException e) {
+ }
+ }
+
+ /**
+ * Test that identifiers can't be OR
.
+ */
+ @Test
+ public void testIdentifierOR() {
+ try {
+ receiver = receiverSession.createReceiver(receiverQueue, "OR > 0");
+ fail("OR is not a valid identifier");
+ } catch (JMSException e) {
+ }
+ }
+
+ /**
+ * Test that identifiers can't be BETWEEN
.
+ */
+ @Test
+ public void testIdentifierBETWEEN() {
+ try {
+ receiver = receiverSession.createReceiver(receiverQueue, "BETWEEN > 0");
+ fail("BETWEEN is not a valid identifier");
+ } catch (JMSException e) {
+ }
+ }
+
+ /**
+ * Test that identifiers can't be LIKE
.
+ */
+ @Test
+ public void testIdentifierLIKE() {
+ try {
+ receiver = receiverSession.createReceiver(receiverQueue, "LIKE > 0");
+ fail("LIKE is not a valid identifier");
+ } catch (JMSException e) {
+ }
+ }
+
+ /**
+ * Test that identifiers can't be IN
.
+ */
+ @Test
+ public void testIdentifierIN() {
+ try {
+ receiver = receiverSession.createReceiver(receiverQueue, "IN > 0");
+ fail("IN is not a valid identifier");
+ } catch (JMSException e) {
+ }
+ }
+
+ /**
+ * Test that identifiers can't be IS
.
+ */
+ @Test
+ public void testIdentifierIS() {
+ try {
+ receiver = receiverSession.createReceiver(receiverQueue, "IS > 0");
+ fail("IS is not a valid identifier");
+ } catch (JMSException e) {
+ }
+ }
+
+ /**
+ * Test that identifiers can't be ESCAPE
.
+ */
+ @Test
+ public void testIdentifierESCAPE() {
+ try {
+ receiver = receiverSession.createReceiver(receiverQueue, "ESCAPE > 0");
+ fail("ESCAPE is not a valid identifier");
+ } catch (JMSException e) {
+ }
+ }
+
+ /**
+ * Test syntax of "identifier IS [NOT] NULL"
+ */
+ @Test
+ public void testNull() {
+ try {
+ receiver = receiverSession.createReceiver(receiverQueue,
+ "prop_name IS NULL");
+ receiver = receiverSession.createReceiver(receiverQueue,
+ "prop_name IS NOT NULL");
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test syntax of "identifier [NOT] LIKE pattern-value
+ * [ESCAPE escape-character]"
+ */
+ @Test
+ public void testLike() {
+ try {
+ receiver = receiverSession.createReceiver(receiverQueue,
+ "phone LIKE '12%3'");
+ receiver = receiverSession.createReceiver(receiverQueue,
+ "word LIKE 'l_se'");
+ receiver = receiverSession.createReceiver(receiverQueue,
+ "underscored LIKE '\\_%' ESCAPE '\\'");
+ receiver = receiverSession.createReceiver(receiverQueue,
+ "phone NOT LIKE '12%3'");
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test syntax of "identifier [NOT] IN (string-literal1,
+ * string-literal2,...)"
+ */
+ @Test
+ public void testIn() {
+ try {
+ receiver = receiverSession.createReceiver(receiverQueue,
+ "Country IN ('UK', 'US', 'France')");
+ receiver = receiverSession.createReceiver(receiverQueue,
+ "Country NOT IN ('UK', 'US', 'France')");
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test syntax of "arithmetic-expr1 [NOT] BETWEEN
+ * arithmetic-expr2 and arithmetic-expr3"
+ */
+ @Test
+ public void testBetween() {
+ try {
+ receiver = receiverSession.createReceiver(receiverQueue,
+ "age BETWEEN 15 and 19");
+ receiver = receiverSession.createReceiver(receiverQueue,
+ "age NOT BETWEEN 15 and 19");
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test diffent syntax for approximate numeric literal (+6.2, -95.7, 7.)
+ */
+ @Test
+ public void testApproximateNumericLiteral() {
+ try {
+ receiver = receiverSession
+ .createReceiver(receiverQueue, "average = +6.2");
+ receiver = receiverSession.createReceiver(receiverQueue,
+ "average = -95.7");
+ receiver = receiverSession.createReceiver(receiverQueue, "average = 7.");
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test diffent syntax for exact numeric literal (+62, -957, 57)
+ */
+ @Test
+ public void testExactNumericLiteral() {
+ try {
+ receiver = receiverSession.createReceiver(receiverQueue, "average = +62");
+ receiver = receiverSession.createReceiver(receiverQueue, "max = -957");
+ receiver = receiverSession.createReceiver(receiverQueue, "max = 57");
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test diffent syntax for zero as an exact or an approximate numeric literal
+ * (0, 0.0, 0.)
+ */
+ @Test
+ public void testZero() {
+ try {
+ receiver = receiverSession.createReceiver(receiverQueue, "max = 0");
+ receiver = receiverSession.createReceiver(receiverQueue, "max = 0.0");
+ receiver = receiverSession.createReceiver(receiverQueue, "max = 0.");
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test diffent syntax for string literal ('literal' and 'literal''s')
+ */
+ @Test
+ public void testString() {
+ try {
+ receiver = receiverSession.createReceiver(receiverQueue,
+ "string = 'literal'");
+ receiver = receiverSession.createReceiver(receiverQueue,
+ "string = 'literal''s'");
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/conform/selector/SelectorTest.java b/joram/joram/client/jms/src/test/java/jms/conform/selector/SelectorTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..08d30352e3f026e77d1c794697c458f890203a13
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/conform/selector/SelectorTest.java
@@ -0,0 +1,506 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2002 - 2007 ScalAgent Distributed Technologies
+ * Copyright (C) 2002 INRIA
+ * Contact: joram-team@objectweb.org
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s): Jeff Mesnil (Inria)
+ * Contributor(s): Nicolas Tachker (ScalAgent D.T.)
+ */
+
+package jms.conform.selector;
+
+import javax.jms.DeliveryMode;
+import javax.jms.JMSException;
+import javax.jms.TextMessage;
+
+import org.junit.jupiter.api.Test;
+
+import jms.framework.PTPTestCase;
+import jms.framework.TestConfig;
+
+
+/**
+ * Test the message selector features of JMS
+ */
+public class SelectorTest extends PTPTestCase {
+
+ /**
+ * Test that an empty string as a message selector indicates that there is no
+ * message selector for the message consumer.
+ */
+ @Test
+ public void testEmptyStringAsSelector() {
+ try {
+ receiverConnection.stop();
+ receiver = receiverSession.createReceiver(receiverQueue, "");
+ receiverConnection.start();
+
+ TextMessage message = senderSession.createTextMessage();
+ message.setText("testEmptyStringAsSelector");
+ sender.send(message);
+
+ TextMessage msg = (TextMessage) receiver.receive(TestConfig.TIMEOUT);
+ assertTrue("No message was received", msg != null);
+ assertEquals("testEmptyStringAsSelector", msg.getText());
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Tats that String literals are well handled by the message selector.
+ *
+ * "string = 'literal''s;"
is true
for
+ * "literal's" and false
for "literal"
+ *
+ */
+ @Test
+ public void testStringLiterals() {
+ try {
+ receiverConnection.stop();
+ receiver = receiverSession.createReceiver(receiverQueue,
+ "string = 'literal''s'");
+ receiverConnection.start();
+
+ TextMessage dummyMessage = senderSession.createTextMessage();
+ dummyMessage.setStringProperty("string", "literal");
+ dummyMessage.setText("testStringLiterals:1");
+ sender.send(dummyMessage);
+
+ TextMessage message = senderSession.createTextMessage();
+ message.setStringProperty("string", "literal's");
+ message.setText("testStringLiterals:2");
+ sender.send(message);
+
+ TextMessage msg = (TextMessage) receiver.receive(TestConfig.TIMEOUT);
+ assertTrue("No message was received", msg != null);
+ assertEquals("testStringLiterals:2", msg.getText());
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test that the JMS property JMSDeliveryMode
is treated as
+ * having the values 'PERSISTENT'
or
+ * 'NON_PERSISTENT'
when used in a message selector (chapter
+ * 3.8.1.3).
+ */
+ @Test
+ public void testJMSDeliveryModeInSelector() {
+ try {
+ receiverConnection.stop();
+ receiver = receiverSession.createReceiver(receiverQueue,
+ "JMSDeliveryMode = 'PERSISTENT'");
+ receiverConnection.start();
+
+ TextMessage dummyMessage = senderSession.createTextMessage();
+ dummyMessage.setText("testJMSDeliveryModeInSelector:1");
+ // send a dummy message in *non persistent* mode
+ sender.send(dummyMessage, DeliveryMode.NON_PERSISTENT, sender
+ .getPriority(), sender.getTimeToLive());
+
+ TextMessage message = senderSession.createTextMessage();
+ message.setText("testJMSDeliveryModeInSelector:2");
+ // send a message in *persistent*
+ sender.send(message, DeliveryMode.PERSISTENT, sender.getPriority(),
+ sender.getTimeToLive());
+
+ TextMessage msg = (TextMessage) receiver.receive(TestConfig.TIMEOUT);
+ assertTrue("No message was received", msg != null);
+ // only the message sent in persistent mode should be received.
+ assertEquals(DeliveryMode.PERSISTENT, msg.getJMSDeliveryMode());
+ assertEquals("testJMSDeliveryModeInSelector:2", msg.getText());
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test that conversions that apply to the get
methods for
+ * properties do not apply when a property is used in a message selector
+ * expression. Based on the example of chapter 3.8.1.1 about identifiers.
+ */
+ @Test
+ public void testIdentifierConversion() {
+ try {
+ receiverConnection.stop();
+ receiver = receiverSession.createReceiver(receiverQueue,
+ "NumberOfOrders > 1");
+ receiverConnection.start();
+
+ TextMessage dummyMessage = senderSession.createTextMessage();
+ dummyMessage.setStringProperty("NumberOfOrders", "2");
+ dummyMessage.setText("testIdentifierConversion:1");
+ sender.send(dummyMessage);
+
+ TextMessage message = senderSession.createTextMessage();
+ message.setIntProperty("NumberOfOrders", 2);
+ message.setText("testIdentifierConversion:2");
+ sender.send(message);
+
+ TextMessage msg = (TextMessage) receiver.receive(TestConfig.TIMEOUT);
+ assertEquals("testIdentifierConversion:2", msg.getText());
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test the message selector using the filter example provided by the JMS
+ * specifications.
+ *
+ * "JMSType = 'car' AND color = 'blue' AND weight > 2500"
+ *
+ */
+ @Test
+ public void testSelectorExampleFromSpecs() {
+ try {
+ receiverConnection.stop();
+ receiver = receiverSession.createReceiver(receiverQueue,
+ "JMSType = 'car' AND color = 'blue' AND weight > 2500");
+ receiverConnection.start();
+
+ TextMessage dummyMessage = senderSession.createTextMessage();
+ dummyMessage.setJMSType("car");
+ dummyMessage.setStringProperty("color", "red");
+ dummyMessage.setLongProperty("weight", 3000);
+ dummyMessage.setText("testSelectorExampleFromSpecs:1");
+ sender.send(dummyMessage);
+
+ TextMessage message = senderSession.createTextMessage();
+ message.setJMSType("car");
+ message.setStringProperty("color", "blue");
+ message.setLongProperty("weight", 3000);
+ message.setText("testSelectorExampleFromSpecs:2");
+ sender.send(message);
+
+ TextMessage msg = (TextMessage) receiver.receive(TestConfig.TIMEOUT);
+ assertEquals("testSelectorExampleFromSpecs:2", msg.getText());
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test the ">" condition in message selector.
+ *
+ * "weight > 2500"
is true
for 3000 and
+ * false
for 1000
+ *
+ */
+ @Test
+ public void testGreaterThan() {
+ try {
+ receiverConnection.stop();
+ receiver = receiverSession.createReceiver(receiverQueue, "weight > 2500");
+ receiverConnection.start();
+
+ TextMessage dummyMessage = senderSession.createTextMessage();
+ dummyMessage.setLongProperty("weight", 1000);
+ dummyMessage.setText("testGreaterThan:1");
+ sender.send(dummyMessage);
+
+ TextMessage message = senderSession.createTextMessage();
+ message.setLongProperty("weight", 3000);
+ message.setText("testGreaterThan:2");
+ sender.send(message);
+
+ TextMessage msg = (TextMessage) receiver.receive(TestConfig.TIMEOUT);
+ assertEquals("testGreaterThan:2", msg.getText());
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test the "=" condition in message selector.
+ *
+ * "weight > 2500"
is true
for 2500 and
+ * false
for 1000
+ *
+ */
+ @Test
+ public void testEquals() {
+ try {
+ receiverConnection.stop();
+ receiver = receiverSession.createReceiver(receiverQueue, "weight = 2500");
+ receiverConnection.start();
+
+ TextMessage dummyMessage = senderSession.createTextMessage();
+ dummyMessage.setLongProperty("weight", 1000);
+ dummyMessage.setText("testEquals:1");
+ sender.send(dummyMessage);
+
+ TextMessage message = senderSession.createTextMessage();
+ message.setLongProperty("weight", 2500);
+ message.setText("testEquals:2");
+ sender.send(message);
+
+ TextMessage msg = (TextMessage) receiver.receive(TestConfig.TIMEOUT);
+ assertEquals("testEquals:2", msg.getText());
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test the "<>" (not equal) condition in message selector.
+ *
+ * "weight <> 2500"
is true
for 1000 and
+ * false
for 2500
+ *
+ */
+ @Test
+ public void testNotEquals() {
+ try {
+ receiverConnection.stop();
+ receiver = receiverSession
+ .createReceiver(receiverQueue, "weight <> 2500");
+ receiverConnection.start();
+
+ TextMessage dummyMessage = senderSession.createTextMessage();
+ dummyMessage.setLongProperty("weight", 2500);
+ dummyMessage.setText("testEquals:1");
+ sender.send(dummyMessage);
+
+ TextMessage message = senderSession.createTextMessage();
+ message.setLongProperty("weight", 1000);
+ message.setText("testEquals:2");
+ sender.send(message);
+
+ TextMessage msg = (TextMessage) receiver.receive(TestConfig.TIMEOUT);
+ assertEquals("testEquals:2", msg.getText());
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test the BETWEEN condition in message selector.
+ *
+ * - "age BETWEEN 15 and 19" is
true
for 17 and
+ * false
for 20
+ *
+ */
+ @Test
+ public void testBetween() {
+ try {
+ receiverConnection.stop();
+ receiver = receiverSession.createReceiver(receiverQueue,
+ "age BETWEEN 15 and 19");
+ receiverConnection.start();
+
+ TextMessage dummyMessage = senderSession.createTextMessage();
+ dummyMessage.setIntProperty("age", 20);
+ dummyMessage.setText("testBetween:1");
+ sender.send(dummyMessage);
+
+ TextMessage message = senderSession.createTextMessage();
+ message.setIntProperty("age", 17);
+ message.setText("testBetween:2");
+ sender.send(message);
+
+ TextMessage msg = (TextMessage) receiver.receive(TestConfig.TIMEOUT);
+ assertTrue("Message not received", msg != null);
+ assertTrue("Message of another test: " + msg.getText(), msg.getText()
+ .startsWith("testBetween"));
+ assertEquals("testBetween:2", msg.getText());
+
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test the IN condition in message selector.
+ *
+ * - "Country IN ('UK', 'US', 'France')" is
true
for 'UK'
+ * and false
for 'Peru'
+ *
+ */
+ @Test
+ public void testIn() {
+ try {
+ receiverConnection.stop();
+ receiver = receiverSession.createReceiver(receiverQueue,
+ "Country IN ('UK', 'US', 'France')");
+ receiverConnection.start();
+
+ TextMessage dummyMessage = senderSession.createTextMessage();
+ dummyMessage.setStringProperty("Country", "Peru");
+ dummyMessage.setText("testIn:1");
+ sender.send(dummyMessage);
+
+ TextMessage message = senderSession.createTextMessage();
+ message.setStringProperty("Country", "UK");
+ message.setText("testIn:2");
+ sender.send(message);
+
+ TextMessage msg = (TextMessage) receiver.receive(TestConfig.TIMEOUT);
+ assertTrue("Message not received", msg != null);
+ assertTrue("Message of another test: " + msg.getText(), msg.getText()
+ .startsWith("testIn"));
+ assertEquals("testIn:2", msg.getText());
+
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test the LIKE ... ESCAPE condition in message selector
+ *
+ * - "underscored LIKE '\_%' ESCAPE '\'" is
true
for '_foo'
+ * and false
for 'bar'
+ *
+ */
+ @Test
+ public void testLikeEscape() {
+ try {
+ receiverConnection.stop();
+ receiver = receiverSession.createReceiver(receiverQueue,
+ "underscored LIKE '\\_%' ESCAPE '\\'");
+ receiverConnection.start();
+
+ TextMessage dummyMessage = senderSession.createTextMessage();
+ dummyMessage.setStringProperty("underscored", "bar");
+ dummyMessage.setText("testLikeEscape:1");
+ sender.send(dummyMessage);
+
+ TextMessage message = senderSession.createTextMessage();
+ message.setStringProperty("underscored", "_foo");
+ message.setText("testLikeEscape:2");
+ sender.send(message);
+
+ TextMessage msg = (TextMessage) receiver.receive(TestConfig.TIMEOUT);
+ assertTrue("Message not received", msg != null);
+ assertTrue("Message of another test: " + msg.getText(), msg.getText()
+ .startsWith("testLikeEscape"));
+ assertEquals("testLikeEscape:2", msg.getText());
+
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test the LIKE condition with '_' in the pattern.
+ *
+ * - "word LIKE 'l_se'" is
true
for 'lose' and
+ * false
for 'loose'
+ *
+ */
+ @Test
+ public void testLike_2() {
+ try {
+ receiverConnection.stop();
+ receiver = receiverSession.createReceiver(receiverQueue,
+ "word LIKE 'l_se'");
+ receiverConnection.start();
+
+ TextMessage dummyMessage = senderSession.createTextMessage();
+ dummyMessage.setStringProperty("word", "loose");
+ dummyMessage.setText("testLike_2:1");
+ sender.send(dummyMessage);
+
+ TextMessage message = senderSession.createTextMessage();
+ message.setStringProperty("word", "lose");
+ message.setText("testLike_2:2");
+ sender.send(message);
+
+ TextMessage msg = (TextMessage) receiver.receive(TestConfig.TIMEOUT);
+ assertTrue("Message not received", msg != null);
+ assertTrue("Message of another test: " + msg.getText(), msg.getText()
+ .startsWith("testLike_2"));
+ assertEquals("testLike_2:2", msg.getText());
+
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test the LIKE condition with '%' in the pattern.
+ *
+ * - "phone LIKE '12%3'" is
true
for '12993' and
+ * false
for '1234'
+ *
+ */
+ @Test
+ public void testLike_1() {
+ try {
+ receiverConnection.stop();
+ receiver = receiverSession.createReceiver(receiverQueue,
+ "phone LIKE '12%3'");
+ receiverConnection.start();
+
+ TextMessage dummyMessage = senderSession.createTextMessage();
+ dummyMessage.setStringProperty("phone", "1234");
+ dummyMessage.setText("testLike_1:1");
+ sender.send(dummyMessage);
+
+ TextMessage message = senderSession.createTextMessage();
+ message.setStringProperty("phone", "12993");
+ message.setText("testLike_1:2");
+ sender.send(message);
+
+ TextMessage msg = (TextMessage) receiver.receive(TestConfig.TIMEOUT);
+ assertTrue("Message not received", msg != null);
+ assertTrue("Message of another test: " + msg.getText(), msg.getText()
+ .startsWith("testLike_1"));
+ assertEquals("testLike_1:2", msg.getText());
+
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test the NULL
value in message selector.
+ *
+ */
+ @Test
+ public void testNull() {
+ try {
+ receiverConnection.stop();
+ receiver = receiverSession.createReceiver(receiverQueue,
+ "prop_name IS NULL");
+ receiverConnection.start();
+
+ TextMessage dummyMessage = senderSession.createTextMessage();
+ dummyMessage.setStringProperty("prop_name", "not null");
+ dummyMessage.setText("testNull:1");
+ sender.send(dummyMessage);
+
+ TextMessage message = senderSession.createTextMessage();
+ message.setText("testNull:2");
+ sender.send(message);
+
+ TextMessage msg = (TextMessage) receiver.receive(TestConfig.TIMEOUT);
+ assertTrue(msg != null);
+ assertEquals("testNull:2", msg.getText());
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/conform/session/QueueSessionTest.java b/joram/joram/client/jms/src/test/java/jms/conform/session/QueueSessionTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..61742deff82a1e461bac72d7a35288c0923f5e36
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/conform/session/QueueSessionTest.java
@@ -0,0 +1,174 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2002 - 2007 ScalAgent Distributed Technologies
+ * Copyright (C) 2002 INRIA
+ * Contact: joram-team@objectweb.org
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s): Jeff Mesnil (Inria)
+ * Contributor(s): Nicolas Tachker (ScalAgent D.T.)
+ */
+
+package jms.conform.session;
+
+import javax.jms.InvalidDestinationException;
+import javax.jms.InvalidSelectorException;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.Queue;
+import javax.jms.QueueBrowser;
+import javax.jms.TextMessage;
+
+import org.junit.jupiter.api.Test;
+
+import jms.framework.PTPTestCase;
+import jms.framework.TestConfig;
+
+
+/**
+ * Test queue sessions
+ * See JMS specifications, 4.4 Session
+ */
+public class QueueSessionTest extends PTPTestCase {
+
+ /**
+ * Test that if we rollback a transaction which has consumed a message, the
+ * message is effectively redelivered.
+ */
+ @Test
+ public void testRollbackRececeivedMessage() {
+ try {
+ senderConnection.stop();
+ // senderSession has been created as non transacted
+ // we create it again but as a transacted session
+ senderSession = senderConnection.createQueueSession(true, 0);
+ assertEquals(true, senderSession.getTransacted());
+ // we create again the sender
+ sender = senderSession.createSender(senderQueue);
+ senderConnection.start();
+
+ receiverConnection.stop();
+ // receiverSession has been created as non transacted
+ // we create it again but as a transacted session
+ receiverSession = receiverConnection.createQueueSession(true, 0);
+ assertEquals(true, receiverSession.getTransacted());
+ // we create again the receiver
+ receiver = receiverSession.createReceiver(receiverQueue);
+ receiverConnection.start();
+
+ // we send a message...
+ TextMessage message = senderSession.createTextMessage();
+ message.setText("testRollbackRececeivedMessage");
+ sender.send(message);
+ // ... and commit the *producer* transaction
+ senderSession.commit();
+
+ // we receive a message...
+ Message m = receiver.receive(TestConfig.TIMEOUT);
+ assertTrue(m != null);
+ assertTrue(m instanceof TextMessage);
+ TextMessage msg = (TextMessage) m;
+ // ... which is the one which was sent...
+ assertEquals("testRollbackRececeivedMessage", msg.getText());
+ // ...and has not been redelivered
+ assertEquals(false, msg.getJMSRedelivered());
+
+ // we rollback the *consumer* transaction
+ receiverSession.rollback();
+
+ // we receive again a message
+ m = receiver.receive(TestConfig.TIMEOUT);
+ assertTrue(m != null);
+ assertTrue(m instanceof TextMessage);
+ msg = (TextMessage) m;
+ // ... which is still the one which was sent...
+ assertEquals("testRollbackRececeivedMessage", msg.getText());
+ // .. but this time, it has been redelivered
+ assertEquals(true, msg.getJMSRedelivered());
+
+ } catch (Exception e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test that a call to the createBrowser()
method with an
+ * invalid messaeg session throws a
+ * javax.jms.InvalidSelectorException
.
+ */
+ @Test
+ public void testCreateBrowser_2() {
+ try {
+ QueueBrowser browser = senderSession.createBrowser(senderQueue,
+ "definitely not a message selector!");
+ fail("Should throw a javax.jms.InvalidSelectorException.\n");
+ } catch (InvalidSelectorException e) {
+ } catch (JMSException e) {
+ fail("Should throw a javax.jms.InvalidSelectorException, not a " + e);
+ }
+ }
+
+ /**
+ * Test that a call to the createBrowser()
method with an
+ * invalid Queue
throws a
+ * javax.jms.InvalidDestinationException
.
+ */
+ @Test
+ public void testCreateBrowser_1() {
+ try {
+ QueueBrowser browser = senderSession.createBrowser((Queue) null);
+ fail("Should throw a javax.jms.InvalidDestinationException.\n");
+ } catch (InvalidDestinationException e) {
+ } catch (JMSException e) {
+ fail("Should throw a javax.jms.InvalidDestinationException, not a " + e);
+ }
+ }
+
+ /**
+ * Test that a call to the createReceiver()
method with an
+ * invalid message selector throws a
+ * javax.jms.InvalidSelectorException
.
+ */
+ @Test
+ public void testCreateReceiver_2() {
+ try {
+ receiver = senderSession.createReceiver(senderQueue,
+ "definitely not a message selector!");
+ fail("Should throw a javax.jms.InvalidSelectorException.\n");
+ } catch (InvalidSelectorException e) {
+ } catch (JMSException e) {
+ fail("Should throw a javax.jms.InvalidSelectorException, not a " + e);
+ }
+ }
+
+ /**
+ * Test that a call to the createReceiver()
method with an
+ * invalid Queue
throws a
+ * javax.jms.InvalidDestinationException
>
+ */
+ @Test
+ public void testCreateReceiver_1() {
+ try {
+ receiver = senderSession.createReceiver((Queue) null);
+ fail("Should throw a javax.jms.InvalidDestinationException.\n");
+ } catch (InvalidDestinationException e) {
+ } catch (JMSException e) {
+ fail("Should throw a javax.jms.InvalidDestinationException, not a " + e);
+ }
+ }
+
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/conform/session/SessionTest.java b/joram/joram/client/jms/src/test/java/jms/conform/session/SessionTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..f411f618188f7b507f3e7173cee565209dadd0e1
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/conform/session/SessionTest.java
@@ -0,0 +1,276 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2002 - 2007 ScalAgent Distributed Technologies
+ * Copyright (C) 2002 INRIA
+ * Contact: joram-team@objectweb.org
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s): Jeff Mesnil (Inria)
+ * Contributor(s): Nicolas Tachker (ScalAgent D.T.)
+ */
+
+package jms.conform.session;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+import org.junit.jupiter.api.Test;
+
+import jms.framework.PTPTestCase;
+import jms.framework.TestConfig;
+
+
+/**
+ * Test sessions
+ * See JMS specifications, 4.4 Session
+ */
+public class SessionTest extends PTPTestCase {
+
+ /**
+ * Test that an attempt to call the recover()
method on a
+ * transacted Session
throws a
+ * javax.jms.IllegalStateException
.
+ */
+ @Test
+ public void testRecoverTransactedSession() {
+ try {
+ // senderSession has been created as non transacted
+ assertEquals(false, senderSession.getTransacted());
+ // we create it again but as a transacted session
+ senderSession = senderConnection.createQueueSession(true, 0);
+ assertEquals(true, senderSession.getTransacted());
+ senderSession.recover();
+ fail("Should raise an IllegalStateException, the session is not transacted.\n");
+ } catch (javax.jms.IllegalStateException e) {
+ } catch (java.lang.IllegalStateException e) {
+ fail("Should raise a javax.jms.IllegalStateException, not a java.lang.IllegalStateException.\n");
+ } catch (Exception e) {
+ fail("Should raise a javax.jms.IllegalStateException, not a " + e);
+ }
+ }
+
+ /**
+ * Test that a call to the rollback()
method on a
+ * transacted Session
rollbacks all the
+ * messages sent in the transaction.
+ */
+ @Test
+ public void testRollbackTransactedSession() {
+ try {
+ // re-create senderSession as a transacted session
+ senderSession = senderConnection.createQueueSession(true, 0);
+ sender = senderSession.createSender(senderQueue);
+ assertEquals(true, senderSession.getTransacted());
+
+ TextMessage message = senderSession.createTextMessage();
+ message.setText("testRollbackTransactedSession");
+ // send a message within a transacted session
+ sender.send(message);
+
+ // rollback the transaction -> the sent message shouldn't be received
+ senderSession.rollback();
+
+ TextMessage m = (TextMessage) receiver.receiveNoWait();
+ // test that no message has been received
+ assertEquals(null, m);
+ } catch (Exception e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test that a call to the rollback()
method on a
+ * transacted Session
rollbacks all the
+ * messages sent in the transaction.
+ */
+ @Test
+ public void testCommitTransactedSession() {
+ try {
+ // re-create senderSession as a transacted session
+ senderSession = senderConnection.createQueueSession(true, 0);
+ sender = senderSession.createSender(senderQueue);
+ assertEquals(true, senderSession.getTransacted());
+
+ TextMessage message = senderSession.createTextMessage();
+ message.setText("testCommitTransactedSession");
+ // send a message within a transacted session
+ sender.send(message);
+
+ TextMessage m = (TextMessage) receiver.receiveNoWait();
+ // test that no message has been received (the transaction has not been
+ // committed yet)
+ assertEquals(null, m);
+
+ // commit the transaction -> the sent message should be received
+ senderSession.commit();
+
+ m = (TextMessage) receiver.receive(TestConfig.TIMEOUT);
+ assertTrue(m != null);
+ assertEquals("testCommitTransactedSession", m.getText());
+ } catch (Exception e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test that an attempt to call the roolback()
method on a
+ * non transacted Session
throws a
+ * javax.jms.IllegalStateException
.
+ */
+ @Test
+ public void testRollbackNonTransactedSession() {
+ try {
+ // senderSession has been created as non transacted in the setUp() method
+ assertEquals(false, senderSession.getTransacted());
+ senderSession.rollback();
+ fail("Should raise an IllegalStateException, the session is not transacted.\n");
+ } catch (javax.jms.IllegalStateException e) {
+ } catch (java.lang.IllegalStateException e) {
+ fail("Should raise a javax.jms.IllegalStateException, not a java.lang.IllegalStateException.\n");
+ } catch (Exception e) {
+ fail("Should raise a javax.jms.IllegalStateException, not a " + e);
+ }
+ }
+
+ /**
+ * Test that an attempt to call the commit()
method on a
+ * non transacted Session
throws a
+ * javax.jms.IllegalStateException
.
+ */
+ @Test
+ public void testCommitNonTransactedSession() {
+ try {
+ // senderSession has been created as non transacted in the setUp() method
+ assertEquals(false, senderSession.getTransacted());
+ senderSession.commit();
+ fail("Should raise an IllegalStateException, the session is not transacted.\n");
+ } catch (javax.jms.IllegalStateException e) {
+ } catch (java.lang.IllegalStateException e) {
+ fail("Should raise a javax.jms.IllegalStateException, not a java.lang.IllegalStateException.\n");
+ } catch (Exception e) {
+ fail("Should raise a javax.jms.IllegalStateException, not a " + e);
+ }
+ }
+
+ /**
+ * Test that the getTransacted()
method of a
+ * Session
returns true
if the session is
+ * transacted, false
else.
+ */
+ @Test
+ public void testGetTransacted() {
+ try {
+ // senderSession has been created as non transacted
+ assertEquals(false, senderSession.getTransacted());
+ // we re-create senderSession as a transacted session
+ senderSession = senderConnection.createQueueSession(true,
+ Session.AUTO_ACKNOWLEDGE);
+ assertEquals(true, senderSession.getTransacted());
+ } catch (Exception e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test that invoking the acknowledge()
method of a received
+ * message from a closed session must throw an
+ * IllegalStateException
.
+ */
+ @Test
+ public void testAcknowledge() {
+ try {
+ receiverSession = receiverConnection.createQueueSession(false,
+ Session.CLIENT_ACKNOWLEDGE);
+ receiver = receiverSession.createReceiver(receiverQueue);
+
+ Message message = senderSession.createMessage();
+ sender.send(message);
+
+ Message m = receiver.receive(TestConfig.TIMEOUT);
+ receiverSession.close();
+ m.acknowledge();
+ fail("4.4.1 Invoking the acknowledge method of a received message from a closed "
+ + " session must throw an [javax.jms.]IllegalStateException.\n");
+ } catch (javax.jms.IllegalStateException e) {
+ } catch (JMSException e) {
+ fail("Should raise a javax.jms.IllegalStateException, not a " + e);
+ } catch (java.lang.IllegalStateException e) {
+ fail("4.4.1 Invoking the acknowledge method of a received message from a closed "
+ + "session must throw an [javax.jms.]IllegalStateException, "
+ + "[not a java.lang.IllegalStateException]");
+ }
+ }
+
+ /**
+ * Test that it is valid to use message objects created or received via the
+ * [closed] session with the exception of a received message
+ * acknowledge()
method.
+ */
+ @Test
+ public void testUseMessage() {
+ try {
+ TextMessage message = senderSession.createTextMessage();
+ message.setText("testUseMessage");
+ sender.send(message);
+
+ TextMessage m = (TextMessage) receiver.receive(TestConfig.TIMEOUT);
+ receiverSession.close();
+ assertEquals("testUseMessage", m.getText());
+ } catch (Exception e) {
+ fail("4.4.1 It is valid to continue to use message objects created or received via "
+ + "the [closed] session.\n");
+ }
+ }
+
+ /**
+ * Test that an attempt to use a Session
which has been closed
+ * throws a javax.jms.IllegalStateException
.
+ */
+ @Test
+ public void testUsedClosedSession() {
+ try {
+ senderSession.close();
+ senderSession.createMessage();
+ fail("4.4.1 An attempt to use [a closed session] must throw a [javax.jms.]IllegalStateException.\n");
+ } catch (javax.jms.IllegalStateException e) {
+ } catch (JMSException e) {
+ fail("Should raise a javax.jms.IllegalStateException, not a " + e);
+ } catch (java.lang.IllegalStateException e) {
+ fail("Should raise a javax.jms.IllegalStateException, not a java.lang.IllegalStateException");
+ }
+ }
+
+ /**
+ * Test that closing a closed session does not throw an
+ * exception.
+ */
+ @Test
+ public void testCloseClosedSession() {
+ try {
+ // senderSession is already started
+ // we close it once
+ senderSession.close();
+ // we close it a second time
+ senderSession.close();
+ } catch (Exception e) {
+ fail("4.4.1 Closing a closed session must NOT throw an exception.\n");
+ }
+ }
+
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/conform/session/TopicSessionTest.java b/joram/joram/client/jms/src/test/java/jms/conform/session/TopicSessionTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..e007d429ea0b42c47ce41ac1de49eea0dcd3dcf8
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/conform/session/TopicSessionTest.java
@@ -0,0 +1,254 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2002 - 2007 ScalAgent Distributed Technologies
+ * Copyright (C) 2002 INRIA
+ * Contact: joram-team@objectweb.org
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s): Jeff Mesnil (Inria)
+ * Contributor(s): Nicolas Tachker (ScalAgent D.T.)
+ * Contributor(s): Andreas Mueller .
+ */
+
+package jms.conform.session;
+
+import javax.jms.InvalidDestinationException;
+import javax.jms.InvalidSelectorException;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.jms.Topic;
+
+import org.junit.jupiter.api.Test;
+
+import jms.framework.PubSubTestCase;
+import jms.framework.TestConfig;
+
+
+/**
+ * Test topic sessions
+ * See JMS specifications, 4.4 Session
+ */
+public class TopicSessionTest extends PubSubTestCase {
+
+ /**
+ * Test that if we rollback a transaction which has consumed a message, the
+ * message is effectively redelivered.
+ */
+ @Test
+ public void testRollbackReceivedMessage() {
+ try {
+ publisherConnection.stop();
+ // publisherSession has been declared has non transacted
+ // we recreate it as a transacted session
+ publisherSession = publisherConnection.createTopicSession(true, 0);
+ assertEquals(true, publisherSession.getTransacted());
+ // we also recreate the publisher
+ publisher = publisherSession.createPublisher(publisherTopic);
+ publisherConnection.start();
+
+ subscriberConnection.stop();
+ // subscriberSession has been declared has non transacted
+ // we recreate it as a transacted session
+ subscriberSession = subscriberConnection.createTopicSession(true, 0);
+ assertEquals(true, subscriberSession.getTransacted());
+ // we also recreate the subscriber
+ subscriber = subscriberSession.createSubscriber(subscriberTopic);
+ subscriberConnection.start();
+
+ // we create a message...
+ TextMessage message = publisherSession.createTextMessage();
+ message.setText("testRollbackReceivedMessage");
+ // ... publish it ...
+ publisher.publish(message);
+ // ... and commit the transaction
+ publisherSession.commit();
+
+ // we receive it
+ Message msg1 = subscriber.receive(TestConfig.TIMEOUT);
+ assertTrue("no message received", msg1 != null);
+ assertTrue(msg1 instanceof TextMessage);
+ assertEquals("testRollbackReceivedMessage", ((TextMessage) msg1)
+ .getText());
+
+ // we rollback the transaction of subscriberSession
+ subscriberSession.rollback();
+
+ // we expect to receive a second time the message
+ Message msg2 = subscriber.receive(TestConfig.TIMEOUT);
+ assertTrue("no message received after rollbacking subscriber session.",
+ msg2 != null);
+ assertTrue(msg2 instanceof TextMessage);
+ assertEquals("testRollbackReceivedMessage", ((TextMessage) msg2)
+ .getText());
+
+ // finally we commit the subscriberSession transaction
+ subscriberSession.commit();
+ } catch (Exception e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test that a durable subscriber effectively receives the messages sent to
+ * its topic while it was inactive.
+ */
+ @Test
+ public void testDurableSubscriber() {
+ try {
+ subscriber = subscriberSession.createDurableSubscriber(subscriberTopic,
+ "testTopic");
+ subscriberConnection.close();
+ subscriberConnection = null;
+
+ TextMessage message = publisherSession.createTextMessage();
+ message.setText("test");
+ publisher.publish(message);
+
+ subscriberConnection = subscriberTCF.createTopicConnection();
+ if (subscriberConnection.getClientID() == null) {
+ subscriberConnection.setClientID("subscriberConnection");
+ }
+ subscriberSession = subscriberConnection.createTopicSession(false,
+ Session.AUTO_ACKNOWLEDGE);
+ subscriber = subscriberSession.createDurableSubscriber(subscriberTopic,
+ "testTopic");
+ subscriberConnection.start();
+
+ TextMessage m = (TextMessage) subscriber.receive(TestConfig.TIMEOUT);
+ assertTrue(m != null);
+ assertEquals("test", m.getText());
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ @Test
+ public void testDurableConsumer() {
+ javax.jms.MessageConsumer subscriber=null;
+ try {
+ subscriber = subscriberSession.createDurableConsumer(subscriberTopic,
+ "testTopic");
+ subscriberConnection.close();
+ subscriberConnection = null;
+
+ TextMessage message = publisherSession.createTextMessage();
+ message.setText("test");
+ publisher.publish(message);
+
+ subscriberConnection = subscriberTCF.createTopicConnection();
+ if (subscriberConnection.getClientID() == null) {
+ subscriberConnection.setClientID("subscriberConnection");
+ }
+ subscriberSession = subscriberConnection.createTopicSession(false,
+ Session.AUTO_ACKNOWLEDGE);
+ subscriber = subscriberSession.createDurableConsumer(subscriberTopic,
+ "testTopic");
+ subscriberConnection.start();
+
+ TextMessage m = (TextMessage) subscriber.receive(TestConfig.TIMEOUT);
+ assertTrue(m != null);
+ assertEquals("test", m.getText());
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test the unsubscription of a durable subscriber.
+ */
+ @Test
+ public void testUnsubscribe() {
+ try {
+ subscriber = subscriberSession.createDurableSubscriber(subscriberTopic,
+ "topic");
+ subscriber.close();
+ // nothing should happen when unsubscribing the durable subscriber
+ subscriberSession.unsubscribe("topic");
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+ /**
+ * Test that a call to the createDurableSubscriber()
method
+ * with an invalid message selector throws a
+ * javax.jms.InvalidSelectorException
.
+ */
+ @Test
+ public void testCreateDurableSubscriber_2() {
+ try {
+ subscriberSession.createDurableSubscriber(subscriberTopic, "topic",
+ "definitely not a message selector!", true);
+ fail("Should throw a javax.jms.InvalidSelectorException.\n");
+ } catch (InvalidSelectorException e) {
+ } catch (JMSException e) {
+ fail("Should throw a javax.jms.InvalidSelectorException, not a " + e);
+ }
+ }
+
+ /**
+ * Test that a call to the createDurableSubscriber()
method
+ * with an invalid Topic
throws a
+ * javax.jms.InvalidDestinationException
.
+ */
+ @Test
+ public void testCreateDurableSubscriber_1() {
+ try {
+ subscriberSession.createDurableSubscriber((Topic) null, "topic");
+ fail("Should throw a javax.jms.InvalidDestinationException.\n");
+ } catch (InvalidDestinationException e) {
+ } catch (JMSException e) {
+ fail("Should throw a javax.jms.InvalidDestinationException, not a " + e);
+ }
+ }
+
+ /**
+ * Test that a call to the createSubscriber()
method with an
+ * invalid message selector throws a
+ * javax.jms.InvalidSelectorException
.
+ */
+ @Test
+ public void testCreateSubscriber_2() {
+ try {
+ subscriberSession.createSubscriber(subscriberTopic,
+ "definitely not a message selector!", true);
+ fail("Should throw a javax.jms.InvalidSelectorException.\n");
+ } catch (InvalidSelectorException e) {
+ } catch (JMSException e) {
+ fail("Should throw a javax.jms.InvalidSelectorException, not a " + e);
+ }
+ }
+
+ /**
+ * Test that a call to the createSubscriber()
method with an
+ * invalid Topic
throws a
+ * javax.jms.InvalidDestinationException
.
+ */
+ @Test
+ public void testCreateSubscriber_1() {
+ try {
+ subscriberSession.createSubscriber((Topic) null);
+ fail("Should throw a javax.jms.InvalidDestinationException.\n");
+ } catch (InvalidDestinationException e) {
+ } catch (JMSException e) {
+ fail("Should throw a javax.jms.InvalidDestinationException, not a " + e);
+ }
+ }
+
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/conform/session/UnifiedSessionTest.java b/joram/joram/client/jms/src/test/java/jms/conform/session/UnifiedSessionTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..72f85c0dc24ecf98dcfd430ca91f80514c5ca590
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/conform/session/UnifiedSessionTest.java
@@ -0,0 +1,262 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2002 - 2007 ScalAgent Distributed Technologies
+ * Copyright (C) 2002 INRIA
+ * Contact: joram-team@objectweb.org
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s): Jeff Mesnil (Inria)
+ * Contributor(s): Nicolas Tachker (ScalAgent D.T.)
+ */
+
+package jms.conform.session;
+
+import javax.jms.JMSException;
+import javax.jms.Queue;
+import javax.jms.QueueBrowser;
+import javax.jms.QueueConnection;
+import javax.jms.QueueSession;
+import javax.jms.ServerSessionPool;
+import javax.jms.Session;
+import javax.jms.TemporaryQueue;
+import javax.jms.TemporaryTopic;
+import javax.jms.Topic;
+import javax.jms.TopicConnection;
+import javax.jms.TopicSession;
+
+import org.junit.jupiter.api.Test;
+
+import jms.conform.connection.ConnectionTest;
+import jms.framework.UnifiedTestCase;
+
+
+/**
+ * Test unified JMS 1.1 sessions.
+ * See JMS 1.1 specifications
+ *
+ * @since JMS 1.1
+ */
+public class UnifiedSessionTest extends UnifiedTestCase {
+
+ /**
+ * QueueConnection
+ */
+ protected QueueConnection queueConnection;
+
+ /**
+ * QueueSession (non transacted, AUTO_ACKNOWLEDGE)
+ */
+ protected QueueSession queueSession;
+
+ /**
+ * TopicConnection
+ */
+ protected TopicConnection topicConnection;
+
+ /**
+ * TopicSession (non transacted, AUTO_ACKNOWLEDGE)
+ */
+ protected TopicSession topicSession;
+
+ /**
+ * Test that a call to createDurableConnectionConsumer()
method
+ * on a QueueConnection
throws a
+ * javax.jms.IllegalStateException
. (see JMS 1.1 specs, table
+ * 4-1).
+ *
+ * @since JMS 1.1
+ */
+ @Test
+ public void testCreateDurableConnectionConsumerOnQueueConnection() {
+ try {
+ queueConnection.createDurableConnectionConsumer(topic,
+ "subscriptionName", "", (ServerSessionPool) null, 1);
+ fail("Should throw a javax.jms.IllegalStateException");
+ } catch (javax.jms.IllegalStateException e) {
+ } catch (JMSException e) {
+ fail("Should throw a javax.jms.IllegalStateException, not a " + e);
+ }
+ }
+
+ /**
+ * Test that a call to createDurableSubscriber()
method on a
+ * QueueSession
throws a
+ * javax.jms.IllegalStateException
. (see JMS 1.1 specs, table
+ * 4-1).
+ *
+ * @since JMS 1.1
+ */
+ @Test
+ public void testCreateDurableSubscriberOnQueueSession() {
+ try {
+ queueSession.createDurableSubscriber(topic, "subscriptionName");
+ fail("Should throw a javax.jms.IllegalStateException");
+ } catch (javax.jms.IllegalStateException e) {
+ } catch (JMSException e) {
+ fail("Should throw a javax.jms.IllegalStateException, not a " + e);
+ }
+ }
+
+ /**
+ * Test that a call to createTemporaryTopic()
method on a
+ * QueueSession
throws a
+ * javax.jms.IllegalStateException
. (see JMS 1.1 specs, table
+ * 4-1).
+ *
+ * @since JMS 1.1
+ */
+ @Test
+ public void testCreateTemporaryTopicOnQueueSession() {
+ try {
+ TemporaryTopic tempTopic = queueSession.createTemporaryTopic();
+ fail("Should throw a javax.jms.IllegalStateException");
+ } catch (javax.jms.IllegalStateException e) {
+ } catch (JMSException e) {
+ fail("Should throw a javax.jms.IllegalStateException, not a " + e);
+ }
+ }
+
+ /**
+ * Test that a call to createTopic()
method on a
+ * QueueSession
throws a
+ * javax.jms.IllegalStateException
. (see JMS 1.1 specs, table
+ * 4-1).
+ *
+ * @since JMS 1.1
+ */
+ @Test
+ public void testCreateTopicOnQueueSession() {
+ try {
+ Topic tempTopic = queueSession.createTopic("topic_name");
+ fail("Should throw a javax.jms.IllegalStateException");
+ } catch (javax.jms.IllegalStateException e) {
+ } catch (JMSException e) {
+ fail("Should throw a javax.jms.IllegalStateException, not a " + e);
+ }
+ }
+
+ /**
+ * Test that a call to unsubscribe()
method on a
+ * QueueSession
throws a
+ * javax.jms.IllegalStateException
. (see JMS 1.1 specs, table
+ * 4-1).
+ *
+ * @since JMS 1.1
+ */
+ @Test
+ public void testUnsubscribeOnQueueSession() {
+ try {
+ queueSession.unsubscribe("subscriptionName");
+ fail("Should throw a javax.jms.IllegalStateException");
+ } catch (javax.jms.IllegalStateException e) {
+ } catch (JMSException e) {
+ fail("Should throw a javax.jms.IllegalStateException, not a " + e);
+ }
+ }
+
+ /**
+ * Test that a call to createBrowser()
method on a
+ * TopicSession
throws a
+ * javax.jms.IllegalStateException
. (see JMS 1.1 specs, table
+ * 4-1).
+ *
+ * @since JMS 1.1
+ */
+ @Test
+ public void testCreateBrowserOnTopicSession() {
+ try {
+ QueueBrowser queueBrowser = topicSession.createBrowser(queue);
+ fail("Should throw a javax.jms.IllegalStateException");
+ } catch (javax.jms.IllegalStateException e) {
+ } catch (JMSException e) {
+ fail("Should throw a javax.jms.IllegalStateException, not a " + e);
+ }
+ }
+
+ /**
+ * Test that a call to createQueue()
method on a
+ * TopicSession
throws a
+ * javax.jms.IllegalStateException
. (see JMS 1.1 specs, table
+ * 4-1).
+ *
+ * @since JMS 1.1
+ */
+ @Test
+ public void testCreateQueueOnTopicSession() {
+ try {
+ Queue tempQueue = topicSession.createQueue("queue_name");
+ fail("Should throw a javax.jms.IllegalStateException");
+ } catch (javax.jms.IllegalStateException e) {
+ } catch (JMSException e) {
+ fail("Should throw a javax.jms.IllegalStateException, not a " + e);
+ }
+ }
+
+ /**
+ * Test that a call to createTemporaryQueue()
method on a
+ * TopicSession
throws a
+ * javax.jms.IllegalStateException
. (see JMS 1.1 specs, table
+ * 4-1).
+ *
+ * @since JMS 1.1
+ */
+ @Test
+ public void testCreateTemporaryQueueOnTopicSession() {
+ try {
+ TemporaryQueue tempQueue = topicSession.createTemporaryQueue();
+ fail("Should throw a javax.jms.IllegalStateException");
+ } catch (javax.jms.IllegalStateException e) {
+ } catch (JMSException e) {
+ fail("Should throw a javax.jms.IllegalStateException, not a " + e);
+ }
+ }
+
+ public void setUp() {
+ super.setUp();
+ try {
+ queueConnection = queueConnectionFactory.createQueueConnection();
+ queueSession = queueConnection.createQueueSession(false,
+ Session.AUTO_ACKNOWLEDGE);
+ topicConnection = topicConnectionFactory.createTopicConnection();
+ topicSession = topicConnection.createTopicSession(false,
+ Session.AUTO_ACKNOWLEDGE);
+
+ queueConnection.start();
+ topicConnection.start();
+ } catch (Exception e) {
+ // XXX
+ e.printStackTrace();
+ }
+ }
+
+ public void tearDown() {
+ try {
+ queueConnection.close();
+ topicConnection.close();
+ } catch (Exception e) {
+ // XXX
+ e.printStackTrace();
+ } finally {
+ queueConnection = null;
+ queueSession = null;
+ topicConnection = null;
+ topicSession = null;
+ super.tearDown();
+ }
+ }
+
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/conform/topic/TemporaryTopicTest.java b/joram/joram/client/jms/src/test/java/jms/conform/topic/TemporaryTopicTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..af71df94d28a65e84e380b099d2cb4cc75851e7b
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/conform/topic/TemporaryTopicTest.java
@@ -0,0 +1,81 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2002 - 2007 ScalAgent Distributed Technologies
+ * Copyright (C) 2002 INRIA
+ * Contact: joram-team@objectweb.org
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s): Jeff Mesnil (Inria)
+ * Contributor(s): Nicolas Tachker (ScalAgent D.T.)
+ */
+
+package jms.conform.topic;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.TemporaryTopic;
+import javax.jms.TextMessage;
+import javax.jms.TopicSubscriber;
+
+import org.junit.jupiter.api.Test;
+
+import jms.framework.PubSubTestCase;
+import jms.framework.TestConfig;
+
+
+/**
+ * Test the javax.jms.TemporaryTopic
features.
+ */
+public class TemporaryTopicTest extends PubSubTestCase {
+
+ private TemporaryTopic tempTopic;
+ private TopicSubscriber tempSubscriber;
+
+ /**
+ * Test a TemporaryTopic
+ */
+ @Test
+ public void testTemporaryTopic() {
+ try {
+ // we stop both publisher and subscriber connections
+ // publisherConnection.stop();
+ // subscriberConnection.stop();
+
+ // we create a temporary topic to receive messages
+ tempTopic = subscriberSession.createTemporaryTopic();
+ // we recreate the sender because it has been
+ // already created with another Destination as parameter
+ publisher = publisherSession.createPublisher(tempTopic);
+ // we create a temporary subscriber on the temporary topic
+ tempSubscriber = subscriberSession.createSubscriber(tempTopic);
+ subscriberConnection.start();
+ publisherConnection.start();
+
+ TextMessage message = publisherSession.createTextMessage();
+ message.setText("testTemporaryTopic");
+ publisher.publish(message);
+
+ Message m = tempSubscriber.receive(TestConfig.TIMEOUT);
+ assertTrue(m instanceof TextMessage);
+ TextMessage msg = (TextMessage) m;
+ assertEquals("testTemporaryTopic", msg.getText());
+ } catch (JMSException e) {
+ fail(e);
+ }
+ }
+
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/framework/JMSTestCase.java b/joram/joram/client/jms/src/test/java/jms/framework/JMSTestCase.java
new file mode 100644
index 0000000000000000000000000000000000000000..33dc20362533255f22b8a56eb204eb7615cd67ea
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/framework/JMSTestCase.java
@@ -0,0 +1,149 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2002 - 2007 ScalAgent Distributed Technologies
+ * Copyright (C) 2002 INRIA
+ * Contact: joram-team@objectweb.org
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s): Jeff Mesnil (Inria)
+ * Contributor(s): Nicolas Tachker (ScalAgent D.T.)
+ */
+
+package jms.framework;
+
+import java.io.File;
+import java.util.Properties;
+import java.util.StringTokenizer;
+
+import javax.jms.JMSException;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.ow2.joram.testutils.SCAdminClassic;
+import org.ow2.joram.testutils.SCAdminOSGi;
+
+import junit.framework.TestCase;
+
+
+
+/**
+ * Class extending framework.TestCase
to provide a new
+ * fail()
method with an Exception
as parameter.
+ *
+ * Every Test Case for JMS should extend this class instead of
+ * framework.TestCase
+ *
+ */
+public abstract class JMSTestCase extends TestCase {
+
+ /**
+ * Fails a test with an exception which will be used for a message.
+ *
+ * If the exception is an instance of javax.jms.JMSException
,
+ * the message of the failure will contained both the JMSException and its
+ * linked exception (provided there's one).
+ */
+ public void fail(Exception e) {
+ if (e instanceof javax.jms.JMSException) {
+ JMSException exception = (JMSException) e;
+ String message = e.toString();
+ Exception linkedException = exception.getLinkedException();
+ if (linkedException != null) {
+ message += " [linked exception: " + linkedException + "]";
+ }
+ super.fail(message);
+ } else {
+ super.fail(e.getMessage());
+ }
+ }
+
+ public JMSTestCase() {
+ super();
+ // Changes the class path with absolute paths
+ try {
+ Properties sysprops = System.getProperties();
+ String classpath = sysprops.getProperty("java.class.path");
+ classpath = getAbsolutePath(classpath);
+ sysprops.setProperty("java.class.path", classpath);
+ } catch (Exception exc) {
+ throw new Error("cannot set absolute classpath");
+ }
+ }
+
+/*
+ @BeforeAll
+ public static void startAgentServer() throws Exception {
+ SCAdminOSGi admin = new SCAdminOSGi();
+ //TODO select admin type ?? SCAdminClassic admin = new SCAdminClassic();
+ try {
+ admin.startAgentServer((short)0);
+ } catch (IllegalStateException exc) {
+ // The process is still alive, kill it!
+ admin.killAgentServer((short)0);
+ Thread.sleep(1000);
+ admin.startAgentServer((short)0);
+ throw(exc);
+ }
+ Thread.sleep(1000);
+ }
+
+ @AfterAll
+ public static void stopAgentServer() {
+ SCAdminOSGi admin = new SCAdminOSGi();
+ try {
+ admin.stopAgentServer((short)0);
+ } catch (Exception exc) {
+ //ignore
+ }
+ //TODO endTest() to report test results ?? also see error(exception) in old BaseTestCase
+ //endTest(null, false);
+ }
+*/
+
+ /**
+ * Change the elements of a path as absolute names.
+ * Use the property path.separator as separator.
+ *
+ * @param path path to transform
+ *
+ * @return transformed path
+ */
+ public static String getAbsolutePath(String path) throws Exception {
+ String ps = System.getProperty("path.separator");
+ StringTokenizer st = new StringTokenizer(path, ps);
+ if (! st.hasMoreTokens())
+ return path;
+
+ StringBuffer buf = new StringBuffer();
+ token_loop:
+ while (true) {
+ String tok = st.nextToken();
+ buf.append(new File(tok).getAbsolutePath());
+ if (! st.hasMoreTokens())
+ break token_loop;
+ buf.append(ps);
+ }
+
+ return buf.toString();
+ }
+
+ abstract public void setUp();
+
+ abstract public void tearDown();
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/framework/PTPTestCase.java b/joram/joram/client/jms/src/test/java/jms/framework/PTPTestCase.java
new file mode 100644
index 0000000000000000000000000000000000000000..2d70a18b957aed7ba4600532b760204f51aaa5a3
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/framework/PTPTestCase.java
@@ -0,0 +1,204 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2002 - 2007 ScalAgent Distributed Technologies
+ * Copyright (C) 2002 INRIA
+ * Contact: joram-team@objectweb.org
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s): Jeff Mesnil (Inria)
+ * Contributor(s): Nicolas Tachker (ScalAgent D.T.)
+ */
+
+package jms.framework;
+
+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.Session;
+import javax.naming.InitialContext;
+
+import fr.dyade.aaa.agent.AgentServer;
+import jms.admin.Admin;
+import jms.providers.admin.JoramAdmin;
+
+
+/**
+ * Creates convenient Point to Point JMS objects which can be needed for tests.
+ *
+ * This class defines the setUp and tearDown methods so that JMS administrated
+ * objects and other "ready to use" PTP objects (that is to say queues,
+ * sessions, senders and receviers) are available conveniently for the test
+ * cases.
+ * Classes which want that convenience should extend PTPTestCase
+ * instead of JMSTestCase
.
+ *
+ */
+public abstract class PTPTestCase extends JMSTestCase {
+
+ private Admin admin;
+ private static final String QCF_NAME = "testQCF";
+ private static final String QUEUE_NAME = "testQueue";
+
+ /**
+ * Queue used by a sender
+ */
+ protected Queue senderQueue;
+
+ /**
+ * Sender on queue
+ */
+ protected QueueSender sender;
+
+ /**
+ * QueueConnectionFactory of the sender
+ */
+ protected QueueConnectionFactory senderQCF;
+
+ /**
+ * QueueConnection of the sender
+ */
+ protected QueueConnection senderConnection;
+
+ /**
+ * QueueSession of the sender (non transacted, AUTO_ACKNOWLEDGE)
+ */
+ protected QueueSession senderSession;
+
+ /**
+ * Queue used by a receiver
+ */
+ protected Queue receiverQueue;
+
+ /**
+ * Receiver on queue
+ */
+ protected QueueReceiver receiver;
+
+ /**
+ * QueueConnectionFactory of the receiver
+ */
+ protected QueueConnectionFactory receiverQCF;
+
+ /**
+ * QueueConnection of the receiver
+ */
+ protected QueueConnection receiverConnection;
+
+ /**
+ * QueueSession of the receiver (non transacted, AUTO_ACKNOWLEDGE)
+ */
+ protected QueueSession receiverSession;
+
+ /**
+ * Create all administrated objects connections and sessions ready to use for
+ * tests.
+ * Start connections.
+ */
+ public void setUp() {
+ try {
+ // Admin step
+ // gets the provider administration wrapper...
+ if (admin == null) {
+ admin = new JoramAdmin();
+ }
+
+ if (senderQCF == null)
+ senderQCF = admin.createQueueConnectionFactory(QCF_NAME);
+ if (senderQueue == null)
+ senderQueue = admin.createQueue(QUEUE_NAME);
+
+ senderConnection = senderQCF.createQueueConnection();
+ senderSession = senderConnection.createQueueSession(false,
+ Session.AUTO_ACKNOWLEDGE);
+ sender = senderSession.createSender(senderQueue);
+
+ if (receiverQCF == null)
+ receiverQCF = admin.createQueueConnectionFactory(QCF_NAME);
+ if (receiverQueue == null)
+ receiverQueue = admin.createQueue(QUEUE_NAME);
+
+ receiverConnection = receiverQCF.createQueueConnection();
+ receiverSession = receiverConnection.createQueueSession(false,
+ Session.AUTO_ACKNOWLEDGE);
+ receiver = receiverSession.createReceiver(receiverQueue);
+
+ senderConnection.start();
+ receiverConnection.start();
+ // end of client step
+
+ } catch (Exception e) {
+ // XXX
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Close connections and delete administrated objects
+ */
+ public void tearDown() {
+ try {
+ if (senderConnection != null)
+ senderConnection.close();
+
+ if (receiverConnection != null)
+ receiverConnection.close();
+
+ if (admin != null) {
+ admin.deleteQueueConnectionFactory(QCF_NAME);
+ admin.deleteQueue(senderQueue);
+ admin.disconnect();
+ admin = null;
+ }
+ } catch (Exception e) {
+ // XXX
+ e.printStackTrace();
+ } finally {
+ senderQueue = null;
+ sender = null;
+ senderQCF = null;
+ senderSession = null;
+ senderConnection = null;
+
+ receiverQueue = null;
+ receiver = null;
+ receiverQCF = null;
+ receiverSession = null;
+ receiverConnection = null;
+ }
+ }
+
+ public Admin getJoramAdmin() {
+ return admin;
+ }
+
+ /*
+ public static void main(String args[]) throws Exception {
+ System.setProperty("felix.dir", "/home/gibello/STAMP/JORAM_NEW/joram/joram/ship/bin");
+ java.nio.file.Path path = java.nio.file.FileSystems.getDefault().getPath(".").toAbsolutePath();
+ System.out.println(path);
+ (new PTPTestCase()).startAgentServer();
+ Thread.sleep(1000);
+ JoramAdmin admin = new JoramAdmin();
+ Thread.sleep(1000);
+ admin.disconnect();
+ System.exit(0);
+ }
+ */
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/framework/PubSubTestCase.java b/joram/joram/client/jms/src/test/java/jms/framework/PubSubTestCase.java
new file mode 100644
index 0000000000000000000000000000000000000000..33203919b394945d9c76387807f3f959f97058f7
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/framework/PubSubTestCase.java
@@ -0,0 +1,192 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2002 - 2007 ScalAgent Distributed Technologies
+ * Copyright (C) 2002 INRIA
+ * Contact: joram-team@objectweb.org
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s): Jeff Mesnil (Inria)
+ * Contributor(s): Nicolas Tachker (ScalAgent D.T.)
+ */
+
+package jms.framework;
+
+import javax.jms.Session;
+import javax.jms.Topic;
+import javax.jms.TopicConnection;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.TopicPublisher;
+import javax.jms.TopicSession;
+import javax.jms.TopicSubscriber;
+
+import jms.admin.Admin;
+import jms.providers.admin.JoramAdmin;
+
+
+/**
+ * Creates convenient JMS Publish/Subscribe objects which can be needed for
+ * tests.
+ * This class defines the setUp and tearDown methods so that JMS administrated
+ * objects and other "ready to use" Pub/Sub objects (that is to say topics,
+ * sessions, publishers and subscribers) are available conveniently for the test
+ * cases.
+ * Classes which want that convenience should extend PubSubTestCase
+ * instead of JMSTestCase
.
+ *
+ */
+public abstract class PubSubTestCase extends JMSTestCase {
+
+ private Admin admin;
+ //private InitialContext ctx;
+ private static final String TCF_NAME = "testTCF";
+ private static final String TOPIC_NAME = "testTopic";
+
+ /**
+ * Topic used by a publisher
+ */
+ protected Topic publisherTopic;
+
+ /**
+ * Publisher on queue
+ */
+ protected TopicPublisher publisher;
+
+ /**
+ * TopicConnectionFactory of the publisher
+ */
+ protected TopicConnectionFactory publisherTCF;
+
+ /**
+ * TopicConnection of the publisher
+ */
+ protected TopicConnection publisherConnection;
+
+ /**
+ * TopicSession of the publisher (non transacted, AUTO_ACKNOWLEDGE)
+ */
+ protected TopicSession publisherSession;
+
+ /**
+ * Topic used by a subscriber
+ */
+ protected Topic subscriberTopic;
+
+ /**
+ * Subscriber on queue
+ */
+ protected TopicSubscriber subscriber;
+
+ /**
+ * TopicConnectionFactory of the subscriber
+ */
+ protected TopicConnectionFactory subscriberTCF;
+
+ /**
+ * TopicConnection of the subscriber
+ */
+ protected TopicConnection subscriberConnection;
+
+ /**
+ * TopicSession of the subscriber (non transacted, AUTO_ACKNOWLEDGE)
+ */
+ protected TopicSession subscriberSession;
+
+ /**
+ * Create all administrated objects connections and sessions ready to use for
+ * tests.
+ * Start connections.
+ */
+ public void setUp() {
+ try {
+ // Admin step
+ // gets the provider administration wrapper...
+ if (admin == null) {
+ admin = new JoramAdmin();
+ }
+
+ if (publisherTCF == null)
+ publisherTCF = admin.createTopicConnectionFactory(TCF_NAME);
+ if (publisherTopic == null)
+ publisherTopic = admin.createTopic(TOPIC_NAME);
+
+ publisherConnection = publisherTCF.createTopicConnection();
+ if (publisherConnection.getClientID() == null) {
+ publisherConnection.setClientID("publisherConnection");
+ }
+
+ publisherSession = publisherConnection.createTopicSession(false,
+ Session.AUTO_ACKNOWLEDGE);
+ publisher = publisherSession.createPublisher(publisherTopic);
+
+ if (subscriberTCF == null)
+ subscriberTCF = admin.createTopicConnectionFactory(TCF_NAME);
+ if (subscriberTopic == null)
+ subscriberTopic = admin.createTopic(TOPIC_NAME);
+
+ subscriberConnection = subscriberTCF.createTopicConnection();
+ if (subscriberConnection.getClientID() == null) {
+ subscriberConnection.setClientID("subscriberConnection");
+ }
+
+ subscriberSession = subscriberConnection.createTopicSession(false,
+ Session.AUTO_ACKNOWLEDGE);
+ subscriber = subscriberSession.createSubscriber(subscriberTopic);
+
+ publisherConnection.start();
+ subscriberConnection.start();
+ // end of client step
+ } catch (Exception e) {
+ // XXX
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Close connections and delete administrated objects
+ */
+ public void tearDown() {
+ try {
+ if (publisherConnection != null)
+ publisherConnection.close();
+ if (subscriberConnection != null)
+ subscriberConnection.close();
+
+ if (admin != null) {
+ admin.deleteTopicConnectionFactory(TCF_NAME);
+ admin.deleteTopic(subscriberTopic);
+ admin.disconnect();
+ admin = null;
+ }
+ } catch (Exception e) {
+ // XXX
+ e.printStackTrace();
+ } finally {
+ publisherTopic = null;
+ publisher = null;
+ publisherTCF = null;
+ publisherSession = null;
+ publisherConnection = null;
+
+ subscriberTopic = null;
+ subscriber = null;
+ subscriberTCF = null;
+ subscriberSession = null;
+ subscriberConnection = null;
+ }
+ }
+
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/framework/TestConfig.java b/joram/joram/client/jms/src/test/java/jms/framework/TestConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..0a0522353a498cd6c23549bdb8acb9b1589de90b
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/framework/TestConfig.java
@@ -0,0 +1,63 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2002 - 2007 ScalAgent Distributed Technologies
+ * Copyright (C) 2002 INRIA
+ * Contact: joram-team@objectweb.org
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s): Jeff Mesnil (Inria)
+ * Contributor(s): Nicolas Tachker (ScalAgent D.T.)
+ */
+
+package jms.framework;
+import java.util.Properties;
+
+/**
+ * Class used to provide configurable options in a convenient way
+ *
+ * @author Jeff Mesnil (jmesnil@inrialpes.fr)
+ * @version $Id: TestConfig.java,v 1.1 2008-01-10 13:21:30 tachker Exp $
+ */
+public class TestConfig {
+
+ // name of the configuration file
+ private static final String PROP_FILE_NAME = "test.properties";
+
+ // name of the timeout property
+ private static final String PROP_NAME = "timeout";
+
+ /**
+ * timeout value used by receive
method in the tests.
+ * the value is specified in the config/test.properties
file.
+ */
+ public static final long TIMEOUT;
+
+ static {
+ // load tests.properties
+ long tempTimeOut = 0;
+ try {
+ Properties props = new Properties();
+ props.load(ClassLoader.getSystemResourceAsStream(PROP_FILE_NAME));
+ props.list(System.out);
+ tempTimeOut = Long.parseLong(props.getProperty(PROP_NAME, "0"));
+ } catch (Exception e) {
+ tempTimeOut = 0;
+ } finally {
+ TIMEOUT = tempTimeOut;
+ }
+ }
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/framework/UnifiedTestCase.java b/joram/joram/client/jms/src/test/java/jms/framework/UnifiedTestCase.java
new file mode 100644
index 0000000000000000000000000000000000000000..1035250edb801fea28d607efd47ecd4b1530f8a3
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/framework/UnifiedTestCase.java
@@ -0,0 +1,238 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2002 - 2007 ScalAgent Distributed Technologies
+ * Copyright (C) 2002 INRIA
+ * Contact: joram-team@objectweb.org
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s): Jeff Mesnil (Inria)
+ * Contributor(s): Nicolas Tachker (ScalAgent D.T.)
+ */
+
+package jms.framework;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Destination;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.Session;
+import javax.jms.Topic;
+import javax.jms.TopicConnectionFactory;
+
+import jms.admin.Admin;
+import jms.providers.admin.JoramAdmin;
+
+
+/**
+ * Creates convenient Unified JMS 1.1 objects which can be needed for tests.
+ *
+ * This class defines the setUp and tearDown methods so that JMS administrated
+ * objects and other "ready to use" JMS objects (that is to say destinations,
+ * sessions, producers and consumers) are available conveniently for the test
+ * cases.
+ * Classes which want that convenience should extend
+ * UnifiedTestCase
instead of JMSTestCase
.
+ *
+ * @since JMS 1.1
+ */
+public abstract class UnifiedTestCase extends JMSTestCase {
+
+ protected Admin admin;
+ //protected InitialContext ctx;
+ private static final String CF_NAME = "testCF";
+ private static final String TCF_NAME = "testTCF";
+ private static final String QCF_NAME = "testQCF";
+ private static final String DESTINATION_NAME = "testDestination";
+ private static final String QUEUE_NAME = "testQueue";
+ private static final String TOPIC_NAME = "testTopic";
+
+ // //////////////////
+ // Unified Domain //
+ // //////////////////
+
+ /**
+ * Destination used by a producer
+ */
+ protected Destination producerDestination;
+
+ /**
+ * Producer
+ */
+ protected MessageProducer producer;
+
+ /**
+ * ConnectionFactory of the producer
+ */
+ protected ConnectionFactory producerCF;
+
+ /**
+ * Connection of the producer
+ */
+ protected Connection producerConnection;
+
+ /**
+ * Session of the producer (non transacted, AUTO_ACKNOWLEDGE)
+ */
+ protected Session producerSession;
+
+ /**
+ * Destination used by a consumer
+ */
+ protected Destination consumerDestination;
+
+ /**
+ * Consumer on destination
+ */
+ protected MessageConsumer consumer;
+
+ /**
+ * ConnectionFactory of the consumer
+ */
+ protected ConnectionFactory consumerCF;
+
+ /**
+ * Connection of the consumer
+ */
+ protected Connection consumerConnection;
+
+ /**
+ * Session of the consumer (non transacted, AUTO_ACKNOWLEDGE)
+ */
+ protected Session consumerSession;
+
+ // //////////////
+ // PTP Domain //
+ // //////////////
+
+ /**
+ * QueueConnectionFactory
+ */
+ protected QueueConnectionFactory queueConnectionFactory;
+
+ /**
+ * Queue
+ */
+ protected Queue queue;
+
+ // //////////////////
+ // Pub/Sub Domain //
+ // //////////////////
+
+ /**
+ * TopicConnectionFactory
+ */
+ protected TopicConnectionFactory topicConnectionFactory;
+
+ /**
+ * Topic
+ */
+ protected Topic topic;
+
+ /**
+ * Create all administrated objects connections and sessions ready to use for
+ * tests.
+ * Start connections.
+ */
+ public void setUp() {
+ try {
+ // Admin step
+ // gets the provider administration wrapper...
+ if (admin == null) {
+ admin = new JoramAdmin();
+ }
+ // ...and creates administrated objects
+
+ producerCF = admin.createConnectionFactory(CF_NAME);
+ // we see destination of the unified domain as a javax.jms.Destination
+ // instead of a javax.jms.Queue to be more generic
+ producerDestination = (Destination) admin.createQueue(DESTINATION_NAME);
+ producerConnection = producerCF.createConnection();
+ producerSession = producerConnection.createSession(false,
+ Session.AUTO_ACKNOWLEDGE);
+ producer = producerSession.createProducer(producerDestination);
+
+ consumerCF = admin.createConnectionFactory(CF_NAME);
+ // we see destination of the unified domain as a javax.jms.Destination
+ // instead of a javax.jms.Queue to be more generic
+ consumerDestination = (Destination) admin.createQueue(DESTINATION_NAME);
+ consumerConnection = consumerCF.createConnection();
+ consumerSession = consumerConnection.createSession(false,
+ Session.AUTO_ACKNOWLEDGE);
+ consumer = consumerSession.createConsumer(consumerDestination);
+
+ queueConnectionFactory = admin.createQueueConnectionFactory(QCF_NAME);
+ queue = admin.createQueue(QUEUE_NAME);
+
+ topicConnectionFactory = admin.createTopicConnectionFactory(TCF_NAME);
+ topic = admin.createTopic(TOPIC_NAME);
+
+ producerConnection.start();
+ consumerConnection.start();
+ // end of client step
+ } catch (Exception e) {
+ // XXX
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Close connections and delete administrated objects
+ */
+ public void tearDown() {
+ try {
+ if (consumerConnection != null)
+ consumerConnection.close();
+ if (producerConnection != null)
+ producerConnection.close();
+
+ if (admin != null) {
+ admin.deleteConnectionFactory(CF_NAME);
+ admin.deleteQueueConnectionFactory(QCF_NAME);
+ admin.deleteTopicConnectionFactory(TCF_NAME);
+ admin.deleteQueue(consumerDestination);
+ admin.deleteQueue(queue);
+ admin.deleteTopic(topic);
+ admin.disconnect();
+ admin = null;
+ }
+ } catch (Exception e) {
+ // XXX
+ e.printStackTrace();
+ } finally {
+ producerDestination = null;
+ producer = null;
+ producerCF = null;
+ producerSession = null;
+ producerConnection = null;
+
+ consumerDestination = null;
+ consumer = null;
+ consumerCF = null;
+ consumerSession = null;
+ consumerConnection = null;
+
+ queueConnectionFactory = null;
+ queue = null;
+
+ topicConnectionFactory = null;
+ topic = null;
+ }
+ }
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/jms2/Jms0Test.java b/joram/joram/client/jms/src/test/java/jms/jms2/Jms0Test.java
new file mode 100644
index 0000000000000000000000000000000000000000..21e0edefc55f422ae921e725d95f044ba9bf9b60
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/jms2/Jms0Test.java
@@ -0,0 +1,83 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2015 ScalAgent Distributed Technologies
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s):
+ */
+package jms.jms2;
+
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSContext;
+import javax.jms.JMSRuntimeException;
+
+import org.junit.jupiter.api.Test;
+import org.objectweb.joram.client.jms.admin.AdminModule;
+import org.objectweb.joram.client.jms.admin.User;
+import org.objectweb.joram.client.jms.tcp.TcpConnectionFactory;
+
+import junit.framework.TestCase;
+
+/**
+ * Creates a JMSContext and close it to verify that the connection is correctly closed.
+ */
+public class Jms0Test extends TestCase {
+
+ @Test
+ public void testJms() throws Exception {
+
+ ConnectionFactory cf = TcpConnectionFactory.create("localhost", 16010);
+ AdminModule.connect(cf, "root", "root");
+ User.create("anonymous", "anonymous", 0);
+ AdminModule.disconnect();
+
+ JMSContext context = cf.createContext();
+ context.close();
+
+ boolean isexc = false;
+ try {
+ context.start();
+ } catch (JMSRuntimeException exc) {
+ //exc.printStackTrace();
+ isexc = true;
+ }
+ assertTrue("JMSContext connection is not correctly closed.", isexc);
+
+ context = cf.createContext();
+ JMSContext context1 = context.createContext(0);
+ context.close();
+
+ isexc = false;
+ try {
+ context.start();
+ } catch (JMSRuntimeException exc) {
+ exc.printStackTrace();
+ isexc = true;
+ }
+ assertFalse("JMSContext connection should not be closed.", isexc);
+
+ context1.close();
+ isexc = false;
+ try {
+ context.start();
+ } catch (JMSRuntimeException exc) {
+ //exc.printStackTrace();
+ isexc = true;
+ }
+ assertTrue("JMSContext connection is not correctly closed.", isexc);
+ }
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/jms2/Jms10Test.java b/joram/joram/client/jms/src/test/java/jms/jms2/Jms10Test.java
new file mode 100644
index 0000000000000000000000000000000000000000..97f5bf402f9435d6efe804f5327baf9a6f326558
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/jms2/Jms10Test.java
@@ -0,0 +1,59 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2013 ScalAgent Distributed Technologies
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s):
+ */
+package jms.jms2;
+
+import javax.jms.ConnectionFactory;
+import javax.jms.IllegalStateRuntimeException;
+import javax.jms.JMSContext;
+import org.junit.jupiter.api.Test;
+import org.objectweb.joram.client.jms.admin.AdminModule;
+import org.objectweb.joram.client.jms.admin.User;
+import org.objectweb.joram.client.jms.tcp.TcpConnectionFactory;
+
+import junit.framework.TestCase;
+
+/**
+ * Call JMSContext.acknowledge() on a closed session which is illegal.
+ */
+public class Jms10Test extends TestCase {
+
+ @Test
+ public void testJms() throws Exception {
+
+ ConnectionFactory cf = TcpConnectionFactory.create("localhost", 16010);
+ AdminModule.connect(cf, "root", "root");
+ User.create("anonymous", "anonymous", 0);
+ AdminModule.disconnect();
+
+ JMSContext context = cf.createContext(JMSContext.CLIENT_ACKNOWLEDGE);
+ context.close();
+
+ try {
+ context.acknowledge();
+ assertTrue("Should throw an IllegalStateRuntimeException", false);
+ } catch (Exception exc) {
+ assertTrue("Expect an IllegalStateRuntimeException, got " + exc,
+ exc instanceof IllegalStateRuntimeException);
+ }
+ }
+
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/jms2/Jms11Test.java b/joram/joram/client/jms/src/test/java/jms/jms2/Jms11Test.java
new file mode 100644
index 0000000000000000000000000000000000000000..4f1218913377c2cbfbdcf045743f81c5a64a98d0
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/jms2/Jms11Test.java
@@ -0,0 +1,60 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2013 ScalAgent Distributed Technologies
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s):
+ */
+package jms.jms2;
+
+import javax.jms.ConnectionFactory;
+import javax.jms.InvalidDestinationRuntimeException;
+import javax.jms.JMSContext;
+import org.junit.jupiter.api.Test;
+import org.objectweb.joram.client.jms.admin.AdminModule;
+import org.objectweb.joram.client.jms.admin.User;
+import org.objectweb.joram.client.jms.tcp.TcpConnectionFactory;
+
+import junit.framework.TestCase;
+
+/**
+ * Testing JMSContext.unsubscribe(String) for InvalidDestinationRuntimeException.
+ */
+public class Jms11Test extends TestCase {
+
+ @Test
+ public void testJms() throws Exception {
+
+ ConnectionFactory cf = TcpConnectionFactory.create("localhost", 16010);
+ AdminModule.connect(cf, "root", "root");
+ User.create("anonymous", "anonymous", 0);
+ AdminModule.disconnect();
+
+ JMSContext context = cf.createContext(JMSContext.CLIENT_ACKNOWLEDGE);
+
+ try {
+ context.unsubscribe("toto");
+ assertTrue("Should throw an InvalidDestinationRuntimeException", false);
+ } catch (Exception exc) {
+ assertTrue("Expect an InvalidDestinationRuntimeException, got " + exc,
+ exc instanceof InvalidDestinationRuntimeException);
+ }
+
+ context.close();
+ }
+
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/jms2/Jms12Test.java b/joram/joram/client/jms/src/test/java/jms/jms2/Jms12Test.java
new file mode 100644
index 0000000000000000000000000000000000000000..5f8357b72ed3cc9b405f8c22cf360bda36e2c656
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/jms2/Jms12Test.java
@@ -0,0 +1,92 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2013 ScalAgent Distributed Technologies
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s):
+ */
+package jms.jms2;
+
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSConsumer;
+import javax.jms.JMSContext;
+import javax.jms.JMSProducer;
+import javax.jms.TextMessage;
+
+import org.junit.jupiter.api.Test;
+import org.objectweb.joram.client.jms.Queue;
+import org.objectweb.joram.client.jms.admin.AdminModule;
+import org.objectweb.joram.client.jms.admin.User;
+import org.objectweb.joram.client.jms.tcp.TcpConnectionFactory;
+
+import junit.framework.TestCase;
+
+/**
+ * Test start and stop of JMSContext.
+ */
+public class Jms12Test extends TestCase {
+
+ @Test
+ public void testJms() throws Exception {
+
+ ConnectionFactory cf = TcpConnectionFactory.create("localhost", 16010);
+ AdminModule.connect(cf, "root", "root");
+ User.create("anonymous", "anonymous", 0);
+ Queue queue = Queue.create("Jms12Test");
+ queue.setFreeReading();
+ queue.setFreeWriting();
+ AdminModule.disconnect();
+
+ JMSContext context = cf.createContext(JMSContext.CLIENT_ACKNOWLEDGE);
+ JMSProducer producer = context.createProducer();
+ JMSConsumer consumer = context.createConsumer(queue);
+ context.stop();
+
+ {
+ TextMessage msg = context.createTextMessage("message");
+
+ msg.setStringProperty("name", "first");
+ producer.send(queue, msg);
+
+ msg.setStringProperty("name", "second");
+ producer.send(queue, msg);
+
+ msg.setStringProperty("name", "last");
+ producer.send(queue, msg);
+
+ TextMessage recv = (TextMessage) consumer.receive(5000L);
+ assertTrue("Received a message on a STOPPED connection", (recv == null));
+
+ context.start();
+
+ recv = (TextMessage) consumer.receive();
+ String name = recv.getStringProperty("name");
+ assertTrue("Received bad message from started connection: " + name, "first".equals(name));
+
+ recv = (TextMessage) consumer.receive();
+ name = recv.getStringProperty("name");
+ assertTrue("Received bad message from started connection: " + name, "second".equals(name));
+
+ recv = (TextMessage) consumer.receive();
+ name = recv.getStringProperty("name");
+ assertTrue("Received bad message from started connection: " + name, "last".equals(name));
+ }
+
+ context.close();
+ }
+
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/jms2/Jms1Test.java b/joram/joram/client/jms/src/test/java/jms/jms2/Jms1Test.java
new file mode 100644
index 0000000000000000000000000000000000000000..77995a6785f760dface7cbd76e7c30ee91fc7d85
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/jms2/Jms1Test.java
@@ -0,0 +1,53 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2013 ScalAgent Distributed Technologies
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s):
+ */
+package jms.jms2;
+
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSContext;
+
+import org.junit.jupiter.api.Test;
+import org.objectweb.joram.client.jms.admin.AdminModule;
+import org.objectweb.joram.client.jms.admin.User;
+import org.objectweb.joram.client.jms.tcp.TcpConnectionFactory;
+
+import junit.framework.TestCase;
+
+/**
+ * Creates a JMSContext with the default user identity and an unspecified sessionMode.
+ */
+public class Jms1Test extends TestCase {
+
+ @Test
+ public void testJms() throws Exception {
+
+ ConnectionFactory cf = TcpConnectionFactory.create("localhost", 16010);
+ AdminModule.connect(cf, "root", "root");
+ User.create("anonymous", "anonymous", 0);
+ AdminModule.disconnect();
+
+ JMSContext context = cf.createContext();
+ // Verify that JMSContext.getSessionMode() returns JMSContext.AUTO_ACKNOWLEDGE
+ int mode = context.getSessionMode();
+ assertTrue("Bad default session mode: " + mode, (mode == JMSContext.AUTO_ACKNOWLEDGE));
+ context.close();
+ }
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/jms2/Jms2Test.java b/joram/joram/client/jms/src/test/java/jms/jms2/Jms2Test.java
new file mode 100644
index 0000000000000000000000000000000000000000..825767f560b4b70e00ae4e1c5ba652edeb134a77
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/jms2/Jms2Test.java
@@ -0,0 +1,92 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2013 ScalAgent Distributed Technologies
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s):
+ */
+package jms.jms2;
+
+import javax.jms.CompletionListener;
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.DeliveryMode;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+import org.junit.jupiter.api.Test;
+import org.objectweb.joram.client.jms.Queue;
+import org.objectweb.joram.client.jms.admin.AdminModule;
+import org.objectweb.joram.client.jms.admin.User;
+import org.objectweb.joram.client.jms.tcp.TcpConnectionFactory;
+
+import junit.framework.TestCase;
+
+/**
+ * Send a NON_PERSISTENT message in asynchronous mode.
+ */
+public class Jms2Test extends TestCase implements MessageListener, CompletionListener {
+
+ @Test
+ public void testJms() throws Exception {
+
+ ConnectionFactory cf = TcpConnectionFactory.create("localhost", 16010);
+ AdminModule.connect(cf, "root", "root");
+ User.create("anonymous", "anonymous", 0);
+ Queue queue = Queue.create("Jms2Test");
+ queue.setFreeReading();
+ queue.setFreeWriting();
+ AdminModule.disconnect();
+
+ Connection cnx = cf.createConnection();
+ Session session = cnx.createSession();
+ MessageProducer producer = session.createProducer(null);
+ MessageConsumer consumer = session.createConsumer(queue);
+ cnx.start();
+
+ TextMessage msg = session.createTextMessage("message");
+ producer.send(queue, msg, DeliveryMode.NON_PERSISTENT, Message.DEFAULT_PRIORITY, 0L, this);
+ consumer.receive();
+ assertTrue("Should complete send", sent);
+
+ cnx.close();
+ }
+
+ volatile int nbmsg = 0;
+
+ @Override
+ public void onMessage(Message message) {
+ nbmsg += 1;
+ }
+
+ volatile boolean sent = false;
+
+ @Override
+ public void onCompletion(Message message) {
+ System.out.println("sent");
+ sent = true;
+ }
+
+ @Override
+ public void onException(Message message, Exception exc) {
+ exc.printStackTrace();
+ }
+}
\ No newline at end of file
diff --git a/joram/joram/client/jms/src/test/java/jms/jms2/Jms3Test.java b/joram/joram/client/jms/src/test/java/jms/jms2/Jms3Test.java
new file mode 100644
index 0000000000000000000000000000000000000000..fd3647d08d4f1a83fd9888a33f4d2e096b74a5ee
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/jms2/Jms3Test.java
@@ -0,0 +1,224 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2013 ScalAgent Distributed Technologies
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s):
+ */
+package jms.jms2;
+
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSConsumer;
+import javax.jms.JMSContext;
+import javax.jms.JMSProducer;
+import javax.jms.MessageNotWriteableRuntimeException;
+import javax.jms.TextMessage;
+
+import org.junit.jupiter.api.Test;
+import org.objectweb.joram.client.jms.Queue;
+import org.objectweb.joram.client.jms.admin.AdminModule;
+import org.objectweb.joram.client.jms.admin.User;
+import org.objectweb.joram.client.jms.tcp.TcpConnectionFactory;
+
+import junit.framework.TestCase;
+
+/**
+ * Set properties on JMSProducer.
+ */
+public class Jms3Test extends TestCase {
+
+ @Test
+ public void testJms() throws Exception {
+ boolean bool = true;
+ byte bValue = 127;
+ short nShort = 10;
+ int nInt = 5;
+ long nLong = 333;
+ float nFloat = 1;
+ double nDouble = 100;
+ String testString = "test";
+
+ ConnectionFactory cf = TcpConnectionFactory.create("localhost", 16010);
+ AdminModule.connect(cf, "root", "root");
+ User.create("anonymous", "anonymous", 0);
+ Queue queue = Queue.create("Jms3Test");
+ queue.setFreeReading();
+ queue.setFreeWriting();
+ AdminModule.disconnect();
+
+ JMSContext context = cf.createContext();
+ JMSProducer producer = context.createProducer();
+ JMSConsumer consumer = context.createConsumer(queue);
+ context.start();
+
+ producer.setProperty("TESTBOOLEAN", bool);
+ producer.setProperty("TESTBYTE", bValue);
+ producer.setProperty("TESTDOUBLE", nDouble);
+ producer.setProperty("TESTFLOAT", nFloat);
+ producer.setProperty("TESTINT", nInt);
+ producer.setProperty("TESTLONG", nLong);
+ producer.setProperty("TESTSHORT", nShort);
+ producer.setProperty("TESTSTRING", "test");
+
+ producer.setProperty("OBJTESTBOOLEAN", Boolean.valueOf(bool) );
+ producer.setProperty("OBJTESTBYTE", Byte.valueOf(bValue));
+ producer.setProperty("OBJTESTDOUBLE", Double.valueOf(nDouble));
+ producer.setProperty("OBJTESTFLOAT", Float.valueOf(nFloat));
+ producer.setProperty("OBJTESTINT", Integer.valueOf(nInt));
+ producer.setProperty("OBJTESTLONG", Long.valueOf(nLong));
+ producer.setProperty("OBJTESTSHORT", Short.valueOf(nShort));
+ producer.setProperty("OBJTESTSTRING", "test");
+
+ try {
+ assertTrue("should return false for unknown getBooleanProperty",
+ producer.getBooleanProperty("TESTDUMMY") == false);
+ } catch (Exception e) {
+ assertTrue("Caught unexpected exception: " + e.getMessage(), false);
+ }
+ try {
+ producer.getByteProperty("TESTDUMMY");
+ assertTrue("NumberFormatException should have occurred for getByteProperty", false);
+ } catch (java.lang.NumberFormatException np) {
+ assertTrue("NumberFormatException as expected", true);
+ }
+ try {
+ producer.getShortProperty("TESTDUMMY");
+ assertTrue("NumberFormatException should have occurred for getShortProperty", false);
+ } catch (java.lang.NumberFormatException np) {
+ assertTrue("NumberFormatException as expected", true);
+ }
+ try {
+ producer.getIntProperty("TESTDUMMY");
+ assertTrue("NumberFormatException should have occurred for getIntProperty", false);
+ } catch (java.lang.NumberFormatException np) {
+ assertTrue("NumberFormatException as expected", true);
+ }
+ try {
+ producer.getLongProperty("TESTDUMMY");
+ assertTrue("NumberFormatException should have occurred for getLongProperty", false);
+ } catch (java.lang.NumberFormatException np) {
+ assertTrue("NumberFormatException as expected", true);
+ }
+ try {
+ producer.getFloatProperty("TESTDUMMY");
+ assertTrue("NullPointerException should have occurred for getFloatProperty", false);
+ } catch (java.lang.NullPointerException np) {
+ assertTrue("NullPointerException as expected", true);
+ }
+ try {
+ producer.getDoubleProperty("TESTDUMMY");
+ assertTrue("NullPointerException should have occurred for getDoubleProperty", false);
+ } catch (java.lang.NullPointerException np) {
+ assertTrue("NullPointerException as expected", true);
+ }
+
+ TextMessage msg = context.createTextMessage("message");
+ producer.send(queue, msg);
+ TextMessage recv = (TextMessage) consumer.receive();
+
+ assertTrue("incorrect value returned from getBooleanProperty",
+ recv.getBooleanProperty("TESTBOOLEAN") == bool);
+ assertTrue("incorrect value returned from getByteProperty",
+ recv.getByteProperty("TESTBYTE") == bValue);
+ assertTrue("incorrect value returned from getLongProperty",
+ recv.getLongProperty("TESTLONG") == nLong);
+ assertTrue("incorrect value returned from getStringProperty",
+ recv.getStringProperty("TESTSTRING").equals(testString));
+ assertTrue("incorrect value returned from getDoubleProperty",
+ recv.getDoubleProperty("TESTDOUBLE") == nDouble);
+ assertTrue("incorrect value returned from getFloatProperty",
+ recv.getFloatProperty("TESTFLOAT") == nFloat);
+ assertTrue("incorrect value returned from getIntProperty",
+ recv.getIntProperty("TESTINT") == nInt);
+ assertTrue("incorrect value returned from getShortProperty",
+ recv.getShortProperty("TESTSHORT") == nShort);
+ assertTrue("incorrect Boolean value returned from getObjectProperty",
+ (((Boolean) recv.getObjectProperty("OBJTESTBOOLEAN")).booleanValue() == bool));
+ assertTrue("incorrect Byte value returned from getObjectProperty",
+ (((Byte) recv.getObjectProperty("OBJTESTBYTE")).byteValue() == bValue));
+ assertTrue("incorrect Long value returned from getObjectProperty",
+ (((Long) recv.getObjectProperty("OBJTESTLONG")).longValue() == nLong));
+ assertTrue("incorrect String value returned from getObjectProperty",
+ (((String) recv.getObjectProperty("OBJTESTSTRING")).equals(testString)));
+ assertTrue("incorrect Double value returned from getObjectProperty",
+ (((Double) recv.getObjectProperty("OBJTESTDOUBLE")).doubleValue() == nDouble));
+ assertTrue("incorrect Float value returned from getObjectProperty",
+ (((Float) recv.getObjectProperty("OBJTESTFLOAT")).floatValue() == nFloat));
+ assertTrue("incorrect Integer value returned from getObjectProperty",
+ (((Integer) recv.getObjectProperty("OBJTESTINT")).intValue() == nInt));
+ assertTrue("incorrect Short value returned from getObjectProperty",
+ (((Short) recv.getObjectProperty("OBJTESTSHORT")).shortValue() == nShort));
+
+ producer.clearProperties();
+
+ // All JMSProducer properties are deleted by the clearProperties method.
+ // This leaves the message with an empty set of properties.
+
+ assertTrue("NullPointerException should have occurred for getDoubleProperty",
+ producer.getObjectProperty("OBJTESTLONG") == null);
+ try {
+ producer.getShortProperty("TESTSHORT");
+ assertTrue("NumberFormatException should have occurred for getShortProperty", false);
+ } catch (java.lang.NumberFormatException np) {
+ assertTrue("NumberFormatException as expected", true);
+ }
+
+
+ // Set/Get JMSProducer message header JMSCorrelationID as bytes.
+ {
+ byte[] cid = "TestCorrelationID".getBytes();
+ producer.setJMSCorrelationIDAsBytes(cid);
+ cid = producer.getJMSCorrelationIDAsBytes();
+ String cidString = new String(cid);
+ assertTrue("getJMSCorrelationID returned incorrect value: " + cidString,
+ ("TestCorrelationID".equals(cidString)));
+ }
+
+ // Set JMSProducer message headers (Set JMSCorrelationID, JMSType, JMSReplyTo)
+
+ String cid = "TestCorrelationID";
+ producer.setJMSCorrelationID(cid);
+ assertTrue("getJMSCorrelationID returned null", cid.equals(producer.getJMSCorrelationID()));
+ String mtype = "TestMessage";
+ producer.setJMSType(mtype);
+ assertTrue("getJMSType returned null", mtype.equals(producer.getJMSType()));
+ producer.setJMSReplyTo(queue);
+ assertTrue("getJMSReplyTo returned null", queue.equals(producer.getJMSReplyTo()));
+
+ msg = context.createTextMessage("message");
+ producer.send(queue, msg);
+ recv = (TextMessage) consumer.receive();
+
+ assertTrue("getJMSCorrelationID returned null", cid.equals(recv.getJMSCorrelationID()));
+ assertTrue("getJMSType returned null", mtype.equals(recv.getJMSType()));
+ assertTrue("getJMSReplyTo returned null", queue.equals(recv.getJMSReplyTo()));
+
+ // Using received TextMessage try and send it.
+ // Expect MessageNotWriteableRuntimeException.
+
+ producer.setProperty("OBJTESTLONG", Long.valueOf(nLong));
+ try {
+ producer.send(queue, recv);
+ assertTrue("Expected MessageNotWriteableRuntimeException to be thrown", false);
+ } catch (MessageNotWriteableRuntimeException e) {
+ } catch (Exception e) {
+ assertTrue("Caught unexpected exception: " + e.getMessage(), false);
+ }
+
+ context.close();
+ }
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/jms2/Jms4Test.java b/joram/joram/client/jms/src/test/java/jms/jms2/Jms4Test.java
new file mode 100644
index 0000000000000000000000000000000000000000..77e6b6234c24be1e0eaaceb1485dd939537c112f
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/jms2/Jms4Test.java
@@ -0,0 +1,134 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2013 ScalAgent Distributed Technologies
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s):
+ */
+package jms.jms2;
+
+import java.util.HashMap;
+
+import javax.jms.BytesMessage;
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSConsumer;
+import javax.jms.JMSContext;
+import javax.jms.JMSProducer;
+import javax.jms.MessageFormatException;
+import javax.jms.ObjectMessage;
+import javax.jms.StreamMessage;
+import javax.jms.TextMessage;
+
+import org.junit.jupiter.api.Test;
+import org.objectweb.joram.client.jms.Queue;
+import org.objectweb.joram.client.jms.admin.AdminModule;
+import org.objectweb.joram.client.jms.admin.User;
+import org.objectweb.joram.client.jms.tcp.TcpConnectionFactory;
+
+import junit.framework.TestCase;
+
+/**
+ * Test Message.getBody method exceptions.
+ */
+public class Jms4Test extends TestCase {
+
+ @Test
+ public void testJms() throws Exception {
+
+ ConnectionFactory cf = TcpConnectionFactory.create("localhost", 16010);
+ AdminModule.connect(cf, "root", "root");
+ User.create("anonymous", "anonymous", 0);
+ Queue queue = Queue.create("Jms4Test");
+ queue.setFreeReading();
+ queue.setFreeWriting();
+ AdminModule.disconnect();
+
+ JMSContext context = cf.createContext();
+ JMSProducer producer = context.createProducer();
+ JMSConsumer consumer = context.createConsumer(queue);
+ context.start();
+
+ producer.send(queue, context.createTextMessage("message"));
+ TextMessage recv1 = (TextMessage) consumer.receive();
+ assertTrue("Message not received", (recv1 != null));
+ // Call TextMessage.getBody(Boolean.class) to extract TextMessage as Boolean.
+ // Expect MessageFormatException.
+ try {
+ recv1.getBody(Boolean.class);
+ assertTrue("Expected MessageFormatException to be thrown", false);
+ } catch (MessageFormatException e) {
+ } catch (Exception e) {
+ assertTrue("Caught unexpected exception: " + e.getMessage(), false);
+ }
+
+ producer.send(queue, context.createObjectMessage(new StringBuffer("message")));
+ ObjectMessage recv2 = (ObjectMessage) consumer.receive();
+ assertTrue("Message not received", (recv2 != null));
+ // Call ObjectMessage.getBody(HashMap.class) to extract ObjectMessage as HashMap.
+ // Expect MessageFormatException.
+ try {
+ recv2.getBody(HashMap.class);
+ assertTrue("Expected MessageFormatException to be thrown", false);
+ } catch (MessageFormatException e) {
+ } catch (Exception e) {
+ assertTrue("Caught unexpected exception: " + e.getMessage(), false);
+ }
+
+ StreamMessage msg1 = context.createStreamMessage();
+ msg1.writeBoolean(true);
+ msg1.writeLong((long) 123456789);
+ producer.send(queue, msg1);
+ StreamMessage recv3 = (StreamMessage) consumer.receive();
+ assertTrue("Message not received", (recv3 != null));
+ // Call StreamMessage.getBody(HashMap.class) to extract StreamMessage as HashMap.
+ // Expect MessageFormatException.
+ try {
+ recv3.getBody(HashMap.class);
+ assertTrue("Expected MessageFormatException to be thrown", false);
+ } catch (MessageFormatException e) {
+ } catch (Exception e) {
+ assertTrue("Caught unexpected exception: " + e.getMessage(), false);
+ }
+
+ BytesMessage msg2 = context.createBytesMessage();
+ msg2.writeBoolean(true);
+ msg2.writeLong((long) 123456789);
+ try {
+ msg2.getBody(StringBuffer.class);
+ assertTrue("Expected MessageFormatException to be thrown", false);
+ } catch (MessageFormatException e) {
+ } catch (Exception e) {
+ assertTrue("Caught unexpected exception: " + e.getMessage(), false);
+ }
+
+ producer.send(queue, msg2);
+ BytesMessage recv4 = (BytesMessage) consumer.receive();
+ assertTrue("Message not received", (recv4 != null));
+ // Call BytesMessage.getBody(StringBuffer.class) to receive BytesMessage as StringBuffer
+ // Expect MessageFormatException.
+ try {
+ recv4.getBody(StringBuffer.class);
+ assertTrue("Expected MessageFormatException to be thrown", false);
+ } catch (MessageFormatException e) {
+ } catch (Exception e) {
+ assertTrue("Caught unexpected exception: " + e.getMessage(), false);
+ }
+
+ context.close();
+ }
+
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/jms2/Jms5Test.java b/joram/joram/client/jms/src/test/java/jms/jms2/Jms5Test.java
new file mode 100644
index 0000000000000000000000000000000000000000..125cd4de1f05dc29920adb855974169570d733d5
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/jms2/Jms5Test.java
@@ -0,0 +1,97 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2013 ScalAgent Distributed Technologies
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s):
+ */
+package jms.jms2;
+
+import javax.jms.CompletionListener;
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSContext;
+import javax.jms.JMSException;
+import javax.jms.JMSProducer;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.TextMessage;
+
+import org.junit.jupiter.api.Test;
+import org.objectweb.joram.client.jms.Queue;
+import org.objectweb.joram.client.jms.admin.AdminModule;
+import org.objectweb.joram.client.jms.admin.User;
+import org.objectweb.joram.client.jms.tcp.TcpConnectionFactory;
+
+import junit.framework.TestCase;
+
+/**
+ * Test the completion order when sending in asynchronous mode.
+ */
+public class Jms5Test extends TestCase implements MessageListener, CompletionListener {
+
+ @Test
+ public void testJms() throws Exception {
+
+ ConnectionFactory cf = TcpConnectionFactory.create("localhost", 16010);
+ AdminModule.connect(cf, "root", "root");
+ User.create("anonymous", "anonymous", 0);
+ Queue queue = Queue.create("Jms5Test");
+ queue.setFreeReading();
+ queue.setFreeWriting();
+ AdminModule.disconnect();
+
+ JMSContext context = cf.createContext();
+ JMSProducer producer = context.createProducer();
+ producer.setAsync(this);
+ context.start();
+
+ TextMessage msg = null;
+ for (int i=0; i < 10; i++) {
+ msg = context.createTextMessage("msg#" + i);
+ msg.setIntProperty("order", i);
+ producer.send(queue, msg);
+ }
+
+ context.close();
+ }
+
+ volatile int nbmsg = 0;
+
+ @Override
+ public void onMessage(Message message) {
+ nbmsg += 1;
+ }
+
+ volatile int sent = 0;
+
+ @Override
+ public void onCompletion(Message message) {
+ int n = -1;
+ try {
+ n = message.getIntProperty("order");
+ } catch (JMSException e) {
+ assertTrue("Unexpected exception: " + e.getMessage(), false);
+ }
+ assertTrue("Received " + n + " should be #" + sent, (n == sent));
+ sent += 1;
+ }
+
+ @Override
+ public void onException(Message message, Exception exc) {
+ exc.printStackTrace();
+ }
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/jms2/Jms6Test.java b/joram/joram/client/jms/src/test/java/jms/jms2/Jms6Test.java
new file mode 100644
index 0000000000000000000000000000000000000000..67af256892e2db2b9a1454e63e203808261f9c4a
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/jms2/Jms6Test.java
@@ -0,0 +1,136 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2013 ScalAgent Distributed Technologies
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s):
+ */
+package jms.jms2;
+
+import javax.jms.CompletionListener;
+import javax.jms.ConnectionFactory;
+import javax.jms.IllegalStateRuntimeException;
+import javax.jms.JMSConsumer;
+import javax.jms.JMSContext;
+import javax.jms.JMSException;
+import javax.jms.JMSProducer;
+import javax.jms.Message;
+import javax.jms.TextMessage;
+
+import org.junit.jupiter.api.Test;
+import org.objectweb.joram.client.jms.Queue;
+import org.objectweb.joram.client.jms.admin.AdminModule;
+import org.objectweb.joram.client.jms.admin.User;
+import org.objectweb.joram.client.jms.tcp.TcpConnectionFactory;
+
+import junit.framework.TestCase;
+
+/**
+ * Test calling stop and close from CompletionListener (expect IllegalStateRuntimeException).
+ */
+public class Jms6Test extends TestCase implements CompletionListener{
+
+ JMSContext context = null;
+
+ @Test
+ public void testJms() throws Exception {
+
+ ConnectionFactory cf = TcpConnectionFactory.create("localhost", 16010);
+ AdminModule.connect(cf, "root", "root");
+ User.create("anonymous", "anonymous", 0);
+ Queue queue = Queue.create("Jms6Test");
+ queue.setFreeReading();
+ queue.setFreeWriting();
+ AdminModule.disconnect();
+
+ context = cf.createContext();
+ JMSProducer producer = context.createProducer();
+ producer.setAsync(this);
+ JMSConsumer consumer = context.createConsumer(queue);
+ context.start();
+
+ int i = 0;
+
+ {
+ // Test to close the context from CompletionListener (this will try to close
+ // only the session as there is a second active context).
+ TextMessage msg = context.createTextMessage("stop");
+ producer.send(queue, msg);
+ Thread.sleep(2000L);
+ assertTrue("Should expect message completion", nbmsg == ++i);
+ Message recv = consumer.receive(1000L);
+ assertTrue("Should not receive message", (recv == null));
+ context.start();
+ recv = consumer.receive(1000L);
+ assertTrue("Should receive message", (recv != null));
+ }
+
+ JMSContext context2 = context.createContext(JMSContext.AUTO_ACKNOWLEDGE);
+
+ {
+ // Test to close the context from CompletionListener (this will try to close
+ // only the session as there is a second active context).
+ TextMessage msg = context.createTextMessage("close");
+ producer.send(queue, msg);
+ Thread.sleep(2000L);
+ assertTrue("Should expect message completion", nbmsg == ++i);
+ }
+
+ context2.close();
+ {
+ // Test to close the context from CompletionListener (this will try to close
+ // the connection as there is no other active context).
+ TextMessage msg = context.createTextMessage("close");
+ producer.send(queue, msg);
+ Thread.sleep(2000L);
+ assertTrue("Should expect message completion", nbmsg == ++i);
+ }
+
+ context.close();
+ }
+
+ volatile int nbmsg = 0;
+
+ @Override
+ public void onCompletion(Message message) {
+ try {
+ if ("stop".equals(((TextMessage) message).getText())) {
+ try {
+ context.stop();
+ assertTrue("expect no exception.", true);
+ } catch (Exception e) {
+ assertTrue("Caught unexpected exception: " + e.getMessage(), false);
+ }
+ } else if ("close".equals(((TextMessage) message).getText())) {
+ try {
+ context.close();
+ assertTrue("expect an IllegalStateRuntimeException.", false);
+ } catch (Exception e) {
+ assertTrue("Caught unexpected exception: " + e.getMessage(), e instanceof IllegalStateRuntimeException);
+ }
+ }
+ nbmsg += 1;
+ } catch (JMSException e) {
+ fail(e.getMessage());
+ }
+ }
+
+ @Override
+ public void onException(Message message, Exception exc) {
+ fail(exc.getMessage());
+ }
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/jms2/Jms7Test.java b/joram/joram/client/jms/src/test/java/jms/jms2/Jms7Test.java
new file mode 100644
index 0000000000000000000000000000000000000000..b577cbd2099ca05e24f85a6db31058f30b7df601
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/jms2/Jms7Test.java
@@ -0,0 +1,119 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2013 - 2019 ScalAgent Distributed Technologies
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s):
+ */
+package jms.jms2;
+
+import javax.jms.CompletionListener;
+import javax.jms.ConnectionFactory;
+import javax.jms.IllegalStateRuntimeException;
+import javax.jms.JMSContext;
+import javax.jms.JMSException;
+import javax.jms.JMSProducer;
+import javax.jms.Message;
+import javax.jms.TextMessage;
+
+import org.junit.jupiter.api.Test;
+import org.objectweb.joram.client.jms.Queue;
+import org.objectweb.joram.client.jms.admin.AdminModule;
+import org.objectweb.joram.client.jms.admin.User;
+import org.objectweb.joram.client.jms.tcp.TcpConnectionFactory;
+
+import junit.framework.TestCase;
+
+/**
+ * Test calling commit and rollback from CompletionListener (expect IllegalStateRuntimeException).
+ */
+public class Jms7Test extends TestCase implements CompletionListener{
+
+ JMSContext context = null;
+
+ @Test
+ public void testJms() throws Exception {
+
+ ConnectionFactory cf = TcpConnectionFactory.create("localhost", 16010);
+ AdminModule.connect(cf, "root", "root");
+ User.create("anonymous", "anonymous", 0);
+ Queue queue = Queue.create("Jms7Test");
+ queue.setFreeReading();
+ queue.setFreeWriting();
+ AdminModule.disconnect();
+
+ context = cf.createContext(JMSContext.SESSION_TRANSACTED);
+ JMSProducer producer = context.createProducer();
+ producer.setAsync(this);
+ context.start();
+
+ /* TODO fix deadlocks !!
+ {
+ // Test to commit the context from CompletionListener.
+ TextMessage msg = context.createTextMessage("commit");
+ producer.send(queue, msg);
+ // TODO (AF): The commit below involves a deadlock with the commit
+ // in CompletionListener !!
+ context.commit();
+ Thread.sleep(2000L);
+ assertTrue("Should expect message completion", nbmsg == 1);
+ }
+
+ {
+ // Test to rollback the context from CompletionListener.
+ TextMessage msg = context.createTextMessage("close");
+ producer.send(queue, msg);
+ context.commit();
+ Thread.sleep(2000L);
+ assertTrue("Should expect message completion", nbmsg == 2);
+ }
+ */
+
+ context.close();
+ }
+
+ volatile int nbmsg = 0;
+
+ @Override
+ public void onCompletion(Message message) {
+ try {
+ if ("commit".equals(((TextMessage) message).getText())) {
+ try {
+ context.commit();
+ assertTrue("expect an IllegalStateRuntimeException.", false);
+ } catch (Exception e) {
+ assertTrue("Caught unexpected exception: " + e.getMessage(), e instanceof IllegalStateRuntimeException);
+ }
+ } else if ("rollback".equals(((TextMessage) message).getText())) {
+ try {
+ context.rollback();
+ assertTrue("expect an IllegalStateRuntimeException.", false);
+ } catch (Exception e) {
+ assertTrue("Caught unexpected exception: " + e.getMessage(), e instanceof IllegalStateRuntimeException);
+ }
+ }
+ nbmsg += 1;
+ } catch (JMSException e) {
+ fail(e.getMessage());
+ }
+ }
+
+ @Override
+ public void onException(Message message, Exception exc) {
+ fail(exc.getMessage());
+ }
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/jms2/Jms8Test.java b/joram/joram/client/jms/src/test/java/jms/jms2/Jms8Test.java
new file mode 100644
index 0000000000000000000000000000000000000000..bc195205f9fc93b549600523d9e9d5a3e06893d0
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/jms2/Jms8Test.java
@@ -0,0 +1,109 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2013 ScalAgent Distributed Technologies
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s):
+ */
+package jms.jms2;
+
+import javax.jms.ConnectionFactory;
+import javax.jms.IllegalStateRuntimeException;
+import javax.jms.JMSConsumer;
+import javax.jms.JMSContext;
+import javax.jms.JMSException;
+import javax.jms.JMSProducer;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.TextMessage;
+
+import org.junit.jupiter.api.Test;
+import org.objectweb.joram.client.jms.Queue;
+import org.objectweb.joram.client.jms.admin.AdminModule;
+import org.objectweb.joram.client.jms.admin.User;
+import org.objectweb.joram.client.jms.tcp.TcpConnectionFactory;
+
+import junit.framework.TestCase;
+
+/**
+ * Test calling stop from MessageListener (expect IllegalStateRuntimeException)..
+ */
+public class Jms8Test extends TestCase implements MessageListener {
+
+ JMSContext context = null;
+ JMSContext context2 = null;
+
+ @Test
+ public void testJms() throws Exception {
+
+ ConnectionFactory cf = TcpConnectionFactory.create("localhost", 16010);
+ AdminModule.connect(cf, "root", "root");
+ User.create("anonymous", "anonymous", 0);
+ Queue queue = Queue.create("Jms8Test");
+ queue.setFreeReading();
+ queue.setFreeWriting();
+ AdminModule.disconnect();
+
+ context = cf.createContext();
+ JMSProducer producer = context.createProducer();
+ context2 = context.createContext(JMSContext.AUTO_ACKNOWLEDGE);
+ JMSConsumer consumer = context2.createConsumer(queue);
+ consumer.setMessageListener(this);
+ context.start();
+ context2.start();
+
+ TextMessage msg = context.createTextMessage("stop");
+ producer.send(queue, msg);
+ Thread.sleep(2000L);
+ assertTrue("Should complete recv", (nbmsg == 1));
+
+ msg = context.createTextMessage("close");
+ producer.send(queue, msg);
+ Thread.sleep(2000L);
+ assertTrue("Should complete recv", (nbmsg == 2));
+
+ context.close();
+ }
+
+ volatile int nbmsg = 0;
+
+ @Override
+ public void onMessage(Message message) {
+ try {
+ if ("stop".equals(((TextMessage) message).getText())) {
+ try {
+ context2.stop();
+ assertTrue("should caught IllegalStateRuntimeException", true);
+ } catch (Exception e) {
+ assertTrue("Caught unexpected exception: " + e.getMessage(), (e instanceof IllegalStateRuntimeException));
+ }
+ nbmsg += 1;
+ } else if ("close".equals(((TextMessage) message).getText())) {
+ try {
+ context2.close();
+ assertTrue("should caught IllegalStateRuntimeException", true);
+ } catch (Exception e) {
+ assertTrue("Caught unexpected exception: " + e.getMessage(), (e instanceof IllegalStateRuntimeException));
+ }
+ nbmsg += 1;
+ }
+ } catch (JMSException e) {
+ fail(e.getMessage());
+ }
+ }
+}
+
diff --git a/joram/joram/client/jms/src/test/java/jms/jms2/Jms9Test.java b/joram/joram/client/jms/src/test/java/jms/jms2/Jms9Test.java
new file mode 100644
index 0000000000000000000000000000000000000000..41ccf935c1907f9e3721810c3b5f1cb5d051faf3
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/jms2/Jms9Test.java
@@ -0,0 +1,79 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2013 - 2019 ScalAgent Distributed Technologies
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s):
+ */
+package jms.jms2;
+
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSConsumer;
+import javax.jms.JMSContext;
+import javax.jms.JMSProducer;
+import javax.jms.TextMessage;
+
+import org.junit.jupiter.api.Test;
+import org.objectweb.joram.client.jms.Topic;
+import org.objectweb.joram.client.jms.admin.AdminModule;
+import org.objectweb.joram.client.jms.admin.User;
+import org.objectweb.joram.client.jms.tcp.TcpConnectionFactory;
+
+import junit.framework.TestCase;
+
+/**
+ * Test durable subscription.
+ */
+public class Jms9Test extends TestCase {
+
+ @Test
+ public void testJms() throws Exception {
+
+ ConnectionFactory cf = TcpConnectionFactory.create("localhost", 16010);
+ AdminModule.connect(cf, "root", "root");
+ User.create("anonymous", "anonymous", 0);
+ Topic topic = Topic.create("Jms9Test");
+ topic.setFreeReading();
+ topic.setFreeWriting();
+ AdminModule.disconnect();
+
+ JMSContext context = cf.createContext();
+ context.setClientID("MyClientID");
+ JMSProducer producer = context.createProducer();
+ JMSConsumer consumer = context.createDurableConsumer(topic, "dursub9", "lastMessage = TRUE", false);
+
+ context.start();
+
+ {
+ TextMessage msg = context.createTextMessage("message");
+
+ msg.setStringProperty("name", "first");
+ msg.setBooleanProperty("lastMessage", false);
+ producer.send(topic, msg);
+
+ msg.setBooleanProperty("lastMessage", true);
+ msg.setStringProperty("name", "second");
+ producer.send(topic, msg);
+
+ TextMessage recv = (TextMessage) consumer.receive();
+ assertTrue("Receive bad message", (recv.getStringProperty("name").equals("second")));
+ }
+
+ context.close();
+ }
+
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/DeliveryDelayQ2Test.java b/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/DeliveryDelayQ2Test.java
new file mode 100644
index 0000000000000000000000000000000000000000..b7498ba9302f8357d8294da7fb23ae3d1bfda51f
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/DeliveryDelayQ2Test.java
@@ -0,0 +1,87 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2016 - 2019 ScalAgent Distributed Technologies
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s):
+ * Contributor(s):
+ */
+package jms.jms2.integrationtest;
+
+import javax.jms.ConnectionFactory;
+import javax.jms.DeliveryMode;
+import javax.jms.JMSConsumer;
+import javax.jms.JMSContext;
+import javax.jms.JMSProducer;
+import javax.jms.Message;
+
+import org.junit.jupiter.api.Test;
+import org.objectweb.joram.client.jms.Queue;
+import org.objectweb.joram.client.jms.admin.AdminModule;
+import org.objectweb.joram.client.jms.admin.User;
+import org.objectweb.joram.client.jms.tcp.TcpConnectionFactory;
+import org.ow2.joram.testutils.AgentManager;
+
+import junit.framework.TestCase;
+
+/**
+ * Test the delivery delay: Verify that a delayed message is delivered after restart.
+ */
+public class DeliveryDelayQ2Test extends TestCase {
+
+ JMSContext context;
+ JMSConsumer consumer;
+
+ ConnectionFactory cf = null;
+ Queue dest = null;
+
+ public void setUp() throws Exception {
+ cf = TcpConnectionFactory.create("localhost", 16010);
+ AdminModule.connect(cf, "root", "root");
+ User.create("anonymous", "anonymous", 0);
+ dest = Queue.create("DeliveryDelayQ2Test");
+ dest.setFreeReading();
+ dest.setFreeWriting();
+ AdminModule.disconnect();
+ }
+
+ @Test
+ public void testDeliveryDelay() throws Exception {
+ JMSContext context = cf.createContext(JMSContext.AUTO_ACKNOWLEDGE);
+ JMSProducer producer = context.createProducer();
+ producer.setDeliveryMode(DeliveryMode.PERSISTENT);
+ producer.setDeliveryDelay(10000L);
+ Message msg = context.createTextMessage("test DeliveryDelay");
+
+ producer.send(dest, msg);
+ System.out.println("Message sent.");
+ context.close();
+
+ AgentManager.restartAgentServer();
+ System.out.println("Server restarted.");
+
+ context = cf.createContext(JMSContext.AUTO_ACKNOWLEDGE);
+ consumer = context.createConsumer(dest);
+ context.start();
+
+ msg = consumer.receive(10000);
+ System.out.println("Message received: " + msg);
+ assertTrue("Don't receive scheduled message", (msg != null));
+
+ context.close();
+ }
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/DeliveryDelayQ3Test.java b/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/DeliveryDelayQ3Test.java
new file mode 100644
index 0000000000000000000000000000000000000000..c9d66eae00efdcf49e8d05910a6cf4c650074309
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/DeliveryDelayQ3Test.java
@@ -0,0 +1,98 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2019 ScalAgent Distributed Technologies
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s):
+ * Contributor(s):
+ */
+package jms.jms2.integrationtest;
+
+import javax.jms.ConnectionFactory;
+import javax.jms.DeliveryMode;
+import javax.jms.JMSConsumer;
+import javax.jms.JMSContext;
+import javax.jms.JMSProducer;
+import javax.jms.Message;
+
+import org.junit.jupiter.api.Test;
+import org.objectweb.joram.client.jms.Queue;
+import org.objectweb.joram.client.jms.admin.AdminModule;
+import org.objectweb.joram.client.jms.admin.User;
+import org.objectweb.joram.client.jms.tcp.TcpConnectionFactory;
+import org.ow2.joram.testutils.AgentManager;
+
+import junit.framework.TestCase;
+
+/**
+ * Test the delivery delay: Verify that a delayed message is scheduled after restart.
+ */
+public class DeliveryDelayQ3Test extends TestCase {
+
+ JMSContext context;
+ JMSConsumer consumer;
+
+ ConnectionFactory cf = null;
+ Queue dest = null;
+
+ public void setUp() throws Exception {
+ cf = TcpConnectionFactory.create("localhost", 16010);
+ AdminModule.connect(cf, "root", "root");
+ User.create("anonymous", "anonymous", 0);
+ dest = Queue.create("DeliveryDelayQ3Test");
+ dest.setFreeReading();
+ dest.setFreeWriting();
+ AdminModule.disconnect();
+ }
+
+ long send = 0L;
+ long recv = 0L;
+
+ @Test
+ public void testDeliveryDelay() {
+ JMSContext context = cf.createContext(JMSContext.AUTO_ACKNOWLEDGE);
+ JMSProducer producer = context.createProducer();
+ producer.setDeliveryMode(DeliveryMode.PERSISTENT);
+ producer.setDeliveryDelay(30000L);
+ Message msg = context.createTextMessage("test DeliveryDelay");
+ send = System.currentTimeMillis();
+ producer.send(dest, msg);
+ System.out.println("Message sent.");
+ context.close();
+
+ try {
+ AgentManager.restartAgentServer();
+ } catch(Exception e) {
+ fail(e.getMessage());
+ }
+
+ System.out.println("Server restarted.");
+
+ context = cf.createContext(JMSContext.AUTO_ACKNOWLEDGE);
+ consumer = context.createConsumer(dest);
+ context.start();
+
+ msg = consumer.receive(30000);
+ recv = System.currentTimeMillis();
+ System.out.println("Message received: " + msg + " -> " + (recv - send));
+ assertTrue("Don't receive scheduled message", (msg != null));
+ assertTrue("The message is received before the delivery delay: " + (recv-send),
+ ((recv - send) >= 30000L));
+
+ context.close();
+ }
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/DeliveryDelayQTest.java b/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/DeliveryDelayQTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..5d1df5624a8b0e022f937de4c3851236c8c06210
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/DeliveryDelayQTest.java
@@ -0,0 +1,116 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2016 - 2019 ScalAgent Distributed Technologies
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s):
+ * Contributor(s):
+ */
+package jms.jms2.integrationtest;
+
+import javax.jms.ConnectionFactory;
+import javax.jms.DeliveryMode;
+import javax.jms.JMSConsumer;
+import javax.jms.JMSContext;
+import javax.jms.JMSException;
+import javax.jms.JMSProducer;
+import javax.jms.Message;
+import javax.jms.TextMessage;
+
+import org.junit.jupiter.api.Test;
+import org.objectweb.joram.client.jms.Queue;
+import org.objectweb.joram.client.jms.admin.AdminModule;
+import org.objectweb.joram.client.jms.admin.User;
+import org.objectweb.joram.client.jms.tcp.TcpConnectionFactory;
+import org.ow2.joram.testutils.AgentManager;
+
+import junit.framework.TestCase;
+
+/**
+ * Test the delivery delay.
+ */
+public class DeliveryDelayQTest extends TestCase implements javax.jms.MessageListener {
+
+ JMSContext context;
+ JMSConsumer consumer;
+
+ ConnectionFactory cf = null;
+ Queue dest = null;
+
+ public void setUp() throws Exception {
+ cf = TcpConnectionFactory.create("localhost", 16010);
+ AdminModule.connect(cf, "root", "root");
+ User.create("anonymous", "anonymous", 0);
+ dest = Queue.create("DeliveryDelayQTest");
+ dest.setFreeReading();
+ dest.setFreeWriting();
+ AdminModule.disconnect();
+ }
+
+ long send = 0L;
+ long recv = 0L;
+
+ private void deliverMessage() throws InterruptedException {
+ context = cf.createContext(JMSContext.AUTO_ACKNOWLEDGE);
+ consumer = context.createConsumer(dest);
+ consumer.setMessageListener(this);
+ context.start();
+
+ JMSContext prodCtx = cf.createContext();
+ JMSProducer producer = prodCtx.createProducer();
+ producer.setDeliveryMode(DeliveryMode.PERSISTENT);
+ producer.setDeliveryDelay(5000L);
+ TextMessage msg = prodCtx.createTextMessage("test redeliveryTime");
+ send = System.currentTimeMillis();
+ producer.send(dest, msg);
+
+ // Wait to receive the message.
+ Thread.sleep(6000);
+
+ assertTrue("The message is received before the delivery delay", (recv - send) >= 5000);
+
+ context.close();
+ prodCtx.close();
+ }
+
+ @Test
+ public void testDeliveryDelay() throws Exception {
+ deliverMessage();
+
+ AgentManager.restartAgentServer();
+
+ System.out.println("Server restarted.");
+ deliverMessage();
+
+ assertTrue("Should receive 2 messages: " + nbrecv, (nbrecv == 2));
+ }
+
+ int nbrecv = 0;
+
+ public void onMessage(Message message) {
+ try {
+ nbrecv += 1;
+ System.out.println("#" + nbrecv + " - " + message.getJMSMessageID() + ", JMSRedelivered = " + message.getJMSRedelivered() +
+ ", JMSTimestamp = " + message.getJMSTimestamp());
+ System.out.println(System.currentTimeMillis() + ": message received deliveryTime = " + message.getJMSDeliveryTime());
+ } catch (JMSException e) {
+ e.printStackTrace();
+ }
+ recv = System.currentTimeMillis();
+ }
+
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/DeliveryDelayT2Test.java b/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/DeliveryDelayT2Test.java
new file mode 100644
index 0000000000000000000000000000000000000000..59835255a2e99cec19d24d780db611659073fafd
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/DeliveryDelayT2Test.java
@@ -0,0 +1,102 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2016 ScalAgent Distributed Technologies
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s):
+ * Contributor(s):
+ */
+package jms.jms2.integrationtest;
+
+import javax.jms.ConnectionFactory;
+import javax.jms.DeliveryMode;
+import javax.jms.JMSConsumer;
+import javax.jms.JMSContext;
+import javax.jms.JMSProducer;
+import javax.jms.Message;
+
+import org.junit.jupiter.api.Test;
+import org.objectweb.joram.client.jms.Topic;
+import org.objectweb.joram.client.jms.admin.AdminModule;
+import org.objectweb.joram.client.jms.admin.User;
+import org.objectweb.joram.client.jms.tcp.TcpConnectionFactory;
+import org.ow2.joram.testutils.AgentManager;
+
+import junit.framework.TestCase;
+
+/**
+ * Test the delivery delay.
+ */
+public class DeliveryDelayT2Test extends TestCase {
+
+ JMSContext context;
+ JMSConsumer consumer;
+
+ ConnectionFactory cf = null;
+ Topic dest = null;
+
+ public void setUp() throws Exception {
+ cf = TcpConnectionFactory.create("localhost", 16010);
+ AdminModule.connect(cf, "root", "root");
+ User.create("anonymous", "anonymous", 0);
+ dest = Topic.create("DeliveryDelayT2Test");
+ dest.setFreeReading();
+ dest.setFreeWriting();
+ AdminModule.disconnect();
+ }
+
+ long send = 0L;
+ long recv = 0L;
+
+ @Test
+ public void testDeliveryDelay() throws Exception {
+ JMSContext context = cf.createContext(JMSContext.AUTO_ACKNOWLEDGE);
+
+ context = cf.createContext(JMSContext.AUTO_ACKNOWLEDGE);
+ context.setClientID("client_dursub");
+ consumer = context.createDurableConsumer(dest, "dursub");
+ consumer.close();
+
+ JMSProducer producer = context.createProducer();
+ producer.setDeliveryMode(DeliveryMode.PERSISTENT);
+ producer.setDeliveryDelay(10000L);
+ Message msg = context.createTextMessage("test redeliveryTime");
+ send = System.currentTimeMillis();
+ producer.send(dest, msg);
+ System.out.println("Message sent.");
+ context.close();
+
+ try {
+ AgentManager.restartAgentServer();
+ } catch(Exception e) {
+ fail(e.getMessage());
+ }
+
+ System.out.println("Server restarted.");
+
+ context = cf.createContext(JMSContext.AUTO_ACKNOWLEDGE);
+ context.setClientID("client_dursub");
+ consumer = context.createDurableConsumer(dest, "dursub");
+ context.start();
+
+ msg = consumer.receive(12000);
+ System.out.println("Message received: " + msg);
+ assertTrue("Don't receive scheduled message", (msg != null));
+
+ context.close();
+ }
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/DeliveryDelayT3Test.java b/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/DeliveryDelayT3Test.java
new file mode 100644
index 0000000000000000000000000000000000000000..7ffb7c537f072b6b3b16662d5f8b07c7bf65318d
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/DeliveryDelayT3Test.java
@@ -0,0 +1,162 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2016 ScalAgent Distributed Technologies
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s):
+ * Contributor(s):
+ */
+package jms.jms2.integrationtest;
+
+import java.util.Properties;
+
+import javax.jms.ConnectionFactory;
+import javax.jms.DeliveryMode;
+import javax.jms.JMSConsumer;
+import javax.jms.JMSContext;
+import javax.jms.JMSProducer;
+import javax.jms.Message;
+
+import org.junit.jupiter.api.Test;
+import org.objectweb.joram.client.jms.Topic;
+import org.objectweb.joram.client.jms.admin.AdminModule;
+import org.objectweb.joram.client.jms.admin.User;
+import org.objectweb.joram.client.jms.tcp.TcpConnectionFactory;
+import org.objectweb.joram.shared.security.SimpleIdentity;
+import org.ow2.joram.testutils.AgentManager;
+
+import junit.framework.TestCase;
+
+/**
+ * Test the delivery delay and redelivery
+ */
+public class DeliveryDelayT3Test extends TestCase {
+
+ public static void main(String[] args) {
+ new DeliveryDelayT3Test().run();
+ }
+
+ JMSContext context;
+ JMSConsumer consumer;
+ JMSConsumer consumer1;
+
+ ConnectionFactory cf = null;
+ Topic dest = null;
+
+ public void setUp() throws Exception {
+ cf = TcpConnectionFactory.create("localhost", 16010);
+ AdminModule.connect(cf, "root", "root");
+
+ System.out.println("Configure User redelivery delay.");
+ Properties prop = new Properties();
+ prop.setProperty(User.REDELIVERY_DELAY, "10");
+ User.create("anonymous", "anonymous", 0, SimpleIdentity.class.getName(), prop);
+
+ dest = Topic.create("DeliveryDelayT3Test");
+ dest.setFreeReading();
+ dest.setFreeWriting();
+ AdminModule.disconnect();
+ }
+
+ long send = 0L;
+ long recv = 0L;
+
+ @Test
+ public void testDeliveryDelay() throws Exception {
+ JMSContext context = cf.createContext(JMSContext.AUTO_ACKNOWLEDGE);
+ context.setClientID("client_dursub");
+ consumer = context.createDurableConsumer(dest, "dursub");
+ consumer.close();
+
+ JMSContext ctxTransacted = cf.createContext(JMSContext.SESSION_TRANSACTED);
+ ctxTransacted.setClientID("client_dursub1");
+ consumer1 = ctxTransacted.createDurableConsumer(dest, "dursub1");
+ consumer1.close();
+
+ JMSProducer producer = context.createProducer();
+ producer.setDeliveryMode(DeliveryMode.PERSISTENT);
+ producer.setDeliveryDelay(10000L);
+ Message msg = context.createTextMessage("test redeliveryTime");
+ send = System.currentTimeMillis();
+ producer.send(dest, msg);
+ System.out.println("Message sent.");
+ context.close();
+ ctxTransacted.close();
+
+ // 1 stop and restart
+ try {
+ AgentManager.restartAgentServer();
+ } catch(Exception e) {
+ fail(e.getMessage());
+ }
+
+ System.out.println("1: Server restarted.");
+
+ context = cf.createContext(JMSContext.AUTO_ACKNOWLEDGE);
+ context.setClientID("client_dursub");
+ consumer = context.createDurableConsumer(dest, "dursub");
+ context.start();
+
+ ctxTransacted = cf.createContext(JMSContext.SESSION_TRANSACTED);
+ ctxTransacted.setClientID("client_dursub1");
+ consumer1 = ctxTransacted.createDurableConsumer(dest, "dursub1");
+ ctxTransacted.start();
+
+ msg = consumer.receive(12000);
+ System.out.println("durSub: Message received: " + msg);
+ assertTrue("Don't receive scheduled message to durSub", (msg != null));
+
+ // rollback the transacted context (dursub1)
+ msg = consumer1.receive(12000);
+ System.out.println("durSub1: Message received: " + msg);
+ assertTrue("Don't receive scheduled message to durSub1", (msg != null));
+ ctxTransacted.rollback();
+
+ context.close();
+ ctxTransacted.close();
+
+ // 2 stop and restart
+ try {
+ AgentManager.restartAgentServer();
+ } catch(Exception e) {
+ fail(e.getMessage());
+ }
+
+ System.out.println("2: Server restarted.");
+
+ context = cf.createContext(JMSContext.AUTO_ACKNOWLEDGE);
+ context.setClientID("client_dursub");
+ consumer = context.createDurableConsumer(dest, "dursub");
+ context.start();
+
+ ctxTransacted = cf.createContext(JMSContext.SESSION_TRANSACTED);
+ ctxTransacted.setClientID("client_dursub1");
+ consumer1 = ctxTransacted.createDurableConsumer(dest, "dursub1");
+ ctxTransacted.start();
+
+ msg = consumer1.receive(12000);
+ System.out.println("durSub1: Message received: " + msg);
+ assertTrue("Don't receive scheduled message to durSub1", (msg != null));
+ ctxTransacted.commit();
+
+ msg = consumer.receive(12000);
+ System.out.println("durSub: (attempt msg=null) Message received: " + msg);
+ assertTrue("Receive scheduled message to durSub (attempt msg=null)", (msg == null));
+ context.close();
+ ctxTransacted.close();
+ }
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/DeliveryDelayTTest.java b/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/DeliveryDelayTTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..9506c7cee1e94cf4cc84e0eb99e25a5f2237d839
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/DeliveryDelayTTest.java
@@ -0,0 +1,117 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2016 ScalAgent Distributed Technologies
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s):
+ * Contributor(s):
+ */
+package jms.jms2.integrationtest;
+
+import javax.jms.ConnectionFactory;
+import javax.jms.DeliveryMode;
+import javax.jms.JMSConsumer;
+import javax.jms.JMSContext;
+import javax.jms.JMSException;
+import javax.jms.JMSProducer;
+import javax.jms.Message;
+import javax.jms.TextMessage;
+
+import org.junit.jupiter.api.Test;
+import org.objectweb.joram.client.jms.Topic;
+import org.objectweb.joram.client.jms.admin.AdminModule;
+import org.objectweb.joram.client.jms.admin.User;
+import org.objectweb.joram.client.jms.tcp.TcpConnectionFactory;
+import org.ow2.joram.testutils.AgentManager;
+
+import junit.framework.TestCase;
+
+/**
+ * Test the delivery delay.
+ */
+public class DeliveryDelayTTest extends TestCase implements javax.jms.MessageListener {
+
+ JMSContext context;
+ JMSConsumer consumer;
+
+ public void setUp() throws Exception {
+ cf = TcpConnectionFactory.create("localhost", 16010);
+ AdminModule.connect(cf, "root", "root");
+ User.create("anonymous", "anonymous", 0);
+ dest = Topic.create("DeliveryDelayTTest");
+ dest.setFreeReading();
+ dest.setFreeWriting();
+ AdminModule.disconnect();
+ }
+
+ @Test
+ public void testDeliveryDelay() throws Exception {
+
+ deliverMessage();
+
+ AgentManager.restartAgentServer();
+
+ System.out.println("Server restarted.");
+ deliverMessage();
+
+ assertTrue("Should receive 2 messages: " + nbrecv, (nbrecv == 2));
+ }
+
+ ConnectionFactory cf = null;
+ Topic dest = null;
+
+ long send = 0L;
+ long recv = 0L;
+
+ void deliverMessage() throws InterruptedException {
+ context = cf.createContext(JMSContext.AUTO_ACKNOWLEDGE);
+ consumer = context.createConsumer(dest);
+ consumer.setMessageListener(this);
+ context.start();
+
+ JMSContext prodCtx = cf.createContext();
+ JMSProducer producer = prodCtx.createProducer();
+ producer.setDeliveryMode(DeliveryMode.PERSISTENT);
+ producer.setDeliveryDelay(5000L);
+ TextMessage msg = prodCtx.createTextMessage("test redeliveryTime");
+ send = System.currentTimeMillis();
+ producer.send(dest, msg);
+
+ // Wait to receive the message.
+ Thread.sleep(6000);
+
+ assertTrue("The rollback or recover message not received after the redelivery delay", (recv - send) > 5000);
+
+ context.close();
+ prodCtx.close();
+ }
+
+ int nbrecv = 0;
+
+ public void onMessage(Message message) {
+ try {
+ nbrecv += 1;
+ System.out.println("#" + nbrecv + " - " + message.getJMSMessageID() + ", JMSRedelivered = " + message.getJMSRedelivered() +
+ ", JMSTimestamp = " + message.getJMSTimestamp());
+ System.out.println(System.currentTimeMillis() + ": message received deliveryTime = " + message.getJMSDeliveryTime());
+ } catch (JMSException e) {
+ e.printStackTrace();
+ }
+ recv = System.currentTimeMillis();
+ }
+
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/QueueDeliveryDelay2Test.java b/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/QueueDeliveryDelay2Test.java
new file mode 100644
index 0000000000000000000000000000000000000000..819c17103a3f13347a4c82ca1c97a7bfa13737d3
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/QueueDeliveryDelay2Test.java
@@ -0,0 +1,95 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2018 ScalAgent Distributed Technologies
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s):
+ * Contributor(s):
+ */
+package jms.jms2.integrationtest;
+
+import javax.jms.ConnectionFactory;
+import javax.jms.DeliveryMode;
+import javax.jms.JMSConsumer;
+import javax.jms.JMSContext;
+import javax.jms.JMSProducer;
+import javax.jms.Message;
+
+import org.junit.jupiter.api.Test;
+import org.objectweb.joram.client.jms.Queue;
+import org.objectweb.joram.client.jms.admin.AdminModule;
+import org.objectweb.joram.client.jms.admin.User;
+import org.objectweb.joram.client.jms.tcp.TcpConnectionFactory;
+import org.ow2.joram.testutils.AgentManager;
+
+import junit.framework.TestCase;
+
+/**
+ * Test the queue delivery delay mechanism.
+ */
+public class QueueDeliveryDelay2Test extends TestCase {
+
+ JMSContext context;
+ JMSConsumer consumer;
+
+ ConnectionFactory cf = null;
+ Queue dest = null;
+
+ public void setUp() throws Exception {
+ cf = TcpConnectionFactory.create("localhost", 16010);
+ AdminModule.connect(cf, "root", "root");
+ User.create("anonymous", "anonymous", 0);
+ dest = Queue.create("QueueDeliveryDelay2Test");
+ dest.setDeliveryDelay(10000);
+ dest.setFreeReading();
+ dest.setFreeWriting();
+ AdminModule.disconnect();
+ }
+
+ long send = 0L;
+ long recv = 0L;
+
+ @Test
+ public void testDeliveryDelay() throws Exception {
+ JMSContext context = cf.createContext(JMSContext.AUTO_ACKNOWLEDGE);
+ JMSProducer producer = context.createProducer();
+ producer.setDeliveryMode(DeliveryMode.PERSISTENT);
+ Message msg = context.createTextMessage("test DeliveryDelay");
+ send = System.currentTimeMillis();
+ producer.send(dest, msg);
+ System.out.println("Message sent.");
+ context.close();
+
+ try {
+ AgentManager.restartAgentServer();
+ } catch(Exception e) {
+ fail(e.getMessage());
+ }
+
+ System.out.println("Server restarted.");
+
+ context = cf.createContext(JMSContext.AUTO_ACKNOWLEDGE);
+ consumer = context.createConsumer(dest);
+ context.start();
+
+ msg = consumer.receive(10000);
+ System.out.println("Message received: " + msg);
+ assertTrue("Don't receive delayed message", (msg != null));
+
+ context.close();
+ }
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/QueueDeliveryDelayTest.java b/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/QueueDeliveryDelayTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..a534f9d9afdd46c0b83c97ff503748289ece3178
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/QueueDeliveryDelayTest.java
@@ -0,0 +1,121 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2018 ScalAgent Distributed Technologies
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s):
+ * Contributor(s):
+ */
+package jms.jms2.integrationtest;
+
+import javax.jms.ConnectionFactory;
+import javax.jms.DeliveryMode;
+import javax.jms.JMSConsumer;
+import javax.jms.JMSContext;
+import javax.jms.JMSException;
+import javax.jms.JMSProducer;
+import javax.jms.Message;
+import javax.jms.TextMessage;
+
+import org.junit.jupiter.api.Test;
+import org.objectweb.joram.client.jms.Queue;
+import org.objectweb.joram.client.jms.admin.AdminModule;
+import org.objectweb.joram.client.jms.admin.User;
+import org.objectweb.joram.client.jms.tcp.TcpConnectionFactory;
+import org.ow2.joram.testutils.AgentManager;
+
+import junit.framework.TestCase;
+
+/**
+ * Test the queue delivery delay mechanism.
+ */
+public class QueueDeliveryDelayTest extends TestCase implements javax.jms.MessageListener {
+
+ JMSContext context;
+ JMSConsumer consumer;
+
+ ConnectionFactory cf = null;
+ Queue dest = null;
+
+ public void setUp() throws Exception {
+ cf = TcpConnectionFactory.create("localhost", 16010);
+ AdminModule.connect(cf, "root", "root");
+ User.create("anonymous", "anonymous", 0);
+ dest = Queue.create("QueueDeliveryDelayTest");
+ dest.setDeliveryDelay(5000);
+ dest.setFreeReading();
+ dest.setFreeWriting();
+ AdminModule.disconnect();
+ }
+
+ @Test
+ public void testDeliveryDelay() throws Exception {
+
+ deliverMessage();
+
+ try {
+ AgentManager.restartAgentServer();
+ } catch(Exception e) {
+ fail(e.getMessage());
+ }
+
+ System.out.println("Server restarted.");
+ deliverMessage();
+
+ assertTrue("Should receive 2 messages: received " + nbrecv, (nbrecv == 2));
+ }
+
+ long send = 0L;
+ long recv = 0L;
+
+ void deliverMessage() throws InterruptedException {
+ context = cf.createContext(JMSContext.AUTO_ACKNOWLEDGE);
+ consumer = context.createConsumer(dest);
+ consumer.setMessageListener(this);
+ context.start();
+
+ JMSContext prodCtx = cf.createContext();
+ JMSProducer producer = prodCtx.createProducer();
+ producer.setDeliveryMode(DeliveryMode.PERSISTENT);
+ TextMessage msg = prodCtx.createTextMessage("test redeliveryTime");
+ send = System.currentTimeMillis();
+ producer.send(dest, msg);
+
+ // Wait to receive the message.
+ Thread.sleep(6000);
+
+ assertTrue("The message is received before the delivery delay", (recv - send) > 5000);
+
+ context.close();
+ prodCtx.close();
+ }
+
+ int nbrecv = 0;
+
+ public void onMessage(Message message) {
+ try {
+ nbrecv += 1;
+ System.out.println("#" + nbrecv + " - " + message.getJMSMessageID() + ", JMSRedelivered = " + message.getJMSRedelivered() +
+ ", JMSTimestamp = " + message.getJMSTimestamp());
+ System.out.println(System.currentTimeMillis() + ": message received deliveryTime = " + message.getJMSDeliveryTime());
+ } catch (JMSException e) {
+ e.printStackTrace();
+ }
+ recv = System.currentTimeMillis();
+ }
+
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/QueuePauseTest.java b/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/QueuePauseTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..2657996ee751d412e8576258660bf533b486e0db
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/QueuePauseTest.java
@@ -0,0 +1,133 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2018 ScalAgent Distributed Technologies
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s):
+ * Contributor(s):
+ */
+package jms.jms2.integrationtest;
+
+import javax.jms.ConnectionFactory;
+import javax.jms.DeliveryMode;
+import javax.jms.JMSConsumer;
+import javax.jms.JMSContext;
+import javax.jms.JMSException;
+import javax.jms.JMSProducer;
+import javax.jms.Message;
+import javax.jms.TextMessage;
+
+import org.objectweb.joram.client.jms.Queue;
+import org.objectweb.joram.client.jms.admin.AdminModule;
+import org.objectweb.joram.client.jms.admin.User;
+import org.objectweb.joram.client.jms.tcp.TcpConnectionFactory;
+import org.ow2.joram.testutils.AgentManager;
+
+import junit.framework.TestCase;
+
+/**
+ * Test the queue pause mechanism.
+ */
+public class QueuePauseTest extends TestCase implements javax.jms.MessageListener {
+
+ JMSContext context;
+ JMSConsumer consumer;
+
+ ConnectionFactory cf = null;
+ Queue dest = null;
+
+ public void setUp() throws Exception {
+ cf = TcpConnectionFactory.create("localhost", 16010);
+ AdminModule.connect(cf, "root", "root");
+ User.create("anonymous", "anonymous", 0);
+ dest = Queue.create("QueuePauseTest");
+ dest.setFreeReading();
+ dest.setFreeWriting();
+ AdminModule.disconnect();
+ }
+
+ public void testQueuePause() throws Exception {
+
+ pause(true);
+ deliverMessage();
+ pause(true);
+
+ try {
+ AgentManager.restartAgentServer();
+ } catch(Exception e) {
+ fail(e.getMessage());
+ }
+
+ System.out.println("Server restarted.");
+ deliverMessage();
+
+ assertTrue("Should receive 2 messages: " + nbrecv, (nbrecv == 2));
+ }
+
+ void pause(boolean pause) throws Exception {
+ cf = TcpConnectionFactory.create("localhost", 16010);
+ AdminModule.connect(cf, "root", "root");
+ dest = Queue.create("QueuePauseTest");
+ dest.setPause(pause);
+ AdminModule.disconnect();
+ }
+
+ boolean received;
+
+ void deliverMessage() throws Exception {
+ context = cf.createContext(JMSContext.AUTO_ACKNOWLEDGE);
+ consumer = context.createConsumer(dest);
+ consumer.setMessageListener(this);
+ context.start();
+
+ JMSContext prodCtx = cf.createContext();
+ JMSProducer producer = prodCtx.createProducer();
+ producer.setDeliveryMode(DeliveryMode.PERSISTENT);
+ TextMessage msg = prodCtx.createTextMessage("test pause");
+ received = false;
+ producer.send(dest, msg);
+
+ // Wait to receive the message.
+ Thread.sleep(10000);
+
+ assertFalse("The message is received before starting queue ", received);
+
+ pause(false);
+
+ // Wait to receive the message.
+ Thread.sleep(5000);
+ assertTrue("The message is not received after starting queue ", received);
+
+ context.close();
+ prodCtx.close();
+ }
+
+ int nbrecv = 0;
+
+ public void onMessage(Message message) {
+ try {
+ nbrecv += 1;
+ System.out.println("#" + nbrecv + " - " + message.getJMSMessageID() + ", JMSRedelivered = " + message.getJMSRedelivered() +
+ ", JMSTimestamp = " + message.getJMSTimestamp());
+ System.out.println(System.currentTimeMillis() + ": message received deliveryTime = " + message.getJMSDeliveryTime());
+ } catch (JMSException e) {
+ e.printStackTrace();
+ }
+ received = true;
+ }
+
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/RedeliveryDelayQAdminTest.java b/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/RedeliveryDelayQAdminTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..15422991b62f1dcac26cd46c67a9e9978f91b5a7
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/RedeliveryDelayQAdminTest.java
@@ -0,0 +1,177 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2016 ScalAgent Distributed Technologies
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s):
+ * Contributor(s):
+ */
+package jms.jms2.integrationtest;
+
+import javax.jms.ConnectionFactory;
+import javax.jms.DeliveryMode;
+import javax.jms.JMSConsumer;
+import javax.jms.JMSContext;
+import javax.jms.JMSException;
+import javax.jms.JMSProducer;
+import javax.jms.Message;
+import javax.jms.TextMessage;
+
+import org.junit.jupiter.api.Test;
+import org.objectweb.joram.client.jms.Queue;
+import org.objectweb.joram.client.jms.admin.AdminModule;
+import org.objectweb.joram.client.jms.admin.User;
+import org.objectweb.joram.client.jms.tcp.TcpConnectionFactory;
+import org.ow2.joram.testutils.AgentManager;
+
+import junit.framework.TestCase;
+
+/**
+ * Test : The message received by the consumer rollback, recover or throw an exception.
+ * The delivery delay is set on server. The message must re-delivered
+ * after the delivery delay.
+ */
+public class RedeliveryDelayQAdminTest extends TestCase implements javax.jms.MessageListener {
+
+ JMSContext context;
+ JMSConsumer consumer;
+
+ ConnectionFactory cf = null;
+ Queue dest = null;
+
+ public void setUp() throws Exception {
+ cf = TcpConnectionFactory.create("localhost", 16010);
+ AdminModule.connect(cf, "root", "root");
+ User.create("anonymous", "anonymous", 0);
+ // Use admin api
+ System.out.println("Configure Queue redelivery delay.");
+ dest = Queue.create(0, "RedeliveryDelayQAdminTest");
+ dest.setRedeliveryDelay(5);
+
+ dest.setFreeReading();
+ dest.setFreeWriting();
+ AdminModule.disconnect();
+
+ }
+
+ @Test
+ public void testRedeliverySessionTransacted() throws Exception {
+ deliverMessage(JMSContext.SESSION_TRANSACTED);
+ AgentManager.restartAgentServer();
+ System.out.println("Server restarted.");
+ deliverMessage(JMSContext.SESSION_TRANSACTED);
+ }
+
+ @Test
+ public void testRedeliveryClientAcknowledge() throws Exception {
+ deliverMessage(JMSContext.CLIENT_ACKNOWLEDGE);
+ AgentManager.restartAgentServer();
+ System.out.println("Server restarted.");
+ deliverMessage(JMSContext.CLIENT_ACKNOWLEDGE);
+ }
+
+ @Test
+ public void testRedeliveryAutoAcknowledge() throws Exception {
+ deliverMessage(JMSContext.AUTO_ACKNOWLEDGE);
+ AgentManager.restartAgentServer();
+ System.out.println("Server restarted.");
+ deliverMessage(JMSContext.AUTO_ACKNOWLEDGE);
+ }
+
+ void deliverMessage(int sessionMode) throws InterruptedException {
+ reset();
+ switch (sessionMode) {
+ case JMSContext.SESSION_TRANSACTED:
+ context = cf.createContext(JMSContext.SESSION_TRANSACTED);
+ break;
+ case JMSContext.CLIENT_ACKNOWLEDGE:
+ context = cf.createContext(JMSContext.CLIENT_ACKNOWLEDGE);
+ break;
+ default:
+ context = cf.createContext(JMSContext.AUTO_ACKNOWLEDGE);
+ break;
+ }
+
+ consumer = context.createConsumer(dest);
+ consumer.setMessageListener(this);
+ context.start();
+
+ JMSContext prodCtx = cf.createContext();
+ JMSProducer producer = prodCtx.createProducer();
+ producer.setDeliveryMode(DeliveryMode.PERSISTENT);
+ TextMessage msg = prodCtx.createTextMessage("test redeliveryTime");
+ producer.send(dest, msg);
+
+ // Wait to receive the message.
+ Thread.sleep(10000L);
+
+ assertTrue("The rollback or recover message not received after the redelivery delay", time >= 5000);
+
+ context.close();
+ prodCtx.close();
+ }
+
+ public void reset() {
+ first = true;
+ time = 0;
+ }
+
+ private boolean first = true;
+ private long time = 0;
+
+ public void onMessage(Message message) {
+ try {
+ System.out.println(message.getJMSMessageID() + ", JMSRedelivered = " + message.getJMSRedelivered());
+ System.out.println(System.currentTimeMillis() + ": message received deliveryTime = " + message.getJMSDeliveryTime());
+ } catch (JMSException e) {
+ e.printStackTrace();
+ }
+
+ time = System.currentTimeMillis() - time;
+ System.out.println("Waiting (" + first + ") " + time);
+
+ if (first) {
+ first = false;
+ switch (context.getSessionMode()) {
+ case JMSContext.SESSION_TRANSACTED:
+ System.out.println("rollback");
+ context.rollback();
+ break;
+ case JMSContext.CLIENT_ACKNOWLEDGE:
+ System.out.println("recover");
+ context.recover();
+ break;
+ default:
+ System.out.println("throw RuntimeException");
+ throw new RuntimeException("Test redeliveryTime");
+ }
+ } else {
+ switch (context.getSessionMode()) {
+ case JMSContext.SESSION_TRANSACTED:
+ System.out.println("commit");
+ context.commit();
+ break;
+ case JMSContext.CLIENT_ACKNOWLEDGE:
+ System.out.println("acknowledge");
+ context.acknowledge();
+ break;
+ default:
+ System.out.println("nothing");
+ }
+ }
+ }
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/RedeliveryDelayQCreationTest.java b/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/RedeliveryDelayQCreationTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..52404cc9e7f2f25c21010df64410acda63c56671
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/RedeliveryDelayQCreationTest.java
@@ -0,0 +1,181 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2016 ScalAgent Distributed Technologies
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s):
+ * Contributor(s):
+ */
+package jms.jms2.integrationtest;
+
+import java.util.Properties;
+
+import javax.jms.ConnectionFactory;
+import javax.jms.DeliveryMode;
+import javax.jms.JMSConsumer;
+import javax.jms.JMSContext;
+import javax.jms.JMSException;
+import javax.jms.JMSProducer;
+import javax.jms.Message;
+import javax.jms.TextMessage;
+
+import org.junit.jupiter.api.Test;
+import org.objectweb.joram.client.jms.Queue;
+import org.objectweb.joram.client.jms.admin.AdminModule;
+import org.objectweb.joram.client.jms.admin.User;
+import org.objectweb.joram.client.jms.tcp.TcpConnectionFactory;
+import org.ow2.joram.testutils.AgentManager;
+
+import junit.framework.TestCase;
+
+/**
+ * Test : The message received by the consumer rollback, recover or throw an exception.
+ * The delivery delay is set on server. The message must re-delivered
+ * after the delivery delay.
+ */
+public class RedeliveryDelayQCreationTest extends TestCase implements javax.jms.MessageListener {
+
+ JMSContext context;
+ JMSConsumer consumer;
+
+ ConnectionFactory cf = null;
+ Queue dest = null;
+
+ public void setUp() throws Exception {
+ cf = TcpConnectionFactory.create("localhost", 16010);
+ AdminModule.connect(cf, "root", "root");
+ User.create("anonymous", "anonymous", 0);
+ // Set at creation time
+ System.out.println("Configure Queue redelivery delay.");
+ Properties prop = new Properties();
+ prop.setProperty(Queue.REDELIVERY_DELAY, "5");
+ prop.setProperty("name", "RedeliveryDelayQCreationTest");
+ dest = Queue.create(0, prop);
+
+ dest.setFreeReading();
+ dest.setFreeWriting();
+ AdminModule.disconnect();
+
+ }
+
+ @Test
+ public void testRedeliverySessionTransacted() throws Exception {
+ deliverMessage(JMSContext.SESSION_TRANSACTED);
+ AgentManager.restartAgentServer();
+ System.out.println("Server restarted.");
+ deliverMessage(JMSContext.SESSION_TRANSACTED);
+ }
+
+ @Test
+ public void testRedeliveryClientAcknowledge() throws Exception {
+ deliverMessage(JMSContext.CLIENT_ACKNOWLEDGE);
+ AgentManager.restartAgentServer();
+ System.out.println("Server restarted.");
+ deliverMessage(JMSContext.CLIENT_ACKNOWLEDGE);
+ }
+
+ @Test
+ public void testRedeliveryAutoAcknowledge() throws Exception {
+ deliverMessage(JMSContext.AUTO_ACKNOWLEDGE);
+ AgentManager.restartAgentServer();
+ System.out.println("Server restarted.");
+ deliverMessage(JMSContext.AUTO_ACKNOWLEDGE);
+ }
+
+ void deliverMessage(int sessionMode) throws InterruptedException {
+ reset();
+ switch (sessionMode) {
+ case JMSContext.SESSION_TRANSACTED:
+ context = cf.createContext(JMSContext.SESSION_TRANSACTED);
+ break;
+ case JMSContext.CLIENT_ACKNOWLEDGE:
+ context = cf.createContext(JMSContext.CLIENT_ACKNOWLEDGE);
+ break;
+ default:
+ context = cf.createContext(JMSContext.AUTO_ACKNOWLEDGE);
+ break;
+ }
+
+ consumer = context.createConsumer(dest);
+ consumer.setMessageListener(this);
+ context.start();
+
+ JMSContext prodCtx = cf.createContext();
+ JMSProducer producer = prodCtx.createProducer();
+ producer.setDeliveryMode(DeliveryMode.PERSISTENT);
+ TextMessage msg = prodCtx.createTextMessage("test redeliveryTime");
+ producer.send(dest, msg);
+
+ // Wait to receive the message.
+ Thread.sleep(10000L);
+
+ assertTrue("The rollback or recover message not received after the redelivery delay", time >= 5000);
+
+ context.close();
+ prodCtx.close();
+ }
+
+ public void reset() {
+ first = true;
+ time = 0;
+ }
+
+ private boolean first = true;
+ private long time = 0;
+
+ public void onMessage(Message message) {
+ try {
+ System.out.println(message.getJMSMessageID() + ", JMSRedelivered = " + message.getJMSRedelivered());
+ System.out.println(System.currentTimeMillis() + ": message received deliveryTime = " + message.getJMSDeliveryTime());
+ } catch (JMSException e) {
+ e.printStackTrace();
+ }
+
+ time = System.currentTimeMillis() - time;
+ System.out.println("Waiting (" + first + ") " + time);
+
+ if (first) {
+ first = false;
+ switch (context.getSessionMode()) {
+ case JMSContext.SESSION_TRANSACTED:
+ System.out.println("rollback");
+ context.rollback();
+ break;
+ case JMSContext.CLIENT_ACKNOWLEDGE:
+ System.out.println("recover");
+ context.recover();
+ break;
+ default:
+ System.out.println("throw RuntimeException");
+ throw new RuntimeException("Test redeliveryTime");
+ }
+ } else {
+ switch (context.getSessionMode()) {
+ case JMSContext.SESSION_TRANSACTED:
+ System.out.println("commit");
+ context.commit();
+ break;
+ case JMSContext.CLIENT_ACKNOWLEDGE:
+ System.out.println("acknowledge");
+ context.acknowledge();
+ break;
+ default:
+ System.out.println("nothing");
+ }
+ }
+ }
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/RedeliveryDelayQDefaultTest.java b/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/RedeliveryDelayQDefaultTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..d2be16754e23af1dd48be7d8ae7a9a2dea23d504
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/RedeliveryDelayQDefaultTest.java
@@ -0,0 +1,176 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2016 ScalAgent Distributed Technologies
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s):
+ * Contributor(s):
+ */
+package jms.jms2.integrationtest;
+
+import javax.jms.ConnectionFactory;
+import javax.jms.DeliveryMode;
+import javax.jms.JMSConsumer;
+import javax.jms.JMSContext;
+import javax.jms.JMSException;
+import javax.jms.JMSProducer;
+import javax.jms.Message;
+import javax.jms.TextMessage;
+
+import org.junit.jupiter.api.Test;
+import org.objectweb.joram.client.jms.Queue;
+import org.objectweb.joram.client.jms.admin.AdminModule;
+import org.objectweb.joram.client.jms.admin.User;
+import org.objectweb.joram.client.jms.tcp.TcpConnectionFactory;
+import org.ow2.joram.testutils.AgentManager;
+
+import junit.framework.TestCase;
+
+/**
+ * Test : The message received by the consumer rollback, recover or throw an exception.
+ * The delivery delay is set on server. The message must re-delivered
+ * after the delivery delay.
+ */
+public class RedeliveryDelayQDefaultTest extends TestCase implements javax.jms.MessageListener {
+
+ JMSContext context;
+ JMSConsumer consumer;
+
+ ConnectionFactory cf = null;
+ Queue dest = null;
+
+ public void setUp() throws Exception {
+ cf = TcpConnectionFactory.create("localhost", 16010);
+ AdminModule.connect(cf, "root", "root");
+ User.create("anonymous", "anonymous", 0);
+ // Default mode
+ System.out.println("Default redelivery delay set.");
+ dest = Queue.create("RedeliveryDelayQDefaultTest");
+
+ dest.setFreeReading();
+ dest.setFreeWriting();
+ AdminModule.disconnect();
+
+ }
+
+ @Test
+ public void testRedeliverySessionTransacted() throws Exception {
+ deliverMessage(JMSContext.SESSION_TRANSACTED);
+ AgentManager.restartAgentServer();
+ System.out.println("Server restarted.");
+ deliverMessage(JMSContext.SESSION_TRANSACTED);
+ }
+
+ @Test
+ public void testRedeliveryClientAcknowledge() throws Exception {
+ deliverMessage(JMSContext.CLIENT_ACKNOWLEDGE);
+ AgentManager.restartAgentServer();
+ System.out.println("Server restarted.");
+ deliverMessage(JMSContext.CLIENT_ACKNOWLEDGE);
+ }
+
+ @Test
+ public void testRedeliveryAutoAcknowledge() throws Exception {
+ deliverMessage(JMSContext.AUTO_ACKNOWLEDGE);
+ AgentManager.restartAgentServer();
+ System.out.println("Server restarted.");
+ deliverMessage(JMSContext.AUTO_ACKNOWLEDGE);
+ }
+
+ void deliverMessage(int sessionMode) throws InterruptedException {
+ reset();
+ switch (sessionMode) {
+ case JMSContext.SESSION_TRANSACTED:
+ context = cf.createContext(JMSContext.SESSION_TRANSACTED);
+ break;
+ case JMSContext.CLIENT_ACKNOWLEDGE:
+ context = cf.createContext(JMSContext.CLIENT_ACKNOWLEDGE);
+ break;
+ default:
+ context = cf.createContext(JMSContext.AUTO_ACKNOWLEDGE);
+ break;
+ }
+
+ consumer = context.createConsumer(dest);
+ consumer.setMessageListener(this);
+ context.start();
+
+ JMSContext prodCtx = cf.createContext();
+ JMSProducer producer = prodCtx.createProducer();
+ producer.setDeliveryMode(DeliveryMode.PERSISTENT);
+ TextMessage msg = prodCtx.createTextMessage("test redeliveryTime");
+ producer.send(dest, msg);
+
+ // Wait to receive the message.
+ Thread.sleep(10000L);
+
+ assertTrue("The rollback or recover message not received after the redelivery delay", time >= 5000);
+
+ context.close();
+ prodCtx.close();
+ }
+
+ public void reset() {
+ first = true;
+ time = 0;
+ }
+
+ private boolean first = true;
+ private long time = 0;
+
+ public void onMessage(Message message) {
+ try {
+ System.out.println(message.getJMSMessageID() + ", JMSRedelivered = " + message.getJMSRedelivered());
+ System.out.println(System.currentTimeMillis() + ": message received deliveryTime = " + message.getJMSDeliveryTime());
+ } catch (JMSException e) {
+ e.printStackTrace();
+ }
+
+ time = System.currentTimeMillis() - time;
+ System.out.println("Waiting (" + first + ") " + time);
+
+ if (first) {
+ first = false;
+ switch (context.getSessionMode()) {
+ case JMSContext.SESSION_TRANSACTED:
+ System.out.println("rollback");
+ context.rollback();
+ break;
+ case JMSContext.CLIENT_ACKNOWLEDGE:
+ System.out.println("recover");
+ context.recover();
+ break;
+ default:
+ System.out.println("throw RuntimeException");
+ throw new RuntimeException("Test redeliveryTime");
+ }
+ } else {
+ switch (context.getSessionMode()) {
+ case JMSContext.SESSION_TRANSACTED:
+ System.out.println("commit");
+ context.commit();
+ break;
+ case JMSContext.CLIENT_ACKNOWLEDGE:
+ System.out.println("acknowledge");
+ context.acknowledge();
+ break;
+ default:
+ System.out.println("nothing");
+ }
+ }
+ }
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/RedeliveryDelayTAdminTest.java b/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/RedeliveryDelayTAdminTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..377b92069121bdd70c6bf0625513b482da40bbc0
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/RedeliveryDelayTAdminTest.java
@@ -0,0 +1,176 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2016 ScalAgent Distributed Technologies
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s):
+ * Contributor(s):
+ */
+package jms.jms2.integrationtest;
+
+import javax.jms.ConnectionFactory;
+import javax.jms.DeliveryMode;
+import javax.jms.JMSConsumer;
+import javax.jms.JMSContext;
+import javax.jms.JMSException;
+import javax.jms.JMSProducer;
+import javax.jms.Message;
+import javax.jms.TextMessage;
+
+import org.junit.jupiter.api.Test;
+import org.objectweb.joram.client.jms.Topic;
+import org.objectweb.joram.client.jms.admin.AdminModule;
+import org.objectweb.joram.client.jms.admin.User;
+import org.objectweb.joram.client.jms.tcp.TcpConnectionFactory;
+import org.ow2.joram.testutils.AgentManager;
+
+import junit.framework.TestCase;
+
+/**
+ * Test : The message received by the consumer rollback, recover or throw an exception.
+ * The delivery delay is set on server. The message must re-delivered
+ * after the delivery delay.
+ */
+public class RedeliveryDelayTAdminTest extends TestCase implements javax.jms.MessageListener {
+
+ JMSContext context;
+ JMSConsumer consumer;
+
+ ConnectionFactory cf = null;
+ Topic dest = null;
+
+ public void setUp() throws Exception {
+ cf = TcpConnectionFactory.create("localhost", 16010);
+ AdminModule.connect(cf, "root", "root");
+ // Use administration API
+ System.out.println("Configure User redelivery delay.");
+ User user = User.create("anonymous", "anonymous");
+ user.setRedeliveryDelay(5);
+
+ dest = Topic.create("RedeliveryDelayTAdminTest");
+ dest.setFreeReading();
+ dest.setFreeWriting();
+ AdminModule.disconnect();
+ }
+
+ @Test
+ public void testRedeliverySessionTransacted() throws Exception {
+ deliverMessage(JMSContext.SESSION_TRANSACTED);
+ AgentManager.restartAgentServer();
+ System.out.println("Server restarted.");
+ deliverMessage(JMSContext.SESSION_TRANSACTED);
+ }
+
+ @Test
+ public void testRedeliveryClientAcknowledge() throws Exception {
+ deliverMessage(JMSContext.CLIENT_ACKNOWLEDGE);
+ AgentManager.restartAgentServer();
+ System.out.println("Server restarted.");
+ deliverMessage(JMSContext.CLIENT_ACKNOWLEDGE);
+ }
+
+ @Test
+ public void testRedeliveryAutoAcknowledge() throws Exception {
+ deliverMessage(JMSContext.AUTO_ACKNOWLEDGE);
+ AgentManager.restartAgentServer();
+ System.out.println("Server restarted.");
+ deliverMessage(JMSContext.AUTO_ACKNOWLEDGE);
+ }
+
+ void deliverMessage(int sessionMode) throws InterruptedException {
+ reset();
+ switch (sessionMode) {
+ case JMSContext.SESSION_TRANSACTED:
+ context = cf.createContext(JMSContext.SESSION_TRANSACTED);
+ break;
+ case JMSContext.CLIENT_ACKNOWLEDGE:
+ context = cf.createContext(JMSContext.CLIENT_ACKNOWLEDGE);
+ break;
+ default:
+ context = cf.createContext(JMSContext.AUTO_ACKNOWLEDGE);
+ break;
+ }
+ consumer = context.createConsumer(dest);
+ consumer.setMessageListener(this);
+ context.start();
+
+ JMSContext prodCtx = cf.createContext();
+ JMSProducer producer = prodCtx.createProducer();
+ producer.setDeliveryMode(DeliveryMode.PERSISTENT);
+ TextMessage msg = prodCtx.createTextMessage("test redeliveryTime");
+ producer.send(dest, msg);
+
+ // Wait to receive the message.
+ Thread.sleep(10000);
+
+ assertTrue("The rollback or recover message not received after the redelivery delay", time >= 5000);
+
+ context.close();
+ prodCtx.close();
+ }
+
+ public void reset() {
+ first = true;
+ time = 0;
+ }
+
+ private boolean first = true;
+ private long time = 0;
+
+ public void onMessage(Message message) {
+ try {
+ System.out.println(message.getJMSMessageID() + ", JMSRedelivered = " + message.getJMSRedelivered());
+ System.out.println(System.currentTimeMillis() + ": message received deliveryTime = " + message.getJMSDeliveryTime());
+ } catch (JMSException e) {
+ e.printStackTrace();
+ }
+
+ time = System.currentTimeMillis() - time;
+ System.out.println("Waiting (" + first + ") " + time);
+
+ if (first) {
+ first = false;
+ switch (context.getSessionMode()) {
+ case JMSContext.SESSION_TRANSACTED:
+ System.out.println("rollback");
+ context.rollback();
+ break;
+ case JMSContext.CLIENT_ACKNOWLEDGE:
+ System.out.println("recover");
+ context.recover();
+ break;
+ default:
+ System.out.println("throw RuntimeException");
+ throw new RuntimeException("Test redeliveryTime");
+ }
+ } else {
+ switch (context.getSessionMode()) {
+ case JMSContext.SESSION_TRANSACTED:
+ System.out.println("commit");
+ context.commit();
+ break;
+ case JMSContext.CLIENT_ACKNOWLEDGE:
+ System.out.println("acknowledge");
+ context.acknowledge();
+ break;
+ default:
+ System.out.println("nothing");
+ }
+ }
+ }
+
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/RedeliveryDelayTCreationTimeTest.java b/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/RedeliveryDelayTCreationTimeTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..584c41dbd33991241a1f44f7afb263453cb4faec
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/RedeliveryDelayTCreationTimeTest.java
@@ -0,0 +1,180 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2016 ScalAgent Distributed Technologies
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s):
+ * Contributor(s):
+ */
+package jms.jms2.integrationtest;
+
+import java.util.Properties;
+
+import javax.jms.ConnectionFactory;
+import javax.jms.DeliveryMode;
+import javax.jms.JMSConsumer;
+import javax.jms.JMSContext;
+import javax.jms.JMSException;
+import javax.jms.JMSProducer;
+import javax.jms.Message;
+import javax.jms.TextMessage;
+
+import org.junit.jupiter.api.Test;
+import org.objectweb.joram.client.jms.Topic;
+import org.objectweb.joram.client.jms.admin.AdminModule;
+import org.objectweb.joram.client.jms.admin.User;
+import org.objectweb.joram.client.jms.tcp.TcpConnectionFactory;
+import org.objectweb.joram.shared.security.SimpleIdentity;
+import org.ow2.joram.testutils.AgentManager;
+
+import junit.framework.TestCase;
+
+/**
+ * Test : The message received by the consumer rollback, recover or throw an exception.
+ * The delivery delay is set on server. The message must re-delivered
+ * after the delivery delay.
+ */
+public class RedeliveryDelayTCreationTimeTest extends TestCase implements javax.jms.MessageListener {
+
+ JMSContext context;
+ JMSConsumer consumer;
+
+ ConnectionFactory cf = null;
+ Topic dest = null;
+
+ public void setUp() throws Exception {
+ cf = TcpConnectionFactory.create("localhost", 16010);
+ AdminModule.connect(cf, "root", "root");
+ // Set at creation time
+ System.out.println("Configure User redelivery delay.");
+ Properties prop = new Properties();
+ prop.setProperty(User.REDELIVERY_DELAY, "5");
+ User.create("anonymous", "anonymous", 0, SimpleIdentity.class.getName(), prop);
+
+ dest = Topic.create("RedeliveryDelayTCreationTimeTest");
+ dest.setFreeReading();
+ dest.setFreeWriting();
+ AdminModule.disconnect();
+ }
+
+ @Test
+ public void testRedeliverySessionTransacted() throws Exception {
+ deliverMessage(JMSContext.SESSION_TRANSACTED);
+ AgentManager.restartAgentServer();
+ System.out.println("Server restarted.");
+ deliverMessage(JMSContext.SESSION_TRANSACTED);
+ }
+
+ @Test
+ public void testRedeliveryClientAcknowledge() throws Exception {
+ deliverMessage(JMSContext.CLIENT_ACKNOWLEDGE);
+ AgentManager.restartAgentServer();
+ System.out.println("Server restarted.");
+ deliverMessage(JMSContext.CLIENT_ACKNOWLEDGE);
+ }
+
+ @Test
+ public void testRedeliveryAutoAcknowledge() throws Exception {
+ deliverMessage(JMSContext.AUTO_ACKNOWLEDGE);
+ AgentManager.restartAgentServer();
+ System.out.println("Server restarted.");
+ deliverMessage(JMSContext.AUTO_ACKNOWLEDGE);
+ }
+
+ void deliverMessage(int sessionMode) throws InterruptedException {
+ reset();
+ switch (sessionMode) {
+ case JMSContext.SESSION_TRANSACTED:
+ context = cf.createContext(JMSContext.SESSION_TRANSACTED);
+ break;
+ case JMSContext.CLIENT_ACKNOWLEDGE:
+ context = cf.createContext(JMSContext.CLIENT_ACKNOWLEDGE);
+ break;
+ default:
+ context = cf.createContext(JMSContext.AUTO_ACKNOWLEDGE);
+ break;
+ }
+ consumer = context.createConsumer(dest);
+ consumer.setMessageListener(this);
+ context.start();
+
+ JMSContext prodCtx = cf.createContext();
+ JMSProducer producer = prodCtx.createProducer();
+ producer.setDeliveryMode(DeliveryMode.PERSISTENT);
+ TextMessage msg = prodCtx.createTextMessage("test redeliveryTime");
+ producer.send(dest, msg);
+
+ // Wait to receive the message.
+ Thread.sleep(10000);
+
+ assertTrue("The rollback or recover message not received after the redelivery delay", time >= 5000);
+
+ context.close();
+ prodCtx.close();
+ }
+
+ public void reset() {
+ first = true;
+ time = 0;
+ }
+
+ private boolean first = true;
+ private long time = 0;
+
+ public void onMessage(Message message) {
+ try {
+ System.out.println(message.getJMSMessageID() + ", JMSRedelivered = " + message.getJMSRedelivered());
+ System.out.println(System.currentTimeMillis() + ": message received deliveryTime = " + message.getJMSDeliveryTime());
+ } catch (JMSException e) {
+ e.printStackTrace();
+ }
+
+ time = System.currentTimeMillis() - time;
+ System.out.println("Waiting (" + first + ") " + time);
+
+ if (first) {
+ first = false;
+ switch (context.getSessionMode()) {
+ case JMSContext.SESSION_TRANSACTED:
+ System.out.println("rollback");
+ context.rollback();
+ break;
+ case JMSContext.CLIENT_ACKNOWLEDGE:
+ System.out.println("recover");
+ context.recover();
+ break;
+ default:
+ System.out.println("throw RuntimeException");
+ throw new RuntimeException("Test redeliveryTime");
+ }
+ } else {
+ switch (context.getSessionMode()) {
+ case JMSContext.SESSION_TRANSACTED:
+ System.out.println("commit");
+ context.commit();
+ break;
+ case JMSContext.CLIENT_ACKNOWLEDGE:
+ System.out.println("acknowledge");
+ context.acknowledge();
+ break;
+ default:
+ System.out.println("nothing");
+ }
+ }
+ }
+
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/RedeliveryDelayTDefaultTest.java b/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/RedeliveryDelayTDefaultTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..501fe2a7b1f7ce311ea507b970a99f8248fa7ff3
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/RedeliveryDelayTDefaultTest.java
@@ -0,0 +1,175 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2016 ScalAgent Distributed Technologies
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s):
+ * Contributor(s):
+ */
+package jms.jms2.integrationtest;
+
+import javax.jms.ConnectionFactory;
+import javax.jms.DeliveryMode;
+import javax.jms.JMSConsumer;
+import javax.jms.JMSContext;
+import javax.jms.JMSException;
+import javax.jms.JMSProducer;
+import javax.jms.Message;
+import javax.jms.TextMessage;
+
+import org.junit.jupiter.api.Test;
+import org.objectweb.joram.client.jms.Topic;
+import org.objectweb.joram.client.jms.admin.AdminModule;
+import org.objectweb.joram.client.jms.admin.User;
+import org.objectweb.joram.client.jms.tcp.TcpConnectionFactory;
+import org.ow2.joram.testutils.AgentManager;
+
+import junit.framework.TestCase;
+
+/**
+ * Test : The message received by the consumer rollback, recover or throw an exception.
+ * The delivery delay is set on server. The message must re-delivered
+ * after the delivery delay.
+ */
+public class RedeliveryDelayTDefaultTest extends TestCase implements javax.jms.MessageListener {
+
+ JMSContext context;
+ JMSConsumer consumer;
+
+ ConnectionFactory cf = null;
+ Topic dest = null;
+
+ public void setUp() throws Exception {
+ cf = TcpConnectionFactory.create("localhost", 16010);
+ AdminModule.connect(cf, "root", "root");
+ // Default mode
+ System.out.println("Default redelivery delay set.");
+ User.create("anonymous", "anonymous", 0);
+
+ dest = Topic.create("RedeliveryDelayTDefaultTest");
+ dest.setFreeReading();
+ dest.setFreeWriting();
+ AdminModule.disconnect();
+ }
+
+ @Test
+ public void testRedeliverySessionTransacted() throws Exception {
+ deliverMessage(JMSContext.SESSION_TRANSACTED);
+ AgentManager.restartAgentServer();
+ System.out.println("Server restarted.");
+ deliverMessage(JMSContext.SESSION_TRANSACTED);
+ }
+
+ @Test
+ public void testRedeliveryClientAcknowledge() throws Exception {
+ deliverMessage(JMSContext.CLIENT_ACKNOWLEDGE);
+ AgentManager.restartAgentServer();
+ System.out.println("Server restarted.");
+ deliverMessage(JMSContext.CLIENT_ACKNOWLEDGE);
+ }
+
+ @Test
+ public void testRedeliveryAutoAcknowledge() throws Exception {
+ deliverMessage(JMSContext.AUTO_ACKNOWLEDGE);
+ AgentManager.restartAgentServer();
+ System.out.println("Server restarted.");
+ deliverMessage(JMSContext.AUTO_ACKNOWLEDGE);
+ }
+
+ void deliverMessage(int sessionMode) throws InterruptedException {
+ reset();
+ switch (sessionMode) {
+ case JMSContext.SESSION_TRANSACTED:
+ context = cf.createContext(JMSContext.SESSION_TRANSACTED);
+ break;
+ case JMSContext.CLIENT_ACKNOWLEDGE:
+ context = cf.createContext(JMSContext.CLIENT_ACKNOWLEDGE);
+ break;
+ default:
+ context = cf.createContext(JMSContext.AUTO_ACKNOWLEDGE);
+ break;
+ }
+ consumer = context.createConsumer(dest);
+ consumer.setMessageListener(this);
+ context.start();
+
+ JMSContext prodCtx = cf.createContext();
+ JMSProducer producer = prodCtx.createProducer();
+ producer.setDeliveryMode(DeliveryMode.PERSISTENT);
+ TextMessage msg = prodCtx.createTextMessage("test redeliveryTime");
+ producer.send(dest, msg);
+
+ // Wait to receive the message.
+ Thread.sleep(10000);
+
+ assertTrue("The rollback or recover message not received after the redelivery delay", time >= 5000);
+
+ context.close();
+ prodCtx.close();
+ }
+
+ public void reset() {
+ first = true;
+ time = 0;
+ }
+
+ private boolean first = true;
+ private long time = 0;
+
+ public void onMessage(Message message) {
+ try {
+ System.out.println(message.getJMSMessageID() + ", JMSRedelivered = " + message.getJMSRedelivered());
+ System.out.println(System.currentTimeMillis() + ": message received deliveryTime = " + message.getJMSDeliveryTime());
+ } catch (JMSException e) {
+ e.printStackTrace();
+ }
+
+ time = System.currentTimeMillis() - time;
+ System.out.println("Waiting (" + first + ") " + time);
+
+ if (first) {
+ first = false;
+ switch (context.getSessionMode()) {
+ case JMSContext.SESSION_TRANSACTED:
+ System.out.println("rollback");
+ context.rollback();
+ break;
+ case JMSContext.CLIENT_ACKNOWLEDGE:
+ System.out.println("recover");
+ context.recover();
+ break;
+ default:
+ System.out.println("throw RuntimeException");
+ throw new RuntimeException("Test redeliveryTime");
+ }
+ } else {
+ switch (context.getSessionMode()) {
+ case JMSContext.SESSION_TRANSACTED:
+ System.out.println("commit");
+ context.commit();
+ break;
+ case JMSContext.CLIENT_ACKNOWLEDGE:
+ System.out.println("acknowledge");
+ context.acknowledge();
+ break;
+ default:
+ System.out.println("nothing");
+ }
+ }
+ }
+
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/SharedConsumer1Test.java b/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/SharedConsumer1Test.java
new file mode 100644
index 0000000000000000000000000000000000000000..0c6a2d753da7bed1ae166f7af6dddc961bfc84b7
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/SharedConsumer1Test.java
@@ -0,0 +1,172 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2013 ScalAgent Distributed Technologies
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s): ScalAgent Distributed Technologies
+ */
+package jms.jms2.integrationtest;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSConsumer;
+import javax.jms.JMSContext;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+import org.junit.jupiter.api.Test;
+import org.objectweb.joram.client.jms.Topic;
+import org.objectweb.joram.client.jms.admin.AdminModule;
+import org.objectweb.joram.client.jms.admin.User;
+import org.objectweb.joram.client.jms.tcp.TcpConnectionFactory;
+
+import junit.framework.TestCase;
+
+/**
+ * Create a Topic, JMSContext, Connection and User.
+ *
+ * - create 2 shared durable consumers on the topic
+ * - create 1 consumer on the topic
+ * - Set message listener for the 3 consumers
+ * - send 2 messages on the topic
+ * - verify that the shared consumers receive 1 message and the non-shared consumer receive 2 messages
+ *
+ * Remove the one message listener on the shared consumer
+ * - send 2 messages on the topic
+ * - verify that the shared consumers receive 2 message and the non-shared consumer receive 2 messages
+ *
+ */
+public class SharedConsumer1Test extends TestCase {
+
+ final String subName = "sharedConsumer1Test";
+
+ @Test
+ public void testSharedConsumer() throws Exception {
+
+ ConnectionFactory cf = TcpConnectionFactory.create("localhost", 16010);
+ AdminModule.connect(cf, "root", "root");
+ User.create("anonymous", "anonymous", 0);
+ Topic topic = Topic.create("SharedConsumer1Test");
+ topic.setFreeReading();
+ topic.setFreeWriting();
+ AdminModule.disconnect();
+
+ Connection cnx = cf.createConnection();
+ cnx.start();
+
+ // create shared consumer
+ JMSContext context = cf.createContext();
+ JMSConsumer receiver1 = context.createSharedDurableConsumer(topic, subName);
+ JMSConsumer receiver2 = context.createSharedDurableConsumer(topic, subName);
+
+ // create non-shared consumer
+ Session sess = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageConsumer receiver3 = sess.createConsumer(topic);
+
+ MsgListener ml1 = new MsgListener("1-Listener on topic");
+ MsgListener ml2 = new MsgListener("2-Listener on topic");
+ MsgListener ml3 = new MsgListener("3-Listener on topic");
+
+ receiver1.setMessageListener(ml1);
+ receiver2.setMessageListener(ml2);
+ receiver3.setMessageListener(ml3);
+
+ sendMsg(cnx, topic, 2);
+
+ Thread.sleep(100);
+ assertEquals("1-Listener : ", 1, ml1.getNbMsgReceived());
+ assertEquals("2-Listener : ", 1, ml2.getNbMsgReceived());
+ assertEquals("3-Listener : ", 2, ml3.getNbMsgReceived());
+ ml1.reset();
+ ml2.reset();
+ ml3.reset();
+
+ System.out.println("remove listener 1");
+ receiver1.setMessageListener(null);
+ sendMsg(cnx, topic, 2);
+ Thread.sleep(100);
+ assertEquals("1-Listener : ", 0, ml1.getNbMsgReceived());
+ assertEquals("2-Listener : ", 2, ml2.getNbMsgReceived());
+ assertEquals("3-Listener : ", 2, ml3.getNbMsgReceived());
+ ml1.reset();
+ ml2.reset();
+ ml3.reset();
+
+ System.out.println("remove listener 2");
+ receiver2.setMessageListener(null);
+ sendMsg(cnx, topic, 2);
+ Thread.sleep(100);
+ assertEquals("1-Listener : ", 0, ml1.getNbMsgReceived());
+ assertEquals("2-Listener : ", 0, ml2.getNbMsgReceived());
+ assertEquals("3-Listener : ", 2, ml3.getNbMsgReceived());
+ ml1.reset();
+ ml2.reset();
+ ml3.reset();
+
+ System.out.println("Close.");
+ receiver1.close();
+ receiver2.close();
+ receiver3.close();
+ System.out.println("unsubscribe");
+ sess.unsubscribe(subName);
+ context.close();
+ cnx.close();
+ }
+
+ public void sendMsg(Connection cnx, Topic topic, int nbMsg) throws JMSException {
+ Session sess = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer producer = sess.createProducer(topic);
+ for (int i = 0; i < nbMsg; i++) {
+ TextMessage msg = sess.createTextMessage("Test number " + i);
+ producer.send(msg);
+ }
+ }
+
+ class MsgListener implements MessageListener {
+ private String ident = null;
+ private int nbMsgReceived = 0;
+
+ public MsgListener(String ident) {
+ this.ident = ident;
+ }
+
+ public void onMessage(Message msg) {
+ try {
+ if (msg instanceof TextMessage) {
+ System.out.println(ident + ": " + ((TextMessage) msg).getText());
+ nbMsgReceived++;
+ }
+ } catch (JMSException e) {
+ System.err.println("Exception in listener: " + e);
+ fail(e.getMessage());
+ }
+ }
+
+ public int getNbMsgReceived() {
+ return nbMsgReceived;
+ }
+
+ public void reset() {
+ nbMsgReceived = 0;
+ }
+ }
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/SharedConsumer2Test.java b/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/SharedConsumer2Test.java
new file mode 100644
index 0000000000000000000000000000000000000000..82be2c7162aa3768b25d6b9a89130d70509595ea
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/jms2/integrationtest/SharedConsumer2Test.java
@@ -0,0 +1,207 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2013 ScalAgent Distributed Technologies
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s): ScalAgent Distributed Technologies
+ */
+package jms.jms2.integrationtest;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSConsumer;
+import javax.jms.JMSContext;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+import org.junit.jupiter.api.Test;
+import org.objectweb.joram.client.jms.Topic;
+import org.objectweb.joram.client.jms.admin.AdminModule;
+import org.objectweb.joram.client.jms.admin.User;
+import org.objectweb.joram.client.jms.tcp.TcpConnectionFactory;
+
+import junit.framework.TestCase;
+
+/**
+ * Create a Topic, JMSContext, Connection and User.
+ *
+ * On main thread:
+ * - create 2 shared durable consumers ("sharedConsumerTest") on the topic
+ * - create 2 non-shared consumer on the topic
+ * - Set message listener for the 4 consumers
+ * On Thread 1:
+ * - create 1 shared durable consumer ("sharedConsumerTest") on the topic
+ *
+ * - send 3 messages on the topic
+ * - verify that the shared consumers (main and Thread) receive 1 message and the non-shared consumer receive 3 messages
+ *
+ * - send 30 messages on the topic
+ * - verify that the sum of received messages by the shared consumer is 30.
+ * - verify that the non-shared consumer received 30 messages each one.
+ */
+public class SharedConsumer2Test extends TestCase {
+
+ final String subName = "sharedConsumer2Test";
+
+ @Test
+ public void testSharedConsumer() throws Exception {
+
+ /* TODO fix test ? (flaky, often fails, not always...)
+ final ConnectionFactory cf = TcpConnectionFactory.create("localhost", 16010);
+ AdminModule.connect(cf, "root", "root");
+ User.create("anonymous", "anonymous", 0);
+ final Topic topic = Topic.create("SharedConsumer2Test");
+ topic.setFreeReading();
+ topic.setFreeWriting();
+ AdminModule.disconnect();
+
+ Connection cnx = cf.createConnection();
+ cnx.start();
+
+ // create shared consumer
+ JMSContext context = cf.createContext();
+ JMSConsumer receiver1 = context.createSharedDurableConsumer(topic, subName);
+ JMSConsumer receiver2 = context.createSharedDurableConsumer(topic, subName);
+
+ // create non-shared consumer
+ Session sess = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageConsumer receiver3 = sess.createConsumer(topic);
+ Session sess1 = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageConsumer receiver4 = sess1.createConsumer(topic);
+
+ MsgListener ml1 = new MsgListener("Main-1-Listener on topic");
+ MsgListener ml2 = new MsgListener("Main-2-Listener on topic");
+ MsgListener ml3 = new MsgListener("Main-3-Listener on topic");
+ MsgListener ml4 = new MsgListener("Main-4-Listener on topic");
+
+ final MsgListener ml = new MsgListener("Thread-1-Listener on topic");
+ Thread t = new Thread() {
+ public synchronized void run() {
+ try {
+ consumer(cf, topic, ml);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ try {
+ wait(50000);
+ } catch (InterruptedException e) { }
+ }
+ };
+ t.start();
+
+ receiver1.setMessageListener(ml1);
+ receiver2.setMessageListener(ml2);
+ receiver3.setMessageListener(ml3);
+ receiver4.setMessageListener(ml4);
+
+ // send 3 messages
+ System.out.println("== send 3");
+ sendMsg(cnx, topic, 3);
+ Thread.sleep(100);
+ assertEquals("Main-1-Listener : ", 1, ml1.getNbMsgReceived());
+ assertEquals("Main-2-Listener : ", 1, ml2.getNbMsgReceived());
+ assertEquals("Main-3-Listener : ", 3, ml3.getNbMsgReceived());
+ assertEquals("Main-4-Listener : ", 3, ml4.getNbMsgReceived());
+ assertEquals("Thread-1-Listener : ", 1, ml.getNbMsgReceived());
+ ml1.reset();
+ ml2.reset();
+ ml3.reset();
+ ml4.reset();
+ ml.reset();
+
+ // send 30 message
+ int nbMsgTosend = 30;
+ System.out.println("\n== send " + nbMsgTosend);
+ sendMsg(cnx, topic, nbMsgTosend);
+ Thread.sleep(500);
+ assertEquals("Main-3-Listener : ", nbMsgTosend, ml3.getNbMsgReceived());
+ assertEquals("Main-4-Listener : ", nbMsgTosend, ml4.getNbMsgReceived());
+ assertEquals("Shared consumers : ", nbMsgTosend, ml.getNbMsgReceived() + ml1.getNbMsgReceived() + ml2.getNbMsgReceived());
+ ml1.reset();
+ ml2.reset();
+ ml3.reset();
+ ml4.reset();
+ ml.reset();
+
+
+ System.out.println("Close.");
+ receiver1.close();
+ receiver2.close();
+ receiver3.close();
+ receiver4.close();
+ System.out.println("unsubscribe");
+ sess.unsubscribe(subName);
+ context.close();
+ cnx.close();
+
+ synchronized (t) {
+ t.notify();
+ }
+ */
+ }
+
+ public void sendMsg(Connection cnx, Topic topic, int nbMsg) throws JMSException {
+ System.out.println("send " + nbMsg + " messages on topic");
+ Session sess = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer producer = sess.createProducer(topic);
+ for (int i = 0; i < nbMsg; i++) {
+ TextMessage msg = sess.createTextMessage("Test number " + i);
+ producer.send(msg);
+ }
+ }
+
+ public void consumer(ConnectionFactory cf, Topic topic, MsgListener ml) {
+ // create shared consumer
+ JMSContext context = cf.createContext();
+ JMSConsumer receiver = context.createSharedDurableConsumer(topic, subName);
+ receiver.setMessageListener(ml);
+ }
+
+ class MsgListener implements MessageListener {
+ private String ident = null;
+ private int nbMsgReceived = 0;
+
+ public MsgListener(String ident) {
+ this.ident = ident;
+ }
+
+ public void onMessage(Message msg) {
+ try {
+ if (msg instanceof TextMessage) {
+ System.out.println(ident + ": " + ((TextMessage) msg).getText());
+ nbMsgReceived++;
+ }
+ } catch (JMSException e) {
+ System.err.println("Exception in listener: " + e);
+ fail(e.getMessage());
+ }
+ }
+
+ public int getNbMsgReceived() {
+ return nbMsgReceived;
+ }
+
+ public void reset() {
+ nbMsgReceived = 0;
+ }
+ }
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/main/Tests.java b/joram/joram/client/jms/src/test/java/jms/main/Tests.java
new file mode 100644
index 0000000000000000000000000000000000000000..293423b9b179f275fdb2f142879622efc72c0045
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/main/Tests.java
@@ -0,0 +1,108 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2007 ScalAgent Distributed Technologies
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s): Nicolas Tachker (ScalAgent)
+ * Contributor(s):
+ */
+package jms.main;
+
+import java.io.File;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.util.ArrayList;
+
+import jms.framework.JMSTestCase;
+
+
+/**
+ */
+public class Tests {
+
+ public static Class[] getClasses(String pckgname)
+ throws ClassNotFoundException {
+ ArrayList classes = new ArrayList();
+ // Get a File object for the package
+ File directory = null;
+ try {
+ ClassLoader cld = Thread.currentThread().getContextClassLoader();
+ if (cld == null) {
+ throw new ClassNotFoundException("Can't get class loader.");
+ }
+ String path = pckgname.replace('.', '/');
+ URL resource = cld.getResource(path);
+ if (resource == null) {
+ throw new ClassNotFoundException("No resource for " + path);
+ }
+ directory = new File(resource.getFile());
+ } catch (NullPointerException x) {
+ throw new ClassNotFoundException(pckgname + " (" + directory
+ + ") does not appear to be a valid package");
+ }
+ if (directory.exists()) {
+ findClass(directory, classes, pckgname);
+ }
+ Class[] classesA = new Class[classes.size()];
+ classes.toArray(classesA);
+ return classesA;
+ }
+
+ public static void findClass(File directory, ArrayList classes,
+ String pckgname) {
+ // Get the list of the files contained in the package
+ String[] files = directory.list();
+ for (int i = 0; i < files.length; i++) {
+ // we are only interested in .class files
+ if (files[i].endsWith(".class")) {
+ // removes the .class extension
+ try {
+ classes.add(Class.forName(pckgname + '.'
+ + files[i].substring(0, files[i].length() - 6)));
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ }
+ } else if (new File(directory, files[i]).isDirectory()) {
+ findClass(new File(directory, files[i]), classes, pckgname + '.'
+ + files[i]);
+ }
+ }
+ }
+
+ /**
+ * @param args
+ * @throws Exception
+ */
+ public static void main(String[] args) throws Exception {
+
+ Class[] classes = getClasses("jms.conform");
+ Method method = null;
+ for (int i = 0; i < classes.length; i++) {
+ try {
+ Object obj = classes[i].newInstance();
+ if (obj instanceof JMSTestCase) {
+ method = classes[i].getMethod("main", new Class[]{String[].class});
+ if (method != null)
+ method.invoke(null, new Object[]{args});
+ }
+ } catch (InstantiationException e) {
+ }
+ }
+
+ }
+
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/providers/admin/JoramAdmin.java b/joram/joram/client/jms/src/test/java/jms/providers/admin/JoramAdmin.java
new file mode 100644
index 0000000000000000000000000000000000000000..53a4ee31feda671d6a0630c72cc6421b798ecaec
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/providers/admin/JoramAdmin.java
@@ -0,0 +1,109 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2002 - 2007 ScalAgent Distributed Technologies
+ * Copyright (C) 2002 INRIA
+ * Contact: joram-team@objectweb.org
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s): Jeff Mesnil (Inria)
+ * Contributor(s): Nicolas Tachker (ScalAgent D.T.)
+ */
+
+package jms.providers.admin;
+
+import java.net.ConnectException;
+
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSException;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.TopicConnectionFactory;
+
+import jms.admin.Admin;
+
+import org.objectweb.joram.client.jms.Queue;
+import org.objectweb.joram.client.jms.Topic;
+import org.objectweb.joram.client.jms.admin.AdminException;
+import org.objectweb.joram.client.jms.admin.AdminModule;
+import org.objectweb.joram.client.jms.admin.User;
+import org.objectweb.joram.client.jms.tcp.QueueTcpConnectionFactory;
+import org.objectweb.joram.client.jms.tcp.TcpConnectionFactory;
+import org.objectweb.joram.client.jms.tcp.TopicTcpConnectionFactory;
+
+public class JoramAdmin implements Admin {
+ private String name = "JORAM";
+
+ public JoramAdmin() {
+ try {
+ AdminModule.connect("root", "root", 30);
+ User.create("anonymous", "anonymous");
+ } catch (Exception e) {
+ if(e.getMessage() == null || ! e.getMessage().contains("Already connected")) e.printStackTrace();
+ }
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public ConnectionFactory createConnectionFactory(String name) throws ConnectException {
+ return TcpConnectionFactory.create();
+ }
+
+ public QueueConnectionFactory createQueueConnectionFactory(String name) throws ConnectException {
+ return QueueTcpConnectionFactory.create();
+ }
+
+ public TopicConnectionFactory createTopicConnectionFactory(String name) throws ConnectException {
+ return TopicTcpConnectionFactory.create();
+ }
+
+ public Queue createQueue(String name) throws ConnectException, AdminException {
+ Queue queue = null;
+ queue = Queue.create(name);
+ queue.setFreeWriting();
+ queue.setFreeReading();
+ return queue;
+ }
+
+ public Topic createTopic(String name) throws ConnectException, AdminException {
+ Topic topic = Topic.create(name);
+ topic.setFreeWriting();
+ topic.setFreeReading();
+ return topic;
+ }
+
+ public void deleteQueue(javax.jms.Destination queue) throws ConnectException, AdminException, JMSException {
+ if(queue != null) ((org.objectweb.joram.client.jms.Destination)queue).delete();
+ }
+
+ public void deleteTopic(javax.jms.Destination topic) throws ConnectException, AdminException, JMSException {
+ if(topic != null) ((org.objectweb.joram.client.jms.Destination)topic).delete();
+ }
+
+ public void deleteConnectionFactory(String name) {
+ }
+
+ public void deleteTopicConnectionFactory(String name) {
+ }
+
+ public void deleteQueueConnectionFactory(String name) {
+ }
+
+ public void disconnect() {
+ AdminModule.disconnect();
+ }
+}
diff --git a/joram/joram/client/jms/src/test/java/jms/providers/admin/a3config.dtd b/joram/joram/client/jms/src/test/java/jms/providers/admin/a3config.dtd
new file mode 100644
index 0000000000000000000000000000000000000000..6b36c60a5e5fb7503090787cee0654430ab8c86e
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/providers/admin/a3config.dtd
@@ -0,0 +1,59 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/joram/joram/client/jms/src/test/java/jms/providers/admin/a3debug.cfg b/joram/joram/client/jms/src/test/java/jms/providers/admin/a3debug.cfg
new file mode 100644
index 0000000000000000000000000000000000000000..69959ab37882fe776edced19fff4f6e9c0a27827
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/providers/admin/a3debug.cfg
@@ -0,0 +1,40 @@
+log.config.classname org.objectweb.util.monolog.wrapper.javaLog.LoggerFactory
+
+# ==============================
+# tty : console handler
+# handler.tty.type Console
+# handler.tty.output System.err
+# handler.tty.pattern %l %h %d, %m%n
+
+# ==============================
+# logf : rolling file handler
+handler.logf.type RollingFile
+handler.logf.output server.log
+handler.logf.pattern %l %h %d, %m%n
+handler.logf.fileNumber 2
+handler.logf.maxSize 100000000
+
+# ==============================
+# logger definitions
+# logger.root.handler.0 tty
+logger.root.handler.0 logf
+
+logger.root.level ERROR
+
+# ==============================
+# ScalAgent middleware
+# logger.fr.dyade.aaa.level DEBUG
+
+# logger.fr.dyade.aaa.agent.Agent.level WARN
+# logger.fr.dyade.aaa.agent.AgentServer.level DEBUG
+# logger.fr.dyade.aaa.agent.Engine.level WARN
+# logger.fr.dyade.aaa.agent.Network.level DEBUG
+# logger.org.objectweb.joram.mom.dest.level DEBUG
+# logger.fr.dyade.aaa.agent.Transaction.level WARN
+# logger.org.objectweb.joram.client.level DEBUG
+
+# logger.com.scalagent.level DEBUG
+# ==============================
+# Joram middleware
+# logger.org.objectweb.joram.level DEBUG
+# logger.fr.dyade.aaa.util.ReliableTcpConnection.level DEBUG
diff --git a/joram/joram/client/jms/src/test/java/jms/providers/admin/a3servers.xml b/joram/joram/client/jms/src/test/java/jms/providers/admin/a3servers.xml
new file mode 100644
index 0000000000000000000000000000000000000000..d08dd47ddf9b2499ff4d94f9f3f314d7476f9ac7
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/providers/admin/a3servers.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/joram/joram/client/jms/src/test/java/jms/providers/admin/provider.properties b/joram/joram/client/jms/src/test/java/jms/providers/admin/provider.properties
new file mode 100644
index 0000000000000000000000000000000000000000..1b7f61ebf898f872ae77dce154a2932d6103f8f2
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/providers/admin/provider.properties
@@ -0,0 +1,30 @@
+##
+# JORAM: Java(TM) Open Reliable Asynchronous Messaging
+# Copyright (C) 2002 INRIA
+# Contact: joram-team@objectweb.org
+#
+# This library 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 any later version.
+#
+# This library 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 library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+# USA
+#
+# Initial developer(s): Jeff Mesnil (jmesnil@inrialpes.fr)
+# Contributor(s): ______________________________________.
+##
+
+##
+# This property is used to chose which provider is to be tested
+# Uncomment the chosen provider and comment the other ones
+##
+
+jms.provider.admin.class = jms.providers.admin.JoramAdmin
\ No newline at end of file
diff --git a/joram/joram/client/jms/src/test/java/jms/providers/admin/test.properties b/joram/joram/client/jms/src/test/java/jms/providers/admin/test.properties
new file mode 100644
index 0000000000000000000000000000000000000000..1a31f57e6ad14615dd17cff9472de82eaa109210
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/jms/providers/admin/test.properties
@@ -0,0 +1,29 @@
+##
+# JORAM: Java(TM) Open Reliable Asynchronous Messaging
+# Copyright (C) 2002 INRIA
+# Contact: joram-team@objectweb.org
+#
+# This library 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 any later version.
+#
+# This library 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 library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+# USA
+#
+# Initial developer(s): Jeff Mesnil (jmesnil@inrialpes.fr)
+# Contributor(s): ______________________________________.
+##
+
+# Timeout specified for receive(long time) method
+# Time in milliseconds or 0 for never expiring
+# Default is set to 30 seconds (long enough to receive slow messages
+# and won't hang up tests infinitely)
+timeout = 30000
\ No newline at end of file
diff --git a/joram/joram/client/jms/src/test/java/org/objectweb/joram/client/jms/admin/AMQPAcquisitionQueueTest.java b/joram/joram/client/jms/src/test/java/org/objectweb/joram/client/jms/admin/AMQPAcquisitionQueueTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..4bdff5967ab57549c680faf6ad2c80c2635a9de6
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/org/objectweb/joram/client/jms/admin/AMQPAcquisitionQueueTest.java
@@ -0,0 +1,25 @@
+package org.objectweb.joram.client.jms.admin;
+
+import java.net.ConnectException;
+
+import org.junit.jupiter.api.Test;
+
+import jms.framework.PTPTestCase;
+
+public class AMQPAcquisitionQueueTest extends PTPTestCase {
+
+ @Test
+ public void testCreate() {
+ try {
+ assertNotNull(AMQPAcquisitionQueue.create("AMQPAcquisitionQueue"));
+ assertNotNull(AMQPAcquisitionQueue.create(0, "AMQPAcquisitionQueue2"));
+ } catch (ConnectException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch(AdminException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/joram/joram/client/jms/src/test/java/org/objectweb/joram/client/jms/admin/AMQPDistributionQueueTest.java b/joram/joram/client/jms/src/test/java/org/objectweb/joram/client/jms/admin/AMQPDistributionQueueTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..946d3658366007b8384be8e123011841d75d50e3
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/org/objectweb/joram/client/jms/admin/AMQPDistributionQueueTest.java
@@ -0,0 +1,25 @@
+package org.objectweb.joram.client.jms.admin;
+
+import java.net.ConnectException;
+
+import org.junit.jupiter.api.Test;
+
+import jms.framework.PTPTestCase;
+
+public class AMQPDistributionQueueTest extends PTPTestCase {
+
+ @Test
+ public void testCreate() {
+ try {
+ assertNotNull(AMQPDistributionQueue.create("AMQPDistributionQueue"));
+ assertNotNull(AMQPDistributionQueue.create(0, "AMQPDistributionQueue2"));
+ } catch (ConnectException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch(AdminException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/joram/joram/client/jms/src/test/java/org/objectweb/joram/client/jms/admin/CollectorQueueTest.java b/joram/joram/client/jms/src/test/java/org/objectweb/joram/client/jms/admin/CollectorQueueTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..5a458e927b8a2649d2e556020309be5fe6d6b5dd
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/org/objectweb/joram/client/jms/admin/CollectorQueueTest.java
@@ -0,0 +1,25 @@
+package org.objectweb.joram.client.jms.admin;
+
+import java.net.ConnectException;
+
+import org.junit.jupiter.api.Test;
+
+import jms.framework.PTPTestCase;
+
+public class CollectorQueueTest extends PTPTestCase {
+
+ @Test
+ public void testCreate() {
+ try {
+ assertNotNull(CollectorQueue.create("any.url.CollectorQueue"));
+ assertNotNull(CollectorQueue.create(0, "any.url.CollectorQueue2"));
+ } catch (ConnectException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch(AdminException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/joram/joram/client/jms/src/test/java/org/objectweb/joram/client/jms/admin/FtpQueueTest.java b/joram/joram/client/jms/src/test/java/org/objectweb/joram/client/jms/admin/FtpQueueTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..381f263d6165fdb8369781090fc6966cacc7d336
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/org/objectweb/joram/client/jms/admin/FtpQueueTest.java
@@ -0,0 +1,25 @@
+package org.objectweb.joram.client.jms.admin;
+
+import java.net.ConnectException;
+
+import org.junit.jupiter.api.Test;
+
+import jms.framework.PTPTestCase;
+
+public class FtpQueueTest extends PTPTestCase {
+
+ @Test
+ public void testCreate() {
+ try {
+ assertNotNull(FtpQueue.create("FtpQueue"));
+ assertNotNull(FtpQueue.create(0, "FtpQueue2"));
+ } catch (ConnectException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch(AdminException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/joram/joram/client/jms/src/test/java/org/objectweb/joram/client/jms/admin/JMSAcquisitionQueueTest.java b/joram/joram/client/jms/src/test/java/org/objectweb/joram/client/jms/admin/JMSAcquisitionQueueTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..32ceae118b1fa4ca2b4a4e29934f0eb002947a0b
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/org/objectweb/joram/client/jms/admin/JMSAcquisitionQueueTest.java
@@ -0,0 +1,25 @@
+package org.objectweb.joram.client.jms.admin;
+
+import java.net.ConnectException;
+
+import org.junit.jupiter.api.Test;
+
+import jms.framework.PTPTestCase;
+
+public class JMSAcquisitionQueueTest extends PTPTestCase {
+
+ @Test
+ public void testCreate() {
+ try {
+ assertNotNull(JMSAcquisitionQueue.create("JMSAcquisitionQueue"));
+ assertNotNull(JMSAcquisitionQueue.create(0, "JMSAcquisitionQueue2"));
+ } catch (ConnectException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch(AdminException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/joram/joram/client/jms/src/test/java/org/objectweb/joram/client/jms/admin/JMSDistributionQueueTest.java b/joram/joram/client/jms/src/test/java/org/objectweb/joram/client/jms/admin/JMSDistributionQueueTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..f463bbe03b94a5b65bb04aaa6d8552f1ca0a97bc
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/org/objectweb/joram/client/jms/admin/JMSDistributionQueueTest.java
@@ -0,0 +1,25 @@
+package org.objectweb.joram.client.jms.admin;
+
+import java.net.ConnectException;
+
+import org.junit.jupiter.api.Test;
+
+import jms.framework.PTPTestCase;
+
+public class JMSDistributionQueueTest extends PTPTestCase {
+
+ @Test
+ public void testCreate() {
+ try {
+ assertNotNull(JMSDistributionQueue.create("JMSDistributionQueue"));
+ assertNotNull(JMSDistributionQueue.create(0, "JMSDistributionQueue2"));
+ } catch (ConnectException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch(AdminException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/joram/joram/client/jms/src/test/java/org/objectweb/joram/client/jms/admin/MailAcquisitionQueueTest.java b/joram/joram/client/jms/src/test/java/org/objectweb/joram/client/jms/admin/MailAcquisitionQueueTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..4089d24431836c0f8afd61a29cb39408709429a6
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/org/objectweb/joram/client/jms/admin/MailAcquisitionQueueTest.java
@@ -0,0 +1,26 @@
+package org.objectweb.joram.client.jms.admin;
+
+import java.net.ConnectException;
+
+import org.junit.jupiter.api.Test;
+
+import jms.framework.PTPTestCase;
+
+public class MailAcquisitionQueueTest extends PTPTestCase {
+
+ @Test
+ public void testCreate() {
+ try {
+ assertNotNull(MailAcquisitionQueue.create());
+ assertNotNull(MailAcquisitionQueue.create(0));
+ assertNotNull(MailAcquisitionQueue.create(0, "MailAcquisitionQueue"));
+ } catch (ConnectException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch(AdminException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/joram/joram/client/jms/src/test/java/org/objectweb/joram/client/jms/admin/MailDistributionQueueTest.java b/joram/joram/client/jms/src/test/java/org/objectweb/joram/client/jms/admin/MailDistributionQueueTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..0ac301b67a4231d9472f9e98385e8facb61af51f
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/org/objectweb/joram/client/jms/admin/MailDistributionQueueTest.java
@@ -0,0 +1,26 @@
+package org.objectweb.joram.client.jms.admin;
+
+import java.net.ConnectException;
+
+import org.junit.jupiter.api.Test;
+
+import jms.framework.PTPTestCase;
+
+public class MailDistributionQueueTest extends PTPTestCase {
+
+ @Test
+ public void testCreate() {
+ try {
+ assertNotNull(MailDistributionQueue.create());
+ assertNotNull(MailDistributionQueue.create(0));
+ assertNotNull(MailDistributionQueue.create(0, "MailDistributionQueue"));
+ } catch (ConnectException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch(AdminException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/joram/joram/client/jms/src/test/java/org/objectweb/joram/client/jms/admin/MonitoringQueueTest.java b/joram/joram/client/jms/src/test/java/org/objectweb/joram/client/jms/admin/MonitoringQueueTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..95fd8d495261377a52497d5b126303faa47cf2d7
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/org/objectweb/joram/client/jms/admin/MonitoringQueueTest.java
@@ -0,0 +1,26 @@
+package org.objectweb.joram.client.jms.admin;
+
+import java.net.ConnectException;
+
+import org.junit.jupiter.api.Test;
+
+import jms.framework.PTPTestCase;
+
+public class MonitoringQueueTest extends PTPTestCase {
+
+ @Test
+ public void testCreate() {
+ try {
+ assertNotNull(MonitoringQueue.create());
+ assertNotNull(MonitoringQueue.create(0));
+ assertNotNull(MonitoringQueue.create(0, "MonitoringQueue"));
+ } catch (ConnectException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch(AdminException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/joram/joram/client/jms/src/test/java/org/objectweb/joram/client/jms/admin/RestAcquisitionQueueTest.java b/joram/joram/client/jms/src/test/java/org/objectweb/joram/client/jms/admin/RestAcquisitionQueueTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..f60ba479bd8699e5fde27e1088a3ffc72c1bc2b7
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/org/objectweb/joram/client/jms/admin/RestAcquisitionQueueTest.java
@@ -0,0 +1,35 @@
+package org.objectweb.joram.client.jms.admin;
+
+import java.net.ConnectException;
+
+import org.junit.jupiter.api.Test;
+
+import jms.framework.PTPTestCase;
+
+public class RestAcquisitionQueueTest extends PTPTestCase {
+
+ @Test
+ public void testCreate() {
+ try {
+ RestAcquisitionQueue queue = new RestAcquisitionQueue();
+ assertNotNull(queue.create("RestAcquisitionQueue"));
+ assertNotNull(queue.create(0, "RestAcquisitionQueue2"));
+
+ assertEquals(queue.getHost(), "localhost");
+ assertEquals(queue.getPort(), 8989);
+ assertEquals(queue.getUsername(), "anonymous");
+ assertEquals(queue.getPassword(), "anonymous");
+ assertTrue(queue.isMediaTypeJson());
+ assertEquals(queue.getTimeout(), 10000);
+ assertEquals(queue.getAcquisitionPeriod(), -1);
+ assertEquals(queue.getIdleTimeout(), 60);
+ } catch (ConnectException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch(AdminException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/joram/joram/client/jms/src/test/java/org/objectweb/joram/client/jms/admin/RestDistributionQueueTest.java b/joram/joram/client/jms/src/test/java/org/objectweb/joram/client/jms/admin/RestDistributionQueueTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..34fe9b2596d0a8ce594017b4c453374f451c8d14
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/org/objectweb/joram/client/jms/admin/RestDistributionQueueTest.java
@@ -0,0 +1,35 @@
+package org.objectweb.joram.client.jms.admin;
+
+import java.net.ConnectException;
+
+import org.junit.jupiter.api.Test;
+
+import jms.framework.PTPTestCase;
+
+public class RestDistributionQueueTest extends PTPTestCase {
+
+ @Test
+ public void testCreate() {
+ try {
+ RestDistributionQueue queue = new RestDistributionQueue();
+ assertNotNull(queue.create("RestDistributionQueue"));
+ assertNotNull(queue.create(0, "RestDistributionQueue2"));
+
+ assertEquals(queue.getHost(), "localhost");
+ assertEquals(queue.getPort(), 8989);
+ assertEquals(queue.getUserName(), "anonymous");
+ assertEquals(queue.getPassword(), "anonymous");
+ assertTrue(queue.isBatch());
+ assertTrue(queue.isAsync());
+ assertEquals(queue.getPeriod(), 1000);
+ assertEquals(queue.getIdleTimeout(), 60);
+ } catch (ConnectException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch(AdminException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/joram/joram/client/jms/src/test/java/org/objectweb/joram/client/jms/admin/SchedulerQueueTest.java b/joram/joram/client/jms/src/test/java/org/objectweb/joram/client/jms/admin/SchedulerQueueTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..5401612f4a6ea75d059e99dc74ca4045927dcfc0
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/org/objectweb/joram/client/jms/admin/SchedulerQueueTest.java
@@ -0,0 +1,25 @@
+package org.objectweb.joram.client.jms.admin;
+
+import java.net.ConnectException;
+
+import org.junit.jupiter.api.Test;
+
+import jms.framework.PTPTestCase;
+
+public class SchedulerQueueTest extends PTPTestCase {
+
+ @Test
+ public void testCreate() {
+ try {
+ assertNotNull(SchedulerQueue.create("SchedulerQueue"));
+ assertNotNull(SchedulerQueue.create(0, "SchedulerQueue2"));
+ } catch (ConnectException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch(AdminException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/joram/joram/client/jms/src/test/java/org/ow2/joram/testutils/AgentManager.java b/joram/joram/client/jms/src/test/java/org/ow2/joram/testutils/AgentManager.java
new file mode 100644
index 0000000000000000000000000000000000000000..afa26ace8c1016f30723b1977f46bb012beef772
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/org/ow2/joram/testutils/AgentManager.java
@@ -0,0 +1,129 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2002 - 2007 ScalAgent Distributed Technologies
+ * Copyright (C) 2002 INRIA
+ * Contact: joram-team@objectweb.org
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s): Jeff Mesnil (Inria)
+ * Contributor(s): Nicolas Tachker (ScalAgent D.T.)
+ */
+
+package org.ow2.joram.testutils;
+
+import java.io.File;
+import java.util.Properties;
+import java.util.StringTokenizer;
+
+import org.ow2.joram.testutils.SCAdminOSGi;
+
+
+/**
+ * Start / Stop Joram agent server.
+ *
+ */
+public class AgentManager {
+
+ public static SCAdminOSGi admin = new SCAdminOSGi();
+
+ public AgentManager() {
+ super();
+ // Changes the class path with absolute paths
+ try {
+ Properties sysprops = System.getProperties();
+ String classpath = sysprops.getProperty("java.class.path");
+ classpath = getAbsolutePath(classpath);
+ sysprops.setProperty("java.class.path", classpath);
+ } catch (Exception exc) {
+ throw new Error("cannot set absolute classpath");
+ }
+ }
+
+ /**
+ * Start Joram agent server
+ * @throws Exception
+ */
+ public static void startAgentServer() throws Exception {
+ //SCAdminOSGi admin = new SCAdminOSGi();
+ //TODO select admin type ?? SCAdminClassic admin = new SCAdminClassic();
+ try {
+ admin.startAgentServer((short)0);
+ } catch (IllegalStateException exc) {
+ // The process is still alive, kill it!
+ admin.killAgentServer((short)0);
+ Thread.sleep(1000);
+ admin.startAgentServer((short)0);
+ throw(exc);
+ }
+ //Thread.sleep(1000);
+ }
+
+ /**
+ * Stop Joram agent server
+ * @throws Exception
+ */
+ public static void stopAgentServer() throws Exception {
+ //SCAdminOSGi admin = new SCAdminOSGi();
+ try {
+ admin.stopAgentServer((short)0);
+ } catch (Exception exc) {
+ //ignore ?
+ throw(exc);
+ }
+ //TODO endTest() to report test results ?? also see error(exception) in old BaseTestCase
+ //endTest(null, false);
+ }
+
+ public static void restartAgentServer() throws Exception {
+ //Thread.sleep(1000);
+ AgentManager.stopAgentServer();
+ Thread.sleep(500);
+ AgentManager.startAgentServer();
+ }
+
+ /**
+ * Change the elements of a path as absolute names.
+ * Use the property path.separator as separator.
+ *
+ * @param path path to transform
+ *
+ * @return transformed path
+ */
+ private static String getAbsolutePath(String path) throws Exception {
+ String ps = System.getProperty("path.separator");
+ StringTokenizer st = new StringTokenizer(path, ps);
+ if (! st.hasMoreTokens())
+ return path;
+
+ StringBuffer buf = new StringBuffer();
+ token_loop:
+ while (true) {
+ String tok = st.nextToken();
+ buf.append(new File(tok).getAbsolutePath());
+ if (! st.hasMoreTokens())
+ break token_loop;
+ buf.append(ps);
+ }
+
+ return buf.toString();
+ }
+
+ public static void main(String args[]) throws Exception {
+ AgentManager.startAgentServer();
+ }
+
+}
diff --git a/joram/joram/client/jms/src/test/java/org/ow2/joram/testutils/AssertionFailedError.java b/joram/joram/client/jms/src/test/java/org/ow2/joram/testutils/AssertionFailedError.java
new file mode 100644
index 0000000000000000000000000000000000000000..cad0ed15a20bdeb34c6fbde98dafbff687fa3fc5
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/org/ow2/joram/testutils/AssertionFailedError.java
@@ -0,0 +1,36 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2001 - 2007 ScalAgent Distributed Technologies
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s): (ScalAgent D.T.)
+ * Contributor(s):
+ */
+package org.ow2.joram.testutils;
+
+/**
+ * Thrown when an assertion failed.
+ */
+public class AssertionFailedError extends Error {
+ public AssertionFailedError() {
+ super();
+ }
+
+ public AssertionFailedError(String message) {
+ super(message);
+ }
+}
diff --git a/joram/joram/client/jms/src/test/java/org/ow2/joram/testutils/BaseTestCase.java b/joram/joram/client/jms/src/test/java/org/ow2/joram/testutils/BaseTestCase.java
new file mode 100644
index 0000000000000000000000000000000000000000..977fae76420a436a311b288ddb699500ec69e297
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/org/ow2/joram/testutils/BaseTestCase.java
@@ -0,0 +1,1039 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2006 - 2012 ScalAgent Distributed Technologies
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s): ScalAgent Distributed Technologies
+ * Contributor(s):
+ */
+
+package org.ow2.joram.testutils;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.io.RandomAccessFile;
+import java.io.StringWriter;
+import java.lang.management.ManagementFactory;
+import java.lang.management.OperatingSystemMXBean;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Properties;
+import java.util.StringTokenizer;
+import java.util.Vector;
+import java.util.zip.GZIPInputStream;
+
+import org.objectweb.joram.client.jms.ConnectionMetaData;
+import org.objectweb.util.monolog.api.BasicLevel;
+import org.objectweb.util.monolog.api.Logger;
+
+import fr.dyade.aaa.common.Debug;
+
+/**
+ * Utility functions for all test cases.
+ */
+public class BaseTestCase {
+ protected static final Logger logmon = Debug.getLogger(BaseTestCase.class.getName());
+
+ private static BaseTestCase current = null;
+
+ protected String name;
+ protected boolean summary = true;
+ protected List failures;
+ protected List errors;
+ protected List exceptions;
+ protected PrintWriter writer = null;
+ protected boolean saveErrors = true;
+
+ public BaseTestCase() {
+ String id = System.getProperty("framework.TestCase.TestId");
+ summary = new Boolean(System.getProperty("framework.TestCase.Summary", "true")).booleanValue();
+ String outfile = System.getProperty("framework.TestCase.OutFile");
+ saveErrors = new Boolean(System.getProperty("framework.TestCase.SaveFailedTests", "true")).booleanValue();
+
+ try {
+ writer = new PrintWriter(new FileWriter(outfile, true));
+ } catch (IOException exc) {
+ throw new Error("Can't create test: " + getClass().getName());
+ }
+
+ if (id == null)
+ this.name = getClass().getName();
+ else
+ this.name = getClass().getName() + '-' + id;
+ setCurrent(this);
+
+ // Changes the class path with absolute paths
+ try {
+ Properties sysprops = System.getProperties();
+ String classpath = sysprops.getProperty("java.class.path");
+ classpath = getAbsolutePath(classpath);
+ sysprops.setProperty("java.class.path", classpath);
+ } catch (Exception exc) {
+ throw new Error("cannot set absolute classpath");
+ }
+ }
+
+ public final synchronized void addException(Throwable t) {
+ if (exceptions == null) exceptions = new Vector();
+ exceptions.add(t);
+ }
+
+ /**
+ * Adds a failure to the list of failures. The passed in exception
+ * caused the failure.
+ * The test framework distinguishes between failures and
+ * errors. A failure is anticipated and checked for with
+ * assertions. Errors are unanticipated problems like an
+ * ArrayIndexOutOfBoundsException
.
+ */
+ public final synchronized void addFailure(Throwable t) {
+ if (failures == null) failures = new Vector();
+ failures.add(t);
+ }
+
+ /**
+ * Gets the number of detected failures.
+ */
+ public final synchronized int failureCount() {
+ if (failures == null) return 0;
+ return failures.size();
+ }
+
+ /**
+ * Adds an error to the list of errors. The passed in exception
+ * caused the error.
+ * The test framework distinguishes between failures and
+ * errors. A failure is anticipated and checked for with
+ * assertions. Errors are unanticipated problems like an
+ * ArrayIndexOutOfBoundsException
.
+ */
+ public final synchronized void addError(Throwable t) {
+ if (errors == null) errors = new Vector();
+ errors.add(t);
+ }
+
+ /**
+ * Gets the number of detected errors.
+ */
+ public final synchronized int errorCount() {
+ if (errors == null) return 0;
+ return errors.size();
+ }
+
+ static int asserts = 0;
+
+ /**
+ * Asserts that a condition is true.
+ */
+ static public void assertTrue(String message, boolean condition) {
+ asserts++;
+ if (!condition) fail(message);
+ }
+
+ /**
+ * Asserts that a condition is true.
+ */
+ static public void assertTrue(boolean condition) {
+ assertTrue(null, condition);
+ }
+
+ /**
+ * Asserts that a condition is false.
+ */
+ static public void assertFalse(String message, boolean condition) {
+ asserts++;
+ if (condition) fail(message);
+ }
+
+ /**
+ * Asserts that a condition is false.
+ */
+ static public void assertFalse(boolean condition) {
+ assertFalse(null, condition);
+ }
+
+ /**
+ * Asserts that two objects are equal.
+ */
+ static public void assertEquals(String message,
+ Object expected, Object actual) {
+ asserts++;
+ if (expected == null && actual == null)
+ return;
+ if (expected != null && expected.equals(actual))
+ return;
+ failNotEquals(message, expected, actual);
+ }
+
+ /**
+ * Asserts that two objects are equal.
+ */
+ static public void assertEquals(Object expected, Object actual) {
+ assertEquals(null, expected, actual);
+ }
+
+ /**
+ * Asserts that two doubles are equal concerning a delta. If the expected
+ * value is infinity then the delta value is ignored.
+ */
+ static public void assertEquals(String message,
+ double expected, double actual,
+ double delta) {
+ asserts++;
+ if (Double.isInfinite(expected)) {
+ if (!(expected == actual))
+ failNotEquals(message, new Double(expected), new Double(actual));
+ } else if (!(Math.abs(expected-actual) <= delta))
+ // Because comparison with NaN always returns false
+ failNotEquals(message, new Double(expected), new Double(actual));
+ }
+
+ /**
+ * Asserts that two doubles are equal concerning a delta. If the expected
+ * value is infinity then the delta value is ignored.
+ */
+ static public void assertEquals(double expected, double actual,
+ double delta) {
+ assertEquals(null, expected, actual, delta);
+ }
+
+ /**
+ * Asserts that two floats are equal concerning a delta. If the expected
+ * value is infinity then the delta value is ignored.
+ */
+ static public void assertEquals(String message,
+ float expected, float actual,
+ float delta) {
+ asserts++;
+ if (Float.isInfinite(expected)) {
+ if (!(expected == actual))
+ failNotEquals(message, new Float(expected), new Float(actual));
+ } else if (!(Math.abs(expected-actual) <= delta))
+ failNotEquals(message, new Float(expected), new Float(actual));
+ }
+
+ /**
+ * Asserts that two floats are equal concerning a delta. If the expected
+ * value is infinity then the delta value is ignored.
+ */
+ static public void assertEquals(float expected, float actual,
+ float delta) {
+ assertEquals(null, expected, actual, delta);
+ }
+
+ /**
+ * Asserts that two longs are equal.
+ */
+ static public void assertEquals(String message,
+ long expected, long actual) {
+ assertEquals(message, new Long(expected), new Long(actual));
+ }
+
+ /**
+ * Asserts that two longs are equal.
+ */
+ static public void assertEquals(long expected, long actual) {
+ assertEquals(null, expected, actual);
+ }
+
+ /**
+ * Asserts that two booleans are equal.
+ */
+ static public void assertEquals(String message,
+ boolean expected, boolean actual) {
+ assertEquals(message, new Boolean(expected), new Boolean(actual));
+ }
+
+ /**
+ * Asserts that two booleans are equal.
+ */
+ static public void assertEquals(boolean expected, boolean actual) {
+ assertEquals(null, expected, actual);
+ }
+
+ /**
+ * Asserts that two bytes are equal.
+ */
+ static public void assertEquals(String message,
+ byte expected, byte actual) {
+ assertEquals(message, new Byte(expected), new Byte(actual));
+ }
+
+ /**
+ * Asserts that two bytes are equal.
+ */
+ static public void assertEquals(byte expected, byte actual) {
+ assertEquals(null, expected, actual);
+ }
+
+ /**
+ * Asserts that two chars are equal.
+ */
+ static public void assertEquals(String message,
+ char expected, char actual) {
+ assertEquals(message, new Character(expected), new Character(actual));
+ }
+
+ /**
+ * Asserts that two chars are equal.
+ */
+ static public void assertEquals(char expected, char actual) {
+ assertEquals(null, expected, actual);
+ }
+
+ /**
+ * Asserts that two shorts are equal.
+ */
+ static public void assertEquals(String message,
+ short expected, short actual) {
+ assertEquals(message, new Short(expected), new Short(actual));
+ }
+
+ /**
+ * Asserts that two shorts are equal.
+ */
+ static public void assertEquals(short expected, short actual) {
+ assertEquals(null, expected, actual);
+ }
+
+ /**
+ * Asserts that two ints are equal.
+ */
+ static public void assertEquals(String message,
+ int expected, int actual) {
+ assertEquals(message, new Integer(expected), new Integer(actual));
+ }
+
+ /**
+ * Asserts that two ints are equal.
+ */
+ static public void assertEquals(int expected, int actual) {
+ assertEquals(null, expected, actual);
+ }
+
+ /**
+ * Asserts that two byte[] are equal.
+ */
+ static public void assertEquals(byte[] tab1, byte[] tab2, int size) {
+ asserts++;
+ boolean ok=true;
+ for(int j=0; j< size && ok==true;j++)
+ if(tab1[j]!=tab2[j]){
+ failNotEquals(null, tab1[j], tab2[j]);
+ ok=false;
+ }
+ }
+
+ /**
+ * Asserts that an object isn't null.
+ */
+ static public void assertNotNull(String message, Object object) {
+ assertTrue(message, object != null);
+ }
+
+ /**
+ * Asserts that an object isn't null.
+ */
+ static public void assertNotNull(Object object) {
+ assertNotNull(null, object);
+ }
+
+ /**
+ * Asserts that an object is null.
+ */
+ static public void assertNull(String message, Object object) {
+ assertTrue(message, object == null);
+ }
+
+ /**
+ * Asserts that an object is null.
+ */
+ static public void assertNull(Object object) {
+ assertNull(null, object);
+ }
+
+ /**
+ * Asserts that two objects refer to the same object.
+ */
+ static public void assertSame(String message,
+ Object expected, Object actual) {
+ asserts++;
+ if (expected == actual)
+ return;
+ failNotSame(message, expected, actual);
+ }
+
+ static boolean isGzip(File file) {
+ asserts++;
+ String name = file.getName();
+ int idx = name.lastIndexOf('.');
+ if (idx == -1) return false;
+ return (name.substring(idx).equals(".gz"));
+ }
+
+ /**
+ * Checks that two files are identical, ignoring address mismatch.
+ *
+ * @param file1 first file
+ * @param file2 second file
+ * @return true
if files are identical
+ */
+ public static boolean check(File file1, File file2) {
+ InputStream f1 = null;
+ InputStream f2 = null;
+
+ try {
+ if (isGzip(file1))
+ f1 = new BufferedInputStream(
+ new GZIPInputStream(
+ new FileInputStream(file1)));
+ else
+ f1 = new BufferedInputStream(new FileInputStream(file1));
+ if (isGzip(file2))
+ f2 = new BufferedInputStream(
+ new GZIPInputStream(
+ new FileInputStream(file2)));
+ else
+ f2 = new BufferedInputStream(new FileInputStream(file2));
+
+ while (true) {
+ int c = f1.read();
+ int c2 = f2.read();
+ if (c2 != c) {
+ // checks for a \r\n \n equivalence
+ if ((c == '\r') && (c2 == '\n')) {
+ c = f1.read();
+ if (c == c2)
+ continue;
+ } else if ((c2 == '\r') && (c == '\n')) {
+ c2 = f2.read();
+ if (c == c2)
+ continue;
+ }
+ return false;
+ }
+ if (c == -1) break;
+ }
+ return true;
+ } catch (IOException exc) {
+ return false;
+ } finally {
+ try {
+ f1.close();
+ } catch (Exception e2) {}
+ try {
+ f2.close();
+ } catch (Exception e2) {}
+ }
+ }
+
+ /**
+ * Asserts that two files are same content.
+ */
+ static public void assertFileSameContent(String expected, String actual) {
+ assertFileSameContent(null,expected,actual);
+ }
+ /**
+ * Asserts that two files are same content.
+ */
+ static public void assertFileSameContent(String message, String expected, String actual) {
+ asserts++;
+ boolean ok = true;
+ File file1 =null;
+ File file2 =null;
+
+ String formatted = "";
+ if (message != null) formatted = message + ", ";
+ try {
+ file1 = new File(expected);
+ if (! file1.canRead()) throw new IOException();
+ expected = file1.getCanonicalPath();
+ } catch (IOException exc) {
+ fail(formatted + "cannot access file <" + expected + ">");
+ ok = false;
+ }
+ try {
+ file2 = new File(actual);
+ if (! file2.canRead()) throw new IOException();
+ actual = file2.getCanonicalPath();
+ } catch (IOException exc) {
+ fail(formatted + "cannot access file <" + actual + ">");
+ ok = false;
+ }
+ if ((! ok) || isSameContent(file1, file2)) return;
+
+ fail(formatted +
+ "files <" + expected + "> and <" + actual + "> differs");
+ }
+
+ public static boolean isSameContent(File file1, File file2) {
+ asserts++;
+ BufferedReader f1 = null;
+ RandomAccessFile f2 = null;
+ long l2= 0;
+ Long pfile;
+ Hashtable h = new Hashtable();
+ try {
+ if ( file1.length()!= file2.length())
+ return false;
+
+ f1 = new BufferedReader(new FileReader(file1));
+ f2 = new RandomAccessFile(file2,"r");
+ while (true) {
+ String line1 = f1.readLine();
+ l2 = 0;
+ if (line1 == null) {
+ break;
+ }
+ while (true) {
+ f2.seek(l2);
+ if (h.containsKey(new Long(l2))) {
+ l2 = ((Long) h.get(new Long(l2))).longValue();
+ continue;
+ }
+ String line2 = f2.readLine();
+ pfile = new Long(f2.getFilePointer());
+ if (line2 == null)
+ return false;
+ if (line1.equals(line2)) {
+ h.put(new Long(l2), pfile);
+ break;
+ }
+ l2 = pfile.longValue();
+ continue;
+ }
+ }
+ return true;
+ } catch (IOException exc) {
+ return false;
+ } finally {
+ try {
+ f1.close();
+ } catch (Exception e2) {}
+ try {
+ f2.close();
+ } catch (Exception e2) {}
+ }
+ }
+
+ /**
+ * Asserts that two files are identical.
+ */
+ static public void assertFileIdentical(String expected, String actual) {
+ assertFileIdentical(null, expected, actual);
+ }
+
+ /**
+ * Asserts that two files are identical.
+ */
+ static public void assertFileIdentical(String message,
+ String expected, String actual) {
+ asserts++;
+ boolean ok = true;
+ File file1 =null;
+ File file2 =null;
+
+ String formatted = "";
+ if (message != null) formatted = message + ", ";
+ try {
+ file1 = new File(expected);
+ if (! file1.canRead()) throw new IOException();
+ expected = file1.getCanonicalPath();
+ } catch (IOException exc) {
+ fail(formatted + "cannot access file <" + expected + ">");
+ ok = false;
+ }
+ try {
+ file2 = new File(actual);
+ if (! file2.canRead()) throw new IOException();
+ actual = file2.getCanonicalPath();
+ } catch (IOException exc) {
+ fail(formatted + "cannot access file <" + actual + ">");
+ ok = false;
+ }
+ if ((! ok) || check(file1, file2)) return;
+
+ fail(formatted +
+ "files <" + expected + "> and <" + actual + "> differs");
+ }
+
+ /**
+ * Asserts that a file exists.
+ */
+ static public void assertFileExist(String expected) {
+ assertFileExist(null, expected);
+ }
+
+ /**
+ * Asserts that a file exists.
+ */
+ static public void assertFileExist(String message, String expected) {
+ asserts++;
+ File file =null;
+
+ String formatted = "";
+ if (message != null) formatted = message + ", ";
+ try {
+ file = new File(expected);
+ if (! file.exists()) throw new IOException();
+ expected = file.getCanonicalPath();
+ } catch (IOException exc) {
+ fail(formatted + "cannot access file <" + expected + ">");
+ }
+ }
+
+ /**
+ * Asserts that two objects refer to the same object.
+ */
+ static public void assertSame(Object expected, Object actual) {
+ assertSame(null, expected, actual);
+ }
+
+ static public void exception(Throwable t) {
+ current.addException(t);
+ }
+
+ /**
+ * Fails a test with the given message.
+ */
+ static public void fail(String message) {
+ if (message == null) message = "";
+ current.addFailure(new AssertionFailedError(message));
+ }
+
+ static public void error(Throwable t) {
+ current.addError(t);
+ }
+
+ static private void failNotEquals(String message,
+ Object expected, Object actual) {
+ String formatted = "";
+ if (message != null)
+ formatted = message + ", ";
+ fail(formatted + "expected:<" + expected + "> but was:<" + actual + ">");
+ }
+
+ static private void failNotSame(String message,
+ Object expected, Object actual) {
+ String formatted = "";
+ if (message != null)
+ formatted = message + ", ";
+ fail(formatted + "expected same");
+ }
+
+ /**
+ * Change the elements of a path as absolute names.
+ * Use the property path.separator as separator.
+ *
+ * @param path path to transform
+ *
+ * @return transformed path
+ */
+ public static String getAbsolutePath(String path) throws Exception {
+ String ps = System.getProperty("path.separator");
+ StringTokenizer st = new StringTokenizer(path, ps);
+ if (! st.hasMoreTokens())
+ return path;
+
+ StringBuffer buf = new StringBuffer();
+ token_loop:
+ while (true) {
+ String tok = st.nextToken();
+ buf.append(new File(tok).getAbsolutePath());
+ if (! st.hasMoreTokens())
+ break token_loop;
+ buf.append(ps);
+ }
+
+ return buf.toString();
+ }
+
+ protected long timeout = 0L;
+ protected long startDate = System.currentTimeMillis();
+ protected long endDate = 0L;
+
+ /**
+ * Runs a TestCase.
+ */
+ public void runTest(String args[]) {
+ Thread t = null;
+ try {
+ setUpEnv(args);
+ setUp();
+ // Creates a thread to execute the test in order to
+ // control the test duration.
+ t = new Thread() {
+ public void run() {
+ try {
+ startTest();
+ } catch (Exception exc) {
+ addError(exc);
+ endTest();
+ }
+ }
+ };
+ t.setDaemon(true);
+ t.start();
+ if (timeout != 0L) {
+ Thread.sleep(timeout);
+ throw new Exception("timeout expired");
+ }
+ } catch (Throwable exc) {
+ // TODO:
+ addError(exc);
+ endTest();
+ }
+ }
+
+ /**
+ * Sets up the generic environment for a class of tests.
+ */
+ protected void setUpEnv(String args[]) throws Exception {}
+
+ /**
+ * Sets up the test specific environment.
+ */
+ protected void setUp() throws Exception {
+ }
+
+ /**
+ * Actually starts the test.
+ * Should call setStartDate to define the actual beginning of the test,
+ * and ensure that endTest is eventually called.
+ */
+ protected void startTest() throws Exception {}
+
+ /**
+ * Informs the framework that a test begins.
+ */
+ public static final void setStartDate() {
+ current.startDate = System.currentTimeMillis();
+ }
+
+ /**
+ * Informs the framework that a test was completed.
+ */
+ public static final void endTest() {
+ endTest(null, true);
+ }
+
+ public static final void endTest(String msg, boolean exit) {
+ current.endDate = System.currentTimeMillis();
+ int status = 0;
+
+ killAllProcess();
+
+ current.endEnv();
+ current.tearDown();
+
+ // computer information
+ writeSysInfo();
+
+ StringBuffer writerBuf = new StringBuffer();
+
+ // write Joram version
+ if (current.summary)
+ System.err.println(ConnectionMetaData.providerName + " " + ConnectionMetaData.providerVersion);
+ writerBuf.append("| " + ConnectionMetaData.providerName + " " + ConnectionMetaData.providerVersion);
+ writerBuf.append("\n");
+
+ // TODO:
+ if ((current.failures != null) || (current.errors != null)) {
+ if (current.summary)
+ System.err.println("TEST \"" + current.name + "\" FAILED" +
+ ", asserts: " + asserts +
+ ", failures: " + current.failureCount() +
+ ", errors: " + current.errorCount() + ", [" +
+ (current.endDate - current.startDate) + "].");
+ writerBuf.append("TEST \"" + current.name + "\" FAILED" +
+ ", asserts: " + asserts +
+ ", failures: " + current.failureCount() +
+ ", errors: " + current.errorCount() + ", [" +
+ (current.endDate - current.startDate) + "].");
+ writerBuf.append("\n");
+ } else {
+ if (current.summary)
+ System.err.println("TEST \"" + current.name + "\" OK [" + asserts + ", " +
+ (current.endDate - current.startDate) + "].");
+ writerBuf.append("TEST \"" + current.name + "\" OK [" + asserts + ", " +
+ (current.endDate - current.startDate) + "].");
+ writerBuf.append("\n");
+ }
+ if (msg != null) {
+ if (current.summary) System.err.println(msg);
+ writerBuf.append(msg);
+ writerBuf.append("\n");
+ }
+
+ if (current.failures != null) {
+ status += current.failures.size();
+ for (int i=0; i 0) {
+ out.write(buf, 0, len);
+ }
+ in.close();
+ out.close();
+ } catch (IOException exc) {
+ throw new IOException(srcPath.toString() + ": " + exc.getMessage());
+ }
+ }
+ }
+
+ public static void writeSysInfo() {
+ InetAddress addr = null;
+ String hostname = null;
+ try {
+ addr = InetAddress.getLocalHost();
+ hostname = addr.getHostName();
+ } catch (UnknownHostException e) { }
+
+ OperatingSystemMXBean bean = ManagementFactory.getOperatingSystemMXBean();
+ if (current.summary) {
+ if (hostname != null)
+ System.err.println("hostname: " + hostname);
+ if (bean != null)
+ System.err.println(
+ "System: " + bean.getArch() +
+ ", OS: " + bean.getName() +
+ ", Nb processor(s): " + bean.getAvailableProcessors());
+ }
+ if (current.writer != null) {
+ current.writer.println("----------------------------------------------------");
+ if (hostname != null)
+ current.writer.println("| hostname: " + hostname);
+ if (bean != null)
+ current.writer.println(
+ "| System: " + bean.getArch() +
+ ", OS: " + bean.getName() +
+ ", Nb processor(s): " + bean.getAvailableProcessors());
+ current.writer.println("| Date: " + new Date(System.currentTimeMillis()));
+ }
+ }
+
+ public void writeIntoFile(String str){
+ if (current.writer != null) {
+ current.writer.println(str);
+ current.writer.flush();
+ }
+ }
+
+ /**
+ * Finalizes the generic environment for a class of tests.
+ */
+ protected void endEnv() {}
+
+ /**
+ * Destroys everything and make sure all parts of the test
+ * are stopped.
+ */
+ protected void tearDown() {
+ }
+
+ public static synchronized BaseTestCase getCurrent() {
+ return current;
+ }
+
+ public static synchronized void setCurrent(BaseTestCase current) {
+ BaseTestCase.current = current;
+ }
+
+ public static void main(String args[]) throws Exception {
+ assertFileIdentical(args[0], args[1]);
+ endTest();
+ }
+
+ static Vector launchedProcess = new Vector();
+
+ public static void killAllProcess() {
+ logmon.log(BasicLevel.DEBUG, "SCAdmin: killAllProcess");
+
+ int exit = -1;
+ for (int i=launchedProcess.size(); i>0; i--) {
+ Process p = launchedProcess.remove(i-1);
+ if (p != null) {
+ try {
+ exit = p.exitValue();
+ logmon.log(BasicLevel.DEBUG, "SCAdmin: killAllProcess exited " + exit);
+ } catch (IllegalThreadStateException exc) {
+ logmon.log(BasicLevel.DEBUG, "SCAdmin: killAllProcess killed");
+ p.destroy();
+ }
+ }
+ }
+ }
+
+ public static Process startProcess(String classname, String[] jvmargs, String[] args) throws IOException {
+ return startProcess(classname, null, jvmargs, args);
+ }
+
+
+ public static Process startProcess(String classname,
+ String cp, String[] jvmargs, String[] args) throws IOException {
+ return startProcess(classname, cp, jvmargs, args, null);
+ }
+
+ public static Process startProcess(String classname, String cp, String[] jvmargs, String[] args, File dir) throws IOException {
+ logmon.log(BasicLevel.DEBUG, "SCAdmin: launch " + classname);
+
+ List argv = new ArrayList();
+
+ String javapath = new File(new File(System.getProperty("java.home"), "bin"), "java").getPath();
+ argv.add(javapath);
+
+ argv.add("-classpath");
+ if (cp != null)
+ argv.add(cp);
+ else
+ argv.add(System.getProperty("java.class.path"));
+
+ if (jvmargs != null) {
+ for (int i = 0; i < jvmargs.length; i++)
+ argv.add(jvmargs[i]);
+ }
+ // Add JMX monitoring options
+ argv.add("-Dcom.sun.management.jmxremote");
+
+ // Main class
+ argv.add(classname);
+
+ if (args != null) {
+ for (int i = 0; i < args.length; i++)
+ argv.add(args[i]);
+ }
+
+ Process p = null;
+ try {
+ p = Runtime.getRuntime().exec((String[]) argv.toArray(new String[argv.size()]), null, dir);
+ } catch (Exception exc) {
+ logmon.log(BasicLevel.DEBUG, "SCAdmin: exception " + exc);
+ exception(exc);
+ // The process is still alive, kill it!
+ p.destroy();
+ return null;
+ }
+
+ p.getInputStream().close();
+ p.getOutputStream().close();
+ p.getErrorStream().close();
+
+ launchedProcess.add(p);
+ return p;
+ }
+}
diff --git a/joram/joram/client/jms/src/test/java/org/ow2/joram/testutils/CheckReportFile.java b/joram/joram/client/jms/src/test/java/org/ow2/joram/testutils/CheckReportFile.java
new file mode 100644
index 0000000000000000000000000000000000000000..04a84d1bd0c52e122f579511dabf3c404af47d41
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/org/ow2/joram/testutils/CheckReportFile.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2009 ScalAgent Distributed Technologies
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s): ScalAgent Distributed Technologies
+ * Contributor(s):
+ */
+package org.ow2.joram.testutils;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+
+/**
+ * This class checks the report file to find 'FAILED' occurrences and exits in
+ * an error status if found. This is useful to show errors when running tests on
+ * bamboo.
+ */
+public class CheckReportFile {
+
+ public static void main(String[] args) throws Exception {
+ FileReader fr = new FileReader(System.getProperty("framework.TestCase.OutFile"));
+ BufferedReader br = new BufferedReader(fr);
+ String line = br.readLine();
+ int failedCount = 0;
+
+ while (line != null) {
+ if (line.indexOf("FAILED") != -1) {
+ failedCount++;
+ System.out.println(line);
+ }
+ line = br.readLine();
+ }
+
+ System.out.println();
+ System.out.println("Failed tests: " + failedCount);
+ if (failedCount > 0) {
+ System.exit(-1);
+ } else {
+ System.exit(0);
+ }
+ }
+
+}
diff --git a/joram/joram/client/jms/src/test/java/org/ow2/joram/testutils/SCAdminClassic.java b/joram/joram/client/jms/src/test/java/org/ow2/joram/testutils/SCAdminClassic.java
new file mode 100644
index 0000000000000000000000000000000000000000..84afada5c7e44b79f10543267f4820047339f632
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/org/ow2/joram/testutils/SCAdminClassic.java
@@ -0,0 +1,136 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2009 - 2012 ScalAgent Distributed Technologies
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s): ScalAgent Distributed Technologies
+ * Contributor(s):
+ */
+package org.ow2.joram.testutils;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.objectweb.util.monolog.api.BasicLevel;
+
+import fr.dyade.aaa.agent.AgentServer;
+import fr.dyade.aaa.agent.conf.A3CML;
+import fr.dyade.aaa.agent.conf.A3CMLConfig;
+import fr.dyade.aaa.agent.conf.UnknownServiceException;
+
+public class SCAdminClassic extends SCBaseAdmin {
+ private static byte [] halt = "halt\n".getBytes();
+
+ protected byte[] getHaltCommand() {
+ return halt;
+ }
+
+ public void startAgentServer(short sid, String[] jvmargs) throws Exception {
+ logmon.log(BasicLevel.DEBUG, "SCAdmin: run AgentServer#" + sid);
+
+ Server server = (Server) launchedServers.get(new Short(sid));
+
+ if (server != null) {
+ try {
+ int exitValue = server.process.exitValue();
+ if (logmon.isLoggable(BasicLevel.DEBUG)) {
+ logmon.log(BasicLevel.DEBUG, "SCAdmin: AgentServer#" + sid + " -> " + exitValue);
+ }
+ } catch (IllegalThreadStateException exc) {
+ if (logmon.isLoggable(BasicLevel.WARN)) {
+ logmon.log(BasicLevel.WARN, "SCAdmin: AgentServer#" + sid + " already running.");
+ }
+ throw new IllegalStateException("AgentServer#" + sid + " already running.");
+ }
+ }
+
+ // Get the configuration
+ A3CMLConfig a3config;
+ try {
+ String configPath = null;
+ if (jvmargs != null) {
+ for (int i = 0; i < jvmargs.length; i++) {
+ String jvmArg = jvmargs[i];
+ if (jvmArg.startsWith("-D" + AgentServer.CFG_FILE_PROPERTY)) {
+ configPath = jvmArg.substring(2 + AgentServer.CFG_FILE_PROPERTY.length() + 1);
+ break;
+ }
+ }
+ }
+ if (configPath == null) {
+ a3config = A3CML.getXMLConfig();
+ } else {
+ a3config = A3CML.getXMLConfig(configPath);
+ }
+ } catch (Exception exc) {
+ logmon.log(BasicLevel.ERROR, "SCAdmin: problem during configuration parsing", exc);
+ throw new Exception("Problem during configuration parsing");
+ }
+
+// String javapath = new File(new File(System.getProperty("java.home"), "bin"), "java").getPath();
+// String classpath = System.getProperty("java.class.path");
+
+// List argv = new ArrayList();
+// argv.add(javapath);
+//
+// argv.add("-classpath");
+// argv.add(classpath);
+// if (jvmargs != null) {
+// for (int i = 0; i < jvmargs.length; i++)
+// argv.add(jvmargs[i]);
+// }
+//
+// // Add JMX monitoring options
+// argv.add("-Dcom.sun.management.jmxremote");
+
+ // Retrieve port from a3 configuration file (a3servers.xml)
+ int port = -1;
+ try {
+ port = Integer.parseInt(a3config.getServiceArgs(sid, "fr.dyade.aaa.agent.AdminProxy"));
+ } catch (UnknownServiceException exc) {
+ if (logmon.isLoggable(BasicLevel.WARN)) {
+ logmon.log(BasicLevel.WARN, "SCAdmin: AdminProxy service not found, server will not be stoppable "
+ + "using SCAdmin. Only the killAgentServer() method can be used. ");
+ }
+ }
+ if (logmon.isLoggable(BasicLevel.DEBUG)) {
+ logmon.log(BasicLevel.DEBUG, "SCAdmin: AgentServer#" + sid + " telnet port: " + port);
+ }
+
+// // Main class
+// argv.add();
+// argv.add(Short.toString(sid));
+// argv.add("s" + sid);
+
+ if (logmon.isLoggable(BasicLevel.DEBUG)) {
+ logmon.log(BasicLevel.DEBUG, "SCAdmin" + ": launches AgentServer#" + sid);
+ }
+
+// Process p = Runtime.getRuntime().exec((String[]) argv.toArray(new String[argv.size()]));
+//
+// p.getInputStream().close();
+// p.getOutputStream().close();
+// p.getErrorStream().close();
+
+ Process p = BaseTestCase.startProcess("fr.dyade.aaa.agent.AgentServer",
+ jvmargs,
+ new String[] {Short.toString(sid), "s" + sid});
+
+ launchedServers.put(new Short(sid), new Server(port, p));
+ }
+}
\ No newline at end of file
diff --git a/joram/joram/client/jms/src/test/java/org/ow2/joram/testutils/SCAdminItf.java b/joram/joram/client/jms/src/test/java/org/ow2/joram/testutils/SCAdminItf.java
new file mode 100644
index 0000000000000000000000000000000000000000..1853c6706c80ea92e0c1c31629141b812dc1b95a
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/org/ow2/joram/testutils/SCAdminItf.java
@@ -0,0 +1,75 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2009 - 2013 ScalAgent Distributed Technologies
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s): ScalAgent Distributed Technologies
+ * Contributor(s):
+ */
+package org.ow2.joram.testutils;
+
+
+/**
+ * Administration interface used to manage the start and the stop of non collocated
+ * AgentServers.
+ */
+public interface SCAdminItf {
+
+ /**
+ * Starts a new AgentServer.
+ *
+ * @param sid
+ * id of the server to start
+ */
+ public void startAgentServer(short sid) throws Exception;
+
+ /**
+ * Starts a new AgentServer.
+ *
+ * @param sid
+ * id of the server to start
+ * @param jvmargs
+ * additional arguments given when launching the server
+ */
+ public void startAgentServer(short sid, String[] jvmargs) throws Exception;
+
+ /**
+ * Kills a given AgentServer. The server must have been started with this
+ * Admin interface.
+ *
+ * @param sid
+ * id of the server to kill
+ */
+ public void killAgentServer(short sid);
+
+ /**
+ * Cleanly stops an AgentServer. The server must have been started with this
+ * Admin interface.
+ *
+ * @param sid
+ * id of the server to stop
+ */
+ public void stopAgentServer(short sid) throws Exception;
+
+ /**
+ * Cleanly stops an AgentServer accessible on the given telnet port.
+ *
+ * @param telnetPort
+ * the port on which the server is reachable.
+ */
+ public void stopAgentServerExt(int telnetPort) throws Exception;
+}
diff --git a/joram/joram/client/jms/src/test/java/org/ow2/joram/testutils/SCAdminOSGi.java b/joram/joram/client/jms/src/test/java/org/ow2/joram/testutils/SCAdminOSGi.java
new file mode 100644
index 0000000000000000000000000000000000000000..f95c9fff28efe8a93963368212dca6bad170a03b
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/org/ow2/joram/testutils/SCAdminOSGi.java
@@ -0,0 +1,105 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2009 - 2012 ScalAgent Distributed Technologies
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s): ScalAgent Distributed Technologies
+ * Contributor(s):
+ */
+package org.ow2.joram.testutils;
+
+import java.io.File;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.objectweb.util.monolog.api.BasicLevel;
+
+import fr.dyade.aaa.agent.osgi.Activator;
+
+public class SCAdminOSGi extends SCBaseAdmin {
+ // use stop 0 to shutdown ! (available in felix and gogo)
+ private static byte [] halt = "stop 0\n".getBytes();
+
+ protected byte[] getHaltCommand() {
+ return halt;
+ }
+
+ public void startAgentServer(short sid, String[] jvmargs) throws Exception {
+ logmon.log(BasicLevel.DEBUG, "SCAdmin: run AgentServer#" + sid);
+
+ Server server = (Server) launchedServers.get(new Short(sid));
+
+ if (server != null) {
+ try {
+ int exitValue = server.process.exitValue();
+ if (logmon.isLoggable(BasicLevel.DEBUG)) {
+ logmon.log(BasicLevel.DEBUG, "SCAdmin: AgentServer#" + sid + " -> " + exitValue);
+ }
+ } catch (IllegalThreadStateException exc) {
+ if (logmon.isLoggable(BasicLevel.WARN)) {
+ logmon.log(BasicLevel.WARN, "SCAdmin: AgentServer#" + sid + " already running.");
+ }
+ throw new IllegalStateException("AgentServer#" + sid + " already running.");
+ }
+ }
+
+ // Find felix jar and put it on the classpath
+ File felixbin = new File(System.getProperty("felix.dir") + "/felix.jar");
+ if (!felixbin.exists()) {
+ throw new Exception("Felix framework not found.");
+ }
+
+ List argv = new ArrayList();
+ if (jvmargs != null) {
+ for (int i = 0; i < jvmargs.length; i++)
+ argv.add(jvmargs[i]);
+ }
+
+ // Choose a random telnet port if unspecified
+ int port = Integer.getInteger("osgi.shell.telnet.port", getFreePort());
+ if (logmon.isLoggable(BasicLevel.DEBUG)) {
+ logmon.log(BasicLevel.DEBUG, "SCAdmin: AgentServer#" + sid + " telnet port: " + port);
+ }
+ System.out.println("SCAdmin: AgentServer#" + sid + " telnet port: " + port);
+
+ // Get felix configuration file.
+ URI configFile = new URI(System.getProperty("felix.config.properties", "file:config.properties"));
+ argv.add("-Dfelix.config.properties=" + configFile);
+
+ // Assign AgentServer properties for server id, storage directory and cluster id.
+ argv.add("-Dorg.osgi.framework.storage=" + 's' + sid + "/felix-cache");
+ argv.add("-Dosgi.shell.telnet.port=" + port);
+ argv.add("-D" + Activator.AGENT_SERVER_ID_PROPERTY + '=' + sid);
+ argv.add("-D" + Activator.AGENT_SERVER_STORAGE_PROPERTY + "=s" + sid);
+ argv.add("-XX:+UnlockDiagnosticVMOptions");
+ argv.add("-XX:+UnsyncloadClass");
+ argv.add("-Dgosh.args=--nointeractive"); // need with gogo
+
+ if (logmon.isLoggable(BasicLevel.DEBUG)) {
+ logmon.log(BasicLevel.DEBUG, "SCAdmin" + ": launches AgentServer#" + sid + " with: " + argv);
+ }
+ System.out.println("SCAdmin" + ": launches AgentServer#" + sid + " with: " + argv);
+
+ Process p = BaseTestCase.startProcess("org.apache.felix.main.Main",
+ "." + File.pathSeparatorChar + felixbin.getAbsolutePath(),
+ (String[]) argv.toArray(new String[argv.size()]),
+ null);
+
+ launchedServers.put(new Short(sid), new Server(port, p));
+ }
+}
\ No newline at end of file
diff --git a/joram/joram/client/jms/src/test/java/org/ow2/joram/testutils/SCBaseAdmin.java b/joram/joram/client/jms/src/test/java/org/ow2/joram/testutils/SCBaseAdmin.java
new file mode 100644
index 0000000000000000000000000000000000000000..2094b11e99b333d3e684fe31539dbdbdba285fe5
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/org/ow2/joram/testutils/SCBaseAdmin.java
@@ -0,0 +1,243 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2012 ScalAgent Distributed Technologies
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s): ScalAgent Distributed Technologies
+ * Contributor(s):
+ */
+package org.ow2.joram.testutils;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+import java.util.Vector;
+
+import org.objectweb.util.monolog.api.BasicLevel;
+import org.objectweb.util.monolog.api.Logger;
+
+import fr.dyade.aaa.agent.UnknownServerException;
+import fr.dyade.aaa.common.Daemon;
+import fr.dyade.aaa.common.Debug;
+
+public abstract class SCBaseAdmin implements SCAdminItf {
+
+ protected abstract byte[] getHaltCommand();
+
+ protected static final Logger logmon = Debug.getLogger(SCBaseAdmin.class.getName());
+
+ /** Map containing all Process
of running AgentServers */
+ protected Map launchedServers = new HashMap();
+
+ public void killAgentServer(short sid) {
+ Server server = (Server) launchedServers.get(new Short(sid));
+ logmon.log(BasicLevel.DEBUG, "SCAdminClassic: kill AgentServer#" + sid);
+ if (server != null) {
+ server.process.destroy();
+ try {
+ server.process.waitFor();
+ } catch (InterruptedException exc) {
+ if (logmon.isLoggable(BasicLevel.ERROR)) {
+ logmon.log(BasicLevel.ERROR, "SCAdminClassic: AgentServer#" + sid
+ + " error waiting for process kill.", exc);
+ }
+ }
+ } else {
+ logmon.log(BasicLevel.WARN, "Server process to kill not found: " + sid);
+ }
+ }
+
+ public void startAgentServer(short sid) throws Exception {
+ startAgentServer(sid, null);
+ }
+
+ public void stopAgentServer(short sid) throws Exception {
+ Socket socket = null;
+ Server server = (Server) launchedServers.get(new Short(sid));
+ TelnetReaderDaemon daemon = null;
+
+ if (server != null) {
+ if (logmon.isLoggable(BasicLevel.DEBUG)) {
+ logmon.log(BasicLevel.DEBUG, "SCAdminClassic: stop AgentServer#" + sid);
+ }
+ try {
+ socket = new Socket("localhost", server.telnetPort);
+ daemon = new TelnetReaderDaemon(socket.getInputStream(), logmon);
+ daemon.start();
+
+ socket.getOutputStream().write(getHaltCommand());
+ socket.getOutputStream().flush();
+ } catch (Throwable exc) {
+ if (logmon.isLoggable(BasicLevel.ERROR))
+ logmon.log(BasicLevel.ERROR, "SCAdminClassic: Can't stop server#" + sid + ", kill it.", exc);
+ killAgentServer(sid);
+ throw new Exception("SCAdminClassic: Can't stop server#" + sid, exc);
+ }
+
+ if (logmon.isLoggable(BasicLevel.DEBUG)) {
+ logmon.log(BasicLevel.DEBUG, "SCAdminClassic: join AgentServer#" + sid + " [" + server.process + ']');
+ }
+ server.process.waitFor();
+ daemon.stop();
+ } else {
+ throw new UnknownServerException("Server " + sid + " unknown: not started using SCAdmin.");
+ }
+ }
+
+ public void stopAgentServerExt(int telnetPort) throws Exception {
+ Socket socket = null;
+ TelnetReaderDaemon daemon = null;
+
+ if (logmon.isLoggable(BasicLevel.DEBUG)) {
+ logmon.log(BasicLevel.DEBUG, "SCAdminClassic: stop on port " + telnetPort);
+ }
+ try {
+ socket = new Socket("localhost", telnetPort);
+ daemon = new TelnetReaderDaemon(socket.getInputStream(), logmon);
+ daemon.start();
+
+ socket.getOutputStream().write(getHaltCommand());
+ socket.getOutputStream().flush();
+ } catch (Throwable exc) {
+ if (logmon.isLoggable(BasicLevel.DEBUG))
+ logmon.log(BasicLevel.DEBUG, "SCAdminClassic: Can't stop server on port " + telnetPort, exc);
+ if (daemon != null) {
+ daemon.stop();
+ }
+ throw new Exception("Can't stop server on port " + telnetPort + ": " + exc.getMessage());
+ }
+
+ if (logmon.isLoggable(BasicLevel.DEBUG)) {
+ logmon.log(BasicLevel.DEBUG, "SCAdminClassic: wait closing telnet connection on " + telnetPort);
+ }
+ while (daemon.isRunning()) {
+ Thread.sleep(500);
+ }
+ daemon.close();
+ }
+
+ protected static class TelnetReaderDaemon extends Daemon {
+
+ private InputStreamReader reader;
+
+ protected TelnetReaderDaemon(InputStream stream, Logger logger) {
+ super("TelnetReaderDaemon", logger);
+ this.reader = new InputStreamReader(stream);
+ }
+
+ protected void close() {
+ }
+
+ protected void shutdown() {
+ try {
+ reader.close();
+ } catch (IOException exc) {
+ }
+ }
+
+ public void run() {
+ int character;
+ StringBuffer sb = new StringBuffer();
+ try {
+ while (running) {
+ canStop = true;
+ try {
+ character = reader.read();
+ } catch (IOException exc) {
+ logmon.log(BasicLevel.ERROR, "Error in telnet daemon.", exc);
+ return;
+ }
+ canStop = false;
+ if (character == -1) break;
+
+ if (character == '\n') {
+ if (logmon.isLoggable(BasicLevel.DEBUG)) {
+ logmon.log(BasicLevel.DEBUG, "TelnetReaderDaemon read: " + sb);
+ }
+ sb.setLength(0);
+ } else {
+ sb.append((char) character);
+ }
+ }
+ } finally {
+ finish();
+ }
+ }
+ }
+
+ protected static class Server {
+ public int telnetPort;
+
+ public Process process;
+
+ public Server(int telnetPort, Process process) {
+ super();
+ this.telnetPort = telnetPort;
+ this.process = process;
+ }
+ }
+ /* *********************************************************** */
+
+ protected static final int MIN_PORT_NUMBER = 1025;
+ protected static final int MAX_PORT_NUMBER = 32760;
+ protected static final int PORT_CHECK_RANGE = 1000;
+ protected static final int PORT_CHECK_START = 20000;
+
+ public static int getFreePort() {
+ Random random = new Random();
+ int port = random.nextInt(PORT_CHECK_RANGE) + PORT_CHECK_START;
+ while (!available(port)) {
+ port = random.nextInt(PORT_CHECK_RANGE) + PORT_CHECK_START;
+ }
+ return port;
+ }
+
+ /**
+ * Checks to see if a specific port is available.
+ *
+ * @param port
+ * the port to check for availability
+ */
+ public static boolean available(int port) {
+ if (port < MIN_PORT_NUMBER || port > MAX_PORT_NUMBER) {
+ throw new IllegalArgumentException("Invalid start port: " + port);
+ }
+ ServerSocket ss = null;
+ try {
+ ss = new ServerSocket(port);
+ return true;
+ } catch (IOException e) {
+ } finally {
+ if (ss != null) {
+ try {
+ ss.close();
+ } catch (IOException e) {
+ /* should not be thrown */
+ }
+ }
+ }
+ return false;
+ }
+}
diff --git a/joram/joram/client/jms/src/test/java/org/ow2/joram/testutils/TestCase.java b/joram/joram/client/jms/src/test/java/org/ow2/joram/testutils/TestCase.java
new file mode 100644
index 0000000000000000000000000000000000000000..76952a7190eda77cb9945b810c0c5ae691ea5ba3
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/org/ow2/joram/testutils/TestCase.java
@@ -0,0 +1,142 @@
+/*
+ * JORAM: Java(TM) Open Reliable Asynchronous Messaging
+ * Copyright (C) 2001 - 2013 ScalAgent Distributed Technologies
+ *
+ * This library 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 any later version.
+ *
+ * This library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA.
+ *
+ * Initial developer(s): ScalAgent Distributed Technologies
+ * Contributor(s):
+ */
+
+package org.ow2.joram.testutils;
+
+import java.io.File;
+import java.util.logging.Logger;
+
+import fr.dyade.aaa.agent.AgentServer;
+
+/**
+ * Framework for tests using A3 agent servers.
+ */
+public abstract class TestCase extends junit.framework.TestCase {
+ protected long timeout = 0L;
+ protected static final Logger logmon = Logger.getLogger(TestCase.class.getName());
+
+ static SCAdminItf admin = null;
+
+ protected boolean running = false;
+
+ public TestCase() {
+ super();
+ }
+
+ /**
+ * Sets up the generic environment for a class of tests.
+ * Starts the agent server.
+ */
+ public void setUp(String args[]) throws Exception {
+ AgentServer.init(args);
+ AgentServer.start();
+ running = true;
+ }
+
+ /**
+ * Finalizes the generic environment for a class of tests.
+ * Stops the agent server.
+ */
+ public void tearDown() {
+ if (running) {
+ // Stop the AgentServer
+ AgentServer.stop(false);
+ running = false;
+ }
+ }
+
+ public static void startAgentServer(short sid) throws Exception {
+ try {
+ getAdmin().startAgentServer(sid);
+ } catch (IllegalStateException exc) {
+ // The process is still alive, kill it!
+ getAdmin().killAgentServer(sid);
+ getAdmin().startAgentServer(sid);
+ throw(exc);
+ }
+ }
+
+ public static void startAgentServer(short sid, String[] jvmargs) throws Exception {
+ try {
+ getAdmin().startAgentServer(sid, jvmargs);
+ } catch (IllegalStateException exc) {
+ // The process is still alive, kill it!
+ getAdmin().killAgentServer(sid);
+ getAdmin().startAgentServer(sid, jvmargs);
+ if (getAdmin() instanceof SCAdminClassic)
+ throw(exc);
+ }
+ }
+
+ public static void stopAgentServer(short sid) {
+ try {
+ getAdmin().stopAgentServer(sid);
+ } catch (Exception exc) {
+ //ignore
+ }
+ }
+
+ public static void stopAgentServerExt(int telnetPort) {
+ try {
+ getAdmin().stopAgentServerExt(telnetPort);
+ } catch (Exception exc) {
+ //ignore
+ }
+ }
+ public static void killAgentServerExt(short sid) {
+ try {
+ getAdmin().killAgentServer(sid);
+ } catch (Exception exc) {
+ //ignore
+ }
+ }
+
+ public static void killAgentServer(short sid) {
+ try {
+ getAdmin().killAgentServer(sid);
+ } catch (Exception exc) {
+ //ignore
+ }
+ }
+
+ public static SCAdminItf getAdmin() throws Exception {
+ if (admin == null) {
+ String scAdminClass = System.getProperty("SCAdminClass", SCAdminOSGi.class.getName());
+ admin = (SCAdminItf) Class.forName(scAdminClass).newInstance();
+ }
+ return admin;
+ }
+
+ public static void deleteDirectory(File dir) {
+ String[] files = dir.list();
+ for (int i = 0; i < files.length; i++) {
+ File f = new File(dir, files[i]);
+ if (f.isDirectory()) {
+ deleteDirectory(f);
+ } else {
+ f.delete();
+ }
+ }
+ dir.delete();
+ }
+}
diff --git a/joram/joram/client/jms/src/test/java/zzstop/ZZZTest.java b/joram/joram/client/jms/src/test/java/zzstop/ZZZTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..045d73a6d1163a7aad74a4fc4381c5ea53a0e710
--- /dev/null
+++ b/joram/joram/client/jms/src/test/java/zzstop/ZZZTest.java
@@ -0,0 +1,38 @@
+package zzstop;
+
+import java.io.File;
+
+import org.junit.jupiter.api.Test;
+import org.ow2.joram.testutils.AgentManager;
+
+import junit.framework.TestCase;
+
+public class ZZZTest extends TestCase {
+
+ @Test
+ public void testStopAgent() {
+ System.setProperty("felix.dir", "../../../ship/bin");
+ try {
+ AgentManager.stopAgentServer();
+
+ // cleanup !
+ deleteDirectory(new File("s0"));
+ for (File f : (new File(".")).listFiles()) {
+ if (f.getName().startsWith("server.log.")) {
+ f.delete();
+ }
+ }
+ } catch(Exception e) {
+ }
+ }
+
+ private boolean deleteDirectory(File dir) {
+ File[] files = dir.listFiles();
+ if (files != null) {
+ for (File file : files) {
+ deleteDirectory(file);
+ }
+ }
+ return dir.delete();
+ }
+}
diff --git a/joram/pom.xml b/joram/pom.xml
index a7563653c922a918c8c59404869718cf4ae9838c..22db6f2894ef2de3e61b34750fab35f0236b0553 100644
--- a/joram/pom.xml
+++ b/joram/pom.xml
@@ -193,14 +193,17 @@
org.apache.maven.plugins
maven-surefire-plugin
2.22.2
-
+
+ alphabetical
+
+