Skip to content

Commit

Permalink
Merge pull request #1415 from eddumelendez
Browse files Browse the repository at this point in the history
* pr/1415-2:
  Add ActiveMQ module when ActiveMQ/Artemis and Testcontainers are selected

Closes gh-1415
  • Loading branch information
mhalbritter committed Mar 1, 2024
2 parents 9fa955b + 3d43100 commit 2a6a9ec
Show file tree
Hide file tree
Showing 10 changed files with 194 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class SimpleDockerServiceResolver implements DockerServiceResolver {
public SimpleDockerServiceResolver() {
this.dockerServices = new HashMap<>();
this.dockerServices.put("activeMQ", activeMQ());
this.dockerServices.put("activeMQClassic", activeMQClassic());
this.dockerServices.put("artemis", artemis());
this.dockerServices.put("cassandra", cassandra());
this.dockerServices.put("elasticsearch", elasticsearch());
this.dockerServices.put("kafka", kafka());
Expand All @@ -59,6 +61,20 @@ private static DockerService activeMQ() {
.build();
}

private static DockerService activeMQClassic() {
return DockerService.withImageAndTag("apache/activemq-classic")
.website("https://hub.docker.com/r/apache/activemq-classic")
.ports(61616)
.build();
}

private static DockerService artemis() {
return DockerService.withImageAndTag("apache/activemq-artemis")
.website("https://hub.docker.com/r/apache/activemq-artemis")
.ports(61616)
.build();
}

private static DockerService cassandra() {
return DockerService.withImageAndTag("cassandra")
.website("https://hub.docker.com/_/cassandra")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 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.
Expand Down Expand Up @@ -35,20 +35,39 @@
@ConditionalOnRequestedDependency("activemq")
public class ActiveMQProjectGenerationConfiguration {

private static final String TESTCONTAINERS_CLASS_NAME = "org.testcontainers.activemq.ActiveMQContainer";

@Bean
@ConditionalOnPlatformVersion("3.2.0-M1")
@ConditionalOnPlatformVersion("[3.2.0-M1,3.3.0-M2)")
@ConditionalOnRequestedDependency("testcontainers")
ServiceConnectionsCustomizer activeMQServiceConnectionsCustomizer(DockerServiceResolver serviceResolver) {
return (serviceConnections) -> serviceResolver.doWith("activeMQ", (service) -> serviceConnections
.addServiceConnection(ServiceConnection.ofGenericContainer("activeMQ", service, "symptoma/activemq")));
}

@Bean
@ConditionalOnPlatformVersion("3.2.0-M1")
@ConditionalOnPlatformVersion("3.3.0-M2")
@ConditionalOnRequestedDependency("testcontainers")
ServiceConnectionsCustomizer activeMQClassicServiceConnectionsCustomizer(DockerServiceResolver serviceResolver) {
return (serviceConnections) -> serviceResolver.doWith("activeMQClassic",
(service) -> serviceConnections.addServiceConnection(
ServiceConnection.ofContainer("activemq", service, TESTCONTAINERS_CLASS_NAME, false)));
}

@Bean
@ConditionalOnPlatformVersion("[3.2.0-M1,3.3.0-M2)")
@ConditionalOnRequestedDependency("docker-compose")
ComposeFileCustomizer activeMQComposeFileCustomizer(DockerServiceResolver serviceResolver) {
return (composeFile) -> serviceResolver.doWith("activeMQ",
(service) -> composeFile.services().add("activemq", service));
}

@Bean
@ConditionalOnPlatformVersion("3.3.0-M2")
@ConditionalOnRequestedDependency("docker-compose")
ComposeFileCustomizer activeMQClassicComposeFileCustomizer(DockerServiceResolver serviceResolver) {
return (composeFile) -> serviceResolver.doWith("activeMQClassic",
(service) -> composeFile.services().add("activemq", service));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2012-2024 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 io.spring.start.site.extension.dependency.activemq;

import io.spring.initializr.generator.condition.ConditionalOnPlatformVersion;
import io.spring.initializr.generator.condition.ConditionalOnRequestedDependency;
import io.spring.initializr.generator.project.ProjectGenerationConfiguration;
import io.spring.start.site.container.ComposeFileCustomizer;
import io.spring.start.site.container.DockerServiceResolver;
import io.spring.start.site.container.ServiceConnections.ServiceConnection;
import io.spring.start.site.container.ServiceConnectionsCustomizer;

import org.springframework.context.annotation.Bean;

/**
* Configuration for generation of projects that depend on ActiveMQ Artemis.
*
* @author Eddú Meléndez
*/
@ProjectGenerationConfiguration
@ConditionalOnRequestedDependency("artemis")
public class ArtemisProjectGenerationConfiguration {

private static final String TESTCONTAINERS_CLASS_NAME = "org.testcontainers.activemq.ArtemisContainer";

@Bean
@ConditionalOnPlatformVersion("3.3.0-M2")
@ConditionalOnRequestedDependency("testcontainers")
ServiceConnectionsCustomizer artemisServiceConnectionsCustomizer(DockerServiceResolver serviceResolver) {
return (serviceConnections) -> serviceResolver.doWith("artemis", (service) -> serviceConnections
.addServiceConnection(ServiceConnection.ofContainer("artemis", service, TESTCONTAINERS_CLASS_NAME, false)));
}

@Bean
@ConditionalOnPlatformVersion("3.3.0-M2")
@ConditionalOnRequestedDependency("docker-compose")
ComposeFileCustomizer artemisComposeFileCustomizer(DockerServiceResolver serviceResolver) {
return (composeFile) -> serviceResolver.doWith("artemis",
(service) -> composeFile.services().add("artemis", service));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,16 @@ abstract class TestcontainersModuleRegistry {

private static final VersionRange SPRING_BOOT_3_2_0_OR_LATER = VersionParser.DEFAULT.parseRange("3.2.0");

private static final VersionRange SPRING_BOOT_3_3_0_M2_OR_LATER = VersionParser.DEFAULT.parseRange("3.3.0-M2");

static Iterable<ImplicitDependency> create(Version platformVersion) {
List<ImplicitDependency.Builder> builders = new ArrayList<>();
if (SPRING_BOOT_3_3_0_M2_OR_LATER.match(platformVersion)) {
builders.add(onDependencies("activemq").customizeBuild(addModule("activemq"))
.customizeHelpDocument(addReferenceLink("ActiveMQ Module", "activemq/")));
builders.add(onDependencies("artemis").customizeBuild(addModule("activemq"))
.customizeHelpDocument(addReferenceLink("ActiveMQ Module", "activemq/")));
}
builders.add(onDependencies("amqp", "amqp-streams").customizeBuild(addModule("rabbitmq"))
.customizeHelpDocument(addReferenceLink("RabbitMQ Module", "rabbitmq/")));
builders.add(onDependencies("cloud-gcp", "cloud-gcp-pubsub").customizeBuild(addModule("gcloud"))
Expand Down
1 change: 1 addition & 0 deletions start-site/src/main/resources/META-INF/spring.factories
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ io.spring.start.site.extension.build.gradle.GradleProjectGenerationConfiguration
io.spring.start.site.extension.build.maven.MavenProjectGenerationConfiguration,\
io.spring.start.site.extension.dependency.DependencyProjectGenerationConfiguration,\
io.spring.start.site.extension.dependency.activemq.ActiveMQProjectGenerationConfiguration,\
io.spring.start.site.extension.dependency.activemq.ArtemisProjectGenerationConfiguration,\
io.spring.start.site.extension.dependency.cassandra.CassandraProjectGenerationConfiguration,\
io.spring.start.site.extension.dependency.derby.DerbyProjectGenerationConfiguration,\
io.spring.start.site.extension.dependency.dgs.DgsCodegenProjectGenerationConfiguration,\
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 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.
Expand Down Expand Up @@ -29,6 +29,7 @@
* Tests for {@link ActiveMQProjectGenerationConfiguration}.
*
* @author Stephane Nicoll
* @author Eddú Meléndez
*/
class ActiveMQProjectGenerationConfigurationTests extends AbstractExtensionTests {

Expand All @@ -54,4 +55,11 @@ void dockerComposeCreatesAppropriateService() {
assertThat(composeFile(request)).hasSameContentAs(new ClassPathResource("compose/activemq.yaml"));
}

@Test
void dockerComposeCreatesAppropriateServiceWithVersion33() {
ProjectRequest request = createProjectRequest("docker-compose", "activemq");
request.setBootVersion("3.3.0-M2");
assertThat(composeFile(request)).hasSameContentAs(new ClassPathResource("compose/activemq-classic.yaml"));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2012-2024 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 io.spring.start.site.extension.dependency.activemq;

import io.spring.initializr.generator.test.project.ProjectStructure;
import io.spring.initializr.web.project.ProjectRequest;
import io.spring.start.site.extension.AbstractExtensionTests;
import org.junit.jupiter.api.Test;

import org.springframework.core.io.ClassPathResource;

import static org.assertj.core.api.Assertions.assertThat;

/**
* Tests for {@link ArtemisProjectGenerationConfiguration}.
*
* @author Eddú Meléndez
*/
class ArtemisProjectGenerationConfigurationTests extends AbstractExtensionTests {

@Test
void dockerComposeWhenDockerComposeIsNotSelectedDoesNotCreateService() {
ProjectRequest request = createProjectRequest("web", "artemis");
request.setBootVersion("3.3.0-M2");
ProjectStructure structure = generateProject(request);
assertThat(structure.getProjectDirectory().resolve("compose.yaml")).doesNotExist();
}

@Test
void dockerComposeWhenIncompatibleSpringBootVersionDoesNotCreateService() {
ProjectRequest request = createProjectRequest("docker-compose", "artemis");
request.setBootVersion("3.1.1");
assertThat(composeFile(request)).doesNotContain("artemis");
}

@Test
void dockerComposeCreatesAppropriateService() {
ProjectRequest request = createProjectRequest("docker-compose", "artemis");
request.setBootVersion("3.3.0-M2");
assertThat(composeFile(request)).hasSameContentAs(new ClassPathResource("compose/artemis.yaml"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ void buildWithSpringBoot32AndOracleJdbcDriverUsesOracleFree() {
.hasDependency(getDependency("testcontainers"));
}

@ParameterizedTest
@MethodSource("supportedTestcontainersActiveMQEntriesBuild")
void buildWithSpringBoot33AndTestcontainersActiveMQModule(String springBootDependencyId,
String testcontainersArtifactId) {
assertThat(generateProject("3.3.0", "testcontainers", springBootDependencyId)).mavenBuild()
.doesNotHaveBom("org.testcontainers", "testcontainers-bom")
.hasDependency(getDependency(springBootDependencyId).resolve(Version.parse("3.3.0")))
.hasDependency("org.testcontainers", testcontainersArtifactId, null, "test")
.hasDependency(getDependency("testcontainers"));
}

static Stream<Arguments> supportedEntriesBuild() {
return Stream.of(Arguments.arguments("amqp", "rabbitmq"), Arguments.of("amqp-streams", "rabbitmq"),
Arguments.arguments("cloud-gcp", "gcloud"), Arguments.arguments("cloud-gcp-pubsub", "gcloud"),
Expand All @@ -83,6 +94,10 @@ static Stream<Arguments> supportedEntriesBuild() {
Arguments.arguments("solace", "solace"), Arguments.arguments("sqlserver", "mssqlserver"));
}

static Stream<Arguments> supportedTestcontainersActiveMQEntriesBuild() {
return Stream.of(Arguments.arguments("activemq", "activemq"), Arguments.arguments("artemis", "activemq"));
}

@ParameterizedTest
@MethodSource("supportedEntriesHelpDocument")
void linkToSupportedEntriesWhenTestContainerIsPresentIsAdded(String dependencyId, String docHref) {
Expand Down
5 changes: 5 additions & 0 deletions start-site/src/test/resources/compose/activemq-classic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
services:
activemq:
image: 'apache/activemq-classic:latest'
ports:
- '61616'
5 changes: 5 additions & 0 deletions start-site/src/test/resources/compose/artemis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
services:
artemis:
image: 'apache/activemq-artemis:latest'
ports:
- '61616'

0 comments on commit 2a6a9ec

Please sign in to comment.