Skip to content

Commit

Permalink
PostgresAppTestExtension: internal refactoring (#535)
Browse files Browse the repository at this point in the history
* Extract method 'buildPostgresConfigOverrides' from the constructor
* This method contains all the logic for building the Postgres-specific
configuration overrides
* Overall this simplifies the constructor
  • Loading branch information
sleberknight authored Dec 24, 2024
1 parent 416e21f commit b5e5fa2
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,16 @@ public PostgresAppTestExtension(String migrationClasspathLocation,
var liquibasePreparer = LiquibasePreparer.forClasspathLocation(migrationClasspathLocation);
postgres = EmbeddedPostgresExtension.preparedDatabase(liquibasePreparer);

var postgresConfigOverrides = buildPostgresConfigOverrides(dataSourceFactoryPropertyName);
var combinedConfigOverrides = ArrayUtils.addAll(postgresConfigOverrides, configOverrides);

app = new DropwizardAppExtension<>(
appClass,
ResourceHelpers.resourceFilePath(configFileName),
combinedConfigOverrides);
}

private ConfigOverride[] buildPostgresConfigOverrides(String dataSourceFactoryPropertyName) {
var dbUserProperty = dataSourceFactoryPropertyName + ".user";
var dbUrlProperty = dataSourceFactoryPropertyName + ".url";
var dbDriverClassProperty = dataSourceFactoryPropertyName + ".driverClass";
Expand All @@ -165,13 +175,7 @@ public PostgresAppTestExtension(String migrationClasspathLocation,
+ "/" + postgres.getConnectionInfo().getDbName());
var driverConfigOverride = ConfigOverride.config(dbDriverClassProperty, Driver.class.getName());

var postgresConfigOverrides = new ConfigOverride[]{userConfigOverride, urlConfigOverride, driverConfigOverride};
var combinedConfigOverrides = ArrayUtils.addAll(postgresConfigOverrides, configOverrides);

app = new DropwizardAppExtension<>(
appClass,
ResourceHelpers.resourceFilePath(configFileName),
combinedConfigOverrides);
return new ConfigOverride[] { userConfigOverride, urlConfigOverride, driverConfigOverride };
}

@Override
Expand Down

0 comments on commit b5e5fa2

Please sign in to comment.