Skip to content

Commit

Permalink
Add tests for enabled/active in Flyway extension
Browse files Browse the repository at this point in the history
  • Loading branch information
gsmet committed Sep 19, 2023
1 parent e0f9964 commit 88e50c2
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 0 deletions.
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);
}
}
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());
}
}
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
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

0 comments on commit 88e50c2

Please sign in to comment.