diff --git a/airbyte-integrations/connectors/source-mongodb-strict-encrypt/src/test-integration/java/io/airbyte/integrations/source/mongodb/MongodbSourceStrictEncryptAcceptanceTest.java b/airbyte-integrations/connectors/source-mongodb-strict-encrypt/src/test-integration/java/io/airbyte/integrations/source/mongodb/MongodbSourceStrictEncryptAcceptanceTest.java index 062c075dc988..1db72334d105 100644 --- a/airbyte-integrations/connectors/source-mongodb-strict-encrypt/src/test-integration/java/io/airbyte/integrations/source/mongodb/MongodbSourceStrictEncryptAcceptanceTest.java +++ b/airbyte-integrations/connectors/source-mongodb-strict-encrypt/src/test-integration/java/io/airbyte/integrations/source/mongodb/MongodbSourceStrictEncryptAcceptanceTest.java @@ -66,28 +66,14 @@ protected void setupEnvironment(final TestDestinationEnv environment) throws Exc + ". Override by setting setting path with the CREDENTIALS_PATH constant."); } - final String credentialsJsonString = Files.readString(CREDENTIALS_PATH); - final JsonNode credentialsJson = Jsons.deserialize(credentialsJsonString); - - final JsonNode instanceConfig = Jsons.jsonNode(ImmutableMap.builder() - .put("instance", MongoInstanceType.ATLAS.getType()) - .put("cluster_url", credentialsJson.get("cluster_url").asText()) - .build()); - - config = Jsons.jsonNode(ImmutableMap.builder() - .put("user", credentialsJson.get("user").asText()) - .put(JdbcUtils.PASSWORD_KEY, credentialsJson.get(JdbcUtils.PASSWORD_KEY).asText()) - .put(INSTANCE_TYPE, instanceConfig) - .put(JdbcUtils.DATABASE_KEY, DATABASE_NAME) - .put("auth_source", "admin") - .build()); - - final var credentials = String.format("%s:%s@", config.get("user").asText(), - config.get(JdbcUtils.PASSWORD_KEY).asText()); - final String connectionString = String.format("mongodb+srv://%s%s/%s?retryWrites=true&w=majority&tls=true", - credentials, - config.get(INSTANCE_TYPE).get("cluster_url").asText(), - config.get(JdbcUtils.DATABASE_KEY).asText()); + config = Jsons.deserialize(Files.readString(CREDENTIALS_PATH)); + ((ObjectNode) config).put(JdbcUtils.DATABASE_KEY, DATABASE_NAME); + + final String connectionString = String.format("mongodb+srv://%s:%s@%s/%s?authSource=admin&retryWrites=true&w=majority&tls=true", + config.get("user").asText(), + config.get(JdbcUtils.PASSWORD_KEY).asText(), + config.get("instance_type").get("cluster_url").asText(), + config.get(JdbcUtils.DATABASE_KEY).asText()); database = new MongoDatabase(connectionString, DATABASE_NAME); diff --git a/airbyte-integrations/connectors/source-mongodb-strict-encrypt/src/test-integration/resources/expected_spec.json b/airbyte-integrations/connectors/source-mongodb-strict-encrypt/src/test-integration/resources/expected_spec.json index 2b5821b4f975..48be1e68bb2f 100644 --- a/airbyte-integrations/connectors/source-mongodb-strict-encrypt/src/test-integration/resources/expected_spec.json +++ b/airbyte-integrations/connectors/source-mongodb-strict-encrypt/src/test-integration/resources/expected_spec.json @@ -20,8 +20,7 @@ "properties": { "instance": { "type": "string", - "enum": ["standalone"], - "default": "standalone" + "const": "standalone" }, "host": { "title": "Host", @@ -47,8 +46,7 @@ "properties": { "instance": { "type": "string", - "enum": ["replica"], - "default": "replica" + "const": "replica" }, "server_addresses": { "title": "Server Addresses", @@ -67,13 +65,12 @@ }, { "title": "MongoDB Atlas", - "additionalProperties": false, + "additionalProperties": true, "required": ["instance", "cluster_url"], "properties": { "instance": { "type": "string", - "enum": ["atlas"], - "default": "atlas" + "const": "atlas" }, "cluster_url": { "title": "Cluster URL", diff --git a/airbyte-integrations/connectors/source-mongodb-v2/src/test-integration/java/io/airbyte/integrations/io/airbyte/integration_tests/sources/MongoDbSourceAtlasAcceptanceTest.java b/airbyte-integrations/connectors/source-mongodb-v2/src/test-integration/java/io/airbyte/integrations/io/airbyte/integration_tests/sources/MongoDbSourceAtlasAcceptanceTest.java index 3ff135af8310..b421f3f57eab 100644 --- a/airbyte-integrations/connectors/source-mongodb-v2/src/test-integration/java/io/airbyte/integrations/io/airbyte/integration_tests/sources/MongoDbSourceAtlasAcceptanceTest.java +++ b/airbyte-integrations/connectors/source-mongodb-v2/src/test-integration/java/io/airbyte/integrations/io/airbyte/integration_tests/sources/MongoDbSourceAtlasAcceptanceTest.java @@ -62,21 +62,8 @@ protected void setupEnvironment(final TestDestinationEnv environment) throws Exc + ". Override by setting setting path with the CREDENTIALS_PATH constant."); } - final String credentialsJsonString = Files.readString(CREDENTIALS_PATH); - final JsonNode credentialsJson = Jsons.deserialize(credentialsJsonString); - - final JsonNode instanceConfig = Jsons.jsonNode(ImmutableMap.builder() - .put("instance", ATLAS.getType()) - .put("cluster_url", credentialsJson.get("cluster_url").asText()) - .build()); - - config = Jsons.jsonNode(ImmutableMap.builder() - .put("user", credentialsJson.get("user").asText()) - .put(JdbcUtils.PASSWORD_KEY, credentialsJson.get(JdbcUtils.PASSWORD_KEY).asText()) - .put("instance_type", instanceConfig) - .put(JdbcUtils.DATABASE_KEY, DATABASE_NAME) - .put("auth_source", "admin") - .build()); + config = Jsons.deserialize(Files.readString(CREDENTIALS_PATH)); + ((ObjectNode) config).put(JdbcUtils.DATABASE_KEY, DATABASE_NAME); final String connectionString = String.format("mongodb+srv://%s:%s@%s/%s?authSource=admin&retryWrites=true&w=majority&tls=true", config.get("user").asText(), @@ -84,7 +71,7 @@ protected void setupEnvironment(final TestDestinationEnv environment) throws Exc config.get("instance_type").get("cluster_url").asText(), config.get(JdbcUtils.DATABASE_KEY).asText()); - database = new MongoDatabase(connectionString, DATABASE_NAME); + database = new MongoDatabase(connectionString, config.get(JdbcUtils.DATABASE_KEY).asText()); final MongoCollection collection = database.createCollection(COLLECTION_NAME); final var objectDocument = new Document("testObject", new Document("name", "subName").append("testField1", "testField1").append("testInt", 10) @@ -134,11 +121,11 @@ public void testCheckIncorrectPassword() throws Exception { @Test public void testCheckIncorrectCluster() throws Exception { - ((ObjectNode) config).with("instance_type") - .put("cluster_url", "cluster0.iqgf8.mongodb.netfail"); + final String badClusterUrl = "cluster0.iqgf8.mongodb.netfail"; + config.withObject("/instance_type").put("cluster_url", badClusterUrl); final AirbyteConnectionStatus status = new MongoDbSource().check(config); assertEquals(AirbyteConnectionStatus.Status.FAILED, status.getStatus()); - assertTrue(status.getMessage().contains("State code: -4")); + assertTrue(status.getMessage().matches("State code: -\\d+.*")); } @Test