KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jtests > jms > conform > message > properties > MessagePropertyTest


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.properties;
26
27 import org.objectweb.jtests.jms.framework.*;
28 import javax.jms.*;
29 import junit.framework.*;
30 import java.util.Vector JavaDoc;
31 import java.util.Enumeration JavaDoc;
32
33 /**
34  * Test the <code>javax.jms.Message</code> properties.
35  * <br />
36  * See JMS Specification, 3.5 Message Properties (p.32-37)
37  *
38  * @author Jeff Mesnil (jmesnil@inrialpes.fr)
39  * @version $Id: MessagePropertyTest.java,v 1.1.18.1 2005/05/18 00:16:04 adrian Exp $
40  */

41 public class MessagePropertyTest extends PTPTestCase {
42   
43   /**
44    * Test that any other class than <code>Boolean, Byte, Short, Integer, Long,
45    * Float, Double</code> and <code>String</code> used in the <code>Message.setObjectProperty()</code>
46    * method throws a <code>javax.jms.MessageFormatException</code>.
47    */

48   public void testSetObjectProperty_2() {
49     try {
50       Message message = senderSession.createMessage();
51       message.setObjectProperty("prop", new Vector JavaDoc());
52       fail("3.5.5 An attempt to use any other class [than Boolean, Byte,...,String] must throw " +
53        "a JMS MessageFormatException.\n");
54     } catch (MessageFormatException e) {
55     } catch (JMSException e) {
56       fail("Should throw a javax.jms.MessageFormatException, not a "+ e);
57     }
58   }
59
60   /**
61    * if a property is set as a <code>Float</code> with the <code>Message.setObjectProperty()</code>
62    * method, it can be retrieve directly as a <code>double</code> by <code>Message.getFloatProperty()</code>
63    */

64   public void testSetObjectProperty_1() {
65     try {
66       Message message = senderSession.createMessage();
67       message.setObjectProperty("pi", new Float JavaDoc(3.14159f));
68       assertEquals(3.14159f, message.getFloatProperty("pi"),0);
69     } catch (JMSException e) {
70       fail(e);
71     }
72   }
73
74   /**
75    * Test that a <code>null</code> value is returned by the <code>Message.getObjectProperty()</code> method
76    * if a property by the specified name does not exits.
77    */

78   public void testGetObjectProperty() {
79     try {
80       Message message = senderSession.createMessage();
81       assertEquals("3.5.5 A null value is returned [by the getObjectProperty method] if a property by the specified " +
82            "name does not exits.\n",
83            null,message.getObjectProperty("prop"));
84     } catch (JMSException e) {
85       fail(e);
86     }
87   }
88
89   /**
90    * Test that a <code>null</code> value is returned by the <code>Message.getStringProperty()</code> method
91    * if a property by the specified name does not exits.
92    */

93   public void testGetStringProperty() {
94    try {
95      Message message = senderSession.createMessage();
96      assertEquals("3.5.5 A null value is returned [by the getStringProperty method] if a property by the specified " +
97           "name does not exits.\n",
98           null,message.getStringProperty("prop"));
99    } catch (JMSException e) {
100      fail(e);
101    }
102   }
103
104   /**
105    * Test that an attempt to get a <code>double</code> property which does not exist throw
106    * a <code>java.lang.NullPointerException</code>
107    */

108   public void testGetDoubleProperty() {
109     try {
110       Message message = senderSession.createMessage();
111       message.getDoubleProperty("prop");
112       fail("Should raise a NullPointerException.\n");
113     } catch (NullPointerException JavaDoc e) {
114     } catch (JMSException e) {
115       fail(e);
116     }
117   }
118   
119   /**
120    * Test that an attempt to get a <code>float</code> property which does not exist throw
121    * a <code>java.lang.NullPointerException</code>
122    */

123   public void testGetFloatProperty() {
124    try {
125      Message message = senderSession.createMessage();
126      message.getFloatProperty("prop");
127      fail("Should raise a NullPointerException.\n");
128    } catch (NullPointerException JavaDoc e) {
129    } catch (JMSException e) {
130      fail(e);
131    }
132   }
133
134   /**
135    * Test that an attempt to get a <code>long</code> property which does not exist throw
136    * a <code>java.lang.NumberFormatException</code>
137    */

138   public void testGetLongProperty() {
139    try {
140      Message message = senderSession.createMessage();
141      message.getLongProperty("prop");
142      fail("Should raise a NumberFormatException.\n");
143    } catch (NumberFormatException JavaDoc e) {
144    } catch (JMSException e) {
145      fail(e);
146    }
147   }
148
149   /**
150    * Test that an attempt to get a <code>int</code> property which does not exist throw
151    * a <code>java.lang.NumberFormatException</code>
152    */

153   public void testGetIntProperty() {
154    try {
155      Message message = senderSession.createMessage();
156      message.getIntProperty("prop");
157      fail("Should raise a NumberFormatException.\n");
158    } catch (NumberFormatException JavaDoc e) {
159    } catch (JMSException e) {
160      fail(e);
161    }
162   }
163
164   /**
165    * Test that an attempt to get a <code>short</code> property which does not exist throw
166    * a <code>java.lang.NumberFormatException</code>
167    */

168   public void testGetShortProperty() {
169    try {
170      Message message = senderSession.createMessage();
171      message.getShortProperty("prop");
172      fail("Should raise a NumberFormatException.\n");
173    } catch (NumberFormatException JavaDoc e) {
174    } catch (JMSException e) {
175      fail(e);
176    }
177   }
178
179   /**
180    * Test that an attempt to get a <code>byte</code> property which does not exist throw
181    * a <code>java.lang.NumberFormatException</code>
182    */

183   public void testGetByteProperty() {
184    try {
185      Message message = senderSession.createMessage();
186      message.getByteProperty("prop");
187      fail("Should raise a NumberFormatException.\n");
188    } catch (NumberFormatException JavaDoc e) {
189    } catch (JMSException e) {
190      fail(e);
191    }
192   }
193   
194   /**
195    * Test that an attempt to get a <code>boolean</code> property which does not exist
196    * returns <code>false</code>
197    */

198   public void testGetBooleanProperty() {
199    try {
200      Message message = senderSession.createMessage();
201      assertEquals(false, message.getBooleanProperty("prop"));
202    } catch (JMSException e) {
203      fail(e);
204    }
205   }
206
207   /**
208    * Test that the <code>Message.getPropertyNames()</code> method does not return
209    * the name of the JMS standard header fields (e.g. <code>JMSCorrelationID</code>.
210    */

211   public void testGetPropertyNames() {
212     try {
213       Message message = senderSession.createMessage();
214       message.setJMSCorrelationID("foo");
215       Enumeration JavaDoc i = message.getPropertyNames();
216       assertTrue("3.5.6 The getPropertyNames method does not return the names of " +
217          "the JMS standard header field [e.g. JMSCorrelationID].\n",
218          !i.hasMoreElements());
219     } catch (JMSException e) {
220       fail(e);
221     }
222   }
223
224   /**
225    * Test that the <code>Message.getPropertyNames()</code> method returns an empty
226    * <code>java.util.Enumeration</code> if there is no properties.
227    * <br />
228    * If there are some, test that it properly return their names.
229    */

230   public void testPropertyIteration() {
231     try {
232       Message message = senderSession.createMessage();
233       Enumeration JavaDoc i = message.getPropertyNames();
234       assertTrue("No property yet defined.\n",
235          !i.hasMoreElements());
236       message.setDoubleProperty("pi", 3.14159);
237       i = message.getPropertyNames();
238       assertEquals("One property defined of name 'pi'.\n",
239            "pi", (String JavaDoc)i.nextElement());
240     } catch (JMSException e) {
241       fail(e);
242     }
243   }
244
245   /**
246    * Test that the <code>Message.clearProperties()</code> method does not clear the
247    * value of the Message's body.
248    */

249   public void testClearProperties_2() {
250     try {
251       TextMessage message = senderSession.createTextMessage();
252       message.setText("foo");
253       message.clearProperties();
254       assertEquals("3.5.7 Clearing a message's property entries does not clear the value of its body.\n",
255            "foo", message.getText());
256     } catch (JMSException e) {
257       fail(e);
258     }
259   }
260
261   /**
262    * Test that the <code>Message.clearProperties()</code> method deletes all the
263    * properties of the Message.
264    */

265   public void testClearProperties_1() {
266     try {
267       TextMessage message = senderSession.createTextMessage();
268       message.setStringProperty("prop", "foo");
269       message.clearProperties();
270       assertEquals("3.5.7 A message's properties are deleted by the clearProperties method.\n",
271            null, message.getStringProperty("prop"));
272     } catch (JMSException e) {
273       fail(e);
274     }
275   }
276     
277   /**
278    * Method to use this class in a Test suite
279    */

280   public static Test suite() {
281     return new TestSuite(MessagePropertyTest.class);
282   }
283   
284   public MessagePropertyTest(String JavaDoc name) {
285     super(name);
286   }
287 }
288
289
Popular Tags