Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/objectweb/jtests/jms/conform/message/MessageBodyTest.java


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 javax.jms.*;
29  import junit.framework.*;
30  
31  /**
32   * Tests on message body.
33   *
34   * @author Jeff Mesnil (jmesnil@inrialpes.fr)
35   * @version $Id: MessageBodyTest.java,v 1.1 2002/04/21 21:15:18 chirino Exp $
36   */
37  public class MessageBodyTest extends PTPTestCase {
38    
39    /**
40     * Test that the <code>TextMessage.clearBody()</code> method does nto clear the 
41     * message properties.
42     */
43    public void testClearBody_2() {
44      try {
45        TextMessage message = senderSession.createTextMessage();
46        message.setStringProperty("prop", "foo");
47        message.clearBody();
48        assertEquals("§3.11.1 Clearing a message's body does not clear its property entries.\n",
49         "foo", message.getStringProperty("prop"));
50      } catch (JMSException e) {
51        fail(e);
52      }
53    }
54  
55    /**
56     * Test that the <code>TextMessage.clearBody()</code> effectively clear the body of the message
57     */
58    public void testClearBody_1() {
59      try {
60        TextMessage message = senderSession.createTextMessage();
61        message.setText("bar");
62        message.clearBody();
63        assertEquals("§3 .11.1 the clearBody method of Message resets the value of the message body " +
64         "to the 'empty' initial message value as set by the message type's create " +
65         "method provided by Session.\n",
66         null, message.getText());
67      } catch (JMSException e) {
68        fail(e);
69      }
70    }
71  
72    /**
73     * Test that a call to the <code>TextMessage.setText()</code> method on a 
74     * received message raises a <code>javax.jms.MessageNotWriteableException</code>.
75     */
76    public void testWriteOnReceivedBody() {
77      try {
78        TextMessage message = senderSession.createTextMessage();
79        message.setText("foo");
80        sender.send(message);
81        
82        Message m = receiver.receive();
83        assertTrue("The message should be an instance of TextMessage.\n",
84       m instanceof TextMessage);
85        TextMessage msg = (TextMessage)m;
86        msg.setText("bar");
87        fail("should raise a MessageNotWriteableException (§3.11.2)");
88      } catch (MessageNotWriteableException e) {
89      } catch (JMSException e) {
90        fail(e);
91      }
92    }
93      
94    /** 
95     * Method to use this class in a Test suite
96     */
97    public static Test suite() {
98       return new TestSuite(MessageBodyTest.class);
99     }
100   
101   public MessageBodyTest(String name) {
102     super(name);
103   }
104 }