Skip to content

Commit b9d7dbd

Browse files
eddumelendezmhalbritter
authored andcommitted
Generate test app when spring cloud azure storage is selected
Spring Cloud Azure 5.16.0 supports Testcontainers and Docker Compose Service Connection for Blob Storage and Queue. * Add `spring-cloud-azure-docker-compose` or `spring-cloud-azure-testcontainers` dependency * Configure `docker-compose.yaml` with image `mcr.microsoft.com/azure-storage/azurite:latest` * Configure `GenericContainer` with image `mcr.microsoft.com/azure-storage/azurite:latest` See gh-1582
1 parent ddf254a commit b9d7dbd

9 files changed

+302
-0
lines changed

start-site/src/main/java/io/spring/start/site/container/SimpleDockerServiceResolver.java

+8
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public SimpleDockerServiceResolver() {
3737
this.dockerServices.put("activeMQ", activeMQ());
3838
this.dockerServices.put("activeMQClassic", activeMQClassic());
3939
this.dockerServices.put("artemis", artemis());
40+
this.dockerServices.put("azurite", azurite());
4041
this.dockerServices.put("cassandra", cassandra());
4142
this.dockerServices.put("chroma", chroma());
4243
this.dockerServices.put("elasticsearch", elasticsearch());
@@ -81,6 +82,13 @@ private static DockerService artemis() {
8182
.build();
8283
}
8384

85+
private static DockerService azurite() {
86+
return DockerService.withImageAndTag("mcr.microsoft.com/azure-storage/azurite")
87+
.website("https://github.com/Azure/Azurite?tab=readme-ov-file#dockerhub")
88+
.ports(10000, 10001, 10002)
89+
.build();
90+
}
91+
8492
private static DockerService cassandra() {
8593
return DockerService.withImageAndTag("cassandra")
8694
.website("https://hub.docker.com/_/cassandra")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2012-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.spring.start.site.extension.dependency.springazure;
18+
19+
import io.spring.initializr.generator.buildsystem.Build;
20+
import io.spring.initializr.generator.buildsystem.Dependency;
21+
import io.spring.initializr.generator.buildsystem.DependencyScope;
22+
import io.spring.initializr.generator.condition.ConditionalOnRequestedDependency;
23+
import io.spring.initializr.generator.project.ProjectGenerationConfiguration;
24+
import io.spring.initializr.generator.spring.build.BuildCustomizer;
25+
26+
import org.springframework.context.annotation.Bean;
27+
28+
/**
29+
* Configuration for generation of projects that depend on Spring Azure Docker Compose.
30+
*
31+
* @author Eddú Meléndez
32+
*/
33+
@ProjectGenerationConfiguration
34+
@ConditionalOnRequestedDependency("azure-storage")
35+
class SpringAzureDockerComposeProjectGenerationConfiguration {
36+
37+
@Bean
38+
@ConditionalOnRequestedDependency("docker-compose")
39+
BuildCustomizer<Build> springAzureDockerComposeBuildCustomizer() {
40+
return (build) -> build.dependencies()
41+
.add("spring-azure-docker-compose",
42+
Dependency.withCoordinates("com.azure.spring", "spring-cloud-azure-docker-compose")
43+
.scope(DependencyScope.TEST_COMPILE));
44+
}
45+
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2012-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.spring.start.site.extension.dependency.springazure;
18+
19+
import io.spring.initializr.generator.condition.ConditionalOnRequestedDependency;
20+
import io.spring.initializr.generator.project.ProjectGenerationConfiguration;
21+
import io.spring.start.site.container.ComposeFileCustomizer;
22+
import io.spring.start.site.container.DockerServiceResolver;
23+
import io.spring.start.site.container.ServiceConnections;
24+
import io.spring.start.site.container.ServiceConnectionsCustomizer;
25+
26+
import org.springframework.context.annotation.Bean;
27+
28+
/**
29+
* Configuration for generation of projects that depend on Azurite (Storage Emulator).
30+
*
31+
* @author Eddú Meléndez
32+
*/
33+
@ProjectGenerationConfiguration
34+
@ConditionalOnRequestedDependency("azure-storage")
35+
class SpringAzureStorageProjectGenerationConfiguration {
36+
37+
@Bean
38+
@ConditionalOnRequestedDependency("testcontainers")
39+
ServiceConnectionsCustomizer azureStorageServiceConnectionsCustomizer(DockerServiceResolver serviceResolver) {
40+
return (serviceConnections) -> serviceResolver.doWith("azurite",
41+
(service) -> serviceConnections.addServiceConnection(ServiceConnections.ServiceConnection
42+
.ofGenericContainer("azurite", service, "azure-storage/azurite")));
43+
}
44+
45+
@Bean
46+
@ConditionalOnRequestedDependency("docker-compose")
47+
ComposeFileCustomizer azureStorageComposeFileCustomizer(DockerServiceResolver serviceResolver) {
48+
return (composeFile) -> serviceResolver.doWith("azurite",
49+
(service) -> composeFile.services().add("azurite", service));
50+
}
51+
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2012-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.spring.start.site.extension.dependency.springazure;
18+
19+
import io.spring.initializr.generator.buildsystem.Build;
20+
import io.spring.initializr.generator.buildsystem.Dependency;
21+
import io.spring.initializr.generator.buildsystem.DependencyScope;
22+
import io.spring.initializr.generator.condition.ConditionalOnRequestedDependency;
23+
import io.spring.initializr.generator.project.ProjectGenerationConfiguration;
24+
import io.spring.initializr.generator.spring.build.BuildCustomizer;
25+
26+
import org.springframework.context.annotation.Bean;
27+
28+
/**
29+
* Configuration for generation of projects that depend on Spring Azure Testcontainers.
30+
*
31+
* @author Eddú Meléndez
32+
*/
33+
@ProjectGenerationConfiguration
34+
@ConditionalOnRequestedDependency("azure-storage")
35+
class SpringAzureTestcontainersProjectGenerationConfiguration {
36+
37+
@Bean
38+
@ConditionalOnRequestedDependency("testcontainers")
39+
BuildCustomizer<Build> springAzureTestcontainersBuildCustomizer() {
40+
return (build) -> build.dependencies()
41+
.add("spring-azure-testcontainers",
42+
Dependency.withCoordinates("com.azure.spring", "spring-cloud-azure-testcontainers")
43+
.scope(DependencyScope.TEST_COMPILE));
44+
}
45+
46+
}

start-site/src/main/resources/META-INF/spring.factories

+3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ io.spring.start.site.extension.dependency.springai.SpringAiQdrantProjectGenerati
3535
io.spring.start.site.extension.dependency.springai.SpringAiTestcontainersProjectGenerationConfiguration,\
3636
io.spring.start.site.extension.dependency.springai.SpringAiWeaviateProjectGenerationConfiguration,\
3737
io.spring.start.site.extension.dependency.springamqp.SpringAmqpProjectGenerationConfiguration,\
38+
io.spring.start.site.extension.dependency.springazure.SpringAzureDockerComposeProjectGenerationConfiguration,\
39+
io.spring.start.site.extension.dependency.springazure.SpringAzureStorageProjectGenerationConfiguration,\
3840
io.spring.start.site.extension.dependency.springazure.SpringAzureProjectGenerationConfiguration,\
41+
io.spring.start.site.extension.dependency.springazure.SpringAzureTestcontainersProjectGenerationConfiguration,\
3942
io.spring.start.site.extension.dependency.springboot.SpringBootProjectGenerationConfiguration,\
4043
io.spring.start.site.extension.dependency.springcloud.SpringCloudProjectGenerationConfiguration,\
4144
io.spring.start.site.extension.dependency.springdata.SpringDataProjectGenerationConfiguration,\
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2012-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.spring.start.site.extension.dependency.springazure;
18+
19+
import io.spring.initializr.web.project.ProjectRequest;
20+
import io.spring.start.site.extension.AbstractExtensionTests;
21+
import org.junit.jupiter.api.Test;
22+
23+
import static org.assertj.core.api.Assertions.assertThat;
24+
25+
/**
26+
* Tests for {@link SpringAzureDockerComposeProjectGenerationConfiguration}.
27+
*
28+
* @author Eddú Meléndez
29+
*/
30+
class SpringAzureDockerComposeProjectGenerationConfigurationTests extends AbstractExtensionTests {
31+
32+
@Test
33+
void springAzureDockerComposeDependencyIsAdded() {
34+
ProjectRequest projectRequest = createProjectRequest("docker-compose", "azure-storage");
35+
assertThat(mavenPom(projectRequest)).hasDependency("com.azure.spring", "spring-cloud-azure-docker-compose",
36+
null, "test");
37+
}
38+
39+
@Test
40+
void shouldNotAddDockerComposeTestcontainersDependencyIfNoSpringAzureDependencyIsSelected() {
41+
ProjectRequest projectRequest = createProjectRequest("docker-compose", "web");
42+
assertThat(mavenPom(projectRequest)).doesNotHaveDependency("com.azure.spring",
43+
"spring-cloud-azure-docker-compose");
44+
}
45+
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 2012-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.spring.start.site.extension.dependency.springazure;
18+
19+
import io.spring.initializr.generator.test.project.ProjectStructure;
20+
import io.spring.initializr.web.project.ProjectRequest;
21+
import io.spring.start.site.extension.AbstractExtensionTests;
22+
import org.junit.jupiter.api.Test;
23+
24+
import org.springframework.core.io.ClassPathResource;
25+
26+
import static org.assertj.core.api.Assertions.assertThat;
27+
28+
/**
29+
* Tests for {@link SpringAzureStorageProjectGenerationConfiguration}
30+
*
31+
* @author Eddú Meléndez
32+
*/
33+
class SpringAzureStorageProjectGenerationConfigurationTests extends AbstractExtensionTests {
34+
35+
@Test
36+
void doesNothingWithoutDockerCompose() {
37+
ProjectRequest request = createProjectRequest("web", "azure-storage");
38+
ProjectStructure structure = generateProject(request);
39+
assertThat(structure.getProjectDirectory().resolve("compose.yaml")).doesNotExist();
40+
}
41+
42+
@Test
43+
void createsAzuriteService() {
44+
ProjectRequest request = createProjectRequest("docker-compose", "azure-storage");
45+
assertThat(composeFile(request)).hasSameContentAs(new ClassPathResource("compose/azurite.yaml"));
46+
}
47+
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2012-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.spring.start.site.extension.dependency.springazure;
18+
19+
import io.spring.initializr.web.project.ProjectRequest;
20+
import io.spring.start.site.extension.AbstractExtensionTests;
21+
import org.junit.jupiter.api.Test;
22+
23+
import static org.assertj.core.api.Assertions.assertThat;
24+
25+
/**
26+
* Tests for {@link SpringAzureTestcontainersProjectGenerationConfiguration}.
27+
*
28+
* @author Eddú Meléndez
29+
*/
30+
class SpringAzureTestcontainersProjectGenerationConfigurationTests extends AbstractExtensionTests {
31+
32+
@Test
33+
void springAzureTestcontainersDependencyIsAdded() {
34+
ProjectRequest projectRequest = createProjectRequest("testcontainers", "azure-storage");
35+
assertThat(mavenPom(projectRequest)).hasDependency("com.azure.spring", "spring-cloud-azure-testcontainers",
36+
null, "test");
37+
}
38+
39+
@Test
40+
void shouldNotAddSpringAzureTestcontainersDependencyIfNoSpringAzureDependencyIsSelected() {
41+
ProjectRequest projectRequest = createProjectRequest("testcontainers", "azure-keyvault");
42+
assertThat(mavenPom(projectRequest)).doesNotHaveDependency("com.azure.spring",
43+
"spring-cloud-azure-testcontainers");
44+
}
45+
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
services:
2+
azurite:
3+
image: 'mcr.microsoft.com/azure-storage/azurite:latest'
4+
ports:
5+
- '10000'
6+
- '10001'
7+
- '10002'

0 commit comments

Comments
 (0)