0001: package org.mockejb.jms.test;
0002:
0003: import javax.jms.*;
0004:
0005: import org.mockejb.jms.StreamMessageImpl;
0006:
0007: /**
0008: * @author dgospodinov
0009: *
0010: * To change the template for this generated type comment go to
0011: * Window>Preferences>Java>Code Generation>Code and Comments
0012: * org.mockejb.jms
0013: */
0014: public class StreamMessageImplTester extends MessageTester {
0015:
0016: private StreamMessage msg;
0017:
0018: public StreamMessageImplTester(String name) {
0019: super (name);
0020: }
0021:
0022: protected void setUp() throws Exception {
0023: msg = new StreamMessageImpl();
0024: message = msg;
0025: super .setUp();
0026: }
0027:
0028: protected void tearDown() throws Exception {
0029: msg = null;
0030: }
0031:
0032: public void testMessageNotReadable() throws JMSException {
0033:
0034: try {
0035: msg.readBoolean();
0036: fail();
0037: } catch (MessageNotReadableException ex) {
0038: }
0039: try {
0040: msg.readByte();
0041: fail();
0042: } catch (MessageNotReadableException ex) {
0043: }
0044: try {
0045: msg.readBytes(new byte[5]);
0046: fail();
0047: } catch (MessageNotReadableException ex) {
0048: }
0049: try {
0050: msg.readChar();
0051: fail();
0052: } catch (MessageNotReadableException ex) {
0053: }
0054: try {
0055: msg.readDouble();
0056: fail();
0057: } catch (MessageNotReadableException ex) {
0058: }
0059: try {
0060: msg.readFloat();
0061: fail();
0062: } catch (MessageNotReadableException ex) {
0063: }
0064: try {
0065: msg.readInt();
0066: fail();
0067: } catch (MessageNotReadableException ex) {
0068: }
0069: try {
0070: msg.readLong();
0071: fail();
0072: } catch (MessageNotReadableException ex) {
0073: }
0074: try {
0075: msg.readShort();
0076: fail();
0077: } catch (MessageNotReadableException ex) {
0078: }
0079: try {
0080: msg.readString();
0081: fail();
0082: } catch (MessageNotReadableException ex) {
0083: }
0084: try {
0085: msg.readObject();
0086: fail();
0087: } catch (MessageNotReadableException ex) {
0088: }
0089: checkMessageAttributes();
0090: }
0091:
0092: public void testMessageNotWritable() throws JMSException {
0093:
0094: msg.reset();
0095:
0096: try {
0097: msg.writeBoolean(true);
0098: fail();
0099: } catch (MessageNotWriteableException ex) {
0100: }
0101: try {
0102: msg.writeByte((byte) 1);
0103: fail();
0104: } catch (MessageNotWriteableException ex) {
0105: }
0106: try {
0107: msg.writeBytes(new byte[5]);
0108: fail();
0109: } catch (MessageNotWriteableException ex) {
0110: }
0111: try {
0112: msg.writeBytes(new byte[5], 0, 1);
0113: fail();
0114: } catch (MessageNotWriteableException ex) {
0115: }
0116: try {
0117: msg.writeChar('a');
0118: fail();
0119: } catch (MessageNotWriteableException ex) {
0120: }
0121: try {
0122: msg.writeDouble(123.33);
0123: fail();
0124: } catch (MessageNotWriteableException ex) {
0125: }
0126: try {
0127: msg.writeFloat((float) 22.22);
0128: fail();
0129: } catch (MessageNotWriteableException ex) {
0130: }
0131: try {
0132: msg.writeInt(122);
0133: fail();
0134: } catch (MessageNotWriteableException ex) {
0135: }
0136: try {
0137: msg.writeLong(11);
0138: fail();
0139: } catch (MessageNotWriteableException ex) {
0140: }
0141: try {
0142: msg.writeShort((short) 88);
0143: fail();
0144: } catch (MessageNotWriteableException ex) {
0145: }
0146: try {
0147: msg.writeObject(null);
0148: fail();
0149: } catch (MessageNotWriteableException ex) {
0150: }
0151: try {
0152: msg.writeString("string");
0153: fail();
0154: } catch (MessageNotWriteableException ex) {
0155: }
0156: checkMessageAttributes();
0157: }
0158:
0159: private void checkTestStreamMessage(StreamMessage msg)
0160: throws JMSException {
0161: byte[] bytesData = new byte[4];
0162: assertTrue(msg.readBoolean());
0163: assertEquals(msg.readBytes(new byte[1]), -1);
0164: assertNull(msg.readObject());
0165: assertEquals(msg.readByte(), (byte) 255);
0166:
0167: assertEquals(msg.readBytes(bytesData), 4);
0168: assertEquals(bytesData[0], (byte) 1);
0169: assertEquals(bytesData[1], (byte) 2);
0170: assertEquals(bytesData[2], (byte) 3);
0171: assertEquals(bytesData[3], (byte) 4);
0172: assertEquals(msg.readBytes(bytesData), -1);
0173: assertEquals(msg.readBytes(bytesData), 1);
0174: assertEquals(bytesData[0], (byte) 2);
0175: assertEquals(msg.readBytes(bytesData), -1);
0176:
0177: assertEquals(msg.readChar(), 'a');
0178: assertEquals(msg.readDouble(), 1.77E307, 0.01E307);
0179: assertEquals(msg.readFloat(), (float) 44.9991, (float) 0.0001);
0180: assertEquals(msg.readInt(), 65536);
0181: assertEquals(msg.readLong(), 9999222233338888L);
0182: assertEquals(msg.readShort(), (short) 32000);
0183: assertEquals(msg.readString(), "String 1");
0184: assertEquals(msg.readString(), "String 2");
0185:
0186: /*
0187: * At this point all bytes from msg have been read. Any read must throw EOF
0188: * exception.
0189: */
0190: try {
0191: msg.readBoolean();
0192: fail();
0193: } catch (MessageEOFException ex) {
0194: }
0195: try {
0196: msg.readByte();
0197: fail();
0198: } catch (MessageEOFException ex) {
0199: }
0200: try {
0201: msg.readBytes(new byte[1]);
0202: fail();
0203: } catch (MessageEOFException ex) {
0204: }
0205: try {
0206: msg.readChar();
0207: fail();
0208: } catch (MessageEOFException ex) {
0209: }
0210: try {
0211: msg.readShort();
0212: fail();
0213: } catch (MessageEOFException ex) {
0214: }
0215: try {
0216: msg.readInt();
0217: fail();
0218: } catch (MessageEOFException ex) {
0219: }
0220: try {
0221: msg.readLong();
0222: fail();
0223: } catch (MessageEOFException ex) {
0224: }
0225: try {
0226: msg.readFloat();
0227: fail();
0228: } catch (MessageEOFException ex) {
0229: }
0230: try {
0231: msg.readDouble();
0232: fail();
0233: } catch (MessageEOFException ex) {
0234: }
0235: try {
0236: msg.readObject();
0237: fail();
0238: } catch (MessageEOFException ex) {
0239: }
0240: try {
0241: msg.readString();
0242: fail();
0243: } catch (MessageEOFException ex) {
0244: }
0245: }
0246:
0247: public void testStreamMessage() throws Throwable {
0248:
0249: byte[] bytesData1 = { 1, 2, 3, 4 };
0250:
0251: // Write to BytesMessage and DataOutputStream and then compare
0252:
0253: msg.writeBoolean(true);
0254: msg.writeBytes(null);
0255: msg.writeObject(null);
0256: msg.writeByte((byte) 255);
0257: msg.writeBytes(bytesData1);
0258: msg.writeBytes(bytesData1, 1, 1);
0259: msg.writeChar('a');
0260: msg.writeDouble(1.77E307);
0261: msg.writeFloat((float) 44.9991);
0262: msg.writeInt(65536);
0263: msg.writeLong(9999222233338888L);
0264: msg.writeShort((short) 32000);
0265: msg.writeString("String 1");
0266: msg.writeString("String 2");
0267:
0268: int repetitions = 2;
0269: while (repetitions-- > 0) {
0270: msg.reset();
0271: checkTestStreamMessage(msg);
0272: }
0273: msg.reset();
0274:
0275: StreamMessage msg1 = new StreamMessageImpl(msg);
0276: msg1.reset();
0277: checkTestStreamMessage(msg1);
0278:
0279: checkMessageAttributes(msg1);
0280: checkMessageAttributes();
0281: }
0282:
0283: public void testBoolean() throws JMSException {
0284:
0285: msg.writeBoolean(true);
0286: try {
0287: msg.readBoolean();
0288: fail();
0289: } catch (MessageNotReadableException ex) {
0290: }
0291: msg.reset();
0292: assertTrue(msg.readBoolean());
0293: msg.reset();
0294: assertEquals(msg.readString(), "true");
0295: msg.reset();
0296: Object o = msg.readObject();
0297: assertTrue(o instanceof Boolean);
0298: assertTrue(((Boolean) o).booleanValue());
0299:
0300: try {
0301: msg.readBoolean();
0302: fail();
0303: } catch (MessageEOFException ex) {
0304: }
0305:
0306: msg.reset();
0307: try {
0308: msg.readChar();
0309: fail();
0310: } catch (MessageFormatException ex) {
0311: }
0312: try {
0313: msg.readByte();
0314: fail();
0315: } catch (MessageFormatException ex) {
0316: }
0317: try {
0318: msg.readShort();
0319: fail();
0320: } catch (MessageFormatException ex) {
0321: }
0322: try {
0323: msg.readInt();
0324: fail();
0325: } catch (MessageFormatException ex) {
0326: }
0327: try {
0328: msg.readLong();
0329: fail();
0330: } catch (MessageFormatException ex) {
0331: }
0332: try {
0333: msg.readFloat();
0334: fail();
0335: } catch (MessageFormatException ex) {
0336: }
0337: try {
0338: msg.readDouble();
0339: fail();
0340: } catch (MessageFormatException ex) {
0341: }
0342: try {
0343: msg.readBytes(new byte[1]);
0344: fail();
0345: } catch (MessageFormatException ex) {
0346: }
0347:
0348: checkMessageAttributes();
0349: }
0350:
0351: public void testByte() throws JMSException {
0352:
0353: msg.writeByte((byte) 127);
0354: try {
0355: msg.readByte();
0356: fail();
0357: } catch (MessageNotReadableException ex) {
0358: }
0359: msg.reset();
0360: assertEquals(msg.readByte(), (byte) 127);
0361: msg.reset();
0362: assertEquals(msg.readShort(), (short) 127);
0363: msg.reset();
0364: assertEquals(msg.readInt(), 127);
0365: msg.reset();
0366: assertEquals(msg.readLong(), 127L);
0367: msg.reset();
0368: assertEquals(msg.readString(), Byte.valueOf("127").toString());
0369: msg.reset();
0370: Object o = msg.readObject();
0371: assertTrue(o instanceof Byte);
0372: assertEquals(((Byte) o).byteValue(), (byte) 127);
0373:
0374: try {
0375: msg.readByte();
0376: fail();
0377: } catch (MessageEOFException ex) {
0378: }
0379:
0380: msg.reset();
0381: try {
0382: msg.readBoolean();
0383: fail();
0384: } catch (MessageFormatException ex) {
0385: }
0386: try {
0387: msg.readChar();
0388: fail();
0389: } catch (MessageFormatException ex) {
0390: }
0391: try {
0392: msg.readFloat();
0393: fail();
0394: } catch (MessageFormatException ex) {
0395: }
0396: try {
0397: msg.readDouble();
0398: fail();
0399: } catch (MessageFormatException ex) {
0400: }
0401: try {
0402: msg.readBytes(new byte[1]);
0403: fail();
0404: } catch (MessageFormatException ex) {
0405: }
0406: checkMessageAttributes();
0407: }
0408:
0409: public void testChar() throws JMSException {
0410:
0411: msg.writeChar('e');
0412: try {
0413: msg.readChar();
0414: fail();
0415: } catch (MessageNotReadableException ex) {
0416: }
0417: msg.reset();
0418: assertEquals(msg.readChar(), 'e');
0419: msg.reset();
0420: assertEquals(msg.readString(), "e");
0421: msg.reset();
0422: Object o = msg.readObject();
0423: assertTrue(o instanceof Character);
0424: assertEquals(((Character) o).charValue(), 'e');
0425:
0426: try {
0427: msg.readChar();
0428: fail();
0429: } catch (MessageEOFException ex) {
0430: }
0431:
0432: msg.reset();
0433: try {
0434: msg.readBoolean();
0435: fail();
0436: } catch (MessageFormatException ex) {
0437: }
0438: try {
0439: msg.readByte();
0440: fail();
0441: } catch (MessageFormatException ex) {
0442: }
0443: try {
0444: msg.readShort();
0445: fail();
0446: } catch (MessageFormatException ex) {
0447: }
0448: try {
0449: msg.readInt();
0450: fail();
0451: } catch (MessageFormatException ex) {
0452: }
0453: try {
0454: msg.readLong();
0455: fail();
0456: } catch (MessageFormatException ex) {
0457: }
0458: try {
0459: msg.readFloat();
0460: fail();
0461: } catch (MessageFormatException ex) {
0462: }
0463: try {
0464: msg.readDouble();
0465: fail();
0466: } catch (MessageFormatException ex) {
0467: }
0468: try {
0469: msg.readBytes(new byte[1]);
0470: fail();
0471: } catch (MessageFormatException ex) {
0472: }
0473:
0474: checkMessageAttributes();
0475: }
0476:
0477: public void testShort() throws JMSException {
0478:
0479: msg.writeShort((short) 29000);
0480: try {
0481: msg.readShort();
0482: fail();
0483: } catch (MessageNotReadableException ex) {
0484: }
0485: msg.reset();
0486: assertEquals(msg.readShort(), (short) 29000);
0487: msg.reset();
0488: assertEquals(msg.readInt(), 29000);
0489: msg.reset();
0490: assertEquals(msg.readLong(), 29000L);
0491: msg.reset();
0492: assertEquals(msg.readString(), Short.valueOf("29000")
0493: .toString());
0494: msg.reset();
0495: Object o = msg.readObject();
0496: assertTrue(o instanceof Short);
0497: assertEquals(((Short) o).shortValue(), (short) 29000);
0498:
0499: try {
0500: msg.readShort();
0501: fail();
0502: } catch (MessageEOFException ex) {
0503: }
0504:
0505: msg.reset();
0506: try {
0507: msg.readBoolean();
0508: fail();
0509: } catch (MessageFormatException ex) {
0510: }
0511: try {
0512: msg.readByte();
0513: fail();
0514: } catch (MessageFormatException ex) {
0515: }
0516: try {
0517: msg.readChar();
0518: fail();
0519: } catch (MessageFormatException ex) {
0520: }
0521: try {
0522: msg.readFloat();
0523: fail();
0524: } catch (MessageFormatException ex) {
0525: }
0526: try {
0527: msg.readDouble();
0528: fail();
0529: } catch (MessageFormatException ex) {
0530: }
0531: try {
0532: msg.readBytes(new byte[1]);
0533: fail();
0534: } catch (MessageFormatException ex) {
0535: }
0536:
0537: checkMessageAttributes();
0538: }
0539:
0540: public void testInt() throws JMSException {
0541:
0542: msg.writeInt(120000);
0543: try {
0544: msg.readInt();
0545: fail();
0546: } catch (MessageNotReadableException ex) {
0547: }
0548: msg.reset();
0549: assertEquals(msg.readInt(), 120000);
0550: msg.reset();
0551: assertEquals(msg.readLong(), 120000L);
0552: msg.reset();
0553: assertEquals(msg.readString(), Integer.valueOf("120000")
0554: .toString());
0555: msg.reset();
0556: Object o = msg.readObject();
0557: assertTrue(o instanceof Integer);
0558: assertEquals(((Integer) o).intValue(), 120000);
0559:
0560: try {
0561: msg.readInt();
0562: fail();
0563: } catch (MessageEOFException ex) {
0564: }
0565: msg.reset();
0566: try {
0567: msg.readBoolean();
0568: fail();
0569: } catch (MessageFormatException ex) {
0570: }
0571: try {
0572: msg.readByte();
0573: fail();
0574: } catch (MessageFormatException ex) {
0575: }
0576: try {
0577: msg.readChar();
0578: fail();
0579: } catch (MessageFormatException ex) {
0580: }
0581: try {
0582: msg.readShort();
0583: fail();
0584: } catch (MessageFormatException ex) {
0585: }
0586: try {
0587: msg.readFloat();
0588: fail();
0589: } catch (MessageFormatException ex) {
0590: }
0591: try {
0592: msg.readDouble();
0593: fail();
0594: } catch (MessageFormatException ex) {
0595: }
0596: try {
0597: msg.readBytes(new byte[1]);
0598: fail();
0599: } catch (MessageFormatException ex) {
0600: }
0601:
0602: checkMessageAttributes();
0603: }
0604:
0605: public void testLong() throws JMSException {
0606:
0607: msg.writeLong(222200002222L);
0608: try {
0609: msg.readLong();
0610: fail();
0611: } catch (MessageNotReadableException ex) {
0612: }
0613: msg.reset();
0614: assertEquals(msg.readLong(), 222200002222L);
0615: msg.reset();
0616: assertEquals(msg.readString(), Long.valueOf("222200002222")
0617: .toString());
0618: msg.reset();
0619: Object o = msg.readObject();
0620: assertTrue(o instanceof Long);
0621: assertEquals(((Long) o).longValue(), 222200002222L);
0622:
0623: try {
0624: msg.readLong();
0625: fail();
0626: } catch (MessageEOFException ex) {
0627: }
0628:
0629: msg.reset();
0630: try {
0631: msg.readBoolean();
0632: fail();
0633: } catch (MessageFormatException ex) {
0634: }
0635: try {
0636: msg.readByte();
0637: fail();
0638: } catch (MessageFormatException ex) {
0639: }
0640: try {
0641: msg.readChar();
0642: fail();
0643: } catch (MessageFormatException ex) {
0644: }
0645: try {
0646: msg.readShort();
0647: fail();
0648: } catch (MessageFormatException ex) {
0649: }
0650: try {
0651: msg.readInt();
0652: fail();
0653: } catch (MessageFormatException ex) {
0654: }
0655: try {
0656: msg.readFloat();
0657: fail();
0658: } catch (MessageFormatException ex) {
0659: }
0660: try {
0661: msg.readDouble();
0662: fail();
0663: } catch (MessageFormatException ex) {
0664: }
0665: try {
0666: msg.readBytes(new byte[1]);
0667: fail();
0668: } catch (MessageFormatException ex) {
0669: }
0670:
0671: checkMessageAttributes();
0672: }
0673:
0674: public void testFloat() throws JMSException {
0675:
0676: msg.writeFloat((float) 1678.1234);
0677: try {
0678: msg.readFloat();
0679: fail();
0680: } catch (MessageNotReadableException ex) {
0681: }
0682: msg.reset();
0683: assertEquals(msg.readFloat(), (float) 1678.1234, (float) 0.0001);
0684: msg.reset();
0685: assertEquals(msg.readDouble(), 1678.1234, 0.0001);
0686: msg.reset();
0687: assertEquals(msg.readString(), Float.valueOf("1678.1234")
0688: .toString());
0689: msg.reset();
0690: Object o = msg.readObject();
0691: assertTrue(o instanceof Float);
0692: assertEquals(((Float) o).floatValue(), (float) 1678.1234,
0693: (float) 0.0001);
0694:
0695: try {
0696: msg.readFloat();
0697: fail();
0698: } catch (MessageEOFException ex) {
0699: }
0700:
0701: msg.reset();
0702: try {
0703: msg.readBoolean();
0704: fail();
0705: } catch (MessageFormatException ex) {
0706: }
0707: try {
0708: msg.readByte();
0709: fail();
0710: } catch (MessageFormatException ex) {
0711: }
0712: try {
0713: msg.readChar();
0714: fail();
0715: } catch (MessageFormatException ex) {
0716: }
0717: try {
0718: msg.readShort();
0719: fail();
0720: } catch (MessageFormatException ex) {
0721: }
0722: try {
0723: msg.readInt();
0724: fail();
0725: } catch (MessageFormatException ex) {
0726: }
0727: try {
0728: msg.readLong();
0729: fail();
0730: } catch (MessageFormatException ex) {
0731: }
0732: try {
0733: msg.readBytes(new byte[1]);
0734: fail();
0735: } catch (MessageFormatException ex) {
0736: }
0737: checkMessageAttributes();
0738: }
0739:
0740: public void testDouble() throws JMSException {
0741:
0742: msg.writeDouble(9.989667788E304);
0743: try {
0744: msg.readDouble();
0745: fail();
0746: } catch (MessageNotReadableException ex) {
0747: }
0748: msg.reset();
0749: assertEquals(msg.readDouble(), 9.989667788E304, 0.000000001E304);
0750: msg.reset();
0751: assertEquals(msg.readString(), Double
0752: .valueOf("9.989667788E304").toString());
0753: msg.reset();
0754: Object o = msg.readObject();
0755: assertTrue(o instanceof Double);
0756: assertEquals(((Double) o).doubleValue(), 9.989667788E304,
0757: 0.000000001E304);
0758:
0759: try {
0760: msg.readDouble();
0761: fail();
0762: } catch (MessageEOFException ex) {
0763: }
0764: msg.reset();
0765: try {
0766: msg.readBoolean();
0767: fail();
0768: } catch (MessageFormatException ex) {
0769: }
0770: try {
0771: msg.readByte();
0772: fail();
0773: } catch (MessageFormatException ex) {
0774: }
0775: try {
0776: msg.readChar();
0777: fail();
0778: } catch (MessageFormatException ex) {
0779: }
0780: try {
0781: msg.readShort();
0782: fail();
0783: } catch (MessageFormatException ex) {
0784: }
0785: try {
0786: msg.readInt();
0787: fail();
0788: } catch (MessageFormatException ex) {
0789: }
0790: try {
0791: msg.readLong();
0792: fail();
0793: } catch (MessageFormatException ex) {
0794: }
0795: try {
0796: msg.readFloat();
0797: fail();
0798: } catch (MessageFormatException ex) {
0799: }
0800: try {
0801: msg.readBytes(new byte[1]);
0802: fail();
0803: } catch (MessageFormatException ex) {
0804: }
0805:
0806: checkMessageAttributes();
0807: }
0808:
0809: public void testString() throws JMSException {
0810:
0811: msg.writeString("123");
0812: try {
0813: msg.readString();
0814: fail();
0815: } catch (MessageNotReadableException ex) {
0816: }
0817: msg.reset();
0818: assertEquals(msg.readString(), "123");
0819: msg.reset();
0820: assertEquals(msg.readByte(), Byte.valueOf("123").byteValue());
0821: msg.reset();
0822: Object o = msg.readObject();
0823: assertTrue(o instanceof String);
0824: assertEquals(o.toString(), "123");
0825:
0826: try {
0827: msg.readString();
0828: fail();
0829: } catch (MessageEOFException ex) {
0830: }
0831:
0832: msg.clearBody();
0833:
0834: msg.writeObject("124");
0835: msg.reset();
0836: o = msg.readObject();
0837: assertTrue(o instanceof String);
0838: assertEquals(o.toString(), "124");
0839: msg.reset();
0840: assertEquals(msg.readShort(), Short.valueOf("124").shortValue());
0841: msg.reset();
0842: assertEquals(msg.readInt(), Integer.valueOf("124").intValue());
0843: msg.reset();
0844: assertEquals(msg.readLong(), Long.valueOf("124").longValue());
0845: msg.reset();
0846: try {
0847: msg.readChar();
0848: fail();
0849: } catch (MessageFormatException ex) {
0850: }
0851: msg.clearBody();
0852: msg.writeString("a");
0853: msg.reset();
0854: try {
0855: msg.readChar();
0856: fail();
0857: } catch (MessageFormatException ex) {
0858: }
0859: try {
0860: msg.readBytes(new byte[1]);
0861: fail();
0862: } catch (MessageFormatException ex) {
0863: }
0864: msg.clearBody();
0865: msg.writeString("123.55");
0866: msg.reset();
0867: assertEquals(msg.readFloat(), Float.valueOf("123.55")
0868: .floatValue(), (float) 0.01);
0869: msg.reset();
0870: assertEquals(msg.readDouble(), Double.valueOf("123.55")
0871: .doubleValue(), 0.01);
0872:
0873: msg.clearBody();
0874: msg.writeString(Boolean.valueOf("true").toString());
0875: msg.reset();
0876: assertTrue(msg.readBoolean());
0877:
0878: msg.clearBody();
0879: msg.writeString(null);
0880: msg.reset();
0881: assertNull(msg.readObject());
0882: msg.reset();
0883: assertNull(msg.readString());
0884:
0885: checkMessageAttributes();
0886: }
0887:
0888: public void testObject() throws JMSException {
0889: try {
0890: msg.writeObject(new Object());
0891: fail();
0892: } catch (MessageFormatException ex) {
0893: }
0894: msg.writeObject(null);
0895: try {
0896: msg.readObject();
0897: fail();
0898: } catch (MessageNotReadableException ex) {
0899: }
0900: msg.writeObject(new Boolean(false));
0901: msg.writeObject(new Byte((byte) 101));
0902: msg.writeObject(new byte[] { 11, 22, 33 });
0903: msg.writeObject(new Character('t'));
0904: msg.writeObject(new Short((short) 29999));
0905: msg.writeObject(new Integer(65537));
0906: msg.writeObject(new Long(888880000011111L));
0907: msg.writeObject(new Float((float) 7788.001));
0908: msg.writeObject(new Double(-1.889911001E-301));
0909: msg.writeObject(new String("String"));
0910:
0911: msg.reset();
0912:
0913: try {
0914: msg.writeObject(null);
0915: fail();
0916: } catch (MessageNotWriteableException ex) {
0917: }
0918: assertNull(msg.readObject());
0919: Object o = msg.readObject();
0920: assertTrue(o instanceof Boolean);
0921: assertFalse(((Boolean) o).booleanValue());
0922: o = msg.readObject();
0923: assertTrue(o instanceof Byte);
0924: assertEquals(((Byte) o).byteValue(), (byte) 101);
0925: o = msg.readObject();
0926: assertTrue(o instanceof byte[]);
0927: assertEquals(((byte[]) o).length, 3);
0928: assertEquals(((byte[]) o)[0], (byte) 11);
0929: assertEquals(((byte[]) o)[1], (byte) 22);
0930: assertEquals(((byte[]) o)[2], (byte) 33);
0931: o = msg.readObject();
0932: assertTrue(o instanceof Character);
0933: assertEquals(((Character) o).charValue(), 't');
0934: o = msg.readObject();
0935: assertTrue(o instanceof Short);
0936: assertEquals(((Short) o).shortValue(), (short) 29999);
0937: o = msg.readObject();
0938: assertTrue(o instanceof Integer);
0939: assertEquals(((Integer) o).intValue(), 65537);
0940: o = msg.readObject();
0941: assertTrue(o instanceof Long);
0942: assertEquals(((Long) o).longValue(), 888880000011111L);
0943: o = msg.readObject();
0944: assertTrue(o instanceof Float);
0945: assertEquals(((Float) o).floatValue(), (float) 7788.001,
0946: (float) 0.001);
0947: o = msg.readObject();
0948: assertTrue(o instanceof Double);
0949: assertEquals(((Double) o).doubleValue(), -1.889911001E-301,
0950: 0.000000001E-301);
0951: o = msg.readObject();
0952: assertTrue(o instanceof String);
0953: assertEquals(o, "String");
0954:
0955: checkMessageAttributes();
0956: }
0957:
0958: public void testByteArray() throws JMSException {
0959:
0960: byte[] bytes1 = { 1, 0, 1, 0, 11, 127, -128, 11, 15 };
0961:
0962: msg.writeBytes(bytes1);
0963: msg.writeBytes(bytes1, 2, 5);
0964: for (int i = 0; i < bytes1.length; bytes1[i++] = 0)
0965: ;
0966:
0967: try {
0968: msg.readBytes(new byte[1]);
0969: fail();
0970: } catch (MessageNotReadableException ex) {
0971: }
0972: try {
0973: msg.writeBytes(bytes1, -1, 1);
0974: fail();
0975: } catch (IllegalArgumentException ex) {
0976: }
0977: try {
0978: msg.writeBytes(bytes1, 1, -1);
0979: fail();
0980: } catch (IllegalArgumentException ex) {
0981: }
0982: try {
0983: msg.writeBytes(bytes1, 1, 111);
0984: fail();
0985: } catch (IllegalArgumentException ex) {
0986: }
0987:
0988: msg.writeBytes(null);
0989: msg.writeBytes(null, 0, 0);
0990: msg.reset();
0991:
0992: bytes1 = new byte[6];
0993: assertEquals(msg.readBytes(bytes1), 6);
0994: assertEquals(bytes1[0], (byte) 1);
0995: assertEquals(bytes1[1], (byte) 0);
0996: assertEquals(bytes1[2], (byte) 1);
0997: assertEquals(bytes1[3], (byte) 0);
0998: assertEquals(bytes1[4], (byte) 11);
0999: assertEquals(bytes1[5], (byte) 127);
1000: assertEquals(msg.readBytes(bytes1), 3);
1001: assertEquals(bytes1[0], (byte) -128);
1002: assertEquals(bytes1[1], (byte) 11);
1003: assertEquals(bytes1[2], (byte) 15);
1004: assertEquals(bytes1[3], (byte) 0);
1005: assertEquals(bytes1[4], (byte) 11);
1006: assertEquals(bytes1[5], (byte) 127);
1007: assertEquals(msg.readBytes(bytes1), -1);
1008: assertEquals(bytes1[0], (byte) -128);
1009: assertEquals(bytes1[1], (byte) 11);
1010: assertEquals(bytes1[2], (byte) 15);
1011: assertEquals(bytes1[3], (byte) 0);
1012: assertEquals(bytes1[4], (byte) 11);
1013: assertEquals(bytes1[5], (byte) 127);
1014:
1015: assertEquals(msg.readBytes(bytes1), 5);
1016: assertEquals(bytes1[0], (byte) 1);
1017: assertEquals(bytes1[1], (byte) 0);
1018: assertEquals(bytes1[2], (byte) 11);
1019: assertEquals(bytes1[3], (byte) 127);
1020: assertEquals(bytes1[4], (byte) -128);
1021: assertEquals(bytes1[5], (byte) 127);
1022: assertEquals(msg.readBytes(bytes1), -1);
1023: assertEquals(bytes1[0], (byte) 1);
1024: assertEquals(bytes1[1], (byte) 0);
1025: assertEquals(bytes1[2], (byte) 11);
1026: assertEquals(bytes1[3], (byte) 127);
1027: assertEquals(bytes1[4], (byte) -128);
1028: assertEquals(bytes1[5], (byte) 127);
1029:
1030: // Read two null values and check that the bytes array is not modified
1031: assertEquals(msg.readBytes(bytes1), -1);
1032: assertEquals(bytes1[0], (byte) 1);
1033: assertEquals(bytes1[1], (byte) 0);
1034: assertEquals(bytes1[2], (byte) 11);
1035: assertEquals(bytes1[3], (byte) 127);
1036: assertEquals(bytes1[4], (byte) -128);
1037: assertEquals(bytes1[5], (byte) 127);
1038:
1039: assertEquals(msg.readBytes(bytes1), -1);
1040: assertEquals(bytes1[0], (byte) 1);
1041: assertEquals(bytes1[1], (byte) 0);
1042: assertEquals(bytes1[2], (byte) 11);
1043: assertEquals(bytes1[3], (byte) 127);
1044: assertEquals(bytes1[4], (byte) -128);
1045: assertEquals(bytes1[5], (byte) 127);
1046:
1047: try {
1048: msg.readObject();
1049: fail();
1050: } catch (MessageEOFException ex) {
1051: }
1052:
1053: msg.reset();
1054:
1055: try {
1056: msg.readBoolean();
1057: fail();
1058: } catch (MessageFormatException ex) {
1059: }
1060: try {
1061: msg.readByte();
1062: fail();
1063: } catch (MessageFormatException ex) {
1064: }
1065: try {
1066: msg.readChar();
1067: fail();
1068: } catch (MessageFormatException ex) {
1069: }
1070: try {
1071: msg.readShort();
1072: fail();
1073: } catch (MessageFormatException ex) {
1074: }
1075: try {
1076: msg.readInt();
1077: fail();
1078: } catch (MessageFormatException ex) {
1079: }
1080: try {
1081: msg.readLong();
1082: fail();
1083: } catch (MessageFormatException ex) {
1084: }
1085: try {
1086: msg.readFloat();
1087: fail();
1088: } catch (MessageFormatException ex) {
1089: }
1090: try {
1091: msg.readDouble();
1092: fail();
1093: } catch (MessageFormatException ex) {
1094: }
1095: try {
1096: msg.readString();
1097: fail();
1098: } catch (MessageFormatException ex) {
1099: }
1100: checkMessageAttributes();
1101: }
1102:
1103: public void testClone() throws JMSException {
1104:
1105: msg.writeByte((byte) 253);
1106: msg.writeBytes(new byte[] { 55, 66, 77 });
1107: msg.writeString("string");
1108:
1109: StreamMessage msg1 = new StreamMessageImpl(msg);
1110:
1111: try {
1112: msg.readObject();
1113: fail();
1114: } catch (MessageNotReadableException ex) {
1115: }
1116: try {
1117: msg1.readObject();
1118: fail();
1119: } catch (MessageNotReadableException ex) {
1120: }
1121:
1122: msg.writeChar('u');
1123: msg1.writeChar('x');
1124:
1125: msg.reset();
1126: assertEquals(msg.readByte(), (byte) 253);
1127: byte[] bytes = new byte[3];
1128: assertEquals(msg.readBytes(bytes), 3);
1129: assertEquals(msg.readBytes(bytes), -1);
1130: assertEquals(bytes[0], (byte) 55);
1131: assertEquals(bytes[1], (byte) 66);
1132: assertEquals(bytes[2], (byte) 77);
1133: assertEquals(msg.readString(), "string");
1134: assertEquals(msg.readChar(), 'u');
1135: try {
1136: msg.readObject();
1137: fail();
1138: } catch (MessageEOFException ex) {
1139: }
1140:
1141: msg1.reset();
1142: assertEquals(msg1.readByte(), (byte) 253);
1143: bytes = new byte[3];
1144: assertEquals(msg1.readBytes(bytes), 3);
1145: assertEquals(msg1.readBytes(bytes), -1);
1146: assertEquals(bytes[0], (byte) 55);
1147: assertEquals(bytes[1], (byte) 66);
1148: assertEquals(bytes[2], (byte) 77);
1149: assertEquals(msg1.readString(), "string");
1150: assertEquals(msg1.readChar(), 'x');
1151: try {
1152: msg1.readObject();
1153: fail();
1154: } catch (MessageEOFException ex) {
1155: }
1156:
1157: msg.reset();
1158: msg.readObject();
1159: msg.readObject();
1160: msg1 = new StreamMessageImpl(msg);
1161:
1162: assertEquals(msg.readString(), "string");
1163: assertEquals(msg.readChar(), 'u');
1164: try {
1165: msg.readObject();
1166: fail();
1167: } catch (MessageEOFException ex) {
1168: }
1169:
1170: msg1.writeChar('f');
1171: msg1.reset();
1172:
1173: checkMessageAttributes(msg1);
1174:
1175: assertEquals(msg1.readByte(), (byte) 253);
1176: bytes = new byte[3];
1177: assertEquals(msg1.readBytes(bytes), 3);
1178: assertEquals(msg1.readBytes(bytes), -1);
1179: assertEquals(bytes[0], (byte) 55);
1180: assertEquals(bytes[1], (byte) 66);
1181: assertEquals(bytes[2], (byte) 77);
1182: assertEquals(msg1.readString(), "string");
1183: assertEquals(msg1.readChar(), 'u');
1184: assertEquals(msg1.readChar(), 'f');
1185: try {
1186: msg1.readObject();
1187: fail();
1188: } catch (MessageEOFException ex) {
1189: }
1190:
1191: checkMessageAttributes(msg1);
1192: checkMessageAttributes();
1193: }
1194:
1195: }
|