Skip to content

Commit

Permalink
[17495] Source-oracle: fixed build and integration test (airbytehq#17769
Browse files Browse the repository at this point in the history
)

* [17495] Source-oracle: fixed build and integration test
  • Loading branch information
etsybaev authored and jhammarstedt committed Oct 31, 2022
1 parent 360a88b commit 05c9e97
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dependencies {
testImplementation libs.connectors.source.testcontainers.oracle.xe

integrationTestJavaImplementation project(':airbyte-integrations:bases:standard-source-test')
integrationTestJavaImplementation project(':airbyte-integrations:connectors:source-oracle-strict-encrypt')

implementation files(project(':airbyte-integrations:bases:base-java').airbyteDocker.outputs)
integrationTestJavaImplementation files(project(':airbyte-integrations:bases:base-java').airbyteDocker.outputs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy;
import org.testcontainers.utility.DockerImageName;

public class OracleContainer extends JdbcDatabaseContainer<OracleContainer> {
public class AirbyteOracleTestContainer extends JdbcDatabaseContainer<AirbyteOracleTestContainer> {

public static final String NAME = "oracle";
private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("gvenzl/oracle-xe");
Expand Down Expand Up @@ -49,21 +49,21 @@ public class OracleContainer extends JdbcDatabaseContainer<OracleContainer> {
private String password = APP_USER_PASSWORD;
private boolean usingSid = false;

public OracleContainer() {
public AirbyteOracleTestContainer() {
this(DEFAULT_IMAGE_NAME.withTag(DEFAULT_TAG));
}

public OracleContainer(final String dockerImageName) {
public AirbyteOracleTestContainer(final String dockerImageName) {
this(DockerImageName.parse(dockerImageName));
}

public OracleContainer(final DockerImageName dockerImageName) {
public AirbyteOracleTestContainer(final DockerImageName dockerImageName) {
super(dockerImageName);
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME);
preconfigure();
}

public OracleContainer(final Future<String> dockerImageName) {
public AirbyteOracleTestContainer(final Future<String> dockerImageName) {
super(dockerImageName);
preconfigure();
}
Expand Down Expand Up @@ -120,7 +120,7 @@ protected boolean isUsingSid() {
}

@Override
public OracleContainer withUsername(final String username) {
public AirbyteOracleTestContainer withUsername(final String username) {
if (StringUtils.isEmpty(username)) {
throw new IllegalArgumentException("Username cannot be null or empty");
}
Expand All @@ -132,7 +132,7 @@ public OracleContainer withUsername(final String username) {
}

@Override
public OracleContainer withPassword(final String password) {
public AirbyteOracleTestContainer withPassword(final String password) {
if (StringUtils.isEmpty(password)) {
throw new IllegalArgumentException("Password cannot be null or empty");
}
Expand All @@ -141,7 +141,7 @@ public OracleContainer withPassword(final String password) {
}

@Override
public OracleContainer withDatabaseName(final String databaseName) {
public AirbyteOracleTestContainer withDatabaseName(final String databaseName) {
if (StringUtils.isEmpty(databaseName)) {
throw new IllegalArgumentException("Database name cannot be null or empty");
}
Expand All @@ -154,13 +154,13 @@ public OracleContainer withDatabaseName(final String databaseName) {
return self();
}

public OracleContainer usingSid() {
public AirbyteOracleTestContainer usingSid() {
this.usingSid = true;
return self();
}

@Override
public OracleContainer withUrlParam(final String paramName, final String paramValue) {
public AirbyteOracleTestContainer withUrlParam(final String paramName, final String paramValue) {
throw new UnsupportedOperationException("The Oracle Database driver does not support this");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,11 @@
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.OracleContainer;

class OracleStrictEncryptJdbcSourceAcceptanceTest extends JdbcSourceAcceptanceTest {

private static final Logger LOGGER = LoggerFactory.getLogger(OracleStrictEncryptJdbcSourceAcceptanceTest.class);
private static OracleContainer ORACLE_DB;
private static AirbyteOracleTestContainer ORACLE_DB;

@BeforeAll
static void init() {
Expand Down Expand Up @@ -86,7 +85,10 @@ static void init() {
CREATE_TABLE_WITH_NULLABLE_CURSOR_TYPE_QUERY = "CREATE TABLE %s (%s VARCHAR(20))";
INSERT_TABLE_WITH_NULLABLE_CURSOR_TYPE_QUERY = "INSERT INTO %s VALUES('Hello world :)')";

ORACLE_DB = new OracleContainer("epiclabs/docker-oracle-xe-11g")
ORACLE_DB = new AirbyteOracleTestContainer()
.withUsername("test")
.withPassword("oracle")
.usingSid()
.withEnv("NLS_DATE_FORMAT", "YYYY-MM-DD")
.withEnv("RELAX_SECURITY", "1");
ORACLE_DB.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ public class OracleStrictEncryptSourceAcceptanceTest extends SourceAcceptanceTes
private static final String STREAM_NAME = "JDBC_SPACE.ID_AND_NAME";
private static final String STREAM_NAME2 = "JDBC_SPACE.STARSHIPS";

protected OracleContainer container;
protected AirbyteOracleTestContainer container;
protected JsonNode config;

@Override
protected void setupEnvironment(final TestDestinationEnv environment) throws Exception {
container = new OracleContainer()
container = new AirbyteOracleTestContainer()
.withUsername("test")
.withPassword("oracle")
.usingSid();;
Expand Down
1 change: 1 addition & 0 deletions airbyte-integrations/connectors/source-oracle/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dependencies {
testImplementation libs.connectors.source.testcontainers.oracle.xe

integrationTestJavaImplementation project(':airbyte-integrations:bases:standard-source-test')
integrationTestJavaImplementation project(':airbyte-integrations:connectors:source-oracle')

implementation files(project(':airbyte-integrations:bases:base-java').airbyteDocker.outputs)
integrationTestJavaImplementation files(project(':airbyte-integrations:bases:base-java').airbyteDocker.outputs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public abstract class AbstractSshOracleSourceAcceptanceTest extends SourceAccept
private static final String STREAM_NAME2 = "JDBC_SPACE.STARSHIPS";
private static final Network network = Network.newNetwork();
private final SshBastionContainer sshBastionContainer = new SshBastionContainer();
private OracleContainer db;
private AirbyteOracleTestContainer db;

private JsonNode config;

Expand Down Expand Up @@ -90,7 +90,7 @@ private void startTestContainers() {
}

private void initAndStartJdbcContainer() {
db = new OracleContainer()
db = new AirbyteOracleTestContainer()
.withUsername("test")
.withPassword("oracle")
.usingSid()
Expand All @@ -108,7 +108,7 @@ protected ConnectorSpecification getSpec() throws Exception {
return SshHelpers.getSpecAndInjectSsh();
}

public ImmutableMap.Builder<Object, Object> getBasicOracleDbConfigBuider(final OracleContainer db) {
public ImmutableMap.Builder<Object, Object> getBasicOracleDbConfigBuider(final AirbyteOracleTestContainer db) {
return ImmutableMap.builder()
.put("host", Objects.requireNonNull(db.getContainerInfo().getNetworkSettings()
.getNetworks()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy;
import org.testcontainers.utility.DockerImageName;

public class OracleContainer extends JdbcDatabaseContainer<OracleContainer> {
public class AirbyteOracleTestContainer extends JdbcDatabaseContainer<AirbyteOracleTestContainer> {

public static final String NAME = "oracle";
private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("gvenzl/oracle-xe");
Expand Down Expand Up @@ -49,21 +49,21 @@ public class OracleContainer extends JdbcDatabaseContainer<OracleContainer> {
private String password = APP_USER_PASSWORD;
private boolean usingSid = false;

public OracleContainer() {
public AirbyteOracleTestContainer() {
this(DEFAULT_IMAGE_NAME.withTag(DEFAULT_TAG));
}

public OracleContainer(final String dockerImageName) {
public AirbyteOracleTestContainer(final String dockerImageName) {
this(DockerImageName.parse(dockerImageName));
}

public OracleContainer(final DockerImageName dockerImageName) {
public AirbyteOracleTestContainer(final DockerImageName dockerImageName) {
super(dockerImageName);
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME);
preconfigure();
}

public OracleContainer(final Future<String> dockerImageName) {
public AirbyteOracleTestContainer(final Future<String> dockerImageName) {
super(dockerImageName);
preconfigure();
}
Expand Down Expand Up @@ -120,7 +120,7 @@ protected boolean isUsingSid() {
}

@Override
public OracleContainer withUsername(final String username) {
public AirbyteOracleTestContainer withUsername(final String username) {
if (StringUtils.isEmpty(username)) {
throw new IllegalArgumentException("Username cannot be null or empty");
}
Expand All @@ -132,7 +132,7 @@ public OracleContainer withUsername(final String username) {
}

@Override
public OracleContainer withPassword(final String password) {
public AirbyteOracleTestContainer withPassword(final String password) {
if (StringUtils.isEmpty(password)) {
throw new IllegalArgumentException("Password cannot be null or empty");
}
Expand All @@ -141,7 +141,7 @@ public OracleContainer withPassword(final String password) {
}

@Override
public OracleContainer withDatabaseName(final String databaseName) {
public AirbyteOracleTestContainer withDatabaseName(final String databaseName) {
if (StringUtils.isEmpty(databaseName)) {
throw new IllegalArgumentException("Database name cannot be null or empty");
}
Expand All @@ -154,13 +154,13 @@ public OracleContainer withDatabaseName(final String databaseName) {
return self();
}

public OracleContainer usingSid() {
public AirbyteOracleTestContainer usingSid() {
this.usingSid = true;
return self();
}

@Override
public OracleContainer withUrlParam(final String paramName, final String paramValue) {
public AirbyteOracleTestContainer withUrlParam(final String paramName, final String paramValue) {
throw new UnsupportedOperationException("The Oracle Database driver does not support this");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,13 @@
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.OracleContainer;

class OracleJdbcSourceAcceptanceTest extends JdbcSourceAcceptanceTest {

private static final Logger LOGGER = LoggerFactory.getLogger(OracleJdbcSourceAcceptanceTest.class);
protected static final String USERNAME_WITHOUT_PERMISSION = "new_user";
protected static final String PASSWORD_WITHOUT_PERMISSION = "new_password";
private static OracleContainer ORACLE_DB;
private static AirbyteOracleTestContainer ORACLE_DB;

@BeforeAll
static void init() {
Expand Down Expand Up @@ -91,8 +90,12 @@ static void init() {
CREATE_TABLE_WITH_NULLABLE_CURSOR_TYPE_QUERY = "CREATE TABLE %s (%s VARCHAR(20))";
INSERT_TABLE_WITH_NULLABLE_CURSOR_TYPE_QUERY = "INSERT INTO %s VALUES('Hello world :)')";

ORACLE_DB = new OracleContainer("epiclabs/docker-oracle-xe-11g")
ORACLE_DB = new AirbyteOracleTestContainer()
.withEnv("NLS_DATE_FORMAT", "YYYY-MM-DD")
.withEnv("RELAX_SECURITY", "1")
.withUsername("TEST_ORA")
.withPassword("oracle")
.usingSid()
.withEnv("RELAX_SECURITY", "1");
ORACLE_DB.start();
}
Expand Down Expand Up @@ -398,8 +401,10 @@ void testCheckIncorrectPasswordFailure() throws Exception {
((ObjectNode) config).put(JdbcUtils.USERNAME_KEY, "locked_user");
((ObjectNode) config).put(JdbcUtils.PASSWORD_KEY, "fake");
final AirbyteConnectionStatus status = source.check(config);

Assertions.assertEquals(AirbyteConnectionStatus.Status.FAILED, status.getStatus());
assertTrue(status.getMessage().contains("State code: 99999; Error code: 28000;"));
assertEquals("State code: 72000; Error code: 1017; Message: ORA-01017: invalid username/password; logon denied\n",
status.getMessage());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ public class OracleSourceAcceptanceTest extends SourceAcceptanceTest {
private static final String STREAM_NAME = "JDBC_SPACE.ID_AND_NAME";
private static final String STREAM_NAME2 = "JDBC_SPACE.STARSHIPS";

protected OracleContainer container;
protected AirbyteOracleTestContainer container;
protected JsonNode config;

@Override
protected void setupEnvironment(final TestDestinationEnv environment) throws Exception {
container = new OracleContainer()
container = new AirbyteOracleTestContainer()
.withUsername("test")
.withPassword("oracle")
.usingSid();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,21 @@
import org.jooq.DSLContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.OracleContainer;

public class OracleSourceDatatypeTest extends AbstractSourceDatabaseTypeTest {

private OracleContainer container;
private AirbyteOracleTestContainer container;
private JsonNode config;
private DSLContext dslContext;

private static final Logger LOGGER = LoggerFactory.getLogger(OracleSourceDatatypeTest.class);

@Override
protected Database setupDatabase() throws Exception {
container = new OracleContainer("epiclabs/docker-oracle-xe-11g")
container = new AirbyteOracleTestContainer()
.withUsername("TEST_ORA")
.withPassword("oracle")
.usingSid()
.withEnv("RELAX_SECURITY", "1");
container.start();

Expand All @@ -64,7 +66,7 @@ protected Database setupDatabase() throws Exception {
final Database database = new Database(dslContext);
LOGGER.warn("config: " + config);

database.query(ctx -> ctx.fetch("CREATE USER test IDENTIFIED BY test DEFAULT TABLESPACE USERS QUOTA UNLIMITED ON USERS"));
database.query(ctx -> ctx.fetch("CREATE USER TEST IDENTIFIED BY TEST DEFAULT TABLESPACE USERS QUOTA UNLIMITED ON USERS"));

return database;
}
Expand Down Expand Up @@ -286,11 +288,11 @@ protected void initTests() {
"<config>1</config>\n" +
"<config>2</config>\n" +
"</list_configuration>')")
.addExpectedValues("<?xml version = '1.0' encoding = 'UTF-8'?>" +
"<list_configuration>\n" +
" <config>1</config>\n" +
" <config>2</config>\n" +
"</list_configuration>")
.addExpectedValues("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<list_configuration>\n"
+ " <config>1</config>\n"
+ " <config>2</config>\n"
+ "</list_configuration>\n")
.build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.OracleContainer;

class OracleSourceTest {

Expand All @@ -48,18 +47,23 @@ class OracleSourceTest {
Field.of("NAME", JsonSchemaType.STRING),
Field.of("IMAGE", JsonSchemaType.STRING))
.withSupportedSyncModes(Lists.newArrayList(SyncMode.FULL_REFRESH, SyncMode.INCREMENTAL))));

private static final ConfiguredAirbyteCatalog CONFIGURED_CATALOG = CatalogHelpers.toDefaultConfiguredCatalog(CATALOG);
private static final Set<AirbyteMessage> ASCII_MESSAGES = Sets.newHashSet(createRecord(STREAM_NAME,
map("ID", new BigDecimal("1.0"), "NAME", "user", "IMAGE", "last_summer.png".getBytes(StandardCharsets.UTF_8))));

private static OracleContainer ORACLE_DB;
private static AirbyteOracleTestContainer ORACLE_DB;

private static JsonNode config;

@BeforeAll
static void init() {
ORACLE_DB = new OracleContainer("epiclabs/docker-oracle-xe-11g")
ORACLE_DB = new AirbyteOracleTestContainer()
.withUsername("TEST_ORA")
.withPassword("oracle")
.usingSid()
.withEnv("RELAX_SECURITY", "1");

ORACLE_DB.start();
}

Expand Down Expand Up @@ -97,16 +101,6 @@ void setup() throws Exception {
}
}

private JsonNode getConfig(final OracleContainer oracleDb) {
return Jsons.jsonNode(ImmutableMap.builder()
.put("host", oracleDb.getHost())
.put("port", oracleDb.getFirstMappedPort())
.put("sid", oracleDb.getSid())
.put("username", oracleDb.getUsername())
.put("password", oracleDb.getPassword())
.build());
}

@AfterAll
static void cleanUp() {
ORACLE_DB.close();
Expand Down

0 comments on commit 05c9e97

Please sign in to comment.