Search in sources :

Example 1 with QpidProtonAmqpMessageWrapper

use of com.rabbitmq.stream.codec.QpidProtonCodec.QpidProtonAmqpMessageWrapper 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);
}
Also used : Arrays(java.util.Arrays) EncodedMessage(com.rabbitmq.stream.Codec.EncodedMessage) UnsignedInteger(com.rabbitmq.stream.amqp.UnsignedInteger) Message(com.rabbitmq.stream.Message) Date(java.util.Date) InstanceOfAssertFactories(org.assertj.core.api.InstanceOfAssertFactories) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Codec(com.rabbitmq.stream.Codec) UnsignedByte(com.rabbitmq.stream.amqp.UnsignedByte) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) UnsignedLong(com.rabbitmq.stream.amqp.UnsignedLong) Charset(java.nio.charset.Charset) AmqpValue(org.apache.qpid.proton.amqp.messaging.AmqpValue) BigInteger(java.math.BigInteger) MethodSource(org.junit.jupiter.params.provider.MethodSource) ThrowableAssert(org.assertj.core.api.ThrowableAssert) Mockito.when(org.mockito.Mockito.when) UUID(java.util.UUID) StandardCharsets(java.nio.charset.StandardCharsets) Consumer(java.util.function.Consumer) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Stream(java.util.stream.Stream) MessageBuilder(com.rabbitmq.stream.MessageBuilder) QpidProtonAmqpMessageWrapper(com.rabbitmq.stream.codec.QpidProtonCodec.QpidProtonAmqpMessageWrapper) UnsignedShort(com.rabbitmq.stream.amqp.UnsignedShort) Mockito.mock(org.mockito.Mockito.mock) EncodedMessage(com.rabbitmq.stream.Codec.EncodedMessage) EncodedMessage(com.rabbitmq.stream.Codec.EncodedMessage) Message(com.rabbitmq.stream.Message) QpidProtonAmqpMessageWrapper(com.rabbitmq.stream.codec.QpidProtonCodec.QpidProtonAmqpMessageWrapper) AmqpValue(org.apache.qpid.proton.amqp.messaging.AmqpValue) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

Codec (com.rabbitmq.stream.Codec)1 EncodedMessage (com.rabbitmq.stream.Codec.EncodedMessage)1 Message (com.rabbitmq.stream.Message)1 MessageBuilder (com.rabbitmq.stream.MessageBuilder)1 UnsignedByte (com.rabbitmq.stream.amqp.UnsignedByte)1 UnsignedInteger (com.rabbitmq.stream.amqp.UnsignedInteger)1 UnsignedLong (com.rabbitmq.stream.amqp.UnsignedLong)1 UnsignedShort (com.rabbitmq.stream.amqp.UnsignedShort)1 QpidProtonAmqpMessageWrapper (com.rabbitmq.stream.codec.QpidProtonCodec.QpidProtonAmqpMessageWrapper)1 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 Charset (java.nio.charset.Charset)1 StandardCharsets (java.nio.charset.StandardCharsets)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Date (java.util.Date)1 List (java.util.List)1 UUID (java.util.UUID)1 Consumer (java.util.function.Consumer)1 Function (java.util.function.Function)1