From eae8c3b068a285effef9b3625541965b74403a77 Mon Sep 17 00:00:00 2001 From: Alvaro Date: Tue, 15 Oct 2024 11:12:08 +0200 Subject: [PATCH 01/10] Add testcontainers to jfleet core --- gradle.properties | 3 +- jfleet-core/build.gradle | 5 ++ .../jdbc/JdbcTransactionPolicyTest.java | 21 +++-- .../jfleet/mysql/MySqlReservedWordTest.java | 25 +++--- .../mysql/MySqlTransactionPolicyTest.java | 31 ++++---- .../org/jfleet/mysql/error/LockRetryTest.java | 31 ++++---- .../jfleet/mysql/manual/ConnectionTest.java | 25 +++--- .../java/org/jfleet/mysql/manual/IdsTest.java | 23 +++--- .../DatabaseArgumentProvider.java | 77 +++++++++++-------- .../parameterized/IsMySql5Condition.java | 16 +++- .../jfleet/parameterized/IsMySql5Present.java | 1 + ...istenceWithMillisecondsResolutionTest.java | 30 +++----- .../postgres/PostgresReservedWordTest.java | 25 +++--- .../PostgresTransactionPolicyTest.java | 30 ++++---- .../postgres/manual/ConnectionTest.java | 22 +++--- .../shared/DateTypePersistenceTest.java | 16 ++-- .../shared/EmbeddedEntityPersistenceTest.java | 18 ++--- .../java/org/jfleet/shared/EncodingTest.java | 17 ++-- .../org/jfleet/shared/IdPersistenceTest.java | 19 ++--- .../shared/ManyToOnePersistenceTest.java | 21 ++--- .../shared/SimpleEntityPersistenceTest.java | 17 ++-- .../shared/SpecialCharsPersistenceTest.java | 25 +++--- .../jfleet/shared/TypePersistenceTest.java | 16 ++-- .../test/java/org/jfleet/util/Database.java | 19 ++--- .../util/DatabaseTestConnectionProvider.java | 20 ++--- .../java/org/jfleet/util/JdbcDatabase.java | 5 +- .../org/jfleet/util/JdbcMysqlDatabase.java | 10 +-- .../org/jfleet/util/JdbcPostgresDatabase.java | 10 +-- .../java/org/jfleet/util/MySqlDatabase.java | 9 +-- .../org/jfleet/util/PostgresDatabase.java | 9 +-- .../util/TransactionPolicyTestHelper.java | 6 +- .../src/test/resources/mysql-test.properties | 4 - .../test/resources/postgres-test.properties | 4 - 33 files changed, 296 insertions(+), 314 deletions(-) delete mode 100644 jfleet-core/src/test/resources/mysql-test.properties delete mode 100644 jfleet-core/src/test/resources/postgres-test.properties diff --git a/gradle.properties b/gradle.properties index ec2fab2..f426aa9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,4 +3,5 @@ version = 0.6.7 parquetVersion = 1.13.1 hadoopVersion = 3.3.5 -junitVersion = 5.10.2 \ No newline at end of file +junitVersion = 5.10.2 +testContainersVersion = 1.20.2 \ No newline at end of file diff --git a/jfleet-core/build.gradle b/jfleet-core/build.gradle index 2f09b3e..55c1287 100644 --- a/jfleet-core/build.gradle +++ b/jfleet-core/build.gradle @@ -37,6 +37,11 @@ dependencies { testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: junitVersion testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: junitVersion testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: junitVersion + testImplementation group: 'org.testcontainers', name: 'testcontainers', version: testContainersVersion + testImplementation group: 'org.testcontainers', name: 'junit-jupiter', version: testContainersVersion + testImplementation group: 'org.testcontainers', name: 'mysql', version: testContainersVersion + testImplementation group: 'org.testcontainers', name: 'postgresql', version: testContainersVersion + } test { diff --git a/jfleet-core/src/test/java/org/jfleet/jdbc/JdbcTransactionPolicyTest.java b/jfleet-core/src/test/java/org/jfleet/jdbc/JdbcTransactionPolicyTest.java index 739e4e8..43b3621 100644 --- a/jfleet-core/src/test/java/org/jfleet/jdbc/JdbcTransactionPolicyTest.java +++ b/jfleet-core/src/test/java/org/jfleet/jdbc/JdbcTransactionPolicyTest.java @@ -15,18 +15,6 @@ */ package org.jfleet.jdbc; -import static org.jfleet.parameterized.Databases.JdbcMySql; -import static org.jfleet.parameterized.Databases.JdbcPosgres; -import static org.jfleet.util.TransactionPolicyTestHelper.employeesWithConstraintError; -import static org.jfleet.util.TransactionPolicyTestHelper.employeesWithOutErrors; -import static org.jfleet.util.TransactionPolicyTestHelper.numberOfRowsInEmployeeTable; -import static org.jfleet.util.TransactionPolicyTestHelper.setupDatabase; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.sql.Connection; -import java.sql.SQLException; - import org.jfleet.BulkInsert; import org.jfleet.entities.Employee; import org.jfleet.jdbc.JdbcConfiguration.JdbcConfigurationBuilder; @@ -36,6 +24,15 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.sql.Connection; +import java.sql.SQLException; + +import static org.jfleet.parameterized.Databases.JdbcMySql; +import static org.jfleet.parameterized.Databases.JdbcPosgres; +import static org.jfleet.util.TransactionPolicyTestHelper.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + public class JdbcTransactionPolicyTest { private static Logger logger = LoggerFactory.getLogger(JdbcTransactionPolicyTest.class); diff --git a/jfleet-core/src/test/java/org/jfleet/mysql/MySqlReservedWordTest.java b/jfleet-core/src/test/java/org/jfleet/mysql/MySqlReservedWordTest.java index a328758..2d9b862 100644 --- a/jfleet-core/src/test/java/org/jfleet/mysql/MySqlReservedWordTest.java +++ b/jfleet-core/src/test/java/org/jfleet/mysql/MySqlReservedWordTest.java @@ -15,26 +15,29 @@ */ package org.jfleet.mysql; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import org.jfleet.BulkInsert; +import org.jfleet.parameterized.DatabaseArgumentProvider; +import org.jfleet.util.MySqlDatabase; +import org.jfleet.util.SqlUtil; +import org.junit.jupiter.api.Test; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; import java.util.stream.IntStream; import java.util.stream.Stream; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Table; - -import org.jfleet.BulkInsert; -import org.jfleet.util.MySqlDatabase; -import org.jfleet.util.SqlUtil; -import org.junit.jupiter.api.Test; +import static org.jfleet.parameterized.Databases.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class MySqlReservedWordTest { + private final MySqlDatabase database = (MySqlDatabase) DatabaseArgumentProvider.getDatabaseContainer(MySql); + @Entity @Table(name = "\"select\"") public class ReservedWordEntity { @@ -65,7 +68,7 @@ public void canPersistWithReservedWords() throws Exception { Stream stream = IntStream.range(0, times) .mapToObj(i -> new ReservedWordEntity(i, "current_user_" + i)); - try (Connection conn = new MySqlDatabase().getConnection()) { + try (Connection conn = database.getConnection()) { SqlUtil.createTableForEntity(conn, ReservedWordEntity.class); insert.insertAll(conn, stream); diff --git a/jfleet-core/src/test/java/org/jfleet/mysql/MySqlTransactionPolicyTest.java b/jfleet-core/src/test/java/org/jfleet/mysql/MySqlTransactionPolicyTest.java index 19e213b..8e874c5 100644 --- a/jfleet-core/src/test/java/org/jfleet/mysql/MySqlTransactionPolicyTest.java +++ b/jfleet-core/src/test/java/org/jfleet/mysql/MySqlTransactionPolicyTest.java @@ -15,39 +15,35 @@ */ package org.jfleet.mysql; -import static org.jfleet.mysql.LoadDataConfiguration.LoadDataConfigurationBuilder.from; -import static org.jfleet.util.TransactionPolicyTestHelper.employeesWithForeignKeyError; -import static org.jfleet.util.TransactionPolicyTestHelper.employeesWithMultipleConstraintsErrors; -import static org.jfleet.util.TransactionPolicyTestHelper.employeesWithOutErrors; -import static org.jfleet.util.TransactionPolicyTestHelper.employeesWithUniqueError; -import static org.jfleet.util.TransactionPolicyTestHelper.numberOfRowsInEmployeeTable; -import static org.jfleet.util.TransactionPolicyTestHelper.setupDatabase; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.io.IOException; -import java.sql.Connection; -import java.sql.SQLException; - import org.jfleet.BulkInsert; import org.jfleet.JFleetException; import org.jfleet.entities.Employee; -import org.jfleet.util.Database; +import org.jfleet.parameterized.DatabaseArgumentProvider; import org.jfleet.util.MySqlDatabase; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.IOException; +import java.sql.Connection; +import java.sql.SQLException; + +import static org.jfleet.mysql.LoadDataConfiguration.LoadDataConfigurationBuilder.from; +import static org.jfleet.parameterized.Databases.MySql; +import static org.jfleet.util.TransactionPolicyTestHelper.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + public class MySqlTransactionPolicyTest { private static Logger logger = LoggerFactory.getLogger(MySqlTransactionPolicyTest.class); private static final int VERY_LOW_SIZE_TO_FREQUENT_LOAD_DATA = 10; - private Database database = new MySqlDatabase(); + private final MySqlDatabase database = (MySqlDatabase) DatabaseArgumentProvider.getDatabaseContainer(MySql); @BeforeEach - public void setup() throws IOException, SQLException { + public void setup() throws SQLException, IOException { try (Connection connection = database.getConnection()) { setupDatabase(connection); } @@ -55,6 +51,7 @@ public void setup() throws IOException, SQLException { @Test public void longTransactionExecuteMultipleLoadDataOperationsTransactionaly() throws Exception { + try (Connection connection = database.getConnection()) { connection.setAutoCommit(false); diff --git a/jfleet-core/src/test/java/org/jfleet/mysql/error/LockRetryTest.java b/jfleet-core/src/test/java/org/jfleet/mysql/error/LockRetryTest.java index 9497631..21476e3 100644 --- a/jfleet-core/src/test/java/org/jfleet/mysql/error/LockRetryTest.java +++ b/jfleet-core/src/test/java/org/jfleet/mysql/error/LockRetryTest.java @@ -15,42 +15,43 @@ */ package org.jfleet.mysql.error; -import static org.jfleet.mysql.LoadDataConfiguration.LoadDataConfigurationBuilder.from; -import static org.jfleet.util.TransactionPolicyTestHelper.numberOfRowsInEmployeeTable; -import static org.jfleet.util.TransactionPolicyTestHelper.setupDatabase; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.io.IOException; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.SQLException; -import java.util.stream.Stream; - import org.jfleet.BulkInsert; import org.jfleet.JFleetException; import org.jfleet.entities.City; import org.jfleet.entities.Employee; import org.jfleet.mysql.LoadDataBulkInsert; import org.jfleet.mysql.LoadDataConfiguration; -import org.jfleet.util.Database; +import org.jfleet.parameterized.DatabaseArgumentProvider; import org.jfleet.util.MySqlDatabase; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.IOException; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.util.stream.Stream; + +import static org.jfleet.mysql.LoadDataConfiguration.LoadDataConfigurationBuilder.from; +import static org.jfleet.parameterized.Databases.MySql; +import static org.jfleet.util.TransactionPolicyTestHelper.numberOfRowsInEmployeeTable; +import static org.jfleet.util.TransactionPolicyTestHelper.setupDatabase; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + public class LockRetryTest { private static Logger logger = LoggerFactory.getLogger(LockRetryTest.class); - private Database database = new MySqlDatabase(); + private final MySqlDatabase database = (MySqlDatabase) DatabaseArgumentProvider.getDatabaseContainer(MySql); private static City city1 = new City(1, "Madrid"); private static City city2 = new City(2, "Barcelona"); @BeforeEach - public void setup() throws IOException, SQLException { + public void setup() throws SQLException, IOException { try (Connection connection = database.getConnection()) { setupDatabase(connection); } diff --git a/jfleet-core/src/test/java/org/jfleet/mysql/manual/ConnectionTest.java b/jfleet-core/src/test/java/org/jfleet/mysql/manual/ConnectionTest.java index 6a36578..52891c1 100644 --- a/jfleet-core/src/test/java/org/jfleet/mysql/manual/ConnectionTest.java +++ b/jfleet-core/src/test/java/org/jfleet/mysql/manual/ConnectionTest.java @@ -15,9 +15,12 @@ */ package org.jfleet.mysql.manual; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import com.mysql.jdbc.Connection; +import com.mysql.jdbc.Statement; +import org.jfleet.parameterized.DatabaseArgumentProvider; +import org.jfleet.parameterized.IsMySql5Present; +import org.jfleet.util.MySqlDatabase; +import org.junit.jupiter.api.Test; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -25,18 +28,16 @@ import java.sql.ResultSet; import java.sql.SQLException; -import org.jfleet.parameterized.IsMySql5Present; -import org.jfleet.util.MySqlDatabase; -import org.junit.jupiter.api.Test; - -import com.mysql.jdbc.Connection; -import com.mysql.jdbc.Statement; +import static org.jfleet.parameterized.Databases.MySql; +import static org.junit.jupiter.api.Assertions.*; public class ConnectionTest { + private final MySqlDatabase database = (MySqlDatabase) DatabaseArgumentProvider.getDatabaseContainer(MySql); + @Test public void canConnectToTestDB() throws SQLException, IOException { - try (java.sql.Connection conn = new MySqlDatabase().getConnection()) { + try (java.sql.Connection conn = database.getConnection()) { assertNotNull(conn); } } @@ -47,7 +48,7 @@ public void canExecuteLoadData() throws SQLException, IOException { int someValue = 12345; String otherValue = "foobar"; - try (Connection conn = (Connection) new MySqlDatabase().getConnection()) { + try (Connection conn = (Connection) database.getConnection()) { conn.setAllowLoadLocalInfile(true); try (Statement stmt = (Statement) conn.createStatement()) { stmt.execute("CREATE TEMPORARY TABLE simple_table (some_column INTEGER, other_column VARCHAR(255))"); @@ -75,7 +76,7 @@ public void canExecuteLoadDataWithNullValues() throws SQLException, IOException int someValue = 12345; String otherValue = "foobar"; - try (Connection conn = (Connection) new MySqlDatabase().getConnection()) { + try (Connection conn = (Connection) database.getConnection()) { conn.setAllowLoadLocalInfile(true); try (Statement stmt = (Statement) conn.createStatement()) { stmt.execute("CREATE TEMPORARY TABLE simple_table (some_column INTEGER, other_column VARCHAR(255))"); diff --git a/jfleet-core/src/test/java/org/jfleet/mysql/manual/IdsTest.java b/jfleet-core/src/test/java/org/jfleet/mysql/manual/IdsTest.java index 79c4e63..6589322 100644 --- a/jfleet-core/src/test/java/org/jfleet/mysql/manual/IdsTest.java +++ b/jfleet-core/src/test/java/org/jfleet/mysql/manual/IdsTest.java @@ -15,8 +15,12 @@ */ package org.jfleet.mysql.manual; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import com.mysql.jdbc.Connection; +import com.mysql.jdbc.Statement; +import org.jfleet.parameterized.DatabaseArgumentProvider; +import org.jfleet.parameterized.IsMySql5Present; +import org.jfleet.util.MySqlDatabase; +import org.junit.jupiter.api.Test; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -24,19 +28,18 @@ import java.sql.ResultSet; import java.sql.SQLException; -import org.jfleet.parameterized.IsMySql5Present; -import org.jfleet.util.MySqlDatabase; -import org.junit.jupiter.api.Test; - -import com.mysql.jdbc.Connection; -import com.mysql.jdbc.Statement; +import static org.jfleet.parameterized.Databases.MySql; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; @IsMySql5Present public class IdsTest { + private final MySqlDatabase database = (MySqlDatabase) DatabaseArgumentProvider.getDatabaseContainer(MySql); + @Test public void canExecuteLoadDataWithAutoIncrement() throws SQLException, IOException { - try (Connection conn = (Connection) new MySqlDatabase().getConnection()) { + try (Connection conn = (Connection) database.getConnection()) { conn.setAllowLoadLocalInfile(true); try (Statement stmt = (Statement) conn.createStatement()) { stmt.execute("CREATE TEMPORARY TABLE table_with_id " @@ -66,7 +69,7 @@ public void canExecuteLoadDataWithAutoIncrement() throws SQLException, IOExcepti @Test public void canExecuteLoadDataWithAutoIncrementIdSetted() throws SQLException, IOException { - try (Connection conn = (Connection) new MySqlDatabase().getConnection()) { + try (Connection conn = (Connection) database.getConnection()) { conn.setAllowLoadLocalInfile(true); try (Statement stmt = (Statement) conn.createStatement()) { stmt.execute("CREATE TEMPORARY TABLE table_with_id " diff --git a/jfleet-core/src/test/java/org/jfleet/parameterized/DatabaseArgumentProvider.java b/jfleet-core/src/test/java/org/jfleet/parameterized/DatabaseArgumentProvider.java index dae2ac0..a2098fe 100644 --- a/jfleet-core/src/test/java/org/jfleet/parameterized/DatabaseArgumentProvider.java +++ b/jfleet-core/src/test/java/org/jfleet/parameterized/DatabaseArgumentProvider.java @@ -15,22 +15,51 @@ */ package org.jfleet.parameterized; -import java.lang.reflect.Method; -import java.util.stream.Stream; - -import org.jfleet.util.Database; -import org.jfleet.util.JdbcMysqlDatabase; -import org.jfleet.util.JdbcPostgresDatabase; -import org.jfleet.util.MySqlDatabase; -import org.jfleet.util.PostgresDatabase; +import org.jfleet.util.*; import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.ArgumentsProvider; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.MySQLContainer; +import org.testcontainers.containers.PostgreSQLContainer; + +import java.lang.reflect.Method; +import java.util.Map; +import java.util.stream.Stream; + +import static org.jfleet.parameterized.Databases.*; public class DatabaseArgumentProvider implements ArgumentsProvider { + //TODO move this + private static PostgreSQLContainer postgreSQLContainer = new PostgreSQLContainer<>("postgres:12-alpine") + .withUsername("test") + .withPassword("test") + .withDatabaseName("postgresdb") + .withUrlParam("reWriteBatchedInserts", "true"); + private static MySQLContainer mySQLContainer = new MySQLContainer<>("mysql:5.7.34") + .withUsername("test") + .withPassword("test") + .withDatabaseName("testdb") + .withUrlParam("useSSL","false") + .withUrlParam("allowPublicKeyRetrieval", "true") + .withUrlParam("useUnicode","true") + .withUrlParam("characterEncoding", "utf-8") + .withUrlParam("allowLoadLocalInfile", "true"); + + private static final Map> map = Map.of( + Postgres, postgreSQLContainer, + JdbcPosgres, postgreSQLContainer, + MySql, mySQLContainer, + JdbcMySql, mySQLContainer + ); + + static { + map.values().parallelStream().forEach(GenericContainer::start); + } + @Override - public Stream provideArguments(ExtensionContext context) throws Exception { + public Stream provideArguments(ExtensionContext context) { Method testMethod = context.getTestMethod().get(); DBs dbs = testMethod.getAnnotation(DBs.class); if (dbs != null) { @@ -43,30 +72,16 @@ public Stream provideArguments(ExtensionContext context) th } private Stream getDatabases(Databases[] dbs) { - return Stream.of(dbs).map(this::createDatabase).map(Arguments::of); + return Stream.of(dbs).map(DatabaseArgumentProvider::getDatabaseContainer).map(Arguments::of); } - private Database createDatabase(Databases enumValue) { - switch (enumValue) { - case JdbcMySql: - return new JdbcMysqlDatabase(); - case JdbcPosgres: - return new JdbcPostgresDatabase(); - case MySql: - return new MySqlDatabase(); - case Postgres: - return new PostgresDatabase(); - } - return null; - } - - public static boolean isMySql5Present() { - try { - Class.forName("com.mysql.jdbc.PreparedStatement"); - } catch (ClassNotFoundException e) { - return false; - } - return true; + public static Database getDatabaseContainer(Databases enumValue) { + return switch (enumValue) { + case JdbcMySql -> new JdbcMysqlDatabase(mySQLContainer); + case JdbcPosgres -> new JdbcPostgresDatabase(postgreSQLContainer); + case MySql -> new MySqlDatabase(mySQLContainer); + case Postgres -> new PostgresDatabase(postgreSQLContainer); + }; } } diff --git a/jfleet-core/src/test/java/org/jfleet/parameterized/IsMySql5Condition.java b/jfleet-core/src/test/java/org/jfleet/parameterized/IsMySql5Condition.java index 6e806a0..53fe2c5 100644 --- a/jfleet-core/src/test/java/org/jfleet/parameterized/IsMySql5Condition.java +++ b/jfleet-core/src/test/java/org/jfleet/parameterized/IsMySql5Condition.java @@ -15,14 +15,13 @@ */ package org.jfleet.parameterized; -import static org.jfleet.parameterized.DatabaseArgumentProvider.isMySql5Present; -import static org.junit.jupiter.api.extension.ConditionEvaluationResult.disabled; -import static org.junit.jupiter.api.extension.ConditionEvaluationResult.enabled; - import org.junit.jupiter.api.extension.ConditionEvaluationResult; import org.junit.jupiter.api.extension.ExecutionCondition; import org.junit.jupiter.api.extension.ExtensionContext; +import static org.junit.jupiter.api.extension.ConditionEvaluationResult.disabled; +import static org.junit.jupiter.api.extension.ConditionEvaluationResult.enabled; + public class IsMySql5Condition implements ExecutionCondition { @Override @@ -33,4 +32,13 @@ public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext con return disabled("MySql 5.x driver is not present"); } + private static boolean isMySql5Present() { + try { + Class.forName("com.mysql.jdbc.PreparedStatement"); + } catch (ClassNotFoundException e) { + return false; + } + return true; + } + } diff --git a/jfleet-core/src/test/java/org/jfleet/parameterized/IsMySql5Present.java b/jfleet-core/src/test/java/org/jfleet/parameterized/IsMySql5Present.java index 085b9af..f9c95e5 100644 --- a/jfleet-core/src/test/java/org/jfleet/parameterized/IsMySql5Present.java +++ b/jfleet-core/src/test/java/org/jfleet/parameterized/IsMySql5Present.java @@ -20,6 +20,7 @@ import org.junit.jupiter.api.extension.ExtendWith; +//TODO review uses @Retention(RetentionPolicy.RUNTIME) @ExtendWith(IsMySql5Condition.class) public @interface IsMySql5Present { diff --git a/jfleet-core/src/test/java/org/jfleet/postgres/PostgresDateTypePersistenceWithMillisecondsResolutionTest.java b/jfleet-core/src/test/java/org/jfleet/postgres/PostgresDateTypePersistenceWithMillisecondsResolutionTest.java index deea163..2fc4cd5 100644 --- a/jfleet-core/src/test/java/org/jfleet/postgres/PostgresDateTypePersistenceWithMillisecondsResolutionTest.java +++ b/jfleet-core/src/test/java/org/jfleet/postgres/PostgresDateTypePersistenceWithMillisecondsResolutionTest.java @@ -15,16 +15,14 @@ */ package org.jfleet.postgres; -import static org.jfleet.parameterized.Databases.JdbcPosgres; -import static org.jfleet.parameterized.Databases.Postgres; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import org.jfleet.BulkInsert; +import org.jfleet.parameterized.DBs; +import org.jfleet.parameterized.TestDBs; +import org.jfleet.shared.entities.EntityWithDateTypes; +import org.jfleet.util.Database; +import org.jfleet.util.SqlUtil; -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.Statement; -import java.sql.Time; -import java.sql.Timestamp; +import java.sql.*; import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.LocalDateTime; @@ -32,13 +30,10 @@ import java.util.Date; import java.util.stream.Stream; -import org.jfleet.BulkInsert; -import org.jfleet.parameterized.DBs; -import org.jfleet.parameterized.TestDBs; -import org.jfleet.shared.entities.EntityWithDateTypes; -import org.jfleet.util.Database; -import org.jfleet.util.PostgresDatabase; -import org.jfleet.util.SqlUtil; +import static org.jfleet.parameterized.Databases.JdbcPosgres; +import static org.jfleet.parameterized.Databases.Postgres; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class PostgresDateTypePersistenceWithMillisecondsResolutionTest { @@ -53,10 +48,9 @@ public void persistWithMillisecondResolution(Database database) throws Exception entity.setSqlTimeStamp(new Timestamp(getDate("24/01/2012 23:12:48.132").getTime())); entity.setLocalTime(LocalTime.of(23, 12, 48, 132_000_000)); entity.setLocalDateTime(LocalDateTime.of(2012, 01, 24, 23, 12, 48, 132_000_000)); - BulkInsert insert = database.getBulkInsert(EntityWithDateTypes.class); - try (Connection conn = new PostgresDatabase().getConnection()) { + try (Connection conn = database.getConnection()) { SqlUtil.createTableForEntity(conn, EntityWithDateTypes.class); insert.insertAll(conn, Stream.of(entity)); diff --git a/jfleet-core/src/test/java/org/jfleet/postgres/PostgresReservedWordTest.java b/jfleet-core/src/test/java/org/jfleet/postgres/PostgresReservedWordTest.java index 227d0ed..e274a9b 100644 --- a/jfleet-core/src/test/java/org/jfleet/postgres/PostgresReservedWordTest.java +++ b/jfleet-core/src/test/java/org/jfleet/postgres/PostgresReservedWordTest.java @@ -15,26 +15,25 @@ */ package org.jfleet.postgres; -import static org.jfleet.parameterized.Databases.JdbcPosgres; -import static org.jfleet.parameterized.Databases.Postgres; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import org.jfleet.BulkInsert; +import org.jfleet.parameterized.DBs; +import org.jfleet.parameterized.TestDBs; +import org.jfleet.util.Database; +import org.jfleet.util.SqlUtil; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; import java.util.stream.IntStream; import java.util.stream.Stream; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Table; - -import org.jfleet.BulkInsert; -import org.jfleet.parameterized.DBs; -import org.jfleet.parameterized.TestDBs; -import org.jfleet.util.Database; -import org.jfleet.util.SqlUtil; +import static org.jfleet.parameterized.Databases.JdbcPosgres; +import static org.jfleet.parameterized.Databases.Postgres; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class PostgresReservedWordTest { diff --git a/jfleet-core/src/test/java/org/jfleet/postgres/PostgresTransactionPolicyTest.java b/jfleet-core/src/test/java/org/jfleet/postgres/PostgresTransactionPolicyTest.java index c05aa12..7f584c2 100644 --- a/jfleet-core/src/test/java/org/jfleet/postgres/PostgresTransactionPolicyTest.java +++ b/jfleet-core/src/test/java/org/jfleet/postgres/PostgresTransactionPolicyTest.java @@ -15,36 +15,34 @@ */ package org.jfleet.postgres; -import static org.jfleet.postgres.PgCopyConfiguration.PgCopyConfigurationBuilder.from; -import static org.jfleet.util.TransactionPolicyTestHelper.employeesWithConstraintError; -import static org.jfleet.util.TransactionPolicyTestHelper.employeesWithOutErrors; -import static org.jfleet.util.TransactionPolicyTestHelper.numberOfRowsInEmployeeTable; -import static org.jfleet.util.TransactionPolicyTestHelper.setupDatabase; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.io.IOException; -import java.sql.Connection; -import java.sql.SQLException; - import org.jfleet.BulkInsert; import org.jfleet.entities.Employee; -import org.jfleet.util.Database; +import org.jfleet.parameterized.DatabaseArgumentProvider; import org.jfleet.util.PostgresDatabase; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.IOException; +import java.sql.Connection; +import java.sql.SQLException; + +import static org.jfleet.parameterized.Databases.Postgres; +import static org.jfleet.postgres.PgCopyConfiguration.PgCopyConfigurationBuilder.from; +import static org.jfleet.util.TransactionPolicyTestHelper.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + public class PostgresTransactionPolicyTest { - private static Logger logger = LoggerFactory.getLogger(PostgresTransactionPolicyTest.class); + private static final Logger logger = LoggerFactory.getLogger(PostgresTransactionPolicyTest.class); private static final int VERY_LOW_SIZE_TO_FREQUENT_LOAD_DATA = 10; - private Database database = new PostgresDatabase(); + private final PostgresDatabase database = (PostgresDatabase) DatabaseArgumentProvider.getDatabaseContainer(Postgres); @BeforeEach - public void setup() throws IOException, SQLException { + public void setup() throws SQLException, IOException { try (Connection connection = database.getConnection()) { setupDatabase(connection); } diff --git a/jfleet-core/src/test/java/org/jfleet/postgres/manual/ConnectionTest.java b/jfleet-core/src/test/java/org/jfleet/postgres/manual/ConnectionTest.java index c133dc0..4ca1b0c 100644 --- a/jfleet-core/src/test/java/org/jfleet/postgres/manual/ConnectionTest.java +++ b/jfleet-core/src/test/java/org/jfleet/postgres/manual/ConnectionTest.java @@ -15,10 +15,13 @@ */ package org.jfleet.postgres.manual; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; +import org.jfleet.common.StringBuilderReader; +import org.jfleet.parameterized.DatabaseArgumentProvider; +import org.jfleet.util.PostgresDatabase; +import org.junit.jupiter.api.Test; +import org.postgresql.copy.CopyManager; +import org.postgresql.jdbc.PgConnection; +import org.postgresql.util.PSQLException; import java.io.IOException; import java.io.Reader; @@ -27,17 +30,12 @@ import java.sql.SQLException; import java.sql.Statement; -import org.jfleet.common.StringBuilderReader; -import org.jfleet.util.Database; -import org.jfleet.util.PostgresDatabase; -import org.junit.jupiter.api.Test; -import org.postgresql.copy.CopyManager; -import org.postgresql.jdbc.PgConnection; -import org.postgresql.util.PSQLException; +import static org.jfleet.parameterized.Databases.Postgres; +import static org.junit.jupiter.api.Assertions.*; public class ConnectionTest { - private Database database = new PostgresDatabase(); + private final PostgresDatabase database = (PostgresDatabase) DatabaseArgumentProvider.getDatabaseContainer(Postgres); @Test public void canConnectToTestDB() throws SQLException, IOException { diff --git a/jfleet-core/src/test/java/org/jfleet/shared/DateTypePersistenceTest.java b/jfleet-core/src/test/java/org/jfleet/shared/DateTypePersistenceTest.java index 9b11601..e3806d5 100644 --- a/jfleet-core/src/test/java/org/jfleet/shared/DateTypePersistenceTest.java +++ b/jfleet-core/src/test/java/org/jfleet/shared/DateTypePersistenceTest.java @@ -15,8 +15,12 @@ */ package org.jfleet.shared; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import org.jfleet.BulkInsert; +import org.jfleet.parameterized.IsMySql5Present; +import org.jfleet.parameterized.TestDBs; +import org.jfleet.shared.entities.EntityWithDateTypes; +import org.jfleet.util.Database; +import org.jfleet.util.SqlUtil; import java.sql.Connection; import java.sql.ResultSet; @@ -29,12 +33,8 @@ import java.util.Date; import java.util.stream.Stream; -import org.jfleet.BulkInsert; -import org.jfleet.parameterized.IsMySql5Present; -import org.jfleet.parameterized.TestDBs; -import org.jfleet.shared.entities.EntityWithDateTypes; -import org.jfleet.util.Database; -import org.jfleet.util.SqlUtil; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class DateTypePersistenceTest { diff --git a/jfleet-core/src/test/java/org/jfleet/shared/EmbeddedEntityPersistenceTest.java b/jfleet-core/src/test/java/org/jfleet/shared/EmbeddedEntityPersistenceTest.java index f866bdf..6d20798 100644 --- a/jfleet-core/src/test/java/org/jfleet/shared/EmbeddedEntityPersistenceTest.java +++ b/jfleet-core/src/test/java/org/jfleet/shared/EmbeddedEntityPersistenceTest.java @@ -15,8 +15,13 @@ */ package org.jfleet.shared; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import org.jfleet.BulkInsert; +import org.jfleet.entities.Address; +import org.jfleet.entities.Company; +import org.jfleet.entities.Person; +import org.jfleet.parameterized.TestDBs; +import org.jfleet.util.Database; +import org.jfleet.util.SqlUtil; import java.sql.Connection; import java.sql.ResultSet; @@ -25,13 +30,8 @@ import java.util.List; import java.util.stream.Stream; -import org.jfleet.BulkInsert; -import org.jfleet.entities.Address; -import org.jfleet.entities.Company; -import org.jfleet.entities.Person; -import org.jfleet.parameterized.TestDBs; -import org.jfleet.util.Database; -import org.jfleet.util.SqlUtil; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class EmbeddedEntityPersistenceTest { diff --git a/jfleet-core/src/test/java/org/jfleet/shared/EncodingTest.java b/jfleet-core/src/test/java/org/jfleet/shared/EncodingTest.java index 069fe69..be1f954 100644 --- a/jfleet-core/src/test/java/org/jfleet/shared/EncodingTest.java +++ b/jfleet-core/src/test/java/org/jfleet/shared/EncodingTest.java @@ -15,9 +15,13 @@ */ package org.jfleet.shared; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import org.jfleet.BulkInsert; +import org.jfleet.parameterized.TestDBs; +import org.jfleet.util.Database; +import org.jfleet.util.SqlUtil; +import javax.persistence.Entity; +import javax.persistence.Table; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; @@ -29,13 +33,8 @@ import java.util.List; import java.util.stream.Collectors; -import javax.persistence.Entity; -import javax.persistence.Table; - -import org.jfleet.BulkInsert; -import org.jfleet.parameterized.TestDBs; -import org.jfleet.util.Database; -import org.jfleet.util.SqlUtil; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class EncodingTest { diff --git a/jfleet-core/src/test/java/org/jfleet/shared/IdPersistenceTest.java b/jfleet-core/src/test/java/org/jfleet/shared/IdPersistenceTest.java index c7f5087..d8d845a 100644 --- a/jfleet-core/src/test/java/org/jfleet/shared/IdPersistenceTest.java +++ b/jfleet-core/src/test/java/org/jfleet/shared/IdPersistenceTest.java @@ -15,26 +15,19 @@ */ package org.jfleet.shared; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import org.jfleet.BulkInsert; +import org.jfleet.parameterized.TestDBs; +import org.jfleet.util.Database; +import org.jfleet.util.SqlUtil; +import javax.persistence.*; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; import java.util.stream.LongStream; import java.util.stream.Stream; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; - -import org.jfleet.BulkInsert; -import org.jfleet.parameterized.TestDBs; -import org.jfleet.util.Database; -import org.jfleet.util.SqlUtil; +import static org.junit.jupiter.api.Assertions.*; public class IdPersistenceTest { diff --git a/jfleet-core/src/test/java/org/jfleet/shared/ManyToOnePersistenceTest.java b/jfleet-core/src/test/java/org/jfleet/shared/ManyToOnePersistenceTest.java index 3ca95e4..d23e9c3 100644 --- a/jfleet-core/src/test/java/org/jfleet/shared/ManyToOnePersistenceTest.java +++ b/jfleet-core/src/test/java/org/jfleet/shared/ManyToOnePersistenceTest.java @@ -15,25 +15,20 @@ */ package org.jfleet.shared; -import static java.util.Arrays.asList; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import org.jfleet.BulkInsert; +import org.jfleet.parameterized.TestDBs; +import org.jfleet.util.Database; +import org.jfleet.util.SqlUtil; +import javax.persistence.*; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; import java.util.List; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.Table; - -import org.jfleet.BulkInsert; -import org.jfleet.parameterized.TestDBs; -import org.jfleet.util.Database; -import org.jfleet.util.SqlUtil; +import static java.util.Arrays.asList; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class ManyToOnePersistenceTest { diff --git a/jfleet-core/src/test/java/org/jfleet/shared/SimpleEntityPersistenceTest.java b/jfleet-core/src/test/java/org/jfleet/shared/SimpleEntityPersistenceTest.java index 1036e61..c292f97 100644 --- a/jfleet-core/src/test/java/org/jfleet/shared/SimpleEntityPersistenceTest.java +++ b/jfleet-core/src/test/java/org/jfleet/shared/SimpleEntityPersistenceTest.java @@ -15,22 +15,21 @@ */ package org.jfleet.shared; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import org.jfleet.BulkInsert; +import org.jfleet.parameterized.TestDBs; +import org.jfleet.util.Database; +import org.jfleet.util.SqlUtil; +import javax.persistence.Entity; +import javax.persistence.Table; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; import java.util.stream.IntStream; import java.util.stream.Stream; -import javax.persistence.Entity; -import javax.persistence.Table; - -import org.jfleet.BulkInsert; -import org.jfleet.parameterized.TestDBs; -import org.jfleet.util.Database; -import org.jfleet.util.SqlUtil; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class SimpleEntityPersistenceTest { diff --git a/jfleet-core/src/test/java/org/jfleet/shared/SpecialCharsPersistenceTest.java b/jfleet-core/src/test/java/org/jfleet/shared/SpecialCharsPersistenceTest.java index b1230b2..ebc74f1 100644 --- a/jfleet-core/src/test/java/org/jfleet/shared/SpecialCharsPersistenceTest.java +++ b/jfleet-core/src/test/java/org/jfleet/shared/SpecialCharsPersistenceTest.java @@ -15,27 +15,26 @@ */ package org.jfleet.shared; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import org.jfleet.BulkInsert; +import org.jfleet.parameterized.TestDBs; +import org.jfleet.util.Database; +import org.jfleet.util.SqlUtil; +import javax.persistence.Entity; +import javax.persistence.Table; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; import java.util.stream.Stream; -import javax.persistence.Entity; -import javax.persistence.Table; - -import org.jfleet.BulkInsert; -import org.jfleet.parameterized.TestDBs; -import org.jfleet.util.Database; -import org.jfleet.util.SqlUtil; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class SpecialCharsPersistenceTest { @Entity @Table(name = "table_with_strings") - class EnityWithStrings { + class EntityWithStrings { private String foo; private String bar; @@ -59,14 +58,14 @@ public void setBar(String bar) { } public void testWithString(Database database, String text) throws Exception { - EnityWithStrings entity = new EnityWithStrings(); + EntityWithStrings entity = new EntityWithStrings(); entity.setFoo("Some text"); entity.setBar(text); - BulkInsert insert = database.getBulkInsert(EnityWithStrings.class); + BulkInsert insert = database.getBulkInsert(EntityWithStrings.class); try (Connection conn = database.getConnection()) { - SqlUtil.createTableForEntity(conn, EnityWithStrings.class); + SqlUtil.createTableForEntity(conn, EntityWithStrings.class); insert.insertAll(conn, Stream.of(entity)); try (Statement stmt = conn.createStatement()) { diff --git a/jfleet-core/src/test/java/org/jfleet/shared/TypePersistenceTest.java b/jfleet-core/src/test/java/org/jfleet/shared/TypePersistenceTest.java index c405427..fb6b515 100644 --- a/jfleet-core/src/test/java/org/jfleet/shared/TypePersistenceTest.java +++ b/jfleet-core/src/test/java/org/jfleet/shared/TypePersistenceTest.java @@ -15,8 +15,12 @@ */ package org.jfleet.shared; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import org.jfleet.BulkInsert; +import org.jfleet.parameterized.TestDBs; +import org.jfleet.shared.entities.EntityWithBasicTypes; +import org.jfleet.shared.entities.EnumForTest; +import org.jfleet.util.Database; +import org.jfleet.util.SqlUtil; import java.math.BigDecimal; import java.math.BigInteger; @@ -25,12 +29,8 @@ import java.sql.Statement; import java.util.stream.Stream; -import org.jfleet.BulkInsert; -import org.jfleet.parameterized.TestDBs; -import org.jfleet.shared.entities.EntityWithBasicTypes; -import org.jfleet.shared.entities.EnumForTest; -import org.jfleet.util.Database; -import org.jfleet.util.SqlUtil; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class TypePersistenceTest { diff --git a/jfleet-core/src/test/java/org/jfleet/util/Database.java b/jfleet-core/src/test/java/org/jfleet/util/Database.java index 931b7c7..7399bbc 100644 --- a/jfleet-core/src/test/java/org/jfleet/util/Database.java +++ b/jfleet-core/src/test/java/org/jfleet/util/Database.java @@ -15,32 +15,29 @@ */ package org.jfleet.util; +import org.jfleet.BulkInsert; +import org.testcontainers.containers.JdbcDatabaseContainer; + import java.io.IOException; import java.sql.Connection; -import org.jfleet.BulkInsert; - public abstract class Database { - private String properties; - - public Database(String properties) { - this.properties = properties; - } + private final JdbcDatabaseContainer container; - public String getProperties() { - return properties; + public Database(JdbcDatabaseContainer container) { + this.container = container; } public abstract BulkInsert getBulkInsert(Class clazz); public Connection getConnection() throws IOException { - return new DatabaseTestConnectionProvider(getProperties()).get(); + return new DatabaseTestConnectionProvider(container).get(); } @Override public String toString() { - return this.getClass().getSimpleName().replace("Database", ""); + return this.getClass().getSimpleName().replace("DatabaseContainer", ""); } } diff --git a/jfleet-core/src/test/java/org/jfleet/util/DatabaseTestConnectionProvider.java b/jfleet-core/src/test/java/org/jfleet/util/DatabaseTestConnectionProvider.java index 62e2ea1..e02761d 100644 --- a/jfleet-core/src/test/java/org/jfleet/util/DatabaseTestConnectionProvider.java +++ b/jfleet-core/src/test/java/org/jfleet/util/DatabaseTestConnectionProvider.java @@ -15,32 +15,28 @@ */ package org.jfleet.util; -import java.io.IOException; -import java.io.InputStream; +import org.testcontainers.containers.JdbcDatabaseContainer; + import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; -import java.util.Properties; import java.util.function.Supplier; public class DatabaseTestConnectionProvider implements Supplier { - private Properties prop; + private final JdbcDatabaseContainer container; - public DatabaseTestConnectionProvider(String propertiesName) throws IOException { - InputStream is = this.getClass().getClassLoader().getResourceAsStream(propertiesName); - Properties p = new Properties(); - p.load(is); - prop = p; + public DatabaseTestConnectionProvider(JdbcDatabaseContainer container) { + this.container = container; } @Override public Connection get() { - String driver = prop.getProperty("driver"); + String driver = container.getDriverClassName(); try { Class.forName(driver).newInstance(); - Connection conn = DriverManager.getConnection(prop.getProperty("urlConnection"), prop.getProperty("user"), - prop.getProperty("password")); + Connection conn = DriverManager.getConnection(container.getJdbcUrl(), container.getUsername(), + container.getPassword()); return conn; } catch (ClassNotFoundException | IllegalAccessException | InstantiationException ex) { throw new RuntimeException("Can not instantiate driver " + driver, ex); diff --git a/jfleet-core/src/test/java/org/jfleet/util/JdbcDatabase.java b/jfleet-core/src/test/java/org/jfleet/util/JdbcDatabase.java index 6f442b3..190680a 100644 --- a/jfleet-core/src/test/java/org/jfleet/util/JdbcDatabase.java +++ b/jfleet-core/src/test/java/org/jfleet/util/JdbcDatabase.java @@ -18,11 +18,12 @@ import org.jfleet.BulkInsert; import org.jfleet.jdbc.JdbcBulkInsert; import org.jfleet.jdbc.JdbcConfiguration; +import org.testcontainers.containers.JdbcDatabaseContainer; public abstract class JdbcDatabase extends Database { - public JdbcDatabase(String properties) { - super(properties); + public JdbcDatabase(JdbcDatabaseContainer container) { + super(container); } @Override diff --git a/jfleet-core/src/test/java/org/jfleet/util/JdbcMysqlDatabase.java b/jfleet-core/src/test/java/org/jfleet/util/JdbcMysqlDatabase.java index dd9811b..218dfcf 100644 --- a/jfleet-core/src/test/java/org/jfleet/util/JdbcMysqlDatabase.java +++ b/jfleet-core/src/test/java/org/jfleet/util/JdbcMysqlDatabase.java @@ -15,14 +15,12 @@ */ package org.jfleet.util; -public class JdbcMysqlDatabase extends JdbcDatabase { +import org.testcontainers.containers.MySQLContainer; - public JdbcMysqlDatabase(String properties) { - super(properties); - } +public class JdbcMysqlDatabase extends JdbcDatabase { - public JdbcMysqlDatabase() { - super("mysql-test.properties"); + public JdbcMysqlDatabase(MySQLContainer container) { + super(container); } } diff --git a/jfleet-core/src/test/java/org/jfleet/util/JdbcPostgresDatabase.java b/jfleet-core/src/test/java/org/jfleet/util/JdbcPostgresDatabase.java index 137b331..aa2d3d0 100644 --- a/jfleet-core/src/test/java/org/jfleet/util/JdbcPostgresDatabase.java +++ b/jfleet-core/src/test/java/org/jfleet/util/JdbcPostgresDatabase.java @@ -15,14 +15,12 @@ */ package org.jfleet.util; -public class JdbcPostgresDatabase extends JdbcDatabase { +import org.testcontainers.containers.PostgreSQLContainer; - public JdbcPostgresDatabase(String properties) { - super(properties); - } +public class JdbcPostgresDatabase extends JdbcDatabase { - public JdbcPostgresDatabase() { - super("postgres-test.properties"); + public JdbcPostgresDatabase(PostgreSQLContainer postgresContainer) { + super(postgresContainer); } } diff --git a/jfleet-core/src/test/java/org/jfleet/util/MySqlDatabase.java b/jfleet-core/src/test/java/org/jfleet/util/MySqlDatabase.java index ff34b6e..1dd0c9e 100644 --- a/jfleet-core/src/test/java/org/jfleet/util/MySqlDatabase.java +++ b/jfleet-core/src/test/java/org/jfleet/util/MySqlDatabase.java @@ -17,15 +17,12 @@ import org.jfleet.BulkInsert; import org.jfleet.mysql.LoadDataBulkInsert; +import org.testcontainers.containers.MySQLContainer; public class MySqlDatabase extends Database { - public MySqlDatabase(String properties) { - super(properties); - } - - public MySqlDatabase() { - super("mysql-test.properties"); + public MySqlDatabase(MySQLContainer mySQLContainer) { + super(mySQLContainer); } @Override diff --git a/jfleet-core/src/test/java/org/jfleet/util/PostgresDatabase.java b/jfleet-core/src/test/java/org/jfleet/util/PostgresDatabase.java index c4580f3..42ef4e9 100644 --- a/jfleet-core/src/test/java/org/jfleet/util/PostgresDatabase.java +++ b/jfleet-core/src/test/java/org/jfleet/util/PostgresDatabase.java @@ -17,15 +17,12 @@ import org.jfleet.BulkInsert; import org.jfleet.postgres.PgCopyBulkInsert; +import org.testcontainers.containers.PostgreSQLContainer; public class PostgresDatabase extends Database { - public PostgresDatabase(String properties) { - super(properties); - } - - public PostgresDatabase() { - super("postgres-test.properties"); + public PostgresDatabase(PostgreSQLContainer postgresContainer) { + super(postgresContainer); } @Override diff --git a/jfleet-core/src/test/java/org/jfleet/util/TransactionPolicyTestHelper.java b/jfleet-core/src/test/java/org/jfleet/util/TransactionPolicyTestHelper.java index ff1d4a4..6862862 100644 --- a/jfleet-core/src/test/java/org/jfleet/util/TransactionPolicyTestHelper.java +++ b/jfleet-core/src/test/java/org/jfleet/util/TransactionPolicyTestHelper.java @@ -15,7 +15,8 @@ */ package org.jfleet.util; -import static org.junit.jupiter.api.Assertions.assertTrue; +import org.jfleet.entities.City; +import org.jfleet.entities.Employee; import java.sql.Connection; import java.sql.ResultSet; @@ -23,8 +24,7 @@ import java.sql.Statement; import java.util.stream.Stream; -import org.jfleet.entities.City; -import org.jfleet.entities.Employee; +import static org.junit.jupiter.api.Assertions.assertTrue; public class TransactionPolicyTestHelper { diff --git a/jfleet-core/src/test/resources/mysql-test.properties b/jfleet-core/src/test/resources/mysql-test.properties deleted file mode 100644 index d04c24e..0000000 --- a/jfleet-core/src/test/resources/mysql-test.properties +++ /dev/null @@ -1,4 +0,0 @@ -driver=com.mysql.jdbc.Driver -user=test -password=test -urlConnection=jdbc:mysql://localhost/testdb?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=utf-8&allowLoadLocalInfile=true \ No newline at end of file diff --git a/jfleet-core/src/test/resources/postgres-test.properties b/jfleet-core/src/test/resources/postgres-test.properties deleted file mode 100644 index c55f2bc..0000000 --- a/jfleet-core/src/test/resources/postgres-test.properties +++ /dev/null @@ -1,4 +0,0 @@ -driver=org.postgresql.Driver -user=test -password=test -urlConnection=jdbc:postgresql://localhost:5432/testdb?reWriteBatchedInserts=true \ No newline at end of file From 6a591ffb1e2bce5084a30a2c78f050448c9661c0 Mon Sep 17 00:00:00 2001 From: Alvaro Date: Tue, 15 Oct 2024 13:07:25 +0200 Subject: [PATCH 02/10] rearrange some code --- .../test/java/org/jfleet/csv/HeaderTest.java | 5 +- .../java/org/jfleet/entities/Company.java | 7 +- .../java/org/jfleet/entities/Employee.java | 6 +- .../inspection/EmbeddedIdInspectorTest.java | 9 +-- .../inspection/EmbeddedInspectorTest.java | 2 +- .../inspection/EntityFieldAccesorTest.java | 7 +- .../inspection/EntityInfoBuilderTest.java | 6 +- .../inspection/EntityInspectorTest.java | 13 +--- .../FailedManyToOneEntityInspectorTest.java | 9 +-- .../inspection/FieldTypeInspectorTest.java | 13 +--- .../HierarchyEntityInspectorTest.java | 7 +- .../ManyToOneEntityInspectorTest.java | 2 +- .../OneToOneEntityInspectorTest.java | 2 +- .../jdbc/JdbcTransactionPolicyTest.java | 18 ++--- .../jfleet/mysql/MySqlReservedWordTest.java | 16 ++--- .../mysql/MySqlTransactionPolicyTest.java | 20 +++--- .../org/jfleet/mysql/error/LockRetryTest.java | 26 +++---- .../jfleet/mysql/manual/ConnectionTest.java | 16 ++--- .../java/org/jfleet/mysql/manual/IdsTest.java | 18 ++--- .../DatabaseArgumentProvider.java | 69 ++++++++++--------- .../parameterized/IsMySql5Condition.java | 6 +- ...istenceWithMillisecondsResolutionTest.java | 20 +++--- .../postgres/PostgresReservedWordTest.java | 18 ++--- .../PostgresTransactionPolicyTest.java | 20 +++--- .../postgres/manual/ConnectionTest.java | 18 ++--- .../shared/DateTypePersistenceTest.java | 16 ++--- .../shared/EmbeddedEntityPersistenceTest.java | 18 ++--- .../java/org/jfleet/shared/EncodingTest.java | 12 ++-- .../org/jfleet/shared/IdPersistenceTest.java | 10 +-- .../shared/ManyToOnePersistenceTest.java | 14 ++-- .../shared/SimpleEntityPersistenceTest.java | 12 ++-- .../shared/SpecialCharsPersistenceTest.java | 12 ++-- .../jfleet/shared/TypePersistenceTest.java | 16 ++--- .../shared/entities/EntityWithBasicTypes.java | 5 +- .../shared/entities/EntityWithDateTypes.java | 7 +- .../test/java/org/jfleet/util/Database.java | 8 +-- .../util/DatabaseTestConnectionProvider.java | 4 +- .../test/java/org/jfleet/util/SqlUtil.java | 3 +- .../util/TransactionPolicyTestHelper.java | 6 +- 39 files changed, 223 insertions(+), 273 deletions(-) diff --git a/jfleet-core/src/test/java/org/jfleet/csv/HeaderTest.java b/jfleet-core/src/test/java/org/jfleet/csv/HeaderTest.java index fab92f9..7247b7f 100644 --- a/jfleet-core/src/test/java/org/jfleet/csv/HeaderTest.java +++ b/jfleet-core/src/test/java/org/jfleet/csv/HeaderTest.java @@ -19,13 +19,12 @@ import static org.jfleet.csv.CsvTestHelper.writeCsvToString; import static org.junit.jupiter.api.Assertions.assertEquals; -import java.io.IOException; -import java.util.Collections; - import javax.persistence.Column; import javax.persistence.Embeddable; import javax.persistence.Embedded; import javax.persistence.Entity; +import java.io.IOException; +import java.util.Collections; import org.jfleet.EntityFieldType.FieldTypeEnum; import org.jfleet.EntityInfoBuilder; diff --git a/jfleet-core/src/test/java/org/jfleet/entities/Company.java b/jfleet-core/src/test/java/org/jfleet/entities/Company.java index db48f1f..c233e5b 100644 --- a/jfleet-core/src/test/java/org/jfleet/entities/Company.java +++ b/jfleet-core/src/test/java/org/jfleet/entities/Company.java @@ -15,12 +15,7 @@ */ package org.jfleet.entities; -import javax.persistence.AttributeOverride; -import javax.persistence.AttributeOverrides; -import javax.persistence.Column; -import javax.persistence.Embedded; -import javax.persistence.Entity; -import javax.persistence.Id; +import javax.persistence.*; @Entity public class Company { diff --git a/jfleet-core/src/test/java/org/jfleet/entities/Employee.java b/jfleet-core/src/test/java/org/jfleet/entities/Employee.java index cca96b6..020457a 100644 --- a/jfleet-core/src/test/java/org/jfleet/entities/Employee.java +++ b/jfleet-core/src/test/java/org/jfleet/entities/Employee.java @@ -15,11 +15,7 @@ */ package org.jfleet.entities; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.Table; +import javax.persistence.*; @Entity @Table(name = "employee") diff --git a/jfleet-core/src/test/java/org/jfleet/inspection/EmbeddedIdInspectorTest.java b/jfleet-core/src/test/java/org/jfleet/inspection/EmbeddedIdInspectorTest.java index 41ca9a9..258bade 100644 --- a/jfleet-core/src/test/java/org/jfleet/inspection/EmbeddedIdInspectorTest.java +++ b/jfleet-core/src/test/java/org/jfleet/inspection/EmbeddedIdInspectorTest.java @@ -17,15 +17,10 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -import javax.persistence.AttributeOverride; -import javax.persistence.AttributeOverrides; -import javax.persistence.Column; -import javax.persistence.Embeddable; -import javax.persistence.EmbeddedId; -import javax.persistence.Entity; +import javax.persistence.*; -import org.jfleet.FieldInfo; import org.jfleet.EntityFieldType.FieldTypeEnum; +import org.jfleet.FieldInfo; import org.junit.jupiter.api.Test; public class EmbeddedIdInspectorTest { diff --git a/jfleet-core/src/test/java/org/jfleet/inspection/EmbeddedInspectorTest.java b/jfleet-core/src/test/java/org/jfleet/inspection/EmbeddedInspectorTest.java index c10cc1f..ae4676a 100644 --- a/jfleet-core/src/test/java/org/jfleet/inspection/EmbeddedInspectorTest.java +++ b/jfleet-core/src/test/java/org/jfleet/inspection/EmbeddedInspectorTest.java @@ -17,8 +17,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -import org.jfleet.FieldInfo; import org.jfleet.EntityFieldType.FieldTypeEnum; +import org.jfleet.FieldInfo; import org.jfleet.entities.Company; import org.jfleet.entities.Person; import org.junit.jupiter.api.Test; diff --git a/jfleet-core/src/test/java/org/jfleet/inspection/EntityFieldAccesorTest.java b/jfleet-core/src/test/java/org/jfleet/inspection/EntityFieldAccesorTest.java index e292e2b..f93a87d 100644 --- a/jfleet-core/src/test/java/org/jfleet/inspection/EntityFieldAccesorTest.java +++ b/jfleet-core/src/test/java/org/jfleet/inspection/EntityFieldAccesorTest.java @@ -18,14 +18,9 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; +import javax.persistence.*; import java.util.function.Function; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.Table; - import org.junit.jupiter.api.Test; public class EntityFieldAccesorTest { diff --git a/jfleet-core/src/test/java/org/jfleet/inspection/EntityInfoBuilderTest.java b/jfleet-core/src/test/java/org/jfleet/inspection/EntityInfoBuilderTest.java index 6c971d2..b0d37db 100644 --- a/jfleet-core/src/test/java/org/jfleet/inspection/EntityInfoBuilderTest.java +++ b/jfleet-core/src/test/java/org/jfleet/inspection/EntityInfoBuilderTest.java @@ -16,11 +16,7 @@ package org.jfleet.inspection; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; import java.util.Date; diff --git a/jfleet-core/src/test/java/org/jfleet/inspection/EntityInspectorTest.java b/jfleet-core/src/test/java/org/jfleet/inspection/EntityInspectorTest.java index d2b3601..9428ca7 100644 --- a/jfleet-core/src/test/java/org/jfleet/inspection/EntityInspectorTest.java +++ b/jfleet-core/src/test/java/org/jfleet/inspection/EntityInspectorTest.java @@ -15,20 +15,11 @@ */ package org.jfleet.inspection; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.*; +import javax.persistence.*; import java.util.List; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; - import org.jfleet.EntityFieldType; import org.jfleet.EntityFieldType.FieldTypeEnum; import org.jfleet.EntityInfo; diff --git a/jfleet-core/src/test/java/org/jfleet/inspection/FailedManyToOneEntityInspectorTest.java b/jfleet-core/src/test/java/org/jfleet/inspection/FailedManyToOneEntityInspectorTest.java index 7bb8115..bd7e29e 100644 --- a/jfleet-core/src/test/java/org/jfleet/inspection/FailedManyToOneEntityInspectorTest.java +++ b/jfleet-core/src/test/java/org/jfleet/inspection/FailedManyToOneEntityInspectorTest.java @@ -18,16 +18,11 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import javax.persistence.*; import java.util.List; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.JoinColumns; -import javax.persistence.JoinTable; -import javax.persistence.ManyToOne; - -import org.jfleet.FieldInfo; import org.jfleet.EntityFieldType.FieldTypeEnum; +import org.jfleet.FieldInfo; import org.junit.jupiter.api.Test; public class FailedManyToOneEntityInspectorTest { diff --git a/jfleet-core/src/test/java/org/jfleet/inspection/FieldTypeInspectorTest.java b/jfleet-core/src/test/java/org/jfleet/inspection/FieldTypeInspectorTest.java index c9dc2ab..ec72c62 100644 --- a/jfleet-core/src/test/java/org/jfleet/inspection/FieldTypeInspectorTest.java +++ b/jfleet-core/src/test/java/org/jfleet/inspection/FieldTypeInspectorTest.java @@ -15,25 +15,18 @@ */ package org.jfleet.inspection; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; +import javax.persistence.*; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.util.Date; import java.util.List; -import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; - import org.jfleet.EntityFieldType; -import org.jfleet.FieldInfo; import org.jfleet.EntityFieldType.FieldTypeEnum; +import org.jfleet.FieldInfo; import org.junit.jupiter.api.Test; public class FieldTypeInspectorTest { diff --git a/jfleet-core/src/test/java/org/jfleet/inspection/HierarchyEntityInspectorTest.java b/jfleet-core/src/test/java/org/jfleet/inspection/HierarchyEntityInspectorTest.java index 59927b1..72a3b03 100644 --- a/jfleet-core/src/test/java/org/jfleet/inspection/HierarchyEntityInspectorTest.java +++ b/jfleet-core/src/test/java/org/jfleet/inspection/HierarchyEntityInspectorTest.java @@ -17,14 +17,9 @@ import static org.junit.jupiter.api.Assertions.assertEquals; +import javax.persistence.*; import java.util.List; -import javax.persistence.AttributeOverride; -import javax.persistence.AttributeOverrides; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.MappedSuperclass; - import org.jfleet.FieldInfo; import org.junit.jupiter.api.Test; diff --git a/jfleet-core/src/test/java/org/jfleet/inspection/ManyToOneEntityInspectorTest.java b/jfleet-core/src/test/java/org/jfleet/inspection/ManyToOneEntityInspectorTest.java index cb6fd1d..b1c1d72 100644 --- a/jfleet-core/src/test/java/org/jfleet/inspection/ManyToOneEntityInspectorTest.java +++ b/jfleet-core/src/test/java/org/jfleet/inspection/ManyToOneEntityInspectorTest.java @@ -22,8 +22,8 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; -import org.jfleet.FieldInfo; import org.jfleet.EntityFieldType.FieldTypeEnum; +import org.jfleet.FieldInfo; import org.junit.jupiter.api.Test; public class ManyToOneEntityInspectorTest { diff --git a/jfleet-core/src/test/java/org/jfleet/inspection/OneToOneEntityInspectorTest.java b/jfleet-core/src/test/java/org/jfleet/inspection/OneToOneEntityInspectorTest.java index 8276c1e..53f3ee2 100644 --- a/jfleet-core/src/test/java/org/jfleet/inspection/OneToOneEntityInspectorTest.java +++ b/jfleet-core/src/test/java/org/jfleet/inspection/OneToOneEntityInspectorTest.java @@ -22,8 +22,8 @@ import javax.persistence.JoinColumn; import javax.persistence.OneToOne; -import org.jfleet.FieldInfo; import org.jfleet.EntityFieldType.FieldTypeEnum; +import org.jfleet.FieldInfo; import org.junit.jupiter.api.Test; public class OneToOneEntityInspectorTest { diff --git a/jfleet-core/src/test/java/org/jfleet/jdbc/JdbcTransactionPolicyTest.java b/jfleet-core/src/test/java/org/jfleet/jdbc/JdbcTransactionPolicyTest.java index 43b3621..844f1ea 100644 --- a/jfleet-core/src/test/java/org/jfleet/jdbc/JdbcTransactionPolicyTest.java +++ b/jfleet-core/src/test/java/org/jfleet/jdbc/JdbcTransactionPolicyTest.java @@ -15,6 +15,15 @@ */ package org.jfleet.jdbc; +import static org.jfleet.parameterized.Databases.JdbcMySql; +import static org.jfleet.parameterized.Databases.JdbcPosgres; +import static org.jfleet.util.TransactionPolicyTestHelper.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.sql.Connection; +import java.sql.SQLException; + import org.jfleet.BulkInsert; import org.jfleet.entities.Employee; import org.jfleet.jdbc.JdbcConfiguration.JdbcConfigurationBuilder; @@ -24,15 +33,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.sql.Connection; -import java.sql.SQLException; - -import static org.jfleet.parameterized.Databases.JdbcMySql; -import static org.jfleet.parameterized.Databases.JdbcPosgres; -import static org.jfleet.util.TransactionPolicyTestHelper.*; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - public class JdbcTransactionPolicyTest { private static Logger logger = LoggerFactory.getLogger(JdbcTransactionPolicyTest.class); diff --git a/jfleet-core/src/test/java/org/jfleet/mysql/MySqlReservedWordTest.java b/jfleet-core/src/test/java/org/jfleet/mysql/MySqlReservedWordTest.java index 2d9b862..70ae17a 100644 --- a/jfleet-core/src/test/java/org/jfleet/mysql/MySqlReservedWordTest.java +++ b/jfleet-core/src/test/java/org/jfleet/mysql/MySqlReservedWordTest.java @@ -15,11 +15,9 @@ */ package org.jfleet.mysql; -import org.jfleet.BulkInsert; -import org.jfleet.parameterized.DatabaseArgumentProvider; -import org.jfleet.util.MySqlDatabase; -import org.jfleet.util.SqlUtil; -import org.junit.jupiter.api.Test; +import static org.jfleet.parameterized.Databases.MySql; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import javax.persistence.Column; import javax.persistence.Entity; @@ -30,9 +28,11 @@ import java.util.stream.IntStream; import java.util.stream.Stream; -import static org.jfleet.parameterized.Databases.*; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import org.jfleet.BulkInsert; +import org.jfleet.parameterized.DatabaseArgumentProvider; +import org.jfleet.util.MySqlDatabase; +import org.jfleet.util.SqlUtil; +import org.junit.jupiter.api.Test; public class MySqlReservedWordTest { diff --git a/jfleet-core/src/test/java/org/jfleet/mysql/MySqlTransactionPolicyTest.java b/jfleet-core/src/test/java/org/jfleet/mysql/MySqlTransactionPolicyTest.java index 8e874c5..ec5eec8 100644 --- a/jfleet-core/src/test/java/org/jfleet/mysql/MySqlTransactionPolicyTest.java +++ b/jfleet-core/src/test/java/org/jfleet/mysql/MySqlTransactionPolicyTest.java @@ -15,6 +15,16 @@ */ package org.jfleet.mysql; +import static org.jfleet.mysql.LoadDataConfiguration.LoadDataConfigurationBuilder.from; +import static org.jfleet.parameterized.Databases.MySql; +import static org.jfleet.util.TransactionPolicyTestHelper.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.io.IOException; +import java.sql.Connection; +import java.sql.SQLException; + import org.jfleet.BulkInsert; import org.jfleet.JFleetException; import org.jfleet.entities.Employee; @@ -25,16 +35,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.IOException; -import java.sql.Connection; -import java.sql.SQLException; - -import static org.jfleet.mysql.LoadDataConfiguration.LoadDataConfigurationBuilder.from; -import static org.jfleet.parameterized.Databases.MySql; -import static org.jfleet.util.TransactionPolicyTestHelper.*; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - public class MySqlTransactionPolicyTest { private static Logger logger = LoggerFactory.getLogger(MySqlTransactionPolicyTest.class); diff --git a/jfleet-core/src/test/java/org/jfleet/mysql/error/LockRetryTest.java b/jfleet-core/src/test/java/org/jfleet/mysql/error/LockRetryTest.java index 21476e3..51f20b8 100644 --- a/jfleet-core/src/test/java/org/jfleet/mysql/error/LockRetryTest.java +++ b/jfleet-core/src/test/java/org/jfleet/mysql/error/LockRetryTest.java @@ -15,6 +15,19 @@ */ package org.jfleet.mysql.error; +import static org.jfleet.mysql.LoadDataConfiguration.LoadDataConfigurationBuilder.from; +import static org.jfleet.parameterized.Databases.MySql; +import static org.jfleet.util.TransactionPolicyTestHelper.numberOfRowsInEmployeeTable; +import static org.jfleet.util.TransactionPolicyTestHelper.setupDatabase; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.io.IOException; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.util.stream.Stream; + import org.jfleet.BulkInsert; import org.jfleet.JFleetException; import org.jfleet.entities.City; @@ -28,19 +41,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.IOException; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.SQLException; -import java.util.stream.Stream; - -import static org.jfleet.mysql.LoadDataConfiguration.LoadDataConfigurationBuilder.from; -import static org.jfleet.parameterized.Databases.MySql; -import static org.jfleet.util.TransactionPolicyTestHelper.numberOfRowsInEmployeeTable; -import static org.jfleet.util.TransactionPolicyTestHelper.setupDatabase; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - public class LockRetryTest { private static Logger logger = LoggerFactory.getLogger(LockRetryTest.class); diff --git a/jfleet-core/src/test/java/org/jfleet/mysql/manual/ConnectionTest.java b/jfleet-core/src/test/java/org/jfleet/mysql/manual/ConnectionTest.java index 52891c1..9f7a40e 100644 --- a/jfleet-core/src/test/java/org/jfleet/mysql/manual/ConnectionTest.java +++ b/jfleet-core/src/test/java/org/jfleet/mysql/manual/ConnectionTest.java @@ -15,12 +15,8 @@ */ package org.jfleet.mysql.manual; -import com.mysql.jdbc.Connection; -import com.mysql.jdbc.Statement; -import org.jfleet.parameterized.DatabaseArgumentProvider; -import org.jfleet.parameterized.IsMySql5Present; -import org.jfleet.util.MySqlDatabase; -import org.junit.jupiter.api.Test; +import static org.jfleet.parameterized.Databases.MySql; +import static org.junit.jupiter.api.Assertions.*; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -28,8 +24,12 @@ import java.sql.ResultSet; import java.sql.SQLException; -import static org.jfleet.parameterized.Databases.MySql; -import static org.junit.jupiter.api.Assertions.*; +import com.mysql.jdbc.Connection; +import com.mysql.jdbc.Statement; +import org.jfleet.parameterized.DatabaseArgumentProvider; +import org.jfleet.parameterized.IsMySql5Present; +import org.jfleet.util.MySqlDatabase; +import org.junit.jupiter.api.Test; public class ConnectionTest { diff --git a/jfleet-core/src/test/java/org/jfleet/mysql/manual/IdsTest.java b/jfleet-core/src/test/java/org/jfleet/mysql/manual/IdsTest.java index 6589322..c6d5e70 100644 --- a/jfleet-core/src/test/java/org/jfleet/mysql/manual/IdsTest.java +++ b/jfleet-core/src/test/java/org/jfleet/mysql/manual/IdsTest.java @@ -15,12 +15,9 @@ */ package org.jfleet.mysql.manual; -import com.mysql.jdbc.Connection; -import com.mysql.jdbc.Statement; -import org.jfleet.parameterized.DatabaseArgumentProvider; -import org.jfleet.parameterized.IsMySql5Present; -import org.jfleet.util.MySqlDatabase; -import org.junit.jupiter.api.Test; +import static org.jfleet.parameterized.Databases.MySql; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -28,9 +25,12 @@ import java.sql.ResultSet; import java.sql.SQLException; -import static org.jfleet.parameterized.Databases.MySql; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import com.mysql.jdbc.Connection; +import com.mysql.jdbc.Statement; +import org.jfleet.parameterized.DatabaseArgumentProvider; +import org.jfleet.parameterized.IsMySql5Present; +import org.jfleet.util.MySqlDatabase; +import org.junit.jupiter.api.Test; @IsMySql5Present public class IdsTest { diff --git a/jfleet-core/src/test/java/org/jfleet/parameterized/DatabaseArgumentProvider.java b/jfleet-core/src/test/java/org/jfleet/parameterized/DatabaseArgumentProvider.java index a2098fe..cf3401e 100644 --- a/jfleet-core/src/test/java/org/jfleet/parameterized/DatabaseArgumentProvider.java +++ b/jfleet-core/src/test/java/org/jfleet/parameterized/DatabaseArgumentProvider.java @@ -15,6 +15,13 @@ */ package org.jfleet.parameterized; +import static org.jfleet.parameterized.Databases.*; + +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; +import java.util.stream.Stream; + import org.jfleet.util.*; import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.jupiter.params.provider.Arguments; @@ -23,38 +30,32 @@ import org.testcontainers.containers.MySQLContainer; import org.testcontainers.containers.PostgreSQLContainer; -import java.lang.reflect.Method; -import java.util.Map; -import java.util.stream.Stream; - -import static org.jfleet.parameterized.Databases.*; - public class DatabaseArgumentProvider implements ArgumentsProvider { - //TODO move this - private static PostgreSQLContainer postgreSQLContainer = new PostgreSQLContainer<>("postgres:12-alpine") + private static final PostgreSQLContainer postgreSqlContainer = new PostgreSQLContainer<>("postgres:12-alpine") .withUsername("test") - .withPassword("test") - .withDatabaseName("postgresdb") - .withUrlParam("reWriteBatchedInserts", "true"); - private static MySQLContainer mySQLContainer = new MySQLContainer<>("mysql:5.7.34") + .withPassword("test") + .withPassword("test") + .withDatabaseName("postgresdb") + .withUrlParam("reWriteBatchedInserts", "true"); + + private static final MySQLContainer mySqlContainer = new MySQLContainer<>("mysql:5.7.34") .withUsername("test") - .withPassword("test") - .withDatabaseName("testdb") - .withUrlParam("useSSL","false") - .withUrlParam("allowPublicKeyRetrieval", "true") - .withUrlParam("useUnicode","true") - .withUrlParam("characterEncoding", "utf-8") - .withUrlParam("allowLoadLocalInfile", "true"); + .withPassword("test") + .withDatabaseName("testdb") + .withUrlParam("useSSL","false") + .withUrlParam("allowPublicKeyRetrieval", "true") + .withUrlParam("useUnicode","true") + .withUrlParam("characterEncoding", "utf-8") + .withUrlParam("allowLoadLocalInfile", "true"); - private static final Map> map = Map.of( - Postgres, postgreSQLContainer, - JdbcPosgres, postgreSQLContainer, - MySql, mySQLContainer, - JdbcMySql, mySQLContainer - ); + private static final Map> map = new HashMap<>(); static { + map.put(Postgres, postgreSqlContainer); + map.put(JdbcPosgres, postgreSqlContainer); + map.put(MySql, mySqlContainer); + map.put(JdbcMySql, mySqlContainer); map.values().parallelStream().forEach(GenericContainer::start); } @@ -76,12 +77,18 @@ private Stream getDatabases(Databases[] dbs) { } public static Database getDatabaseContainer(Databases enumValue) { - return switch (enumValue) { - case JdbcMySql -> new JdbcMysqlDatabase(mySQLContainer); - case JdbcPosgres -> new JdbcPostgresDatabase(postgreSQLContainer); - case MySql -> new MySqlDatabase(mySQLContainer); - case Postgres -> new PostgresDatabase(postgreSQLContainer); - }; + switch (enumValue) { + case JdbcMySql: + return new JdbcMysqlDatabase(mySqlContainer); + case JdbcPosgres: + return new JdbcPostgresDatabase(postgreSqlContainer); + case MySql: + return new MySqlDatabase(mySqlContainer); + case Postgres: + return new PostgresDatabase(postgreSqlContainer); + } + + return null; } } diff --git a/jfleet-core/src/test/java/org/jfleet/parameterized/IsMySql5Condition.java b/jfleet-core/src/test/java/org/jfleet/parameterized/IsMySql5Condition.java index 53fe2c5..194f0f3 100644 --- a/jfleet-core/src/test/java/org/jfleet/parameterized/IsMySql5Condition.java +++ b/jfleet-core/src/test/java/org/jfleet/parameterized/IsMySql5Condition.java @@ -15,13 +15,13 @@ */ package org.jfleet.parameterized; +import static org.junit.jupiter.api.extension.ConditionEvaluationResult.disabled; +import static org.junit.jupiter.api.extension.ConditionEvaluationResult.enabled; + import org.junit.jupiter.api.extension.ConditionEvaluationResult; import org.junit.jupiter.api.extension.ExecutionCondition; import org.junit.jupiter.api.extension.ExtensionContext; -import static org.junit.jupiter.api.extension.ConditionEvaluationResult.disabled; -import static org.junit.jupiter.api.extension.ConditionEvaluationResult.enabled; - public class IsMySql5Condition implements ExecutionCondition { @Override diff --git a/jfleet-core/src/test/java/org/jfleet/postgres/PostgresDateTypePersistenceWithMillisecondsResolutionTest.java b/jfleet-core/src/test/java/org/jfleet/postgres/PostgresDateTypePersistenceWithMillisecondsResolutionTest.java index 2fc4cd5..6eab66a 100644 --- a/jfleet-core/src/test/java/org/jfleet/postgres/PostgresDateTypePersistenceWithMillisecondsResolutionTest.java +++ b/jfleet-core/src/test/java/org/jfleet/postgres/PostgresDateTypePersistenceWithMillisecondsResolutionTest.java @@ -15,12 +15,10 @@ */ package org.jfleet.postgres; -import org.jfleet.BulkInsert; -import org.jfleet.parameterized.DBs; -import org.jfleet.parameterized.TestDBs; -import org.jfleet.shared.entities.EntityWithDateTypes; -import org.jfleet.util.Database; -import org.jfleet.util.SqlUtil; +import static org.jfleet.parameterized.Databases.JdbcPosgres; +import static org.jfleet.parameterized.Databases.Postgres; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.sql.*; import java.text.ParseException; @@ -30,10 +28,12 @@ import java.util.Date; import java.util.stream.Stream; -import static org.jfleet.parameterized.Databases.JdbcPosgres; -import static org.jfleet.parameterized.Databases.Postgres; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import org.jfleet.BulkInsert; +import org.jfleet.parameterized.DBs; +import org.jfleet.parameterized.TestDBs; +import org.jfleet.shared.entities.EntityWithDateTypes; +import org.jfleet.util.Database; +import org.jfleet.util.SqlUtil; public class PostgresDateTypePersistenceWithMillisecondsResolutionTest { diff --git a/jfleet-core/src/test/java/org/jfleet/postgres/PostgresReservedWordTest.java b/jfleet-core/src/test/java/org/jfleet/postgres/PostgresReservedWordTest.java index e274a9b..b7a513c 100644 --- a/jfleet-core/src/test/java/org/jfleet/postgres/PostgresReservedWordTest.java +++ b/jfleet-core/src/test/java/org/jfleet/postgres/PostgresReservedWordTest.java @@ -15,11 +15,10 @@ */ package org.jfleet.postgres; -import org.jfleet.BulkInsert; -import org.jfleet.parameterized.DBs; -import org.jfleet.parameterized.TestDBs; -import org.jfleet.util.Database; -import org.jfleet.util.SqlUtil; +import static org.jfleet.parameterized.Databases.JdbcPosgres; +import static org.jfleet.parameterized.Databases.Postgres; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import javax.persistence.Column; import javax.persistence.Entity; @@ -30,10 +29,11 @@ import java.util.stream.IntStream; import java.util.stream.Stream; -import static org.jfleet.parameterized.Databases.JdbcPosgres; -import static org.jfleet.parameterized.Databases.Postgres; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import org.jfleet.BulkInsert; +import org.jfleet.parameterized.DBs; +import org.jfleet.parameterized.TestDBs; +import org.jfleet.util.Database; +import org.jfleet.util.SqlUtil; public class PostgresReservedWordTest { diff --git a/jfleet-core/src/test/java/org/jfleet/postgres/PostgresTransactionPolicyTest.java b/jfleet-core/src/test/java/org/jfleet/postgres/PostgresTransactionPolicyTest.java index 7f584c2..f5c881c 100644 --- a/jfleet-core/src/test/java/org/jfleet/postgres/PostgresTransactionPolicyTest.java +++ b/jfleet-core/src/test/java/org/jfleet/postgres/PostgresTransactionPolicyTest.java @@ -15,6 +15,16 @@ */ package org.jfleet.postgres; +import static org.jfleet.parameterized.Databases.Postgres; +import static org.jfleet.postgres.PgCopyConfiguration.PgCopyConfigurationBuilder.from; +import static org.jfleet.util.TransactionPolicyTestHelper.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.io.IOException; +import java.sql.Connection; +import java.sql.SQLException; + import org.jfleet.BulkInsert; import org.jfleet.entities.Employee; import org.jfleet.parameterized.DatabaseArgumentProvider; @@ -24,16 +34,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.IOException; -import java.sql.Connection; -import java.sql.SQLException; - -import static org.jfleet.parameterized.Databases.Postgres; -import static org.jfleet.postgres.PgCopyConfiguration.PgCopyConfigurationBuilder.from; -import static org.jfleet.util.TransactionPolicyTestHelper.*; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - public class PostgresTransactionPolicyTest { private static final Logger logger = LoggerFactory.getLogger(PostgresTransactionPolicyTest.class); diff --git a/jfleet-core/src/test/java/org/jfleet/postgres/manual/ConnectionTest.java b/jfleet-core/src/test/java/org/jfleet/postgres/manual/ConnectionTest.java index 4ca1b0c..3d2544c 100644 --- a/jfleet-core/src/test/java/org/jfleet/postgres/manual/ConnectionTest.java +++ b/jfleet-core/src/test/java/org/jfleet/postgres/manual/ConnectionTest.java @@ -15,13 +15,8 @@ */ package org.jfleet.postgres.manual; -import org.jfleet.common.StringBuilderReader; -import org.jfleet.parameterized.DatabaseArgumentProvider; -import org.jfleet.util.PostgresDatabase; -import org.junit.jupiter.api.Test; -import org.postgresql.copy.CopyManager; -import org.postgresql.jdbc.PgConnection; -import org.postgresql.util.PSQLException; +import static org.jfleet.parameterized.Databases.Postgres; +import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; import java.io.Reader; @@ -30,8 +25,13 @@ import java.sql.SQLException; import java.sql.Statement; -import static org.jfleet.parameterized.Databases.Postgres; -import static org.junit.jupiter.api.Assertions.*; +import org.jfleet.common.StringBuilderReader; +import org.jfleet.parameterized.DatabaseArgumentProvider; +import org.jfleet.util.PostgresDatabase; +import org.junit.jupiter.api.Test; +import org.postgresql.copy.CopyManager; +import org.postgresql.jdbc.PgConnection; +import org.postgresql.util.PSQLException; public class ConnectionTest { diff --git a/jfleet-core/src/test/java/org/jfleet/shared/DateTypePersistenceTest.java b/jfleet-core/src/test/java/org/jfleet/shared/DateTypePersistenceTest.java index e3806d5..9b11601 100644 --- a/jfleet-core/src/test/java/org/jfleet/shared/DateTypePersistenceTest.java +++ b/jfleet-core/src/test/java/org/jfleet/shared/DateTypePersistenceTest.java @@ -15,12 +15,8 @@ */ package org.jfleet.shared; -import org.jfleet.BulkInsert; -import org.jfleet.parameterized.IsMySql5Present; -import org.jfleet.parameterized.TestDBs; -import org.jfleet.shared.entities.EntityWithDateTypes; -import org.jfleet.util.Database; -import org.jfleet.util.SqlUtil; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.sql.Connection; import java.sql.ResultSet; @@ -33,8 +29,12 @@ import java.util.Date; import java.util.stream.Stream; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import org.jfleet.BulkInsert; +import org.jfleet.parameterized.IsMySql5Present; +import org.jfleet.parameterized.TestDBs; +import org.jfleet.shared.entities.EntityWithDateTypes; +import org.jfleet.util.Database; +import org.jfleet.util.SqlUtil; public class DateTypePersistenceTest { diff --git a/jfleet-core/src/test/java/org/jfleet/shared/EmbeddedEntityPersistenceTest.java b/jfleet-core/src/test/java/org/jfleet/shared/EmbeddedEntityPersistenceTest.java index 6d20798..f866bdf 100644 --- a/jfleet-core/src/test/java/org/jfleet/shared/EmbeddedEntityPersistenceTest.java +++ b/jfleet-core/src/test/java/org/jfleet/shared/EmbeddedEntityPersistenceTest.java @@ -15,13 +15,8 @@ */ package org.jfleet.shared; -import org.jfleet.BulkInsert; -import org.jfleet.entities.Address; -import org.jfleet.entities.Company; -import org.jfleet.entities.Person; -import org.jfleet.parameterized.TestDBs; -import org.jfleet.util.Database; -import org.jfleet.util.SqlUtil; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.sql.Connection; import java.sql.ResultSet; @@ -30,8 +25,13 @@ import java.util.List; import java.util.stream.Stream; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import org.jfleet.BulkInsert; +import org.jfleet.entities.Address; +import org.jfleet.entities.Company; +import org.jfleet.entities.Person; +import org.jfleet.parameterized.TestDBs; +import org.jfleet.util.Database; +import org.jfleet.util.SqlUtil; public class EmbeddedEntityPersistenceTest { diff --git a/jfleet-core/src/test/java/org/jfleet/shared/EncodingTest.java b/jfleet-core/src/test/java/org/jfleet/shared/EncodingTest.java index be1f954..6a39565 100644 --- a/jfleet-core/src/test/java/org/jfleet/shared/EncodingTest.java +++ b/jfleet-core/src/test/java/org/jfleet/shared/EncodingTest.java @@ -15,10 +15,8 @@ */ package org.jfleet.shared; -import org.jfleet.BulkInsert; -import org.jfleet.parameterized.TestDBs; -import org.jfleet.util.Database; -import org.jfleet.util.SqlUtil; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import javax.persistence.Entity; import javax.persistence.Table; @@ -33,8 +31,10 @@ import java.util.List; import java.util.stream.Collectors; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import org.jfleet.BulkInsert; +import org.jfleet.parameterized.TestDBs; +import org.jfleet.util.Database; +import org.jfleet.util.SqlUtil; public class EncodingTest { diff --git a/jfleet-core/src/test/java/org/jfleet/shared/IdPersistenceTest.java b/jfleet-core/src/test/java/org/jfleet/shared/IdPersistenceTest.java index d8d845a..5152df9 100644 --- a/jfleet-core/src/test/java/org/jfleet/shared/IdPersistenceTest.java +++ b/jfleet-core/src/test/java/org/jfleet/shared/IdPersistenceTest.java @@ -15,10 +15,7 @@ */ package org.jfleet.shared; -import org.jfleet.BulkInsert; -import org.jfleet.parameterized.TestDBs; -import org.jfleet.util.Database; -import org.jfleet.util.SqlUtil; +import static org.junit.jupiter.api.Assertions.*; import javax.persistence.*; import java.sql.Connection; @@ -27,7 +24,10 @@ import java.util.stream.LongStream; import java.util.stream.Stream; -import static org.junit.jupiter.api.Assertions.*; +import org.jfleet.BulkInsert; +import org.jfleet.parameterized.TestDBs; +import org.jfleet.util.Database; +import org.jfleet.util.SqlUtil; public class IdPersistenceTest { diff --git a/jfleet-core/src/test/java/org/jfleet/shared/ManyToOnePersistenceTest.java b/jfleet-core/src/test/java/org/jfleet/shared/ManyToOnePersistenceTest.java index d23e9c3..705d4e8 100644 --- a/jfleet-core/src/test/java/org/jfleet/shared/ManyToOnePersistenceTest.java +++ b/jfleet-core/src/test/java/org/jfleet/shared/ManyToOnePersistenceTest.java @@ -15,10 +15,9 @@ */ package org.jfleet.shared; -import org.jfleet.BulkInsert; -import org.jfleet.parameterized.TestDBs; -import org.jfleet.util.Database; -import org.jfleet.util.SqlUtil; +import static java.util.Arrays.asList; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import javax.persistence.*; import java.sql.Connection; @@ -26,9 +25,10 @@ import java.sql.Statement; import java.util.List; -import static java.util.Arrays.asList; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import org.jfleet.BulkInsert; +import org.jfleet.parameterized.TestDBs; +import org.jfleet.util.Database; +import org.jfleet.util.SqlUtil; public class ManyToOnePersistenceTest { diff --git a/jfleet-core/src/test/java/org/jfleet/shared/SimpleEntityPersistenceTest.java b/jfleet-core/src/test/java/org/jfleet/shared/SimpleEntityPersistenceTest.java index c292f97..57d9a13 100644 --- a/jfleet-core/src/test/java/org/jfleet/shared/SimpleEntityPersistenceTest.java +++ b/jfleet-core/src/test/java/org/jfleet/shared/SimpleEntityPersistenceTest.java @@ -15,10 +15,8 @@ */ package org.jfleet.shared; -import org.jfleet.BulkInsert; -import org.jfleet.parameterized.TestDBs; -import org.jfleet.util.Database; -import org.jfleet.util.SqlUtil; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import javax.persistence.Entity; import javax.persistence.Table; @@ -28,8 +26,10 @@ import java.util.stream.IntStream; import java.util.stream.Stream; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import org.jfleet.BulkInsert; +import org.jfleet.parameterized.TestDBs; +import org.jfleet.util.Database; +import org.jfleet.util.SqlUtil; public class SimpleEntityPersistenceTest { diff --git a/jfleet-core/src/test/java/org/jfleet/shared/SpecialCharsPersistenceTest.java b/jfleet-core/src/test/java/org/jfleet/shared/SpecialCharsPersistenceTest.java index ebc74f1..b224dcd 100644 --- a/jfleet-core/src/test/java/org/jfleet/shared/SpecialCharsPersistenceTest.java +++ b/jfleet-core/src/test/java/org/jfleet/shared/SpecialCharsPersistenceTest.java @@ -15,10 +15,8 @@ */ package org.jfleet.shared; -import org.jfleet.BulkInsert; -import org.jfleet.parameterized.TestDBs; -import org.jfleet.util.Database; -import org.jfleet.util.SqlUtil; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import javax.persistence.Entity; import javax.persistence.Table; @@ -27,8 +25,10 @@ import java.sql.Statement; import java.util.stream.Stream; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import org.jfleet.BulkInsert; +import org.jfleet.parameterized.TestDBs; +import org.jfleet.util.Database; +import org.jfleet.util.SqlUtil; public class SpecialCharsPersistenceTest { diff --git a/jfleet-core/src/test/java/org/jfleet/shared/TypePersistenceTest.java b/jfleet-core/src/test/java/org/jfleet/shared/TypePersistenceTest.java index fb6b515..c405427 100644 --- a/jfleet-core/src/test/java/org/jfleet/shared/TypePersistenceTest.java +++ b/jfleet-core/src/test/java/org/jfleet/shared/TypePersistenceTest.java @@ -15,12 +15,8 @@ */ package org.jfleet.shared; -import org.jfleet.BulkInsert; -import org.jfleet.parameterized.TestDBs; -import org.jfleet.shared.entities.EntityWithBasicTypes; -import org.jfleet.shared.entities.EnumForTest; -import org.jfleet.util.Database; -import org.jfleet.util.SqlUtil; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.math.BigDecimal; import java.math.BigInteger; @@ -29,8 +25,12 @@ import java.sql.Statement; import java.util.stream.Stream; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import org.jfleet.BulkInsert; +import org.jfleet.parameterized.TestDBs; +import org.jfleet.shared.entities.EntityWithBasicTypes; +import org.jfleet.shared.entities.EnumForTest; +import org.jfleet.util.Database; +import org.jfleet.util.SqlUtil; public class TypePersistenceTest { diff --git a/jfleet-core/src/test/java/org/jfleet/shared/entities/EntityWithBasicTypes.java b/jfleet-core/src/test/java/org/jfleet/shared/entities/EntityWithBasicTypes.java index 4d52784..3b45966 100644 --- a/jfleet-core/src/test/java/org/jfleet/shared/entities/EntityWithBasicTypes.java +++ b/jfleet-core/src/test/java/org/jfleet/shared/entities/EntityWithBasicTypes.java @@ -15,13 +15,12 @@ */ package org.jfleet.shared.entities; -import java.math.BigDecimal; -import java.math.BigInteger; - import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; import javax.persistence.Table; +import java.math.BigDecimal; +import java.math.BigInteger; @Entity @Table(name = "table_with_basic_types") diff --git a/jfleet-core/src/test/java/org/jfleet/shared/entities/EntityWithDateTypes.java b/jfleet-core/src/test/java/org/jfleet/shared/entities/EntityWithDateTypes.java index 17b34e5..a3ba4cc 100644 --- a/jfleet-core/src/test/java/org/jfleet/shared/entities/EntityWithDateTypes.java +++ b/jfleet-core/src/test/java/org/jfleet/shared/entities/EntityWithDateTypes.java @@ -15,17 +15,12 @@ */ package org.jfleet.shared.entities; +import javax.persistence.*; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.util.Date; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; - @Entity @Table(name = "table_with_date_types") public class EntityWithDateTypes { diff --git a/jfleet-core/src/test/java/org/jfleet/util/Database.java b/jfleet-core/src/test/java/org/jfleet/util/Database.java index 7399bbc..8ded8b2 100644 --- a/jfleet-core/src/test/java/org/jfleet/util/Database.java +++ b/jfleet-core/src/test/java/org/jfleet/util/Database.java @@ -15,12 +15,12 @@ */ package org.jfleet.util; -import org.jfleet.BulkInsert; -import org.testcontainers.containers.JdbcDatabaseContainer; - import java.io.IOException; import java.sql.Connection; +import org.jfleet.BulkInsert; +import org.testcontainers.containers.JdbcDatabaseContainer; + public abstract class Database { private final JdbcDatabaseContainer container; @@ -37,7 +37,7 @@ public Connection getConnection() throws IOException { @Override public String toString() { - return this.getClass().getSimpleName().replace("DatabaseContainer", ""); + return this.getClass().getSimpleName().replace("Database", ""); } } diff --git a/jfleet-core/src/test/java/org/jfleet/util/DatabaseTestConnectionProvider.java b/jfleet-core/src/test/java/org/jfleet/util/DatabaseTestConnectionProvider.java index e02761d..f218031 100644 --- a/jfleet-core/src/test/java/org/jfleet/util/DatabaseTestConnectionProvider.java +++ b/jfleet-core/src/test/java/org/jfleet/util/DatabaseTestConnectionProvider.java @@ -15,13 +15,13 @@ */ package org.jfleet.util; -import org.testcontainers.containers.JdbcDatabaseContainer; - import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.util.function.Supplier; +import org.testcontainers.containers.JdbcDatabaseContainer; + public class DatabaseTestConnectionProvider implements Supplier { private final JdbcDatabaseContainer container; diff --git a/jfleet-core/src/test/java/org/jfleet/util/SqlUtil.java b/jfleet-core/src/test/java/org/jfleet/util/SqlUtil.java index 9be3c45..b5bc663 100644 --- a/jfleet-core/src/test/java/org/jfleet/util/SqlUtil.java +++ b/jfleet-core/src/test/java/org/jfleet/util/SqlUtil.java @@ -19,6 +19,7 @@ import java.sql.SQLException; import java.sql.Statement; +import com.mysql.cj.jdbc.JdbcConnection; import org.jfleet.EntityInfo; import org.jfleet.inspection.JpaEntityInspector; import org.jfleet.util.Dialect.DDLHelper; @@ -26,8 +27,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.mysql.cj.jdbc.JdbcConnection; - public class SqlUtil { private static Logger logger = LoggerFactory.getLogger(SqlUtil.class); diff --git a/jfleet-core/src/test/java/org/jfleet/util/TransactionPolicyTestHelper.java b/jfleet-core/src/test/java/org/jfleet/util/TransactionPolicyTestHelper.java index 6862862..ff1d4a4 100644 --- a/jfleet-core/src/test/java/org/jfleet/util/TransactionPolicyTestHelper.java +++ b/jfleet-core/src/test/java/org/jfleet/util/TransactionPolicyTestHelper.java @@ -15,8 +15,7 @@ */ package org.jfleet.util; -import org.jfleet.entities.City; -import org.jfleet.entities.Employee; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.sql.Connection; import java.sql.ResultSet; @@ -24,7 +23,8 @@ import java.sql.Statement; import java.util.stream.Stream; -import static org.junit.jupiter.api.Assertions.assertTrue; +import org.jfleet.entities.City; +import org.jfleet.entities.Employee; public class TransactionPolicyTestHelper { From 6ea44213a861269d20a74c358bc8d85c3b48f396 Mon Sep 17 00:00:00 2001 From: Alvaro Date: Tue, 15 Oct 2024 13:08:31 +0200 Subject: [PATCH 03/10] add gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 99bd243..a77fb30 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .gradle bin +build +.idea \ No newline at end of file From 26187c2cd4fa81321079a1591c266b14e374b1aa Mon Sep 17 00:00:00 2001 From: Alvaro Date: Tue, 15 Oct 2024 16:55:48 +0200 Subject: [PATCH 04/10] remove * from imports --- .../src/test/java/org/jfleet/csv/HeaderTest.java | 5 +++-- .../src/test/java/org/jfleet/entities/Company.java | 7 ++++++- .../src/test/java/org/jfleet/entities/Employee.java | 6 +++++- .../jfleet/inspection/EmbeddedIdInspectorTest.java | 7 ++++++- .../jfleet/inspection/EntityFieldAccesorTest.java | 7 ++++++- .../jfleet/inspection/EntityInfoBuilderTest.java | 6 +++++- .../org/jfleet/inspection/EntityInspectorTest.java | 13 +++++++++++-- .../FailedManyToOneEntityInspectorTest.java | 7 ++++++- .../jfleet/inspection/FieldTypeInspectorTest.java | 11 +++++++++-- .../inspection/HierarchyEntityInspectorTest.java | 7 ++++++- .../org/jfleet/jdbc/JdbcTransactionPolicyTest.java | 5 ++++- .../org/jfleet/mysql/MySqlReservedWordTest.java | 7 ++++--- .../jfleet/mysql/MySqlTransactionPolicyTest.java | 7 ++++++- .../org/jfleet/mysql/manual/ConnectionTest.java | 9 ++++++--- .../test/java/org/jfleet/mysql/manual/IdsTest.java | 5 +++-- .../parameterized/DatabaseArgumentProvider.java | 11 +++++++++-- ...pePersistenceWithMillisecondsResolutionTest.java | 6 +++++- .../jfleet/postgres/PostgresReservedWordTest.java | 7 ++++--- .../postgres/PostgresTransactionPolicyTest.java | 5 ++++- .../org/jfleet/postgres/manual/ConnectionTest.java | 5 ++++- .../test/java/org/jfleet/shared/EncodingTest.java | 5 +++-- .../java/org/jfleet/shared/IdPersistenceTest.java | 11 +++++++++-- .../org/jfleet/shared/ManyToOnePersistenceTest.java | 7 ++++++- .../jfleet/shared/SimpleEntityPersistenceTest.java | 5 +++-- .../jfleet/shared/SpecialCharsPersistenceTest.java | 5 +++-- .../shared/entities/EntityWithBasicTypes.java | 5 +++-- .../jfleet/shared/entities/EntityWithDateTypes.java | 7 ++++++- .../src/test/java/org/jfleet/util/SqlUtil.java | 3 ++- 28 files changed, 147 insertions(+), 44 deletions(-) diff --git a/jfleet-core/src/test/java/org/jfleet/csv/HeaderTest.java b/jfleet-core/src/test/java/org/jfleet/csv/HeaderTest.java index 7247b7f..fab92f9 100644 --- a/jfleet-core/src/test/java/org/jfleet/csv/HeaderTest.java +++ b/jfleet-core/src/test/java/org/jfleet/csv/HeaderTest.java @@ -19,12 +19,13 @@ import static org.jfleet.csv.CsvTestHelper.writeCsvToString; import static org.junit.jupiter.api.Assertions.assertEquals; +import java.io.IOException; +import java.util.Collections; + import javax.persistence.Column; import javax.persistence.Embeddable; import javax.persistence.Embedded; import javax.persistence.Entity; -import java.io.IOException; -import java.util.Collections; import org.jfleet.EntityFieldType.FieldTypeEnum; import org.jfleet.EntityInfoBuilder; diff --git a/jfleet-core/src/test/java/org/jfleet/entities/Company.java b/jfleet-core/src/test/java/org/jfleet/entities/Company.java index c233e5b..db48f1f 100644 --- a/jfleet-core/src/test/java/org/jfleet/entities/Company.java +++ b/jfleet-core/src/test/java/org/jfleet/entities/Company.java @@ -15,7 +15,12 @@ */ package org.jfleet.entities; -import javax.persistence.*; +import javax.persistence.AttributeOverride; +import javax.persistence.AttributeOverrides; +import javax.persistence.Column; +import javax.persistence.Embedded; +import javax.persistence.Entity; +import javax.persistence.Id; @Entity public class Company { diff --git a/jfleet-core/src/test/java/org/jfleet/entities/Employee.java b/jfleet-core/src/test/java/org/jfleet/entities/Employee.java index 020457a..cca96b6 100644 --- a/jfleet-core/src/test/java/org/jfleet/entities/Employee.java +++ b/jfleet-core/src/test/java/org/jfleet/entities/Employee.java @@ -15,7 +15,11 @@ */ package org.jfleet.entities; -import javax.persistence.*; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; @Entity @Table(name = "employee") diff --git a/jfleet-core/src/test/java/org/jfleet/inspection/EmbeddedIdInspectorTest.java b/jfleet-core/src/test/java/org/jfleet/inspection/EmbeddedIdInspectorTest.java index 258bade..b2ff299 100644 --- a/jfleet-core/src/test/java/org/jfleet/inspection/EmbeddedIdInspectorTest.java +++ b/jfleet-core/src/test/java/org/jfleet/inspection/EmbeddedIdInspectorTest.java @@ -17,7 +17,12 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -import javax.persistence.*; +import javax.persistence.AttributeOverride; +import javax.persistence.AttributeOverrides; +import javax.persistence.Column; +import javax.persistence.Embeddable; +import javax.persistence.EmbeddedId; +import javax.persistence.Entity; import org.jfleet.EntityFieldType.FieldTypeEnum; import org.jfleet.FieldInfo; diff --git a/jfleet-core/src/test/java/org/jfleet/inspection/EntityFieldAccesorTest.java b/jfleet-core/src/test/java/org/jfleet/inspection/EntityFieldAccesorTest.java index f93a87d..e292e2b 100644 --- a/jfleet-core/src/test/java/org/jfleet/inspection/EntityFieldAccesorTest.java +++ b/jfleet-core/src/test/java/org/jfleet/inspection/EntityFieldAccesorTest.java @@ -18,9 +18,14 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; -import javax.persistence.*; import java.util.function.Function; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + import org.junit.jupiter.api.Test; public class EntityFieldAccesorTest { diff --git a/jfleet-core/src/test/java/org/jfleet/inspection/EntityInfoBuilderTest.java b/jfleet-core/src/test/java/org/jfleet/inspection/EntityInfoBuilderTest.java index b0d37db..6c971d2 100644 --- a/jfleet-core/src/test/java/org/jfleet/inspection/EntityInfoBuilderTest.java +++ b/jfleet-core/src/test/java/org/jfleet/inspection/EntityInfoBuilderTest.java @@ -16,7 +16,11 @@ package org.jfleet.inspection; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Date; diff --git a/jfleet-core/src/test/java/org/jfleet/inspection/EntityInspectorTest.java b/jfleet-core/src/test/java/org/jfleet/inspection/EntityInspectorTest.java index 9428ca7..054887e 100644 --- a/jfleet-core/src/test/java/org/jfleet/inspection/EntityInspectorTest.java +++ b/jfleet-core/src/test/java/org/jfleet/inspection/EntityInspectorTest.java @@ -15,11 +15,20 @@ */ package org.jfleet.inspection; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; -import javax.persistence.*; import java.util.List; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + import org.jfleet.EntityFieldType; import org.jfleet.EntityFieldType.FieldTypeEnum; import org.jfleet.EntityInfo; diff --git a/jfleet-core/src/test/java/org/jfleet/inspection/FailedManyToOneEntityInspectorTest.java b/jfleet-core/src/test/java/org/jfleet/inspection/FailedManyToOneEntityInspectorTest.java index bd7e29e..e959c98 100644 --- a/jfleet-core/src/test/java/org/jfleet/inspection/FailedManyToOneEntityInspectorTest.java +++ b/jfleet-core/src/test/java/org/jfleet/inspection/FailedManyToOneEntityInspectorTest.java @@ -18,9 +18,14 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import javax.persistence.*; import java.util.List; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.JoinColumns; +import javax.persistence.JoinTable; +import javax.persistence.ManyToOne; + import org.jfleet.EntityFieldType.FieldTypeEnum; import org.jfleet.FieldInfo; import org.junit.jupiter.api.Test; diff --git a/jfleet-core/src/test/java/org/jfleet/inspection/FieldTypeInspectorTest.java b/jfleet-core/src/test/java/org/jfleet/inspection/FieldTypeInspectorTest.java index ec72c62..248f40e 100644 --- a/jfleet-core/src/test/java/org/jfleet/inspection/FieldTypeInspectorTest.java +++ b/jfleet-core/src/test/java/org/jfleet/inspection/FieldTypeInspectorTest.java @@ -15,15 +15,22 @@ */ package org.jfleet.inspection; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; -import javax.persistence.*; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.util.Date; import java.util.List; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + import org.jfleet.EntityFieldType; import org.jfleet.EntityFieldType.FieldTypeEnum; import org.jfleet.FieldInfo; diff --git a/jfleet-core/src/test/java/org/jfleet/inspection/HierarchyEntityInspectorTest.java b/jfleet-core/src/test/java/org/jfleet/inspection/HierarchyEntityInspectorTest.java index 72a3b03..59927b1 100644 --- a/jfleet-core/src/test/java/org/jfleet/inspection/HierarchyEntityInspectorTest.java +++ b/jfleet-core/src/test/java/org/jfleet/inspection/HierarchyEntityInspectorTest.java @@ -17,9 +17,14 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -import javax.persistence.*; import java.util.List; +import javax.persistence.AttributeOverride; +import javax.persistence.AttributeOverrides; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.MappedSuperclass; + import org.jfleet.FieldInfo; import org.junit.jupiter.api.Test; diff --git a/jfleet-core/src/test/java/org/jfleet/jdbc/JdbcTransactionPolicyTest.java b/jfleet-core/src/test/java/org/jfleet/jdbc/JdbcTransactionPolicyTest.java index 844f1ea..739e4e8 100644 --- a/jfleet-core/src/test/java/org/jfleet/jdbc/JdbcTransactionPolicyTest.java +++ b/jfleet-core/src/test/java/org/jfleet/jdbc/JdbcTransactionPolicyTest.java @@ -17,7 +17,10 @@ import static org.jfleet.parameterized.Databases.JdbcMySql; import static org.jfleet.parameterized.Databases.JdbcPosgres; -import static org.jfleet.util.TransactionPolicyTestHelper.*; +import static org.jfleet.util.TransactionPolicyTestHelper.employeesWithConstraintError; +import static org.jfleet.util.TransactionPolicyTestHelper.employeesWithOutErrors; +import static org.jfleet.util.TransactionPolicyTestHelper.numberOfRowsInEmployeeTable; +import static org.jfleet.util.TransactionPolicyTestHelper.setupDatabase; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; diff --git a/jfleet-core/src/test/java/org/jfleet/mysql/MySqlReservedWordTest.java b/jfleet-core/src/test/java/org/jfleet/mysql/MySqlReservedWordTest.java index 70ae17a..13d4f5d 100644 --- a/jfleet-core/src/test/java/org/jfleet/mysql/MySqlReservedWordTest.java +++ b/jfleet-core/src/test/java/org/jfleet/mysql/MySqlReservedWordTest.java @@ -19,15 +19,16 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Table; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; import java.util.stream.IntStream; import java.util.stream.Stream; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; + import org.jfleet.BulkInsert; import org.jfleet.parameterized.DatabaseArgumentProvider; import org.jfleet.util.MySqlDatabase; diff --git a/jfleet-core/src/test/java/org/jfleet/mysql/MySqlTransactionPolicyTest.java b/jfleet-core/src/test/java/org/jfleet/mysql/MySqlTransactionPolicyTest.java index ec5eec8..ff696d6 100644 --- a/jfleet-core/src/test/java/org/jfleet/mysql/MySqlTransactionPolicyTest.java +++ b/jfleet-core/src/test/java/org/jfleet/mysql/MySqlTransactionPolicyTest.java @@ -17,7 +17,12 @@ import static org.jfleet.mysql.LoadDataConfiguration.LoadDataConfigurationBuilder.from; import static org.jfleet.parameterized.Databases.MySql; -import static org.jfleet.util.TransactionPolicyTestHelper.*; +import static org.jfleet.util.TransactionPolicyTestHelper.employeesWithForeignKeyError; +import static org.jfleet.util.TransactionPolicyTestHelper.employeesWithMultipleConstraintsErrors; +import static org.jfleet.util.TransactionPolicyTestHelper.employeesWithOutErrors; +import static org.jfleet.util.TransactionPolicyTestHelper.employeesWithUniqueError; +import static org.jfleet.util.TransactionPolicyTestHelper.numberOfRowsInEmployeeTable; +import static org.jfleet.util.TransactionPolicyTestHelper.setupDatabase; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; diff --git a/jfleet-core/src/test/java/org/jfleet/mysql/manual/ConnectionTest.java b/jfleet-core/src/test/java/org/jfleet/mysql/manual/ConnectionTest.java index 9f7a40e..831503d 100644 --- a/jfleet-core/src/test/java/org/jfleet/mysql/manual/ConnectionTest.java +++ b/jfleet-core/src/test/java/org/jfleet/mysql/manual/ConnectionTest.java @@ -16,7 +16,9 @@ package org.jfleet.mysql.manual; import static org.jfleet.parameterized.Databases.MySql; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -24,13 +26,14 @@ import java.sql.ResultSet; import java.sql.SQLException; -import com.mysql.jdbc.Connection; -import com.mysql.jdbc.Statement; import org.jfleet.parameterized.DatabaseArgumentProvider; import org.jfleet.parameterized.IsMySql5Present; import org.jfleet.util.MySqlDatabase; import org.junit.jupiter.api.Test; +import com.mysql.jdbc.Connection; +import com.mysql.jdbc.Statement; + public class ConnectionTest { private final MySqlDatabase database = (MySqlDatabase) DatabaseArgumentProvider.getDatabaseContainer(MySql); diff --git a/jfleet-core/src/test/java/org/jfleet/mysql/manual/IdsTest.java b/jfleet-core/src/test/java/org/jfleet/mysql/manual/IdsTest.java index c6d5e70..37bebe5 100644 --- a/jfleet-core/src/test/java/org/jfleet/mysql/manual/IdsTest.java +++ b/jfleet-core/src/test/java/org/jfleet/mysql/manual/IdsTest.java @@ -25,13 +25,14 @@ import java.sql.ResultSet; import java.sql.SQLException; -import com.mysql.jdbc.Connection; -import com.mysql.jdbc.Statement; import org.jfleet.parameterized.DatabaseArgumentProvider; import org.jfleet.parameterized.IsMySql5Present; import org.jfleet.util.MySqlDatabase; import org.junit.jupiter.api.Test; +import com.mysql.jdbc.Connection; +import com.mysql.jdbc.Statement; + @IsMySql5Present public class IdsTest { diff --git a/jfleet-core/src/test/java/org/jfleet/parameterized/DatabaseArgumentProvider.java b/jfleet-core/src/test/java/org/jfleet/parameterized/DatabaseArgumentProvider.java index cf3401e..3a92168 100644 --- a/jfleet-core/src/test/java/org/jfleet/parameterized/DatabaseArgumentProvider.java +++ b/jfleet-core/src/test/java/org/jfleet/parameterized/DatabaseArgumentProvider.java @@ -15,14 +15,21 @@ */ package org.jfleet.parameterized; -import static org.jfleet.parameterized.Databases.*; +import static org.jfleet.parameterized.Databases.JdbcMySql; +import static org.jfleet.parameterized.Databases.JdbcPosgres; +import static org.jfleet.parameterized.Databases.MySql; +import static org.jfleet.parameterized.Databases.Postgres; import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; import java.util.stream.Stream; -import org.jfleet.util.*; +import org.jfleet.util.Database; +import org.jfleet.util.JdbcMysqlDatabase; +import org.jfleet.util.JdbcPostgresDatabase; +import org.jfleet.util.MySqlDatabase; +import org.jfleet.util.PostgresDatabase; import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.ArgumentsProvider; diff --git a/jfleet-core/src/test/java/org/jfleet/postgres/PostgresDateTypePersistenceWithMillisecondsResolutionTest.java b/jfleet-core/src/test/java/org/jfleet/postgres/PostgresDateTypePersistenceWithMillisecondsResolutionTest.java index 6eab66a..2296082 100644 --- a/jfleet-core/src/test/java/org/jfleet/postgres/PostgresDateTypePersistenceWithMillisecondsResolutionTest.java +++ b/jfleet-core/src/test/java/org/jfleet/postgres/PostgresDateTypePersistenceWithMillisecondsResolutionTest.java @@ -20,7 +20,11 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.sql.*; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.Statement; +import java.sql.Time; +import java.sql.Timestamp; import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.LocalDateTime; diff --git a/jfleet-core/src/test/java/org/jfleet/postgres/PostgresReservedWordTest.java b/jfleet-core/src/test/java/org/jfleet/postgres/PostgresReservedWordTest.java index b7a513c..227d0ed 100644 --- a/jfleet-core/src/test/java/org/jfleet/postgres/PostgresReservedWordTest.java +++ b/jfleet-core/src/test/java/org/jfleet/postgres/PostgresReservedWordTest.java @@ -20,15 +20,16 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Table; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; import java.util.stream.IntStream; import java.util.stream.Stream; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; + import org.jfleet.BulkInsert; import org.jfleet.parameterized.DBs; import org.jfleet.parameterized.TestDBs; diff --git a/jfleet-core/src/test/java/org/jfleet/postgres/PostgresTransactionPolicyTest.java b/jfleet-core/src/test/java/org/jfleet/postgres/PostgresTransactionPolicyTest.java index f5c881c..6b39666 100644 --- a/jfleet-core/src/test/java/org/jfleet/postgres/PostgresTransactionPolicyTest.java +++ b/jfleet-core/src/test/java/org/jfleet/postgres/PostgresTransactionPolicyTest.java @@ -17,7 +17,10 @@ import static org.jfleet.parameterized.Databases.Postgres; import static org.jfleet.postgres.PgCopyConfiguration.PgCopyConfigurationBuilder.from; -import static org.jfleet.util.TransactionPolicyTestHelper.*; +import static org.jfleet.util.TransactionPolicyTestHelper.employeesWithConstraintError; +import static org.jfleet.util.TransactionPolicyTestHelper.employeesWithOutErrors; +import static org.jfleet.util.TransactionPolicyTestHelper.numberOfRowsInEmployeeTable; +import static org.jfleet.util.TransactionPolicyTestHelper.setupDatabase; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; diff --git a/jfleet-core/src/test/java/org/jfleet/postgres/manual/ConnectionTest.java b/jfleet-core/src/test/java/org/jfleet/postgres/manual/ConnectionTest.java index 3d2544c..9afe2ba 100644 --- a/jfleet-core/src/test/java/org/jfleet/postgres/manual/ConnectionTest.java +++ b/jfleet-core/src/test/java/org/jfleet/postgres/manual/ConnectionTest.java @@ -16,7 +16,10 @@ package org.jfleet.postgres.manual; import static org.jfleet.parameterized.Databases.Postgres; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.io.Reader; diff --git a/jfleet-core/src/test/java/org/jfleet/shared/EncodingTest.java b/jfleet-core/src/test/java/org/jfleet/shared/EncodingTest.java index 6a39565..069fe69 100644 --- a/jfleet-core/src/test/java/org/jfleet/shared/EncodingTest.java +++ b/jfleet-core/src/test/java/org/jfleet/shared/EncodingTest.java @@ -18,8 +18,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -import javax.persistence.Entity; -import javax.persistence.Table; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; @@ -31,6 +29,9 @@ import java.util.List; import java.util.stream.Collectors; +import javax.persistence.Entity; +import javax.persistence.Table; + import org.jfleet.BulkInsert; import org.jfleet.parameterized.TestDBs; import org.jfleet.util.Database; diff --git a/jfleet-core/src/test/java/org/jfleet/shared/IdPersistenceTest.java b/jfleet-core/src/test/java/org/jfleet/shared/IdPersistenceTest.java index 5152df9..c7f5087 100644 --- a/jfleet-core/src/test/java/org/jfleet/shared/IdPersistenceTest.java +++ b/jfleet-core/src/test/java/org/jfleet/shared/IdPersistenceTest.java @@ -15,15 +15,22 @@ */ package org.jfleet.shared; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; -import javax.persistence.*; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; import java.util.stream.LongStream; import java.util.stream.Stream; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + import org.jfleet.BulkInsert; import org.jfleet.parameterized.TestDBs; import org.jfleet.util.Database; diff --git a/jfleet-core/src/test/java/org/jfleet/shared/ManyToOnePersistenceTest.java b/jfleet-core/src/test/java/org/jfleet/shared/ManyToOnePersistenceTest.java index 705d4e8..3ca95e4 100644 --- a/jfleet-core/src/test/java/org/jfleet/shared/ManyToOnePersistenceTest.java +++ b/jfleet-core/src/test/java/org/jfleet/shared/ManyToOnePersistenceTest.java @@ -19,12 +19,17 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -import javax.persistence.*; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; import java.util.List; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + import org.jfleet.BulkInsert; import org.jfleet.parameterized.TestDBs; import org.jfleet.util.Database; diff --git a/jfleet-core/src/test/java/org/jfleet/shared/SimpleEntityPersistenceTest.java b/jfleet-core/src/test/java/org/jfleet/shared/SimpleEntityPersistenceTest.java index 57d9a13..1036e61 100644 --- a/jfleet-core/src/test/java/org/jfleet/shared/SimpleEntityPersistenceTest.java +++ b/jfleet-core/src/test/java/org/jfleet/shared/SimpleEntityPersistenceTest.java @@ -18,14 +18,15 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -import javax.persistence.Entity; -import javax.persistence.Table; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; import java.util.stream.IntStream; import java.util.stream.Stream; +import javax.persistence.Entity; +import javax.persistence.Table; + import org.jfleet.BulkInsert; import org.jfleet.parameterized.TestDBs; import org.jfleet.util.Database; diff --git a/jfleet-core/src/test/java/org/jfleet/shared/SpecialCharsPersistenceTest.java b/jfleet-core/src/test/java/org/jfleet/shared/SpecialCharsPersistenceTest.java index b224dcd..03bde17 100644 --- a/jfleet-core/src/test/java/org/jfleet/shared/SpecialCharsPersistenceTest.java +++ b/jfleet-core/src/test/java/org/jfleet/shared/SpecialCharsPersistenceTest.java @@ -18,13 +18,14 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -import javax.persistence.Entity; -import javax.persistence.Table; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; import java.util.stream.Stream; +import javax.persistence.Entity; +import javax.persistence.Table; + import org.jfleet.BulkInsert; import org.jfleet.parameterized.TestDBs; import org.jfleet.util.Database; diff --git a/jfleet-core/src/test/java/org/jfleet/shared/entities/EntityWithBasicTypes.java b/jfleet-core/src/test/java/org/jfleet/shared/entities/EntityWithBasicTypes.java index 3b45966..4d52784 100644 --- a/jfleet-core/src/test/java/org/jfleet/shared/entities/EntityWithBasicTypes.java +++ b/jfleet-core/src/test/java/org/jfleet/shared/entities/EntityWithBasicTypes.java @@ -15,12 +15,13 @@ */ package org.jfleet.shared.entities; +import java.math.BigDecimal; +import java.math.BigInteger; + import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; import javax.persistence.Table; -import java.math.BigDecimal; -import java.math.BigInteger; @Entity @Table(name = "table_with_basic_types") diff --git a/jfleet-core/src/test/java/org/jfleet/shared/entities/EntityWithDateTypes.java b/jfleet-core/src/test/java/org/jfleet/shared/entities/EntityWithDateTypes.java index a3ba4cc..17b34e5 100644 --- a/jfleet-core/src/test/java/org/jfleet/shared/entities/EntityWithDateTypes.java +++ b/jfleet-core/src/test/java/org/jfleet/shared/entities/EntityWithDateTypes.java @@ -15,12 +15,17 @@ */ package org.jfleet.shared.entities; -import javax.persistence.*; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.util.Date; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + @Entity @Table(name = "table_with_date_types") public class EntityWithDateTypes { diff --git a/jfleet-core/src/test/java/org/jfleet/util/SqlUtil.java b/jfleet-core/src/test/java/org/jfleet/util/SqlUtil.java index b5bc663..9be3c45 100644 --- a/jfleet-core/src/test/java/org/jfleet/util/SqlUtil.java +++ b/jfleet-core/src/test/java/org/jfleet/util/SqlUtil.java @@ -19,7 +19,6 @@ import java.sql.SQLException; import java.sql.Statement; -import com.mysql.cj.jdbc.JdbcConnection; import org.jfleet.EntityInfo; import org.jfleet.inspection.JpaEntityInspector; import org.jfleet.util.Dialect.DDLHelper; @@ -27,6 +26,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.mysql.cj.jdbc.JdbcConnection; + public class SqlUtil { private static Logger logger = LoggerFactory.getLogger(SqlUtil.class); From 5635d234b75183bc638eb286d263426f3b631ef8 Mon Sep 17 00:00:00 2001 From: Alvaro Date: Wed, 16 Oct 2024 10:33:28 +0200 Subject: [PATCH 05/10] change between mysql versions --- .../jfleet/parameterized/DatabaseArgumentProvider.java | 10 +++++++++- .../org/jfleet/parameterized/IsMySql5Condition.java | 2 +- .../java/org/jfleet/parameterized/IsMySql5Present.java | 1 - 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/jfleet-core/src/test/java/org/jfleet/parameterized/DatabaseArgumentProvider.java b/jfleet-core/src/test/java/org/jfleet/parameterized/DatabaseArgumentProvider.java index 3a92168..316191c 100644 --- a/jfleet-core/src/test/java/org/jfleet/parameterized/DatabaseArgumentProvider.java +++ b/jfleet-core/src/test/java/org/jfleet/parameterized/DatabaseArgumentProvider.java @@ -19,6 +19,7 @@ import static org.jfleet.parameterized.Databases.JdbcPosgres; import static org.jfleet.parameterized.Databases.MySql; import static org.jfleet.parameterized.Databases.Postgres; +import static org.jfleet.parameterized.IsMySql5Condition.isMySql5Present; import java.lang.reflect.Method; import java.util.HashMap; @@ -39,6 +40,9 @@ public class DatabaseArgumentProvider implements ArgumentsProvider { + private static final String MYSQL_5_VERSION = "mysql:5.7.34"; + private static final String MYSQL_8_VERSION = "mysql:8.0.39"; + private static final PostgreSQLContainer postgreSqlContainer = new PostgreSQLContainer<>("postgres:12-alpine") .withUsername("test") .withPassword("test") @@ -46,7 +50,7 @@ public class DatabaseArgumentProvider implements ArgumentsProvider { .withDatabaseName("postgresdb") .withUrlParam("reWriteBatchedInserts", "true"); - private static final MySQLContainer mySqlContainer = new MySQLContainer<>("mysql:5.7.34") + private static final MySQLContainer mySqlContainer = new MySQLContainer<>(getMysqlVersion()) .withUsername("test") .withPassword("test") .withDatabaseName("testdb") @@ -56,6 +60,10 @@ public class DatabaseArgumentProvider implements ArgumentsProvider { .withUrlParam("characterEncoding", "utf-8") .withUrlParam("allowLoadLocalInfile", "true"); + private static String getMysqlVersion() { + return isMySql5Present() ? MYSQL_5_VERSION: MYSQL_8_VERSION; + } + private static final Map> map = new HashMap<>(); static { diff --git a/jfleet-core/src/test/java/org/jfleet/parameterized/IsMySql5Condition.java b/jfleet-core/src/test/java/org/jfleet/parameterized/IsMySql5Condition.java index 194f0f3..91a2342 100644 --- a/jfleet-core/src/test/java/org/jfleet/parameterized/IsMySql5Condition.java +++ b/jfleet-core/src/test/java/org/jfleet/parameterized/IsMySql5Condition.java @@ -32,7 +32,7 @@ public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext con return disabled("MySql 5.x driver is not present"); } - private static boolean isMySql5Present() { + public static boolean isMySql5Present() { try { Class.forName("com.mysql.jdbc.PreparedStatement"); } catch (ClassNotFoundException e) { diff --git a/jfleet-core/src/test/java/org/jfleet/parameterized/IsMySql5Present.java b/jfleet-core/src/test/java/org/jfleet/parameterized/IsMySql5Present.java index f9c95e5..085b9af 100644 --- a/jfleet-core/src/test/java/org/jfleet/parameterized/IsMySql5Present.java +++ b/jfleet-core/src/test/java/org/jfleet/parameterized/IsMySql5Present.java @@ -20,7 +20,6 @@ import org.junit.jupiter.api.extension.ExtendWith; -//TODO review uses @Retention(RetentionPolicy.RUNTIME) @ExtendWith(IsMySql5Condition.class) public @interface IsMySql5Present { From 9fe454b89e66f0c26580221032f9e190636ddf81 Mon Sep 17 00:00:00 2001 From: Alvaro Date: Wed, 16 Oct 2024 13:11:36 +0200 Subject: [PATCH 06/10] add config file for mysql local-infile config --- .../DatabaseArgumentProvider.java | 56 ++-------------- .../jfleet/shared/TypePersistenceTest.java | 2 + .../org/jfleet/util/DatabaseContainers.java | 65 +++++++++++++++++++ .../org/jfleet/util/JdbcMysqlDatabase.java | 4 +- .../org/jfleet/util/JdbcPostgresDatabase.java | 4 +- .../java/org/jfleet/util/MySqlDatabase.java | 4 +- .../org/jfleet/util/PostgresDatabase.java | 4 +- .../src/test/resources/my-sql-config/my.cnf | 2 + 8 files changed, 84 insertions(+), 57 deletions(-) create mode 100644 jfleet-core/src/test/java/org/jfleet/util/DatabaseContainers.java create mode 100644 jfleet-core/src/test/resources/my-sql-config/my.cnf diff --git a/jfleet-core/src/test/java/org/jfleet/parameterized/DatabaseArgumentProvider.java b/jfleet-core/src/test/java/org/jfleet/parameterized/DatabaseArgumentProvider.java index 316191c..714aeb0 100644 --- a/jfleet-core/src/test/java/org/jfleet/parameterized/DatabaseArgumentProvider.java +++ b/jfleet-core/src/test/java/org/jfleet/parameterized/DatabaseArgumentProvider.java @@ -15,18 +15,11 @@ */ package org.jfleet.parameterized; -import static org.jfleet.parameterized.Databases.JdbcMySql; -import static org.jfleet.parameterized.Databases.JdbcPosgres; -import static org.jfleet.parameterized.Databases.MySql; -import static org.jfleet.parameterized.Databases.Postgres; -import static org.jfleet.parameterized.IsMySql5Condition.isMySql5Present; - import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.Map; import java.util.stream.Stream; import org.jfleet.util.Database; +import org.jfleet.util.DatabaseContainers; import org.jfleet.util.JdbcMysqlDatabase; import org.jfleet.util.JdbcPostgresDatabase; import org.jfleet.util.MySqlDatabase; @@ -34,46 +27,10 @@ import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.ArgumentsProvider; -import org.testcontainers.containers.GenericContainer; -import org.testcontainers.containers.MySQLContainer; -import org.testcontainers.containers.PostgreSQLContainer; +import org.testcontainers.containers.JdbcDatabaseContainer; public class DatabaseArgumentProvider implements ArgumentsProvider { - private static final String MYSQL_5_VERSION = "mysql:5.7.34"; - private static final String MYSQL_8_VERSION = "mysql:8.0.39"; - - private static final PostgreSQLContainer postgreSqlContainer = new PostgreSQLContainer<>("postgres:12-alpine") - .withUsername("test") - .withPassword("test") - .withPassword("test") - .withDatabaseName("postgresdb") - .withUrlParam("reWriteBatchedInserts", "true"); - - private static final MySQLContainer mySqlContainer = new MySQLContainer<>(getMysqlVersion()) - .withUsername("test") - .withPassword("test") - .withDatabaseName("testdb") - .withUrlParam("useSSL","false") - .withUrlParam("allowPublicKeyRetrieval", "true") - .withUrlParam("useUnicode","true") - .withUrlParam("characterEncoding", "utf-8") - .withUrlParam("allowLoadLocalInfile", "true"); - - private static String getMysqlVersion() { - return isMySql5Present() ? MYSQL_5_VERSION: MYSQL_8_VERSION; - } - - private static final Map> map = new HashMap<>(); - - static { - map.put(Postgres, postgreSqlContainer); - map.put(JdbcPosgres, postgreSqlContainer); - map.put(MySql, mySqlContainer); - map.put(JdbcMySql, mySqlContainer); - map.values().parallelStream().forEach(GenericContainer::start); - } - @Override public Stream provideArguments(ExtensionContext context) { Method testMethod = context.getTestMethod().get(); @@ -92,15 +49,16 @@ private Stream getDatabases(Databases[] dbs) { } public static Database getDatabaseContainer(Databases enumValue) { + JdbcDatabaseContainer container = DatabaseContainers.getContainer(enumValue); switch (enumValue) { case JdbcMySql: - return new JdbcMysqlDatabase(mySqlContainer); + return new JdbcMysqlDatabase(container); case JdbcPosgres: - return new JdbcPostgresDatabase(postgreSqlContainer); + return new JdbcPostgresDatabase(container); case MySql: - return new MySqlDatabase(mySqlContainer); + return new MySqlDatabase(container); case Postgres: - return new PostgresDatabase(postgreSqlContainer); + return new PostgresDatabase(container); } return null; diff --git a/jfleet-core/src/test/java/org/jfleet/shared/TypePersistenceTest.java b/jfleet-core/src/test/java/org/jfleet/shared/TypePersistenceTest.java index c405427..c2e318f 100644 --- a/jfleet-core/src/test/java/org/jfleet/shared/TypePersistenceTest.java +++ b/jfleet-core/src/test/java/org/jfleet/shared/TypePersistenceTest.java @@ -26,6 +26,8 @@ import java.util.stream.Stream; import org.jfleet.BulkInsert; +import org.jfleet.parameterized.DBs; +import org.jfleet.parameterized.Databases; import org.jfleet.parameterized.TestDBs; import org.jfleet.shared.entities.EntityWithBasicTypes; import org.jfleet.shared.entities.EnumForTest; diff --git a/jfleet-core/src/test/java/org/jfleet/util/DatabaseContainers.java b/jfleet-core/src/test/java/org/jfleet/util/DatabaseContainers.java new file mode 100644 index 0000000..8e84f70 --- /dev/null +++ b/jfleet-core/src/test/java/org/jfleet/util/DatabaseContainers.java @@ -0,0 +1,65 @@ +package org.jfleet.util; + +import static org.jfleet.parameterized.Databases.JdbcMySql; +import static org.jfleet.parameterized.Databases.JdbcPosgres; +import static org.jfleet.parameterized.Databases.MySql; +import static org.jfleet.parameterized.Databases.Postgres; +import static org.jfleet.parameterized.IsMySql5Condition.isMySql5Present; + +import java.util.HashMap; +import java.util.Map; + +import org.jfleet.parameterized.Databases; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.JdbcDatabaseContainer; +import org.testcontainers.containers.MySQLContainer; +import org.testcontainers.containers.PostgreSQLContainer; + +public class DatabaseContainers { + + private static final String MYSQL_5_VERSION = "mysql:5.7.34"; + private static final String MYSQL_8_VERSION = "mysql:8.0.39"; + private static final String POSTGRES_12_VERSION = "postgres:12-alpine"; + + private static final Map> map = new HashMap<>(); + static { + map.put(Postgres, createPostgresContainer()); + map.put(JdbcPosgres, createPostgresContainer()); + map.put(MySql, createMySqlContainer()); + map.put(JdbcMySql, createMySqlContainer()); + + // Start all containers sequentially or some will not be properly initialized + map.values().forEach(GenericContainer::start); + } + + public static JdbcDatabaseContainer getContainer(Databases database) { + return map.get(database); + } + + private static PostgreSQLContainer createPostgresContainer() { + return new PostgreSQLContainer<>(POSTGRES_12_VERSION) + .withUsername("test") + .withPassword("test") + .withPassword("test") + .withDatabaseName("postgresdb") + .withUrlParam("reWriteBatchedInserts", "true"); + } + + private static MySQLContainer createMySqlContainer() { + return new MySQLContainer<>(getMysqlVersion()) + .withConfigurationOverride("my-sql-config") + .withUsername("test") + .withPassword("test") + .withDatabaseName("testdb") + .withUrlParam("useSSL", "false") + .withUrlParam("allowPublicKeyRetrieval", "true") + .withUrlParam("useUnicode", "true") + .withUrlParam("characterEncoding", "utf-8") + .withUrlParam("allowLoadLocalInfile", "true"); + } + + private static String getMysqlVersion() { + return isMySql5Present() ? MYSQL_5_VERSION: MYSQL_8_VERSION; + } + +} diff --git a/jfleet-core/src/test/java/org/jfleet/util/JdbcMysqlDatabase.java b/jfleet-core/src/test/java/org/jfleet/util/JdbcMysqlDatabase.java index 218dfcf..4dd6817 100644 --- a/jfleet-core/src/test/java/org/jfleet/util/JdbcMysqlDatabase.java +++ b/jfleet-core/src/test/java/org/jfleet/util/JdbcMysqlDatabase.java @@ -15,11 +15,11 @@ */ package org.jfleet.util; -import org.testcontainers.containers.MySQLContainer; +import org.testcontainers.containers.JdbcDatabaseContainer; public class JdbcMysqlDatabase extends JdbcDatabase { - public JdbcMysqlDatabase(MySQLContainer container) { + public JdbcMysqlDatabase(JdbcDatabaseContainer container) { super(container); } diff --git a/jfleet-core/src/test/java/org/jfleet/util/JdbcPostgresDatabase.java b/jfleet-core/src/test/java/org/jfleet/util/JdbcPostgresDatabase.java index aa2d3d0..632f1fe 100644 --- a/jfleet-core/src/test/java/org/jfleet/util/JdbcPostgresDatabase.java +++ b/jfleet-core/src/test/java/org/jfleet/util/JdbcPostgresDatabase.java @@ -15,11 +15,11 @@ */ package org.jfleet.util; -import org.testcontainers.containers.PostgreSQLContainer; +import org.testcontainers.containers.JdbcDatabaseContainer; public class JdbcPostgresDatabase extends JdbcDatabase { - public JdbcPostgresDatabase(PostgreSQLContainer postgresContainer) { + public JdbcPostgresDatabase(JdbcDatabaseContainer postgresContainer) { super(postgresContainer); } diff --git a/jfleet-core/src/test/java/org/jfleet/util/MySqlDatabase.java b/jfleet-core/src/test/java/org/jfleet/util/MySqlDatabase.java index 1dd0c9e..9469b10 100644 --- a/jfleet-core/src/test/java/org/jfleet/util/MySqlDatabase.java +++ b/jfleet-core/src/test/java/org/jfleet/util/MySqlDatabase.java @@ -17,11 +17,11 @@ import org.jfleet.BulkInsert; import org.jfleet.mysql.LoadDataBulkInsert; -import org.testcontainers.containers.MySQLContainer; +import org.testcontainers.containers.JdbcDatabaseContainer; public class MySqlDatabase extends Database { - public MySqlDatabase(MySQLContainer mySQLContainer) { + public MySqlDatabase(JdbcDatabaseContainer mySQLContainer) { super(mySQLContainer); } diff --git a/jfleet-core/src/test/java/org/jfleet/util/PostgresDatabase.java b/jfleet-core/src/test/java/org/jfleet/util/PostgresDatabase.java index 42ef4e9..d56712c 100644 --- a/jfleet-core/src/test/java/org/jfleet/util/PostgresDatabase.java +++ b/jfleet-core/src/test/java/org/jfleet/util/PostgresDatabase.java @@ -17,11 +17,11 @@ import org.jfleet.BulkInsert; import org.jfleet.postgres.PgCopyBulkInsert; -import org.testcontainers.containers.PostgreSQLContainer; +import org.testcontainers.containers.JdbcDatabaseContainer; public class PostgresDatabase extends Database { - public PostgresDatabase(PostgreSQLContainer postgresContainer) { + public PostgresDatabase(JdbcDatabaseContainer postgresContainer) { super(postgresContainer); } diff --git a/jfleet-core/src/test/resources/my-sql-config/my.cnf b/jfleet-core/src/test/resources/my-sql-config/my.cnf new file mode 100644 index 0000000..dcb67a1 --- /dev/null +++ b/jfleet-core/src/test/resources/my-sql-config/my.cnf @@ -0,0 +1,2 @@ +[mysqld] +local-infile=1 \ No newline at end of file From 6026b7896144e52da7d856152a5c9e3396d6e383 Mon Sep 17 00:00:00 2001 From: Alvaro Date: Wed, 16 Oct 2024 13:48:24 +0200 Subject: [PATCH 07/10] modify the readme --- README.md | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index d28ba2b..8ac75a6 100644 --- a/README.md +++ b/README.md @@ -213,17 +213,12 @@ Any database engine with a standard JDBC driver should be used with the `JdbcBul ## Running the tests -Tests need a MySQL and a PostgreSQL instances running in localhost. A database called `testdb` must exist and an user `test` with password `test` must have `CREATE TABLE` and `DROP TABLE` permissions. +The tests utilize [TestContainers](https://testcontainers.com/) to create lightweight, temporary instances of common databases. +TestContainers automatically handles downloading the required database images and managing their lifecycle. +During test execution, two databases—MySQL and PostgreSQL—are instantiated and will automatically shut down once the tests complete. +For details on how these containers are configured, refer to the `DatabaseContainers` class in the `jfleet-core` module. -You can modify this settings changing locally [mysql-test.properties](https://github.com/jerolba/jfleet/blob/master/jfleet-core/src/test/resources/mysql-test.properties) and [postgres-test.properties](https://github.com/jerolba/jfleet/blob/master/jfleet-core/src/test/resources/postgres-test.properties) files. - -If you have docker installed, you can launch them using the following commands: - -```bash -docker run --name mysql-jfleet -e MYSQL_ROOT_PASSWORD=jfleet -e MYSQL_USER=test -e MYSQL_PASSWORD=test -e MYSQL_DATABASE=testdb -p 3306:3306 -d mysql:5.7 - -docker run --name postgres-jfleet -e POSTGRES_USER=test -e POSTGRES_PASSWORD=test -e POSTGRES_DB=testdb -p 5432:5432 -d postgres:12.5 -``` +To run the tests locally, ensure that Docker or a compatible Docker-API runtime is installed. For more information on configuring TestContainers, please consult the [System Requirements guide](https://java.testcontainers.org/supported_docker_environment/). To execute all test you must execute the command: From e07110f01b2de6e9abd0480672b049eae68e7aca Mon Sep 17 00:00:00 2001 From: Alvaro Date: Wed, 16 Oct 2024 13:51:09 +0200 Subject: [PATCH 08/10] fix docu --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 8ac75a6..e62f057 100644 --- a/README.md +++ b/README.md @@ -215,6 +215,7 @@ Any database engine with a standard JDBC driver should be used with the `JdbcBul The tests utilize [TestContainers](https://testcontainers.com/) to create lightweight, temporary instances of common databases. TestContainers automatically handles downloading the required database images and managing their lifecycle. + During test execution, two databases—MySQL and PostgreSQL—are instantiated and will automatically shut down once the tests complete. For details on how these containers are configured, refer to the `DatabaseContainers` class in the `jfleet-core` module. From 334b74f0370c385ccb466c11f8bfc1c836a70481 Mon Sep 17 00:00:00 2001 From: Alvaro Date: Thu, 17 Oct 2024 17:12:13 +0200 Subject: [PATCH 09/10] change circleci --- .circleci/config.yml | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 6ecdbb6..eb55438 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,16 +3,6 @@ jobs: build: docker: - image: eclipse-temurin:17.0.10_7-jdk-jammy - - image: circleci/mysql:5.7 - environment: - - MYSQL_USER=test - - MYSQL_PASSWORD=test - - MYSQL_DATABASE=testdb - - image: circleci/postgres:12.5 - environment: - - POSTGRES_USER=test - - POSTGRES_PASSWORD=test - - POSTGRES_DB=testdb working_directory: ~/repo @@ -33,18 +23,6 @@ jobs: build-latest: docker: - image: eclipse-temurin:17.0.10_7-jdk-jammy - - image: circleci/mysql:8.0 - environment: - - MYSQL_USER=test - - MYSQL_PASSWORD=test - - MYSQL_DATABASE=testdb - #In MySql 8 local-infile is not active by default - command: mysqld --local-infile=1 - - image: circleci/postgres:13.1 - environment: - - POSTGRES_USER=test - - POSTGRES_PASSWORD=test - - POSTGRES_DB=testdb working_directory: ~/repo From 636767c98ef56298520f9431a39ec41318de967b Mon Sep 17 00:00:00 2001 From: Alvaro Date: Mon, 21 Oct 2024 05:41:51 +0200 Subject: [PATCH 10/10] created DatabaseContainer class to manually call database instances --- .../jfleet/mysql/MySqlReservedWordTest.java | 6 ++-- .../mysql/MySqlTransactionPolicyTest.java | 6 ++-- .../org/jfleet/mysql/error/LockRetryTest.java | 6 ++-- .../jfleet/mysql/manual/ConnectionTest.java | 6 ++-- .../java/org/jfleet/mysql/manual/IdsTest.java | 6 ++-- .../DatabaseArgumentProvider.java | 25 +---------------- .../parameterized/DatabaseProvider.java | 28 +++++++++++++++++++ .../PostgresTransactionPolicyTest.java | 6 ++-- .../postgres/manual/ConnectionTest.java | 6 ++-- 9 files changed, 50 insertions(+), 45 deletions(-) create mode 100644 jfleet-core/src/test/java/org/jfleet/parameterized/DatabaseProvider.java diff --git a/jfleet-core/src/test/java/org/jfleet/mysql/MySqlReservedWordTest.java b/jfleet-core/src/test/java/org/jfleet/mysql/MySqlReservedWordTest.java index 13d4f5d..9a69fdc 100644 --- a/jfleet-core/src/test/java/org/jfleet/mysql/MySqlReservedWordTest.java +++ b/jfleet-core/src/test/java/org/jfleet/mysql/MySqlReservedWordTest.java @@ -30,14 +30,14 @@ import javax.persistence.Table; import org.jfleet.BulkInsert; -import org.jfleet.parameterized.DatabaseArgumentProvider; -import org.jfleet.util.MySqlDatabase; +import org.jfleet.parameterized.DatabaseProvider; +import org.jfleet.util.Database; import org.jfleet.util.SqlUtil; import org.junit.jupiter.api.Test; public class MySqlReservedWordTest { - private final MySqlDatabase database = (MySqlDatabase) DatabaseArgumentProvider.getDatabaseContainer(MySql); + private final Database database = DatabaseProvider.getDatabase(MySql); @Entity @Table(name = "\"select\"") diff --git a/jfleet-core/src/test/java/org/jfleet/mysql/MySqlTransactionPolicyTest.java b/jfleet-core/src/test/java/org/jfleet/mysql/MySqlTransactionPolicyTest.java index ff696d6..092a9ba 100644 --- a/jfleet-core/src/test/java/org/jfleet/mysql/MySqlTransactionPolicyTest.java +++ b/jfleet-core/src/test/java/org/jfleet/mysql/MySqlTransactionPolicyTest.java @@ -33,8 +33,8 @@ import org.jfleet.BulkInsert; import org.jfleet.JFleetException; import org.jfleet.entities.Employee; -import org.jfleet.parameterized.DatabaseArgumentProvider; -import org.jfleet.util.MySqlDatabase; +import org.jfleet.parameterized.DatabaseProvider; +import org.jfleet.util.Database; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.slf4j.Logger; @@ -45,7 +45,7 @@ public class MySqlTransactionPolicyTest { private static Logger logger = LoggerFactory.getLogger(MySqlTransactionPolicyTest.class); private static final int VERY_LOW_SIZE_TO_FREQUENT_LOAD_DATA = 10; - private final MySqlDatabase database = (MySqlDatabase) DatabaseArgumentProvider.getDatabaseContainer(MySql); + private final Database database = DatabaseProvider.getDatabase(MySql); @BeforeEach public void setup() throws SQLException, IOException { diff --git a/jfleet-core/src/test/java/org/jfleet/mysql/error/LockRetryTest.java b/jfleet-core/src/test/java/org/jfleet/mysql/error/LockRetryTest.java index 51f20b8..f98b3e5 100644 --- a/jfleet-core/src/test/java/org/jfleet/mysql/error/LockRetryTest.java +++ b/jfleet-core/src/test/java/org/jfleet/mysql/error/LockRetryTest.java @@ -34,8 +34,8 @@ import org.jfleet.entities.Employee; import org.jfleet.mysql.LoadDataBulkInsert; import org.jfleet.mysql.LoadDataConfiguration; -import org.jfleet.parameterized.DatabaseArgumentProvider; -import org.jfleet.util.MySqlDatabase; +import org.jfleet.parameterized.DatabaseProvider; +import org.jfleet.util.Database; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.slf4j.Logger; @@ -45,7 +45,7 @@ public class LockRetryTest { private static Logger logger = LoggerFactory.getLogger(LockRetryTest.class); - private final MySqlDatabase database = (MySqlDatabase) DatabaseArgumentProvider.getDatabaseContainer(MySql); + private final Database database = DatabaseProvider.getDatabase(MySql); private static City city1 = new City(1, "Madrid"); private static City city2 = new City(2, "Barcelona"); diff --git a/jfleet-core/src/test/java/org/jfleet/mysql/manual/ConnectionTest.java b/jfleet-core/src/test/java/org/jfleet/mysql/manual/ConnectionTest.java index 831503d..5c19b66 100644 --- a/jfleet-core/src/test/java/org/jfleet/mysql/manual/ConnectionTest.java +++ b/jfleet-core/src/test/java/org/jfleet/mysql/manual/ConnectionTest.java @@ -26,9 +26,9 @@ import java.sql.ResultSet; import java.sql.SQLException; -import org.jfleet.parameterized.DatabaseArgumentProvider; +import org.jfleet.parameterized.DatabaseProvider; import org.jfleet.parameterized.IsMySql5Present; -import org.jfleet.util.MySqlDatabase; +import org.jfleet.util.Database; import org.junit.jupiter.api.Test; import com.mysql.jdbc.Connection; @@ -36,7 +36,7 @@ public class ConnectionTest { - private final MySqlDatabase database = (MySqlDatabase) DatabaseArgumentProvider.getDatabaseContainer(MySql); + private final Database database = DatabaseProvider.getDatabase(MySql); @Test public void canConnectToTestDB() throws SQLException, IOException { diff --git a/jfleet-core/src/test/java/org/jfleet/mysql/manual/IdsTest.java b/jfleet-core/src/test/java/org/jfleet/mysql/manual/IdsTest.java index 37bebe5..2702025 100644 --- a/jfleet-core/src/test/java/org/jfleet/mysql/manual/IdsTest.java +++ b/jfleet-core/src/test/java/org/jfleet/mysql/manual/IdsTest.java @@ -25,9 +25,9 @@ import java.sql.ResultSet; import java.sql.SQLException; -import org.jfleet.parameterized.DatabaseArgumentProvider; +import org.jfleet.parameterized.DatabaseProvider; import org.jfleet.parameterized.IsMySql5Present; -import org.jfleet.util.MySqlDatabase; +import org.jfleet.util.Database; import org.junit.jupiter.api.Test; import com.mysql.jdbc.Connection; @@ -36,7 +36,7 @@ @IsMySql5Present public class IdsTest { - private final MySqlDatabase database = (MySqlDatabase) DatabaseArgumentProvider.getDatabaseContainer(MySql); + private final Database database = DatabaseProvider.getDatabase(MySql); @Test public void canExecuteLoadDataWithAutoIncrement() throws SQLException, IOException { diff --git a/jfleet-core/src/test/java/org/jfleet/parameterized/DatabaseArgumentProvider.java b/jfleet-core/src/test/java/org/jfleet/parameterized/DatabaseArgumentProvider.java index 714aeb0..6dddbda 100644 --- a/jfleet-core/src/test/java/org/jfleet/parameterized/DatabaseArgumentProvider.java +++ b/jfleet-core/src/test/java/org/jfleet/parameterized/DatabaseArgumentProvider.java @@ -18,16 +18,9 @@ import java.lang.reflect.Method; import java.util.stream.Stream; -import org.jfleet.util.Database; -import org.jfleet.util.DatabaseContainers; -import org.jfleet.util.JdbcMysqlDatabase; -import org.jfleet.util.JdbcPostgresDatabase; -import org.jfleet.util.MySqlDatabase; -import org.jfleet.util.PostgresDatabase; import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.ArgumentsProvider; -import org.testcontainers.containers.JdbcDatabaseContainer; public class DatabaseArgumentProvider implements ArgumentsProvider { @@ -45,23 +38,7 @@ public Stream provideArguments(ExtensionContext context) { } private Stream getDatabases(Databases[] dbs) { - return Stream.of(dbs).map(DatabaseArgumentProvider::getDatabaseContainer).map(Arguments::of); - } - - public static Database getDatabaseContainer(Databases enumValue) { - JdbcDatabaseContainer container = DatabaseContainers.getContainer(enumValue); - switch (enumValue) { - case JdbcMySql: - return new JdbcMysqlDatabase(container); - case JdbcPosgres: - return new JdbcPostgresDatabase(container); - case MySql: - return new MySqlDatabase(container); - case Postgres: - return new PostgresDatabase(container); - } - - return null; + return Stream.of(dbs).map(DatabaseProvider::getDatabase).map(Arguments::of); } } diff --git a/jfleet-core/src/test/java/org/jfleet/parameterized/DatabaseProvider.java b/jfleet-core/src/test/java/org/jfleet/parameterized/DatabaseProvider.java new file mode 100644 index 0000000..2bcc84b --- /dev/null +++ b/jfleet-core/src/test/java/org/jfleet/parameterized/DatabaseProvider.java @@ -0,0 +1,28 @@ +package org.jfleet.parameterized; + +import org.jfleet.util.Database; +import org.jfleet.util.DatabaseContainers; +import org.jfleet.util.JdbcMysqlDatabase; +import org.jfleet.util.JdbcPostgresDatabase; +import org.jfleet.util.MySqlDatabase; +import org.jfleet.util.PostgresDatabase; +import org.testcontainers.containers.JdbcDatabaseContainer; + +public class DatabaseProvider { + + public static Database getDatabase(Databases enumValue) { + JdbcDatabaseContainer container = DatabaseContainers.getContainer(enumValue); + switch (enumValue) { + case JdbcMySql: + return new JdbcMysqlDatabase(container); + case JdbcPosgres: + return new JdbcPostgresDatabase(container); + case MySql: + return new MySqlDatabase(container); + case Postgres: + return new PostgresDatabase(container); + } + + return null; + } +} diff --git a/jfleet-core/src/test/java/org/jfleet/postgres/PostgresTransactionPolicyTest.java b/jfleet-core/src/test/java/org/jfleet/postgres/PostgresTransactionPolicyTest.java index 6b39666..68c4f53 100644 --- a/jfleet-core/src/test/java/org/jfleet/postgres/PostgresTransactionPolicyTest.java +++ b/jfleet-core/src/test/java/org/jfleet/postgres/PostgresTransactionPolicyTest.java @@ -30,8 +30,8 @@ import org.jfleet.BulkInsert; import org.jfleet.entities.Employee; -import org.jfleet.parameterized.DatabaseArgumentProvider; -import org.jfleet.util.PostgresDatabase; +import org.jfleet.parameterized.DatabaseProvider; +import org.jfleet.util.Database; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.slf4j.Logger; @@ -42,7 +42,7 @@ public class PostgresTransactionPolicyTest { private static final Logger logger = LoggerFactory.getLogger(PostgresTransactionPolicyTest.class); private static final int VERY_LOW_SIZE_TO_FREQUENT_LOAD_DATA = 10; - private final PostgresDatabase database = (PostgresDatabase) DatabaseArgumentProvider.getDatabaseContainer(Postgres); + private final Database database = DatabaseProvider.getDatabase(Postgres); @BeforeEach public void setup() throws SQLException, IOException { diff --git a/jfleet-core/src/test/java/org/jfleet/postgres/manual/ConnectionTest.java b/jfleet-core/src/test/java/org/jfleet/postgres/manual/ConnectionTest.java index 9afe2ba..26e9fe7 100644 --- a/jfleet-core/src/test/java/org/jfleet/postgres/manual/ConnectionTest.java +++ b/jfleet-core/src/test/java/org/jfleet/postgres/manual/ConnectionTest.java @@ -29,8 +29,8 @@ import java.sql.Statement; import org.jfleet.common.StringBuilderReader; -import org.jfleet.parameterized.DatabaseArgumentProvider; -import org.jfleet.util.PostgresDatabase; +import org.jfleet.parameterized.DatabaseProvider; +import org.jfleet.util.Database; import org.junit.jupiter.api.Test; import org.postgresql.copy.CopyManager; import org.postgresql.jdbc.PgConnection; @@ -38,7 +38,7 @@ public class ConnectionTest { - private final PostgresDatabase database = (PostgresDatabase) DatabaseArgumentProvider.getDatabaseContainer(Postgres); + private final Database database = DatabaseProvider.getDatabase(Postgres); @Test public void canConnectToTestDB() throws SQLException, IOException {