KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jtests > jms > conform > message > MessageBodyTest


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2002 INRIA
4  * Contact: joram-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * Initial developer(s): Jeff Mesnil (jmesnil@inrialpes.fr)
22  * Contributor(s): ______________________________________.
23  */

24
25 package org.objectweb.jtests.jms.conform.message;
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
32 /**
33  * Tests on message body.
34  *
35  * @author Jeff Mesnil (jmesnil@inrialpes.fr)
36  * @version $Id: MessageBodyTest.java,v 1.3 2002/04/23 08:36:13 jmesnil Exp $
37  */

38 public class MessageBodyTest extends PTPTestCase {
39   
40   /**
41    * Test that the <code>TextMessage.clearBody()</code> method does nto clear the
42    * message properties.
43    */

44   public void testClearBody_2() {
45     try {
46       TextMessage message = senderSession.createTextMessage();
47       message.setStringProperty("prop", "foo");
48       message.clearBody();
49       assertEquals("§3.11.1 Clearing a message's body does not clear its property entries.\n",
50            "foo", message.getStringProperty("prop"));
51     } catch (JMSException e) {
52       fail(e);
53     }
54   }
55
56   /**
57    * Test that the <code>TextMessage.clearBody()</code> effectively clear the body of the message
58    */

59   public void testClearBody_1() {
60     try {
61       TextMessage message = senderSession.createTextMessage();
62       message.setText("bar");
63       message.clearBody();
64       assertEquals("§3 .11.1 the clearBody method of Message resets the value of the message body " +
65            "to the 'empty' initial message value as set by the message type's create " +
66            "method provided by Session.\n",
67            null, message.getText());
68     } catch (JMSException e) {
69       fail(e);
70     }
71   }
72
73   /**
74    * Test that a call to the <code>TextMessage.setText()</code> method on a
75    * received message raises a <code>javax.jms.MessageNotWriteableException</code>.
76    */

77   public void testWriteOnReceivedBody() {
78     try {
79       TextMessage message = senderSession.createTextMessage();
80       message.setText("foo");
81       sender.send(message);
82       
83       Message m = receiver.receive(TestConfig.TIMEOUT);
84       assertTrue("The message should be an instance of TextMessage.\n",
85          m instanceof TextMessage);
86       TextMessage msg = (TextMessage)m;
87       msg.setText("bar");
88       fail("should raise a MessageNotWriteableException (§3.11.2)");
89     } catch (MessageNotWriteableException e) {
90     } catch (JMSException e) {
91       fail(e);
92     }
93   }
94     
95   /**
96    * Method to use this class in a Test suite
97    */

98   public static Test suite() {
99      return new TestSuite(MessageBodyTest.class);
100    }
101   
102   public MessageBodyTest(String JavaDoc name) {
103     super(name);
104   }
105 }
106
Popular Tags