use of com.rabbitmq.stream.Codec in project rabbitmq-stream-java-client by rabbitmq.
the class CodecsTest method supportAmqpValueBody.
@ParameterizedTest
@MethodSource("codecs")
void supportAmqpValueBody(Codec codec) {
Function<Object, Message> encodeDecode = content -> {
org.apache.qpid.proton.message.Message nativeMessage = org.apache.qpid.proton.message.Message.Factory.create();
nativeMessage.setBody(new AmqpValue(content));
QpidProtonAmqpMessageWrapper wrapper = new QpidProtonAmqpMessageWrapper(true, 1L, nativeMessage);
EncodedMessage encoded = new QpidProtonCodec().encode(wrapper);
byte[] encodedData = new byte[encoded.getSize()];
System.arraycopy(encoded.getData(), 0, encodedData, 0, encoded.getSize());
Message decodedMessage = codec.decode(encodedData);
return decodedMessage;
};
Message m1 = encodeDecode.apply("hello".getBytes(StandardCharsets.UTF_8));
assertThat(m1.getBodyAsBinary()).asString(StandardCharsets.UTF_8).isEqualTo("hello");
Message m2 = encodeDecode.apply("a string is not an array of byte");
assertThatThrownBy(() -> m2.getBodyAsBinary()).isInstanceOf(IllegalStateException.class);
}
Aggregations