|
43 | 43 | import org.springframework.amqp.core.AcknowledgeMode; |
44 | 44 | import org.springframework.amqp.core.AmqpAdmin; |
45 | 45 | import org.springframework.amqp.core.Message; |
| 46 | +import org.springframework.amqp.core.MessageProperties; |
46 | 47 | import org.springframework.amqp.rabbit.annotation.EnableRabbit; |
47 | 48 | import org.springframework.amqp.rabbit.annotation.RabbitListener; |
48 | 49 | import org.springframework.amqp.rabbit.config.AbstractRabbitListenerContainerFactory; |
|
62 | 63 | import org.springframework.amqp.rabbit.listener.RabbitListenerContainerFactory; |
63 | 64 | import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer; |
64 | 65 | import org.springframework.amqp.rabbit.retry.MessageRecoverer; |
65 | | -import org.springframework.amqp.support.converter.AllowedListDeserializingMessageConverter; |
| 66 | +import org.springframework.amqp.support.converter.MessageConversionException; |
66 | 67 | import org.springframework.amqp.support.converter.MessageConverter; |
67 | 68 | import org.springframework.amqp.support.converter.SerializerMessageConverter; |
68 | 69 | import org.springframework.beans.factory.NoSuchBeanDefinitionException; |
69 | 70 | import org.springframework.boot.autoconfigure.AutoConfigurations; |
70 | 71 | import org.springframework.boot.autoconfigure.ssl.SslAutoConfiguration; |
| 72 | +import org.springframework.boot.context.properties.source.InvalidConfigurationPropertyValueException; |
71 | 73 | import org.springframework.boot.test.context.FilteredClassLoader; |
72 | 74 | import org.springframework.boot.test.context.assertj.AssertableApplicationContext; |
73 | 75 | import org.springframework.boot.test.context.runner.ApplicationContextRunner; |
@@ -802,20 +804,27 @@ void customizeRequestedChannelMax() { |
802 | 804 | }); |
803 | 805 | } |
804 | 806 |
|
805 | | - @SuppressWarnings("unchecked") |
806 | 807 | @ParameterizedTest |
807 | 808 | @ValueSource(classes = { TestConfiguration.class, TestConfiguration6.class }) |
| 809 | + @SuppressWarnings("unchecked") |
808 | 810 | void customizeAllowedListPatterns(Class<?> configuration) { |
809 | 811 | this.contextRunner.withUserConfiguration(configuration) |
810 | 812 | .withPropertyValues("spring.rabbitmq.template.allowed-list-patterns:*") |
811 | 813 | .run((context) -> { |
812 | 814 | MessageConverter messageConverter = context.getBean(RabbitTemplate.class).getMessageConverter(); |
813 | | - assertThat(messageConverter).isInstanceOfSatisfying(AllowedListDeserializingMessageConverter.class, |
814 | | - (mc) -> assertThat(mc).extracting("allowedListPatterns") |
815 | | - .isInstanceOfSatisfying(Collection.class, (set) -> assertThat(set).contains("*"))); |
| 815 | + assertThat(messageConverter).extracting("allowedListPatterns") |
| 816 | + .isInstanceOfSatisfying(Collection.class, (set) -> assertThat(set).contains("*")); |
816 | 817 | }); |
817 | 818 | } |
818 | 819 |
|
| 820 | + @Test |
| 821 | + void customizeAllowedListPatternsWhenHasNoAllowedListDeserializingMessageConverter() { |
| 822 | + this.contextRunner.withUserConfiguration(CustomMessageConverterConfiguration.class) |
| 823 | + .withPropertyValues("spring.rabbitmq.template.allowed-list-patterns:*") |
| 824 | + .run((context) -> assertThat(context).getFailure() |
| 825 | + .hasRootCauseInstanceOf(InvalidConfigurationPropertyValueException.class)); |
| 826 | + } |
| 827 | + |
819 | 828 | @Test |
820 | 829 | void noSslByDefault() { |
821 | 830 | this.contextRunner.withUserConfiguration(TestConfiguration.class).run((context) -> { |
@@ -1417,6 +1426,29 @@ public List<Address> getAddresses() { |
1417 | 1426 |
|
1418 | 1427 | } |
1419 | 1428 |
|
| 1429 | + @Configuration |
| 1430 | + static class CustomMessageConverterConfiguration { |
| 1431 | + |
| 1432 | + @Bean |
| 1433 | + MessageConverter messageConverter() { |
| 1434 | + return new MessageConverter() { |
| 1435 | + |
| 1436 | + @Override |
| 1437 | + public Message toMessage(Object object, MessageProperties messageProperties) |
| 1438 | + throws MessageConversionException { |
| 1439 | + return new Message(object.toString().getBytes()); |
| 1440 | + } |
| 1441 | + |
| 1442 | + @Override |
| 1443 | + public Object fromMessage(Message message) throws MessageConversionException { |
| 1444 | + return new String(message.getBody()); |
| 1445 | + } |
| 1446 | + |
| 1447 | + }; |
| 1448 | + } |
| 1449 | + |
| 1450 | + } |
| 1451 | + |
1420 | 1452 | static class TestListener { |
1421 | 1453 |
|
1422 | 1454 | @RabbitListener(queues = "test", autoStartup = "false") |
|
0 commit comments