1 18 package org.apache.activemq.command; 19 20 import junit.framework.TestCase; 21 22 import javax.jms.JMSException ; 23 import javax.jms.MessageNotReadableException ; 24 import javax.jms.MessageNotWriteableException ; 25 26 import org.apache.activemq.command.ActiveMQObjectMessage; 27 28 import java.io.IOException ; 29 30 33 public class ActiveMQObjectMessageTest extends TestCase { 34 35 public static void main(String [] args) { 36 junit.textui.TestRunner.run(ActiveMQObjectMessageTest.class); 37 } 38 39 42 protected void setUp() throws Exception { 43 super.setUp(); 44 } 45 46 49 protected void tearDown() throws Exception { 50 super.tearDown(); 51 } 52 53 58 public ActiveMQObjectMessageTest(String arg0) { 59 super(arg0); 60 } 61 62 public void testBytes() throws JMSException , IOException { 63 ActiveMQObjectMessage msg = new ActiveMQObjectMessage(); 64 String str = "testText"; 65 msg.setObject(str); 66 67 msg = (ActiveMQObjectMessage) msg.copy(); 68 assertEquals(msg.getObject(), str); 69 70 } 71 72 public void testSetObject() throws JMSException { 73 ActiveMQObjectMessage msg = new ActiveMQObjectMessage(); 74 String str = "testText"; 75 msg.setObject(str); 76 assertTrue(msg.getObject() == str); 77 } 78 79 public void testClearBody() throws JMSException { 80 ActiveMQObjectMessage objectMessage = new ActiveMQObjectMessage(); 81 try { 82 objectMessage.setObject("String"); 83 objectMessage.clearBody(); 84 assertFalse(objectMessage.isReadOnlyBody()); 85 assertNull(objectMessage.getObject()); 86 objectMessage.setObject("String"); 87 objectMessage.getObject(); 88 } catch (MessageNotWriteableException mnwe) { 89 fail("should be writeable"); 90 } 91 } 92 93 public void testReadOnlyBody() throws JMSException { 94 ActiveMQObjectMessage msg = new ActiveMQObjectMessage(); 95 msg.setObject("test"); 96 msg.setReadOnlyBody(true); 97 try { 98 msg.getObject(); 99 } catch (MessageNotReadableException e) { 100 fail("should be readable"); 101 } 102 try { 103 msg.setObject("test"); 104 fail("should throw exception"); 105 } catch (MessageNotWriteableException e) { 106 } 107 } 108 109 public void testWriteOnlyBody() throws JMSException { ActiveMQObjectMessage msg = new ActiveMQObjectMessage(); 111 msg.setReadOnlyBody(false); 112 try { 113 msg.setObject("test"); 114 msg.getObject(); 115 } catch (MessageNotReadableException e) { 116 fail("should be readable"); 117 } 118 msg.setReadOnlyBody(true); 119 try { 120 msg.getObject(); 121 msg.setObject("test"); 122 fail("should throw exception"); 123 } catch (MessageNotReadableException e) { 124 fail("should be readable"); 125 } catch (MessageNotWriteableException mnwe) { 126 } 127 } 128 129 } 130 | Popular Tags |