@Test public void testWriteObjectWithShort() throws Exception { doWriteObjectWithType(RandomUtil.randomShort(), new TypeReader() { @Override public Object readType(final ActiveMQStreamMessage message) throws Exception { return message.readShort(); } }); }
@Test public void testSetObjectFromShort() throws Exception { doTestSetObject(RandomUtil.randomShort()); }
@Test public void testGetShortFromString() throws Exception { short value = RandomUtil.randomShort(); ActiveMQMapMessage message = new ActiveMQMapMessage(); message.setString(itemName, Short.toString(value)); Assert.assertEquals(value, message.getShort(itemName)); }
@Test public void testGetStringFromShort() throws Exception { short value = RandomUtil.randomShort(); ActiveMQMapMessage message = new ActiveMQMapMessage(); message.setShort(itemName, value); Assert.assertEquals(Short.toString(value), message.getString(itemName)); }
@Test public void testReadStringFromShort() throws Exception { short value = RandomUtil.randomShort(); ActiveMQStreamMessage message = new ActiveMQStreamMessage(); message.writeShort(value); message.reset(); Assert.assertEquals(Short.toString(value), message.readString()); }
@Test public void testReadShortFromString() throws Exception { short value = RandomUtil.randomShort(); ActiveMQStreamMessage message = new ActiveMQStreamMessage(); message.writeString(Short.toString(value)); message.reset(); Assert.assertEquals(value, message.readShort()); }
@Test public void testGetIntFromShort() throws Exception { short value = RandomUtil.randomShort(); ActiveMQMapMessage message = new ActiveMQMapMessage(); message.setShort(itemName, value); Assert.assertEquals(value, message.getInt(itemName)); }
@Test public void testGetLongFromShort() throws Exception { short value = RandomUtil.randomShort(); ActiveMQMapMessage message = new ActiveMQMapMessage(); message.setShort(itemName, value); Assert.assertEquals(value, message.getLong(itemName)); }
@Test public void testGetShortFromShort() throws Exception { short value = RandomUtil.randomShort(); ActiveMQMapMessage message = new ActiveMQMapMessage(); message.setShort(itemName, value); Assert.assertEquals(value, message.getShort(itemName)); }
@Test public void testReadIntFromShort() throws Exception { short value = RandomUtil.randomShort(); ActiveMQStreamMessage message = new ActiveMQStreamMessage(); message.writeShort(value); message.reset(); Assert.assertEquals(value, message.readInt()); }
@Test public void testReadShortFromShort() throws Exception { short value = RandomUtil.randomShort(); ActiveMQStreamMessage message = new ActiveMQStreamMessage(); message.writeShort(value); message.reset(); Assert.assertEquals(value, message.readShort()); }
@Test public void testReadObjectFromShort() throws Exception { short value = RandomUtil.randomShort(); ActiveMQStreamMessage message = new ActiveMQStreamMessage(); message.writeShort(value); message.reset(); Assert.assertEquals(value, message.readObject()); }
@Test public void testReadLongFromShort() throws Exception { short value = RandomUtil.randomShort(); ActiveMQStreamMessage message = new ActiveMQStreamMessage(); message.writeShort(value); message.reset(); Assert.assertEquals(value, message.readLong()); }
@Test public void testShortProperty() throws Exception { Short val = RandomUtil.randomShort(); props.putShortProperty(key, val); Assert.assertEquals(val, props.getShortProperty(key)); Assert.assertEquals(Integer.valueOf(val), props.getIntProperty(key)); Assert.assertEquals(new SimpleString(Short.toString(val)), props.getSimpleStringProperty(key)); props.putSimpleStringProperty(key, new SimpleString(Short.toString(val))); Assert.assertEquals(val, props.getShortProperty(key)); Byte byteVal = RandomUtil.randomByte(); props.putByteProperty(key, byteVal); Assert.assertEquals(Short.valueOf(byteVal), props.getShortProperty(key)); try { props.putBooleanProperty(key, RandomUtil.randomBoolean()); props.getShortProperty(key); Assert.fail(); } catch (ActiveMQPropertyConversionException e) { } try { props.getShortProperty(unknownKey); Assert.fail(); } catch (NumberFormatException e) { } }
@Test public void testLongProperty() throws Exception { Long val = RandomUtil.randomLong(); props.putLongProperty(key, val); Assert.assertEquals(val, props.getLongProperty(key)); Assert.assertEquals(new SimpleString(Long.toString(val)), props.getSimpleStringProperty(key)); props.putSimpleStringProperty(key, new SimpleString(Long.toString(val))); Assert.assertEquals(val, props.getLongProperty(key)); Byte byteVal = RandomUtil.randomByte(); props.putByteProperty(key, byteVal); Assert.assertEquals(Long.valueOf(byteVal), props.getLongProperty(key)); Short shortVal = RandomUtil.randomShort(); props.putShortProperty(key, shortVal); Assert.assertEquals(Long.valueOf(shortVal), props.getLongProperty(key)); Integer intVal = RandomUtil.randomInt(); props.putIntProperty(key, intVal); Assert.assertEquals(Long.valueOf(intVal), props.getLongProperty(key)); try { props.putBooleanProperty(key, RandomUtil.randomBoolean()); props.getLongProperty(key); Assert.fail(); } catch (ActiveMQPropertyConversionException e) { } try { props.getLongProperty(unknownKey); Assert.fail(); } catch (NumberFormatException e) { } }
short val8 = RandomUtil.randomShort(); msg.putShortProperty(prop8, val8);
@Test public void testEncodeDecode() throws Exception { props.putByteProperty(RandomUtil.randomSimpleString(), RandomUtil.randomByte()); props.putBytesProperty(RandomUtil.randomSimpleString(), RandomUtil.randomBytes()); props.putBytesProperty(RandomUtil.randomSimpleString(), null); props.putBooleanProperty(RandomUtil.randomSimpleString(), RandomUtil.randomBoolean()); props.putShortProperty(RandomUtil.randomSimpleString(), RandomUtil.randomShort()); props.putIntProperty(RandomUtil.randomSimpleString(), RandomUtil.randomInt()); props.putLongProperty(RandomUtil.randomSimpleString(), RandomUtil.randomLong()); props.putFloatProperty(RandomUtil.randomSimpleString(), RandomUtil.randomFloat()); props.putDoubleProperty(RandomUtil.randomSimpleString(), RandomUtil.randomDouble()); props.putCharProperty(RandomUtil.randomSimpleString(), RandomUtil.randomChar()); props.putSimpleStringProperty(RandomUtil.randomSimpleString(), RandomUtil.randomSimpleString()); props.putSimpleStringProperty(RandomUtil.randomSimpleString(), null); SimpleString keyToRemove = RandomUtil.randomSimpleString(); props.putSimpleStringProperty(keyToRemove, RandomUtil.randomSimpleString()); ActiveMQBuffer buffer = ActiveMQBuffers.dynamicBuffer(1024); props.encode(buffer.byteBuf()); Assert.assertEquals(props.getEncodeSize(), buffer.writerIndex()); TypedProperties decodedProps = new TypedProperties(); decodedProps.decode(buffer.byteBuf()); TypedPropertiesTest.assertEqualsTypeProperties(props, decodedProps); buffer.clear(); // After removing a property, you should still be able to encode the Property props.removeProperty(keyToRemove); props.encode(buffer.byteBuf()); Assert.assertEquals(props.getEncodeSize(), buffer.writerIndex()); }