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