From 914a0049ab18bf57f45e966ac06fb2a5bf9e2efc Mon Sep 17 00:00:00 2001 From: Rustam_Lotsmanenko <Rustam_Lotsmanenko@epam.com> Date: Sat, 24 Apr 2021 20:38:08 +0400 Subject: [PATCH] undo test-core index deletion changes & records steps --- .../opengroup/osdu/common/RecordSteps.java | 15 ++++------ .../osdu/common/SchemaServiceRecordSteps.java | 17 ++++------- .../org/opengroup/osdu/models/TestIndex.java | 5 +--- .../step_definitions/index/record/Steps.java | 30 +++++++++++-------- .../opengroup/osdu/util/GcpElasticUtils.java | 20 +++++++++++++ 5 files changed, 50 insertions(+), 37 deletions(-) create mode 100644 testing/indexer-test-gcp/src/test/java/org/opengroup/osdu/util/GcpElasticUtils.java diff --git a/testing/indexer-test-core/src/main/java/org/opengroup/osdu/common/RecordSteps.java b/testing/indexer-test-core/src/main/java/org/opengroup/osdu/common/RecordSteps.java index da05637c1..fbf12a6f9 100644 --- a/testing/indexer-test-core/src/main/java/org/opengroup/osdu/common/RecordSteps.java +++ b/testing/indexer-test-core/src/main/java/org/opengroup/osdu/common/RecordSteps.java @@ -151,26 +151,23 @@ public class RecordSteps extends TestsBase { public void i_should_get_the_documents_for_the_in_the_Elastic_Search_by_geoQuery ( int expectedNumber, String index, Double topLatitude, Double topLongitude, Double bottomLatitude, Double bottomLongitude, String field) throws Throwable { index = generateActualName(index, timeStamp); - String actualName = generateActualName(index, timeStamp); - long numOfIndexedDocuments = createIndex(actualName); - long actualNumberOfRecords = elasticUtils.fetchRecordsByBoundingBoxQuery(actualName, field, topLatitude, topLongitude, bottomLatitude, bottomLongitude); + long numOfIndexedDocuments = createIndex(index); + long actualNumberOfRecords = elasticUtils.fetchRecordsByBoundingBoxQuery(index, field, topLatitude, topLongitude, bottomLatitude, bottomLongitude); assertEquals(expectedNumber, actualNumberOfRecords); } public void i_should_get_the_documents_for_the_in_the_Elastic_Search_by_nestedQuery( int expectedNumber, String index, String path, String firstNestedField, String firstNestedValue, String secondNestedField, String secondNestedValue) throws Exception { - String actualName = generateActualName(index, timeStamp); - long numOfIndexedDocuments = createIndex(actualName); - long actualNumberOfRecords = elasticUtils.fetchRecordsByNestedQuery(actualName, path, firstNestedField, firstNestedValue, secondNestedField, secondNestedValue); + long numOfIndexedDocuments = createIndex(index); + long actualNumberOfRecords = elasticUtils.fetchRecordsByNestedQuery(index, path, firstNestedField, firstNestedValue, secondNestedField, secondNestedValue); assertEquals(expectedNumber, actualNumberOfRecords); } public void i_should_be_able_search_documents_for_the_by_flattened_inner_properties(int expectedCount, String index, String flattenedField, String flattenedFieldValue) throws IOException, InterruptedException { - String actualName = generateActualName(index, timeStamp); - long numOfIndexedDocuments = createIndex(actualName); - long actualNumberOfRecords = elasticUtils.fetchRecordsWithFlattenedFieldsQuery(actualName, flattenedField, flattenedFieldValue); + long numOfIndexedDocuments = createIndex(index); + long actualNumberOfRecords = elasticUtils.fetchRecordsWithFlattenedFieldsQuery(index, flattenedField, flattenedFieldValue); assertEquals(expectedCount, actualNumberOfRecords); } diff --git a/testing/indexer-test-core/src/main/java/org/opengroup/osdu/common/SchemaServiceRecordSteps.java b/testing/indexer-test-core/src/main/java/org/opengroup/osdu/common/SchemaServiceRecordSteps.java index 05acd914a..993c26b25 100644 --- a/testing/indexer-test-core/src/main/java/org/opengroup/osdu/common/SchemaServiceRecordSteps.java +++ b/testing/indexer-test-core/src/main/java/org/opengroup/osdu/common/SchemaServiceRecordSteps.java @@ -1,29 +1,24 @@ package org.opengroup.osdu.common; import cucumber.api.DataTable; -import java.util.List; -import java.util.Map; -import lombok.extern.java.Log; import org.opengroup.osdu.models.Setup; import org.opengroup.osdu.models.schema.PersistentSchemaTestIndex; import org.opengroup.osdu.util.ElasticUtils; import org.opengroup.osdu.util.HTTPClient; -import org.opengroup.osdu.util.IndexerClientUtil; -@Log -public class SchemaServiceRecordSteps extends RecordSteps { +import java.util.List; +import java.util.Map; - private IndexerClientUtil indexerClient; +public class SchemaServiceRecordSteps extends RecordSteps { public SchemaServiceRecordSteps(HTTPClient httpClient, ElasticUtils elasticUtils) { super(httpClient, elasticUtils); - indexerClient = new IndexerClientUtil(this.httpClient); } public void the_schema_is_created_with_the_following_kind(DataTable dataTable) { List<Setup> inputList = dataTable.asList(Setup.class); inputList.forEach(this::createSchema); - inputList.forEach(s -> deleteIndex(generateActualNameWithoutTs(s.getKind()))); + inputList.forEach(s -> deleteIndex(generateActualNameWithoutTs(s.getIndex()))); super.addShutDownHook(); } @@ -38,8 +33,8 @@ public class SchemaServiceRecordSteps extends RecordSteps { super.getInputIndexMap().put(testIndex.getKind(), testIndex); } - private void deleteIndex(String kind) { - indexerClient.deleteIndex(kind); + private void deleteIndex(String index) { + this.elasticUtils.deleteIndex(index); } @Override diff --git a/testing/indexer-test-core/src/main/java/org/opengroup/osdu/models/TestIndex.java b/testing/indexer-test-core/src/main/java/org/opengroup/osdu/models/TestIndex.java index 0a5725afa..d10712707 100644 --- a/testing/indexer-test-core/src/main/java/org/opengroup/osdu/models/TestIndex.java +++ b/testing/indexer-test-core/src/main/java/org/opengroup/osdu/models/TestIndex.java @@ -19,7 +19,6 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.logging.Logger; -import org.opengroup.osdu.util.IndexerClientUtil; import static org.junit.Assert.assertEquals; import static org.opengroup.osdu.util.Config.*; @@ -39,7 +38,6 @@ public class TestIndex { private HTTPClient httpClient; private Map<String, String> headers; private ElasticUtils elasticUtils; - protected IndexerClientUtil indexerClient; private Gson gson = new Gson(); public TestIndex(ElasticUtils elasticUtils){ @@ -49,7 +47,6 @@ public class TestIndex { public void setHttpClient(HTTPClient httpClient) { this.httpClient = httpClient; headers = httpClient.getCommonHeader(); - indexerClient = new IndexerClientUtil(this.httpClient); } public void setupIndex() { @@ -76,7 +73,7 @@ public class TestIndex { } public void cleanupIndex() { - this.indexerClient.deleteIndex(kind); + this.elasticUtils.deleteIndex(index); } private String getRecordFile() { diff --git a/testing/indexer-test-gcp/src/test/java/org/opengroup/osdu/step_definitions/index/record/Steps.java b/testing/indexer-test-gcp/src/test/java/org/opengroup/osdu/step_definitions/index/record/Steps.java index 186a9fc4e..bc1ee68b4 100644 --- a/testing/indexer-test-gcp/src/test/java/org/opengroup/osdu/step_definitions/index/record/Steps.java +++ b/testing/indexer-test-gcp/src/test/java/org/opengroup/osdu/step_definitions/index/record/Steps.java @@ -11,6 +11,7 @@ import lombok.extern.java.Log; import org.opengroup.osdu.common.SchemaServiceRecordSteps; import org.opengroup.osdu.util.ElasticUtils; import org.opengroup.osdu.util.GCPHTTPClient; +import org.opengroup.osdu.util.GcpElasticUtils; @Log public class Steps extends SchemaServiceRecordSteps { @@ -23,6 +24,7 @@ public class Steps extends SchemaServiceRecordSteps { public void before(Scenario scenario) { this.scenario = scenario; this.httpClient = new GCPHTTPClient(); + this.elasticUtils = new GcpElasticUtils(this.httpClient); } @Given("^the schema is created with the following kind$") @@ -41,39 +43,41 @@ public class Steps extends SchemaServiceRecordSteps { } @Then("^I should get the elastic \"(.*?)\" for the \"([^\"]*)\" and \"([^\"]*)\" in the Elastic Search$") - public void i_should_get_the_elastic_for_the_tenant_testindex_timestamp_well_in_the_Elastic_Search(String expectedMapping, String type, String index) throws Throwable { + public void i_should_get_the_elastic_for_the_tenant_testindex_timestamp_well_in_the_Elastic_Search(String expectedMapping, String type, String index) + throws Throwable { super.i_should_get_the_elastic_for_the_tenant_testindex_timestamp_well_in_the_Elastic_Search(expectedMapping, type, index); } @Then("^I should get the (\\d+) documents for the \"([^\"]*)\" in the Elastic Search with out \"(.*?)\"$") - public void iShouldGetTheNumberDocumentsForTheIndexInTheElasticSearchWithOutSkippedAttribute(int expectedCount, String index, String skippedAttributes) throws Throwable { + public void iShouldGetTheNumberDocumentsForTheIndexInTheElasticSearchWithOutSkippedAttribute(int expectedCount, String index, String skippedAttributes) + throws Throwable { super.iShouldGetTheNumberDocumentsForTheIndexInTheElasticSearchWithOutSkippedAttribute(expectedCount, index, skippedAttributes); } -//TODO fix tags step -// @Then("^I should be able to search (\\d+) record with index \"([^\"]*)\" by tag \"([^\"]*)\" and value \"([^\"]*)\"$") -// public void iShouldBeAbleToSearchRecordByTagKeyAndTagValue(int expectedNumber, String index, String tagKey, String tagValue) throws Throwable { -// super.iShouldBeAbleToSearchRecordByTagKeyAndTagValue(index, tagKey, tagValue, expectedNumber); -// } -// @Then("^I should be able search (\\d+) documents for the \"([^\"]*)\" by bounding box query with points \\((-?\\d+), (-?\\d+)\\) and \\((-?\\d+), (-?\\d+)\\) on field \"([^\"]*)\"$") public void i_should_get_the_documents_for_the_in_the_Elastic_Search_by_geoQuery( - int expectedCount, String index, Double topLatitude, Double topLongitude, Double bottomLatitude, Double bottomLongitude, String field) throws Throwable { - super.i_should_get_the_documents_for_the_in_the_Elastic_Search_by_geoQuery(expectedCount, index, topLatitude, topLongitude, bottomLatitude, bottomLongitude, field); + int expectedCount, String index, Double topLatitude, Double topLongitude, Double bottomLatitude, Double bottomLongitude, String field) + throws Throwable { + String actualName = generateActualName(index, null); + super.i_should_get_the_documents_for_the_in_the_Elastic_Search_by_geoQuery(expectedCount, actualName, topLatitude, topLongitude, bottomLatitude, + bottomLongitude, field); } @Then("^I should be able search (\\d+) documents for the \"([^\"]*)\" by nested \"([^\"]*)\" and properties \\(\"([^\"]*)\", (\\d+)\\) and \\(\"([^\"]*)\", \"([^\"]*)\"\\)$") public void i_should_get_the_documents_for_the_in_the_Elastic_Search_by_nestedQuery( int expectedCount, String index, String path, String firstNestedProperty, String firstNestedValue, String secondNestedProperty, String secondNestedValue) throws Exception { - super.i_should_get_the_documents_for_the_in_the_Elastic_Search_by_nestedQuery(expectedCount, index, path, firstNestedProperty, firstNestedValue, + String actualName = generateActualName(index, null); + super.i_should_get_the_documents_for_the_in_the_Elastic_Search_by_nestedQuery(expectedCount, actualName, path, firstNestedProperty, firstNestedValue, secondNestedProperty, secondNestedValue); } @Then("^I should be able search (\\d+) documents for the \"([^\"]*)\" by flattened inner properties \\(\"([^\"]*)\", \"([^\"]*)\"\\)$") - public void i_should_be_able_search_documents_for_the_by_flattened_inner_properties(int expectedCount, String index, String flattenedField, String flattenedFieldValue) + public void i_should_be_able_search_documents_for_the_by_flattened_inner_properties(int expectedCount, String index, String flattenedField, + String flattenedFieldValue) throws IOException, InterruptedException { - super.i_should_be_able_search_documents_for_the_by_flattened_inner_properties(expectedCount,index,flattenedField,flattenedFieldValue); + String actualName = generateActualName(index, null); + super.i_should_be_able_search_documents_for_the_by_flattened_inner_properties(expectedCount, actualName, flattenedField, flattenedFieldValue); } } \ No newline at end of file diff --git a/testing/indexer-test-gcp/src/test/java/org/opengroup/osdu/util/GcpElasticUtils.java b/testing/indexer-test-gcp/src/test/java/org/opengroup/osdu/util/GcpElasticUtils.java new file mode 100644 index 000000000..ce781c6e8 --- /dev/null +++ b/testing/indexer-test-gcp/src/test/java/org/opengroup/osdu/util/GcpElasticUtils.java @@ -0,0 +1,20 @@ +package org.opengroup.osdu.util; + +public class GcpElasticUtils extends ElasticUtils { + + private IndexerClientUtil indexerClientUtil; + + public GcpElasticUtils(HTTPClient httpClient) { + super(); + this.indexerClientUtil = new IndexerClientUtil(httpClient); + } + + @Override + public void deleteIndex(String index) { + indexerClientUtil.deleteIndex(convertIndexToKindName(index)); + } + + private String convertIndexToKindName(String index) { + return index.replaceAll("-",":"); + } +} -- GitLab