Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate test app when Spring AI MongoDB Atlas is selected #1660

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public SimpleDockerServiceResolver() {
this.dockerServices.put("mariaDb", mariaDb());
this.dockerServices.put("milvus", milvus());
this.dockerServices.put("mongoDb", mongoDb());
this.dockerServices.put("mongoDbAtlas", mongoDbAtlas());
this.dockerServices.put("mysql", mysql());
this.dockerServices.put("neo4j", neo4j());
this.dockerServices.put("ollama", ollama());
Expand Down Expand Up @@ -141,6 +142,13 @@ private static DockerService mongoDb() {
return DockerService.withImageAndTag("mongo").website("https://hub.docker.com/_/mongo").ports(27017).build();
}

private static DockerService mongoDbAtlas() {
return DockerService.withImageAndTag("mongodb/mongodb-atlas-local")
.website("https://hub.docker.com/r/mongodb/mongodb-atlas-local")
.ports(27017)
.build();
}

private static DockerService mysql() {
return DockerService.withImageAndTag("mysql").website("https://hub.docker.com/_/mysql").ports(3306).build();
}
Expand Down
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));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ static Iterable<ImplicitDependency> create(Version platformVersion) {
builders.add(onDependencies("data-elasticsearch", "spring-ai-vectordb-elasticsearch")
.customizeBuild(addModule("elasticsearch"))
.customizeHelpDocument(addReferenceLink("Elasticsearch Container", "elasticsearch/")));
builders.add(onDependencies("data-mongodb", "data-mongodb-reactive").customizeBuild(addModule("mongodb"))
builders.add(onDependencies("data-mongodb", "data-mongodb-reactive", "spring-ai-vectordb-mongodb-atlas")
.customizeBuild(addModule("mongodb"))
.customizeHelpDocument(addReferenceLink("MongoDB Module", "databases/mongodb/")));
builders.add(onDependencies("data-neo4j", "spring-ai-vectordb-neo4j").customizeBuild(addModule("neo4j"))
.customizeHelpDocument(addReferenceLink("Neo4j Module", "databases/neo4j/")));
Expand Down
1 change: 1 addition & 0 deletions start-site/src/main/resources/META-INF/spring.factories
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ io.spring.start.site.extension.dependency.solace.SolaceProjectGenerationConfigur
io.spring.start.site.extension.dependency.springai.SpringAiChromaProjectGenerationConfiguration,\
io.spring.start.site.extension.dependency.springai.SpringAiDockerComposeProjectGenerationConfiguration,\
io.spring.start.site.extension.dependency.springai.SpringAiMilvusProjectGenerationConfiguration,\
io.spring.start.site.extension.dependency.springai.SpringAiMongoDbAtlasProjectGenerationConfiguration,\
io.spring.start.site.extension.dependency.springai.SpringAiOllamaProjectGenerationConfiguration,\
io.spring.start.site.extension.dependency.springai.SpringAiQdrantProjectGenerationConfiguration,\
io.spring.start.site.extension.dependency.springai.SpringAiTestcontainersProjectGenerationConfiguration,\
Expand Down
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"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ static Stream<Arguments> supportedTestcontainersActiveMQEntriesBuild() {
static Stream<Arguments> supportedTestcontainersSpringAiEntriesBuild() {
return Stream.of(Arguments.arguments("spring-ai-vectordb-chroma", "chromadb"),
Arguments.arguments("spring-ai-vectordb-milvus", "milvus"),
Arguments.arguments("spring-ai-vectordb-mongodb-atlas", "mongodb"),
Arguments.arguments("spring-ai-vectordb-qdrant", "qdrant"),
Arguments.arguments("spring-ai-vectordb-weaviate", "weaviate"));
}
Expand Down
5 changes: 5 additions & 0 deletions start-site/src/test/resources/compose/mongodb-atlas.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
services:
mongodbatlas:
image: 'mongodb/mongodb-atlas-local:latest'
ports:
- '27017'
Loading