-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for enabled/active in Flyway extension
(cherry picked from commit 88e50c2)
Showing
4 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
.../io/quarkus/flyway/test/FlywayExtensionBaselineOnMigrateNamedDataSourcesInactiveTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...s/flyway/deployment/src/test/java/io/quarkus/flyway/test/FlywayExtensionDisabledTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> 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()); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...y/deployment/src/test/resources/baseline-on-migrate-named-datasources-inactive.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
8 changes: 8 additions & 0 deletions
8
extensions/flyway/deployment/src/test/resources/disabled-config.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |