diff --git a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/di/EntitlementsClientFactory.java b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/di/EntitlementsClientFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..dd7cbd1efa355aebf59aab8b148371afa29f8569 --- /dev/null +++ b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/di/EntitlementsClientFactory.java @@ -0,0 +1,58 @@ +// Copyright © Amazon Web Services +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + + +package org.opengroup.osdu.indexer.aws.di; + +import org.opengroup.osdu.core.common.entitlements.EntitlementsAPIConfig; +import org.opengroup.osdu.core.common.entitlements.EntitlementsFactory; +import org.opengroup.osdu.core.common.entitlements.IEntitlementsFactory; +import org.opengroup.osdu.core.common.http.json.HttpResponseBodyMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.beans.factory.config.AbstractFactoryBean; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Component; +import org.springframework.web.context.annotation.RequestScope; + +@Component +@RequestScope +@Lazy +public class EntitlementsClientFactory extends AbstractFactoryBean<IEntitlementsFactory> { + + @Value("${AUTHORIZE_API}") + private String AUTHORIZE_API; + + @Value("${AUTHORIZE_API_KEY:}") + private String AUTHORIZE_API_KEY; + + @Autowired + private HttpResponseBodyMapper mapper; + + @Override + protected IEntitlementsFactory createInstance() throws Exception { + + return new EntitlementsFactory(EntitlementsAPIConfig + .builder() + .rootUrl(AUTHORIZE_API) + .apiKey(AUTHORIZE_API_KEY) + .build(), + mapper); + } + + @Override + public Class<?> getObjectType() { + return IEntitlementsFactory.class; + } +} \ No newline at end of file diff --git a/testing/indexer-test-aws/src/test/java/org/opengroup/osdu/step_definitions/index/cleanup/RunTest.java b/testing/indexer-test-aws/src/test/java/org/opengroup/osdu/step_definitions/index/cleanup/RunTest.java new file mode 100644 index 0000000000000000000000000000000000000000..ccf35e02cffb041fdf0582ae87e6891028947543 --- /dev/null +++ b/testing/indexer-test-aws/src/test/java/org/opengroup/osdu/step_definitions/index/cleanup/RunTest.java @@ -0,0 +1,27 @@ +// Copyright © Amazon Web Services +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.opengroup.osdu.step_definitions.index.cleanup; + +import cucumber.api.CucumberOptions; +import cucumber.api.junit.Cucumber; +import org.junit.runner.RunWith; + +@RunWith(Cucumber.class) +@CucumberOptions( + features = "classpath:features/indexcleanup/IndexCleanup.feature", + glue = {"classpath:org.opengroup.osdu.step_definitions/index/cleanup"}, + plugin = {"pretty", "junit:target/cucumber-reports/TEST-indexcleanup.xml"}) +public class RunTest { +} \ No newline at end of file diff --git a/testing/indexer-test-aws/src/test/java/org/opengroup/osdu/step_definitions/index/cleanup/Steps.java b/testing/indexer-test-aws/src/test/java/org/opengroup/osdu/step_definitions/index/cleanup/Steps.java new file mode 100644 index 0000000000000000000000000000000000000000..b69fd683d35214a73fd9c268e6dcb879d95f97c8 --- /dev/null +++ b/testing/indexer-test-aws/src/test/java/org/opengroup/osdu/step_definitions/index/cleanup/Steps.java @@ -0,0 +1,113 @@ +// Copyright © Amazon Web Services +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + + +package org.opengroup.osdu.step_definitions.index.cleanup; + +import cucumber.api.DataTable; +import cucumber.api.Scenario; +import cucumber.api.java.Before; +import cucumber.api.java.en.Given; +import cucumber.api.java.en.Then; +import cucumber.api.java.en.When; +import java.io.IOException; +import java.util.HashSet; +import java.util.Set; + +import lombok.extern.java.Log; +import org.opengroup.osdu.common.CleanupIndiciesSteps; +import org.opengroup.osdu.core.common.model.legal.Legal; +import org.opengroup.osdu.util.AWSHTTPClient; +import org.opengroup.osdu.util.LegalTagUtilsAws; +import org.opengroup.osdu.util.ElasticUtilsAws; + +import static org.opengroup.osdu.util.Config.getOtherRelevantDataCountries; + +@Log +public class Steps extends CleanupIndiciesSteps { + + protected LegalTagUtilsAws legalTagUtils; + private String legalTagName; + + public Steps() { + super(new AWSHTTPClient(), new ElasticUtilsAws()); + } + + @Before + public void before(Scenario scenario) throws Exception { + this.scenario = scenario; + this.httpClient = new AWSHTTPClient(); + legalTagUtils = new LegalTagUtilsAws(this.httpClient); + this.legalTagName = this.legalTagUtils.createRandomName(); + this.legalTagUtils.create(this.legalTagName); + } + + @Override + public void tearDown() { + super.tearDown(); + this.legalTagUtils.delete(this.legalTagName); + } + + @Override + protected Legal generateLegalTag() { + Legal legal = new Legal(); + Set<String> legalTags = new HashSet<>(); + legalTags.add(this.legalTagName); + legal.setLegaltags(legalTags); + Set<String> otherRelevantCountries = new HashSet<>(); + otherRelevantCountries.add(getOtherRelevantDataCountries()); + legal.setOtherRelevantDataCountries(otherRelevantCountries); + return legal; + } + + @Given("^the schema is created with the following kind$") + public void theSchemaIsCreatedWithTheFollowingKind(DataTable dataTable) { + super.theSchemaIsCreatedWithTheFollowingKind(dataTable); + } + + @When("^I ingest records with the \"(.*?)\" with \"(.*?)\" for a given \"(.*?)\"$") + public void iIngestRecordsWithTheforAGiven(String record, String dataGroup, String kind) { + super.iIngestRecordsWithTheforAGiven(record, dataGroup, kind); + } + + @Then("^I check that the index for \"(.*?)\" has been created$") + public void iCheckThatTheIndexForHasBeenCreated(String kind) throws IOException, InterruptedException { + super.iCheckThatTheIndexForHasBeenCreated(kind); + } + + @Then("^I should delete the records I created earlier$") + public void iShouldDeleteTheRecordsForICreatedEarlier() { + super.iShouldDeleteTheRecordsForICreatedEarlier(); + } + + @Then("^I should delete the schema for \"(.*?)\" I created earlier$") + public void iShouldDeleteTheSchemaForICreatedEarlier(String kind) { + super.iShouldDeleteTheSchemaForICreatedEarlier(kind); + } + + @Then("^I should check that the index for \"(.*?)\" has not been deleted$") + public void iShouldCheckThetTheIndexforHasNotBeenDeleted(String kind) throws IOException, InterruptedException { + super.iShouldCheckThetTheIndexforHasNotBeenDeleted(kind); + } + + @Then("^I should to run cleanup of indexes for \"(.*?)\" and \"(.*?)\"$") + public void iShouldToRunCleanupOfIndexesForAnd(String kind, String message) { + super.iShouldToRunCleanupOfIndexesForAnd(kind, message); + } + + @Then("^I should check that the index for \"(.*?)\" has been deleted$") + public void iShouldCheckThatTheIndexForHasBeenDeleted(String kind) throws IOException, InterruptedException { + super.iShouldCheckThatTheIndexForHasBeenDeleted(kind); + } +} \ No newline at end of file diff --git a/testing/indexer-test-core/src/main/java/org/opengroup/osdu/common/CleanupIndiciesSteps.java b/testing/indexer-test-core/src/main/java/org/opengroup/osdu/common/CleanupIndiciesSteps.java index b1f4377b50e9fc71d76e064b91bd716dcbc0d5dc..d15a6668d90540a862167070018333599feb1143 100644 --- a/testing/indexer-test-core/src/main/java/org/opengroup/osdu/common/CleanupIndiciesSteps.java +++ b/testing/indexer-test-core/src/main/java/org/opengroup/osdu/common/CleanupIndiciesSteps.java @@ -42,6 +42,7 @@ import org.opengroup.osdu.models.Setup; import org.opengroup.osdu.models.TestIndex; import org.opengroup.osdu.util.FileHandler; import org.opengroup.osdu.util.HTTPClient; +import org.opengroup.osdu.util.ElasticUtils; @Log public class CleanupIndiciesSteps extends TestsBase { @@ -55,6 +56,11 @@ public class CleanupIndiciesSteps extends TestsBase { super(httpClient); } + public CleanupIndiciesSteps(HTTPClient httpClient, ElasticUtils elasticUtils) { + super(httpClient, elasticUtils); + } + + public void theSchemaIsCreatedWithTheFollowingKind(DataTable dataTable) { List<Setup> inputList = dataTable.asList(Setup.class); for (Setup input : inputList) {