use of org.apache.qpid.protonj2.buffer.ProtonBufferInputStream in project qpid-protonj2 by apache.
the class AcceptedTypeCodecTest method testEncodeDecodeArray.
private void testEncodeDecodeArray(boolean fromStream) throws IOException {
ProtonBuffer buffer = ProtonByteBufferAllocator.DEFAULT.allocate();
InputStream stream = new ProtonBufferInputStream(buffer);
Accepted[] array = new Accepted[3];
array[0] = Accepted.getInstance();
array[1] = Accepted.getInstance();
array[2] = Accepted.getInstance();
encoder.writeObject(buffer, encoderState, array);
final Object result;
if (fromStream) {
result = streamDecoder.readObject(stream, streamDecoderState);
} else {
result = decoder.readObject(buffer, decoderState);
}
assertTrue(result.getClass().isArray());
assertEquals(Accepted.class, result.getClass().getComponentType());
Accepted[] resultArray = (Accepted[]) result;
for (int i = 0; i < resultArray.length; ++i) {
assertNotNull(resultArray[i]);
assertTrue(resultArray[i] instanceof Accepted);
}
}
use of org.apache.qpid.protonj2.buffer.ProtonBufferInputStream in project qpid-protonj2 by apache.
the class AmqpSequenceTypeCodecTest method doTestSkipValue.
private void doTestSkipValue(boolean fromStream) throws IOException {
ProtonBuffer buffer = ProtonByteBufferAllocator.DEFAULT.allocate();
InputStream stream = new ProtonBufferInputStream(buffer);
List<Object> list = new ArrayList<>();
list.add("one");
list.add("two");
list.add("three");
for (int i = 0; i < 10; ++i) {
encoder.writeObject(buffer, encoderState, new AmqpSequence<>(list));
}
encoder.writeObject(buffer, encoderState, new Modified());
for (int i = 0; i < 10; ++i) {
if (fromStream) {
StreamTypeDecoder<?> typeDecoder = streamDecoder.readNextTypeDecoder(stream, streamDecoderState);
assertEquals(AmqpSequence.class, typeDecoder.getTypeClass());
typeDecoder.skipValue(stream, streamDecoderState);
} else {
TypeDecoder<?> typeDecoder = decoder.readNextTypeDecoder(buffer, decoderState);
assertEquals(AmqpSequence.class, typeDecoder.getTypeClass());
typeDecoder.skipValue(buffer, decoderState);
}
}
final Object result;
if (fromStream) {
result = streamDecoder.readObject(stream, streamDecoderState);
} else {
result = decoder.readObject(buffer, decoderState);
}
assertNotNull(result);
assertTrue(result instanceof Modified);
Modified modified = (Modified) result;
assertFalse(modified.isUndeliverableHere());
assertFalse(modified.isDeliveryFailed());
}
use of org.apache.qpid.protonj2.buffer.ProtonBufferInputStream in project qpid-protonj2 by apache.
the class AmqpSequenceTypeCodecTest method doTestDecodeWithInvalidMapType.
private void doTestDecodeWithInvalidMapType(byte mapType, boolean fromStream) throws IOException {
ProtonBuffer buffer = ProtonByteBufferAllocator.DEFAULT.allocate();
InputStream stream = new ProtonBufferInputStream(buffer);
// Described Type Indicator
buffer.writeByte((byte) 0);
buffer.writeByte(EncodingCodes.SMALLULONG);
buffer.writeByte(AmqpSequence.DESCRIPTOR_CODE.byteValue());
if (mapType == EncodingCodes.MAP32) {
buffer.writeByte(EncodingCodes.MAP32);
// Size
buffer.writeInt((byte) 0);
// Count
buffer.writeInt((byte) 0);
} else {
buffer.writeByte(EncodingCodes.MAP8);
// Size
buffer.writeByte((byte) 0);
// Count
buffer.writeByte((byte) 0);
}
if (fromStream) {
try {
streamDecoder.readObject(stream, streamDecoderState);
fail("Should not decode type with invalid encoding");
} catch (DecodeException ex) {
}
} else {
try {
decoder.readObject(buffer, decoderState);
fail("Should not decode type with invalid encoding");
} catch (DecodeException ex) {
}
}
}
use of org.apache.qpid.protonj2.buffer.ProtonBufferInputStream in project qpid-protonj2 by apache.
the class AmqpSequenceTypeCodecTest method doTestSkipValueWithInvalidMapType.
private void doTestSkipValueWithInvalidMapType(byte mapType, boolean fromStream) throws IOException {
ProtonBuffer buffer = ProtonByteBufferAllocator.DEFAULT.allocate();
InputStream stream = new ProtonBufferInputStream(buffer);
// Described Type Indicator
buffer.writeByte((byte) 0);
buffer.writeByte(EncodingCodes.SMALLULONG);
buffer.writeByte(AmqpSequence.DESCRIPTOR_CODE.byteValue());
if (mapType == EncodingCodes.MAP32) {
buffer.writeByte(EncodingCodes.MAP32);
// Size
buffer.writeInt((byte) 0);
// Count
buffer.writeInt((byte) 0);
} else {
buffer.writeByte(EncodingCodes.MAP8);
// Size
buffer.writeByte((byte) 0);
// Count
buffer.writeByte((byte) 0);
}
if (fromStream) {
StreamTypeDecoder<?> typeDecoder = streamDecoder.readNextTypeDecoder(stream, streamDecoderState);
assertEquals(AmqpSequence.class, typeDecoder.getTypeClass());
try {
typeDecoder.skipValue(stream, streamDecoderState);
fail("Should not be able to skip type with invalid encoding");
} catch (DecodeException ex) {
}
} else {
TypeDecoder<?> typeDecoder = decoder.readNextTypeDecoder(buffer, decoderState);
assertEquals(AmqpSequence.class, typeDecoder.getTypeClass());
try {
typeDecoder.skipValue(buffer, decoderState);
fail("Should not be able to skip type with invalid encoding");
} catch (DecodeException ex) {
}
}
}
use of org.apache.qpid.protonj2.buffer.ProtonBufferInputStream in project qpid-protonj2 by apache.
the class ApplicationPropertiesTypeCodecTest method doTestSkipValue.
private void doTestSkipValue(boolean fromStream) throws IOException {
ProtonBuffer buffer = ProtonByteBufferAllocator.DEFAULT.allocate();
InputStream stream = new ProtonBufferInputStream(buffer);
Map<String, Object> map = new HashMap<>();
map.put("one", 1);
map.put("two", Boolean.TRUE);
map.put("three", "test");
for (int i = 0; i < 10; ++i) {
encoder.writeObject(buffer, encoderState, new ApplicationProperties(map));
}
encoder.writeObject(buffer, encoderState, new Modified());
for (int i = 0; i < 10; ++i) {
if (fromStream) {
StreamTypeDecoder<?> typeDecoder = streamDecoder.readNextTypeDecoder(stream, streamDecoderState);
assertEquals(ApplicationProperties.class, typeDecoder.getTypeClass());
typeDecoder.skipValue(stream, streamDecoderState);
} else {
TypeDecoder<?> typeDecoder = decoder.readNextTypeDecoder(buffer, decoderState);
assertEquals(ApplicationProperties.class, typeDecoder.getTypeClass());
typeDecoder.skipValue(buffer, decoderState);
}
}
final Object result;
if (fromStream) {
result = streamDecoder.readObject(stream, streamDecoderState);
} else {
result = decoder.readObject(buffer, decoderState);
}
assertNotNull(result);
assertTrue(result instanceof Modified);
Modified modified = (Modified) result;
assertFalse(modified.isUndeliverableHere());
assertFalse(modified.isDeliveryFailed());
}
Aggregations