| Home >> All >> org >> activemq >> [ message Javadoc ] |
Source code: org/activemq/message/ActiveMQTextMessageTest.java
1 /* 2 * Created on Mar 4, 2004 3 * 4 * To change the template for this generated file go to 5 * Window - Preferences - Java - Code Generation - Code and Comments 6 */ 7 package org.activemq.message; 8 9 import junit.framework.TestCase; 10 import junit.textui.TestRunner; 11 12 import javax.jms.JMSException; 13 import org.activemq.io.WireFormat; 14 import org.activemq.io.impl.DefaultWireFormat; 15 import java.io.IOException; 16 17 /** 18 * To change the template for this generated type comment go to 19 * Window - Preferences - Java - Code Generation - Code and Comments 20 */ 21 public class ActiveMQTextMessageTest extends TestCase { 22 23 private WireFormat wireFormat = new DefaultWireFormat(); 24 25 public static void main(String[] args) { 26 TestRunner.run(ActiveMQTextMessageTest.class); 27 } 28 29 public void testGetPacketType() { 30 ActiveMQTextMessage msg = new ActiveMQTextMessage(); 31 assertTrue(msg.getPacketType() == Packet.ACTIVEMQ_TEXT_MESSAGE); 32 } 33 34 public void testSetText() { 35 ActiveMQTextMessage msg = new ActiveMQTextMessage(); 36 String str = "testText"; 37 try { 38 msg.setText(str); 39 assertTrue(msg.getText() == str); 40 } 41 catch (JMSException e) { 42 e.printStackTrace(); 43 } 44 boolean readOnlyTest = false; 45 msg.setReadOnly(true); 46 try { 47 msg.setText(str); 48 } 49 catch (JMSException e) { 50 readOnlyTest = true; 51 } 52 assertTrue(readOnlyTest); 53 } 54 55 56 public void testReadAndWriteMessage() throws JMSException, IOException { 57 ActiveMQTextMessage message = new ActiveMQTextMessage(); 58 message.setJMSMessageID("abc:123"); 59 message.setExternalMessageId(true); 60 message.setText("Testing 1, 2, 3"); 61 62 byte[] data = wireFormat.toBytes(message); 63 Packet packet = wireFormat.fromBytes(data); 64 65 assertTrue(packet instanceof ActiveMQTextMessage); 66 ActiveMQTextMessage message2 = (ActiveMQTextMessage) packet; 67 assertEquals("Message IDs", message.getJMSMessageID(), message2.getJMSMessageID()); 68 assertEquals("Message Text", message.getText(), message2.getText()); 69 } 70 }