Skip to content

Commit

Permalink
Update OracleContainer and re-activate on CI (#4298)
Browse files Browse the repository at this point in the history
Will now use "gvenzl/oracle-xe:18.4.0-slim" by default.

Co-authored-by: Piotr <[email protected]>
Co-authored-by: Sergei Egorov <[email protected]>
  • Loading branch information
3 people authored Aug 19, 2021
1 parent 5b66056 commit 99b91b8
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicReference;
Expand Down Expand Up @@ -61,6 +60,7 @@ public class TestcontainersConfiguration {
private static final String PULSAR_IMAGE = "apachepulsar/pulsar";
private static final String LOCALSTACK_IMAGE = "localstack/localstack";
private static final String SSHD_IMAGE = "testcontainers/sshd";
private static final String ORACLE_IMAGE = "gvenzl/oracle-xe";

private static final ImmutableMap<DockerImageName, String> CONTAINER_MAPPING = ImmutableMap.<DockerImageName, String>builder()
.put(DockerImageName.parse(AMBASSADOR_IMAGE), "ambassador.container.image")
Expand All @@ -73,6 +73,7 @@ public class TestcontainersConfiguration {
.put(DockerImageName.parse(PULSAR_IMAGE), "pulsar.container.image")
.put(DockerImageName.parse(LOCALSTACK_IMAGE), "localstack.container.image")
.put(DockerImageName.parse(SSHD_IMAGE), "sshd.container.image")
.put(DockerImageName.parse(ORACLE_IMAGE), "oracle.container.image")
.build();

@Getter(lazy = true)
Expand Down Expand Up @@ -146,7 +147,7 @@ public String getKafkaImage() {

@Deprecated
public String getOracleImage() {
return getEnvVarOrProperty("oracle.container.image", null);
return getImage(ORACLE_IMAGE).asCanonicalNameString();
}

@Deprecated
Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,39 @@
package org.testcontainers.containers;

import com.google.common.collect.Sets;
import org.apache.commons.lang.StringUtils;
import org.testcontainers.utility.DockerImageName;
import org.testcontainers.utility.TestcontainersConfiguration;

import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Future;

/**
* @author gusohal
*/
public class OracleContainer extends JdbcDatabaseContainer<OracleContainer> {

public static final String NAME = "oracle";
private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("gvenzl/oracle-xe");


static final String DEFAULT_TAG = "18.4.0-slim";
static final String IMAGE = DEFAULT_IMAGE_NAME.getUnversionedPart();

private static final int ORACLE_PORT = 1521;
private static final int APEX_HTTP_PORT = 8080;

private static final int DEFAULT_STARTUP_TIMEOUT_SECONDS = 240;
private static final int DEFAULT_CONNECT_TIMEOUT_SECONDS = 120;
private static final List<String> ORACLE_SYSTEM_USERS = Arrays.asList("system", "sys");

private String username = "system";
private String password = "oracle";

private static String resolveImageName() {
String image = TestcontainersConfiguration.getInstance().getOracleImage();

if (image == null) {
throw new IllegalStateException("An image to use for Oracle containers must be configured. " +
"To do this, please place a file on the classpath named `testcontainers.properties`, " +
"containing `oracle.container.image=IMAGE`, where IMAGE is a suitable image name and tag.");
}
return image;
}
private String username = "test";
private String password = "test";

/**
* @deprecated use {@link OracleContainer(DockerImageName)} instead
*/
@Deprecated
public OracleContainer() {
this(resolveImageName());
this(DEFAULT_IMAGE_NAME.withTag(DEFAULT_TAG));
}

public OracleContainer(String dockerImageName) {
Expand Down Expand Up @@ -74,7 +68,7 @@ public String getDriverClassName() {

@Override
public String getJdbcUrl() {
return "jdbc:oracle:thin:" + getUsername() + "/" + getPassword() + "@" + getHost() + ":" + getOraclePort() + ":" + getSid();
return "jdbc:oracle:thin:" + getUsername() + "/" + getPassword() + "@" + getHost() + ":" + getOraclePort() + "/xepdb1";
}

@Override
Expand All @@ -89,12 +83,21 @@ public String getPassword() {

@Override
public OracleContainer withUsername(String username) {
if (StringUtils.isEmpty(username)) {
throw new IllegalArgumentException("Username cannot be null or empty");
}
if (ORACLE_SYSTEM_USERS.contains(username.toLowerCase())) {
throw new IllegalArgumentException("Username cannot be one of " + ORACLE_SYSTEM_USERS);
}
this.username = username;
return self();
}

@Override
public OracleContainer withPassword(String password) {
if (StringUtils.isEmpty(password)) {
throw new IllegalArgumentException("Password cannot be null or empty");
}
this.password = password;
return self();
}
Expand Down Expand Up @@ -122,4 +125,11 @@ public Integer getWebPort() {
public String getTestQueryString() {
return "SELECT 1 FROM DUAL";
}

@Override
protected void configure() {
withEnv("ORACLE_PASSWORD", password);
withEnv("APP_USER", username);
withEnv("APP_USER_PASSWORD", password);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.testcontainers.containers;

import org.testcontainers.utility.DockerImageName;

/**
* Factory for Oracle containers.
*/
Expand All @@ -11,15 +13,14 @@ public boolean supports(String databaseType) {

@Override
public JdbcDatabaseContainer newInstance() {
return new OracleContainer();
return newInstance(OracleContainer.DEFAULT_TAG);
}

@Override
public JdbcDatabaseContainer newInstance(String tag) {
if (tag != null) {
throw new UnsupportedOperationException("Oracle database tag should be set in the configured image name");
return new OracleContainer(DockerImageName.parse(OracleContainer.IMAGE).withTag(tag));
}

return new OracleContainer();
return newInstance();
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
package org.testcontainers.junit.oracle;

import org.junit.Ignore;
import org.junit.Test;
import org.testcontainers.containers.OracleContainer;
import org.testcontainers.db.AbstractContainerDatabaseTest;
import org.testcontainers.utility.DockerImageName;

import java.sql.ResultSet;
import java.sql.SQLException;

import static org.rnorth.visibleassertions.VisibleAssertions.assertEquals;

@Ignore
public class SimpleOracleTest extends AbstractContainerDatabaseTest {

public static final DockerImageName ORACLE_DOCKER_IMAGE_NAME = DockerImageName.parse("gvenzl/oracle-xe:18.4.0-slim");

@Test
public void testSimple() throws SQLException {
try (OracleContainer oracle = new OracleContainer()) {

try (
OracleContainer oracle = new OracleContainer(ORACLE_DOCKER_IMAGE_NAME)
.withUsername("baz")
.withPassword("bar")
) {
oracle.start();
ResultSet resultSet = performQuery(oracle, "SELECT 1 FROM dual");

int resultSetInt = resultSet.getInt(1);
Expand Down

0 comments on commit 99b91b8

Please sign in to comment.