FINERACT-1508: Liquibase test extension for Cucumber + Windows path shortening enabled for Cucumber
This commit is contained in:
committed by
Aleksandar Vidakovic
parent
17f521604d
commit
2d2192ca17
+98
-53
@@ -18,8 +18,13 @@
|
||||
*/
|
||||
package org.apache.fineract.infrastructure.core;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
@@ -48,81 +53,121 @@ public class LiquibaseStepDefinitions implements En {
|
||||
private ExtendedSpringLiquibase initialTenantLiquibase;
|
||||
private ExtendedSpringLiquibase tenantLiquibase;
|
||||
private FineractPlatformTenant defaultTenant;
|
||||
private DataSource defaultTenantDataSource;
|
||||
private DataSource tenantStoreDataSource;
|
||||
private TenantDatabaseUpgradeService tenantDatabaseUpgradeService;
|
||||
private List allTenants;
|
||||
private SchemaUpgradeNeededException result;
|
||||
private List<FineractPlatformTenant> allTenants;
|
||||
private SchemaUpgradeNeededException executionException;
|
||||
private DataSource defaultTenantDataSource;
|
||||
|
||||
public LiquibaseStepDefinitions() {
|
||||
Given("Liquibase is disabled with a default tenant", () -> {
|
||||
tenantDataSourceFactory = mock(TenantDataSourceFactory.class);
|
||||
tenantDetailsService = mock(TenantDetailsService.class);
|
||||
databaseStateVerifier = mock(TenantDatabaseStateVerifier.class);
|
||||
fineractProperties = mock(FineractProperties.class);
|
||||
|
||||
liquibaseFactory = mock(ExtendedSpringLiquibaseFactory.class);
|
||||
|
||||
defaultTenant = mock(FineractPlatformTenant.class);
|
||||
|
||||
allTenants = List.of(defaultTenant);
|
||||
|
||||
defaultTenantDataSource = mock(DataSource.class);
|
||||
|
||||
initialTenantLiquibase = mock(ExtendedSpringLiquibase.class);
|
||||
tenantLiquibase = mock(ExtendedSpringLiquibase.class);
|
||||
initialTenantStoreLiquibase = mock(ExtendedSpringLiquibase.class);
|
||||
tenantStoreLiquibase = mock(ExtendedSpringLiquibase.class);
|
||||
|
||||
given(databaseStateVerifier.isLiquibaseDisabled()).willReturn(true);
|
||||
given(fineractProperties.getTenant()).willReturn(new FineractProperties.FineractTenantProperties());
|
||||
given(liquibaseFactory.create(defaultTenantDataSource, "tenant_store_db", "initial_switch"))
|
||||
.willReturn(initialTenantStoreLiquibase);
|
||||
given(liquibaseFactory.create(defaultTenantDataSource, "tenant_store_db")).willReturn(tenantStoreLiquibase);
|
||||
|
||||
given(tenantDetailsService.findAllTenants()).willReturn(allTenants);
|
||||
given(tenantDataSourceFactory.create(defaultTenant)).willReturn(defaultTenantDataSource);
|
||||
given(liquibaseFactory.create(defaultTenantDataSource, "tenant_db", "initial_switch")).willReturn(initialTenantLiquibase);
|
||||
given(liquibaseFactory.create(defaultTenantDataSource, "tenant_db")).willReturn(tenantLiquibase);
|
||||
|
||||
tenantDatabaseUpgradeService = new TenantDatabaseUpgradeService(tenantDetailsService, defaultTenantDataSource,
|
||||
fineractProperties, databaseStateVerifier, liquibaseFactory, tenantDataSourceFactory);
|
||||
initializeLiquibase(false);
|
||||
});
|
||||
Given("Liquibase is enabled with a default tenant", () -> {
|
||||
initializeLiquibase(true);
|
||||
});
|
||||
Given("Liquibase runs the very first time for the tenant store", () -> {
|
||||
given(databaseStateVerifier.isFirstLiquibaseMigration(defaultTenantDataSource)).willReturn(true);
|
||||
given(databaseStateVerifier.isFirstLiquibaseMigration(tenantStoreDataSource)).willReturn(true);
|
||||
});
|
||||
Given("A previously Flyway migrated tenant store database", () -> {
|
||||
given(databaseStateVerifier.isFlywayPresent(defaultTenantDataSource)).willReturn(true);
|
||||
Given("A previously Flyway migrated tenant store database on the latest version", () -> {
|
||||
given(databaseStateVerifier.isFlywayPresent(tenantStoreDataSource)).willReturn(true);
|
||||
given(databaseStateVerifier.isTenantStoreOnLatestUpgradableVersion(tenantStoreDataSource)).willReturn(true);
|
||||
});
|
||||
Given("A previously Flyway migrated tenant store database on an earlier version than 1.6", () -> {
|
||||
given(databaseStateVerifier.isTenantStoreOnLatestUpgradableVersion(defaultTenantDataSource)).willReturn(false);
|
||||
Given("A previously Flyway migrated tenant store database on an earlier version", () -> {
|
||||
given(databaseStateVerifier.isFlywayPresent(tenantStoreDataSource)).willReturn(true);
|
||||
given(databaseStateVerifier.isTenantStoreOnLatestUpgradableVersion(tenantStoreDataSource)).willReturn(false);
|
||||
});
|
||||
Given("Liquibase runs the very first time for the default tenant", () -> {
|
||||
given(databaseStateVerifier.isFirstLiquibaseMigration(defaultTenantDataSource)).willReturn(true);
|
||||
});
|
||||
Given("A previously Flyway migrated default tenant database", () -> {
|
||||
Given("A previously Flyway migrated default tenant database on the latest version", () -> {
|
||||
given(databaseStateVerifier.isFlywayPresent(defaultTenantDataSource)).willReturn(true);
|
||||
given(databaseStateVerifier.isTenantOnLatestUpgradableVersion(defaultTenantDataSource)).willReturn(true);
|
||||
});
|
||||
Given("A previously Flyway migrated default tenant database on the 1.6 version", () -> {
|
||||
given(databaseStateVerifier.isTenantStoreOnLatestUpgradableVersion(defaultTenantDataSource)).willReturn(true);
|
||||
Given("A previously Flyway migrated default tenant database on an earlier version", () -> {
|
||||
given(databaseStateVerifier.isFlywayPresent(defaultTenantDataSource)).willReturn(true);
|
||||
given(databaseStateVerifier.isTenantOnLatestUpgradableVersion(defaultTenantDataSource)).willReturn(false);
|
||||
});
|
||||
|
||||
When("The database migration process is executed", () -> {
|
||||
// TODO: @galovics will not throw an exception if disabled = true... but if Liquibase is enabled then "Then"
|
||||
// section (as layed out in original tests) will fail
|
||||
// this.result = assertThrows(SchemaUpgradeNeededException.class, () ->
|
||||
// tenantDatabaseUpgradeService.afterPropertiesSet());
|
||||
try {
|
||||
tenantDatabaseUpgradeService.afterPropertiesSet();
|
||||
} catch (SchemaUpgradeNeededException e) {
|
||||
executionException = e;
|
||||
}
|
||||
});
|
||||
|
||||
tenantDatabaseUpgradeService.afterPropertiesSet();
|
||||
Then("The database migration did not do anything", () -> {
|
||||
verify(databaseStateVerifier).isLiquibaseDisabled();
|
||||
verifyNoMoreInteractions(databaseStateVerifier);
|
||||
verifyNoInteractions(tenantDetailsService, tenantStoreDataSource, fineractProperties, liquibaseFactory,
|
||||
tenantDataSourceFactory);
|
||||
});
|
||||
|
||||
Then("The tenant store upgrade fails with a schema upgrade needed", () -> {
|
||||
// TODO: @galovics verifications work dependent on Liquibase enabled or not... for what should we test?
|
||||
// assertThat(result).isNotNull();
|
||||
// verify(liquibaseFactory).create(eq(defaultTenantDataSource), any());
|
||||
|
||||
assertThat(executionException).isNotNull();
|
||||
verify(liquibaseFactory).create(eq(tenantStoreDataSource), any());
|
||||
verifyNoMoreInteractions(liquibaseFactory);
|
||||
verifyNoInteractions(initialTenantStoreLiquibase, tenantStoreLiquibase, initialTenantLiquibase, tenantLiquibase,
|
||||
defaultTenantDataSource);
|
||||
verifyNoInteractions(initialTenantStoreLiquibase, tenantStoreLiquibase, initialTenantLiquibase, tenantLiquibase);
|
||||
});
|
||||
|
||||
Then("The default tenant upgrade fails with a schema upgrade needed", () -> {
|
||||
assertThat(executionException).isNotNull();
|
||||
verify(liquibaseFactory, times(2)).create(eq(tenantStoreDataSource), any());
|
||||
verify(liquibaseFactory).create(eq(defaultTenantDataSource), any());
|
||||
verifyNoMoreInteractions(liquibaseFactory);
|
||||
verify(initialTenantStoreLiquibase).changeLogSync();
|
||||
verify(tenantStoreLiquibase).afterPropertiesSet();
|
||||
verifyNoInteractions(initialTenantLiquibase, tenantLiquibase);
|
||||
});
|
||||
|
||||
Then("The tenant store and the default tenant gets upgraded from scratch", () -> {
|
||||
verify(initialTenantStoreLiquibase).afterPropertiesSet();
|
||||
verify(tenantStoreLiquibase).afterPropertiesSet();
|
||||
verify(initialTenantLiquibase).afterPropertiesSet();
|
||||
verify(tenantLiquibase).afterPropertiesSet();
|
||||
});
|
||||
|
||||
Then("The tenant store and the default tenant gets synced and then upgraded", () -> {
|
||||
verify(initialTenantStoreLiquibase).changeLogSync();
|
||||
verify(tenantStoreLiquibase).afterPropertiesSet();
|
||||
verify(initialTenantLiquibase).changeLogSync();
|
||||
verify(tenantLiquibase).afterPropertiesSet();
|
||||
});
|
||||
}
|
||||
|
||||
private void initializeLiquibase(boolean liquibaseEnabled) {
|
||||
tenantDataSourceFactory = mock(TenantDataSourceFactory.class);
|
||||
tenantDetailsService = mock(TenantDetailsService.class);
|
||||
databaseStateVerifier = mock(TenantDatabaseStateVerifier.class);
|
||||
fineractProperties = mock(FineractProperties.class);
|
||||
|
||||
liquibaseFactory = mock(ExtendedSpringLiquibaseFactory.class);
|
||||
|
||||
defaultTenant = mock(FineractPlatformTenant.class);
|
||||
|
||||
allTenants = List.of(defaultTenant);
|
||||
|
||||
tenantStoreDataSource = mock(DataSource.class);
|
||||
|
||||
initialTenantLiquibase = mock(ExtendedSpringLiquibase.class);
|
||||
tenantLiquibase = mock(ExtendedSpringLiquibase.class);
|
||||
initialTenantStoreLiquibase = mock(ExtendedSpringLiquibase.class);
|
||||
tenantStoreLiquibase = mock(ExtendedSpringLiquibase.class);
|
||||
|
||||
defaultTenantDataSource = mock(DataSource.class);
|
||||
|
||||
given(databaseStateVerifier.isLiquibaseDisabled()).willReturn(!liquibaseEnabled);
|
||||
given(fineractProperties.getTenant()).willReturn(new FineractProperties.FineractTenantProperties());
|
||||
given(liquibaseFactory.create(tenantStoreDataSource, "tenant_store_db", "initial_switch")).willReturn(initialTenantStoreLiquibase);
|
||||
given(liquibaseFactory.create(tenantStoreDataSource, "tenant_store_db")).willReturn(tenantStoreLiquibase);
|
||||
|
||||
given(tenantDetailsService.findAllTenants()).willReturn(allTenants);
|
||||
given(tenantDataSourceFactory.create(defaultTenant)).willReturn(defaultTenantDataSource);
|
||||
given(liquibaseFactory.create(defaultTenantDataSource, "tenant_db", "initial_switch")).willReturn(initialTenantLiquibase);
|
||||
given(liquibaseFactory.create(defaultTenantDataSource, "tenant_db")).willReturn(tenantLiquibase);
|
||||
|
||||
tenantDatabaseUpgradeService = new TenantDatabaseUpgradeService(tenantDetailsService, tenantStoreDataSource, fineractProperties,
|
||||
databaseStateVerifier, liquibaseFactory, tenantDataSourceFactory);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user