Skip to content

Commit

Permalink
Polish "Enable Spring Pulsar with Spring Boot 3.2.x"
Browse files Browse the repository at this point in the history
  • Loading branch information
snicoll committed Sep 21, 2023
1 parent 8d7ae8a commit a74c15e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package io.spring.start.site.extension.dependency.springpulsar;

import java.util.Map;

import io.spring.initializr.generator.buildsystem.Dependency;
import io.spring.initializr.generator.condition.ConditionalOnPlatformVersion;
import io.spring.initializr.generator.condition.ConditionalOnRequestedDependency;
import io.spring.initializr.generator.condition.ProjectGenerationCondition;
Expand All @@ -26,6 +29,7 @@
import io.spring.start.site.container.DockerServiceResolver;
import io.spring.start.site.container.ServiceConnections;
import io.spring.start.site.container.ServiceConnectionsCustomizer;
import io.spring.start.site.extension.dependency.springpulsar.SpringPulsarProjectGenerationConfiguration.OnPulsarDependencyCondition;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ConditionContext;
Expand All @@ -38,13 +42,13 @@
* @author Chris Bono
*/
@ProjectGenerationConfiguration
@Conditional(SpringPulsarProjectGenerationConfiguration.OnPulsarRequestedDependencyCondition.class)
@Conditional(OnPulsarDependencyCondition.class)
class SpringPulsarProjectGenerationConfiguration {

private static final String TESTCONTAINERS_CLASS_NAME = "org.testcontainers.containers.PulsarContainer";

@Bean
@ConditionalOnPlatformVersion("3.2.0-SNAPSHOT")
@ConditionalOnPlatformVersion("3.2.0-M3")
@ConditionalOnRequestedDependency("testcontainers")
ServiceConnectionsCustomizer pulsarServiceConnectionsCustomizer(DockerServiceResolver serviceResolver) {
return (serviceConnections) -> serviceResolver.doWith("pulsar",
Expand All @@ -53,7 +57,7 @@ ServiceConnectionsCustomizer pulsarServiceConnectionsCustomizer(DockerServiceRes
}

@Bean
@ConditionalOnPlatformVersion("3.2.0-SNAPSHOT")
@ConditionalOnPlatformVersion("3.2.0-M3")
@ConditionalOnRequestedDependency("docker-compose")
ComposeFileCustomizer pulsarComposeFileCustomizer(DockerServiceResolver serviceResolver) {
return (composeFile) -> serviceResolver.doWith("pulsar",
Expand All @@ -68,13 +72,13 @@ SpringPulsarBinderBuildCustomizer pulsarBinderBuildCustomizer(InitializrMetadata
return new SpringPulsarBinderBuildCustomizer(metadata, description);
}

static class OnPulsarRequestedDependencyCondition extends ProjectGenerationCondition {
static class OnPulsarDependencyCondition extends ProjectGenerationCondition {

@Override
protected boolean matches(ProjectDescription description, ConditionContext context,
AnnotatedTypeMetadata metadata) {
return description.getRequestedDependencies().containsKey("pulsar")
|| description.getRequestedDependencies().containsKey("pulsar-reactive");
Map<String, Dependency> requestedDependencies = description.getRequestedDependencies();
return requestedDependencies.containsKey("pulsar") || requestedDependencies.containsKey("pulsar-reactive");
}

}
Expand Down
8 changes: 3 additions & 5 deletions start-site/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -786,20 +786,19 @@ initializr:
href: https://docs.spring.io/spring-boot/docs/{bootVersion}/reference/htmlsingle/index.html#messaging.jms.artemis
- name: Spring for Apache Pulsar
id: pulsar
compatibilityRange: "[3.0.0,3.2.0-SNAPSHOT]"
compatibilityRange: "3.0.0"
description: Build messaging applications with Apache Pulsar
links:
- rel: reference
href: https://docs.spring.io/spring-boot/docs/{bootVersion}/reference/htmlsingle/index.html#messaging.pulsar
mappings:
- compatibilityRange: "[3.0.0,3.2.0-M1)"
- compatibilityRange: "[3.0.0,3.2.0-M3)"
version: 0.2.0
groupId: org.springframework.pulsar
artifactId: spring-pulsar-spring-boot-starter
starter: false
- name: Spring for Apache Pulsar (Reactive)
id: pulsar-reactive
compatibilityRange: "[3.0.0,3.2.0-SNAPSHOT]"
compatibilityRange: "3.0.0"
description: Build reactive messaging applications with Apache Pulsar
facets:
- reactive
Expand All @@ -811,7 +810,6 @@ initializr:
version: 0.2.0
groupId: org.springframework.pulsar
artifactId: spring-pulsar-reactive-spring-boot-starter
starter: false
- name: WebSocket
id: websocket
description: Build Servlet-based WebSocket applications with SockJS and STOMP.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ void pulsarReactiveLegacyStarterUsedWhenBoot30orBoot31Selected(String bootVersio
@Test
void pulsarBootStarterUsedWhenBoot32Selected() {
ProjectRequest request = createProjectRequest("pulsar");
request.setBootVersion("3.2.0-SNAPSHOT");
request.setBootVersion("3.2.0-M3");
ProjectStructure project = generateProject(request);
assertThat(project).mavenBuild().hasDependency("org.springframework.boot", "spring-boot-starter-pulsar");
}

@Test
void pulsarReactiveBootStarterUsedWhenBoot32Selected() {
ProjectRequest request = createProjectRequest("pulsar-reactive");
request.setBootVersion("3.2.0-SNAPSHOT");
request.setBootVersion("3.2.0-M3");
ProjectStructure project = generateProject(request);
assertThat(project).mavenBuild()
.hasDependency("org.springframework.boot", "spring-boot-starter-pulsar-reactive");
Expand All @@ -92,7 +92,7 @@ class DockerComposeConfigurationTests {
@Test
void serviceNotCreatedWhenDockerComposeNotSelected() {
ProjectRequest request = createProjectRequest("pulsar");
request.setBootVersion("3.2.0-SNAPSHOT");
request.setBootVersion("3.2.0-M3");
ProjectStructure structure = generateProject(request);
assertThat(structure.getProjectDirectory().resolve("compose.yaml")).doesNotExist();
}
Expand All @@ -109,7 +109,7 @@ void serviceNotCreatedWhenIncompatibleBootVersionSelected(String bootVersion) {
@ValueSource(strings = { "pulsar", "pulsar-reactive" })
void serviceCreatedWhenDockerComposeSelectedWithCompatibleBootVersion(String pulsarDependencyId) {
ProjectRequest request = createProjectRequest("docker-compose", pulsarDependencyId);
request.setBootVersion("3.2.0-SNAPSHOT");
request.setBootVersion("3.2.0-M3");
assertThat(composeFile(request)).hasSameContentAs(new ClassPathResource("compose/pulsar.yaml"));
}

Expand All @@ -120,12 +120,12 @@ class ServiceConnectionConfigurationTests {

private final ProjectAssetTester projectTester = new ProjectAssetTester()
.withConfiguration(SpringPulsarProjectGenerationConfiguration.class)
.withBean(DockerServiceResolver.class, () -> new SimpleDockerServiceResolver());
.withBean(DockerServiceResolver.class, SimpleDockerServiceResolver::new);

@Test
void connectionNotAddedWhenTestcontainersNotSelected() {
MutableProjectDescription description = new MutableProjectDescription();
description.setPlatformVersion(Version.parse("3.2.0-SNAPSHOT"));
description.setPlatformVersion(Version.parse("3.2.0-M3"));
description.addDependency("pulsar", mock(Dependency.class));
this.projectTester.configure(description,
(context) -> assertThat(context).doesNotHaveBean("pulsarServiceConnectionsCustomizer"));
Expand All @@ -134,7 +134,7 @@ void connectionNotAddedWhenTestcontainersNotSelected() {
@Test
void connectionNotAddedWhenPulsarNotSelected() {
MutableProjectDescription description = new MutableProjectDescription();
description.setPlatformVersion(Version.parse("3.2.0-SNAPSHOT"));
description.setPlatformVersion(Version.parse("3.2.0-M3"));
description.addDependency("testcontainers", mock(Dependency.class));
this.projectTester.configure(description,
(context) -> assertThat(context).doesNotHaveBean("pulsarServiceConnectionsCustomizer"));
Expand All @@ -155,7 +155,7 @@ void connectionNotAddedWhenIncompatibleBootVersionSelected(String bootVersion) {
@ValueSource(strings = { "pulsar", "pulsar-reactive" })
void connectionAddedWhenTestcontainersAndPulsarSelectedWithCompatibleBootVersion(String pulsarDependencyId) {
MutableProjectDescription description = new MutableProjectDescription();
description.setPlatformVersion(Version.parse("3.2.0-SNAPSHOT"));
description.setPlatformVersion(Version.parse("3.2.0-M3"));
description.addDependency("testcontainers", mock(Dependency.class));
description.addDependency(pulsarDependencyId, mock(Dependency.class));
this.projectTester.configure(description,
Expand All @@ -164,11 +164,11 @@ void connectionAddedWhenTestcontainersAndPulsarSelectedWithCompatibleBootVersion
.satisfies((customizer) -> {
ServiceConnections connections = new ServiceConnections();
customizer.customize(connections);
assertPulsarServiceConnectionAddded(connections);
assertPulsarServiceConnectionAdded(connections);
}));
}

private void assertPulsarServiceConnectionAddded(ServiceConnections connections) {
private void assertPulsarServiceConnectionAdded(ServiceConnections connections) {
assertThat(connections.values()).first().satisfies((connection) -> {
assertThat(connection.id()).isEqualTo("pulsar");
assertThat(connection.containerClassName()).isEqualTo("org.testcontainers.containers.PulsarContainer");
Expand Down Expand Up @@ -208,7 +208,7 @@ void binderNotAddedWhenPulsarNotSelected() {
}

@ParameterizedTest
@ValueSource(strings = { "3.2.0-M1", "3.2.0-SNAPSHOT" })
@ValueSource(strings = { "3.2.0-M1", "3.2.0-M3" })
void binderNotAddedWhenPulsarAndCloudStreamSelectedWithIncompatibleBootVersion(String bootVersion) {
ProjectRequest request = createProjectRequest("pulsar", "cloud-stream");
request.setBootVersion(bootVersion);
Expand All @@ -217,7 +217,7 @@ void binderNotAddedWhenPulsarAndCloudStreamSelectedWithIncompatibleBootVersion(S
}

@ParameterizedTest
@ValueSource(strings = { "3.0.0", "3.1.3", "3.1.4-SNAPSHOT" })
@ValueSource(strings = { "3.0.0", "3.1.3" })
void binderAddedWhenPulsarAndCloudStreamSelectedWithCompatibleBootVersion(String bootVersion) {
ProjectRequest request = createProjectRequest("pulsar", "cloud-stream");
request.setBootVersion(bootVersion);
Expand All @@ -226,7 +226,7 @@ void binderAddedWhenPulsarAndCloudStreamSelectedWithCompatibleBootVersion(String
}

@ParameterizedTest
@ValueSource(strings = { "3.0.0", "3.1.3", "3.1.4-SNAPSHOT" })
@ValueSource(strings = { "3.0.0", "3.1.3" })
void binderAddedWhenPulsarReactiveAndCloudStreamSelectedWithCompatibleBootVersion(String bootVersion) {
ProjectRequest request = createProjectRequest("pulsar-reactive", "cloud-stream");
request.setBootVersion(bootVersion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import io.spring.initializr.generator.test.io.TextAssert;
import io.spring.initializr.generator.test.project.ProjectStructure;
import io.spring.initializr.generator.version.Version;
import io.spring.initializr.web.project.ProjectRequest;
import io.spring.start.site.extension.AbstractExtensionTests;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -51,7 +52,7 @@ void buildWithOnlyTestContainers() {
void buildWithSupportedEntries(String springBootDependencyId, String testcontainersArtifactId) {
assertThat(generateProject("3.0.0", "testcontainers", springBootDependencyId)).mavenBuild()
.hasBom("org.testcontainers", "testcontainers-bom", "${testcontainers.version}")
.hasDependency(getDependency(springBootDependencyId))
.hasDependency(getDependency(springBootDependencyId).resolve(Version.parse("3.0.0")))
.hasDependency("org.testcontainers", testcontainersArtifactId, null, "test")
.hasDependency(getDependency("testcontainers"));
}
Expand Down

0 comments on commit a74c15e

Please sign in to comment.