KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > command > ActiveMQObjectMessageTest


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.command;
19
20 import junit.framework.TestCase;
21
22 import javax.jms.JMSException JavaDoc;
23 import javax.jms.MessageNotReadableException JavaDoc;
24 import javax.jms.MessageNotWriteableException JavaDoc;
25
26 import org.apache.activemq.command.ActiveMQObjectMessage;
27
28 import java.io.IOException JavaDoc;
29
30 /**
31  * @version $Revision$
32  */

33 public class ActiveMQObjectMessageTest extends TestCase {
34
35     public static void main(String JavaDoc[] args) {
36         junit.textui.TestRunner.run(ActiveMQObjectMessageTest.class);
37     }
38
39     /*
40      * @see TestCase#setUp()
41      */

42     protected void setUp() throws Exception JavaDoc {
43         super.setUp();
44     }
45
46     /*
47      * @see TestCase#tearDown()
48      */

49     protected void tearDown() throws Exception JavaDoc {
50         super.tearDown();
51     }
52
53     /**
54      * Constructor for ActiveMQObjectMessageTest.
55      *
56      * @param arg0
57      */

58     public ActiveMQObjectMessageTest(String JavaDoc arg0) {
59         super(arg0);
60     }
61
62     public void testBytes() throws JMSException JavaDoc, IOException JavaDoc {
63         ActiveMQObjectMessage msg = new ActiveMQObjectMessage();
64         String JavaDoc 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 JavaDoc {
73         ActiveMQObjectMessage msg = new ActiveMQObjectMessage();
74         String JavaDoc str = "testText";
75         msg.setObject(str);
76         assertTrue(msg.getObject() == str);
77     }
78
79     public void testClearBody() throws JMSException JavaDoc {
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 JavaDoc mnwe) {
89             fail("should be writeable");
90         }
91     }
92
93     public void testReadOnlyBody() throws JMSException JavaDoc {
94         ActiveMQObjectMessage msg = new ActiveMQObjectMessage();
95         msg.setObject("test");
96         msg.setReadOnlyBody(true);
97         try {
98             msg.getObject();
99         } catch (MessageNotReadableException JavaDoc e) {
100             fail("should be readable");
101         }
102         try {
103             msg.setObject("test");
104             fail("should throw exception");
105         } catch (MessageNotWriteableException JavaDoc e) {
106         }
107     }
108
109     public void testWriteOnlyBody() throws JMSException JavaDoc { // should always be readable
110
ActiveMQObjectMessage msg = new ActiveMQObjectMessage();
111         msg.setReadOnlyBody(false);
112         try {
113             msg.setObject("test");
114             msg.getObject();
115         } catch (MessageNotReadableException JavaDoc 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 JavaDoc e) {
124             fail("should be readable");
125         } catch (MessageNotWriteableException JavaDoc mnwe) {
126         }
127     }
128
129 }
130
Popular Tags