Source code: org/objectweb/jtests/jms/conform/message/properties/MessagePropertyConversionTest.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.properties;
26
27 import org.objectweb.jtests.jms.framework.*;
28 import javax.jms.*;
29 import junit.framework.*;
30
31 /**
32 * Test the conversion of primitive types for the <code>javax.jms.Message</code> properties.
33 * <br />
34 * See JMS Specification, §3.5.4 Property Value Conversion and the corresponding table (p.33-34).
35 * <br />
36 * The method name <code>testXXX2YYY</code> means that we test if a property
37 * which has been set as a <code>XXX</code> type can be read as a <code>YYY</code> type,
38 * where <code>XXX</code> and <code>YYY</code> can be <code>boolean, byte, short, long, float
39 * double</code> or <code>String</code>.
40 *
41 * <pre>
42 * ---------------------------------------------------------------|
43 * | boolean | byte | short | int | long | float | double | String|
44 * |-----------------------------------------------------------------------|
45 * |boolean | X X |
46 * |byte | X X X X X |
47 * |short | X X X X |
48 * |int | X X X |
49 * |long | X X |
50 * |float | X X X |
51 * |double | X X |
52 * |String | Y Y Y Y Y Y Y X |
53 * |-----------------------------------------------------------------------|
54 * </pre>
55 * A value set as the row type can be read as the column type.
56 * <br />
57 * The unmarked cases must throw a <code>javax.jms.MessageFormatException</code>
58 * <br />
59 * The cases marked with a Y should throw a <code>java.lang.MessageFormatException</code> <strong>if</strong> the
60 * String is not a correct representation of the column type (otherwise, it returns the property).
61 *
62 * @author Jeff Mesnil (jmesnil@inrialpes.fr)
63 * @version $Id: MessagePropertyConversionTest.java,v 1.1.4.1 2003/05/31 00:35:11 ejort Exp $
64 */
65 public class MessagePropertyConversionTest extends PTPTestCase {
66
67 /**
68 * if a property is set as a <code>java.lang.String</code>,
69 * it can also be read as a <code>java.lang.String</code>.
70 */
71 public void testString2String() {
72 try {
73 Message message = senderSession.createMessage();
74 message.setStringProperty("pi", "3.14159");
75 assertEquals("3.14159", message.getStringProperty("pi"));
76 } catch (JMSException e) {
77 fail(e);
78 }
79 }
80
81 /**
82 * if a property is set as a <code>java.lang.String</code>,
83 * to get it as a <code>double</code> throws a <code>java.lang.NuberFormatException</code>
84 * if the <code>String</code> is not a correct representation for a <code>double</code>
85 * (e.g. <code>"not a number"</code>).
86 */
87 public void testString2Double_2() {
88 try {
89 Message message = senderSession.createMessage();
90 message.setStringProperty("pi", "not_a_number");
91 message.getDoubleProperty("pi");
92 fail("§3.5.4 The String to numeric conversions must throw the java.lang.NumberFormatException " +
93 " if the numeric's valueOf() method does not accept the String value as a valid representation.\n");
94 } catch (java.lang.NumberFormatException e) {
95 } catch (JMSException e) {
96 fail(e);
97 }
98 }
99
100 /**
101 * if a property is set as a <code>java.lang.String</code>,
102 * it can also be read as a <code>double</code> as long as the <code>String</code>
103 * is a correct representation of a <code>double</code> (e.g. <code>"3.14159"</code>).
104 */
105 public void testString2Double_1() {
106 try {
107 Message message = senderSession.createMessage();
108 message.setStringProperty("pi", "3.14159");
109 assertEquals(3.14159, message.getDoubleProperty("pi"),0);
110 } catch (JMSException e) {
111 fail(e);
112 }
113 }
114
115 /**
116 * if a property is set as a <code>java.lang.String</code>,
117 * to get it as a <code>float</code> throws a <code>java.lang.NuberFormatException</code>
118 * if the <code>String</code> is not a correct representation for a <code>float</code>
119 * (e.g. <code>"not_a_number"</code>).
120 */
121 public void testString2Float_2() {
122 try {
123 Message message = senderSession.createMessage();
124 message.setStringProperty("pi", "not_a_number");
125 message.getFloatProperty("pi");
126 fail("§3.5.4 The String to numeric conversions must throw the java.lang.NumberFormatException " +
127 " if the numeric's valueOf() method does not accept the String value as a valid representation.\n");
128 } catch (java.lang.NumberFormatException e) {
129 } catch (JMSException e) {
130 fail(e);
131 }
132 }
133
134 /**
135 * if a property is set as a <code>java.lang.String</code>,
136 * it can also be read as a <code>float</code> as long as the <code>String</code>
137 * is a correct representation of a <code>float</code> (e.g. <code>"3.14159"</code>).
138 */
139 public void testString2Float_1() {
140 try {
141 Message message = senderSession.createMessage();
142 message.setStringProperty("pi", "3.14159");
143 assertEquals(3.14159F,message.getFloatProperty("pi"), 0);
144 } catch (JMSException e) {
145 fail(e);
146 }
147 }
148
149 /**
150 * if a property is set as a <code>java.lang.String</code>,
151 * to get it as a <code>long</code> throws a <code>java.lang.NuberFormatException</code>
152 * if the <code>String</code> is not a correct representation for a <code>long</code>
153 * (e.g. <code>"3.14159"</code>).
154 */
155 public void testString2Long_2() {
156 try {
157 Message message = senderSession.createMessage();
158 message.setStringProperty("pi", "3.14159");
159 message.getLongProperty("pi");
160 fail("§3.5.4 The String to numeric conversions must throw the java.lang.NumberFormatException " +
161 " if the numeric's valueOf() method does not accept the String value as a valid representation.\n");
162 } catch (java.lang.NumberFormatException e) {
163 } catch (JMSException e) {
164 fail(e);
165 }
166 }
167
168 /**
169 * if a property is set as a <code>java.lang.String</code>,
170 * it can also be read as a <code>long</code> as long as the <code>String</code>
171 * is a correct representation of a <code>long</code> (e.g. <code>"0"</code>).
172 */
173 public void testString2Long_1() {
174 try {
175 Message message = senderSession.createMessage();
176 message.setStringProperty("prop", "0");
177 assertEquals((long)0,message.getLongProperty("prop"));
178 } catch (JMSException e) {
179 fail(e);
180 }
181 }
182
183 /**
184 * if a property is set as a <code>java.lang.String</code>,
185 * to get it as a <code>int</code> throws a <code>java.lang.NuberFormatException</code>
186 * if the <code>String</code> is not a correct representation for a <code>int</code>
187 * (e.g. <code>"3.14159"</code>).
188 */
189 public void testString2Int_2() {
190 try {
191 Message message = senderSession.createMessage();
192 message.setStringProperty("pi", "3.14159");
193 message.getIntProperty("pi");
194 fail("§3.5.4 The String to numeric conversions must throw the java.lang.NumberFormatException " +
195 " if the numeric's valueOf() method does not accept the String value as a valid representation.\n");
196 } catch (java.lang.NumberFormatException e) {
197 } catch (JMSException e) {
198 fail(e);
199 }
200 }
201
202 /**
203 * if a property is set as a <code>java.lang.String</code>,
204 * it can also be read as a <code>int</code> as long as the <code>String</code>
205 * is a correct representation of a <code>int</code> (e.g. <code>"0"</code>).
206 */
207 public void testString2Int_1() {
208 try {
209 Message message = senderSession.createMessage();
210 message.setStringProperty("prop", "0");
211 assertEquals((int)0,message.getIntProperty("prop"));
212 } catch (JMSException e) {
213 fail(e);
214 }
215 }
216
217 /**
218 * if a property is set as a <code>java.lang.String</code>,
219 * to get it as a <code>short</code> throws a <code>java.lang.NuberFormatException</code>
220 * if the <code>String</code> is not a correct representation for a <code>short</code>
221 * (e.g. <code>"3.14159"</code>).
222 */
223 public void testString2Short_2() {
224 try {
225 Message message = senderSession.createMessage();
226 message.setStringProperty("pi", "3.14159");
227 message.getShortProperty("pi");
228 fail("§3.5.4 The String to numeric conversions must throw the java.lang.NumberFormatException " +
229 " if the numeric's valueOf() method does not accept the String value as a valid representation.\n");
230 } catch (java.lang.NumberFormatException e) {
231 } catch (JMSException e) {
232 fail(e);
233 }
234 }
235
236 /**
237 * if a property is set as a <code>java.lang.String</code>,
238 * it can also be read as a <code>short</code> as long as the <code>String</code>
239 * is a correct representation of a <code>short</code> (e.g. <code>"0"</code>).
240 */
241 public void testString2Short_1() {
242 try {
243 Message message = senderSession.createMessage();
244 message.setStringProperty("prop", "0");
245 assertEquals((short)0,message.getShortProperty("prop"));
246 } catch (JMSException e) {
247 fail(e);
248 }
249 }
250
251 /**
252 * if a property is set as a <code>java.lang.String</code>,
253 * to get it as a <code>byte</code> throws a <code>java.lang.NuberFormatException</code>
254 * if the <code>String</code> is not a correct representation for a <code>byte</code>
255 * (e.g. <code>"3.14159"</code>).
256 */
257 public void testString2Byte_2() {
258 try {
259 Message message = senderSession.createMessage();
260 message.setStringProperty("pi", "3.14159");
261 message.getByteProperty("pi");
262 fail("§3.5.4 The String to numeric conversions must throw the java.lang.NumberFormatException " +
263 " if the numeric's valueOf() method does not accept the String value as a valid representation.\n");
264 } catch (java.lang.NumberFormatException e) {
265 } catch (JMSException e) {
266 fail(e);
267 }
268 }
269
270 /**
271 * if a property is set as a <code>java.lang.String</code>,
272 * it can also be read as a <code>byte</code> if the <code>String</code>
273 * is a correct representation of a <code>byte</code> (e.g. <code>"0"</code>).
274 */
275 public void testString2Byte_1() {
276 try {
277 Message message = senderSession.createMessage();
278 message.setStringProperty("prop", "0");
279 assertEquals((byte)0,message.getByteProperty("prop"));
280 } catch (JMSException e) {
281 fail(e);
282 }
283 }
284
285 /**
286 * if a property is set as a <code>java.lang.String</code>,
287 * to get it as a <code>boolean</code> returns <code>true</code> if the property is not
288 * null and is equal, ignoring case, to the string "true" (.eg. "True" is ok), else it
289 * returns <code>false</code> (e.g. "test")
290 */
291 public void testString2Boolean_2() {
292 try {
293 Message message = senderSession.createMessage();
294 message.setStringProperty("prop", "test");
295 assertEquals(false, message.getBooleanProperty("prop"));
296 } catch (MessageFormatException e) {
297 } catch (JMSException e) {
298 fail(e);
299 }
300 }
301
302 /**
303 * if a property is set as a <code>java.lang.String</code>,
304 * it can also be read as a <code>boolean</code> if the <code>String</code>
305 * is a correct representation of a <code>boolean</code> (e.g. <code>"true"</code>).
306 */
307 public void testString2Boolean_1() {
308 try {
309 Message message = senderSession.createMessage();
310 message.setStringProperty("prop", "true");
311 assertEquals(true,message.getBooleanProperty("prop"));
312 } catch (JMSException e) {
313 fail(e);
314 }
315 }
316
317 /**
318 * if a property is set as a <code>double</code>,
319 * it can also be read as a <code>java.lang.String</code>.
320 */
321 public void testDouble2String() {
322 try {
323 Message message = senderSession.createMessage();
324 message.setDoubleProperty("prop", 127.0);
325 assertEquals("127.0", message.getStringProperty("prop"));
326 } catch (JMSException e) {
327 fail(e);
328 }
329 }
330
331 /**
332 * if a property is set as a <code>double</code>,
333 * it can also be read as a <code>double</code>.
334 */
335 public void testDouble2Double() {
336 try {
337 Message message = senderSession.createMessage();
338 message.setDoubleProperty("prop", 127.0);
339 assertEquals(127.0, message.getDoubleProperty("prop"), 0);
340 } catch (JMSException e) {
341 fail(e);
342 }
343 }
344
345 /**
346 * if a property is set as a <code>double</code>,
347 * to get is as a <code>float</code> throws a <code>javax.jms.MessageFormatException</code>.
348 */
349 public void testDouble2Float() {
350 try {
351 Message message = senderSession.createMessage();
352 message.setDoubleProperty("prop", 127.0);
353 message.getFloatProperty("prop");
354 fail("§3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
355 } catch (MessageFormatException e) {
356 } catch (JMSException e) {
357 fail(e);
358 }
359 }
360
361 /**
362 * if a property is set as a <code>double</code>,
363 * to get is as a <code>long</code> throws a <code>javax.jms.MessageFormatException</code>.
364 */
365 public void testDouble2Long() {
366 try {
367 Message message = senderSession.createMessage();
368 message.setDoubleProperty("prop", 127.0);
369 message.getLongProperty("prop");
370 fail("§3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
371 } catch (MessageFormatException e) {
372 } catch (JMSException e) {
373 fail(e);
374 }
375 }
376
377 /**
378 * if a property is set as a <code>double</code>,
379 * to get is as an <code>int</code> throws a <code>javax.jms.MessageFormatException</code>.
380 */
381 public void testDouble2Int() {
382 try {
383 Message message = senderSession.createMessage();
384 message.setDoubleProperty("prop", 127.0);
385 message.getIntProperty("prop");
386 fail("§3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
387 } catch (MessageFormatException e) {
388 } catch (JMSException e) {
389 fail(e);
390 }
391 }
392
393 /**
394 * if a property is set as a <code>double</code>,
395 * to get is as a <code>short</code> throws a <code>javax.jms.MessageFormatException</code>.
396 */
397 public void testDouble2Short() {
398 try {
399 Message message = senderSession.createMessage();
400 // store a value that can't be converted to short
401 message.setDoubleProperty("prop", 127.0);
402 message.getShortProperty("prop");
403 fail("§3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
404 } catch (MessageFormatException e) {
405 } catch (JMSException e) {
406 fail(e);
407 }
408 }
409
410 /**
411 * if a property is set as a <code>double</code>,
412 * to get is as a <code>byte</code> throws a <code>javax.jms.MessageFormatException</code>.
413 */
414 public void testDouble2Byte() {
415 try {
416 Message message = senderSession.createMessage();
417 // store a value that can't be converted to byte
418 message.setDoubleProperty("prop", 127.0);
419 message.getByteProperty("prop");
420 fail("§3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
421 } catch (MessageFormatException e) {
422 } catch (JMSException e) {
423 fail(e);
424 }
425 }
426
427 /**
428 * if a property is set as a <code>double</code>,
429 * to get is as a <code>boolean</code> throws a <code>javax.jms.MessageFormatException</code>.
430 */
431 public void testDouble2Boolean() {
432 try {
433 Message message = senderSession.createMessage();
434 // store a value that can be converted to boolean
435 message.setDoubleProperty("prop", 127.0);
436 message.getBooleanProperty("prop");
437 fail("§3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
438 } catch (MessageFormatException e) {
439 } catch (JMSException e) {
440 fail(e);
441 }
442 }
443
444 /**
445 * if a property is set as a <code>float</code>,
446 * it can also be read as a <code>String</code>.
447 */
448 public void testFloat2String() {
449 try {
450 Message message = senderSession.createMessage();
451 message.setFloatProperty("prop", 127.0F);
452 assertEquals("127.0", message.getStringProperty("prop"));
453 } catch (JMSException e) {
454 fail(e);
455 }
456 }
457
458 /**
459 * if a property is set as a <code>float</code>,
460 * it can also be read as a <code>double</code>.
461 */
462 public void testFloat2Double() {
463 try {
464 Message message = senderSession.createMessage();
465 message.setFloatProperty("prop", 127.0F);
466 assertEquals(127.0, message.getDoubleProperty("prop"), 0);
467 } catch (JMSException e) {
468 fail(e);
469 }
470 }
471
472 /**
473 * if a property is set as a <code>float</code>,
474 * it can also be read as a <code>float</code>.
475 */
476 public void testFloat2Float() {
477 try {
478 Message message = senderSession.createMessage();
479 message.setFloatProperty("prop", 127.0F);
480 assertEquals(127.0F, message.getFloatProperty("prop"), 0);
481 } catch (JMSException e) {
482 fail(e);
483 }
484 }
485
486 /**
487 * if a property is set as a <code>float</code>,
488 * to get is as a <code>long</code> throws a <code>javax.jms.MessageFormatException</code>.
489 */
490 public void testFloat2Long() {
491 try {
492 Message message = senderSession.createMessage();
493 message.setFloatProperty("prop", 127.0F);
494 message.getLongProperty("prop");
495 fail("§3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
496 } catch (MessageFormatException e) {
497 } catch (JMSException e) {
498 fail(e);
499 }
500 }
501
502 /**
503 * if a property is set as a <code>float</code>,
504 * to get is as a <code>int</code> throws a <code>javax.jms.MessageFormatException</code>.
505 */
506 public void testFloat2Int() {
507 try {
508 Message message = senderSession.createMessage();
509 message.setFloatProperty("prop", 127.0F);
510 message.getIntProperty("prop");
511 fail("§3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
512 } catch (MessageFormatException e) {
513 } catch (JMSException e) {
514 fail(e);
515 }
516 }
517
518 /**
519 * if a property is set as a <code>float</code>,
520 * to get is as a <code>short</code> throws a <code>javax.jms.MessageFormatException</code>.
521 */
522 public void testFloat2Short() {
523 try {
524 Message message = senderSession.createMessage();
525 // store a value that can't be converted to short
526 message.setFloatProperty("prop", 127.0F);
527 message.getShortProperty("prop");
528 fail("§3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
529 } catch (MessageFormatException e) {
530 } catch (JMSException e) {
531 fail(e);
532 }
533 }
534
535 /**
536 * if a property is set as a <code>float</code>,
537 * to get is as a <code>byte</code> throws a <code>javax.jms.MessageFormatException</code>.
538 */
539 public void testFloat2Byte() {
540 try {
541 Message message = senderSession.createMessage();
542 // store a value that can't be converted to byte
543 message.setFloatProperty("prop", 127.0F);
544 message.getByteProperty("prop");
545 fail("§3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
546 } catch (MessageFormatException e) {
547 } catch (JMSException e) {
548 fail(e);
549 }
550 }
551
552 /**
553 * if a property is set as a <code>float</code>,
554 * to get is as a <code>boolean</code> throws a <code>javax.jms.MessageFormatException</code>.
555 */
556 public void testFloat2Boolean() {
557 try {
558 Message message = senderSession.createMessage();
559 // store a value that can be converted to boolean
560 message.setFloatProperty("prop", 127.0F);
561 message.getBooleanProperty("prop");
562 fail("§3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
563 } catch (MessageFormatException e) {
564 } catch (JMSException e) {
565 fail(e);
566 }
567 }
568
569 /**
570 * if a property is set as a <code>long</code>,
571 * it can also be read as a <code>String</code>.
572 */
573 public void testLong2String() {
574 try {
575 Message message = senderSession.createMessage();
576 message.setLongProperty("prop", 127L);
577 assertEquals("127", message.getStringProperty("prop"));
578 } catch (JMSException e) {
579 fail(e);
580 }
581 }
582
583 /**
584 * if a property is set as a <code>long</code>,
585 * to get is as a <code>double</code> throws a <code>javax.jms.MessageFormatException</code>.
586 */
587 public void testLong2Double() {
588 try {
589 Message message = senderSession.createMessage();
590 message.setLongProperty("prop", 127L);
591 message.getDoubleProperty("prop");
592 fail("§3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
593 } catch (MessageFormatException e) {
594 } catch (JMSException e) {
595 fail(e);
596 }
597 }
598
599 /**
600 * if a property is set as a <code>long</code>,
601 * to get is as a <code>float</code> throws a <code>javax.jms.MessageFormatException</code>.
602 */
603 public void testLong2Float() {
604 try {
605 Message message = senderSession.createMessage();
606 message.setLongProperty("prop", 127L);
607 message.getFloatProperty("prop");
608 fail("§3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
609 } catch (MessageFormatException e) {
610 } catch (JMSException e) {
611 fail(e);
612 }
613 }
614
615 /**
616 * if a property is set as a <code>long</code>,
617 * it can also be read as a <code>long</code>.
618 */
619 public void testLong2Long() {
620 try {
621 Message message = senderSession.createMessage();
622 message.setLongProperty("prop", 127L);
623 assertEquals(127L, message.getLongProperty("prop"));
624 } catch (JMSException e) {
625 fail(e);
626 }
627 }
628
629 /**
630 * if a property is set as a <code>long</code>,
631 * to get is as an <code>int</code> throws a <code>javax.jms.MessageFormatException</code>.
632 */
633 public void testLong2Int() {
634 try {
635 Message message = senderSession.createMessage();
636 message.setLongProperty("prop", 127L);
637 message.getIntProperty("prop");
638 fail("§3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
639 } catch (MessageFormatException e) {
640 } catch (JMSException e) {
641 fail(e);
642 }
643 }
644
645 /**
646 * if a property is set as a <code>long</code>,
647 * to get is as a <code>short</code> throws a <code>javax.jms.MessageFormatException</code>.
648 */
649 public void testLong2Short() {
650 try {
651 Message message = senderSession.createMessage();
652 // store a value that can't be converted to short
653 message.setLongProperty("prop", 127L);
654 message.getShortProperty("prop");
655 fail("§3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
656 } catch (MessageFormatException e) {
657 } catch (JMSException e) {
658 fail(e);
659 }
660 }
661
662 /**
663 * if a property is set as a <code>long</code>,
664 * to get is as a <code>byte</code> throws a <code>javax.jms.MessageFormatException</code>.
665 */
666 public void testLong2Byte() {
667 try {
668 Message message = senderSession.createMessage();
669 // store a value that can't be converted to byte
670 message.setLongProperty("prop", 127L);
671 message.getByteProperty("prop");
672 fail("§3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
673 } catch (MessageFormatException e) {
674 } catch (JMSException e) {
675 fail(e);
676 }
677 }
678
679 /**
680 * if a property is set as a <code>long</code>,
681 * to get is as a <code>boolean</code> throws a <code>javax.jms.MessageFormatException</code>.
682 */
683 public void testLong2Boolean() {
684 try {
685 Message message = senderSession.createMessage();
686 // store a value that can be converted to boolean
687 message.setLongProperty("prop", 127L);
688 message.getBooleanProperty("prop");
689 fail("§3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
690 } catch (MessageFormatException e) {
691 } catch (JMSException e) {
692 fail(e);
693 }
694 }
695
696 /**
697 * if a property is set as an <code>int</code>,
698 * it can also be read as a <code>String</code>.
699 */
700 public void testInt2String() {
701 try {
702 Message message = senderSession.createMessage();
703 message.setIntProperty("prop", (int)127);
704 assertEquals("127", message.getStringProperty("prop"));
705 } catch (JMSException e) {
706 fail(e);
707 }
708 }
709
710 /**
711 * if a property is set as a <code>int</code>,
712 * to get is as a <code>double</code> throws a <code>javax.jms.MessageFormatException</code>.
713 */
714 public void testInt2Double() {
715 try {
716 Message message = senderSession.createMessage();
717 message.setIntProperty("prop", (int)127);
718 message.getDoubleProperty("prop");
719 fail("§3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
720 } catch (MessageFormatException e) {
721 } catch (JMSException e) {
722 fail(e);
723 }
724 }
725
726 /**
727 * if a property is set as a <code>int</code>,
728 * to get is as a <code>float</code> throws a <code>javax.jms.MessageFormatException</code>.
729 */
730 public void testInt2Float() {
731 try {
732 Message message = senderSession.createMessage();
733 message.setIntProperty("prop", (int)127);
734 message.getFloatProperty("prop");
735 fail("§3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
736 } catch (MessageFormatException e) {
737 } catch (JMSException e) {
738 fail(e);
739 }
740 }
741
742 /**
743 * if a property is set as an <code>int</code>,
744 * it can also be read as a <code>long</code>.
745 */
746 public void testInt2Long() {
747 try {
748 Message message = senderSession.createMessage();
749 message.setIntProperty("prop", (int)127);
750 assertEquals(127L, message.getLongProperty("prop"));
751 } catch (JMSException e) {
752 fail(e);
753 }
754 }
755
756 /**
757 * if a property is set as an <code>int</code>,
758 * it can also be read as an <code>int</code>.
759 */
760 public void testInt2Int() {
761 try {
762 Message message = senderSession.createMessage();
763 message.setIntProperty("prop", (int)127);
764 assertEquals((int)127, message.getIntProperty("prop"));
765 } catch (JMSException e) {
766 fail(e);
767 }
768 }
769
770 /**
771 * if a property is set as a <code>int</code>,
772 * to get is as a <code>short</code> throws a <code>javax.jms.MessageFormatException</code>.
773 */
774 public void testInt2Short() {
775 try {
776 Message message = senderSession.createMessage();
777 // store a value that can't be converted to short
778 message.setIntProperty("prop", Integer.MAX_VALUE);
779 message.getShortProperty("prop");
780 fail("§3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
781 } catch (MessageFormatException e) {
782 } catch (JMSException e) {
783 fail(e);
784 }
785 }
786
787 /**
788 * if a property is set as a <code>int</code>,
789 * to get is as a <code>byte</code> throws a <code>javax.jms.MessageFormatException</code>.
790 */
791 public void testInt2Byte() {
792 try {
793 Message message = senderSession.createMessage();
794 // store a value that can't be converted to byte
795 message.setIntProperty("prop", Integer.MAX_VALUE);
796 message.getByteProperty("prop");
797 fail("§3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
798 } catch (MessageFormatException e) {
799 } catch (JMSException e) {
800 fail(e);
801 }
802 }
803
804 /**
805 * if a property is set as a <code>int</code>,
806 * to get is as a <code>boolean</code> throws a <code>javax.jms.MessageFormatException</code>.
807 */
808 public void testInt2Boolean() {
809 try {
810 Message message = senderSession.createMessage();
811 // store a value that can be converted to boolean
812 message.setIntProperty("prop", Integer.MAX_VALUE);
813 message.getBooleanProperty("prop");
814 fail("§3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
815 } catch (MessageFormatException e) {
816 } catch (JMSException e) {
817 fail(e);
818 }
819 }
820
821 /**
822 * if a property is set as a <code>short</code>,
823 * it can also be read as a <code>String</code>.
824 */
825 public void testShort2String() {
826 try {
827 Message message = senderSession.createMessage();
828 message.setShortProperty("prop", (short)127);
829 assertEquals("127", message.getStringProperty("prop"));
830 } catch (JMSException e) {
831 fail(e);
832 }
833 }
834
835 /**
836 * if a property is set as a <code>short</code>,
837 * to get is as a <code>double</code> throws a <code>javax.jms.MessageFormatException</code>.
838 */
839 public void testShort2Double() {
840 try {
841 Message message = senderSession.createMessage();
842 message.setShortProperty("prop", (short)127);
843 message.getDoubleProperty("prop");
844 fail("§3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
845 } catch (MessageFormatException e) {
846 } catch (JMSException e) {
847 fail(e);
848 }
849 }
850
851 /**
852 * if a property is set as a <code>short</code>,
853 * to get is as a <code>float</code> throws a <code>javax.jms.MessageFormatException</code>.
854 */
855 public void testShort2Float() {
856 try {
857 Message message = senderSession.createMessage();
858 message.setShortProperty("prop", (short)127);
859 message.getFloatProperty("prop");
860 fail("§3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
861 } catch (MessageFormatException e) {
862 } catch (JMSException e) {
863 fail(e);
864 }
865 }
866
867 /**
868 * if a property is set as a <code>short</code>,
869 * it can also be read as a <code>long</code>.
870 */
871 public void testShort2Long() {
872 try {
873 Message message = senderSession.createMessage();
874 message.setShortProperty("prop", (short)127);
875 assertEquals(127L, message.getLongProperty("prop"));
876 } catch (JMSException e) {
877 fail(e);
878 }
879 }
880
881 /**
882 * if a property is set as a <code>short</code>,
883 * it can also be read as an <code>int</code>.
884 */
885 public void testShort2Int() {
886 try {
887 Message message = senderSession.createMessage();
888 message.setShortProperty("prop", (short)127);
889 assertEquals((int)127, message.getIntProperty("prop"));
890 } catch (JMSException e) {
891 fail(e);
892 }
893 }
894
895 /**
896 * if a property is set as a <code>short</code>,
897 * it can also be read as a <code>short</code>.
898 */
899 public void testShort2Short() {
900 try {
901 Message message = senderSession.createMessage();
902 message.setShortProperty("prop", (short)127);
903 assertEquals((short)127, message.getShortProperty("prop"));
904 } catch (JMSException e) {
905 fail(e);
906 }
907 }
908
909 /**
910 * if a property is set as a <code>short</code>,
911 * to get is as a <code>byte</code> throws a <code>javax.jms.MessageFormatException</code>.
912 */
913 public void testShort2Byte() {
914 try {
915 Message message = senderSession.createMessage();
916 message.setShortProperty("prop", (short)127);
917 message.getByteProperty("prop");
918 fail("§3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
919 } catch (MessageFormatException e) {
920 } catch (JMSException e) {
921 fail(e);
922 }
923 }
924
925 /**
926 * if a property is set as a <code>short</code>,
927 * to get is as a <code>boolean</code> throws a <code>javax.jms.MessageFormatException</code>.
928 */
929 public void testShort2Boolean() {
930 try {
931 Message message = senderSession.createMessage();
932 // store a value that can't be converted to boolean
933 message.setShortProperty("prop", (short)127);
934 message.getBooleanProperty("prop");
935 fail("§3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
936 } catch (MessageFormatException e) {
937 } catch (JMSException e) {
938 fail(e);
939 }
940 }
941
942 /**
943 * if a property is set as a <code>byte</code>,
944 * it can also be read as a <code>String</code>.
945 */
946 public void testByte2String() {
947 try {
948 Message message = senderSession.createMessage();
949 message.setByteProperty("prop", (byte)127);
950 assertEquals("127", message.getStringProperty("prop"));
951 } catch (JMSException e) {
952 fail(e);
953 }
954 }
955
956 /**
957 * if a property is set as a <code>byte</code>,
958 * to get is as a <code>double</code> throws a <code>javax.jms.MessageFormatException</code>.
959 */
960 public void testByte2Double() {
961 try {
962 Message message = senderSession.createMessage();
963 message.setByteProperty("prop", (byte)127);
964 message.getDoubleProperty("prop");
965 fail("§3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
966 } catch (MessageFormatException e) {
967 } catch (JMSException e) {
968 fail(e);
969 }
970 }
971
972 /**
973 * if a property is set as a <code>byte</code>,
974 * to get is as a <code>float</code> throws a <code>javax.jms.MessageFormatException</code>.
975 */
976 public void testByte2Float() {
977 try {
978 Message message = senderSession.createMessage();
979 message.setByteProperty("prop", (byte)127);
980 message.getFloatProperty("prop");
981 fail("§3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
982 } catch (MessageFormatException e) {
983 } catch (JMSException e) {
984 fail(e);
985 }
986 }
987
988 /**
989 * if a property is set as a <code>byte</code>,
990 * it can also be read as a <code>long</code>.
991 */
992 public void testByte2Long() {
993 try {
994 Message message = senderSession.createMessage();
995 message.setByteProperty("prop", (byte)127);
996 assertEquals(127L, message.getLongProperty("prop"));
997 } catch (JMSException e) {
998 fail(e);
999 }
1000 }
1001
1002 /**
1003 * if a property is set as a <code>byte</code>,
1004 * it can also be read as an <code>int</code>.
1005 */
1006 public void testByte2Int() {
1007 try {
1008 Message message = senderSession.createMessage();
1009 message.setByteProperty("prop", (byte)127);
1010 assertEquals((int)127, message.getIntProperty("prop"));
1011 } catch (JMSException e) {
1012 fail(e);
1013 }
1014 }
1015
1016 /**
1017 * if a property is set as a <code>byte</code>,
1018 * it can also be read as a <code>short</code>.
1019 */
1020 public void testByte2Short() {
1021 try {
1022 Message message = senderSession.createMessage();
1023 message.setByteProperty("prop", (byte)127);
1024 assertEquals((short)127, message.getShortProperty("prop"));
1025 } catch (JMSException e) {
1026 fail(e);
1027 }
1028 }
1029
1030 /**
1031 * if a property is set as a <code>byte</code>,
1032 * it can also be read as a <code>byte</code>.
1033 */
1034 public void testByte2Byte() {
1035 try {
1036 Message message = senderSession.createMessage();
1037 message.setByteProperty("prop", (byte)127);
1038 assertEquals((byte)127, message.getByteProperty("prop"));
1039 } catch (JMSException e) {
1040 fail(e);
1041 }
1042 }
1043
1044 /**
1045 * if a property is set as a <code>byte</code>,
1046 * to get is as a <code>boolean</code> throws a <code>javax.jms.MessageFormatException</code>.
1047 */
1048 public void testByte2Boolean() {
1049 try {
1050 Message message = senderSession.createMessage();
1051 // store a value that can't be converted to boolean
1052 message.setByteProperty("prop", (byte)127);
1053 message.getBooleanProperty("prop");
1054 fail("§3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
1055 } catch (MessageFormatException e) {
1056 } catch (JMSException e) {
1057 fail(e);
1058 }
1059 }
1060
1061 /**
1062 * if a property is set as a <code>boolean</code>,
1063 * it can also be read as a <code>String</code>.
1064 */
1065 public void testBoolean2String() {
1066 try {
1067 Message message = senderSession.createMessage();
1068 message.setBooleanProperty("prop", true);
1069 assertEquals("true",message.getStringProperty("prop"));
1070 } catch (JMSException e) {
1071 fail(e);
1072 }
1073 }
1074
1075 /**
1076 * if a property is set as a <code>boolean</code>,
1077 * to get is as a <code>double</code> throws a <code>javax.jms.MessageFormatException</code>.
1078 */
1079 public void testBoolean2Double() {
1080 try {
1081 Message message = senderSession.createMessage();
1082 // store a value that can't be converted to double
1083 message.setBooleanProperty("prop", true);
1084 message.getDoubleProperty("prop");
1085 fail("§3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
1086 } catch (MessageFormatException e) {
1087 } catch (JMSException e) {
1088 fail(e);
1089 }
1090 }
1091
1092 /**
1093 * if a property is set as a <code>boolean</code>,
1094 * to get is as a <code>float</code> throws a <code>javax.jms.MessageFormatException</code>.
1095 */
1096 public void testBoolean2Float() {
1097 try {
1098 Message message = senderSession.createMessage();
1099 // store a value that can't be converted to float
1100 message.setBooleanProperty("prop", true);
1101 message.getFloatProperty("prop");
1102 fail("§3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
1103 } catch (MessageFormatException e) {
1104 } catch (JMSException e) {
1105 fail(e);
1106 }
1107 }
1108
1109 /**
1110 * if a property is set as a <code>boolean</code>,
1111 * to get is as a <code>long</code> throws a <code>javax.jms.MessageFormatException</code>.
1112 */
1113 public void testBoolean2Long() {
1114 try {
1115 Message message = senderSession.createMessage();
1116 // store a value that can't be converted to long
1117 message.setBooleanProperty("true", true);
1118 message.getLongProperty("true");
1119 fail("§3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
1120 } catch (MessageFormatException e) {
1121 } catch (JMSException e) {
1122 fail(e);
1123 }
1124 }
1125
1126 /**
1127 * if a property is set as a <code>boolean</code>,
1128 * to get is as a <code>int</code> throws a <code>javax.jms.MessageFormatException</code>.
1129 */
1130 public void testBoolean2Int() {
1131 try {
1132 Message message = senderSession.createMessage();
1133 // store a value that can't be converted to int
1134 message.setBooleanProperty("prop", true);
1135 message.getIntProperty("prop");
1136 fail("§3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
1137 } catch (MessageFormatException e) {
1138 } catch (JMSException e) {
1139 fail(e);
1140 }
1141 }
1142
1143 /**
1144 * if a property is set as a <code>boolean</code>,
1145 * to get is as a <code>short</code> throws a <code>javax.jms.MessageFormatException</code>.
1146 */
1147 public void testBoolean2Short() {
1148 try {
1149 Message message = senderSession.createMessage();
1150 // store a value that can't be converted to short
1151 message.setBooleanProperty("prop", true);
1152 message.getShortProperty("prop");
1153 fail("§3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
1154 } catch (MessageFormatException e) {
1155 } catch (JMSException e) {
1156 fail(e);
1157 }
1158 }
1159
1160 /**
1161 * if a property is set as a <code>boolean</code>,
1162 * to get is as a <code>byte</code> throws a <code>javax.jms.MessageFormatException</code>.
1163 */
1164 public void testBoolean2Byte() {
1165 try {
1166 Message message = senderSession.createMessage();
1167 // store a value that can't be converted to byte
1168 message.setBooleanProperty("prop", true);
1169 message.getByteProperty("prop");
1170 fail("§3.5.4 The unmarked cases [of Table 0-4] should raise a JMS MessageFormatException.\n");
1171 } catch (MessageFormatException e) {
1172 } catch (JMSException e) {
1173 fail(e);
1174 }
1175 }
1176
1177 /**
1178 * if a property is set as a <code>boolean</code>,
1179 * it can also be read as a <code>boolean</code>.
1180 */
1181 public void testBoolean2Boolean() {
1182 try {
1183 Message message = senderSession.createMessage();
1184 message.setBooleanProperty("prop", true);
1185 assertEquals(true,message.getBooleanProperty("prop"));
1186 } catch (JMSException e) {
1187 fail(e);
1188 }
1189 }
1190
1191 /**
1192 * Method to use this class in a Test suite
1193 */
1194 public static Test suite() {
1195 return new TestSuite(MessagePropertyConversionTest.class);
1196 }
1197
1198 public MessagePropertyConversionTest(String name) {
1199 super(name);
1200 }
1201}