Search in sources :

Example 1 with DatabaseTestHelper

use of uk.gov.pay.adminusers.utils.DatabaseTestHelper in project pay-adminusers by alphagov.

the class DaoTestBase method setup.

@BeforeAll
public static void setup() throws Exception {
    final Properties properties = new Properties();
    properties.put("javax.persistence.jdbc.driver", postgres.getDriverClass());
    properties.put("javax.persistence.jdbc.url", postgres.getConnectionUrl());
    properties.put("javax.persistence.jdbc.user", postgres.getUsername());
    properties.put("javax.persistence.jdbc.password", postgres.getPassword());
    JpaPersistModule jpaModule = new JpaPersistModule("AdminUsersUnit").properties(properties);
    databaseHelper = new DatabaseTestHelper(Jdbi.create(postgres.getConnectionUrl(), postgres.getUsername(), postgres.getPassword()));
    try (Connection connection = DriverManager.getConnection(postgres.getConnectionUrl(), postgres.getUsername(), postgres.getPassword())) {
        Liquibase migrator = new Liquibase("config/initial-db-state.xml", new ClassLoaderResourceAccessor(), new JdbcConnection(connection));
        Liquibase migrator2 = new Liquibase("migrations.xml", new ClassLoaderResourceAccessor(), new JdbcConnection(connection));
        migrator.update("");
        migrator2.update("");
    }
    env = GuicedTestEnvironment.from(jpaModule).start();
}
Also used : Liquibase(liquibase.Liquibase) DatabaseTestHelper(uk.gov.pay.adminusers.utils.DatabaseTestHelper) Connection(java.sql.Connection) JdbcConnection(liquibase.database.jvm.JdbcConnection) JdbcConnection(liquibase.database.jvm.JdbcConnection) Properties(java.util.Properties) ClassLoaderResourceAccessor(liquibase.resource.ClassLoaderResourceAccessor) JpaPersistModule(com.google.inject.persist.jpa.JpaPersistModule) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 2 with DatabaseTestHelper

use of uk.gov.pay.adminusers.utils.DatabaseTestHelper in project pay-adminusers by alphagov.

the class DropwizardAppWithPostgresExtension method beforeAll.

@Override
public void beforeAll(ExtensionContext context) throws Exception {
    LOGGER.info("Clearing database.");
    app.getApplication().run("db", "drop-all", "--confirm-delete-everything", configFilePath);
    app.getApplication().run("migrateToInitialDbState", configFilePath);
    doSecondaryDatabaseMigration();
    restoreDropwizardsLogging();
    DataSourceFactory dataSourceFactory = app.getConfiguration().getDataSourceFactory();
    databaseTestHelper = new DatabaseTestHelper(Jdbi.create(dataSourceFactory.getUrl(), dataSourceFactory.getUser(), dataSourceFactory.getPassword()));
}
Also used : DataSourceFactory(io.dropwizard.db.DataSourceFactory) DatabaseTestHelper(uk.gov.pay.adminusers.utils.DatabaseTestHelper) ConfigOverride(io.dropwizard.testing.ConfigOverride)

Aggregations

DatabaseTestHelper (uk.gov.pay.adminusers.utils.DatabaseTestHelper)2 JpaPersistModule (com.google.inject.persist.jpa.JpaPersistModule)1 DataSourceFactory (io.dropwizard.db.DataSourceFactory)1 ConfigOverride (io.dropwizard.testing.ConfigOverride)1 Connection (java.sql.Connection)1 Properties (java.util.Properties)1 Liquibase (liquibase.Liquibase)1 JdbcConnection (liquibase.database.jvm.JdbcConnection)1 ClassLoaderResourceAccessor (liquibase.resource.ClassLoaderResourceAccessor)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1