refactor: 리펙토링 진행중 의존성 gradle은 얇게 유지, 각 모듈에서 처리하고 있는 부분에 대해서 리펙토링

This commit is contained in:
donghyeon-ka
2026-09-24 11:15:10 +09:00
parent ba8a8c171c
commit b5114b9bb4
12 changed files with 153 additions and 37 deletions
@@ -1,7 +1,7 @@
package dev.caskeleton.messaging.admin.runtime; package dev.caskeleton.messaging.admin.runtime;
import dev.caskeleton.messaging.admin.VerifiedApproval;
import dev.caskeleton.messaging.admin.DestructiveOperation; import dev.caskeleton.messaging.admin.DestructiveOperation;
import dev.caskeleton.messaging.admin.VerifiedApproval;
import dev.caskeleton.messaging.api.destination.DestinationName; import dev.caskeleton.messaging.api.destination.DestinationName;
import java.time.Duration; import java.time.Duration;
import java.time.Instant; import java.time.Instant;
@@ -31,7 +31,6 @@ com.puppycrawl.tools:checkstyle:13.5.0=checkstyle
commons-beanutils:commons-beanutils:1.11.0=checkstyle commons-beanutils:commons-beanutils:1.11.0=checkstyle
commons-collections:commons-collections:3.2.2=checkstyle commons-collections:commons-collections:3.2.2=checkstyle
commons-io:commons-io:2.21.0=spotbugs commons-io:commons-io:2.21.0=spotbugs
commons-logging:commons-logging:1.3.6=runtimeClasspath,testRuntimeClasspath
info.picocli:picocli:4.7.7=checkstyle info.picocli:picocli:4.7.7=checkstyle
io.github.eisop:dataflow-errorprone:3.41.0-eisop1=annotationProcessor,testAnnotationProcessor io.github.eisop:dataflow-errorprone:3.41.0-eisop1=annotationProcessor,testAnnotationProcessor
io.github.java-diff-utils:java-diff-utils:4.12=annotationProcessor,testAnnotationProcessor io.github.java-diff-utils:java-diff-utils:4.12=annotationProcessor,testAnnotationProcessor
@@ -89,14 +88,6 @@ org.reflections:reflections:0.10.2=checkstyle
org.slf4j:slf4j-api:2.0.18=runtimeClasspath,spotbugs,spotbugsSlf4j,testRuntimeClasspath org.slf4j:slf4j-api:2.0.18=runtimeClasspath,spotbugs,spotbugsSlf4j,testRuntimeClasspath
org.slf4j:slf4j-simple:2.0.17=spotbugsSlf4j org.slf4j:slf4j-simple:2.0.17=spotbugsSlf4j
org.slf4j:slf4j-simple:2.0.18=checkstyle org.slf4j:slf4j-simple:2.0.18=checkstyle
org.springframework.kafka:spring-kafka:4.0.7=runtimeClasspath,testRuntimeClasspath
org.springframework:spring-aop:7.0.9=runtimeClasspath,testRuntimeClasspath
org.springframework:spring-beans:7.0.9=runtimeClasspath,testRuntimeClasspath
org.springframework:spring-context:7.0.9=runtimeClasspath,testRuntimeClasspath
org.springframework:spring-core:7.0.9=runtimeClasspath,testRuntimeClasspath
org.springframework:spring-expression:7.0.9=runtimeClasspath,testRuntimeClasspath
org.springframework:spring-messaging:7.0.9=runtimeClasspath,testRuntimeClasspath
org.springframework:spring-tx:7.0.9=runtimeClasspath,testRuntimeClasspath
org.xerial.snappy:snappy-java:1.1.10.7=runtimeClasspath,testRuntimeClasspath org.xerial.snappy:snappy-java:1.1.10.7=runtimeClasspath,testRuntimeClasspath
org.xmlresolver:xmlresolver:5.3.3=checkstyle,spotbugs org.xmlresolver:xmlresolver:5.3.3=checkstyle,spotbugs
empty= empty=
+3 -1
View File
@@ -12,7 +12,9 @@ auxiliarySourceSets {
} }
dependencies { dependencies {
implementation 'org.springframework.kafka:spring-kafka' // No spring-kafka. It was declared here and imported by nothing: this adapter drives the plain
// `org.apache.kafka` producer API directly, and a declared library that no source names is a
// resolution, a lock entry and a transitive surface bought for nothing.
api project(':messaging:messaging-core-api') api project(':messaging:messaging-core-api')
api project(':messaging:messaging-schema-api') api project(':messaging:messaging-schema-api')
api project(':messaging:messaging-policy') api project(':messaging:messaging-policy')
@@ -37,7 +37,6 @@ commons-codec:commons-codec:1.19.0=integrationTestCompileClasspath,integrationTe
commons-collections:commons-collections:3.2.2=checkstyle commons-collections:commons-collections:3.2.2=checkstyle
commons-io:commons-io:2.20.0=integrationTestCompileClasspath,integrationTestRuntimeClasspath commons-io:commons-io:2.20.0=integrationTestCompileClasspath,integrationTestRuntimeClasspath
commons-io:commons-io:2.21.0=spotbugs commons-io:commons-io:2.21.0=spotbugs
commons-logging:commons-logging:1.3.6=compileClasspath,integrationTestCompileClasspath,integrationTestRuntimeClasspath,jmhCompileClasspath,jmhRuntimeClasspath,runtimeClasspath,testCompileClasspath,testFixturesRuntimeClasspath,testRuntimeClasspath
eu.rekawek.toxiproxy:toxiproxy-java:2.1.7=integrationTestCompileClasspath,integrationTestRuntimeClasspath eu.rekawek.toxiproxy:toxiproxy-java:2.1.7=integrationTestCompileClasspath,integrationTestRuntimeClasspath
info.picocli:picocli:4.7.7=checkstyle info.picocli:picocli:4.7.7=checkstyle
io.github.eisop:dataflow-errorprone:3.41.0-eisop1=annotationProcessor,integrationTestAnnotationProcessor,jmhAnnotationProcessor,testAnnotationProcessor,testFixturesAnnotationProcessor io.github.eisop:dataflow-errorprone:3.41.0-eisop1=annotationProcessor,integrationTestAnnotationProcessor,jmhAnnotationProcessor,testAnnotationProcessor,testFixturesAnnotationProcessor
@@ -104,14 +103,6 @@ org.rnorth.duct-tape:duct-tape:1.0.8=integrationTestCompileClasspath,integration
org.slf4j:slf4j-api:2.0.18=integrationTestCompileClasspath,integrationTestRuntimeClasspath,jmhRuntimeClasspath,runtimeClasspath,spotbugs,spotbugsSlf4j,testFixturesRuntimeClasspath,testRuntimeClasspath org.slf4j:slf4j-api:2.0.18=integrationTestCompileClasspath,integrationTestRuntimeClasspath,jmhRuntimeClasspath,runtimeClasspath,spotbugs,spotbugsSlf4j,testFixturesRuntimeClasspath,testRuntimeClasspath
org.slf4j:slf4j-simple:2.0.17=spotbugsSlf4j org.slf4j:slf4j-simple:2.0.17=spotbugsSlf4j
org.slf4j:slf4j-simple:2.0.18=checkstyle org.slf4j:slf4j-simple:2.0.18=checkstyle
org.springframework.kafka:spring-kafka:4.0.7=compileClasspath,integrationTestCompileClasspath,integrationTestRuntimeClasspath,jmhCompileClasspath,jmhRuntimeClasspath,runtimeClasspath,testCompileClasspath,testFixturesRuntimeClasspath,testRuntimeClasspath
org.springframework:spring-aop:7.0.9=compileClasspath,integrationTestCompileClasspath,integrationTestRuntimeClasspath,jmhCompileClasspath,jmhRuntimeClasspath,runtimeClasspath,testCompileClasspath,testFixturesRuntimeClasspath,testRuntimeClasspath
org.springframework:spring-beans:7.0.9=compileClasspath,integrationTestCompileClasspath,integrationTestRuntimeClasspath,jmhCompileClasspath,jmhRuntimeClasspath,runtimeClasspath,testCompileClasspath,testFixturesRuntimeClasspath,testRuntimeClasspath
org.springframework:spring-context:7.0.9=compileClasspath,integrationTestCompileClasspath,integrationTestRuntimeClasspath,jmhCompileClasspath,jmhRuntimeClasspath,runtimeClasspath,testCompileClasspath,testFixturesRuntimeClasspath,testRuntimeClasspath
org.springframework:spring-core:7.0.9=compileClasspath,integrationTestCompileClasspath,integrationTestRuntimeClasspath,jmhCompileClasspath,jmhRuntimeClasspath,runtimeClasspath,testCompileClasspath,testFixturesRuntimeClasspath,testRuntimeClasspath
org.springframework:spring-expression:7.0.9=compileClasspath,integrationTestCompileClasspath,integrationTestRuntimeClasspath,jmhCompileClasspath,jmhRuntimeClasspath,runtimeClasspath,testCompileClasspath,testFixturesRuntimeClasspath,testRuntimeClasspath
org.springframework:spring-messaging:7.0.9=compileClasspath,integrationTestCompileClasspath,integrationTestRuntimeClasspath,jmhCompileClasspath,jmhRuntimeClasspath,runtimeClasspath,testCompileClasspath,testFixturesRuntimeClasspath,testRuntimeClasspath
org.springframework:spring-tx:7.0.9=compileClasspath,integrationTestCompileClasspath,integrationTestRuntimeClasspath,jmhCompileClasspath,jmhRuntimeClasspath,runtimeClasspath,testCompileClasspath,testFixturesRuntimeClasspath,testRuntimeClasspath
org.testcontainers:testcontainers-junit-jupiter:2.0.5=integrationTestCompileClasspath,integrationTestRuntimeClasspath org.testcontainers:testcontainers-junit-jupiter:2.0.5=integrationTestCompileClasspath,integrationTestRuntimeClasspath
org.testcontainers:testcontainers-kafka:2.0.5=integrationTestCompileClasspath,integrationTestRuntimeClasspath org.testcontainers:testcontainers-kafka:2.0.5=integrationTestCompileClasspath,integrationTestRuntimeClasspath
org.testcontainers:testcontainers-toxiproxy:2.0.5=integrationTestCompileClasspath,integrationTestRuntimeClasspath org.testcontainers:testcontainers-toxiproxy:2.0.5=integrationTestCompileClasspath,integrationTestRuntimeClasspath
@@ -524,7 +524,6 @@ class KafkaConsumerRegistrarTest {
super.commitSync(offsets); super.commitSync(offsets);
} }
} }
} }
/** Queues handler work so the in-flight ceiling is observable. */ /** Queues handler work so the in-flight ceiling is observable. */
@@ -8,6 +8,7 @@ import dev.caskeleton.messaging.api.MessageType;
import dev.caskeleton.messaging.api.SchemaVersion; import dev.caskeleton.messaging.api.SchemaVersion;
import dev.caskeleton.messaging.api.destination.DestinationName; import dev.caskeleton.messaging.api.destination.DestinationName;
import dev.caskeleton.messaging.reliability.OutboxCanonicalMetadata; import dev.caskeleton.messaging.reliability.OutboxCanonicalMetadata;
import dev.caskeleton.messaging.reliability.OutboxLease;
import dev.caskeleton.messaging.reliability.OutboxRecord; import dev.caskeleton.messaging.reliability.OutboxRecord;
import dev.caskeleton.messaging.reliability.OutboxStatus; import dev.caskeleton.messaging.reliability.OutboxStatus;
import dev.caskeleton.messaging.testkit.DockerAvailability; import dev.caskeleton.messaging.testkit.DockerAvailability;
@@ -130,9 +131,14 @@ class OutboxPostgresIT {
void anAmbiguousRowStaysClaimableUnderItsOriginalIdentity() { void anAmbiguousRowStaysClaimableUnderItsOriginalIdentity() {
OutboxRecord record = record(); OutboxRecord record = record();
appendInTransaction(record); appendInTransaction(record);
repository.leaseBatch(10, Duration.ofSeconds(30), NOW); // Claimed rather than leased: a terminal write is checked against the lease token, so
// `markAmbiguous` takes the lease that owns the row. The identity-keyed overload this test used
// to call is gone, and with it the possibility of one relay writing an outcome onto a row
// another relay currently owns.
OutboxLease lease =
repository.claimBatch("ambiguous-relay", 10, Duration.ofSeconds(30), NOW).getFirst();
repository.markAmbiguous(record.messageId(), "CONFIRM_TIMEOUT", NOW); repository.markAmbiguous(lease, "CONFIRM_TIMEOUT", NOW);
assertThat(repository.find(record.messageId()).orElseThrow().status()) assertThat(repository.find(record.messageId()).orElseThrow().status())
.isEqualTo(OutboxStatus.AMBIGUOUS); .isEqualTo(OutboxStatus.AMBIGUOUS);
@@ -131,9 +131,11 @@ class RabbitTopologyAndBatchTest {
false, false,
Duration.ofMillis(3)); Duration.ofMillis(3));
assertThat(result.failure()).hasValueSatisfying( assertThat(result.failure())
failure -> assertThat(failure.category()).isEqualTo( .hasValueSatisfying(
dev.caskeleton.messaging.api.error.FailureCategory.AUTHENTICATION)); failure ->
assertThat(failure.category())
.isEqualTo(dev.caskeleton.messaging.api.error.FailureCategory.AUTHENTICATION));
} }
@Test @Test
@@ -142,17 +144,17 @@ class RabbitTopologyAndBatchTest {
new com.rabbitmq.client.ShutdownSignalException( new com.rabbitmq.client.ShutdownSignalException(
false, false,
false, false,
new com.rabbitmq.client.impl.AMQImpl.Channel.Close( new com.rabbitmq.client.impl.AMQImpl.Channel.Close(403, "ACCESS_REFUSED", 60, 40),
403, "ACCESS_REFUSED", 60, 40),
null); null);
PublishResult result = PublishResult result =
new RabbitPublishFailureClassifier() new RabbitPublishFailureClassifier().classify(accessRefused, false, Duration.ofMillis(3));
.classify(accessRefused, false, Duration.ofMillis(3));
assertThat(result.failure()).hasValueSatisfying( assertThat(result.failure())
failure -> assertThat(failure.category()).isEqualTo( .hasValueSatisfying(
dev.caskeleton.messaging.api.error.FailureCategory.AUTHORIZATION)); failure ->
assertThat(failure.category())
.isEqualTo(dev.caskeleton.messaging.api.error.FailureCategory.AUTHORIZATION));
} }
@Test @Test
@@ -115,7 +115,8 @@ class DefaultMessagePublisherTest {
assertThat(result.completion()).isEqualTo(PublishCompletion.CONFIRMED); assertThat(result.completion()).isEqualTo(PublishCompletion.CONFIRMED);
assertThat(codecs.encodes()).isZero(); assertThat(codecs.encodes()).isZero();
assertThat(transport.lastRequest().envelope().payload().bytes()).containsExactly(wireBytes); assertThat(transport.lastRequest().envelope().payload().bytes()).containsExactly(wireBytes);
assertThat(transport.lastRequest().envelope().payload().contentType()).isEqualTo(ContentType.JSON); assertThat(transport.lastRequest().envelope().payload().contentType())
.isEqualTo(ContentType.JSON);
assertThat(admission.inFlight()).isZero(); assertThat(admission.inFlight()).isZero();
} }
@@ -98,14 +98,12 @@ org.springframework.boot:spring-boot-actuator:4.0.8=runtimeClasspath,testRuntime
org.springframework.boot:spring-boot-autoconfigure:4.0.8=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.springframework.boot:spring-boot-autoconfigure:4.0.8=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.springframework.boot:spring-boot-configuration-processor:4.0.8=annotationProcessor org.springframework.boot:spring-boot-configuration-processor:4.0.8=annotationProcessor
org.springframework.boot:spring-boot:4.0.8=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.springframework.boot:spring-boot:4.0.8=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.springframework.kafka:spring-kafka:4.0.7=runtimeClasspath,testRuntimeClasspath
org.springframework:spring-aop:7.0.9=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.springframework:spring-aop:7.0.9=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.springframework:spring-beans:7.0.9=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.springframework:spring-beans:7.0.9=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.springframework:spring-context:7.0.9=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.springframework:spring-context:7.0.9=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.springframework:spring-core:7.0.9=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.springframework:spring-core:7.0.9=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.springframework:spring-expression:7.0.9=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.springframework:spring-expression:7.0.9=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.springframework:spring-jdbc:7.0.9=runtimeClasspath,testRuntimeClasspath org.springframework:spring-jdbc:7.0.9=runtimeClasspath,testRuntimeClasspath
org.springframework:spring-messaging:7.0.9=runtimeClasspath,testRuntimeClasspath
org.springframework:spring-tx:7.0.9=runtimeClasspath,testRuntimeClasspath org.springframework:spring-tx:7.0.9=runtimeClasspath,testRuntimeClasspath
org.xerial.snappy:snappy-java:1.1.10.7=runtimeClasspath,testRuntimeClasspath org.xerial.snappy:snappy-java:1.1.10.7=runtimeClasspath,testRuntimeClasspath
org.xmlresolver:xmlresolver:5.3.3=checkstyle,spotbugs org.xmlresolver:xmlresolver:5.3.3=checkstyle,spotbugs
@@ -123,7 +123,6 @@ org.springframework.boot:spring-boot-autoconfigure:4.0.8=compileClasspath,integr
org.springframework.boot:spring-boot-configuration-processor:4.0.8=annotationProcessor org.springframework.boot:spring-boot-configuration-processor:4.0.8=annotationProcessor
org.springframework.boot:spring-boot-test:4.0.8=integrationTestCompileClasspath,integrationTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath org.springframework.boot:spring-boot-test:4.0.8=integrationTestCompileClasspath,integrationTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
org.springframework.boot:spring-boot:4.0.8=compileClasspath,integrationTestCompileClasspath,integrationTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.springframework.boot:spring-boot:4.0.8=compileClasspath,integrationTestCompileClasspath,integrationTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.springframework.kafka:spring-kafka:4.0.7=integrationTestRuntimeClasspath,testRuntimeClasspath
org.springframework:spring-aop:7.0.9=compileClasspath,integrationTestCompileClasspath,integrationTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.springframework:spring-aop:7.0.9=compileClasspath,integrationTestCompileClasspath,integrationTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.springframework:spring-beans:7.0.9=compileClasspath,integrationTestCompileClasspath,integrationTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.springframework:spring-beans:7.0.9=compileClasspath,integrationTestCompileClasspath,integrationTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.springframework:spring-context:7.0.9=compileClasspath,integrationTestCompileClasspath,integrationTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath org.springframework:spring-context:7.0.9=compileClasspath,integrationTestCompileClasspath,integrationTestRuntimeClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
@@ -48,6 +48,12 @@ public class MessagingProviderSelection {
"kafka", "dev.caskeleton.messaging.autoconfigure.KafkaMessagingAutoConfiguration", "kafka", "dev.caskeleton.messaging.autoconfigure.KafkaMessagingAutoConfiguration",
"rabbit", "dev.caskeleton.messaging.autoconfigure.RabbitMessagingAutoConfiguration"); "rabbit", "dev.caskeleton.messaging.autoconfigure.RabbitMessagingAutoConfiguration");
/** Broker id to the starter a deployment adds to its build to obtain that transport. */
static final Map<String, String> PROVIDER_STARTERS =
Map.of(
"kafka", "messaging-spring-boot-starter-kafka",
"rabbit", "messaging-spring-boot-starter-rabbit");
/** /**
* Broker ids that ship without a {@code MessagingTransport}, and why. * Broker ids that ship without a {@code MessagingTransport}, and why.
* *
@@ -118,6 +124,23 @@ public class MessagingProviderSelection {
+ clientClass + clientClass
+ " on the classpath; the deployment selected a transport it did not ship"); + " on the classpath; the deployment selected a transport it did not ship");
} }
// The client library and the broker starter are two different build decisions, and only the
// second one carries the configuration that assembles the transport. A deployment can hold the
// Kafka client transitively and still not ship the Kafka starter — this core starter is
// broker-neutral on purpose — and until this check existed that combination reached Spring's
// import machinery, which reported a missing .class file rather than a missing capability.
String providerConfiguration = PROVIDER_CONFIGURATIONS.get(broker);
if (!ClassUtils.isPresent(
providerConfiguration, MessagingProviderSelection.class.getClassLoader())) {
throw new IllegalStateException(
MessagingSettings.PREFIX
+ ".broker="
+ broker
+ " needs the "
+ PROVIDER_STARTERS.get(broker)
+ " module on the classpath; this core starter is broker-neutral and the deployment"
+ " did not compose the transport it selected");
}
String unfinished = BROKERS_WITHOUT_A_TRANSPORT.get(broker); String unfinished = BROKERS_WITHOUT_A_TRANSPORT.get(broker);
if (unfinished != null) { if (unfinished != null) {
throw new IllegalStateException( throw new IllegalStateException(
@@ -0,0 +1,104 @@
package dev.caskeleton.messaging.autoconfigure;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.core.annotation.AnnotatedElementUtils;
/**
* This leaf's auto-configurations are registered, not merely annotated.
*
* <p>Spring Boot needs two independent things before an auto-configuration runs: the annotation on
* the class, and a line naming it in {@code META-INF/spring/...AutoConfiguration.imports}. Tests
* that build a context with {@code AutoConfigurations.of(...)} supply the second one themselves, so
* they stay green for a capability that is present in no running application — which is exactly how
* several capabilities in this repository came to be assembled by nothing.
*
* <p>So this reads the registration file the jar actually ships and asserts both directions: every
* class this leaf means to register is named in it, and every name in it resolves to a class that
* carries {@code @AutoConfiguration}. A rename, a move or a deleted line fails here rather than in
* a deployment that starts and quietly does less than it says.
*/
class MessagingPlatformAutoConfigurationRegistrationTest {
private static final String IMPORTS_RESOURCE =
"META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports";
/** The auto-configurations this leaf publishes. */
private static final List<String> PUBLISHED_ROOTS =
List.of("dev.caskeleton.messaging.autoconfigure.MessagingPlatformRootAutoConfiguration");
@Test
@DisplayName("the shipped registration file names every root this leaf publishes")
void theShippedRegistrationFileNamesEveryRoot() {
assertThat(registeredNames())
.as("the registration lines this leaf's own jar ships")
.containsAll(PUBLISHED_ROOTS);
}
@Test
@DisplayName("every registered name resolves to a real Boot auto-configuration")
void everyRegisteredNameResolvesToAnAutoConfiguration() {
for (String name : registeredNames()) {
Class<?> registered;
try {
registered =
Class.forName(
name,
false,
MessagingPlatformAutoConfigurationRegistrationTest.class.getClassLoader());
} catch (ClassNotFoundException missing) {
throw new AssertionError(
IMPORTS_RESOURCE + " registers " + name + ", which does not exist", missing);
}
assertThat(AnnotatedElementUtils.hasAnnotation(registered, AutoConfiguration.class))
.as("%s is registered but is not annotated @AutoConfiguration", name)
.isTrue();
}
}
/**
* The registration lines this leaf's own resource declares.
*
* <p>Read from this leaf's source tree rather than from the classpath. {@code
* ClassLoader#getResources} returns every registration file on the test runtime classpath —
* Spring Boot's, springdoc's, and every dependency leaf's — so asserting over that set tests
* other people's modules and fails on their conditional classes. The file below is the one this
* leaf packages, which is the thing this contract is about.
*/
private static List<String> registeredNames() {
Path resource = leafRoot().resolve("src/main/resources/" + IMPORTS_RESOURCE);
assertThat(Files.isRegularFile(resource)).as("%s", resource).isTrue();
List<String> names;
try {
names =
Files.readAllLines(resource, StandardCharsets.UTF_8).stream()
.map(String::strip)
.filter(line -> !line.isEmpty() && !line.startsWith("#"))
.toList();
} catch (IOException failure) {
throw new UncheckedIOException("cannot read " + resource, failure);
}
assertThat(names).as("%s registers nothing", resource).isNotEmpty();
return names;
}
/** The nearest directory above the test's working directory that ships a registration file. */
private static Path leafRoot() {
for (Path path = Path.of("").toAbsolutePath(); path != null; path = path.getParent()) {
if (Files.isRegularFile(path.resolve("src/main/resources/" + IMPORTS_RESOURCE))) {
return path;
}
}
throw new IllegalStateException(
"no leaf shipping " + IMPORTS_RESOURCE + " found above " + Path.of("").toAbsolutePath());
}
}