Skip to content

Commit

Permalink
Refine JDBC integration tests.
Browse files Browse the repository at this point in the history
Introduce composed annotations and conditions to deduplicate annotations required for a test, to express database runtime conditions and database activation.
Simplify test configuration.
Split tests into unit test and integration test run.

Original pull request #1621
Closes #1620
  • Loading branch information
mp911de authored and schauder committed Sep 22, 2023
1 parent 1e20a32 commit 610bc45
Show file tree
Hide file tree
Showing 54 changed files with 980 additions and 840 deletions.
22 changes: 22 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,28 @@
<includes>
<include>**/*Tests.java</include>
</includes>
<excludes>
<exclude>**/*IntegrationTests.java</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<id>default-test</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
</goals>
<configuration>
<includes>
<include>**/*IntegrationTests.java</include>
</includes>
</configuration>
</execution>
</executions>
Expand Down
82 changes: 40 additions & 42 deletions spring-data-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,28 @@

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<id>default-test</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
</goals>
<configuration>
<systemPropertyVariables>
<spring.profiles.active>hsql</spring.profiles.active>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<profile>
Expand All @@ -243,21 +265,18 @@
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<id>postgres-test</id>
<phase>test</phase>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
<goal>integration-test</goal>
</goals>
<configuration>
<includes>
<include>**/*IntegrationTests.java</include>
</includes>
<excludes>
<exclude>**/*HsqlIntegrationTests.java</exclude>
</excludes>
<systemPropertyVariables>
<spring.profiles.active>postgres</spring.profiles.active>
</systemPropertyVariables>
Expand All @@ -274,129 +293,108 @@
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<id>h2-test</id>
<phase>test</phase>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
<goal>integration-test</goal>
</goals>
<configuration>
<includes>
<include>**/*IntegrationTests.java</include>
</includes>
<excludes>
<exclude>**/*HsqlIntegrationTests.java</exclude>
</excludes>
<systemPropertyVariables>
<spring.profiles.active>h2</spring.profiles.active>
</systemPropertyVariables>
</configuration>
</execution>
<execution>
<id>mysql-test</id>
<phase>test</phase>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
<goal>integration-test</goal>
</goals>
<configuration>
<includes>
<include>**/*IntegrationTests.java</include>
</includes>
<excludes>
<exclude>**/*HsqlIntegrationTests.java</exclude>
</excludes>
<systemPropertyVariables>
<spring.profiles.active>mysql</spring.profiles.active>
</systemPropertyVariables>
</configuration>
</execution>
<execution>
<id>postgres-test</id>
<phase>test</phase>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
<goal>integration-test</goal>
</goals>
<configuration>
<includes>
<include>**/*IntegrationTests.java</include>
</includes>
<excludes>
<exclude>**/*HsqlIntegrationTests.java</exclude>
</excludes>
<systemPropertyVariables>
<spring.profiles.active>postgres</spring.profiles.active>
</systemPropertyVariables>
</configuration>
</execution>
<execution>
<id>mariadb-test</id>
<phase>test</phase>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
<goal>integration-test</goal>
</goals>
<configuration>
<includes>
<include>**/*IntegrationTests.java</include>
</includes>
<excludes>
<exclude>**/*HsqlIntegrationTests.java</exclude>
</excludes>
<systemPropertyVariables>
<spring.profiles.active>mariadb</spring.profiles.active>
</systemPropertyVariables>
</configuration>
</execution>
<execution>
<id>db2-test</id>
<phase>test</phase>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
<goal>integration-test</goal>
</goals>
<configuration>
<includes>
<include>**/*IntegrationTests.java</include>
</includes>
<excludes>
<exclude>**/*HsqlIntegrationTests.java</exclude>
</excludes>
<systemPropertyVariables>
<spring.profiles.active>db2</spring.profiles.active>
</systemPropertyVariables>
</configuration>
</execution>
<execution>
<id>oracle-test</id>
<phase>test</phase>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
<goal>integration-test</goal>
</goals>
<configuration>
<includes>
<include>**/*IntegrationTests.java</include>
</includes>
<excludes>
<exclude>**/*HsqlIntegrationTests.java</exclude>
</excludes>
<systemPropertyVariables>
<spring.profiles.active>oracle</spring.profiles.active>
</systemPropertyVariables>
</configuration>
</execution>
<execution>
<id>mssql-test</id>
<phase>test</phase>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
<goal>integration-test</goal>
</goals>
<configuration>
<includes>
<include>**/*IntegrationTests.java</include>
</includes>
<excludes>
<exclude>**/*HsqlIntegrationTests.java</exclude>
</excludes>
<systemPropertyVariables>
<spring.profiles.active>mssql</spring.profiles.active>
</systemPropertyVariables>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import static org.assertj.core.api.SoftAssertions.*;
import static org.springframework.data.jdbc.testing.TestConfiguration.*;
import static org.springframework.data.jdbc.testing.TestDatabaseFeatures.Feature.*;
import static org.springframework.test.context.TestExecutionListeners.MergeMode.*;

import java.time.LocalDateTime;
import java.util.ArrayList;
Expand All @@ -38,7 +37,6 @@

import org.assertj.core.api.SoftAssertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Bean;
Expand All @@ -55,9 +53,8 @@
import org.springframework.data.domain.Sort;
import org.springframework.data.jdbc.core.convert.DataAccessStrategy;
import org.springframework.data.jdbc.core.convert.JdbcConverter;
import org.springframework.data.jdbc.testing.AssumeFeatureTestExecutionListener;
import org.springframework.data.jdbc.testing.CombiningActiveProfileResolver;
import org.springframework.data.jdbc.testing.EnabledOnFeature;
import org.springframework.data.jdbc.testing.IntegrationTest;
import org.springframework.data.jdbc.testing.TestConfiguration;
import org.springframework.data.jdbc.testing.TestDatabaseFeatures;
import org.springframework.data.mapping.context.InvalidPersistentPropertyPath;
Expand All @@ -69,10 +66,6 @@
import org.springframework.data.relational.core.mapping.Table;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.transaction.annotation.Transactional;

/**
* Integration tests for {@link JdbcAggregateTemplate}.
Expand All @@ -89,10 +82,7 @@
* @author Chirag Tailor
* @author Vincent Galloy
*/
@ContextConfiguration
@Transactional
@TestExecutionListeners(value = AssumeFeatureTestExecutionListener.class, mergeMode = MERGE_WITH_DEFAULTS)
@ExtendWith(SpringExtension.class)
@IntegrationTest
abstract class AbstractJdbcAggregateTemplateIntegrationTests {

@Autowired JdbcAggregateOperations template;
Expand Down Expand Up @@ -1611,6 +1601,7 @@ public boolean isNew() {
return getId() == null;
}

@Override
public Long getId() {
return this.id;
}
Expand Down Expand Up @@ -1658,18 +1649,15 @@ public Long getVersion() {
public boolean equals(final Object o) {
if (o == this)
return true;
if (!(o instanceof AggregateWithImmutableVersion))
if (!(o instanceof final AggregateWithImmutableVersion other))
return false;
final AggregateWithImmutableVersion other = (AggregateWithImmutableVersion) o;
final Object this$id = this.id;
final Object other$id = other.id;
if (this$id == null ? other$id != null : !this$id.equals(other$id))
if (!Objects.equals(this$id, other$id))
return false;
final Object this$version = this.getVersion();
final Object other$version = other.getVersion();
if (this$version == null ? other$version != null : !this$version.equals(other$version))
return false;
return true;
return Objects.equals(this$version, other$version);
}

public int hashCode() {
Expand Down Expand Up @@ -1722,18 +1710,15 @@ public String toString() {
public boolean equals(final Object o) {
if (o == this)
return true;
if (!(o instanceof ConstructorInvocation))
if (!(o instanceof final ConstructorInvocation other))
return false;
final ConstructorInvocation other = (ConstructorInvocation) o;
final Object this$id = this.id;
final Object other$id = other.id;
if (this$id == null ? other$id != null : !this$id.equals(other$id))
if (!Objects.equals(this$id, other$id))
return false;
final Object this$version = this.getVersion();
final Object other$version = other.getVersion();
if (this$version == null ? other$version != null : !this$version.equals(other$version))
return false;
return true;
return Objects.equals(this$version, other$version);
}

public int hashCode() {
Expand All @@ -1757,6 +1742,7 @@ void setVersion(Number newVersion) {
this.version = (Long) newVersion;
}

@Override
public Long getVersion() {
return this.version;
}
Expand Down Expand Up @@ -1788,6 +1774,7 @@ void setVersion(Number newVersion) {
this.version = (Integer) newVersion;
}

@Override
public Integer getVersion() {
return this.version;
}
Expand Down Expand Up @@ -1819,6 +1806,7 @@ void setVersion(Number newVersion) {
this.version = (Short) newVersion;
}

@Override
public Short getVersion() {
return this.version;
}
Expand Down Expand Up @@ -1876,7 +1864,7 @@ JdbcAggregateOperations operations(ApplicationEventPublisher publisher, Relation

static class JdbcAggregateTemplateIntegrationTests extends AbstractJdbcAggregateTemplateIntegrationTests {}

@ActiveProfiles(value = PROFILE_SINGLE_QUERY_LOADING, resolver = CombiningActiveProfileResolver.class)
@ActiveProfiles(value = PROFILE_SINGLE_QUERY_LOADING)
static class JdbcAggregateTemplateSingleQueryLoadingIntegrationTests
extends AbstractJdbcAggregateTemplateIntegrationTests {

Expand Down
Loading

0 comments on commit 610bc45

Please sign in to comment.