|
31 | 31 | import static java.util.concurrent.Executors.newSingleThreadExecutor;
|
32 | 32 | import static java.util.stream.IntStream.range;
|
33 | 33 | import static java.util.stream.Stream.of;
|
34 |
| -import static org.assertj.core.api.Assertions.*; |
| 34 | +import static org.assertj.core.api.Assertions.assertThatThrownBy; |
| 35 | +import static org.assertj.core.api.Fail.fail; |
35 | 36 |
|
36 | 37 | import com.rabbitmq.client.amqp.AmqpException;
|
37 | 38 | import com.rabbitmq.client.amqp.Connection;
|
@@ -138,7 +139,7 @@ void queueDeclareDeletePublishConsume(String subject) {
|
138 | 139 | assertThat(queueInfo).hasName(name).hasNoConsumers().hasMessageCount(messageCount);
|
139 | 140 |
|
140 | 141 | AtomicReference<String> receivedSubject = new AtomicReference<>();
|
141 |
| - Sync consumeSync = TestUtils.sync(messageCount); |
| 142 | + Sync consumeSync = sync(messageCount); |
142 | 143 | com.rabbitmq.client.amqp.Consumer consumer =
|
143 | 144 | connection
|
144 | 145 | .consumerBuilder()
|
@@ -840,4 +841,69 @@ void messagesAreDispatchedToEnvironmentConnectionExecutorService() {
|
840 | 841 | connExecutor.shutdown();
|
841 | 842 | }
|
842 | 843 | }
|
| 844 | + |
| 845 | + @Test |
| 846 | + void messageAnnotationsSupportListMapArray() { |
| 847 | + String q = connection.management().queue().exclusive(true).declare().name(); |
| 848 | + Publisher publisher = connection.publisherBuilder().queue(q).build(); |
| 849 | + |
| 850 | + Message message = |
| 851 | + publisher |
| 852 | + .message() |
| 853 | + .annotation( |
| 854 | + "x-list", |
| 855 | + List.of("1", "2", 3, List.of("1"), Map.of("k1", "v1"), new String[] {"1"})) |
| 856 | + .annotation( |
| 857 | + "x-map", |
| 858 | + Map.of( |
| 859 | + "k1", |
| 860 | + "v1", |
| 861 | + "k2", |
| 862 | + List.of("v2"), |
| 863 | + "k3", |
| 864 | + Map.of("k1", "v1"), |
| 865 | + "k4", |
| 866 | + new String[] {"1"})) |
| 867 | + .annotation("x-arrayString", new String[] {"1", "2", "3"}) |
| 868 | + .annotation("x-arrayInteger", new Integer[] {1, 2, 3}) |
| 869 | + .annotation("x-arrayInt", new Integer[] {4, 5, 6}); |
| 870 | + |
| 871 | + publisher.publish(message, ctx -> {}); |
| 872 | + Sync consumeSync = sync(); |
| 873 | + AtomicReference<Message> inMessage = new AtomicReference<>(); |
| 874 | + connection |
| 875 | + .consumerBuilder() |
| 876 | + .queue(q) |
| 877 | + .messageHandler( |
| 878 | + (context, m) -> { |
| 879 | + inMessage.set(m); |
| 880 | + context.accept(); |
| 881 | + consumeSync.down(); |
| 882 | + }) |
| 883 | + .build(); |
| 884 | + |
| 885 | + assertThat(consumeSync).completes(); |
| 886 | + Message m = inMessage.get(); |
| 887 | + List<?> list = (List<?>) m.annotation("x-list"); |
| 888 | + org.assertj.core.api.Assertions.assertThat(list.get(0)).isEqualTo("1"); |
| 889 | + org.assertj.core.api.Assertions.assertThat(list.get(1)).isEqualTo("2"); |
| 890 | + org.assertj.core.api.Assertions.assertThat(list.get(2)).isEqualTo(3); |
| 891 | + org.assertj.core.api.Assertions.assertThat(list.get(3)).isEqualTo(List.of("1")); |
| 892 | + org.assertj.core.api.Assertions.assertThat(list.get(4)).isEqualTo(Map.of("k1", "v1")); |
| 893 | + org.assertj.core.api.Assertions.assertThat(list.get(5)).isEqualTo(new String[] {"1"}); |
| 894 | + |
| 895 | + Map<?, ?> map = (Map<?, ?>) m.annotation("x-map"); |
| 896 | + org.assertj.core.api.Assertions.assertThat(map.get("k1")).isEqualTo("v1"); |
| 897 | + org.assertj.core.api.Assertions.assertThat(map.get("k2")).isEqualTo(List.of("v2")); |
| 898 | + org.assertj.core.api.Assertions.assertThat(map.get("k3")).isEqualTo(Map.of("k1", "v1")); |
| 899 | + org.assertj.core.api.Assertions.assertThat(map.get("k4")).isEqualTo(new String[] {"1"}); |
| 900 | + |
| 901 | + Object[] arrayString = (Object[]) m.annotation("x-arrayString"); |
| 902 | + org.assertj.core.api.Assertions.assertThat(arrayString).containsExactly("1", "2", "3"); |
| 903 | + |
| 904 | + int[] ints = (int[]) m.annotation("x-arrayInteger"); |
| 905 | + org.assertj.core.api.Assertions.assertThat(ints).containsExactly(1, 2, 3); |
| 906 | + ints = (int[]) m.annotation("x-arrayInt"); |
| 907 | + org.assertj.core.api.Assertions.assertThat(ints).containsExactly(4, 5, 6); |
| 908 | + } |
843 | 909 | }
|
0 commit comments