From b28e4e07c6cec15a32b9a5fcab1348996c9e2f10 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Mon, 13 Jul 2020 14:09:42 +0200 Subject: [PATCH] DATAJDBC-256 - Polishing. Rename RequiredFeature to EnabledOnFeature to align with JUnit terminology. Use RunWith instead of Spring rules. Reformat code. Update documentation. Original pull request: #232. --- ...JdbcAggregateTemplateIntegrationTests.java | 65 +++++++++---------- ...gregateTemplateSchemaIntegrationTests.java | 15 ++--- ...itoryCustomConversionIntegrationTests.java | 12 ++-- ...dedNotInAggregateRootIntegrationTests.java | 11 ++-- ...EmbeddedWithReferenceIntegrationTests.java | 11 ++-- .../JdbcRepositoryIntegrationTests.java | 15 ++--- ...oryPropertyConversionIntegrationTests.java | 23 +++---- ...sitoryWithCollectionsIntegrationTests.java | 5 +- ...bcRepositoryWithListsIntegrationTests.java | 5 +- ...dbcRepositoryWithMapsIntegrationTests.java | 5 +- .../data/jdbc/testing/AssumeFeatureRule.java | 13 ++-- .../data/jdbc/testing/EnabledOnFeature.java | 53 +++++++++++++++ .../OracleDataSourceConfiguration.java | 28 ++++---- .../data/jdbc/testing/RequiredFeature.java | 27 -------- .../relational/core/dialect/IdGeneration.java | 6 +- src/main/asciidoc/new-features.adoc | 5 ++ src/main/asciidoc/preface.adoc | 1 + 17 files changed, 155 insertions(+), 145 deletions(-) create mode 100644 spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/EnabledOnFeature.java delete mode 100644 spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/RequiredFeature.java diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateTemplateIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateTemplateIntegrationTests.java index b8bb4ed8..a8e2303c 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateTemplateIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateTemplateIntegrationTests.java @@ -37,9 +37,9 @@ import java.util.function.Function; import java.util.stream.IntStream; import org.assertj.core.api.SoftAssertions; -import org.junit.ClassRule; -import org.junit.Rule; import org.junit.Test; +import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.annotation.Bean; @@ -55,7 +55,7 @@ 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.AssumeFeatureRule; -import org.springframework.data.jdbc.testing.RequiredFeature; +import org.springframework.data.jdbc.testing.EnabledOnFeature; import org.springframework.data.jdbc.testing.TestConfiguration; import org.springframework.data.jdbc.testing.TestDatabaseFeatures; import org.springframework.data.relational.core.conversion.DbActionExecutionException; @@ -65,8 +65,7 @@ import org.springframework.data.relational.core.mapping.Table; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestExecutionListeners; -import org.springframework.test.context.junit4.rules.SpringClassRule; -import org.springframework.test.context.junit4.rules.SpringMethodRule; +import org.springframework.test.context.junit4.SpringRunner; import org.springframework.transaction.annotation.Transactional; /** @@ -84,11 +83,9 @@ import org.springframework.transaction.annotation.Transactional; @ContextConfiguration @Transactional @TestExecutionListeners(value = AssumeFeatureRule.class, mergeMode = MERGE_WITH_DEFAULTS) +@RunWith(SpringRunner.class) public class JdbcAggregateTemplateIntegrationTests { - @ClassRule public static final SpringClassRule classRule = new SpringClassRule(); - @Rule public SpringMethodRule methodRule = new SpringMethodRule(); - @Autowired JdbcAggregateOperations template; @Autowired NamedParameterJdbcOperations jdbcTemplate; @@ -191,7 +188,7 @@ public class JdbcAggregateTemplateIntegrationTests { } @Test // DATAJDBC-112 - @RequiredFeature(SUPPORTS_QUOTED_IDS) + @EnabledOnFeature(SUPPORTS_QUOTED_IDS) public void saveAndLoadAnEntityWithReferencedEntityById() { template.save(legoSet); @@ -213,7 +210,7 @@ public class JdbcAggregateTemplateIntegrationTests { } @Test // DATAJDBC-112 - @RequiredFeature(SUPPORTS_QUOTED_IDS) + @EnabledOnFeature(SUPPORTS_QUOTED_IDS) public void saveAndLoadManyEntitiesWithReferencedEntity() { template.save(legoSet); @@ -226,7 +223,7 @@ public class JdbcAggregateTemplateIntegrationTests { } @Test // DATAJDBC-101 - @RequiredFeature(SUPPORTS_QUOTED_IDS) + @EnabledOnFeature(SUPPORTS_QUOTED_IDS) public void saveAndLoadManyEntitiesWithReferencedEntitySorted() { template.save(createLegoSet("Lava")); @@ -241,7 +238,7 @@ public class JdbcAggregateTemplateIntegrationTests { } @Test // DATAJDBC-101 - @RequiredFeature(SUPPORTS_QUOTED_IDS) + @EnabledOnFeature(SUPPORTS_QUOTED_IDS) public void saveAndLoadManyEntitiesWithReferencedEntitySortedAndPaged() { template.save(createLegoSet("Lava")); @@ -256,7 +253,7 @@ public class JdbcAggregateTemplateIntegrationTests { } @Test // DATAJDBC-112 - @RequiredFeature(SUPPORTS_QUOTED_IDS) + @EnabledOnFeature(SUPPORTS_QUOTED_IDS) public void saveAndLoadManyEntitiesByIdWithReferencedEntity() { template.save(legoSet); @@ -268,7 +265,7 @@ public class JdbcAggregateTemplateIntegrationTests { } @Test // DATAJDBC-112 - @RequiredFeature(SUPPORTS_QUOTED_IDS) + @EnabledOnFeature(SUPPORTS_QUOTED_IDS) public void saveAndLoadAnEntityWithReferencedNullEntity() { legoSet.setManual(null); @@ -281,7 +278,7 @@ public class JdbcAggregateTemplateIntegrationTests { } @Test // DATAJDBC-112 - @RequiredFeature(SUPPORTS_QUOTED_IDS) + @EnabledOnFeature(SUPPORTS_QUOTED_IDS) public void saveAndDeleteAnEntityWithReferencedEntity() { template.save(legoSet); @@ -297,7 +294,7 @@ public class JdbcAggregateTemplateIntegrationTests { } @Test // DATAJDBC-112 - @RequiredFeature(SUPPORTS_QUOTED_IDS) + @EnabledOnFeature(SUPPORTS_QUOTED_IDS) public void saveAndDeleteAllWithReferencedEntity() { template.save(legoSet); @@ -313,7 +310,7 @@ public class JdbcAggregateTemplateIntegrationTests { } @Test // DATAJDBC-112 - @RequiredFeature(SUPPORTS_QUOTED_IDS) + @EnabledOnFeature(SUPPORTS_QUOTED_IDS) public void updateReferencedEntityFromNull() { legoSet.setManual(null); @@ -332,7 +329,7 @@ public class JdbcAggregateTemplateIntegrationTests { } @Test // DATAJDBC-112 - @RequiredFeature(SUPPORTS_QUOTED_IDS) + @EnabledOnFeature(SUPPORTS_QUOTED_IDS) public void updateReferencedEntityToNull() { template.save(legoSet); @@ -363,7 +360,7 @@ public class JdbcAggregateTemplateIntegrationTests { } @Test // DATAJDBC-112 - @RequiredFeature(SUPPORTS_QUOTED_IDS) + @EnabledOnFeature(SUPPORTS_QUOTED_IDS) public void replaceReferencedEntity() { template.save(legoSet); @@ -385,7 +382,7 @@ public class JdbcAggregateTemplateIntegrationTests { } @Test // DATAJDBC-112 - @RequiredFeature({SUPPORTS_QUOTED_IDS, TestDatabaseFeatures.Feature.SUPPORTS_GENERATED_IDS_IN_REFERENCED_ENTITIES}) + @EnabledOnFeature({ SUPPORTS_QUOTED_IDS, TestDatabaseFeatures.Feature.SUPPORTS_GENERATED_IDS_IN_REFERENCED_ENTITIES }) public void changeReferencedEntity() { template.save(legoSet); @@ -400,7 +397,7 @@ public class JdbcAggregateTemplateIntegrationTests { } @Test // DATAJDBC-266 - @RequiredFeature(SUPPORTS_QUOTED_IDS) + @EnabledOnFeature(SUPPORTS_QUOTED_IDS) public void oneToOneChildWithoutId() { OneToOneParent parent = new OneToOneParent(); @@ -417,7 +414,7 @@ public class JdbcAggregateTemplateIntegrationTests { } @Test // DATAJDBC-266 - @RequiredFeature(SUPPORTS_QUOTED_IDS) + @EnabledOnFeature(SUPPORTS_QUOTED_IDS) public void oneToOneNullChildWithoutId() { OneToOneParent parent = new OneToOneParent(); @@ -433,7 +430,7 @@ public class JdbcAggregateTemplateIntegrationTests { } @Test // DATAJDBC-266 - @RequiredFeature(SUPPORTS_QUOTED_IDS) + @EnabledOnFeature(SUPPORTS_QUOTED_IDS) public void oneToOneNullAttributes() { OneToOneParent parent = new OneToOneParent(); @@ -449,7 +446,7 @@ public class JdbcAggregateTemplateIntegrationTests { } @Test // DATAJDBC-125 - @RequiredFeature(SUPPORTS_QUOTED_IDS) + @EnabledOnFeature(SUPPORTS_QUOTED_IDS) public void saveAndLoadAnEntityWithSecondaryReferenceNull() { template.save(legoSet); @@ -462,7 +459,7 @@ public class JdbcAggregateTemplateIntegrationTests { } @Test // DATAJDBC-125 - @RequiredFeature(SUPPORTS_QUOTED_IDS) + @EnabledOnFeature(SUPPORTS_QUOTED_IDS) public void saveAndLoadAnEntityWithSecondaryReferenceNotNull() { legoSet.alternativeInstructions = new Manual(); @@ -484,7 +481,7 @@ public class JdbcAggregateTemplateIntegrationTests { } @Test // DATAJDBC-276 - @RequiredFeature(SUPPORTS_QUOTED_IDS) + @EnabledOnFeature(SUPPORTS_QUOTED_IDS) public void saveAndLoadAnEntityWithListOfElementsWithoutId() { ListParent entity = new ListParent(); @@ -503,7 +500,7 @@ public class JdbcAggregateTemplateIntegrationTests { } @Test // DATAJDBC-259 - @RequiredFeature(SUPPORTS_ARRAYS) + @EnabledOnFeature(SUPPORTS_ARRAYS) public void saveAndLoadAnEntityWithArray() { ArrayOwner arrayOwner = new ArrayOwner(); @@ -521,7 +518,7 @@ public class JdbcAggregateTemplateIntegrationTests { } @Test // DATAJDBC-259, DATAJDBC-512 - @RequiredFeature(SUPPORTS_MULTIDIMENSIONAL_ARRAYS) + @EnabledOnFeature(SUPPORTS_MULTIDIMENSIONAL_ARRAYS) public void saveAndLoadAnEntityWithMultidimensionalArray() { ArrayOwner arrayOwner = new ArrayOwner(); @@ -540,7 +537,7 @@ public class JdbcAggregateTemplateIntegrationTests { } @Test // DATAJDBC-259 - @RequiredFeature(SUPPORTS_ARRAYS) + @EnabledOnFeature(SUPPORTS_ARRAYS) public void saveAndLoadAnEntityWithList() { ListOwner arrayOwner = new ListOwner(); @@ -558,7 +555,7 @@ public class JdbcAggregateTemplateIntegrationTests { } @Test // DATAJDBC-259 - @RequiredFeature(SUPPORTS_ARRAYS) + @EnabledOnFeature(SUPPORTS_ARRAYS) public void saveAndLoadAnEntityWithSet() { SetOwner setOwner = new SetOwner(); @@ -591,7 +588,7 @@ public class JdbcAggregateTemplateIntegrationTests { } @Test // DATAJDBC-340 - @RequiredFeature(SUPPORTS_QUOTED_IDS) + @EnabledOnFeature(SUPPORTS_QUOTED_IDS) public void saveAndLoadLongChain() { Chain4 chain4 = new Chain4(); @@ -620,7 +617,7 @@ public class JdbcAggregateTemplateIntegrationTests { } @Test // DATAJDBC-359 - @RequiredFeature(SUPPORTS_QUOTED_IDS) + @EnabledOnFeature(SUPPORTS_QUOTED_IDS) public void saveAndLoadLongChainWithoutIds() { NoIdChain4 chain4 = new NoIdChain4(); @@ -705,7 +702,7 @@ public class JdbcAggregateTemplateIntegrationTests { } @Test // DATAJDBC-431 - @RequiredFeature(IS_HSQL) + @EnabledOnFeature(IS_HSQL) public void readOnlyGetsLoadedButNotWritten() { WithReadOnly entity = new WithReadOnly(); @@ -813,7 +810,7 @@ public class JdbcAggregateTemplateIntegrationTests { } @Test // DATAJDBC-462 - @RequiredFeature(SUPPORTS_QUOTED_IDS) + @EnabledOnFeature(SUPPORTS_QUOTED_IDS) public void resavingAnUnversionedEntity() { LegoSet legoSet = new LegoSet(); diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateTemplateSchemaIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateTemplateSchemaIntegrationTests.java index 0be9a8f6..0ee9b7f9 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateTemplateSchemaIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/JdbcAggregateTemplateSchemaIntegrationTests.java @@ -19,9 +19,9 @@ import static org.assertj.core.api.Assertions.*; import static org.springframework.data.jdbc.testing.TestDatabaseFeatures.Feature.*; import static org.springframework.test.context.TestExecutionListeners.MergeMode.*; -import org.junit.ClassRule; -import org.junit.Rule; import org.junit.Test; +import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.annotation.Bean; @@ -31,15 +31,14 @@ import org.springframework.data.annotation.Id; import org.springframework.data.jdbc.core.convert.DataAccessStrategy; import org.springframework.data.jdbc.core.convert.JdbcConverter; import org.springframework.data.jdbc.testing.AssumeFeatureRule; -import org.springframework.data.jdbc.testing.RequiredFeature; +import org.springframework.data.jdbc.testing.EnabledOnFeature; import org.springframework.data.jdbc.testing.TestConfiguration; import org.springframework.data.relational.core.mapping.NamingStrategy; import org.springframework.data.relational.core.mapping.RelationalMappingContext; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestExecutionListeners; -import org.springframework.test.context.junit4.rules.SpringClassRule; -import org.springframework.test.context.junit4.rules.SpringMethodRule; +import org.springframework.test.context.junit4.SpringRunner; import org.springframework.transaction.annotation.Transactional; /** @@ -50,16 +49,14 @@ import org.springframework.transaction.annotation.Transactional; @ContextConfiguration @Transactional @TestExecutionListeners(value = AssumeFeatureRule.class, mergeMode = MERGE_WITH_DEFAULTS) +@RunWith(SpringRunner.class) public class JdbcAggregateTemplateSchemaIntegrationTests { - @ClassRule public static final SpringClassRule classRule = new SpringClassRule(); - @Rule public SpringMethodRule methodRule = new SpringMethodRule(); - @Autowired JdbcAggregateOperations template; @Autowired NamedParameterJdbcOperations jdbcTemplate; @Test - @RequiredFeature(SUPPORTS_QUOTED_IDS) + @EnabledOnFeature(SUPPORTS_QUOTED_IDS) public void insertFindUpdateDelete() { DummyEntity entity = new DummyEntity(); diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryCustomConversionIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryCustomConversionIntegrationTests.java index bd9f4b49..35d5d3ca 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryCustomConversionIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryCustomConversionIntegrationTests.java @@ -24,9 +24,9 @@ import java.sql.JDBCType; import java.util.Date; import org.assertj.core.api.SoftAssertions; -import org.junit.ClassRule; -import org.junit.Rule; import org.junit.Test; +import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -40,12 +40,10 @@ import org.springframework.data.jdbc.core.convert.JdbcValue; import org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory; import org.springframework.data.jdbc.testing.AssumeFeatureRule; import org.springframework.data.jdbc.testing.TestConfiguration; -import org.springframework.data.jdbc.testing.TestDatabaseFeatures; import org.springframework.data.repository.CrudRepository; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestExecutionListeners; -import org.springframework.test.context.junit4.rules.SpringClassRule; -import org.springframework.test.context.junit4.rules.SpringMethodRule; +import org.springframework.test.context.junit4.SpringRunner; import org.springframework.transaction.annotation.Transactional; /** @@ -57,6 +55,7 @@ import org.springframework.transaction.annotation.Transactional; @ContextConfiguration @Transactional @TestExecutionListeners(value = AssumeFeatureRule.class, mergeMode = MERGE_WITH_DEFAULTS) +@RunWith(SpringRunner.class) public class JdbcRepositoryCustomConversionIntegrationTests { @Configuration @@ -82,9 +81,6 @@ public class JdbcRepositoryCustomConversionIntegrationTests { } } - @ClassRule public static final SpringClassRule classRule = new SpringClassRule(); - @Rule public SpringMethodRule methodRule = new SpringMethodRule(); - @Autowired EntityWithBooleanRepository repository; /** diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedNotInAggregateRootIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedNotInAggregateRootIntegrationTests.java index 1170f55d..ee3a1e44 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedNotInAggregateRootIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedNotInAggregateRootIntegrationTests.java @@ -23,9 +23,9 @@ import lombok.Data; import java.sql.SQLException; -import org.junit.ClassRule; -import org.junit.Rule; import org.junit.Test; +import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -34,7 +34,6 @@ import org.springframework.data.annotation.Id; import org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory; import org.springframework.data.jdbc.testing.AssumeFeatureRule; import org.springframework.data.jdbc.testing.TestConfiguration; -import org.springframework.data.jdbc.testing.TestDatabaseFeatures; import org.springframework.data.relational.core.dialect.Dialect; import org.springframework.data.relational.core.mapping.Column; import org.springframework.data.relational.core.mapping.Embedded; @@ -45,8 +44,7 @@ import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestExecutionListeners; -import org.springframework.test.context.junit4.rules.SpringClassRule; -import org.springframework.test.context.junit4.rules.SpringMethodRule; +import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.jdbc.JdbcTestUtils; import org.springframework.transaction.annotation.Transactional; @@ -58,10 +56,9 @@ import org.springframework.transaction.annotation.Transactional; @ContextConfiguration @Transactional @TestExecutionListeners(value = AssumeFeatureRule.class, mergeMode = MERGE_WITH_DEFAULTS) +@RunWith(SpringRunner.class) public class JdbcRepositoryEmbeddedNotInAggregateRootIntegrationTests { - @ClassRule public static final SpringClassRule classRule = new SpringClassRule(); - @Rule public SpringMethodRule methodRule = new SpringMethodRule(); @Autowired NamedParameterJdbcTemplate template; @Autowired DummyEntityRepository repository; @Autowired Dialect dialect; diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedWithReferenceIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedWithReferenceIntegrationTests.java index 41f80044..de8d21d2 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedWithReferenceIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryEmbeddedWithReferenceIntegrationTests.java @@ -23,9 +23,9 @@ import lombok.Data; import java.util.List; -import org.junit.ClassRule; -import org.junit.Rule; import org.junit.Test; +import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -34,7 +34,6 @@ import org.springframework.data.annotation.Id; import org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory; import org.springframework.data.jdbc.testing.AssumeFeatureRule; import org.springframework.data.jdbc.testing.TestConfiguration; -import org.springframework.data.jdbc.testing.TestDatabaseFeatures; import org.springframework.data.relational.core.dialect.Dialect; import org.springframework.data.relational.core.mapping.Column; import org.springframework.data.relational.core.mapping.Embedded; @@ -45,8 +44,7 @@ import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestExecutionListeners; -import org.springframework.test.context.junit4.rules.SpringClassRule; -import org.springframework.test.context.junit4.rules.SpringMethodRule; +import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.jdbc.JdbcTestUtils; import org.springframework.transaction.annotation.Transactional; @@ -59,10 +57,9 @@ import org.springframework.transaction.annotation.Transactional; @ContextConfiguration @Transactional @TestExecutionListeners(value = AssumeFeatureRule.class, mergeMode = MERGE_WITH_DEFAULTS) +@RunWith(SpringRunner.class) public class JdbcRepositoryEmbeddedWithReferenceIntegrationTests { - @ClassRule public static final SpringClassRule classRule = new SpringClassRule(); - @Rule public SpringMethodRule methodRule = new SpringMethodRule(); @Autowired NamedParameterJdbcTemplate template; @Autowired DummyEntityRepository repository; @Autowired Dialect dialect; diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryIntegrationTests.java index 1d8d88e5..7d12ec14 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryIntegrationTests.java @@ -30,9 +30,9 @@ import java.util.ArrayList; import java.util.List; import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Rule; import org.junit.Test; +import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.PropertiesFactoryBean; import org.springframework.context.ApplicationListener; @@ -44,9 +44,8 @@ import org.springframework.data.annotation.Id; import org.springframework.data.jdbc.repository.query.Query; import org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory; import org.springframework.data.jdbc.testing.AssumeFeatureRule; -import org.springframework.data.jdbc.testing.RequiredFeature; +import org.springframework.data.jdbc.testing.EnabledOnFeature; import org.springframework.data.jdbc.testing.TestConfiguration; -import org.springframework.data.jdbc.testing.TestDatabaseFeatures; import org.springframework.data.relational.core.mapping.event.AbstractRelationalEvent; import org.springframework.data.relational.core.mapping.event.AfterLoadEvent; import org.springframework.data.repository.CrudRepository; @@ -57,8 +56,7 @@ import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.test.context.TestExecutionListeners; -import org.springframework.test.context.junit4.rules.SpringClassRule; -import org.springframework.test.context.junit4.rules.SpringMethodRule; +import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.jdbc.JdbcTestUtils; import org.springframework.transaction.annotation.Transactional; @@ -70,10 +68,9 @@ import org.springframework.transaction.annotation.Transactional; */ @Transactional @TestExecutionListeners(value = AssumeFeatureRule.class, mergeMode = MERGE_WITH_DEFAULTS) +@RunWith(SpringRunner.class) public class JdbcRepositoryIntegrationTests { - @ClassRule public static final SpringClassRule classRule = new SpringClassRule(); - @Rule public SpringMethodRule methodRule = new SpringMethodRule(); @Autowired NamedParameterJdbcTemplate template; @Autowired DummyEntityRepository repository; @Autowired MyEventListener eventListener; @@ -262,7 +259,7 @@ public class JdbcRepositoryIntegrationTests { } @Test // DATAJDBC-464, DATAJDBC-318 - @RequiredFeature(SUPPORTS_DATE_DATATYPES) + @EnabledOnFeature(SUPPORTS_DATE_DATATYPES) public void executeQueryWithParameterRequiringConversion() { Instant now = Instant.now(); diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryPropertyConversionIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryPropertyConversionIntegrationTests.java index 85749fe7..8b44205d 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryPropertyConversionIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryPropertyConversionIntegrationTests.java @@ -32,9 +32,9 @@ import java.util.Date; import org.assertj.core.api.Condition; import org.assertj.core.api.SoftAssertions; -import org.junit.ClassRule; -import org.junit.Rule; import org.junit.Test; +import org.junit.runner.RunWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationListener; import org.springframework.context.annotation.Bean; @@ -43,15 +43,13 @@ import org.springframework.context.annotation.Import; import org.springframework.data.annotation.Id; import org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory; import org.springframework.data.jdbc.testing.AssumeFeatureRule; -import org.springframework.data.jdbc.testing.RequiredFeature; +import org.springframework.data.jdbc.testing.EnabledOnFeature; import org.springframework.data.jdbc.testing.TestConfiguration; -import org.springframework.data.jdbc.testing.TestDatabaseFeatures; import org.springframework.data.relational.core.mapping.event.BeforeSaveEvent; import org.springframework.data.repository.CrudRepository; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestExecutionListeners; -import org.springframework.test.context.junit4.rules.SpringClassRule; -import org.springframework.test.context.junit4.rules.SpringMethodRule; +import org.springframework.test.context.junit4.SpringRunner; import org.springframework.transaction.annotation.Transactional; /** @@ -64,10 +62,9 @@ import org.springframework.transaction.annotation.Transactional; @ContextConfiguration @Transactional @TestExecutionListeners(value = AssumeFeatureRule.class, mergeMode = MERGE_WITH_DEFAULTS) +@RunWith(SpringRunner.class) public class JdbcRepositoryPropertyConversionIntegrationTests { - @ClassRule public static final SpringClassRule classRule = new SpringClassRule(); - @Rule public SpringMethodRule methodRule = new SpringMethodRule(); @Autowired DummyEntityRepository repository; private static EntityWithColumnsRequiringConversions createDummyEntity() { @@ -90,7 +87,7 @@ public class JdbcRepositoryPropertyConversionIntegrationTests { } @Test // DATAJDBC-95 - @RequiredFeature(SUPPORTS_HUGE_NUMBERS) + @EnabledOnFeature(SUPPORTS_HUGE_NUMBERS) public void saveAndLoadAnEntity() { EntityWithColumnsRequiringConversions entity = repository.save(createDummyEntity()); @@ -109,7 +106,7 @@ public class JdbcRepositoryPropertyConversionIntegrationTests { } @Test // DATAJDBC-95 - @RequiredFeature(SUPPORTS_HUGE_NUMBERS) + @EnabledOnFeature(SUPPORTS_HUGE_NUMBERS) public void existsById() { EntityWithColumnsRequiringConversions entity = repository.save(createDummyEntity()); @@ -118,7 +115,7 @@ public class JdbcRepositoryPropertyConversionIntegrationTests { } @Test // DATAJDBC-95 - @RequiredFeature(SUPPORTS_HUGE_NUMBERS) + @EnabledOnFeature(SUPPORTS_HUGE_NUMBERS) public void findAllById() { EntityWithColumnsRequiringConversions entity = repository.save(createDummyEntity()); @@ -127,7 +124,7 @@ public class JdbcRepositoryPropertyConversionIntegrationTests { } @Test // DATAJDBC-95 - @RequiredFeature(SUPPORTS_HUGE_NUMBERS) + @EnabledOnFeature(SUPPORTS_HUGE_NUMBERS) public void deleteAll() { EntityWithColumnsRequiringConversions entity = repository.save(createDummyEntity()); @@ -138,7 +135,7 @@ public class JdbcRepositoryPropertyConversionIntegrationTests { } @Test // DATAJDBC-95 - @RequiredFeature(SUPPORTS_HUGE_NUMBERS) + @EnabledOnFeature(SUPPORTS_HUGE_NUMBERS) public void deleteById() { EntityWithColumnsRequiringConversions entity = repository.save(createDummyEntity()); diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryWithCollectionsIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryWithCollectionsIntegrationTests.java index 728e2047..8c4eb803 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryWithCollectionsIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryWithCollectionsIntegrationTests.java @@ -35,9 +35,8 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.data.annotation.Id; import org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory; -import org.springframework.data.jdbc.testing.RequiredFeature; +import org.springframework.data.jdbc.testing.EnabledOnFeature; import org.springframework.data.jdbc.testing.TestConfiguration; -import org.springframework.data.jdbc.testing.TestDatabaseFeatures; import org.springframework.data.repository.CrudRepository; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.test.context.ContextConfiguration; @@ -128,7 +127,7 @@ public class JdbcRepositoryWithCollectionsIntegrationTests { } @Test // DATAJDBC-113 - @RequiredFeature(SUPPORTS_GENERATED_IDS_IN_REFERENCED_ENTITIES) + @EnabledOnFeature(SUPPORTS_GENERATED_IDS_IN_REFERENCED_ENTITIES) public void updateSet() { Element element1 = createElement("one"); diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryWithListsIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryWithListsIntegrationTests.java index 88d01f24..c33937d9 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryWithListsIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryWithListsIntegrationTests.java @@ -35,9 +35,8 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.data.annotation.Id; import org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory; -import org.springframework.data.jdbc.testing.RequiredFeature; +import org.springframework.data.jdbc.testing.EnabledOnFeature; import org.springframework.data.jdbc.testing.TestConfiguration; -import org.springframework.data.jdbc.testing.TestDatabaseFeatures; import org.springframework.data.repository.CrudRepository; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.test.context.ContextConfiguration; @@ -127,7 +126,7 @@ public class JdbcRepositoryWithListsIntegrationTests { } @Test // DATAJDBC-130 - @RequiredFeature(SUPPORTS_GENERATED_IDS_IN_REFERENCED_ENTITIES) + @EnabledOnFeature(SUPPORTS_GENERATED_IDS_IN_REFERENCED_ENTITIES) public void updateList() { Element element1 = createElement("one"); diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryWithMapsIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryWithMapsIntegrationTests.java index 471442c2..67627e81 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryWithMapsIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryWithMapsIntegrationTests.java @@ -34,9 +34,8 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.data.annotation.Id; import org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory; -import org.springframework.data.jdbc.testing.RequiredFeature; +import org.springframework.data.jdbc.testing.EnabledOnFeature; import org.springframework.data.jdbc.testing.TestConfiguration; -import org.springframework.data.jdbc.testing.TestDatabaseFeatures; import org.springframework.data.repository.CrudRepository; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.test.context.ContextConfiguration; @@ -139,7 +138,7 @@ public class JdbcRepositoryWithMapsIntegrationTests { } @Test // DATAJDBC-131 - @RequiredFeature(SUPPORTS_GENERATED_IDS_IN_REFERENCED_ENTITIES) + @EnabledOnFeature(SUPPORTS_GENERATED_IDS_IN_REFERENCED_ENTITIES) public void updateMap() { Element element1 = createElement("one"); diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/AssumeFeatureRule.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/AssumeFeatureRule.java index beea21a1..013820d3 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/AssumeFeatureRule.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/AssumeFeatureRule.java @@ -23,22 +23,28 @@ import org.springframework.context.ApplicationContext; import org.springframework.test.context.TestContext; import org.springframework.test.context.TestExecutionListener; +/** + * {@link TestExecutionListener} to evaluate {@link EnabledOnFeature} annotations. + * + * @author Jens Schauder + * @author Mark Paluch + */ public class AssumeFeatureRule implements TestExecutionListener { @Override - public void beforeTestMethod(TestContext testContext) throws Exception { + public void beforeTestMethod(TestContext testContext) { ApplicationContext applicationContext = testContext.getApplicationContext(); TestDatabaseFeatures databaseFeatures = applicationContext.getBean(TestDatabaseFeatures.class); List requiredFeatures = new ArrayList<>(); - RequiredFeature classAnnotation = testContext.getTestClass().getAnnotation(RequiredFeature.class); + EnabledOnFeature classAnnotation = testContext.getTestClass().getAnnotation(EnabledOnFeature.class); if (classAnnotation != null) { requiredFeatures.addAll(Arrays.asList(classAnnotation.value())); } - RequiredFeature methodAnnotation = testContext.getTestMethod().getAnnotation(RequiredFeature.class); + EnabledOnFeature methodAnnotation = testContext.getTestMethod().getAnnotation(EnabledOnFeature.class); if (methodAnnotation != null) { requiredFeatures.addAll(Arrays.asList(methodAnnotation.value())); } @@ -46,6 +52,5 @@ public class AssumeFeatureRule implements TestExecutionListener { for (TestDatabaseFeatures.Feature requiredFeature : requiredFeatures) { requiredFeature.test(databaseFeatures); } - } } diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/EnabledOnFeature.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/EnabledOnFeature.java new file mode 100644 index 00000000..bd5d34b2 --- /dev/null +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/EnabledOnFeature.java @@ -0,0 +1,53 @@ +/* + * Copyright 2020 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 org.springframework.data.jdbc.testing; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * {@code @RequiredFeature} is used to signal that the annotated test class or test method is only enabled on + * one or more specified Spring Data JDBC {@link org.springframework.data.jdbc.testing.TestDatabaseFeatures.Feature + * features} are supported by the underlying database. + *

+ * When applied at the class level, all test methods within that class will be enabled if they support all database + * features. + *

+ * If a test method is disabled via this annotation, that does not prevent the test class from being instantiated. + * Rather, it prevents the execution of the test method and method-level lifecycle callbacks such as {@code @BeforeEach} + * methods, {@code @AfterEach} methods, and corresponding extension APIs. When annotated on method and class level, all + * annotated features must match to run a test. + *

+ * This annotation cannot be used as meta-annotation. + * + * @author Jens Schauder + * @author Mark Paluch + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.METHOD, ElementType.TYPE }) +@Documented +public @interface EnabledOnFeature { + + /** + * Databases features on which the annotated class or method should be enabled. + * + * @see TestDatabaseFeatures.Feature + */ + TestDatabaseFeatures.Feature[] value(); +} diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/OracleDataSourceConfiguration.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/OracleDataSourceConfiguration.java index 2325fdf4..83d19536 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/OracleDataSourceConfiguration.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/OracleDataSourceConfiguration.java @@ -15,24 +15,25 @@ */ package org.springframework.data.jdbc.testing; +import static org.awaitility.pollinterval.FibonacciPollInterval.*; + +import java.sql.Connection; +import java.sql.SQLException; +import java.util.concurrent.TimeUnit; + import javax.sql.DataSource; import org.awaitility.Awaitility; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; import org.springframework.jdbc.datasource.DriverManagerDataSource; import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; + import org.testcontainers.containers.OracleContainer; -import java.sql.Connection; -import java.sql.SQLException; -import java.time.temporal.ChronoUnit; -import java.util.concurrent.TimeUnit; - -import static org.awaitility.pollinterval.FibonacciPollInterval.*; - /** * {@link DataSource} setup for Oracle Database XE. Starts a docker container with a Oracle database. * @@ -74,16 +75,13 @@ public class OracleDataSourceConfiguration extends DataSourceConfiguration { // Oracle container says its ready but it's like with a cat that denies service and still wants food although it had // its food. Therefore, we make sure that we can properly establish a connection instead of trusting the cat // ...err... Oracle. - Awaitility.await() - .atMost(5L, TimeUnit.MINUTES ) - .pollInterval(fibonacci(TimeUnit.SECONDS)) + Awaitility.await().atMost(5L, TimeUnit.MINUTES).pollInterval(fibonacci(TimeUnit.SECONDS)) .ignoreException(SQLException.class).until(() -> { - try (Connection connection = dataSource.getConnection()) { - return true; - } - }); - + try (Connection connection = dataSource.getConnection()) { + return true; + } + }); return dataSource; } diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/RequiredFeature.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/RequiredFeature.java deleted file mode 100644 index 903c3fe8..00000000 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/RequiredFeature.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2020 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 org.springframework.data.jdbc.testing; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD, ElementType.TYPE}) -public @interface RequiredFeature { - TestDatabaseFeatures.Feature[] value(); -} diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/dialect/IdGeneration.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/dialect/IdGeneration.java index 19285ff3..1528e67f 100644 --- a/spring-data-relational/src/main/java/org/springframework/data/relational/core/dialect/IdGeneration.java +++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/dialect/IdGeneration.java @@ -24,6 +24,7 @@ import java.sql.Connection; * @since 2.1 */ public interface IdGeneration { + /** * A default instance working for many databases and equivalent to Spring Data JDBCs behavior before version 2.1. */ @@ -33,11 +34,10 @@ public interface IdGeneration { * Does the driver require the specification of those columns for which a generated id shall be returned. *

* This should be {@literal false} for most dialects. One notable exception is Oracle. - * + * * @return {@literal true} if the a list of column names should get passed to the JDBC driver for which ids shall be * generated. - * - * @see Connection#prepareStatement(String, String[])? + * @see Connection#prepareStatement(String, String[]) */ default boolean driverRequiresKeyColumnNames() { return false; diff --git a/src/main/asciidoc/new-features.adoc b/src/main/asciidoc/new-features.adoc index 6c5dee91..af671875 100644 --- a/src/main/asciidoc/new-features.adoc +++ b/src/main/asciidoc/new-features.adoc @@ -3,6 +3,11 @@ This section covers the significant changes for each version. +[[new-features.2-1-0]] +== What's New in Spring Data JDBC 2.1 + +* Dialect for Oracle databases. + [[new-features.2-0-0]] == What's New in Spring Data JDBC 2.0 diff --git a/src/main/asciidoc/preface.adoc b/src/main/asciidoc/preface.adoc index d90edf23..f52514d6 100644 --- a/src/main/asciidoc/preface.adoc +++ b/src/main/asciidoc/preface.adoc @@ -46,6 +46,7 @@ Spring Data JDBC includes direct support for the following databases: * MariaDB * Microsoft SQL Server * MySQL +* Oracle * Postgres If you use a different database then your application won’t startup. The <> section contains further detail on how to proceed in such case.