|
| 1 | +/* |
| 2 | + * Copyright (c) 2022 Airbyte, Inc., all rights reserved. |
| 3 | + */ |
| 4 | + |
| 5 | +package io.airbyte.integrations.destination.elasticsearch; |
| 6 | + |
| 7 | +import com.fasterxml.jackson.databind.JsonNode; |
| 8 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 9 | +import com.google.common.collect.ImmutableMap; |
| 10 | +import io.airbyte.commons.json.Jsons; |
| 11 | +import io.airbyte.integrations.standardtest.destination.DestinationAcceptanceTest; |
| 12 | +import io.airbyte.integrations.standardtest.destination.comparator.AdvancedTestDataComparator; |
| 13 | +import io.airbyte.integrations.standardtest.destination.comparator.TestDataComparator; |
| 14 | +import java.io.IOException; |
| 15 | +import java.util.List; |
| 16 | +import java.util.Map; |
| 17 | +import org.junit.jupiter.api.AfterAll; |
| 18 | +import org.junit.jupiter.api.BeforeAll; |
| 19 | +import org.testcontainers.elasticsearch.ElasticsearchContainer; |
| 20 | + |
| 21 | +public class ElasticsearchStrictEncryptDestinationAcceptanceTest extends DestinationAcceptanceTest { |
| 22 | + |
| 23 | + private final ObjectMapper mapper = new ObjectMapper(); |
| 24 | + private static ElasticsearchContainer container; |
| 25 | + |
| 26 | + @BeforeAll |
| 27 | + public static void beforeAll() { |
| 28 | + |
| 29 | + container = new ElasticsearchContainer("docker.elastic.co/elasticsearch/elasticsearch:7.15.1") |
| 30 | + .withPassword("MagicWord"); |
| 31 | + |
| 32 | + container.start(); |
| 33 | + } |
| 34 | + |
| 35 | + @AfterAll |
| 36 | + public static void afterAll() { |
| 37 | + container.stop(); |
| 38 | + container.close(); |
| 39 | + } |
| 40 | + |
| 41 | + @Override |
| 42 | + protected String getImageName() { |
| 43 | + return "airbyte/destination-elasticsearch-strict-encrypt:dev"; |
| 44 | + } |
| 45 | + |
| 46 | + @Override |
| 47 | + protected int getMaxRecordValueLimit() { |
| 48 | + return 2000000; |
| 49 | + } |
| 50 | + |
| 51 | + @Override |
| 52 | + protected boolean implementsNamespaces() { |
| 53 | + return true; |
| 54 | + } |
| 55 | + |
| 56 | + @Override |
| 57 | + protected boolean supportsNormalization() { |
| 58 | + return false; |
| 59 | + } |
| 60 | + |
| 61 | + @Override |
| 62 | + protected boolean supportBasicDataTypeTest() { |
| 63 | + return true; |
| 64 | + } |
| 65 | + |
| 66 | + @Override |
| 67 | + protected boolean supportArrayDataTypeTest() { |
| 68 | + return false; |
| 69 | + } |
| 70 | + |
| 71 | + @Override |
| 72 | + protected boolean supportObjectDataTypeTest() { |
| 73 | + return true; |
| 74 | + } |
| 75 | + |
| 76 | + @Override |
| 77 | + protected TestDataComparator getTestDataComparator() { |
| 78 | + return new AdvancedTestDataComparator(); |
| 79 | + } |
| 80 | + |
| 81 | + @Override |
| 82 | + protected JsonNode getConfig() { |
| 83 | + |
| 84 | + final JsonNode authConfig = Jsons.jsonNode(Map.of( |
| 85 | + "method", "basic", |
| 86 | + "username", "elastic", |
| 87 | + "password", "MagicWord")); |
| 88 | + |
| 89 | + return Jsons.jsonNode(ImmutableMap.builder() |
| 90 | + .put("endpoint", String.format("http://%s:%s", container.getHost(), container.getMappedPort(9200))) |
| 91 | + .put("authenticationMethod", authConfig) |
| 92 | + .build()); |
| 93 | + } |
| 94 | + |
| 95 | + @Override |
| 96 | + protected JsonNode getFailCheckConfig() { |
| 97 | + // should result in a failed connection check |
| 98 | + return mapper.createObjectNode(); |
| 99 | + } |
| 100 | + |
| 101 | + @Override |
| 102 | + protected List<JsonNode> retrieveRecords(DestinationAcceptanceTest.TestDestinationEnv testEnv, |
| 103 | + String streamName, |
| 104 | + String namespace, |
| 105 | + JsonNode streamSchema) |
| 106 | + throws IOException { |
| 107 | + // Records returned from this method will be compared against records provided to the connector |
| 108 | + // to verify they were written correctly |
| 109 | + final String indexName = new ElasticsearchWriteConfig() |
| 110 | + .setNamespace(namespace) |
| 111 | + .setStreamName(streamName) |
| 112 | + .getIndexName(); |
| 113 | + |
| 114 | + ElasticsearchConnection connection = new ElasticsearchConnection(mapper.convertValue(getConfig(), ConnectorConfiguration.class)); |
| 115 | + return connection.getRecords(indexName); |
| 116 | + } |
| 117 | + |
| 118 | + @Override |
| 119 | + protected void setup(DestinationAcceptanceTest.TestDestinationEnv testEnv) {} |
| 120 | + |
| 121 | + @Override |
| 122 | + protected void tearDown(DestinationAcceptanceTest.TestDestinationEnv testEnv) { |
| 123 | + ElasticsearchConnection connection = new ElasticsearchConnection(mapper.convertValue(getConfig(), ConnectorConfiguration.class)); |
| 124 | + connection.allIndices().forEach(connection::deleteIndexIfPresent); |
| 125 | + } |
| 126 | + |
| 127 | +} |
0 commit comments