-
Notifications
You must be signed in to change notification settings - Fork 914
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 #1660 from eddumelendez
* pr/1660: Generate test app when Spring AI MongoDB Atlas is selected Closes gh-1660
- Loading branch information
Showing
7 changed files
with
121 additions
and
1 deletion.
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
56 changes: 56 additions & 0 deletions
56
...ite/extension/dependency/springai/SpringAiMongoDbAtlasProjectGenerationConfiguration.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,56 @@ | ||
/* | ||
* 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.springai; | ||
|
||
import io.spring.initializr.generator.condition.ConditionalOnPlatformVersion; | ||
import io.spring.initializr.generator.condition.ConditionalOnRequestedDependency; | ||
import io.spring.initializr.generator.project.ProjectGenerationConfiguration; | ||
import io.spring.start.site.container.ComposeFileCustomizer; | ||
import io.spring.start.site.container.DockerServiceResolver; | ||
import io.spring.start.site.container.ServiceConnections.ServiceConnection; | ||
import io.spring.start.site.container.ServiceConnectionsCustomizer; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
|
||
/** | ||
* Configuration for generation of projects that depend on MongoDb Atlas. | ||
* | ||
* @author Eddú Meléndez | ||
*/ | ||
@ProjectGenerationConfiguration | ||
@ConditionalOnPlatformVersion("3.4.0") | ||
@ConditionalOnRequestedDependency("spring-ai-vectordb-mongodb-atlas") | ||
class SpringAiMongoDbAtlasProjectGenerationConfiguration { | ||
|
||
private static final String TESTCONTAINERS_CLASS_NAME = "org.testcontainers.mongodb.MongoDBAtlasLocalContainer"; | ||
|
||
@Bean | ||
@ConditionalOnRequestedDependency("testcontainers") | ||
ServiceConnectionsCustomizer mongodbAtlasServiceConnectionsCustomizer(DockerServiceResolver serviceResolver) { | ||
return (serviceConnections) -> serviceResolver.doWith("mongoDbAtlas", | ||
(service) -> serviceConnections.addServiceConnection( | ||
ServiceConnection.ofContainer("mongoDbAtlas", service, TESTCONTAINERS_CLASS_NAME, false))); | ||
} | ||
|
||
@Bean | ||
@ConditionalOnRequestedDependency("docker-compose") | ||
ComposeFileCustomizer mongodbAtlasComposeFileCustomizer(DockerServiceResolver serviceResolver) { | ||
return (composeFile) -> serviceResolver.doWith("mongoDbAtlas", | ||
(service) -> composeFile.services().add("mongodbatlas", service)); | ||
} | ||
|
||
} |
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
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
48 changes: 48 additions & 0 deletions
48
...xtension/dependency/springai/SpringAiMongoDbAtlasProjectGenerationConfigurationTests.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,48 @@ | ||
/* | ||
* 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.springai; | ||
|
||
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 SpringAiMongoDbAtlasProjectGenerationConfiguration} | ||
* | ||
* @author Eddú Meléndez | ||
*/ | ||
class SpringAiMongoDbAtlasProjectGenerationConfigurationTests extends AbstractExtensionTests { | ||
|
||
@Test | ||
void doesNothingWithoutDockerCompose() { | ||
ProjectRequest request = createProjectRequest("web", "spring-ai-vectordb-mongodb-atlas"); | ||
ProjectStructure structure = generateProject(request); | ||
assertThat(structure.getProjectDirectory().resolve("compose.yaml")).doesNotExist(); | ||
} | ||
|
||
@Test | ||
void createsMongoDbAtlasService() { | ||
ProjectRequest request = createProjectRequest("docker-compose", "spring-ai-vectordb-mongodb-atlas"); | ||
assertThat(composeFile(request)).hasSameContentAs(new ClassPathResource("compose/mongodb-atlas.yaml")); | ||
} | ||
|
||
} |
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
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,5 @@ | ||
services: | ||
mongodbatlas: | ||
image: 'mongodb/mongodb-atlas-local:latest' | ||
ports: | ||
- '27017' |