Skip to content

Commit 9c054a0

Browse files
onobcmhalbritter
authored andcommitted
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
1 parent 9b4974f commit 9c054a0

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/pulsar/PulsarAutoConfigurationTests.java

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
import org.apache.pulsar.client.api.ReaderBuilder;
2828
import org.apache.pulsar.client.api.interceptor.ProducerInterceptor;
2929
import org.apache.pulsar.common.schema.SchemaType;
30-
import org.assertj.core.api.InstanceOfAssertFactories;
31-
import org.junit.jupiter.api.Disabled;
3230
import org.junit.jupiter.api.Nested;
3331
import org.junit.jupiter.api.Test;
3432
import org.junit.jupiter.api.condition.EnabledForJreRange;
@@ -285,24 +283,29 @@ void injectsExpectedBeans() {
285283
}
286284

287285
@Test
288-
@Disabled("Changes in https://github.com/spring-projects/spring-pulsar/issues/593 prevent introspection of the interceptors")
289-
void whenHasUseDefinedProducerInterceptorInjectsBean() {
286+
<T> void whenHasUseDefinedProducerInterceptorInjectsBean() {
290287
ProducerInterceptor interceptor = mock(ProducerInterceptor.class);
291288
this.contextRunner.withBean("customProducerInterceptor", ProducerInterceptor.class, () -> interceptor)
292-
.run((context) -> assertThat(context).getBean(PulsarTemplate.class)
293-
.extracting("interceptorsCustomizers")
294-
.asInstanceOf(InstanceOfAssertFactories.LIST)
295-
.contains(interceptor));
289+
.run((context) -> {
290+
PulsarTemplate<?> pulsarTemplate = context.getBean(PulsarTemplate.class);
291+
Customizers<ProducerBuilderCustomizer<T>, ProducerBuilder<T>> customizers = Customizers
292+
.of(ProducerBuilder.class, ProducerBuilderCustomizer::customize);
293+
assertThat(customizers.fromField(pulsarTemplate, "interceptorsCustomizers"))
294+
.callsInOrder(ProducerBuilder::intercept, interceptor);
295+
});
296296
}
297297

298298
@Test
299-
@Disabled("Changes in https://github.com/spring-projects/spring-pulsar/issues/593 prevent introspection of the interceptors")
300-
void whenHasUseDefinedProducerInterceptorsInjectsBeansInCorrectOrder() {
301-
this.contextRunner.withUserConfiguration(InterceptorTestConfiguration.class)
302-
.run((context) -> assertThat(context).getBean(PulsarTemplate.class)
303-
.extracting("interceptorsCustomizers")
304-
.asInstanceOf(InstanceOfAssertFactories.LIST)
305-
.containsExactly(context.getBean("interceptorBar"), context.getBean("interceptorFoo")));
299+
<T> void whenHasUseDefinedProducerInterceptorsInjectsBeansInCorrectOrder() {
300+
this.contextRunner.withUserConfiguration(InterceptorTestConfiguration.class).run((context) -> {
301+
ProducerInterceptor interceptorFoo = context.getBean("interceptorFoo", ProducerInterceptor.class);
302+
ProducerInterceptor interceptorBar = context.getBean("interceptorBar", ProducerInterceptor.class);
303+
PulsarTemplate<?> pulsarTemplate = context.getBean(PulsarTemplate.class);
304+
Customizers<ProducerBuilderCustomizer<T>, ProducerBuilder<T>> customizers = Customizers
305+
.of(ProducerBuilder.class, ProducerBuilderCustomizer::customize);
306+
assertThat(customizers.fromField(pulsarTemplate, "interceptorsCustomizers"))
307+
.callsInOrder(ProducerBuilder::intercept, interceptorBar, interceptorFoo);
308+
});
306309
}
307310

308311
@Test

0 commit comments

Comments
 (0)