-
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 #1579 from eddumelendez
* pr/1579: Polish "Generate test application when spring ai redis is selected" Generate test application when spring ai redis is selected Closes gh-1579
- Loading branch information
Showing
6 changed files
with
118 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
53 changes: 53 additions & 0 deletions
53
...pring/start/site/extension/dependency/redis/RedisStackProjectGenerationConfiguration.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,53 @@ | ||
/* | ||
* 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.redis; | ||
|
||
import io.spring.initializr.generator.condition.ConditionalOnRequestedDependency; | ||
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; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** | ||
* Configuration for generation of projects that depend on Redis Stack. | ||
* | ||
* @author Eddú Meléndez | ||
*/ | ||
@Configuration(proxyBeanMethods = false) | ||
@ConditionalOnRequestedDependency("spring-ai-vectordb-redis") | ||
class RedisStackProjectGenerationConfiguration { | ||
|
||
@Bean | ||
@ConditionalOnRequestedDependency("testcontainers") | ||
ServiceConnectionsCustomizer redisStackServiceConnectionsCustomizer(DockerServiceResolver serviceResolver) { | ||
return (serviceConnections) -> serviceResolver.doWith("redisStack", (service) -> serviceConnections | ||
.addServiceConnection(ServiceConnection.ofGenericContainer("redisStack", service, "redis"))); | ||
} | ||
|
||
@Bean | ||
@ConditionalOnRequestedDependency("docker-compose") | ||
ComposeFileCustomizer redisStackComposeFileCustomizer(DockerServiceResolver serviceResolver) { | ||
return (composeFile) -> serviceResolver.doWith("redisStack", | ||
(service) -> composeFile.services() | ||
.add("redis", service | ||
.andThen((builder) -> builder.label("org.springframework.boot.service-connection", "redis")))); | ||
} | ||
|
||
} |
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
.../start/site/extension/dependency/redis/RedisStackProjectGenerationConfigurationTests.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.redis; | ||
|
||
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 RedisStackProjectGenerationConfiguration}. | ||
* | ||
* @author Eddú Meléndez | ||
*/ | ||
class RedisStackProjectGenerationConfigurationTests extends AbstractExtensionTests { | ||
|
||
@Test | ||
void doesNothingWithoutDockerCompose() { | ||
ProjectRequest request = createProjectRequest("spring-ai-vectordb-redis"); | ||
ProjectStructure structure = generateProject(request); | ||
assertThat(structure.getProjectDirectory().resolve("compose.yaml")).doesNotExist(); | ||
} | ||
|
||
@Test | ||
void createsRedisStackService() { | ||
ProjectRequest request = createProjectRequest("docker-compose", "spring-ai-vectordb-redis"); | ||
assertThat(composeFile(request)).hasSameContentAs(new ClassPathResource("compose/redis-stack.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
services: | ||
redis: | ||
image: 'redis/redis-stack:latest' | ||
labels: | ||
- "org.springframework.boot.service-connection=redis" | ||
ports: | ||
- '6379' |