|
19 | 19 | import static org.mockito.Mockito.when; |
20 | 20 |
|
21 | 21 | import com.rabbitmq.stream.Codec; |
| 22 | +import com.rabbitmq.stream.Codec.EncodedMessage; |
22 | 23 | import com.rabbitmq.stream.Message; |
23 | 24 | import com.rabbitmq.stream.MessageBuilder; |
24 | 25 | import com.rabbitmq.stream.amqp.UnsignedByte; |
25 | 26 | import com.rabbitmq.stream.amqp.UnsignedInteger; |
26 | 27 | import com.rabbitmq.stream.amqp.UnsignedLong; |
27 | 28 | import com.rabbitmq.stream.amqp.UnsignedShort; |
| 29 | +import com.rabbitmq.stream.codec.QpidProtonCodec.QpidProtonAmqpMessageWrapper; |
28 | 30 | import java.math.BigDecimal; |
29 | 31 | import java.math.BigInteger; |
30 | 32 | import java.nio.charset.Charset; |
31 | 33 | import java.nio.charset.StandardCharsets; |
32 | | -import java.util.*; |
| 34 | +import java.util.ArrayList; |
| 35 | +import java.util.Arrays; |
| 36 | +import java.util.Date; |
| 37 | +import java.util.List; |
| 38 | +import java.util.UUID; |
33 | 39 | import java.util.function.Consumer; |
34 | 40 | import java.util.function.Function; |
35 | 41 | import java.util.function.Supplier; |
36 | 42 | import java.util.stream.Stream; |
| 43 | +import org.apache.qpid.proton.amqp.messaging.AmqpValue; |
37 | 44 | import org.assertj.core.api.InstanceOfAssertFactories; |
38 | 45 | import org.assertj.core.api.ThrowableAssert; |
39 | 46 | import org.junit.jupiter.params.ParameterizedTest; |
@@ -71,6 +78,18 @@ static Iterable<Codec> readCreatedMessage() { |
71 | 78 | new SwiftMqCodec()); |
72 | 79 | } |
73 | 80 |
|
| 81 | + static Stream<Codec> codecs() { |
| 82 | + return Stream.of(new QpidProtonCodec(), new SwiftMqCodec()); |
| 83 | + } |
| 84 | + |
| 85 | + static Stream<MessageBuilder> messageBuilders() { |
| 86 | + return Stream.of( |
| 87 | + new QpidProtonMessageBuilder(), |
| 88 | + new SwiftMqMessageBuilder(), |
| 89 | + new WrapperMessageBuilder(), |
| 90 | + new SimpleCodec().messageBuilder()); |
| 91 | + } |
| 92 | + |
74 | 93 | @ParameterizedTest |
75 | 94 | @MethodSource("codecsCouples") |
76 | 95 | void codecs(CodecCouple codecCouple) { |
@@ -493,12 +512,28 @@ void notSupportedTypes(Supplier<MessageBuilder> messageBuilderSupplier) { |
493 | 512 | action -> assertThatThrownBy(action).isInstanceOf(UnsupportedOperationException.class)); |
494 | 513 | } |
495 | 514 |
|
496 | | - static Stream<MessageBuilder> messageBuilders() { |
497 | | - return Stream.of( |
498 | | - new QpidProtonMessageBuilder(), |
499 | | - new SwiftMqMessageBuilder(), |
500 | | - new WrapperMessageBuilder(), |
501 | | - new SimpleCodec().messageBuilder()); |
| 515 | + @ParameterizedTest |
| 516 | + @MethodSource("codecs") |
| 517 | + void supportAmqpValueBody(Codec codec) { |
| 518 | + Function<Object, Message> encodeDecode = |
| 519 | + content -> { |
| 520 | + org.apache.qpid.proton.message.Message nativeMessage = |
| 521 | + org.apache.qpid.proton.message.Message.Factory.create(); |
| 522 | + nativeMessage.setBody(new AmqpValue(content)); |
| 523 | + QpidProtonAmqpMessageWrapper wrapper = |
| 524 | + new QpidProtonAmqpMessageWrapper(true, 1L, nativeMessage); |
| 525 | + EncodedMessage encoded = new QpidProtonCodec().encode(wrapper); |
| 526 | + byte[] encodedData = new byte[encoded.getSize()]; |
| 527 | + System.arraycopy(encoded.getData(), 0, encodedData, 0, encoded.getSize()); |
| 528 | + Message decodedMessage = codec.decode(encodedData); |
| 529 | + return decodedMessage; |
| 530 | + }; |
| 531 | + |
| 532 | + Message m1 = encodeDecode.apply("hello".getBytes(StandardCharsets.UTF_8)); |
| 533 | + assertThat(m1.getBodyAsBinary()).asString(StandardCharsets.UTF_8).isEqualTo("hello"); |
| 534 | + |
| 535 | + Message m2 = encodeDecode.apply("a string is not an array of byte"); |
| 536 | + assertThatThrownBy(() -> m2.getBodyAsBinary()).isInstanceOf(IllegalStateException.class); |
502 | 537 | } |
503 | 538 |
|
504 | 539 | @ParameterizedTest |
|
0 commit comments