From 0e41d622ada85b73aa2220cf162f50ecba1e5db9 Mon Sep 17 00:00:00 2001 From: Gaetano Piazzolla Date: Mon, 25 Dec 2023 17:10:07 +0100 Subject: [PATCH] JAVA-28932 Upgrade flyway-repair to Spring boot3 migration --- persistence-modules/flyway-repair/pom.xml | 9 +++-- .../test/java/FlywayAppIntegrationTest.java | 38 +++++++++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 persistence-modules/flyway-repair/src/test/java/FlywayAppIntegrationTest.java diff --git a/persistence-modules/flyway-repair/pom.xml b/persistence-modules/flyway-repair/pom.xml index 2cae31c8a6..f7fa4f4d5e 100644 --- a/persistence-modules/flyway-repair/pom.xml +++ b/persistence-modules/flyway-repair/pom.xml @@ -10,9 +10,9 @@ com.baeldung - parent-boot-2 + parent-boot-3 0.0.1-SNAPSHOT - ../../parent-boot-2 + ../../parent-boot-3 @@ -74,7 +74,10 @@ src/main/resources/application-${spring-boot.run.profiles}.properties - 10.2.0 + 10.4.0 + 17 + 17 + 17 \ No newline at end of file diff --git a/persistence-modules/flyway-repair/src/test/java/FlywayAppIntegrationTest.java b/persistence-modules/flyway-repair/src/test/java/FlywayAppIntegrationTest.java new file mode 100644 index 0000000000..e2280ac2e4 --- /dev/null +++ b/persistence-modules/flyway-repair/src/test/java/FlywayAppIntegrationTest.java @@ -0,0 +1,38 @@ +import java.sql.DatabaseMetaData; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Set; + +import javax.sql.DataSource; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +import com.baeldung.flywaycallbacks.FlywayApplication; + +@RunWith(SpringRunner.class) +@ContextConfiguration(classes = { FlywayApplication.class }) +public class FlywayAppIntegrationTest { + + @Autowired + private DataSource dataSource; + + @Test + public void testAllMigrationsExecuted() throws SQLException { + DatabaseMetaData metadata = dataSource.getConnection() + .getMetaData(); + ResultSet resultSet = metadata.getTables(null, null, null, new String[] { "TABLE" }); + Set tables = Set.of("TABLE_ONE", "TABLE_TWO", "TABLE_THREE", "TABLE_FOUR"); + int migrations = 0; + while (resultSet.next()) { + if (tables.contains(resultSet.getString("TABLE_NAME"))) { + migrations++; + } + } + Assert.assertEquals(migrations, 4); + } +}