Skip to content

Commit 6e5cfd8

Browse files
eddumelendezmhalbritter
authored andcommitted
Generate test app when RabbitMQ Streams is selected
See spring-iogh-1611
1 parent d2472ab commit 6e5cfd8

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: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012 - present the original author or authors.
2+
* Copyright 2012-2023 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.ConditionalOnPlatformVersion;
2021
import io.spring.initializr.generator.condition.ConditionalOnRequestedDependency;
2122
import io.spring.initializr.generator.project.ProjectGenerationConfiguration;
@@ -34,39 +35,51 @@
3435
* Configuration for generation of projects that depend on Spring AMQP.
3536
*
3637
* @author Stephane Nicoll
38+
* @author Eddú Meléndez
3739
*/
3840
@ProjectGenerationConfiguration
3941
class SpringAmqpProjectGenerationConfiguration {
4042

4143
@Configuration(proxyBeanMethods = false)
42-
@ConditionalOnRequestedDependency("amqp")
4344
static class AmqpConfiguration {
4445

4546
@Bean
4647
@ConditionalOnPlatformVersion("[3.5.0,4.0.0-RC1]")
48+
@ConditionalOnRequestedDependency("amqp")
4749
SpringRabbitTestBuildCustomizer springAmqpTestBuildCustomizer() {
4850
return new SpringRabbitTestBuildCustomizer();
4951
}
5052

5153
@Bean
5254
@ConditionalOnRequestedDependency("testcontainers")
53-
ServiceConnectionsCustomizer rabbitServiceConnectionsCustomizer(DockerServiceResolver serviceResolver,
54-
Testcontainers testcontainers) {
55-
Container container = testcontainers.getContainer(SupportedContainer.RABBITMQ);
56-
return (serviceConnections) -> serviceResolver
57-
.doWith("rabbit", (service) -> serviceConnections.addServiceConnection(
58-
ServiceConnection.ofContainer("rabbit", service, container.className(), container.generic())));
55+
ServiceConnectionsCustomizer rabbitServiceConnectionsCustomizer(Build build,
56+
DockerServiceResolver serviceResolver, Testcontainers testcontainers) {
57+
return (serviceConnections) -> {
58+
if (isAmqpEnabled(build)) {
59+
Container container = testcontainers.getContainer(SupportedContainer.RABBITMQ);
60+
serviceResolver.doWith("rabbit",
61+
(service) -> serviceConnections.addServiceConnection(ServiceConnection.ofContainer("rabbit",
62+
service, container.className(), container.generic())));
63+
}
64+
};
5965
}
6066

6167
@Bean
6268
@ConditionalOnRequestedDependency("docker-compose")
63-
ComposeFileCustomizer rabbitComposeFileCustomizer(DockerServiceResolver serviceResolver) {
64-
return (composeFile) -> serviceResolver.doWith("rabbit",
65-
(service) -> composeFile.services()
69+
ComposeFileCustomizer rabbitComposeFileCustomizer(Build build, DockerServiceResolver serviceResolver) {
70+
return (composeFile) -> {
71+
if (isAmqpEnabled(build)) {
72+
serviceResolver.doWith("rabbit", (service) -> composeFile.services()
6673
.add("rabbitmq",
6774
service.andThen((builder) -> builder.environment("RABBITMQ_DEFAULT_USER", "myuser")
6875
.environment("RABBITMQ_DEFAULT_PASS", "secret")
6976
.ports(5672))));
77+
}
78+
};
79+
}
80+
81+
private boolean isAmqpEnabled(Build build) {
82+
return build.dependencies().has("amqp") || build.dependencies().has("amqp-streams");
7083
}
7184

7285
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
*
3838
* @author Stephane Nicoll
3939
* @author Moritz Halbritter
40+
* @author Eddú Meléndez
4041
*/
4142
class SpringAmqpProjectGenerationConfigurationTests extends AbstractExtensionTests {
4243

@@ -73,4 +74,17 @@ void springAmqpWithDockerCompose() {
7374
assertThat(composeFile(request)).hasSameContentAs(new ClassPathResource("compose/rabbitmq.yaml"));
7475
}
7576

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

0 commit comments

Comments
 (0)