Skip to content

Commit 610bc45

Browse files
mp911deschauder
authored andcommitted
Refine JDBC integration tests.
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
1 parent 1e20a32 commit 610bc45

File tree

54 files changed

+980
-840
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+980
-840
lines changed

pom.xml

+22
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,28 @@
168168
<includes>
169169
<include>**/*Tests.java</include>
170170
</includes>
171+
<excludes>
172+
<exclude>**/*IntegrationTests.java</exclude>
173+
</excludes>
174+
</configuration>
175+
</execution>
176+
</executions>
177+
</plugin>
178+
179+
<plugin>
180+
<groupId>org.apache.maven.plugins</groupId>
181+
<artifactId>maven-failsafe-plugin</artifactId>
182+
<executions>
183+
<execution>
184+
<id>default-test</id>
185+
<phase>integration-test</phase>
186+
<goals>
187+
<goal>integration-test</goal>
188+
</goals>
189+
<configuration>
190+
<includes>
191+
<include>**/*IntegrationTests.java</include>
192+
</includes>
171193
</configuration>
172194
</execution>
173195
</executions>

spring-data-jdbc/pom.xml

+40-42
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,28 @@
235235

236236
</dependencies>
237237

238+
<build>
239+
<plugins>
240+
<plugin>
241+
<groupId>org.apache.maven.plugins</groupId>
242+
<artifactId>maven-failsafe-plugin</artifactId>
243+
<executions>
244+
<execution>
245+
<id>default-test</id>
246+
<phase>integration-test</phase>
247+
<goals>
248+
<goal>integration-test</goal>
249+
</goals>
250+
<configuration>
251+
<systemPropertyVariables>
252+
<spring.profiles.active>hsql</spring.profiles.active>
253+
</systemPropertyVariables>
254+
</configuration>
255+
</execution>
256+
</executions>
257+
</plugin>
258+
</plugins>
259+
</build>
238260

239261
<profiles>
240262
<profile>
@@ -243,21 +265,18 @@
243265
<plugins>
244266
<plugin>
245267
<groupId>org.apache.maven.plugins</groupId>
246-
<artifactId>maven-surefire-plugin</artifactId>
268+
<artifactId>maven-failsafe-plugin</artifactId>
247269
<executions>
248270
<execution>
249271
<id>postgres-test</id>
250-
<phase>test</phase>
272+
<phase>integration-test</phase>
251273
<goals>
252-
<goal>test</goal>
274+
<goal>integration-test</goal>
253275
</goals>
254276
<configuration>
255277
<includes>
256278
<include>**/*IntegrationTests.java</include>
257279
</includes>
258-
<excludes>
259-
<exclude>**/*HsqlIntegrationTests.java</exclude>
260-
</excludes>
261280
<systemPropertyVariables>
262281
<spring.profiles.active>postgres</spring.profiles.active>
263282
</systemPropertyVariables>
@@ -274,129 +293,108 @@
274293
<plugins>
275294
<plugin>
276295
<groupId>org.apache.maven.plugins</groupId>
277-
<artifactId>maven-surefire-plugin</artifactId>
296+
<artifactId>maven-failsafe-plugin</artifactId>
278297
<executions>
279298
<execution>
280299
<id>h2-test</id>
281-
<phase>test</phase>
300+
<phase>integration-test</phase>
282301
<goals>
283-
<goal>test</goal>
302+
<goal>integration-test</goal>
284303
</goals>
285304
<configuration>
286305
<includes>
287306
<include>**/*IntegrationTests.java</include>
288307
</includes>
289-
<excludes>
290-
<exclude>**/*HsqlIntegrationTests.java</exclude>
291-
</excludes>
292308
<systemPropertyVariables>
293309
<spring.profiles.active>h2</spring.profiles.active>
294310
</systemPropertyVariables>
295311
</configuration>
296312
</execution>
297313
<execution>
298314
<id>mysql-test</id>
299-
<phase>test</phase>
315+
<phase>integration-test</phase>
300316
<goals>
301-
<goal>test</goal>
317+
<goal>integration-test</goal>
302318
</goals>
303319
<configuration>
304320
<includes>
305321
<include>**/*IntegrationTests.java</include>
306322
</includes>
307-
<excludes>
308-
<exclude>**/*HsqlIntegrationTests.java</exclude>
309-
</excludes>
310323
<systemPropertyVariables>
311324
<spring.profiles.active>mysql</spring.profiles.active>
312325
</systemPropertyVariables>
313326
</configuration>
314327
</execution>
315328
<execution>
316329
<id>postgres-test</id>
317-
<phase>test</phase>
330+
<phase>integration-test</phase>
318331
<goals>
319-
<goal>test</goal>
332+
<goal>integration-test</goal>
320333
</goals>
321334
<configuration>
322335
<includes>
323336
<include>**/*IntegrationTests.java</include>
324337
</includes>
325-
<excludes>
326-
<exclude>**/*HsqlIntegrationTests.java</exclude>
327-
</excludes>
328338
<systemPropertyVariables>
329339
<spring.profiles.active>postgres</spring.profiles.active>
330340
</systemPropertyVariables>
331341
</configuration>
332342
</execution>
333343
<execution>
334344
<id>mariadb-test</id>
335-
<phase>test</phase>
345+
<phase>integration-test</phase>
336346
<goals>
337-
<goal>test</goal>
347+
<goal>integration-test</goal>
338348
</goals>
339349
<configuration>
340350
<includes>
341351
<include>**/*IntegrationTests.java</include>
342352
</includes>
343-
<excludes>
344-
<exclude>**/*HsqlIntegrationTests.java</exclude>
345-
</excludes>
346353
<systemPropertyVariables>
347354
<spring.profiles.active>mariadb</spring.profiles.active>
348355
</systemPropertyVariables>
349356
</configuration>
350357
</execution>
351358
<execution>
352359
<id>db2-test</id>
353-
<phase>test</phase>
360+
<phase>integration-test</phase>
354361
<goals>
355-
<goal>test</goal>
362+
<goal>integration-test</goal>
356363
</goals>
357364
<configuration>
358365
<includes>
359366
<include>**/*IntegrationTests.java</include>
360367
</includes>
361-
<excludes>
362-
<exclude>**/*HsqlIntegrationTests.java</exclude>
363-
</excludes>
364368
<systemPropertyVariables>
365369
<spring.profiles.active>db2</spring.profiles.active>
366370
</systemPropertyVariables>
367371
</configuration>
368372
</execution>
369373
<execution>
370374
<id>oracle-test</id>
371-
<phase>test</phase>
375+
<phase>integration-test</phase>
372376
<goals>
373-
<goal>test</goal>
377+
<goal>integration-test</goal>
374378
</goals>
375379
<configuration>
376380
<includes>
377381
<include>**/*IntegrationTests.java</include>
378382
</includes>
379-
<excludes>
380-
<exclude>**/*HsqlIntegrationTests.java</exclude>
381-
</excludes>
382383
<systemPropertyVariables>
383384
<spring.profiles.active>oracle</spring.profiles.active>
384385
</systemPropertyVariables>
385386
</configuration>
386387
</execution>
387388
<execution>
388389
<id>mssql-test</id>
389-
<phase>test</phase>
390+
<phase>integration-test</phase>
390391
<goals>
391-
<goal>test</goal>
392+
<goal>integration-test</goal>
392393
</goals>
393394
<configuration>
394395
<includes>
395396
<include>**/*IntegrationTests.java</include>
396397
</includes>
397-
<excludes>
398-
<exclude>**/*HsqlIntegrationTests.java</exclude>
399-
</excludes>
400398
<systemPropertyVariables>
401399
<spring.profiles.active>mssql</spring.profiles.active>
402400
</systemPropertyVariables>

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/AbstractJdbcAggregateTemplateIntegrationTests.java

+13-25
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import static org.assertj.core.api.SoftAssertions.*;
2222
import static org.springframework.data.jdbc.testing.TestConfiguration.*;
2323
import static org.springframework.data.jdbc.testing.TestDatabaseFeatures.Feature.*;
24-
import static org.springframework.test.context.TestExecutionListeners.MergeMode.*;
2524

2625
import java.time.LocalDateTime;
2726
import java.util.ArrayList;
@@ -38,7 +37,6 @@
3837

3938
import org.assertj.core.api.SoftAssertions;
4039
import org.junit.jupiter.api.Test;
41-
import org.junit.jupiter.api.extension.ExtendWith;
4240
import org.springframework.beans.factory.annotation.Autowired;
4341
import org.springframework.context.ApplicationEventPublisher;
4442
import org.springframework.context.annotation.Bean;
@@ -55,9 +53,8 @@
5553
import org.springframework.data.domain.Sort;
5654
import org.springframework.data.jdbc.core.convert.DataAccessStrategy;
5755
import org.springframework.data.jdbc.core.convert.JdbcConverter;
58-
import org.springframework.data.jdbc.testing.AssumeFeatureTestExecutionListener;
59-
import org.springframework.data.jdbc.testing.CombiningActiveProfileResolver;
6056
import org.springframework.data.jdbc.testing.EnabledOnFeature;
57+
import org.springframework.data.jdbc.testing.IntegrationTest;
6158
import org.springframework.data.jdbc.testing.TestConfiguration;
6259
import org.springframework.data.jdbc.testing.TestDatabaseFeatures;
6360
import org.springframework.data.mapping.context.InvalidPersistentPropertyPath;
@@ -69,10 +66,6 @@
6966
import org.springframework.data.relational.core.mapping.Table;
7067
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
7168
import org.springframework.test.context.ActiveProfiles;
72-
import org.springframework.test.context.ContextConfiguration;
73-
import org.springframework.test.context.TestExecutionListeners;
74-
import org.springframework.test.context.junit.jupiter.SpringExtension;
75-
import org.springframework.transaction.annotation.Transactional;
7669

7770
/**
7871
* Integration tests for {@link JdbcAggregateTemplate}.
@@ -89,10 +82,7 @@
8982
* @author Chirag Tailor
9083
* @author Vincent Galloy
9184
*/
92-
@ContextConfiguration
93-
@Transactional
94-
@TestExecutionListeners(value = AssumeFeatureTestExecutionListener.class, mergeMode = MERGE_WITH_DEFAULTS)
95-
@ExtendWith(SpringExtension.class)
85+
@IntegrationTest
9686
abstract class AbstractJdbcAggregateTemplateIntegrationTests {
9787

9888
@Autowired JdbcAggregateOperations template;
@@ -1611,6 +1601,7 @@ public boolean isNew() {
16111601
return getId() == null;
16121602
}
16131603

1604+
@Override
16141605
public Long getId() {
16151606
return this.id;
16161607
}
@@ -1658,18 +1649,15 @@ public Long getVersion() {
16581649
public boolean equals(final Object o) {
16591650
if (o == this)
16601651
return true;
1661-
if (!(o instanceof AggregateWithImmutableVersion))
1652+
if (!(o instanceof final AggregateWithImmutableVersion other))
16621653
return false;
1663-
final AggregateWithImmutableVersion other = (AggregateWithImmutableVersion) o;
16641654
final Object this$id = this.id;
16651655
final Object other$id = other.id;
1666-
if (this$id == null ? other$id != null : !this$id.equals(other$id))
1656+
if (!Objects.equals(this$id, other$id))
16671657
return false;
16681658
final Object this$version = this.getVersion();
16691659
final Object other$version = other.getVersion();
1670-
if (this$version == null ? other$version != null : !this$version.equals(other$version))
1671-
return false;
1672-
return true;
1660+
return Objects.equals(this$version, other$version);
16731661
}
16741662

16751663
public int hashCode() {
@@ -1722,18 +1710,15 @@ public String toString() {
17221710
public boolean equals(final Object o) {
17231711
if (o == this)
17241712
return true;
1725-
if (!(o instanceof ConstructorInvocation))
1713+
if (!(o instanceof final ConstructorInvocation other))
17261714
return false;
1727-
final ConstructorInvocation other = (ConstructorInvocation) o;
17281715
final Object this$id = this.id;
17291716
final Object other$id = other.id;
1730-
if (this$id == null ? other$id != null : !this$id.equals(other$id))
1717+
if (!Objects.equals(this$id, other$id))
17311718
return false;
17321719
final Object this$version = this.getVersion();
17331720
final Object other$version = other.getVersion();
1734-
if (this$version == null ? other$version != null : !this$version.equals(other$version))
1735-
return false;
1736-
return true;
1721+
return Objects.equals(this$version, other$version);
17371722
}
17381723

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

1745+
@Override
17601746
public Long getVersion() {
17611747
return this.version;
17621748
}
@@ -1788,6 +1774,7 @@ void setVersion(Number newVersion) {
17881774
this.version = (Integer) newVersion;
17891775
}
17901776

1777+
@Override
17911778
public Integer getVersion() {
17921779
return this.version;
17931780
}
@@ -1819,6 +1806,7 @@ void setVersion(Number newVersion) {
18191806
this.version = (Short) newVersion;
18201807
}
18211808

1809+
@Override
18221810
public Short getVersion() {
18231811
return this.version;
18241812
}
@@ -1876,7 +1864,7 @@ JdbcAggregateOperations operations(ApplicationEventPublisher publisher, Relation
18761864

18771865
static class JdbcAggregateTemplateIntegrationTests extends AbstractJdbcAggregateTemplateIntegrationTests {}
18781866

1879-
@ActiveProfiles(value = PROFILE_SINGLE_QUERY_LOADING, resolver = CombiningActiveProfileResolver.class)
1867+
@ActiveProfiles(value = PROFILE_SINGLE_QUERY_LOADING)
18801868
static class JdbcAggregateTemplateSingleQueryLoadingIntegrationTests
18811869
extends AbstractJdbcAggregateTemplateIntegrationTests {
18821870

0 commit comments

Comments
 (0)