package org.objectweb.jtests.jms.conform.message.headers;
import org.objectweb.jtests.jms.framework.PTPTestCase;
import javax.jms.*;
import junit.framework.*;
import javax.naming.* ;
public class MessageHeaderTest extends PTPTestCase {
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();
} catch (JMSException e) {
fail(e);
}
}
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();
} catch (JMSException e) {
fail(e);
}
}
public void testJMSExpiration() {
try {
Message message= senderSession.createMessage();
sender.send(message);
Message msg = receiver.receive();
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);
}
}
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();
assertTrue("§3.4.3 All JMSMessageID values must start with the prefix 'ID:'.\n",
msg.getJMSMessageID().startsWith("ID:"));
} catch (JMSException e) {
fail(e);
}
}
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();
} catch (JMSException e) {
fail(e);
}
}
public void testJMSDeliveryMode() {
try {
assertEquals(DeliveryMode.PERSISTENT, sender.getDeliveryMode());
Message message = senderSession.createMessage();
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();
} catch (JMSException e) {
fail(e);
}
}
public void testJMSDestination() {
try {
admin.createQueue("anotherQueue");
Context ctx = admin.createInitialContext();
Queue anotherQueue = (Queue)ctx.lookup("anotherQueue");
assertTrue(anotherQueue != senderQueue);
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();
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 (JMSException e) {
fail(e);
} catch (NamingException e) {
fail(e.getMessage());
}
}
public void testJMSReplyTo_1() {
try {
Message message = senderSession.createMessage();
message.setJMSReplyTo(senderQueue);
sender.send(message);
Message msg = receiver.receive();
Destination dest = msg.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);
}
}
public void testJMSReplyTo_2() {
try {
TemporaryQueue tempQueue = senderSession.createTemporaryQueue();
Message message = senderSession.createMessage();
message.setJMSReplyTo(tempQueue);
sender.send(message);
Message msg = receiver.receive();
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);
}
}
public static Test suite() {
return new TestSuite(MessageHeaderTest.class);
}
public MessageHeaderTest(String name) {
super(name);
}
}