Skip to content

Commit

Permalink
Polish "Fix password property for Oracle container"
Browse files Browse the repository at this point in the history
  • Loading branch information
snicoll committed Aug 22, 2023
1 parent ab1e521 commit 5a25c31
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class OracleEnvironmentTests {

@Test
void getUsernameWhenHasAppUser() {
OracleEnvironment environment = new OracleEnvironment(Map.of("APP_USER", "alice", "APP_USER_PASSWORD", "secret"));
OracleEnvironment environment = new OracleEnvironment(
Map.of("APP_USER", "alice", "APP_USER_PASSWORD", "secret"));
assertThat(environment.getUsername()).isEqualTo("alice");
}

Expand All @@ -46,7 +47,8 @@ void getUsernameWhenHasNoAppUser() {

@Test
void getPasswordWhenHasAppPassword() {
OracleEnvironment environment = new OracleEnvironment(Map.of("APP_USER", "alice", "APP_USER_PASSWORD", "secret"));
OracleEnvironment environment = new OracleEnvironment(
Map.of("APP_USER", "alice", "APP_USER_PASSWORD", "secret"));
assertThat(environment.getPassword()).isEqualTo("secret");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.time.Duration;

import org.awaitility.Awaitility;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.OS;

Expand All @@ -42,59 +41,30 @@
*/
@DisabledOnOs(os = { OS.LINUX, OS.MAC }, architecture = "aarch64",
disabledReason = "The Oracle image has no ARM support")
class OracleJdbcDockerComposeConnectionDetailsFactoryIntegrationTests {
class OracleJdbcDockerComposeConnectionDetailsFactoryIntegrationTests extends AbstractDockerComposeIntegrationTests {

@Nested
class OracleJdbcDockerComposeConnectionDetailsFactoryDefaultSettingsIntegrationTests extends AbstractDockerComposeIntegrationTests {
OracleJdbcDockerComposeConnectionDetailsFactoryDefaultSettingsIntegrationTests() {
super("oracle-compose.yaml", DockerImageNames.oracleXe());
}

@Test
@SuppressWarnings("unchecked")
void runCreatesConnectionDetailsThatCanBeUsedToAccessDatabase() throws Exception {
JdbcConnectionDetails connectionDetails = run(JdbcConnectionDetails.class);
assertThat(connectionDetails.getUsername()).isEqualTo("system");
assertThat(connectionDetails.getPassword()).isEqualTo("secret");
assertThat(connectionDetails.getJdbcUrl()).startsWith("jdbc:oracle:thin:@").endsWith("/xepdb1");
SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
dataSource.setUrl(connectionDetails.getJdbcUrl());
dataSource.setUsername(connectionDetails.getUsername());
dataSource.setPassword(connectionDetails.getPassword());
dataSource.setDriverClass((Class<? extends Driver>) ClassUtils.forName(connectionDetails.getDriverClassName(),
getClass().getClassLoader()));
Awaitility.await().atMost(Duration.ofMinutes(1)).ignoreExceptions().untilAsserted(() -> {
JdbcTemplate template = new JdbcTemplate(dataSource);
assertThat(template.queryForObject(DatabaseDriver.ORACLE.getValidationQuery(), String.class))
.isEqualTo("Hello");
});
}
OracleJdbcDockerComposeConnectionDetailsFactoryIntegrationTests() {
super("oracle-compose.yaml", DockerImageNames.oracleXe());
}

@Nested
class OracleJdbcDockerComposeConnectionDetailsFactoryNonDefaultSettingsIntegrationTests extends AbstractDockerComposeIntegrationTests {
protected OracleJdbcDockerComposeConnectionDetailsFactoryNonDefaultSettingsIntegrationTests() {
super("oracle-non-default-compose.yaml", DockerImageNames.oracleXe());
}

@Test
@SuppressWarnings("unchecked")
void runCreatesConnectionDetailsWithNonDefaultUsernameAndPasswordThatCanBeUsedToAccessDatabase() throws Exception {
JdbcConnectionDetails connectionDetails = run(JdbcConnectionDetails.class);
assertThat(connectionDetails.getUsername()).isEqualTo("app_user");
assertThat(connectionDetails.getPassword()).isEqualTo("app_user_secret");
assertThat(connectionDetails.getJdbcUrl()).startsWith("jdbc:oracle:thin:@").endsWith("/xepdb1");
SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
dataSource.setUrl(connectionDetails.getJdbcUrl());
dataSource.setUsername(connectionDetails.getUsername());
dataSource.setPassword(connectionDetails.getPassword());
dataSource.setDriverClass((Class<? extends Driver>) ClassUtils.forName(connectionDetails.getDriverClassName(),
getClass().getClassLoader()));
Awaitility.await().atMost(Duration.ofMinutes(1)).ignoreExceptions().untilAsserted(() -> {
JdbcTemplate template = new JdbcTemplate(dataSource);
assertThat(template.queryForObject(DatabaseDriver.ORACLE.getValidationQuery(), String.class))
.isEqualTo("Hello");
});
}
@Test
@SuppressWarnings("unchecked")
void runCreatesConnectionDetailsThatCanBeUsedToAccessDatabase() throws Exception {
JdbcConnectionDetails connectionDetails = run(JdbcConnectionDetails.class);
assertThat(connectionDetails.getUsername()).isEqualTo("app_user");
assertThat(connectionDetails.getPassword()).isEqualTo("app_user_secret");
assertThat(connectionDetails.getJdbcUrl()).startsWith("jdbc:oracle:thin:@").endsWith("/xepdb1");
SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
dataSource.setUrl(connectionDetails.getJdbcUrl());
dataSource.setUsername(connectionDetails.getUsername());
dataSource.setPassword(connectionDetails.getPassword());
dataSource.setDriverClass((Class<? extends Driver>) ClassUtils.forName(connectionDetails.getDriverClassName(),
getClass().getClassLoader()));
Awaitility.await().atMost(Duration.ofMinutes(1)).ignoreExceptions().untilAsserted(() -> {
JdbcTemplate template = new JdbcTemplate(dataSource);
assertThat(template.queryForObject(DatabaseDriver.ORACLE.getValidationQuery(), String.class))
.isEqualTo("Hello");
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ services:
ports:
- '1521'
environment:
- 'APP_USER=app_user'
- 'APP_USER_PASSWORD=app_user_secret'
- 'ORACLE_PASSWORD=secret'
healthcheck:
test: ["CMD-SHELL", "healthcheck.sh"]
Expand Down

This file was deleted.

0 comments on commit 5a25c31

Please sign in to comment.