001: package org.mockejb.jms.test;
002:
003: import java.util.Enumeration;
004: import javax.jms.*;
005:
006: import org.mockejb.jms.MapMessageImpl;
007: import org.mockejb.jms.MessageUtility;
008:
009: /**
010: * Tests <code>MapMessageImpl</code>.
011: *
012: * @author Dimitar Gospodinov
013: */
014: public class MapMessageImplTest extends MessageTester {
015:
016: private MapMessage msg;
017:
018: public MapMessageImplTest(String name) {
019: super (name);
020: }
021:
022: protected void setUp() throws Exception {
023: msg = new MapMessageImpl();
024: message = msg;
025: super .setUp();
026: }
027:
028: protected void tearDown() throws Exception {
029: msg = null;
030: }
031:
032: public void testAllValues() throws JMSException {
033: assertFalse(msg.getMapNames().hasMoreElements());
034: assertNull(msg.getObject("some name"));
035:
036: msg.setBoolean("boolean", false);
037: msg.setByte("byte", (byte) 127);
038: msg.setShort("short", (short) 8192);
039: msg.setShort("short", (short) 8193);
040: msg.setInt("int", 65536);
041: msg.setLong("long", 400111000111L);
042: msg.setFloat("float", (float) 34.8);
043: msg.setDouble("double", 23232311111.8821);
044: msg.setString("string", "str_val");
045: Object obj = Long.valueOf("900111000111");
046: msg.setObject("obj_long", obj);
047: msg.setBoolean("boolean1", true);
048: msg.setChar("char", 'd');
049:
050: byte[] bytes = { 1, 2, 3, 4, 127 };
051: msg.setBytes("bytes1", bytes);
052: msg.setBytes("bytes2", bytes, 2, 3);
053:
054: checkValues(msg, obj);
055: MapMessage msg1 = new MapMessageImpl(msg);
056: checkValues(new MapMessageImpl(msg), obj);
057: checkMessageAttributes(msg1);
058: checkMessageAttributes();
059:
060: msg.clearProperties();
061: assertFalse(msg.getPropertyNames().hasMoreElements());
062:
063: try {
064: msg.setObjectProperty("obj", new Object());
065: fail();
066: } catch (MessageFormatException ex) {
067: }
068: }
069:
070: private void checkValues(MapMessage msg, Object objValue)
071: throws JMSException {
072: Enumeration e = msg.getMapNames();
073: int i = 0;
074: Object obj;
075: while (e.hasMoreElements()) {
076: String name = (String) e.nextElement();
077: if (name.equals("boolean")) {
078: assertFalse(msg.getBoolean("boolean"));
079: obj = msg.getObject("boolean");
080: assertTrue(obj instanceof Boolean);
081: assertFalse(((Boolean) obj).booleanValue());
082: } else if (name.equals("byte")) {
083: assertEquals(msg.getByte("byte"), (byte) 127);
084: obj = msg.getObject("byte");
085: assertTrue(obj instanceof Byte);
086: assertEquals(((Byte) obj).byteValue(), (byte) 127);
087: } else if (name.equals("short")) {
088: assertEquals(msg.getShort("short"), (short) 8193);
089: obj = msg.getObject("short");
090: assertTrue(obj instanceof Short);
091: assertEquals(((Short) obj).shortValue(), (short) 8193);
092: } else if (name.equals("int")) {
093: assertEquals(msg.getInt("int"), 65536);
094: obj = msg.getObject("int");
095: assertTrue(obj instanceof Integer);
096: assertEquals(((Integer) obj).intValue(), 65536);
097: } else if (name.equals("long")) {
098: assertEquals(msg.getLong("long"), 400111000111L);
099: obj = msg.getObject("long");
100: assertTrue(obj instanceof Long);
101: assertEquals(((Long) obj).longValue(), 400111000111L);
102: } else if (name.equals("float")) {
103: assertEquals(msg.getFloat("float"), (float) 34.8,
104: (float) 0.1);
105: obj = msg.getObject("float");
106: assertTrue(obj instanceof Float);
107: assertEquals(((Float) obj).floatValue(), (float) 34.8,
108: (float) 0.1);
109: } else if (name.equals("double")) {
110: assertEquals(msg.getDouble("double"), 23232311111.8821,
111: 0.0001);
112: obj = msg.getObject("double");
113: assertTrue(obj instanceof Double);
114: assertEquals(((Double) obj).doubleValue(),
115: 23232311111.8821, 0.0001);
116: } else if (name.equals("string")) {
117: assertEquals(msg.getString("string"), "str_val");
118: obj = msg.getObject("string");
119: assertTrue(obj instanceof String);
120: assertEquals(obj, "str_val");
121: } else if (name.equals("obj_long")) {
122: assertSame(msg.getObject("obj_long"), objValue);
123: } else if (name.equals("boolean1")) {
124: assertTrue(msg.getBoolean("boolean1"));
125: obj = msg.getObject("boolean1");
126: assertTrue(obj instanceof Boolean);
127: assertTrue(((Boolean) obj).booleanValue());
128: } else if (name.equals("char")) {
129: assertEquals(msg.getChar("char"), 'd');
130: obj = msg.getObject("char");
131: assertTrue(obj instanceof Character);
132: assertEquals(((Character) obj).charValue(), 'd');
133: } else if (name.equals("bytes1")) {
134: byte[] bytes = msg.getBytes("bytes1");
135: assertNotNull(bytes);
136: assertEquals(bytes.length, 5);
137: assertEquals((byte) bytes[0], (byte) 1);
138: assertEquals((byte) bytes[1], (byte) 2);
139: assertEquals((byte) bytes[2], (byte) 3);
140: assertEquals((byte) bytes[3], (byte) 4);
141: assertEquals((byte) bytes[4], (byte) 127);
142: } else if (name.equals("bytes2")) {
143: byte[] bytes = msg.getBytes("bytes2");
144: assertNotNull(bytes);
145: assertEquals(bytes.length, 3);
146: assertEquals((byte) bytes[0], (byte) 3);
147: assertEquals((byte) bytes[1], (byte) 4);
148: assertEquals((byte) bytes[2], (byte) 127);
149: } else {
150: fail();
151: }
152: i++;
153: }
154: assertEquals(i, 13);
155: }
156:
157: public void testBoolean() throws JMSException {
158:
159: msg.setBoolean("boolean", true);
160: assertTrue(msg.itemExists("boolean"));
161: assertTrue(msg.getBoolean("boolean"));
162: assertEquals(msg.getString("boolean"), "true");
163: assertTrue(msg.getObject("boolean") instanceof Boolean);
164: assertTrue(((Boolean) msg.getObject("boolean")).booleanValue());
165:
166: msg.setBoolean("boolean", false);
167: assertFalse(msg.getBoolean("boolean"));
168:
169: msg.setObject("boolean", Boolean.FALSE);
170: assertFalse(msg.getBoolean("boolean"));
171:
172: try {
173: msg.getChar("boolean");
174: fail();
175: } catch (MessageFormatException ex) {
176: }
177: try {
178: msg.getByte("boolean");
179: fail();
180: } catch (MessageFormatException ex) {
181: }
182: try {
183: msg.getShort("boolean");
184: fail();
185: } catch (MessageFormatException ex) {
186: }
187: try {
188: msg.getInt("boolean");
189: fail();
190: } catch (MessageFormatException ex) {
191: }
192: try {
193: msg.getLong("boolean");
194: fail();
195: } catch (MessageFormatException ex) {
196: }
197: try {
198: msg.getFloat("boolean");
199: fail();
200: } catch (MessageFormatException ex) {
201: }
202: try {
203: msg.getDouble("boolean");
204: fail();
205: } catch (MessageFormatException ex) {
206: }
207:
208: MapMessage msg1 = new MapMessageImpl(msg);
209: assertTrue(msg1.itemExists("boolean"));
210: assertFalse(msg1.getBoolean("boolean"));
211: checkMessageAttributes(msg1);
212: checkMessageAttributes();
213: assertTrue(MessageUtility.compare(msg, msg1));
214: }
215:
216: public void testByte() throws JMSException {
217:
218: msg.setByte("byte", (byte) 127);
219: assertTrue(msg.itemExists("byte"));
220: assertEquals(msg.getByte("byte"), (byte) 127);
221: assertEquals(msg.getShort("byte"), (short) 127);
222: assertEquals(msg.getInt("byte"), 127);
223: assertEquals(msg.getLong("byte"), 127L);
224: assertEquals(msg.getString("byte"), Byte.valueOf("127")
225: .toString());
226: assertTrue(msg.getObject("byte") instanceof Byte);
227: assertEquals(((Byte) msg.getObject("byte")).byteValue(),
228: (byte) 127);
229:
230: msg.setObject("byte", new Byte((byte) 126));
231: assertEquals(msg.getByte("byte"), (byte) 126);
232:
233: try {
234: msg.getBoolean("byte");
235: fail();
236: } catch (MessageFormatException ex) {
237: }
238: try {
239: msg.getChar("byte");
240: fail();
241: } catch (MessageFormatException ex) {
242: }
243: try {
244: msg.getFloat("byte");
245: fail();
246: } catch (MessageFormatException ex) {
247: }
248: try {
249: msg.getDouble("byte");
250: fail();
251: } catch (MessageFormatException ex) {
252: }
253:
254: msg.setByte("byte", (byte) 125);
255: assertEquals(msg.getByte("byte"), (byte) 125);
256:
257: MapMessage msg1 = new MapMessageImpl(msg);
258: assertTrue(msg1.itemExists("byte"));
259: assertEquals(msg1.getByte("byte"), (byte) 125);
260:
261: checkMessageAttributes(msg1);
262: checkMessageAttributes();
263: assertTrue(MessageUtility.compare(msg, msg1));
264: }
265:
266: public void testChar() throws JMSException {
267:
268: msg.setChar("char", 'e');
269: assertTrue(msg.itemExists("char"));
270: assertEquals(msg.getChar("char"), 'e');
271: assertTrue(msg.getObject("char") instanceof Character);
272: assertEquals(((Character) msg.getObject("char")).charValue(),
273: 'e');
274: assertEquals(msg.getString("char"), "e");
275:
276: msg.setObject("char", new Character('x'));
277: assertEquals(msg.getChar("char"), 'x');
278:
279: try {
280: msg.getBoolean("char");
281: fail();
282: } catch (MessageFormatException ex) {
283: }
284: try {
285: msg.getByte("char");
286: fail();
287: } catch (MessageFormatException ex) {
288: }
289: try {
290: msg.getShort("char");
291: fail();
292: } catch (MessageFormatException ex) {
293: }
294: try {
295: msg.getInt("char");
296: fail();
297: } catch (MessageFormatException ex) {
298: }
299: try {
300: msg.getLong("char");
301: fail();
302: } catch (MessageFormatException ex) {
303: }
304: try {
305: msg.getFloat("char");
306: fail();
307: } catch (MessageFormatException ex) {
308: }
309: try {
310: msg.getDouble("char");
311: fail();
312: } catch (MessageFormatException ex) {
313: }
314:
315: msg.setChar("char", 'g');
316: assertEquals(msg.getChar("char"), 'g');
317:
318: MapMessage msg1 = new MapMessageImpl(msg);
319: assertTrue(msg1.itemExists("char"));
320: assertEquals(msg1.getChar("char"), 'g');
321:
322: checkMessageAttributes(msg1);
323: checkMessageAttributes();
324: assertTrue(MessageUtility.compare(msg, msg1));
325: }
326:
327: public void testShort() throws JMSException {
328:
329: msg.setShort("short", (short) 29000);
330: assertTrue(msg.itemExists("short"));
331: assertEquals(msg.getShort("short"), (short) 29000);
332: assertEquals(msg.getInt("short"), 29000);
333: assertEquals(msg.getLong("short"), 29000L);
334: assertEquals(msg.getString("short"), Short.valueOf("29000")
335: .toString());
336: assertTrue(msg.getObject("short") instanceof Short);
337: assertEquals(((Short) msg.getObject("short")).shortValue(),
338: (short) 29000);
339:
340: msg.setObject("short", new Short((short) 29001));
341: assertTrue(msg.getObject("short") instanceof Short);
342: assertEquals(((Short) msg.getObject("short")).shortValue(),
343: (short) 29001);
344:
345: try {
346: msg.getBoolean("short");
347: fail();
348: } catch (MessageFormatException ex) {
349: }
350: try {
351: msg.getByte("short");
352: fail();
353: } catch (MessageFormatException ex) {
354: }
355: try {
356: msg.getChar("short");
357: fail();
358: } catch (MessageFormatException ex) {
359: }
360: try {
361: msg.getFloat("short");
362: fail();
363: } catch (MessageFormatException ex) {
364: }
365: try {
366: msg.getDouble("short");
367: fail();
368: } catch (MessageFormatException ex) {
369: }
370:
371: msg.setShort("short", (short) 29002);
372: assertEquals(msg.getShort("short"), (short) 29002);
373:
374: MapMessage msg1 = new MapMessageImpl(msg);
375: assertTrue(msg1.itemExists("short"));
376: assertEquals(msg1.getShort("short"), (short) 29002);
377:
378: checkMessageAttributes(msg1);
379: checkMessageAttributes();
380: assertTrue(MessageUtility.compare(msg, msg1));
381: }
382:
383: public void testInt() throws JMSException {
384:
385: msg.setInt("int", 120000);
386: assertTrue(msg.itemExists("int"));
387: assertEquals(msg.getInt("int"), 120000);
388: assertEquals(msg.getLong("int"), 120000L);
389: assertEquals(msg.getString("int"), Integer.valueOf("120000")
390: .toString());
391: assertTrue(msg.getObject("int") instanceof Integer);
392: assertEquals(((Integer) msg.getObject("int")).intValue(),
393: 120000);
394:
395: msg.setObject("int", new Integer(120001));
396: assertTrue(msg.getObject("int") instanceof Integer);
397: assertEquals(((Integer) msg.getObject("int")).intValue(),
398: 120001);
399:
400: try {
401: msg.getBoolean("int");
402: fail();
403: } catch (MessageFormatException ex) {
404: }
405: try {
406: msg.getByte("int");
407: fail();
408: } catch (MessageFormatException ex) {
409: }
410: try {
411: msg.getChar("int");
412: fail();
413: } catch (MessageFormatException ex) {
414: }
415: try {
416: msg.getShort("int");
417: fail();
418: } catch (MessageFormatException ex) {
419: }
420: try {
421: msg.getFloat("int");
422: fail();
423: } catch (MessageFormatException ex) {
424: }
425: try {
426: msg.getDouble("int");
427: fail();
428: } catch (MessageFormatException ex) {
429: }
430:
431: msg.setInt("int", 240000);
432: assertEquals(msg.getInt("int"), 240000);
433:
434: MapMessage msg1 = new MapMessageImpl(msg);
435: assertTrue(msg1.itemExists("int"));
436: assertEquals(msg1.getInt("int"), 240000);
437:
438: checkMessageAttributes(msg1);
439: checkMessageAttributes();
440: assertTrue(MessageUtility.compare(msg, msg1));
441: }
442:
443: public void testLong() throws JMSException {
444:
445: msg.setLong("long", 222200002222L);
446: assertTrue(msg.itemExists("long"));
447: assertEquals(msg.getLong("long"), 222200002222L);
448: assertEquals(msg.getString("long"), Long
449: .valueOf("222200002222").toString());
450: assertTrue(msg.getObject("long") instanceof Long);
451: assertEquals(((Long) msg.getObject("long")).longValue(),
452: 222200002222L);
453:
454: msg.setObject("long", new Long(222299992222L));
455: assertTrue(msg.getObject("long") instanceof Long);
456: assertEquals(((Long) msg.getObject("long")).longValue(),
457: 222299992222L);
458:
459: try {
460: msg.getBoolean("long");
461: fail();
462: } catch (MessageFormatException ex) {
463: }
464: try {
465: msg.getByte("long");
466: fail();
467: } catch (MessageFormatException ex) {
468: }
469: try {
470: msg.getChar("long");
471: fail();
472: } catch (MessageFormatException ex) {
473: }
474: try {
475: msg.getShort("long");
476: fail();
477: } catch (MessageFormatException ex) {
478: }
479: try {
480: msg.getInt("long");
481: fail();
482: } catch (MessageFormatException ex) {
483: }
484: try {
485: msg.getFloat("long");
486: fail();
487: } catch (MessageFormatException ex) {
488: }
489: try {
490: msg.getDouble("long");
491: fail();
492: } catch (MessageFormatException ex) {
493: }
494:
495: msg.setLong("long", 222288882222L);
496: assertEquals(msg.getLong("long"), 222288882222L);
497:
498: MapMessage msg1 = new MapMessageImpl(msg);
499: assertTrue(msg1.itemExists("long"));
500: assertEquals(msg1.getLong("long"), 222288882222L);
501:
502: checkMessageAttributes(msg1);
503: checkMessageAttributes();
504: assertTrue(MessageUtility.compare(msg, msg1));
505: }
506:
507: public void testFloat() throws JMSException {
508:
509: msg.setFloat("float", (float) 1678.1234);
510: assertTrue(msg.itemExists("float"));
511: assertEquals(msg.getFloat("float"), (float) 1678.1234,
512: (float) 0.0001);
513: assertEquals(msg.getDouble("float"), 1678.1234, 0.0001);
514: assertEquals(msg.getString("float"), Float.valueOf("1678.1234")
515: .toString());
516: assertTrue(msg.getObject("float") instanceof Float);
517: assertEquals(((Float) msg.getObject("float")).floatValue(),
518: (float) 1678.1234, (float) 0.0001);
519:
520: msg.setObject("float", new Float((float) 1778.1234));
521: assertTrue(msg.getObject("float") instanceof Float);
522: assertEquals(((Float) msg.getObject("float")).floatValue(),
523: (float) 1778.1234, (float) 0.0001);
524:
525: try {
526: msg.getBoolean("float");
527: fail();
528: } catch (MessageFormatException ex) {
529: }
530: try {
531: msg.getByte("float");
532: fail();
533: } catch (MessageFormatException ex) {
534: }
535: try {
536: msg.getChar("float");
537: fail();
538: } catch (MessageFormatException ex) {
539: }
540: try {
541: msg.getShort("float");
542: fail();
543: } catch (MessageFormatException ex) {
544: }
545: try {
546: msg.getInt("float");
547: fail();
548: } catch (MessageFormatException ex) {
549: }
550: try {
551: msg.getLong("float");
552: fail();
553: } catch (MessageFormatException ex) {
554: }
555:
556: msg.setFloat("float", (float) 1677.1004);
557: assertEquals(msg.getFloat("float"), (float) 1677.1004,
558: (float) 0.0001);
559:
560: MapMessage msg1 = new MapMessageImpl(msg);
561: assertTrue(msg1.itemExists("float"));
562: assertEquals(msg1.getFloat("float"), (float) 1677.1004,
563: (float) 0.0001);
564:
565: checkMessageAttributes(msg1);
566: checkMessageAttributes();
567: assertTrue(MessageUtility.compare(msg, msg1));
568: }
569:
570: public void testDouble() throws JMSException {
571:
572: msg.setDouble("double", 9.989667788E304);
573: assertTrue(msg.itemExists("double"));
574: assertEquals(msg.getDouble("double"), 9.989667788E304,
575: 0.000000001E304);
576: assertEquals(msg.getString("double"), Double.valueOf(
577: "9.989667788E304").toString());
578: assertTrue(msg.getObject("double") instanceof Double);
579: assertEquals(((Double) msg.getObject("double")).doubleValue(),
580: 9.989667788E304, 0.000000001E304);
581:
582: msg.setObject("double", new Double(9.911111788E304));
583: assertTrue(msg.getObject("double") instanceof Double);
584: assertEquals(((Double) msg.getObject("double")).doubleValue(),
585: 9.911111788E304, 0.000000001E304);
586:
587: try {
588: msg.getBoolean("double");
589: fail();
590: } catch (MessageFormatException ex) {
591: }
592: try {
593: msg.getByte("double");
594: fail();
595: } catch (MessageFormatException ex) {
596: }
597: try {
598: msg.getChar("double");
599: fail();
600: } catch (MessageFormatException ex) {
601: }
602: try {
603: msg.getShort("double");
604: fail();
605: } catch (MessageFormatException ex) {
606: }
607: try {
608: msg.getInt("double");
609: fail();
610: } catch (MessageFormatException ex) {
611: }
612: try {
613: msg.getLong("double");
614: fail();
615: } catch (MessageFormatException ex) {
616: }
617: try {
618: msg.getFloat("double");
619: fail();
620: } catch (MessageFormatException ex) {
621: }
622:
623: msg.setDouble("double", -8.7654321E-303);
624: assertEquals(msg.getDouble("double"), -8.7654321E-303,
625: 0.0000001E-303);
626:
627: MapMessage msg1 = new MapMessageImpl(msg);
628: assertTrue(msg1.itemExists("double"));
629: assertEquals(msg1.getDouble("double"), -8.7654321E-303,
630: 0.0000001E-303);
631:
632: checkMessageAttributes(msg1);
633: checkMessageAttributes();
634: assertTrue(MessageUtility.compare(msg, msg1));
635: }
636:
637: public void testString() throws JMSException {
638:
639: msg.setString("string", "123");
640: assertTrue(msg.itemExists("string"));
641: assertEquals(msg.getString("string"), "123");
642: assertEquals(msg.getByte("string"), Byte.valueOf("123")
643: .byteValue());
644: assertTrue(msg.getObject("string") instanceof String);
645: assertEquals(msg.getObject("string").toString(), "123");
646:
647: msg.setObject("string", "124");
648: assertTrue(msg.getObject("string") instanceof String);
649: assertEquals(msg.getObject("string").toString(), "124");
650:
651: assertEquals(msg.getShort("string"), Short.valueOf("124")
652: .shortValue());
653:
654: assertEquals(msg.getInt("string"), Integer.valueOf("124")
655: .intValue());
656:
657: assertEquals(msg.getLong("string"), Long.valueOf("124")
658: .longValue());
659:
660: try {
661: msg.getChar("string");
662: fail();
663: } catch (MessageFormatException ex) {
664: }
665: msg.setString("string", "a");
666: try {
667: msg.getChar("string");
668: fail();
669: } catch (MessageFormatException ex) {
670: }
671:
672: msg.setString("string", "123.55");
673: assertEquals(msg.getFloat("string"), Float.valueOf("123.55")
674: .floatValue(), (float) 0.01);
675: assertEquals(msg.getDouble("string"), Double.valueOf("123.55")
676: .doubleValue(), 0.01);
677:
678: msg.setString("string", Boolean.valueOf("true").toString());
679: assertTrue(msg.getBoolean("string"));
680:
681: msg.setInt("string", -5555);
682: assertEquals(msg.getInt("string"), -5555);
683: assertEquals(msg.getString("string"), Integer.toString(-5555));
684:
685: msg.setString("null", null);
686: assertNull(msg.getObject("null"));
687: assertNull(msg.getString("null"));
688:
689: MapMessage msg1 = new MapMessageImpl(msg);
690: assertTrue(msg1.itemExists("string"));
691: assertEquals(msg1.getString("string"), Integer.toString(-5555));
692: assertTrue(msg1.itemExists("null"));
693: assertNull(msg1.getString("null"));
694:
695: checkMessageAttributes(msg1);
696: checkMessageAttributes();
697: assertTrue(MessageUtility.compare(msg, msg1));
698: }
699:
700: private void checkBytes(byte[] source, MapMessage msg, String name)
701: throws JMSException {
702:
703: assertTrue(msg.itemExists(name));
704:
705: Object o = msg.getObject(name);
706: byte[] bytesRead = msg.getBytes(name);
707:
708: assertNotNull(o);
709: assertNotNull(bytesRead);
710: assertTrue(o instanceof byte[]);
711: assertNotSame(source, o);
712: assertNotSame(source, bytesRead);
713: assertNotSame(bytesRead, o);
714: assertEquals(((byte[]) o).length, source.length);
715: assertEquals(bytesRead.length, source.length);
716:
717: for (int i = 0; i < source.length; i++) {
718: assertEquals(source[i], bytesRead[i]);
719: assertEquals(source[i], ((byte[]) o)[i]);
720: }
721: }
722:
723: public void testByteArray() throws JMSException {
724:
725: byte[] bytes1 = { 1, 0, 1, 0, 11, 127, -128, 11, 15 };
726:
727: msg.setBytes("bytes1", bytes1);
728: checkBytes(bytes1, msg, "bytes1");
729:
730: msg.setBytes("bytes2", bytes1, 2, 5);
731: byte[] bytes2 = { 1, 0, 11, 127, -128 };
732: checkBytes(bytes2, msg, "bytes2");
733:
734: try {
735: msg.getBoolean("bytes1");
736: fail();
737: } catch (MessageFormatException ex) {
738: }
739: try {
740: msg.getByte("bytes1");
741: fail();
742: } catch (MessageFormatException ex) {
743: }
744: try {
745: msg.getChar("bytes1");
746: fail();
747: } catch (MessageFormatException ex) {
748: }
749: try {
750: msg.getShort("bytes1");
751: fail();
752: } catch (MessageFormatException ex) {
753: }
754: try {
755: msg.getInt("bytes1");
756: fail();
757: } catch (MessageFormatException ex) {
758: }
759: try {
760: msg.getLong("bytes1");
761: fail();
762: } catch (MessageFormatException ex) {
763: }
764: try {
765: msg.getFloat("bytes1");
766: fail();
767: } catch (MessageFormatException ex) {
768: }
769: try {
770: msg.getDouble("bytes1");
771: fail();
772: } catch (MessageFormatException ex) {
773: }
774: try {
775: msg.getString("bytes1");
776: fail();
777: } catch (MessageFormatException ex) {
778: }
779:
780: msg.setBytes("b1", null);
781: assertNull(msg.getBytes("b1"));
782: assertNull(msg.getObject("b1"));
783:
784: try {
785: msg.setBytes("b1", null, 0, 1);
786: fail();
787: } catch (IllegalArgumentException ex) {
788: }
789: try {
790: msg.setBytes("b1", new byte[5], -1, 5);
791: fail();
792: } catch (IllegalArgumentException ex) {
793: }
794: try {
795: msg.setBytes("b1", new byte[5], 1, -5);
796: fail();
797: } catch (IllegalArgumentException ex) {
798: }
799: try {
800: msg.setBytes("b1", new byte[5], 2, 5);
801: fail();
802: } catch (IllegalArgumentException ex) {
803: }
804:
805: MapMessage msg1 = new MapMessageImpl(msg);
806:
807: checkBytes(bytes1, msg1, "bytes1");
808: checkBytes(bytes2, msg1, "bytes2");
809: assertTrue(msg1.itemExists("b1"));
810: assertNull(msg1.getBytes("b1"));
811: assertNull(msg1.getObject("b1"));
812:
813: checkMessageAttributes(msg1);
814: checkMessageAttributes();
815: assertTrue(MessageUtility.compare(msg, msg1));
816: }
817:
818: }
|