diff --git a/NOTICE b/NOTICE index 136a6e36f4ca81e59ceb5686a8a6f8b288d7ea6b..781f0e1ad1fd9dd40dc39566ab6573cdd5082d47 100644 --- a/NOTICE +++ b/NOTICE @@ -215,11 +215,11 @@ The following software have components provided under the terms of this license: - AWS Java SDK for Amazon EMR (from https://aws.amazon.com/sdkforjava) - AWS Java SDK for Amazon EMR Containers (from https://aws.amazon.com/sdkforjava) - AWS Java SDK for Amazon ElastiCache (from https://aws.amazon.com/sdkforjava) -- AWS Java SDK for Amazon Elastic Inference (from https://aws.amazon.com/sdkforjava) - AWS Java SDK for Amazon Elastic Block Store (from https://aws.amazon.com/sdkforjava) - AWS Java SDK for Amazon Elastic Container Registry Public (from https://aws.amazon.com/sdkforjava) - AWS Java SDK for Amazon Elastic Container Service for Kubernetes (from https://aws.amazon.com/sdkforjava) - AWS Java SDK for Amazon Elastic File System (from https://aws.amazon.com/sdkforjava) +- AWS Java SDK for Amazon Elastic Inference (from https://aws.amazon.com/sdkforjava) - AWS Java SDK for Amazon Elastic Transcoder (from https://aws.amazon.com/sdkforjava) - AWS Java SDK for Amazon Elasticsearch Service (from https://aws.amazon.com/sdkforjava) - AWS Java SDK for Amazon EventBridge (from https://aws.amazon.com/sdkforjava) @@ -335,9 +335,9 @@ The following software have components provided under the terms of this license: - Apache Groovy (from http://groovy-lang.org, http://groovy.codehaus.org/, https://groovy-lang.org) - Apache HTTP transport v2 for the Google HTTP Client Library for Java. (from https://repo1.maven.org/maven2/com/google/http-client/google-http-client-apache-v2) - Apache HttpAsyncClient (from http://hc.apache.org/httpcomponents-asyncclient) -- Apache HttpClient (from http://hc.apache.org/httpcomponents-client) -- Apache HttpClient Cache (from http://hc.apache.org/httpcomponents-client) -- Apache HttpCore (from http://hc.apache.org/httpcomponents-core-ga, http://hc.apache.org/httpcomponents-core-ga/) +- Apache HttpClient (from http://hc.apache.org/httpcomponents-client, http://hc.apache.org/httpcomponents-client-ga) +- Apache HttpClient Cache (from http://hc.apache.org/httpcomponents-client, http://hc.apache.org/httpcomponents-client-ga) +- Apache HttpCore (from http://hc.apache.org/httpcomponents-core-ga, http://hc.apache.org/httpcomponents-core-ga/, http://hc.apache.org/httpcomponents-core/) - Apache HttpCore NIO (from http://hc.apache.org/httpcomponents-core-ga, http://hc.apache.org/httpcomponents-core/) - Apache Log4j API (from https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-api) - Apache Log4j Core (from https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-core) @@ -345,9 +345,9 @@ The following software have components provided under the terms of this license: - Apache Log4j SLF4J Binding (from https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-slf4j-impl) - Apache Log4j to SLF4J Adapter (from https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-to-slf4j) - Apache Lucene (module: memory) (from https://lucene.apache.org/) -- Apache Lucene (module: misc) (from https://lucene.apache.org/) -- Apache Lucene (module: spatial-extras) (from https://lucene.apache.org/) -- Apache Lucene (module: suggest) (from https://lucene.apache.org/) +- Apache Lucene (module: misc) (from https://lucene.apache.org/, https://repo1.maven.org/maven2/org/apache/lucene/lucene-misc) +- Apache Lucene (module: spatial-extras) (from https://lucene.apache.org/, https://repo1.maven.org/maven2/org/apache/lucene/lucene-spatial-extras) +- Apache Lucene (module: suggest) (from https://lucene.apache.org/, https://repo1.maven.org/maven2/org/apache/lucene/lucene-suggest) - Apache Maven Invoker (from https://repo1.maven.org/maven2/org/apache/maven/shared/maven-invoker) - Apache Maven Reporting API (from https://repo1.maven.org/maven2/org/apache/maven/reporting/maven-reporting-api) - Apache Maven Reporting Implementation (from https://repo1.maven.org/maven2/org/apache/maven/reporting/maven-reporting-impl) @@ -372,8 +372,8 @@ The following software have components provided under the terms of this license: - Byte Buddy (without dependencies) (from https://repo1.maven.org/maven2/net/bytebuddy/byte-buddy) - Byte Buddy Java agent (from https://repo1.maven.org/maven2/net/bytebuddy/byte-buddy-agent) - ClassMate (from http://github.com/cowtowncoder/java-classmate) -- Cloud Key Management Service (KMS) API v1-rev20221107-2.0.0 (from https://repo1.maven.org/maven2/com/google/apis/google-api-services-cloudkms) -- Cloud Storage JSON API v1-rev20220705-2.0.0 (from https://repo1.maven.org/maven2/com/google/apis/google-api-services-storage) +- Cloud Key Management Service (KMS) API (from https://repo1.maven.org/maven2/com/google/apis/google-api-services-cloudkms) +- Cloud Storage JSON API (from https://repo1.maven.org/maven2/com/google/apis/google-api-services-storage) - CloudWatch Metrics for AWS Java SDK (from https://aws.amazon.com/sdkforjava) - Cobertura (from http://cobertura.sourceforge.net) - Cobertura Limited Runtime (from http://cobertura.sourceforge.net) @@ -400,7 +400,7 @@ The following software have components provided under the terms of this license: - Google Cloud Core HTTP (from https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-core-http, https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-http, https://github.com/googleapis/java-core) - Google Cloud Core gRPC (from https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc, https://github.com/googleapis/java-core) - Google Cloud Datastore (from https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-datastore, https://github.com/googleapis/java-datastore) -- Google Cloud IAM Service Account Credentials (from https://github.com/googleapis/java-iamcredentials) +- Google Cloud IAM Service Account Credentials (from https://github.com/googleapis/google-cloud-java, https://github.com/googleapis/java-iamcredentials) - Google Cloud Logging (from https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-logging, https://github.com/googleapis/java-logging) - Google Cloud Pub/Sub (from https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-pubsub, https://github.com/googleapis/java-pubsub) - Google Cloud Storage (from https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-storage, https://github.com/googleapis/java-storage) @@ -663,7 +663,7 @@ The following software have components provided under the terms of this license: - parent-join (from https://github.com/elastic/elasticsearch) - perfmark:perfmark-api (from https://github.com/perfmark/perfmark) - proto-google-cloud-datastore-v1 (from https://github.com/googleapis/googleapis, https://github.com/googleapis/java-datastore/proto-google-cloud-datastore-v1) -- proto-google-cloud-iamcredentials-v1 (from https://github.com/googleapis/java-iamcredentials/proto-google-cloud-iamcredentials-v1, https://repo1.maven.org/maven2/com/google/api/grpc/proto-google-cloud-iamcredentials-v1) +- proto-google-cloud-iamcredentials-v1 (from https://github.com/googleapis/google-cloud-java, https://github.com/googleapis/java-iamcredentials/proto-google-cloud-iamcredentials-v1, https://repo1.maven.org/maven2/com/google/api/grpc/proto-google-cloud-iamcredentials-v1) - proto-google-cloud-logging-v2 (from https://github.com/googleapis/java-logging/proto-google-cloud-logging-v2, https://repo1.maven.org/maven2/com/google/api/grpc/proto-google-cloud-logging-v2) - proto-google-cloud-pubsub-v1 (from https://github.com/googleapis/googleapis, https://github.com/googleapis/java-pubsub/proto-google-cloud-pubsub-v1) - proto-google-common-protos (from https://github.com/googleapis/api-client-staging, https://github.com/googleapis/googleapis, https://github.com/googleapis/java-iam/proto-google-common-protos) @@ -698,9 +698,9 @@ The following software have components provided under the terms of this license: - API Common (from https://github.com/googleapis, https://github.com/googleapis/api-common-java) - Apache Lucene (module: memory) (from https://lucene.apache.org/) -- Apache Lucene (module: misc) (from https://lucene.apache.org/) -- Apache Lucene (module: spatial-extras) (from https://lucene.apache.org/) -- Apache Lucene (module: suggest) (from https://lucene.apache.org/) +- Apache Lucene (module: misc) (from https://lucene.apache.org/, https://repo1.maven.org/maven2/org/apache/lucene/lucene-misc) +- Apache Lucene (module: spatial-extras) (from https://lucene.apache.org/, https://repo1.maven.org/maven2/org/apache/lucene/lucene-spatial-extras) +- Apache Lucene (module: suggest) (from https://lucene.apache.org/, https://repo1.maven.org/maven2/org/apache/lucene/lucene-suggest) - GAX (Google Api eXtensions) for Java (Core) (from https://repo1.maven.org/maven2/com/google/api/gax) - GAX (Google Api eXtensions) for Java (HTTP JSON) (from https://repo1.maven.org/maven2/com/google/api/gax-httpjson) - GAX (Google Api eXtensions) for Java (gRPC) (from https://repo1.maven.org/maven2/com/google/api/gax-grpc) @@ -736,9 +736,9 @@ The following software have components provided under the terms of this license: - ASM Tree (from http://asm.ow2.io/) - ASM Util (from http://asm.ow2.io/) - Apache Lucene (module: memory) (from https://lucene.apache.org/) -- Apache Lucene (module: misc) (from https://lucene.apache.org/) -- Apache Lucene (module: spatial-extras) (from https://lucene.apache.org/) -- Apache Lucene (module: suggest) (from https://lucene.apache.org/) +- Apache Lucene (module: misc) (from https://lucene.apache.org/, https://repo1.maven.org/maven2/org/apache/lucene/lucene-misc) +- Apache Lucene (module: spatial-extras) (from https://lucene.apache.org/, https://repo1.maven.org/maven2/org/apache/lucene/lucene-spatial-extras) +- Apache Lucene (module: suggest) (from https://lucene.apache.org/, https://repo1.maven.org/maven2/org/apache/lucene/lucene-suggest) - AspectJ Weaver (from http://www.aspectj.org, https://www.eclipse.org/aspectj/) - Class Model for Hk2 (from https://repo1.maven.org/maven2/org/glassfish/hk2/class-model) - GAX (Google Api eXtensions) for Java (Core) (from https://repo1.maven.org/maven2/com/google/api/gax) @@ -1123,15 +1123,15 @@ The following software have components provided under the terms of this license: - AWS Java SDK for AWS Lambda (from https://aws.amazon.com/sdkforjava) - Animal Sniffer Annotations (from https://repo1.maven.org/maven2/org/codehaus/mojo/animal-sniffer-annotations) -- Apache HttpClient Cache (from http://hc.apache.org/httpcomponents-client) +- Apache HttpClient Cache (from http://hc.apache.org/httpcomponents-client, http://hc.apache.org/httpcomponents-client-ga) - Apache Log4j API (from https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-api) - Apache Log4j Core (from https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-core) - Apache Log4j SLF4J Binding (from https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-slf4j-impl) - Apache Log4j to SLF4J Adapter (from https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-to-slf4j) - Apache Lucene (module: memory) (from https://lucene.apache.org/) -- Apache Lucene (module: misc) (from https://lucene.apache.org/) -- Apache Lucene (module: spatial-extras) (from https://lucene.apache.org/) -- Apache Lucene (module: suggest) (from https://lucene.apache.org/) +- Apache Lucene (module: misc) (from https://lucene.apache.org/, https://repo1.maven.org/maven2/org/apache/lucene/lucene-misc) +- Apache Lucene (module: spatial-extras) (from https://lucene.apache.org/, https://repo1.maven.org/maven2/org/apache/lucene/lucene-spatial-extras) +- Apache Lucene (module: suggest) (from https://lucene.apache.org/, https://repo1.maven.org/maven2/org/apache/lucene/lucene-suggest) - Azure Java Client Authentication Library for AutoRest (from https://github.com/Azure/autorest-clientruntime-for-java) - Azure Java Client Runtime for ARM (from https://github.com/Azure/autorest-clientruntime-for-java) - Azure Java Client Runtime for AutoRest (from https://github.com/Azure/autorest-clientruntime-for-java) @@ -1283,9 +1283,9 @@ X11 The following software have components provided under the terms of this license: - Apache Lucene (module: memory) (from https://lucene.apache.org/) -- Apache Lucene (module: misc) (from https://lucene.apache.org/) -- Apache Lucene (module: spatial-extras) (from https://lucene.apache.org/) -- Apache Lucene (module: suggest) (from https://lucene.apache.org/) +- Apache Lucene (module: misc) (from https://lucene.apache.org/, https://repo1.maven.org/maven2/org/apache/lucene/lucene-misc) +- Apache Lucene (module: spatial-extras) (from https://lucene.apache.org/, https://repo1.maven.org/maven2/org/apache/lucene/lucene-spatial-extras) +- Apache Lucene (module: suggest) (from https://lucene.apache.org/, https://repo1.maven.org/maven2/org/apache/lucene/lucene-suggest) - Lucene Common Analyzers (from https://repo1.maven.org/maven2/org/apache/lucene/lucene-analyzers-common) - Lucene Grouping (from https://lucene.apache.org/, https://repo1.maven.org/maven2/org/apache/lucene/lucene-grouping) - Lucene Highlighter (from https://lucene.apache.org/, https://repo1.maven.org/maven2/org/apache/lucene/lucene-highlighter) diff --git a/provider/indexer-azure/pom.xml b/provider/indexer-azure/pom.xml index 7d6b176131067cf510404aed6cd580bb9dbe5155..7d22014ce9f02195aabbf5755e95821dbd785379 100644 --- a/provider/indexer-azure/pom.xml +++ b/provider/indexer-azure/pom.xml @@ -389,6 +389,25 @@ </execution> </executions> </plugin> + <plugin> + <groupId>org.jacoco</groupId> + <artifactId>jacoco-maven-plugin</artifactId> + <version>0.8.2</version> + <executions> + <execution> + <goals> + <goal>prepare-agent</goal> + </goals> + </execution> + <execution> + <id>report</id> + <phase>prepare-package</phase> + <goals> + <goal>report</goal> + </goals> + </execution> + </executions> + </plugin> <plugin> <groupId>com.microsoft.azure</groupId> <artifactId>azure-webapp-maven-plugin</artifactId> @@ -429,8 +448,32 @@ <threadCount>1</threadCount> </configuration> </plugin> + <plugin> + <groupId>org.jacoco</groupId> + <artifactId>jacoco-maven-plugin</artifactId> + <configuration> + <excludes> + <exclude>**/cache/*</exclude> + <exclude>**/security/*</exclude> + </excludes> + </configuration> + </plugin> </plugins> </build> - - + <reporting> + <plugins> + <plugin> + <groupId>org.jacoco</groupId> + <artifactId>jacoco-maven-plugin</artifactId> + <reportSets> + <reportSet> + <reports> + <!-- select non-aggregate reports --> + <report>report</report> + </reports> + </reportSet> + </reportSets> + </plugin> + </plugins> + </reporting> </project> diff --git a/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/IndexerAzureApplicationTest.java b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/IndexerAzureApplicationTest.java new file mode 100644 index 0000000000000000000000000000000000000000..6d38bc8f2150ee3d1fb06fc9fae04e754298915d --- /dev/null +++ b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/IndexerAzureApplicationTest.java @@ -0,0 +1,16 @@ +package org.opengroup.osdu.indexer.azure; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; + +import static org.junit.jupiter.api.Assertions.*; + +@RunWith(MockitoJUnitRunner.class) +public class IndexerAzureApplicationTest { + + @Test + public void shouldReturn_notNullInstance_when_creatingNewObject() { + assertNotNull(new IndexerAzureApplication()); + } +} diff --git a/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/di/EntitlementsClientFactoryTest.java b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/di/EntitlementsClientFactoryTest.java new file mode 100644 index 0000000000000000000000000000000000000000..22b3b071ddd3879c42fd7a9f58adfe50875f8d99 --- /dev/null +++ b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/di/EntitlementsClientFactoryTest.java @@ -0,0 +1,47 @@ +package org.opengroup.osdu.indexer.azure.di; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; +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.test.util.ReflectionTestUtils; +import static org.junit.jupiter.api.Assertions.*; + +@RunWith(MockitoJUnitRunner.class) +public class EntitlementsClientFactoryTest { + + private static String authorizeApi = "authorizeApi"; + private static String authorizeApiKey = "authorizeApiKey"; + + @Mock + private HttpResponseBodyMapper mapper; + + @InjectMocks + public EntitlementsClientFactory sut; + + @BeforeEach + public void setUp() { + MockitoAnnotations.openMocks(EntitlementsClientFactoryTest.this); + ReflectionTestUtils.setField(sut, authorizeApi, authorizeApi); + ReflectionTestUtils.setField(sut, authorizeApiKey, authorizeApiKey); + } + + @Test + public void shouldReturn_notNull_EntitlementFactory_when_createInstance_isCalled() throws Exception{ + IEntitlementsFactory entitlementFactory = sut.createInstance(); + assertNotNull(entitlementFactory); + } + + @Test + public void shouldReturn_IEntitlementFactoryClass_when_getObjectType_isCalled() { + Class<?> responseClass = sut.getObjectType(); + assertEquals(responseClass, IEntitlementsFactory.class); + } +} diff --git a/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/di/RedisConfigTest.java b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/di/RedisConfigTest.java new file mode 100644 index 0000000000000000000000000000000000000000..c7b56ccf4a20c8da1ac253cc3c6a2be62961118e --- /dev/null +++ b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/di/RedisConfigTest.java @@ -0,0 +1,59 @@ +package org.opengroup.osdu.indexer.azure.di; + +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.mockito.Spy; +import org.springframework.beans.factory.annotation.Value; +import static org.junit.jupiter.api.Assertions.*; + +public class RedisConfigTest { + @Spy + @Value("5000") + private int port; + + @Mock + @Value("4000") + public int indexRedisTtl; + + @Mock + @Value("3000") + public int jwtTtl; + + @Mock + @Value("2000") + public int schemaTtl; + + @InjectMocks + public RedisConfig sut = new RedisConfig(); + + public void setup() + { + MockitoAnnotations.openMocks(RedisConfigTest.this); + } + + @Test + public void shouldReturnPort_whenGetRedisPortCalled() { + int port_val = sut.getRedisPort(); + assertEquals(port_val, port); + } + + @Test + public void shouldReturnSetValue_when_GetIndexRedisTtl_isCalled() { + int indexRedisTtl_val = sut.getIndexRedisTtl(); + assertEquals(indexRedisTtl_val, indexRedisTtl); + } + + @Test + public void shouldReturnSetValue_when_GetJwtRedisTtl_isCalled() { + int jwtTtl_val = sut.getJwtRedisTtl(); + assertEquals(jwtTtl_val, jwtTtl); + } + + @Test + public void shouldReturnSetValue_when_GetSchemaRedisTtl_isCalled() { + int schemaTtl_val = sut.getSchemaRedisTtl(); + assertEquals(schemaTtl_val, schemaTtl); + } +} diff --git a/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/di/TenantInfoServiceTest.java b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/di/TenantInfoServiceTest.java new file mode 100644 index 0000000000000000000000000000000000000000..047c1d401d65f53a011ffdfbc9c5a10ea76cfcc3 --- /dev/null +++ b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/di/TenantInfoServiceTest.java @@ -0,0 +1,57 @@ +package org.opengroup.osdu.indexer.azure.di; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.model.tenant.TenantInfo; +import org.opengroup.osdu.core.common.provider.interfaces.ITenantFactory; +import javax.inject.Inject; +import java.util.ArrayList; +import java.util.List; +import static org.junit.jupiter.api.Assertions.*; +import static reactor.core.publisher.Mono.when; + +@RunWith(MockitoJUnitRunner.class) +public class TenantInfoServiceTest { + + @Mock + private ITenantFactory tenantFactory; + + @Mock + private DpsHeaders headers; + + @InjectMocks + TenantInfoService sut; + + @BeforeEach + public void setUp() { + MockitoAnnotations.openMocks(TenantInfoServiceTest.this); + } + + @Test + public void shouldReturnSetValue_when_getTenantInfo_isCalled() { + TenantInfo tenantInfo = new TenantInfo(); + Mockito.when(headers.getPartitionId()).thenReturn("opendes"); + Mockito.when(tenantFactory.getTenantInfo("opendes")).thenReturn(tenantInfo); + + TenantInfo tenantInfoExpected = sut.getTenantInfo(); + + assertEquals(tenantInfo, tenantInfoExpected); + } + + @Test + public void shouldReturnSetList_when_getAllTenantInfos_isCalled() { + List<TenantInfo> tenantInfoArrayList = new ArrayList<>(); + Mockito.when(tenantFactory.listTenantInfo()).thenReturn(tenantInfoArrayList); + + List<TenantInfo> tenantInfoArrayListExpected = sut.getAllTenantInfos(); + + assertEquals(tenantInfoArrayList, tenantInfoArrayListExpected); + } +} diff --git a/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/publish/PublisherImplTest.java b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/publish/PublisherImplTest.java new file mode 100644 index 0000000000000000000000000000000000000000..565b99dc8cb70b8ceaebe695ef1600954d5ed325 --- /dev/null +++ b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/publish/PublisherImplTest.java @@ -0,0 +1,77 @@ +package org.opengroup.osdu.indexer.azure.publish; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.Test; +import org.junit.platform.commons.util.ReflectionUtils; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; +import org.opengroup.osdu.azure.servicebus.ITopicClientFactory; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.model.indexer.JobStatus; +import org.springframework.test.util.ReflectionTestUtils; +import javax.inject.Inject; +import javax.inject.Named; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.*; + +@RunWith(MockitoJUnitRunner.class) +public class PublisherImplTest { + + private static String serviceBusTopicField = "serviceBusTopic"; + private static String serviceBusTopicValue = "recordChangeTopic"; + private static String publishToIndexingProgressTopicField = "publishToIndexingProgressTopic"; + private static Boolean publishToIndexingProgressTopicValue = true; + private static String partitionId = "opendes"; + + @Mock + public ITopicClientFactory topicClientFactory; + + @Mock + private JaxRsDpsLog logger; + + @Mock + private DpsHeaders dpsHeaders; + + @Mock + private JobStatus jobStatus; + + @InjectMocks + public PublisherImpl sut; + + @Test + public void should_invoke_getPartitionIdOfdpsHeaders_when_publishStatusChangedTagsToTopic_isCalled() throws Exception { + ReflectionTestUtils.setField(sut,serviceBusTopicField,serviceBusTopicValue); + ReflectionTestUtils.setField(sut,publishToIndexingProgressTopicField,publishToIndexingProgressTopicValue); + when(dpsHeaders.getPartitionId()).thenReturn(partitionId); + + sut.publishStatusChangedTagsToTopic(dpsHeaders, jobStatus); + + verify(dpsHeaders, times(3)).getPartitionId(); + } + + @Test + public void should_invoke_getAccountIdOfDpsHeaders_when_publishStatusChangedTagsToTopic_isCalledWithGetPartitionIdReturningEmptyString() throws Exception { + ReflectionTestUtils.setField(sut,serviceBusTopicField,serviceBusTopicValue); + ReflectionTestUtils.setField(sut,publishToIndexingProgressTopicField,publishToIndexingProgressTopicValue); + when(dpsHeaders.getPartitionId()).thenReturn(""); + + sut.publishStatusChangedTagsToTopic(dpsHeaders, jobStatus); + + verify(dpsHeaders, times(1)).getAccountId(); + } + + @Test + public void should_invoke_getClientOftopicClientFactory_when_publishStatusChangedTagsToTopic_isCalled() throws Exception { + ReflectionTestUtils.setField(sut,serviceBusTopicField,serviceBusTopicValue); + ReflectionTestUtils.setField(sut,publishToIndexingProgressTopicField,publishToIndexingProgressTopicValue); + when(dpsHeaders.getPartitionId()).thenReturn(partitionId); + + sut.publishStatusChangedTagsToTopic(dpsHeaders, jobStatus); + + verify(topicClientFactory, times(1)).getClient(partitionId, serviceBusTopicValue); + } +} diff --git a/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/RetryPolicyTest.java b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/RetryPolicyTest.java index cb891b20be7bd68190258f643cdcb64588976116..e130e5fa5f1f68326f4c9c37c9f3a5b6640da3db 100644 --- a/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/RetryPolicyTest.java +++ b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/RetryPolicyTest.java @@ -15,7 +15,6 @@ package org.opengroup.osdu.indexer.azure.service; import io.github.resilience4j.retry.RetryConfig; - import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; @@ -25,9 +24,7 @@ import org.opengroup.osdu.core.common.http.FetchServiceHttpRequest; import org.opengroup.osdu.core.common.http.UrlFetchServiceImpl; import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.core.common.model.http.HttpResponse; - import java.util.function.Predicate; - import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -128,7 +125,6 @@ public class RetryPolicyTest { @Mock private JaxRsDpsLog logger; - @Test public void retry_should_be_true_for_jsonResponseWithNotFound() { RetryConfig config = this.retryPolicy.retryConfig(response -> this.retryPolicy.batchRetryPolicy(response)); @@ -160,4 +156,71 @@ public class RetryPolicyTest { assertFalse(value); } + @Test + public void shouldReturnFalse_when_emptyResponse_for_schemaRetryPolicy() + { + HttpResponse response=null; + + Boolean value=retryPolicy.schemaRetryPolicy(response); + + assertFalse(value); + } + + @Test + public void shouldReturnFalse_when_ResponseCode404_for_schemaRetryPolicy() + { + HttpResponse response=new HttpResponse(); + response.setBody(JSON_RESPONSE1_WITHOUT_NOT_FOUND); + response.setResponseCode(404); + + Boolean value=retryPolicy.schemaRetryPolicy(response); + + assertFalse(value); + } + + @Test + public void shouldReturnTrue_when_ResponseCode505_for_schemaRetryPolicy() + { + HttpResponse response=new HttpResponse(); + response.setBody(JSON_RESPONSE1_WITHOUT_NOT_FOUND); + response.setResponseCode(505); + + Boolean value=retryPolicy.schemaRetryPolicy(response); + + assertTrue(value); + } + + @Test + public void shouldReturnFalse_when_ResponseCode200_for_schemaRetryPolicy() + { + HttpResponse response=new HttpResponse(); + response.setBody(JSON_RESPONSE1_WITHOUT_NOT_FOUND); + response.setResponseCode(200); + + Boolean value=retryPolicy.schemaRetryPolicy(response); + + assertFalse(value); + } + + @Test + public void shouldReturnFalse_when_emptyResponse_for_defaultRetryPolicy() + { + HttpResponse response=null; + + Boolean value=retryPolicy.defaultRetryPolicy(response); + + assertFalse(value); + } + + @Test + public void shouldReturnTrue_when_defaultResponse_for_defaultRetryPolicy() + { + HttpResponse response=new HttpResponse(); + response.setBody(JSON_RESPONSE1_WITHOUT_NOT_FOUND); + response.setResponseCode(504); + + Boolean value=retryPolicy.defaultRetryPolicy(response); + + assertTrue(value); + } } diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/config/AzureBootstrapConfig.java b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/config/AzureBootstrapConfig.java similarity index 98% rename from provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/config/AzureBootstrapConfig.java rename to provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/config/AzureBootstrapConfig.java index 17b8d526b78fba8ce7819d73bce2302515ebaaf6..c6747b8f9d7ccec534944b2f712698971345247a 100644 --- a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/config/AzureBootstrapConfig.java +++ b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/config/AzureBootstrapConfig.java @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package org.opengroup.osdu.indexer.azure.config; +package org.opengroup.osdu.indexer.azure.service.config; import com.azure.security.keyvault.secrets.SecretClient; import org.opengroup.osdu.azure.KeyVaultFacade; diff --git a/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/util/IndexerQueueTaskBuilderAzureTest.java b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/util/IndexerQueueTaskBuilderAzureTest.java new file mode 100644 index 0000000000000000000000000000000000000000..e1333d34f6cb7e1d3bc5ede5a642ecb8680d930c --- /dev/null +++ b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/util/IndexerQueueTaskBuilderAzureTest.java @@ -0,0 +1,158 @@ +package org.opengroup.osdu.indexer.azure.util; + +import com.microsoft.azure.servicebus.TopicClient; +import com.microsoft.azure.servicebus.primitives.ServiceBusException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.Test; +import org.mockito.Spy; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnitRunner; +import org.opengroup.osdu.azure.servicebus.ITopicClientFactory; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; +import org.opengroup.osdu.core.common.model.http.AppException; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.model.indexer.RecordQueryResponse; +import org.opengroup.osdu.core.common.model.indexer.RecordReindexRequest; +import org.opengroup.osdu.core.common.model.search.RecordChangedMessages; +import org.opengroup.osdu.indexer.config.IndexerConfigurationProperties; +import org.opengroup.osdu.indexer.service.StorageService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.util.ReflectionTestUtils; +import javax.inject.Inject; +import javax.inject.Named; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.*; +import static org.opengroup.osdu.core.common.model.http.DpsHeaders.AUTHORIZATION; + +@RunWith(MockitoJUnitRunner.class) +public class IndexerQueueTaskBuilderAzureTest { + + private String payload="{payload : value }"; + private static String partitionId = "opendes"; + private static String correlationId = "correlationId"; + private static String serviceBusReindexTopicNameField = "serviceBusReindexTopicName"; + private static String serviceBusReindexTopicNameValue = "recordChangeTopic"; + private static String authorisedHeader = "Bearer opendes"; + + @Spy + private ITopicClientFactory topicClientFactory; + + @Mock + private IndexerConfigurationProperties configurationProperties; + + @Mock + private JaxRsDpsLog logger; + + @Mock + DpsHeaders dpsHeaders; + + @Mock + RequestInfoImpl requestInfo; + + @Mock + StorageService storageService; + + @InjectMocks + IndexerQueueTaskBuilderAzure sut; + + @Test + public void createWorkerTask_should_invoke_correctMethods() throws ServiceBusException, InterruptedException, NoSuchFieldException { + when(dpsHeaders.getPartitionIdWithFallbackToAccountId()).thenReturn(partitionId); + when(dpsHeaders.getPartitionId()).thenReturn(partitionId); + when(dpsHeaders.getCorrelationId()).thenReturn(correlationId); + ReflectionTestUtils.setField(sut, serviceBusReindexTopicNameField, serviceBusReindexTopicNameValue); + + sut.createWorkerTask(payload, dpsHeaders); + + verify(dpsHeaders, times(4)).getPartitionIdWithFallbackToAccountId(); + verify(dpsHeaders, times(2)).getCorrelationId(); + verify(dpsHeaders, times(1)).addCorrelationIdIfMissing(); + verify(topicClientFactory, times(1)).getClient(partitionId, serviceBusReindexTopicNameValue); + } + + @Test + public void createWorkerTaskWithCountDown_should_invoke_correctMethods() throws ServiceBusException, InterruptedException, NoSuchFieldException { + Long milliseconds=8000L; + when(dpsHeaders.getPartitionIdWithFallbackToAccountId()).thenReturn(partitionId); + when(dpsHeaders.getPartitionId()).thenReturn(partitionId); + when(dpsHeaders.getCorrelationId()).thenReturn(correlationId); + ReflectionTestUtils.setField(sut, serviceBusReindexTopicNameField, serviceBusReindexTopicNameValue); + + sut.createWorkerTask(payload, milliseconds, dpsHeaders); + + verify(dpsHeaders, times(2)).addCorrelationIdIfMissing(); + verify(dpsHeaders, times(4)).getPartitionIdWithFallbackToAccountId(); + verify(dpsHeaders, times(2)).getCorrelationId(); + verify(topicClientFactory, times(1)).getClient(partitionId, serviceBusReindexTopicNameValue); + } + + @Test(expected = AppException.class) + public void createReIndexTask_InvalidParameter_ShouldThrowException() + { + sut.createReIndexTask(payload,dpsHeaders); + } + + @Test + public void createReIndexTaskWithEmptyStorageResponse_should_invoke_correctMethods() throws ServiceBusException, InterruptedException, NoSuchFieldException, URISyntaxException { + Long milliseconds = 8000L; + RecordQueryResponse recordQueryResponse = new RecordQueryResponse(); + when(requestInfo.checkOrGetAuthorizationHeader()).thenReturn(authorisedHeader); + when(storageService.getRecordsByKind(any())).thenReturn(recordQueryResponse); + ReflectionTestUtils.setField(sut, serviceBusReindexTopicNameField, serviceBusReindexTopicNameValue); + + sut.createReIndexTask(payload, milliseconds, dpsHeaders); + + verify(requestInfo,times(1)).checkOrGetAuthorizationHeader(); + verify(dpsHeaders, times(1)).put(AUTHORIZATION, authorisedHeader); + verify(storageService,times(1)).getRecordsByKind(any()); + verify(dpsHeaders, times(1)).addCorrelationIdIfMissing(); + } + + @Test + public void createReIndexTaskWithNonEmptyStorageResponse_should_invoke_correctMethods() throws ServiceBusException, InterruptedException, NoSuchFieldException, URISyntaxException { + Long milliseconds = 8000L; + RecordQueryResponse recordQueryResponse = new RecordQueryResponse(); + List<String> res = Arrays.asList("r1","r2","r3"); + recordQueryResponse.setResults(res); + when(dpsHeaders.getPartitionIdWithFallbackToAccountId()).thenReturn(partitionId); + when(dpsHeaders.getCorrelationId()).thenReturn(correlationId); + when(dpsHeaders.getPartitionId()).thenReturn(partitionId); + when(requestInfo.checkOrGetAuthorizationHeader()).thenReturn(authorisedHeader); + when(storageService.getRecordsByKind(any())).thenReturn(recordQueryResponse); + ReflectionTestUtils.setField(sut, serviceBusReindexTopicNameField, serviceBusReindexTopicNameValue); + + sut.createReIndexTask(payload, milliseconds, dpsHeaders); + + verify(requestInfo,times(1)).checkOrGetAuthorizationHeader(); + verify(dpsHeaders, times(1)).put(AUTHORIZATION, authorisedHeader); + verify(storageService,times(1)).getRecordsByKind(any()); + verify(dpsHeaders, times(6)).getPartitionIdWithFallbackToAccountId(); + verify(dpsHeaders, times(3)).getCorrelationId(); + verify(dpsHeaders, times(2)).addCorrelationIdIfMissing(); + verify(topicClientFactory, times(1)).getClient(partitionId, serviceBusReindexTopicNameValue); + } + + @Test + public void createReIndexTaskWithCountdown_should_invoke_correctMethods() throws ServiceBusException, InterruptedException, NoSuchFieldException, URISyntaxException { + Long milliseconds = 8000L; + RecordQueryResponse recordQueryResponse = new RecordQueryResponse(); + when(requestInfo.checkOrGetAuthorizationHeader()).thenReturn(authorisedHeader); + when(storageService.getRecordsByKind(any())).thenReturn(recordQueryResponse); + ReflectionTestUtils.setField(sut, serviceBusReindexTopicNameField, serviceBusReindexTopicNameValue); + + sut.createReIndexTask(payload, milliseconds, dpsHeaders); + + verify(requestInfo,times(1)).checkOrGetAuthorizationHeader(); + verify(dpsHeaders, times(1)).put(AUTHORIZATION, authorisedHeader); + verify(storageService,times(1)).getRecordsByKind(any()); + verify(dpsHeaders, times(1)).addCorrelationIdIfMissing(); + } +} diff --git a/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/util/RequestInfoImplTest.java b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/util/RequestInfoImplTest.java new file mode 100644 index 0000000000000000000000000000000000000000..8b2c66becc92c96dcd12825a5347af9cc39acdfa --- /dev/null +++ b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/util/RequestInfoImplTest.java @@ -0,0 +1,145 @@ +package org.opengroup.osdu.indexer.azure.util; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.*; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.opengroup.osdu.core.common.model.http.AppException; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.model.tenant.TenantInfo; +import org.opengroup.osdu.core.common.util.IServiceAccountJwtClient; +import org.springframework.test.util.ReflectionTestUtils; +import java.util.*; +import static junit.framework.TestCase.*; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.powermock.api.mockito.PowerMockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class RequestInfoImplTest { + + private static String deploymentEnvironmentField = "DEPLOYMENT_ENVIRONMENT"; + private static String deploymentEnvironmentValue = "LOCAL"; + private static String deploymentEnvironmentValueCloud = "CLOUD"; + private static String tenant = "tenant1"; + private static String bearerToken = "bearerToken"; + private static String expectedToken = "Bearer bearerToken"; + private static String partitionId = "opendes"; + private static String owner = "owner"; + + @Mock + private DpsHeaders standardHeaders; + + @Mock + private IServiceAccountJwtClient serviceAccountJwtClient; + + @Mock + private TenantInfo tenantInfo; + + @InjectMocks + public RequestInfoImpl sut; + + @Before + public void setup() { + MockitoAnnotations.openMocks(RequestInfoImplTest.this); + ReflectionTestUtils.setField(sut, deploymentEnvironmentField, deploymentEnvironmentValue); + + } + + @Test + public void shouldReturnStandardHeaders_when_getHeaders_isCalled() { + DpsHeaders headers = sut.getHeaders(); + assertEquals(headers, standardHeaders); + } + + @Test + public void shouldReturnSamePartitionIdReturnedByStandardHeaders_when_getPartitionId_isCalled() { + when(standardHeaders.getPartitionId()).thenReturn(partitionId); + + String expectedPartitionId = sut.getPartitionId(); + + verify(standardHeaders,times(1)).getPartitionId(); + assertEquals(partitionId, expectedPartitionId); + } + + @Test + public void shouldReturnSameHeadersReturnedByStandardHeaders_when_getHeadersMap_isCalled() { + Map<String, String> headers = new HashMap(); + when(standardHeaders.getHeaders()).thenReturn(headers); + + Map<String, String> headersMap = sut.getHeadersMap(); + + verify(standardHeaders,times(1)).getHeaders(); + assertEquals(headers, headersMap); + } + + @Test + public void should_invoke_getAuthorizationMethod_when_getHeadersWithDwdAuthZ_isCalled() + { + when(standardHeaders.getAuthorization()).thenReturn(owner); + + DpsHeaders dpsHeaders=sut.getHeadersWithDwdAuthZ(); + + verify(standardHeaders,times(1)).getAuthorization(); + assertEquals(standardHeaders,dpsHeaders); + } + + @Test + public void should_invoke_getAuthorizationMethod_when_getHeadersMapWithDwdAuthZ_isCalled() + { + when(standardHeaders.getAuthorization()).thenReturn(owner); + + Map<String,String> dpsHeadersMap=sut.getHeadersMapWithDwdAuthZ(); + + verify(standardHeaders,times(1)).getAuthorization(); + verify(standardHeaders,times(1)).getHeaders(); + assertEquals(standardHeaders.getHeaders(),dpsHeadersMap); + } + + @Test + public void shouldReturnFalse_when_isCronRequest() { + Boolean cronRequest = sut.isCronRequest(); + assertFalse(cronRequest); + } + + @Test + public void shouldReturnFalse_when_isTaskQueueRequest() { + Boolean taskQueueRequest = sut.isTaskQueueRequest(); + assertFalse(taskQueueRequest); + } + + @Test + public void shouldInvoke_getAuthorization_andReturnAuthHeader_when_checkOrGetAuthorizationHeader_withAuth_isCalled() + { + when(standardHeaders.getAuthorization()).thenReturn(owner); + + String authHeader=sut.checkOrGetAuthorizationHeader(); + + verify(standardHeaders,times(1)).getAuthorization(); + assertEquals(authHeader,owner); + } + + @Test(expected = AppException.class) + public void shouldThrowException_checkOrGetAuthorizationHeader_isCalled_with_nullAsAuthHeader() + { +// Authorization token cannot be empty, hence it is expected to throw an App exception. + when(standardHeaders.getAuthorization()).thenReturn(null); + String authHeader=sut.checkOrGetAuthorizationHeader(); + } + + @Test + public void checkOrGetAuthorizationHeader_withCloud() + { + ReflectionTestUtils.setField(sut,deploymentEnvironmentField,deploymentEnvironmentValueCloud); + when(tenantInfo.getName()).thenReturn(tenant); + when(serviceAccountJwtClient.getIdToken(tenant)).thenReturn(bearerToken); + + String bearerToken=sut.checkOrGetAuthorizationHeader(); + + verify(tenantInfo,times(1)).getName(); + verify(serviceAccountJwtClient,times(1)).getIdToken(tenant); + assertEquals(bearerToken, expectedToken); + } +} diff --git a/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/util/ServiceAccountJwtClientImplTest.java b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/util/ServiceAccountJwtClientImplTest.java new file mode 100644 index 0000000000000000000000000000000000000000..f55c96dc2a34306fc6e0d4beb4cbed79513263f6 --- /dev/null +++ b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/util/ServiceAccountJwtClientImplTest.java @@ -0,0 +1,68 @@ +package org.opengroup.osdu.indexer.azure.util; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.*; +import org.mockito.junit.MockitoJUnitRunner; +import org.opengroup.osdu.azure.util.AzureServicePrincipleTokenService; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; +import org.opengroup.osdu.core.common.model.http.AppException; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.model.tenant.TenantInfo; +import org.opengroup.osdu.core.common.provider.interfaces.ITenantFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.test.context.junit4.SpringRunner; +import javax.inject.Inject; +import java.util.*; +import static junit.framework.TestCase.*; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.*; + +@RunWith(MockitoJUnitRunner.class) +public class ServiceAccountJwtClientImplTest { + + private String partitionId="opendes"; + private static String authorizationToken = "authorizationToken"; + + @Mock + private ITenantFactory tenantInfoServiceProvider; + + @Mock + private DpsHeaders dpsHeaders; + + @Mock + private JaxRsDpsLog log; + + @Mock + private AzureServicePrincipleTokenService tokenService; + + @InjectMocks + ServiceAccountJwtClientImpl sut; + + @Test + public void should_invoke_methodsWithRightArguments_andReturnAuthToken_when_getIdToken_isCalled() { + TenantInfo tenant=new TenantInfo(); + when(tenantInfoServiceProvider.getTenantInfo(partitionId)).thenReturn(tenant); + when(tokenService.getAuthorizationToken()).thenReturn(authorizationToken); + + String authToken=sut.getIdToken(partitionId); + + verify(tenantInfoServiceProvider,times(1)).getTenantInfo(partitionId); + verify(tokenService,times(1)).getAuthorizationToken(); + verify(dpsHeaders,times(1)).put(DpsHeaders.USER_EMAIL, tenant.getServiceAccount()); + assertEquals(authorizationToken, authToken); + } + + @Test(expected = AppException.class) + public void should_throw_appException_when_getIdToken_isCalled_with_tenantNull() { + when(tenantInfoServiceProvider.getTenantInfo(partitionId)).thenReturn(null); + + sut.getIdToken(partitionId); + + Assert.fail("Invalid tenant Name from azure"); + } +} diff --git a/testing/indexer-test-core/src/main/java/org/opengroup/osdu/util/HTTPClient.java b/testing/indexer-test-core/src/main/java/org/opengroup/osdu/util/HTTPClient.java index 1ce98c78a3710d279c9500d01a80e2ccaa0075f2..865f645ab744aa9f9e5866eadbff2a65f747b175 100644 --- a/testing/indexer-test-core/src/main/java/org/opengroup/osdu/util/HTTPClient.java +++ b/testing/indexer-test-core/src/main/java/org/opengroup/osdu/util/HTTPClient.java @@ -61,7 +61,7 @@ public abstract class HTTPClient { headers.put(HEADER_CORRELATION_ID, correlationId); Client client = getClient(); client.setReadTimeout(180000); - client.setConnectTimeout(10000); + client.setConnectTimeout(300000); log.info("URL: = " + url); WebResource webResource = client.resource(url); response = this.getClientResponse(httpMethod, payLoad, webResource, headers, token); @@ -91,4 +91,4 @@ public abstract class HTTPClient { currentHeaders.put("data-partition-id", value); return currentHeaders; } -} \ No newline at end of file +}