Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate test app when RabbitMQ Streams is selected #1611

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 All @@ -16,6 +16,7 @@

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

import io.spring.initializr.generator.buildsystem.Build;
import io.spring.initializr.generator.condition.ConditionalOnRequestedDependency;
import io.spring.initializr.generator.project.ProjectGenerationConfiguration;
import io.spring.start.site.container.ComposeFileCustomizer;
Expand All @@ -29,35 +30,47 @@
* Configuration for generation of projects that depend on Spring AMQP.
*
* @author Stephane Nicoll
* @author Stephane Nicoll
* @author Eddú Meléndez
*/
@ProjectGenerationConfiguration
@ConditionalOnRequestedDependency("amqp")
class SpringAmqpProjectGenerationConfiguration {

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

@Bean
@ConditionalOnRequestedDependency("amqp")
SpringRabbitTestBuildCustomizer springAmqpTestBuildCustomizer() {
return new SpringRabbitTestBuildCustomizer();
}

@Bean
@ConditionalOnRequestedDependency("testcontainers")
ServiceConnectionsCustomizer rabbitServiceConnectionsCustomizer(DockerServiceResolver serviceResolver) {
return (serviceConnections) -> serviceResolver.doWith("rabbit", (service) -> serviceConnections
.addServiceConnection(ServiceConnection.ofContainer("rabbit", service, TESTCONTAINERS_CLASS_NAME, false)));
ServiceConnectionsCustomizer rabbitServiceConnectionsCustomizer(Build build,
DockerServiceResolver serviceResolver) {
return (serviceConnections) -> serviceResolver.doWith("rabbit", (service) -> {
if (isAmqpEnabled(build)) {
serviceConnections.addServiceConnection(
ServiceConnection.ofContainer("rabbit", service, TESTCONTAINERS_CLASS_NAME, false));
}
});
}

@Bean
@ConditionalOnRequestedDependency("docker-compose")
ComposeFileCustomizer rabbitComposeFileCustomizer(DockerServiceResolver serviceResolver) {
return (composeFile) -> serviceResolver.doWith("rabbit",
(service) -> composeFile.services()
ComposeFileCustomizer rabbitComposeFileCustomizer(Build build, DockerServiceResolver serviceResolver) {
return (composeFile) -> serviceResolver.doWith("rabbit", (service) -> {
if (isAmqpEnabled(build)) {
composeFile.services()
.add("rabbitmq",
service.andThen((builder) -> builder.environment("RABBITMQ_DEFAULT_USER", "myuser")
.environment("RABBITMQ_DEFAULT_PASS", "secret")
.ports(5672))));
.ports(5672)));
}
});
}

private boolean isAmqpEnabled(Build build) {
return build.dependencies().has("amqp") || build.dependencies().has("amqp-streams");
}

}
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,6 +35,7 @@
*
* @author Stephane Nicoll
* @author Moritz Halbritter
* @author Eddú Meléndez
*/
class SpringAmqpProjectGenerationConfigurationTests extends AbstractExtensionTests {

Expand Down Expand Up @@ -70,4 +71,17 @@ void springAmqpWithDockerCompose() {
assertThat(composeFile(request)).hasSameContentAs(new ClassPathResource("compose/rabbitmq.yaml"));
}

@Test
void springAmqpStreamsWithoutDockerCompose() {
ProjectRequest request = createProjectRequest("web", "amqp-streams");
ProjectStructure structure = generateProject(request);
assertThat(structure.getProjectDirectory().resolve("compose.yaml")).doesNotExist();
}

@Test
void springAmqpStreamsWithDockerCompose() {
ProjectRequest request = createProjectRequest("docker-compose", "amqp-streams");
assertThat(composeFile(request)).hasSameContentAs(new ClassPathResource("compose/rabbitmq.yaml"));
}

}