From 9c054a021fc34728a68a835a5c2e421f3e11df9f Mon Sep 17 00:00:00 2001 From: Chris Bono Date: Tue, 12 Mar 2024 12:09:46 -0500 Subject: [PATCH] Re-enable Spring Pulsar interceptor tests The PulsarTemplate recently replaced its list of ProducerInterceptors with a list of ProducerBuilderCustomizers that customize the builder by adding each interceptor to the builder. The PulsarAutoConfigurationTests previosuly relied on the previous field. This commit adjusts the tests to instead use the Customizers testing utility to verify the interceptors. See gh-39912 --- .../pulsar/PulsarAutoConfigurationTests.java | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/pulsar/PulsarAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/pulsar/PulsarAutoConfigurationTests.java index 7e0fb8b2b2..3df54e006f 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/pulsar/PulsarAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/pulsar/PulsarAutoConfigurationTests.java @@ -27,8 +27,6 @@ import org.apache.pulsar.client.api.PulsarClient; import org.apache.pulsar.client.api.ReaderBuilder; import org.apache.pulsar.client.api.interceptor.ProducerInterceptor; import org.apache.pulsar.common.schema.SchemaType; -import org.assertj.core.api.InstanceOfAssertFactories; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledForJreRange; @@ -285,24 +283,29 @@ class PulsarAutoConfigurationTests { } @Test - @Disabled("Changes in https://github.com/spring-projects/spring-pulsar/issues/593 prevent introspection of the interceptors") - void whenHasUseDefinedProducerInterceptorInjectsBean() { + void whenHasUseDefinedProducerInterceptorInjectsBean() { ProducerInterceptor interceptor = mock(ProducerInterceptor.class); this.contextRunner.withBean("customProducerInterceptor", ProducerInterceptor.class, () -> interceptor) - .run((context) -> assertThat(context).getBean(PulsarTemplate.class) - .extracting("interceptorsCustomizers") - .asInstanceOf(InstanceOfAssertFactories.LIST) - .contains(interceptor)); + .run((context) -> { + PulsarTemplate pulsarTemplate = context.getBean(PulsarTemplate.class); + Customizers, ProducerBuilder> customizers = Customizers + .of(ProducerBuilder.class, ProducerBuilderCustomizer::customize); + assertThat(customizers.fromField(pulsarTemplate, "interceptorsCustomizers")) + .callsInOrder(ProducerBuilder::intercept, interceptor); + }); } @Test - @Disabled("Changes in https://github.com/spring-projects/spring-pulsar/issues/593 prevent introspection of the interceptors") - void whenHasUseDefinedProducerInterceptorsInjectsBeansInCorrectOrder() { - this.contextRunner.withUserConfiguration(InterceptorTestConfiguration.class) - .run((context) -> assertThat(context).getBean(PulsarTemplate.class) - .extracting("interceptorsCustomizers") - .asInstanceOf(InstanceOfAssertFactories.LIST) - .containsExactly(context.getBean("interceptorBar"), context.getBean("interceptorFoo"))); + void whenHasUseDefinedProducerInterceptorsInjectsBeansInCorrectOrder() { + this.contextRunner.withUserConfiguration(InterceptorTestConfiguration.class).run((context) -> { + ProducerInterceptor interceptorFoo = context.getBean("interceptorFoo", ProducerInterceptor.class); + ProducerInterceptor interceptorBar = context.getBean("interceptorBar", ProducerInterceptor.class); + PulsarTemplate pulsarTemplate = context.getBean(PulsarTemplate.class); + Customizers, ProducerBuilder> customizers = Customizers + .of(ProducerBuilder.class, ProducerBuilderCustomizer::customize); + assertThat(customizers.fromField(pulsarTemplate, "interceptorsCustomizers")) + .callsInOrder(ProducerBuilder::intercept, interceptorBar, interceptorFoo); + }); } @Test