-
Notifications
You must be signed in to change notification settings - Fork 902
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1582 from eddumelendez
* pr/1582: Polish "Generate test app when spring cloud azure storage is selected" Generate test app when spring cloud azure storage is selected Closes gh-1582
- Loading branch information
Showing
7 changed files
with
256 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...ension/dependency/springazure/SpringAzureDockerComposeProjectGenerationConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* 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. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.spring.start.site.extension.dependency.springazure; | ||
|
||
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(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)); | ||
} | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
...nsion/dependency/springazure/SpringAzureTestcontainersProjectGenerationConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* 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. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.spring.start.site.extension.dependency.springazure; | ||
|
||
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.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; | ||
|
||
/** | ||
* Configuration for generation of projects that depend on Spring Azure Testcontainers. | ||
* | ||
* @author Eddú Meléndez | ||
*/ | ||
@ProjectGenerationConfiguration | ||
@ConditionalOnRequestedDependency("azure-storage") | ||
class SpringAzureTestcontainersProjectGenerationConfiguration { | ||
|
||
@Bean | ||
@ConditionalOnRequestedDependency("testcontainers") | ||
BuildCustomizer<Build> springAzureTestcontainersBuildCustomizer() { | ||
return (build) -> build.dependencies() | ||
.add("spring-azure-testcontainers", | ||
Dependency.withCoordinates("com.azure.spring", "spring-cloud-azure-testcontainers") | ||
.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"))); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...n/dependency/springazure/SpringAzureDockerComposeProjectGenerationConfigurationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* 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. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
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; | ||
|
||
/** | ||
* Tests for {@link SpringAzureDockerComposeProjectGenerationConfiguration}. | ||
* | ||
* @author Eddú Meléndez | ||
*/ | ||
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, "runtime"); | ||
} | ||
|
||
@Test | ||
void shouldNotAddDockerComposeTestcontainersDependencyIfNoSpringAzureDependencyIsSelected() { | ||
ProjectRequest projectRequest = createProjectRequest("docker-compose", "web"); | ||
assertThat(mavenPom(projectRequest)).doesNotHaveDependency("com.azure.spring", | ||
"spring-cloud-azure-docker-compose"); | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
.../dependency/springazure/SpringAzureTestcontainersProjectGenerationConfigurationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* 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. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.spring.start.site.extension.dependency.springazure; | ||
|
||
import io.spring.initializr.web.project.ProjectRequest; | ||
import io.spring.start.site.extension.AbstractExtensionTests; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* Tests for {@link SpringAzureTestcontainersProjectGenerationConfiguration}. | ||
* | ||
* @author Eddú Meléndez | ||
*/ | ||
class SpringAzureTestcontainersProjectGenerationConfigurationTests extends AbstractExtensionTests { | ||
|
||
@Test | ||
void springAzureTestcontainersDependencyIsAdded() { | ||
ProjectRequest projectRequest = createProjectRequest("testcontainers", "azure-storage"); | ||
assertThat(mavenPom(projectRequest)).hasDependency("com.azure.spring", "spring-cloud-azure-testcontainers", | ||
null, "test"); | ||
} | ||
|
||
@Test | ||
void shouldNotAddSpringAzureTestcontainersDependencyIfNoSpringAzureDependencyIsSelected() { | ||
ProjectRequest projectRequest = createProjectRequest("testcontainers", "azure-keyvault"); | ||
assertThat(mavenPom(projectRequest)).doesNotHaveDependency("com.azure.spring", | ||
"spring-cloud-azure-testcontainers"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
services: | ||
azurite: | ||
image: 'mcr.microsoft.com/azure-storage/azurite:latest' | ||
ports: | ||
- '10000' | ||
- '10001' | ||
- '10002' |