Merge pull request #100 from spring-cloud/integration-tests-1.x

Integration tests 1.x
This commit is contained in:
Anthony Dahanne
2023-08-18 09:28:52 -04:00
committed by GitHub
122 changed files with 391 additions and 184 deletions

189
pom.xml
View File

@@ -5,13 +5,23 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-bindings</artifactId>
<version>1.13.0-SNAPSHOT</version>
<artifactId>spring-cloud-bindings-parent</artifactId>
<version>1.14.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Spring Cloud Cloud Native Buildpacks Bindings</name>
<name>Spring Cloud Cloud Native Buildpacks Bindings Parent</name>
<description>Java Library and Auto-configuration for Cloud Native Buildpack Bindings</description>
<url>https://github.com/spring-cloud/spring-cloud-bindings</url>
<properties>
<java.version>1.8</java.version>
<spring-boot.version>2.6.15</spring-boot.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<licenses>
<license>
<name>Apache License, Version 2.0</name>
@@ -19,173 +29,20 @@
</license>
</licenses>
<modules>
<module>spring-cloud-bindings</module>
<module>spring-cloud-bindings-tests</module>
</modules>
<scm>
<url>https://github.com/spring-cloud/spring-cloud-bindings</url>
</scm>
<developers>
<developer>
<id>scb-team</id>
<name>Spring Cloud Bindings Team</name>
<organizationUrl>https://github.com/spring-cloud/spring-cloud-bindings/graphs/contributors</organizationUrl>
</developer>
<developer>
<id>scb-team</id>
<name>Spring Cloud Bindings Team</name>
<organizationUrl>https://github.com/spring-cloud/spring-cloud-bindings/graphs/contributors</organizationUrl>
</developer>
</developers>
<properties>
<java.version>1.8</java.version>
<jsr305.version>3.0.2</jsr305.version>
<mariadb-r2dbc.version>1.0.3</mariadb-r2dbc.version>
<spring-boot.version>2.3.3.RELEASE</spring-boot.version>
<!-- Plugins -->
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
<maven-source-plugin.version>3.2.1</maven-source-plugin.version>
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
<maven-gpg-plugin.version>3.0.1</maven-gpg-plugin.version>
<maven-javadoc-plugin.version>3.4.1</maven-javadoc-plugin.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>${jsr305.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mariadb</groupId>
<artifactId>r2dbc-mariadb</artifactId>
<version>${mariadb-r2dbc.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<compilerArgs>
<arg>-Werror</arg>
<arg>-Xlint:all</arg>
<arg>-Xlint:-options</arg>
<arg>-Xlint:-processing</arg>
<arg>-Xlint:-serial</arg>
</compilerArgs>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${maven-source-plugin.version}</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${maven-javadoc-plugin.version}</version>
<configuration>
<quiet>true</quiet>
<source>1.8</source>
<tags>
<tag>
<name>NonNullApi</name>
<placement>X</placement>
</tag>
</tags>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>${maven-gpg-plugin.version}</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
<configuration>
<gpgArguments>
<arg>--pinentry-mode</arg>
<arg>loopback</arg>
</gpgArguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<runOrder>random</runOrder>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -1,8 +1,6 @@
ARG base_image=ubuntu:bionic
FROM ${base_image}
ADD https://repo.spring.io/libs-release/io/spring/concourse/releasescripts/concourse-release-scripts/0.3.2/concourse-release-scripts-0.3.2.jar /opt/concourse-release-scripts.jar
RUN apt-get update && apt-get install --no-install-recommends -y \
git gnupg \
&& rm -rf /var/lib/apt/lists/*

View File

@@ -34,6 +34,9 @@ cd source
VERSION=$(./mvnw --quiet help:evaluate -DforceStdout -Dexpression=project.version)
git add pom.xml
git add spring-cloud-bindings/pom.xml
git add spring-cloud-bindings-tests/pom.xml
git checkout -- .
git \

View File

@@ -30,5 +30,4 @@ EOF
REPOSITORY="${PWD}"/repository
cd source
./mvnw deploy -Dmaven.test.skip=true -DaltDeploymentRepository="local::default::file://${REPOSITORY}"

View File

@@ -4,6 +4,6 @@ set -euo pipefail
export BUILD_INFO_LOCATION=$(pwd)/repository/build-info.json
java -jar /opt/concourse-release-scripts.jar publishToCentral 'RELEASE' "$BUILD_INFO_LOCATION" repository
java -jar /concourse-release-scripts.jar publishToCentral 'RELEASE' "$BUILD_INFO_LOCATION" repository
echo "Sync complete"

View File

@@ -10,6 +10,9 @@ cd source
VERSION=$(./mvnw --quiet help:evaluate -DforceStdout -Dexpression=project.version)
git add pom.xml
git add spring-cloud-bindings/pom.xml
git add spring-cloud-bindings-tests/pom.xml
git checkout -- .
git \

View 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`

View 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.14.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>${project.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>

View File

@@ -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"));
}
}

View File

@@ -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();
}
}

View File

@@ -0,0 +1,7 @@
package org.springframework.cloud;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringBoot2Application {
}

View File

@@ -0,0 +1 @@
localhost

View File

@@ -0,0 +1 @@
4242

View File

@@ -0,0 +1 @@
redis

View File

@@ -0,0 +1,188 @@
<?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.14.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>spring-cloud-bindings</artifactId>
<name>Spring Cloud Cloud Native Buildpacks Bindings</name>
<description>Java Library and Auto-configuration for Cloud Native Buildpack Bindings</description>
<url>https://github.com/spring-cloud/spring-cloud-bindings</url>
<licenses>
<license>
<name>Apache License, Version 2.0</name>
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>
<scm>
<url>https://github.com/spring-cloud/spring-cloud-bindings</url>
</scm>
<developers>
<developer>
<id>scb-team</id>
<name>Spring Cloud Bindings Team</name>
<organizationUrl>https://github.com/spring-cloud/spring-cloud-bindings/graphs/contributors</organizationUrl>
</developer>
</developers>
<properties>
<jsr305.version>3.0.2</jsr305.version>
<mariadb-r2dbc.version>1.1.2</mariadb-r2dbc.version>
<!-- Plugins -->
<maven-compiler-plugin.version>3.10.1</maven-compiler-plugin.version>
<maven-source-plugin.version>3.2.1</maven-source-plugin.version>
<maven-surefire-plugin.version>3.0.0-M7</maven-surefire-plugin.version>
<maven-gpg-plugin.version>3.0.1</maven-gpg-plugin.version>
<maven-javadoc-plugin.version>3.4.1</maven-javadoc-plugin.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>${jsr305.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mariadb</groupId>
<artifactId>r2dbc-mariadb</artifactId>
<version>${mariadb-r2dbc.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<compilerArgs>
<arg>-Werror</arg>
<arg>-Xlint:all</arg>
<arg>-Xlint:-options</arg>
<arg>-Xlint:-processing</arg>
<arg>-Xlint:-serial</arg>
</compilerArgs>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${maven-source-plugin.version}</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${maven-javadoc-plugin.version}</version>
<configuration>
<quiet>true</quiet>
<source>1.8</source>
<tags>
<tag>
<name>NonNullApi</name>
<placement>X</placement>
</tag>
</tags>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>${maven-gpg-plugin.version}</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
<configuration>
<gpgArguments>
<arg>--pinentry-mode</arg>
<arg>loopback</arg>
</gpgArguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<runOrder>random</runOrder>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -23,6 +23,7 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* A representation of a binding as defined by the
@@ -114,13 +115,12 @@ public final class Binding {
return Collections.emptyMap();
}
try {
return Files.list(path)
.filter(p -> {
try (Stream<Path> paths = Files.list(path)) {
return paths.filter(p -> {
try {
return !Files.isHidden(p);
} catch (IOException e) {
throw new IllegalStateException(String.format("unable to determine id file '%s' is hidden", p), e);
throw new IllegalStateException(String.format("unable to determine if file '%s' is hidden", p), e);
}
})
.filter(p -> !Files.isDirectory(p))

View File

@@ -26,6 +26,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
@@ -81,8 +82,8 @@ public final class Bindings {
throw new IllegalArgumentException(String.format("%s is not a directory", p));
}
try {
this.bindings = Files.list(p)
try (Stream<Path> paths = Files.list(p)) {
this.bindings = paths
.map(Binding::new)
.collect(Collectors.toList());
} catch (IOException e) {

View File

@@ -17,7 +17,7 @@
package org.springframework.cloud.bindings.boot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.context.config.ConfigFileApplicationListener;
import org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor;
import org.springframework.boot.context.event.ApplicationPreparedEvent;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.boot.logging.DeferredLog;
@@ -59,7 +59,7 @@ public final class BindingFlattenedEnvironmentPostProcessor implements Applicati
@Override
public int getOrder() {
// Before ConfigFileApplicationListener so values there can use values from {@link Bindings}.
return ConfigFileApplicationListener.DEFAULT_ORDER - 1;
return ConfigDataEnvironmentPostProcessor.ORDER - 1;
}
@Override

View File

@@ -17,7 +17,7 @@
package org.springframework.cloud.bindings.boot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.context.config.ConfigFileApplicationListener;
import org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor;
import org.springframework.boot.context.event.ApplicationPreparedEvent;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.boot.logging.DeferredLog;
@@ -77,7 +77,7 @@ public final class BindingSpecificEnvironmentPostProcessor implements Applicatio
@Override
public int getOrder() {
// Before ConfigFileApplicationListener so values there can use values from {@link Bindings}.
return ConfigFileApplicationListener.DEFAULT_ORDER - 1;
return ConfigDataEnvironmentPostProcessor.ORDER - 1;
}
@Override

View File

@@ -19,7 +19,7 @@ package org.springframework.cloud.bindings.boot;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.context.config.ConfigFileApplicationListener;
import org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor;
import org.springframework.cloud.bindings.Binding;
import org.springframework.cloud.bindings.Bindings;
import org.springframework.cloud.bindings.FluentMap;
@@ -82,7 +82,7 @@ final class BindingFlattenedEnvironmentPostProcessorTest {
@DisplayName("has order before ConfigFileApplicationListener")
void order() {
assertThat(new BindingFlattenedEnvironmentPostProcessor(new Bindings()).getOrder())
.isLessThan(ConfigFileApplicationListener.DEFAULT_ORDER);
.isLessThan(ConfigDataEnvironmentPostProcessor.ORDER);
}
}

View File

@@ -19,7 +19,7 @@ package org.springframework.cloud.bindings.boot;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.context.config.ConfigFileApplicationListener;
import org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor;
import org.springframework.cloud.bindings.Binding;
import org.springframework.cloud.bindings.Bindings;
import org.springframework.cloud.bindings.FluentMap;
@@ -98,7 +98,7 @@ final class BindingSpecificEnvironmentPostProcessorTest {
@DisplayName("has order before ConfigFileApplicationListener")
void order() {
assertThat(new BindingSpecificEnvironmentPostProcessor(new Bindings()).getOrder())
.isLessThan(ConfigFileApplicationListener.DEFAULT_ORDER);
.isLessThan(ConfigDataEnvironmentPostProcessor.ORDER);
}
@Test

Some files were not shown because too many files have changed in this diff Show More