Bump to latest 2.5 spring boot release
Contains feedback from @Kehrlann Original commit by @abelsromero - amended to keep compatibility with Spring Boot 2 Add integration tests * use Maven modules to do so * spring-cloud-bindings goes one level down * addition of a spring-cloud-bindings parent Inspired by @gregturn and spring-data-rest Integrate PR#94 comments from @Kehrlann * move bindings to src/test/resources * get rid of unused / duplicate annotations * move all dependencies to test scope for test projects Spring Boot 2 support * only in branch 1.x, SB3 support is in main branch
This commit is contained in:
23
spring-cloud-bindings-tests/README.md
Normal file
23
spring-cloud-bindings-tests/README.md
Normal file
@@ -0,0 +1,23 @@
|
||||
# Spring Cloud Bindings Test Boot 2
|
||||
|
||||
## Purpose of this module
|
||||
|
||||
For several Spring Cloud Bindings integrations, the properties bindings need to be different between Spring Boot 2 and Spring Boot 3.
|
||||
|
||||
For example, we can take some Redis properties bindings; with Spring Boot 2, they need to be mapped this way:
|
||||
|
||||
| Property | Value |
|
||||
|---------------------|----------|
|
||||
| `spring.redis.port` | `{port}` |
|
||||
| `spring.redis.host` | `{host}` |
|
||||
|
||||
But in a Spring Boot 3 application, the mapping needs to be different because of changes with Spring Data Redis:
|
||||
|
||||
| Property | Value |
|
||||
|--------------------------|----------|
|
||||
| `spring.data.redis.port` | `{port}` |
|
||||
| `spring.data.redis.host` | `{host}` |
|
||||
|
||||
This module runs an application, based on Spring Boot 2, and checks whether the `RedisConnectionFactory` properly picked up the `spring.redis.port` and `spring.redis.host` values.
|
||||
|
||||
Pay attention to the 2 environment variables set in the `pom.xml` that set the `JAVA_TOOL_OPTIONS` and `SERVICE_BINDING_ROOT` - they allow Spring Boot Bindings to load the proper configuration in `bindings/redis`
|
||||
71
spring-cloud-bindings-tests/pom.xml
Normal file
71
spring-cloud-bindings-tests/pom.xml
Normal file
@@ -0,0 +1,71 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-bindings-parent</artifactId>
|
||||
<version>1.13.0-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<artifactId>spring-cloud-bindings-tests</artifactId>
|
||||
<description>Test project to verify Spring Cloud Bindings works properly with Spring Boot 2</description>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
<version>${spring-boot.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
<version>${spring-boot.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-bindings</artifactId>
|
||||
<version>${version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<version>${spring-boot.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.kstyrc</groupId>
|
||||
<artifactId>embedded-redis</artifactId>
|
||||
<version>0.6</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.10.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.2</version>
|
||||
<configuration>
|
||||
<forkCount>1</forkCount>
|
||||
<reuseForks>false</reuseForks>
|
||||
<environmentVariables>
|
||||
<JAVA_TOOL_OPTIONS>-Dorg.springframework.cloud.bindings.boot.enable=true</JAVA_TOOL_OPTIONS>
|
||||
<SERVICE_BINDING_ROOT>${basedir}/src/test/resources/bindings</SERVICE_BINDING_ROOT>
|
||||
</environmentVariables>
|
||||
<argLine>-Xmx1024m</argLine>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.springframework.cloud;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@SpringBootTest(classes = RedisServerTestConfiguration.class)
|
||||
public class IntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate redisTemplate;
|
||||
|
||||
@Test
|
||||
public void shouldSaveUser_toRedis() {
|
||||
redisTemplate.opsForValue().set("hello", "world");
|
||||
assertTrue(redisTemplate.hasKey("hello"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package org.springframework.cloud;
|
||||
|
||||
import org.springframework.boot.test.context.TestConfiguration;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import redis.embedded.RedisServer;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
import java.io.IOException;
|
||||
import java.util.Scanner;
|
||||
|
||||
@TestConfiguration
|
||||
public class RedisServerTestConfiguration {
|
||||
|
||||
private final RedisServer redisServer;
|
||||
|
||||
public RedisServerTestConfiguration() throws IOException {
|
||||
try (Scanner scanner = new Scanner(new ClassPathResource("bindings/redis/port").getInputStream())) {
|
||||
int port = scanner.nextInt();
|
||||
this.redisServer = new RedisServer(port);
|
||||
}
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void postConstruct() {
|
||||
redisServer.start();
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
public void preDestroy() {
|
||||
redisServer.stop();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package org.springframework.cloud;
|
||||
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class SpringBoot2Application {
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
localhost
|
||||
@@ -0,0 +1 @@
|
||||
4242
|
||||
@@ -0,0 +1 @@
|
||||
redis
|
||||
Reference in New Issue
Block a user