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 4ab3a430f6a32a9d75232eef30b6787f54589db0..ebfaba6b5ef99eaf3a5429799057d459172c5063 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 @@ -53,7 +53,7 @@ public class RecordSteps extends TestsBase { public void tearDown() { for (String kind : inputIndexMap.keySet()) { TestIndex testIndex = inputIndexMap.get(kind); - testIndex.cleanupIndex(); + testIndex.cleanupIndex(kind); testIndex.deleteSchema(kind); } 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 993c26b25b545bcac741b7de314e31b6bd8ed984..af48584f1b8e315f0435c65d78442913b8cbfd6f 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 @@ -17,12 +17,11 @@ public class SchemaServiceRecordSteps extends RecordSteps { 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.getIndex()))); + inputList.forEach(this::setup); super.addShutDownHook(); } - private void createSchema(Setup input) { + private void setup(Setup input) { PersistentSchemaTestIndex testIndex = new PersistentSchemaTestIndex(super.elasticUtils, super.httpClient, this); testIndex.setIndex(generateActualName(input.getIndex(), super.getTimeStamp())); testIndex.setSchemaFile(input.getSchemaFile()); @@ -31,10 +30,12 @@ public class SchemaServiceRecordSteps extends RecordSteps { testIndex.setKind(testIndex.getSchemaModel().getSchemaInfo().getSchemaIdentity().getId()); super.getInputIndexMap().put(testIndex.getKind(), testIndex); + + deleteIndex(testIndex.getKind()); } - private void deleteIndex(String index) { - this.elasticUtils.deleteIndex(index); + private void deleteIndex(String kind) { + this.indexerClientUtil.deleteIndex(kind); } @Override diff --git a/testing/indexer-test-core/src/main/java/org/opengroup/osdu/common/TestsBase.java b/testing/indexer-test-core/src/main/java/org/opengroup/osdu/common/TestsBase.java index 2b8d960eccc3cc1a934e480e9e2d6b31c725be47..c441a25ed892793d9ff5885c3d36a5382e8f0f15 100644 --- a/testing/indexer-test-core/src/main/java/org/opengroup/osdu/common/TestsBase.java +++ b/testing/indexer-test-core/src/main/java/org/opengroup/osdu/common/TestsBase.java @@ -12,6 +12,7 @@ import org.opengroup.osdu.util.HTTPClient; import com.sun.jersey.api.client.ClientResponse; import cucumber.api.Scenario; import lombok.extern.java.Log; +import org.opengroup.osdu.util.IndexerClientUtil; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedMap; @@ -28,6 +29,7 @@ public abstract class TestsBase { protected Map<String, String> tenantMap = new HashMap<>(); protected Map<String, TestIndex> inputRecordMap = new HashMap<>(); protected ElasticUtils elasticUtils; + protected IndexerClientUtil indexerClientUtil; public TestsBase(HTTPClient httpClient) { this.httpClient = httpClient; @@ -36,6 +38,7 @@ public abstract class TestsBase { tenantMap.put("common", "common"); elasticUtils = new ElasticUtils(); + this.indexerClientUtil = new IndexerClientUtil(this.httpClient); } public TestsBase(HTTPClient httpClient, ElasticUtils elasticUtils) { @@ -45,6 +48,7 @@ public abstract class TestsBase { tenantMap.put("common", "common"); this.elasticUtils = elasticUtils; + this.indexerClientUtil = new IndexerClientUtil(this.httpClient); } protected TestIndex getTextIndex(){ @@ -94,7 +98,7 @@ public abstract class TestsBase { public void tearDown() { for (String kind : inputRecordMap.keySet()) { TestIndex testIndex = inputRecordMap.get(kind); - testIndex.cleanupIndex(); + testIndex.cleanupIndex(kind); } } 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 d10712707e051e24f5fb8c79d9d500cf653d5646..0bc1eae64f034cfebe4ded22f9e999e39c3ec782 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 @@ -13,6 +13,7 @@ import org.opengroup.osdu.core.common.model.legal.Legal; import org.opengroup.osdu.util.ElasticUtils; import org.opengroup.osdu.util.FileHandler; import org.opengroup.osdu.util.HTTPClient; +import org.opengroup.osdu.util.IndexerClientUtil; import java.util.HashSet; import java.util.List; @@ -38,6 +39,7 @@ public class TestIndex { private HTTPClient httpClient; private Map<String, String> headers; private ElasticUtils elasticUtils; + private IndexerClientUtil indexerClientUtil; private Gson gson = new Gson(); public TestIndex(ElasticUtils elasticUtils){ @@ -47,6 +49,7 @@ public class TestIndex { public void setHttpClient(HTTPClient httpClient) { this.httpClient = httpClient; headers = httpClient.getCommonHeader(); + this.indexerClientUtil = new IndexerClientUtil(this.httpClient); } public void setupIndex() { @@ -72,8 +75,8 @@ public class TestIndex { this.elasticUtils.createIndex(this.index, this.getIndexMappingFromJson()); } - public void cleanupIndex() { - this.elasticUtils.deleteIndex(index); + public void cleanupIndex(String kind) { + this.indexerClientUtil.deleteIndex(kind); } private String getRecordFile() { diff --git a/testing/indexer-test-core/src/main/java/org/opengroup/osdu/util/IndexerClientUtil.java b/testing/indexer-test-core/src/main/java/org/opengroup/osdu/util/IndexerClientUtil.java index 33771a92bcf0bf93852027e1a63e722d9cfd5752..4ebd244273344b3d23aa38610a130268a4d7e782 100644 --- a/testing/indexer-test-core/src/main/java/org/opengroup/osdu/util/IndexerClientUtil.java +++ b/testing/indexer-test-core/src/main/java/org/opengroup/osdu/util/IndexerClientUtil.java @@ -1,20 +1,16 @@ package org.opengroup.osdu.util; -import static org.opengroup.osdu.util.Config.getDataPartitionIdTenant1; -import static org.opengroup.osdu.util.Config.getIndexerBaseURL; - -import com.google.gson.Gson; import com.sun.jersey.api.client.ClientResponse; -import java.util.Map; -import javax.ws.rs.HttpMethod; import lombok.extern.java.Log; -import org.opengroup.osdu.core.common.model.search.RecordChangedMessages; + +import javax.ws.rs.HttpMethod; +import java.util.Map; + +import static org.opengroup.osdu.util.Config.getIndexerBaseURL; @Log public class IndexerClientUtil { - private final String purgeMessage = "{\"data\":\"[{\\\"kind\\\":\\\"%s\\\",\\\"op\\\":\\\"purge_schema\\\"}]\",\"attributes\":{\"account-id\":\"%s\"}}"; - private final HTTPClient httpClient; private Map<String, String> headers; @@ -24,15 +20,9 @@ public class IndexerClientUtil { } public void deleteIndex(String kind) { - String url = getIndexerBaseURL() + "index-cleanup"; + String url = getIndexerBaseURL() + "index?kind=" + kind; log.info("URL: " + url); - ClientResponse response = httpClient.send(HttpMethod.POST, url, convertMessageIntoJson(kind), headers, httpClient.getAccessToken()); + ClientResponse response = httpClient.send(HttpMethod.DELETE, url, "", headers, httpClient.getAccessToken()); log.info(response.toString()); } - - private String convertMessageIntoJson(String kind) { - RecordChangedMessages - recordChangedMessages = (new Gson()).fromJson(String.format(purgeMessage, kind, getDataPartitionIdTenant1()), RecordChangedMessages.class); - return new Gson().toJson(recordChangedMessages); - } } 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 3a3cdd3cab71937ba02f1a2a05b71eca3a430f47..a01ca063d369d546a19d52e69470784459f5b70c 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 @@ -10,7 +10,6 @@ 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,7 +22,6 @@ 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$") 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 deleted file mode 100644 index ce781c6e8cafb3cd208c52e6ca86e5c670ce2a2e..0000000000000000000000000000000000000000 --- a/testing/indexer-test-gcp/src/test/java/org/opengroup/osdu/util/GcpElasticUtils.java +++ /dev/null @@ -1,20 +0,0 @@ -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("-",":"); - } -}