Skip to content

Commit

Permalink
Polish "Generate test app when spring cloud azure storage is selected"
Browse files Browse the repository at this point in the history
  • Loading branch information
mhalbritter committed Sep 13, 2024
1 parent b9d7dbd commit 4400544
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,56 @@
import io.spring.initializr.generator.buildsystem.Build;
import io.spring.initializr.generator.buildsystem.Dependency;
import io.spring.initializr.generator.buildsystem.DependencyScope;
import io.spring.initializr.generator.buildsystem.gradle.GradleBuildSystem;
import io.spring.initializr.generator.buildsystem.maven.MavenBuildSystem;
import io.spring.initializr.generator.condition.ConditionalOnBuildSystem;
import io.spring.initializr.generator.condition.ConditionalOnRequestedDependency;
import io.spring.initializr.generator.project.ProjectGenerationConfiguration;
import io.spring.initializr.generator.spring.build.BuildCustomizer;
import io.spring.initializr.generator.spring.build.gradle.DevelopmentOnlyDependencyGradleBuildCustomizer;
import io.spring.initializr.generator.spring.build.maven.OptionalDependencyMavenBuildCustomizer;
import io.spring.start.site.container.ComposeFileCustomizer;
import io.spring.start.site.container.DockerServiceResolver;

import org.springframework.context.annotation.Bean;

/**
* Configuration for generation of projects that depend on Spring Azure Docker Compose.
*
* @author Eddú Meléndez
* @author Moritz Halbritter
*/
@ProjectGenerationConfiguration
@ConditionalOnRequestedDependency("azure-storage")
class SpringAzureDockerComposeProjectGenerationConfiguration {

private static final String DEPENDENCY_ID = "spring-azure-docker-compose";

@Bean
@ConditionalOnRequestedDependency("docker-compose")
BuildCustomizer<Build> springAzureDockerComposeBuildCustomizer() {
return (build) -> build.dependencies()
.add("spring-azure-docker-compose",
Dependency.withCoordinates("com.azure.spring", "spring-cloud-azure-docker-compose")
.scope(DependencyScope.TEST_COMPILE));
.add(DEPENDENCY_ID, Dependency.withCoordinates("com.azure.spring", "spring-cloud-azure-docker-compose")
.scope(DependencyScope.RUNTIME));
}

@Bean
@ConditionalOnBuildSystem(MavenBuildSystem.ID)
OptionalDependencyMavenBuildCustomizer springAzureDockerComposeMavenBuildCustomizer() {
return new OptionalDependencyMavenBuildCustomizer(DEPENDENCY_ID);
}

@Bean
@ConditionalOnBuildSystem(GradleBuildSystem.ID)
DevelopmentOnlyDependencyGradleBuildCustomizer springAzureDockerComposeGradleBuildCustomizer() {
return new DevelopmentOnlyDependencyGradleBuildCustomizer(DEPENDENCY_ID);
}

@Bean
@ConditionalOnRequestedDependency("docker-compose")
ComposeFileCustomizer azureStorageComposeFileCustomizer(DockerServiceResolver serviceResolver) {
return (composeFile) -> serviceResolver.doWith("azurite",
(service) -> composeFile.services().add("azurite", service));
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import io.spring.initializr.generator.condition.ConditionalOnRequestedDependency;
import io.spring.initializr.generator.project.ProjectGenerationConfiguration;
import io.spring.initializr.generator.spring.build.BuildCustomizer;
import io.spring.start.site.container.DockerServiceResolver;
import io.spring.start.site.container.ServiceConnections;
import io.spring.start.site.container.ServiceConnectionsCustomizer;

import org.springframework.context.annotation.Bean;

Expand All @@ -43,4 +46,12 @@ BuildCustomizer<Build> springAzureTestcontainersBuildCustomizer() {
.scope(DependencyScope.TEST_COMPILE));
}

@Bean
@ConditionalOnRequestedDependency("testcontainers")
ServiceConnectionsCustomizer azureStorageServiceConnectionsCustomizer(DockerServiceResolver serviceResolver) {
return (serviceConnections) -> serviceResolver.doWith("azurite",
(service) -> serviceConnections.addServiceConnection(ServiceConnections.ServiceConnection
.ofGenericContainer("azurite", service, "azure-storage/azurite")));
}

}
1 change: 0 additions & 1 deletion start-site/src/main/resources/META-INF/spring.factories
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ io.spring.start.site.extension.dependency.springai.SpringAiTestcontainersProject
io.spring.start.site.extension.dependency.springai.SpringAiWeaviateProjectGenerationConfiguration,\
io.spring.start.site.extension.dependency.springamqp.SpringAmqpProjectGenerationConfiguration,\
io.spring.start.site.extension.dependency.springazure.SpringAzureDockerComposeProjectGenerationConfiguration,\
io.spring.start.site.extension.dependency.springazure.SpringAzureStorageProjectGenerationConfiguration,\
io.spring.start.site.extension.dependency.springazure.SpringAzureProjectGenerationConfiguration,\
io.spring.start.site.extension.dependency.springazure.SpringAzureTestcontainersProjectGenerationConfiguration,\
io.spring.start.site.extension.dependency.springboot.SpringBootProjectGenerationConfiguration,\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@

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

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;

/**
Expand All @@ -29,11 +32,24 @@
*/
class SpringAzureDockerComposeProjectGenerationConfigurationTests extends AbstractExtensionTests {

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

@Test
void createsAzuriteService() {
ProjectRequest request = createProjectRequest("docker-compose", "azure-storage");
assertThat(composeFile(request)).hasSameContentAs(new ClassPathResource("compose/azurite.yaml"));
}

@Test
void springAzureDockerComposeDependencyIsAdded() {
ProjectRequest projectRequest = createProjectRequest("docker-compose", "azure-storage");
assertThat(mavenPom(projectRequest)).hasDependency("com.azure.spring", "spring-cloud-azure-docker-compose",
null, "test");
null, "runtime");
}

@Test
Expand Down

This file was deleted.

0 comments on commit 4400544

Please sign in to comment.