Skip to content

Commit c45a19a

Browse files
committed
Generate test app when RabbitMQ Streams is selected
Currently, when rabbitmq streams and docker compose/testcontainers are selected, no container is provided. For that reason, the test and test app can not be executed sucessfully. RabbitMQ Streams requires an additional configuration to enable it using Spring Boot and also in the container itself but providing RabbitMQ service would be enough to execute the test and test app.
1 parent df9f120 commit c45a19a

2 files changed

Lines changed: 38 additions & 11 deletions

File tree

start-site/src/main/java/io/spring/start/site/extension/dependency/springamqp/SpringAmqpProjectGenerationConfiguration.java

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616

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

19+
import io.spring.initializr.generator.buildsystem.Build;
1920
import io.spring.initializr.generator.condition.ConditionalOnRequestedDependency;
2021
import io.spring.initializr.generator.project.ProjectGenerationConfiguration;
2122
import io.spring.start.site.container.ComposeFileCustomizer;
@@ -29,35 +30,47 @@
2930
* Configuration for generation of projects that depend on Spring AMQP.
3031
*
3132
* @author Stephane Nicoll
32-
* @author Stephane Nicoll
33+
* @author Eddú Meléndez
3334
*/
3435
@ProjectGenerationConfiguration
35-
@ConditionalOnRequestedDependency("amqp")
3636
class SpringAmqpProjectGenerationConfiguration {
3737

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

4040
@Bean
41+
@ConditionalOnRequestedDependency("amqp")
4142
SpringRabbitTestBuildCustomizer springAmqpTestBuildCustomizer() {
4243
return new SpringRabbitTestBuildCustomizer();
4344
}
4445

4546
@Bean
4647
@ConditionalOnRequestedDependency("testcontainers")
47-
ServiceConnectionsCustomizer rabbitServiceConnectionsCustomizer(DockerServiceResolver serviceResolver) {
48-
return (serviceConnections) -> serviceResolver.doWith("rabbit", (service) -> serviceConnections
49-
.addServiceConnection(ServiceConnection.ofContainer("rabbit", service, TESTCONTAINERS_CLASS_NAME, false)));
48+
ServiceConnectionsCustomizer rabbitServiceConnectionsCustomizer(Build build,
49+
DockerServiceResolver serviceResolver) {
50+
return (serviceConnections) -> serviceResolver.doWith("rabbit", (service) -> {
51+
if (isAmqpEnabled(build)) {
52+
serviceConnections.addServiceConnection(
53+
ServiceConnection.ofContainer("rabbit", service, TESTCONTAINERS_CLASS_NAME, false));
54+
}
55+
});
5056
}
5157

5258
@Bean
5359
@ConditionalOnRequestedDependency("docker-compose")
54-
ComposeFileCustomizer rabbitComposeFileCustomizer(DockerServiceResolver serviceResolver) {
55-
return (composeFile) -> serviceResolver.doWith("rabbit",
56-
(service) -> composeFile.services()
60+
ComposeFileCustomizer rabbitComposeFileCustomizer(Build build, DockerServiceResolver serviceResolver) {
61+
return (composeFile) -> serviceResolver.doWith("rabbit", (service) -> {
62+
if (isAmqpEnabled(build)) {
63+
composeFile.services()
5764
.add("rabbitmq",
5865
service.andThen((builder) -> builder.environment("RABBITMQ_DEFAULT_USER", "myuser")
5966
.environment("RABBITMQ_DEFAULT_PASS", "secret")
60-
.ports(5672))));
67+
.ports(5672)));
68+
}
69+
});
70+
}
71+
72+
private boolean isAmqpEnabled(Build build) {
73+
return build.dependencies().has("amqp") || build.dependencies().has("amqp-streams");
6174
}
6275

6376
}

start-site/src/test/java/io/spring/start/site/extension/dependency/springamqp/SpringAmqpProjectGenerationConfigurationTests.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -35,6 +35,7 @@
3535
*
3636
* @author Stephane Nicoll
3737
* @author Moritz Halbritter
38+
* @author Eddú Meléndez
3839
*/
3940
class SpringAmqpProjectGenerationConfigurationTests extends AbstractExtensionTests {
4041

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

74+
@Test
75+
void springAmqpStreamsWithoutDockerCompose() {
76+
ProjectRequest request = createProjectRequest("web", "amqp-streams");
77+
ProjectStructure structure = generateProject(request);
78+
assertThat(structure.getProjectDirectory().resolve("compose.yaml")).doesNotExist();
79+
}
80+
81+
@Test
82+
void springAmqpStreamsWithDockerCompose() {
83+
ProjectRequest request = createProjectRequest("docker-compose", "amqp-streams");
84+
assertThat(composeFile(request)).hasSameContentAs(new ClassPathResource("compose/rabbitmq.yaml"));
85+
}
86+
7387
}

0 commit comments

Comments
 (0)