From 1582a4d475fa3392aef96ebbe35faa7f3e0cd9a5 Mon Sep 17 00:00:00 2001 From: Jens Schauder Date: Tue, 14 Mar 2017 15:47:02 +0100 Subject: [PATCH] DATAJDBC-105 - Test with multiple databases. Different databases are now supported by means of Maven Profiles and Spring Profiles. There is one Profile for each supported database. The default Profile is equivalent to hql. There is a Maven Profile all-dbs, which runs the integration tests against all databases. The databases need to be started outside the build. The build assumes the default configuration as I found it after `brew install ` For now we support the databases mysql, postgres and hsqldb. In order to make the new databases work setting of properties and reading generated ids was improved to do some simple conversions. This might be considered a first step towards DATAJDBC-104. The project root contains some basic scripts for starting and stopping databases, as well as running a build against all supported databases. Integration tests using a database now use Rules instead of JUnit runners. This gives more flexibility when adding fancy stuff to the Tests in the form of other Rules. Related issue: DATAJDBC-104. Original pull request: #5. --- pom.xml | 78 ++++++++++++++- readme.md | 29 ++++++ run-tests-against-all-dbs.sh | 3 + .../jdbc/mapping/event/AfterCreation.java | 3 +- .../data/jdbc/mapping/event/AfterDelete.java | 7 +- .../data/jdbc/mapping/event/AfterSave.java | 2 - .../data/jdbc/mapping/event/BeforeInsert.java | 5 +- .../data/jdbc/mapping/event/BeforeSave.java | 2 - .../data/jdbc/mapping/event/Identifier.java | 12 +-- .../data/jdbc/mapping/event/JdbcEvent.java | 21 ++-- .../jdbc/mapping/event/JdbcEventWithId.java | 2 +- .../data/jdbc/mapping/event/WithEntity.java | 3 +- .../data/jdbc/mapping/event/WithId.java | 9 +- .../mapping/model/JdbcPersistentEntity.java | 2 +- .../data/jdbc/repository/EntityRowMapper.java | 17 +++- .../EventPublishingEntityRowMapper.java | 7 +- .../jdbc/repository/SimpleJdbcRepository.java | 62 ++++++++---- .../data/jdbc/repository/SqlGenerator.java | 78 +++++++++------ .../EventPublishingEntityRowMapperTest.java | 6 +- ...epositoryIdGenerationIntegrationTests.java | 49 ++++------ .../JdbcRepositoryIntegrationTests.java | 96 +++++++++---------- .../SimpleJdbcRepositoryEventsUnitTests.java | 42 ++++---- .../jdbc/testing/DataSourceFactoryBean.java | 59 ++++++++++++ .../testing/HsqlDataSourceFactoryBean.java | 52 ++++++++++ .../testing/MySqlDataSourceFactoryBean.java | 84 ++++++++++++++++ .../PostgresDataSourceFactoryBean.java | 69 +++++++++++++ src/test/resources/create-mysql.sql | 2 + ...toryIdGenerationIntegrationTests-hsql.sql} | 1 - ...toryIdGenerationIntegrationTests-mysql.sql | 2 + ...yIdGenerationIntegrationTests-postgres.sql | 5 + .../JdbcRepositoryIntegrationTests-hsql.sql | 1 + .../JdbcRepositoryIntegrationTests-mysql.sql | 1 + ...dbcRepositoryIntegrationTests-postgres.sql | 2 + .../jdbc-repository-integration-tests.sql | 1 - start-all-dbs.sh | 7 ++ stop-all-dbs.sh | 7 ++ 36 files changed, 626 insertions(+), 202 deletions(-) create mode 100755 run-tests-against-all-dbs.sh create mode 100644 src/test/java/org/springframework/data/jdbc/testing/DataSourceFactoryBean.java create mode 100644 src/test/java/org/springframework/data/jdbc/testing/HsqlDataSourceFactoryBean.java create mode 100644 src/test/java/org/springframework/data/jdbc/testing/MySqlDataSourceFactoryBean.java create mode 100644 src/test/java/org/springframework/data/jdbc/testing/PostgresDataSourceFactoryBean.java create mode 100644 src/test/resources/create-mysql.sql rename src/test/resources/org.springframework.data.jdbc.repository/{jdbc-repository-id-generation-integration-tests.sql => JdbcRepositoryIdGenerationIntegrationTests-hsql.sql} (99%) create mode 100644 src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIdGenerationIntegrationTests-mysql.sql create mode 100644 src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIdGenerationIntegrationTests-postgres.sql create mode 100644 src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-hsql.sql create mode 100644 src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-mysql.sql create mode 100644 src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-postgres.sql delete mode 100644 src/test/resources/org.springframework.data.jdbc.repository/jdbc-repository-integration-tests.sql create mode 100755 start-all-dbs.sh create mode 100755 stop-all-dbs.sh diff --git a/pom.xml b/pom.xml index cef9f314..ba6948c9 100644 --- a/pom.xml +++ b/pom.xml @@ -42,6 +42,50 @@ + + + all-dbs + + + + org.apache.maven.plugins + maven-surefire-plugin + + + mysql-test + test + + test + + + + **/*IntegrationTests.java + + + mysql + + + + + postgres-test + test + + test + + + + **/*IntegrationTests.java + + + postgres + + + + + + + + @@ -97,10 +141,33 @@ test + + mysql + mysql-connector-java + 5.1.41 + test + + + + org.postgresql + postgresql + 42.0.0 + test + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.12 + + +