diff --git a/extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionBaselineOnMigrateNamedDataSourcesInactiveTest.java b/extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionBaselineOnMigrateNamedDataSourcesInactiveTest.java new file mode 100644 index 0000000000000..f4b5fb39d1c18 --- /dev/null +++ b/extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionBaselineOnMigrateNamedDataSourcesInactiveTest.java @@ -0,0 +1,70 @@ +package io.quarkus.flyway.test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import jakarta.inject.Inject; + +import org.flywaydb.core.Flyway; +import org.flywaydb.core.api.MigrationInfo; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.flyway.FlywayDataSource; +import io.quarkus.test.QuarkusUnitTest; + +public class FlywayExtensionBaselineOnMigrateNamedDataSourcesInactiveTest { + + @Inject + @FlywayDataSource("users") + Flyway flywayUsers; + + @Inject + @FlywayDataSource("laptops") + Flyway flywayLaptops; + + static final FlywayH2TestCustomizer customizerUsers = FlywayH2TestCustomizer + .withDbName("quarkus-flyway-baseline-on-named-ds-users") + .withPort(11302) + .withInitSqlFile("src/test/resources/h2-init-data.sql"); + + static final FlywayH2TestCustomizer customizerLaptops = FlywayH2TestCustomizer + .withDbName("quarkus-flyway-baseline-on-named-ds-laptops") + .withPort(11303) + .withInitSqlFile("src/test/resources/h2-init-data.sql"); + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + .setBeforeAllCustomizer(new Runnable() { + @Override + public void run() { + customizerUsers.startH2(); + customizerLaptops.startH2(); + } + }) + .setAfterAllCustomizer(new Runnable() { + @Override + public void run() { + customizerUsers.stopH2(); + customizerLaptops.stopH2(); + } + }) + .withApplicationRoot((jar) -> jar + .addClass(FlywayH2TestCustomizer.class) + .addAsResource("baseline-on-migrate-named-datasources-inactive.properties", "application.properties")); + + @Test + @DisplayName("Create history table correctly") + public void testFlywayInitialBaselineInfo() { + MigrationInfo baselineInfo = flywayUsers.info().applied()[0]; + + assertEquals("0.0.1", baselineInfo.getVersion().getVersion()); + assertEquals("Initial description for test", baselineInfo.getDescription()); + } + + @Test + @DisplayName("History table not created if inactive") + public void testFlywayInitialBaselineInfoInactive() { + assertEquals(0, flywayLaptops.info().applied().length); + } +} diff --git a/extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionDisabledTest.java b/extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionDisabledTest.java new file mode 100644 index 0000000000000..c5fa111d1074f --- /dev/null +++ b/extensions/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionDisabledTest.java @@ -0,0 +1,31 @@ +package io.quarkus.flyway.test; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import jakarta.enterprise.inject.Instance; +import jakarta.inject.Inject; + +import org.flywaydb.core.Flyway; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusUnitTest; + +public class FlywayExtensionDisabledTest { + + @Inject + Instance flyway; + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + .withApplicationRoot((jar) -> jar + .addAsResource("db/migration/V1.0.0__Quarkus.sql") + .addAsResource("disabled-config.properties", "application.properties")); + + @Test + @DisplayName("No Flyway instance available if disabled") + public void testFlywayConfigInjection() { + assertTrue(flyway.isUnsatisfied()); + } +} diff --git a/extensions/flyway/deployment/src/test/resources/baseline-on-migrate-named-datasources-inactive.properties b/extensions/flyway/deployment/src/test/resources/baseline-on-migrate-named-datasources-inactive.properties new file mode 100644 index 0000000000000..d816d7b5a8451 --- /dev/null +++ b/extensions/flyway/deployment/src/test/resources/baseline-on-migrate-named-datasources-inactive.properties @@ -0,0 +1,24 @@ +quarkus.datasource.users.db-kind=h2 +quarkus.datasource.users.username=sa +quarkus.datasource.users.password=sa +quarkus.datasource.users.jdbc.url=jdbc:h2:tcp://localhost:11302/mem:quarkus-flyway-baseline-on-named-ds-users + +# Flyway config properties +quarkus.flyway.users.migrate-at-start=true +quarkus.flyway.users.table=test_flyway_history +quarkus.flyway.users.baseline-on-migrate=true +quarkus.flyway.users.baseline-version=0.0.1 +quarkus.flyway.users.baseline-description=Initial description for test + +quarkus.datasource.laptops.db-kind=h2 +quarkus.datasource.laptops.username=sa +quarkus.datasource.laptops.password=sa +quarkus.datasource.laptops.jdbc.url=jdbc:h2:tcp://localhost:11302/mem:quarkus-flyway-baseline-on-named-ds-laptops + +# Flyway config properties +quarkus.flyway.laptops.active=false +quarkus.flyway.laptops.migrate-at-start=true +quarkus.flyway.laptops.table=test_flyway_history +quarkus.flyway.laptops.baseline-on-migrate=true +quarkus.flyway.laptops.baseline-version=0.0.1 +quarkus.flyway.laptops.baseline-description=Initial description for test diff --git a/extensions/flyway/deployment/src/test/resources/disabled-config.properties b/extensions/flyway/deployment/src/test/resources/disabled-config.properties new file mode 100644 index 0000000000000..7bf03c9db53df --- /dev/null +++ b/extensions/flyway/deployment/src/test/resources/disabled-config.properties @@ -0,0 +1,8 @@ +quarkus.datasource.db-kind=h2 +quarkus.datasource.username=sa +quarkus.datasource.password=sa +quarkus.datasource.jdbc.url=jdbc:h2:tcp://localhost/mem:test-quarkus-migrate-at-start;DB_CLOSE_DELAY=-1 + +# Flyway config properties +quarkus.flyway.enabled=false +quarkus.flyway.migrate-at-start=true