From 8442ed72d23491db98f66890416264e23e6b775c Mon Sep 17 00:00:00 2001 From: Hyun Lee Date: Thu, 10 Sep 2026 19:22:45 -0500 Subject: [PATCH] GH-1763 - Register JDBC event publication auto-configuration for JDBC slice tests. @JdbcTest and @DataJdbcTest slices did not include JdbcEventPublicationAutoConfiguration, so no EventPublicationRepository was available in those tests. We now list it in an AutoConfigureJdbc.imports file, which @DataJdbcTest picks up through @AutoConfigureJdbc as well. The Jackson-based EventSerializer configurations are listed as optional entries, as the repository cannot be created without a serializer and Boot's JSON auto-configuration is not part of the JDBC slices. Signed-off-by: Hyun Lee --- .../spring-modulith-events-jdbc/pom.xml | 13 ++++ ...st.autoconfigure.AutoConfigureJdbc.imports | 3 + ...liceAutoConfigurationIntegrationTests.java | 72 +++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 spring-modulith-events/spring-modulith-events-jdbc/src/main/resources/META-INF/spring/org.springframework.boot.jdbc.test.autoconfigure.AutoConfigureJdbc.imports create mode 100644 spring-modulith-events/spring-modulith-events-jdbc/src/test/java/org/springframework/modulith/events/jdbc/JdbcEventPublicationSliceAutoConfigurationIntegrationTests.java diff --git a/spring-modulith-events/spring-modulith-events-jdbc/pom.xml b/spring-modulith-events/spring-modulith-events-jdbc/pom.xml index 37d9d3f6e..03254eae9 100644 --- a/spring-modulith-events/spring-modulith-events-jdbc/pom.xml +++ b/spring-modulith-events/spring-modulith-events-jdbc/pom.xml @@ -64,6 +64,19 @@ test + + org.springframework.boot + spring-boot-data-jdbc-test + test + + + + ${project.groupId} + spring-modulith-events-jackson + ${project.version} + test + + org.springframework spring-web diff --git a/spring-modulith-events/spring-modulith-events-jdbc/src/main/resources/META-INF/spring/org.springframework.boot.jdbc.test.autoconfigure.AutoConfigureJdbc.imports b/spring-modulith-events/spring-modulith-events-jdbc/src/main/resources/META-INF/spring/org.springframework.boot.jdbc.test.autoconfigure.AutoConfigureJdbc.imports new file mode 100644 index 000000000..81a5494e4 --- /dev/null +++ b/spring-modulith-events/spring-modulith-events-jdbc/src/main/resources/META-INF/spring/org.springframework.boot.jdbc.test.autoconfigure.AutoConfigureJdbc.imports @@ -0,0 +1,3 @@ +org.springframework.modulith.events.jdbc.JdbcEventPublicationAutoConfiguration +optional:org.springframework.modulith.events.jackson.JacksonEventSerializationConfiguration +optional:org.springframework.modulith.events.jackson2.Jackson2EventSerializationConfiguration diff --git a/spring-modulith-events/spring-modulith-events-jdbc/src/test/java/org/springframework/modulith/events/jdbc/JdbcEventPublicationSliceAutoConfigurationIntegrationTests.java b/spring-modulith-events/spring-modulith-events-jdbc/src/test/java/org/springframework/modulith/events/jdbc/JdbcEventPublicationSliceAutoConfigurationIntegrationTests.java new file mode 100644 index 000000000..a99df3edf --- /dev/null +++ b/spring-modulith-events/spring-modulith-events-jdbc/src/test/java/org/springframework/modulith/events/jdbc/JdbcEventPublicationSliceAutoConfigurationIntegrationTests.java @@ -0,0 +1,72 @@ +/* + * Copyright 2026 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.modulith.events.jdbc; + +import static org.assertj.core.api.Assertions.*; + +import java.lang.annotation.Annotation; +import java.util.stream.Stream; + +import org.junit.jupiter.api.DynamicTest; +import org.junit.jupiter.api.TestFactory; +import org.springframework.boot.autoconfigure.AutoConfigurationPackage; +import org.springframework.boot.data.jdbc.test.autoconfigure.DataJdbcTest; +import org.springframework.boot.jdbc.test.autoconfigure.JdbcTest; +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.modulith.events.core.EventPublicationRepository; +import org.springframework.modulith.events.core.EventSerializer; + +/** + * Integration tests for the registration of {@link JdbcEventPublicationAutoConfiguration} for JDBC-based slice tests. + * + * @author Hyun Lee + */ +class JdbcEventPublicationSliceAutoConfigurationIntegrationTests { + + @TestFactory // GH-1763 + Stream registersEventPublicationRepositoryForSlices() { + + return DynamicTest.stream(Stream.of(JdbcSlicing.class, DataJdbcSlicing.class), + it -> getTestAnnotationName(it) + " registers the event publication repository", + it -> new ApplicationContextRunner() + .withUserConfiguration(it) + .run(context -> { + assertThat(context).hasNotFailed(); + assertThat(context).hasSingleBean(EventPublicationRepository.class); + assertThat(context).hasSingleBean(EventSerializer.class); + })); + } + + private static String getTestAnnotationName(Class type) { + + return Stream.of(type.getDeclaredAnnotations()) + .map(Annotation::annotationType) + .map(Class::getSimpleName) + .filter(it -> it.endsWith("Test")) + .findFirst() + .orElseThrow(); + } + + @TestConfiguration + @JdbcTest + static class JdbcSlicing {} + + @TestConfiguration + @DataJdbcTest + @AutoConfigurationPackage + static class DataJdbcSlicing {} +}