1 24 25 package org.objectweb.jtests.jms.conform.message.headers; 26 27 import org.objectweb.jtests.jms.framework.PTPTestCase; 28 import org.objectweb.jtests.jms.framework.TestConfig; 29 import javax.jms.*; 30 import junit.framework.*; 31 import javax.naming.* ; 32 33 39 public class MessageHeaderTest extends PTPTestCase { 40 41 45 public void testJMSPriority_2() { 46 try { 47 Message message= senderSession.createMessage(); 48 sender.send(message); 49 sender.setPriority(9); 50 sender.send(message); 51 assertEquals("§3.4.9 After completion of the send it holds the value specified by the " + 52 "method sending the message.\n", 53 9, message.getJMSPriority()); 54 55 Message msg = receiver.receive(TestConfig.TIMEOUT); 56 } catch (JMSException e) { 57 fail(e); 58 } 59 } 60 61 66 public void testJMSPriority_1() { 67 try { 68 Message message= senderSession.createMessage(); 69 message.setJMSPriority(0); 70 sender.send(message); 71 assertTrue("§3.4.9 When a message is sent this value is ignored.\n", 72 message.getJMSPriority() != 0); 73 assertEquals("§3.4.9 After completion of the send it holds the value specified by the " + 74 "method sending the message.\n", 75 Message.DEFAULT_PRIORITY, message.getJMSPriority()); 76 77 Message msg = receiver.receive(TestConfig.TIMEOUT); 78 } catch (JMSException e) { 79 fail(e); 80 } 81 } 82 83 87 public void testJMSExpiration() { 88 try { 89 Message message= senderSession.createMessage(); 90 sender.send(message); 91 92 Message msg = receiver.receive(TestConfig.TIMEOUT); 93 assertEquals("§3.4.9 When a message is received its JMSExpiration header field contains this same " + 94 "value [i.e. set on return of the send method].\n", 95 message.getJMSExpiration(), msg.getJMSExpiration()); 96 } catch (JMSException e) { 97 fail(e); 98 } 99 } 100 101 105 public void testJMSMessageID_2() { 106 try { 107 Message message = senderSession.createMessage(); 108 sender.send(message); 109 assertTrue("§3.4.3 When the send method returns it contains a provider-assigned value.\n", 110 message.getJMSMessageID() != null); 111 assertTrue("§3.4.3 All JMSMessageID values must start with the prefix 'ID:'.\n", 112 message.getJMSMessageID().startsWith("ID:")); 113 114 Message msg = receiver.receive(TestConfig.TIMEOUT); 115 assertTrue("§3.4.3 All JMSMessageID values must start with the prefix 'ID:'.\n", 116 msg.getJMSMessageID().startsWith("ID:")); 117 } catch (JMSException e) { 118 fail(e); 119 } 120 } 121 122 126 public void testJMSMessageID_1() { 127 try { 128 Message message = senderSession.createMessage(); 129 message.setJMSMessageID("ID:foo"); 130 sender.send(message); 131 assertTrue("§3.4.3 When a message is sent this value is ignored.\n", 132 message.getJMSMessageID() != "ID:foo"); 133 Message msg = receiver.receive(TestConfig.TIMEOUT); 134 } catch (JMSException e) { 135 fail(e); 136 } 137 } 138 139 144 public void testJMSDeliveryMode() { 145 try { 146 assertEquals(DeliveryMode.PERSISTENT, sender.getDeliveryMode()); 148 Message message = senderSession.createMessage(); 149 message.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT); 151 sender.send(message); 152 assertTrue("§3.4.2 When a message is sent this value is ignored", 153 message.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT); 154 assertEquals("§3.4.2 After completion of the send it holds the delivery mode specified " + 155 "by the sending method (persistent by default).\n", 156 Message.DEFAULT_DELIVERY_MODE, message.getJMSDeliveryMode()); 157 158 Message msg = receiver.receive(TestConfig.TIMEOUT); 159 } catch (JMSException e) { 160 fail(e); 161 } 162 } 163 164 170 public void testJMSDestination() { 171 try { 172 admin.createQueue("anotherQueue"); 173 Context ctx = admin.createInitialContext(); 174 Queue anotherQueue = (Queue)ctx.lookup("anotherQueue"); 175 assertTrue(anotherQueue != senderQueue); 176 177 Message message = senderSession.createMessage(); 179 message.setJMSDestination(anotherQueue); 180 sender.send(message); 181 assertTrue("§3.4.1 When a message is sent this value is ignored.\n", 182 message.getJMSDestination() != anotherQueue); 183 assertEquals("§3.4.1 After completion of the send it holds the destination object specified " + 184 "by the sending method.\n", 185 senderQueue, message.getJMSDestination()); 186 187 Message msg = receiver.receive(TestConfig.TIMEOUT); 188 assertEquals("§3.4.1 When a message is received, its destination value must be equivalent " + 189 " to the value assigned when it was sent.\n", 190 ((Queue)message.getJMSDestination()).getQueueName(), 191 ((Queue)msg.getJMSDestination()).getQueueName()); 192 193 admin.deleteQueue("anotherQueue"); 194 } catch (JMSException e) { 195 fail(e); 196 } catch (NamingException e) { 197 fail(e.getMessage()); 198 } 199 } 200 201 206 public void testJMSReplyTo_1() { 207 try { 208 Message message = senderSession.createMessage(); 209 message.setJMSReplyTo(senderQueue); 210 sender.send(message); 211 212 Message msg = receiver.receive(TestConfig.TIMEOUT); 213 Destination dest = msg.getJMSReplyTo(); 214 assertTrue("JMS ReplyTo header field should be a Queue", 215 dest instanceof Queue); 216 Queue replyTo = (Queue) dest; 217 assertEquals("JMS ReplyTo header field should be equals to the sender queue", 218 ((Queue)replyTo).getQueueName(), ((Queue)senderQueue).getQueueName()); 219 } catch (JMSException e) { 220 fail(e); 221 } 222 } 223 224 229 public void testJMSReplyTo_2() { 230 try { 231 TemporaryQueue tempQueue = senderSession.createTemporaryQueue(); 232 Message message = senderSession.createMessage(); 233 message.setJMSReplyTo(tempQueue); 234 sender.send(message); 235 236 Message msg = receiver.receive(TestConfig.TIMEOUT); 237 Destination dest = msg.getJMSReplyTo(); 238 assertTrue("JMS ReplyTo header field should be a TemporaryQueue", 239 dest instanceof TemporaryQueue); 240 Queue replyTo = (Queue) dest; 241 assertEquals("JMS ReplyTo header field should be equals to the temporary queue", 242 ((Queue)replyTo).getQueueName(), ((Queue)tempQueue).getQueueName()); 243 } catch (JMSException e) { 244 fail(e); 245 } 246 } 247 248 251 public static Test suite() { 252 return new TestSuite(MessageHeaderTest.class); 253 } 254 255 public MessageHeaderTest(String name) { 256 super(name); 257 } 258 } 259 260 | Popular Tags |