Skip to content

Commit

Permalink
Restructure testcontainers configuration classes
Browse files Browse the repository at this point in the history
  • Loading branch information
mhalbritter committed Nov 13, 2023
1 parent abbc0de commit 26a4f9c
Showing 1 changed file with 52 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
* Configuration for generation of projects that depend on Testcontainers.
Expand Down Expand Up @@ -69,7 +68,7 @@ public ImplicitDependencyHelpDocumentCustomizer testcontainersHelpCustomizer(Bui

@Configuration(proxyBeanMethods = false)
@ConditionalOnPlatformVersion("3.1.0-RC1")
static class ServiceConnectionsConfiguration {
static class SpringBoot31Configuration {

@Bean
ServiceConnections serviceConnections(ObjectProvider<ServiceConnectionsCustomizer> customizers) {
Expand All @@ -78,67 +77,64 @@ ServiceConnections serviceConnections(ObjectProvider<ServiceConnectionsCustomize
return serviceConnections;
}

}
@Configuration(proxyBeanMethods = false)
static class SpringBootSupportConfiguration {

@Configuration(proxyBeanMethods = false)
@ConditionalOnPlatformVersion("3.1.0-RC1")
@Import(ServiceConnectionsConfiguration.class)
static class SpringBootSupportConfiguration {
@Bean
BuildCustomizer<Build> springBootTestcontainersBuildCustomizer() {
return (build) -> build.dependencies()
.add("spring-boot-testcontainers",
Dependency.withCoordinates("org.springframework.boot", "spring-boot-testcontainers")
.scope(DependencyScope.TEST_COMPILE));

@Bean
BuildCustomizer<Build> springBootTestcontainersBuildCustomizer() {
return (build) -> build.dependencies()
.add("spring-boot-testcontainers",
Dependency.withCoordinates("org.springframework.boot", "spring-boot-testcontainers")
.scope(DependencyScope.TEST_COMPILE));
}

}
@Bean
TestContainersHelpDocumentCustomizer springBootTestcontainersHelpDocumentCustomizer(
ProjectDescription description, ServiceConnections serviceConnections) {
return new TestContainersHelpDocumentCustomizer(description, serviceConnections);
}

@Bean
TestContainersHelpDocumentCustomizer springBootTestcontainersHelpDocumentCustomizer(
ProjectDescription description, ServiceConnections serviceConnections) {
return new TestContainersHelpDocumentCustomizer(description, serviceConnections);
}

}

@Configuration(proxyBeanMethods = false)
@ConditionalOnPlatformVersion("3.1.0-RC1")
@Import(ServiceConnectionsConfiguration.class)
static class TestApplicationConfiguration {

private final ProjectDescription description;
@Configuration(proxyBeanMethods = false)
static class TestApplicationConfiguration {

private final ProjectDescription description;

private final IndentingWriterFactory indentingWriterFactory;

TestApplicationConfiguration(ProjectDescription description,
IndentingWriterFactory indentingWriterFactory) {
this.description = description;
this.indentingWriterFactory = indentingWriterFactory;
}

@Bean
@ConditionalOnLanguage(GroovyLanguage.ID)
GroovyTestContainersApplicationCodeProjectContributor groovyTestContainersApplicationCodeProjectContributor(
ServiceConnections serviceConnections) {
return new GroovyTestContainersApplicationCodeProjectContributor(this.indentingWriterFactory,
this.description, serviceConnections);
}

@Bean
@ConditionalOnLanguage(KotlinLanguage.ID)
@ConditionalOnPlatformVersion("3.1.1-SNAPSHOT") // https://github.com/spring-projects/spring-boot/issues/35756
KotlinTestContainersApplicationCodeProjectContributor kotlinTestContainersApplicationCodeProjectContributor(
ServiceConnections serviceConnections) {
return new KotlinTestContainersApplicationCodeProjectContributor(this.indentingWriterFactory,
this.description, serviceConnections);
}

@Bean
@ConditionalOnLanguage(JavaLanguage.ID)
JavaTestContainersApplicationCodeProjectContributor javaTestContainersApplicationCodeProjectContributor(
ServiceConnections serviceConnections) {
return new JavaTestContainersApplicationCodeProjectContributor(this.indentingWriterFactory,
this.description, serviceConnections);
}

private final IndentingWriterFactory indentingWriterFactory;

TestApplicationConfiguration(ProjectDescription description, IndentingWriterFactory indentingWriterFactory) {
this.description = description;
this.indentingWriterFactory = indentingWriterFactory;
}

@Bean
@ConditionalOnLanguage(GroovyLanguage.ID)
GroovyTestContainersApplicationCodeProjectContributor groovyTestContainersApplicationCodeProjectContributor(
ServiceConnections serviceConnections) {
return new GroovyTestContainersApplicationCodeProjectContributor(this.indentingWriterFactory,
this.description, serviceConnections);
}

@Bean
@ConditionalOnLanguage(KotlinLanguage.ID)
@ConditionalOnPlatformVersion("3.1.1-SNAPSHOT") // https://github.com/spring-projects/spring-boot/issues/35756
KotlinTestContainersApplicationCodeProjectContributor kotlinTestContainersApplicationCodeProjectContributor(
ServiceConnections serviceConnections) {
return new KotlinTestContainersApplicationCodeProjectContributor(this.indentingWriterFactory,
this.description, serviceConnections);
}

@Bean
@ConditionalOnLanguage(JavaLanguage.ID)
JavaTestContainersApplicationCodeProjectContributor javaTestContainersApplicationCodeProjectContributor(
ServiceConnections serviceConnections) {
return new JavaTestContainersApplicationCodeProjectContributor(this.indentingWriterFactory,
this.description, serviceConnections);
}

}
Expand Down

0 comments on commit 26a4f9c

Please sign in to comment.