Commit 3963ccec authored by Sutton's avatar Sutton
Browse files

Merged

parents 41de963f c27e44b9
Pipeline #28598 failed with stages
in 56 minutes and 46 seconds
......@@ -79,7 +79,6 @@ The following software have components provided under the terms of this license:
- Data Mapper for Jackson (from http://jackson.codehaus.org)
- Elastic JNA Distribution (from https://github.com/java-native-access/jna)
- Elasticsearch: 5.0.0-alpha5 (from https://github.com/elastic/elasticsearch)
- Elasticsearch: 5.0.0-alpha5 (from https://github.com/elastic/elasticsearch)
- Expression Language 3.0 (from http://uel.java.net)
- Expression Language 3.0 API (from http://uel.java.net)
- FindBugs-jsr305 (from http://findbugs.sourceforge.net/)
......@@ -157,34 +156,18 @@ The following software have components provided under the terms of this license:
- KeePassJava2 :: Simple (from https://repo1.maven.org/maven2/org/linguafranca/pwdb/KeePassJava2-simple)
- Lettuce (from http://github.com/lettuce-io/lettuce-core)
- Lucene Common Analyzers (from )
- Lucene Common Analyzers (from )
- Lucene Core (from )
- Lucene Core (from )
- Lucene Grouping (from )
- Lucene Grouping (from )
- Lucene Highlighter (from )
- Lucene Highlighter (from )
- Lucene Join (from )
- Lucene Join (from )
- Lucene Memory (from )
- Lucene Memory (from )
- Lucene Memory (from )
- Lucene Memory (from )
- Lucene Miscellaneous (from )
- Lucene Miscellaneous (from )
- Lucene Queries (from )
- Lucene Queries (from )
- Lucene QueryParsers (from )
- Lucene QueryParsers (from )
- Lucene Sandbox (from )
- Lucene Sandbox (from )
- Lucene Spatial (from )
- Lucene Spatial (from )
- Lucene Spatial 3D (from )
- Lucene Spatial 3D (from )
- Lucene Spatial Extras (from )
- Lucene Spatial Extras (from )
- Lucene Suggest (from )
- Lucene Suggest (from )
- MapStruct Core (from )
- Metrics Core (from https://github.com/dropwizard/metrics)
......@@ -304,10 +287,8 @@ The following software have components provided under the terms of this license:
- Woodstox (from https://github.com/FasterXML/woodstox)
- aalto-xml (from )
- aggs-matrix-stats (from https://github.com/elastic/elasticsearch)
- aggs-matrix-stats (from https://github.com/elastic/elasticsearch)
- aws-ssm-java-caching-client (from https://github.com/awslabs/aws-ssm-java-caching-client)
- cli (from https://github.com/elastic/elasticsearch)
- cli (from https://github.com/elastic/elasticsearch)
- com.google.api.grpc:grpc-google-cloud-pubsub-v1 (from https://github.com/googleapis/googleapis)
- com.google.api.grpc:proto-google-cloud-logging-v2 (from https://github.com/googleapis/googleapis)
- com.google.api.grpc:proto-google-cloud-pubsub-v1 (from https://github.com/googleapis/googleapis)
......@@ -316,7 +297,7 @@ The following software have components provided under the terms of this license:
- compiler (from http://github.com/spullara/mustache.java)
- datastore-v1-proto-client (from )
- elasticsearch-core (from https://github.com/elastic/elasticsearch)
- elasticsearch-core (from https://github.com/elastic/elasticsearch)
- elasticsearch-geo (from https://github.com/elastic/elasticsearch)
- embedded-elasticsearch (from https://github.com/allegro/embedded-elasticsearch)
- error-prone annotations (from )
- io.grpc:grpc-alts (from https://github.com/grpc/grpc-java)
......@@ -351,14 +332,13 @@ The following software have components provided under the terms of this license:
- json-patch (from https://github.com/fge/json-patch)
- jsr311-api (from https://jsr311.dev.java.net)
- lang-mustache (from https://github.com/elastic/elasticsearch)
- lang-mustache (from https://github.com/elastic/elasticsearch)
- lettuce (from http://github.com/mp911de/lettuce/wiki)
- mapper-extras (from https://github.com/elastic/elasticsearch)
- micrometer-core (from https://github.com/micrometer-metrics/micrometer)
- micrometer-registry-azure-monitor (from https://github.com/micrometer-metrics/micrometer)
- minio (from https://github.com/minio/minio-java)
- org.xmlunit:xmlunit-core (from http://www.xmlunit.org/)
- parent-join (from https://github.com/elastic/elasticsearch)
- parent-join (from https://github.com/elastic/elasticsearch)
- powermock-api-support (from )
- powermock-core (from http://www.powermock.org)
- powermock-module-junit4 (from http://www.powermock.org)
......@@ -367,14 +347,10 @@ The following software have components provided under the terms of this license:
- proto-google-cloud-datastore-v1 (from https://github.com/googleapis/api-client-staging)
- proton-j (from )
- rank-eval (from https://github.com/elastic/elasticsearch)
- rank-eval (from https://github.com/elastic/elasticsearch)
- rest (from https://github.com/elastic/elasticsearch)
- rest (from https://github.com/elastic/elasticsearch)
- rest-high-level (from https://github.com/elastic/elasticsearch)
- rest-high-level (from https://github.com/elastic/elasticsearch)
- rxjava (from https://github.com/ReactiveX/RxJava)
- secure-sm (from https://github.com/elastic/elasticsearch)
- secure-sm (from https://github.com/elastic/elasticsearch)
- spring-security-config (from http://spring.io/spring-security)
- spring-security-core (from http://spring.io/spring-security)
- spring-security-oauth2-client (from http://spring.io/spring-security)
......@@ -400,7 +376,6 @@ The following software have components provided under the terms of this license:
- tomcat-embed-el (from http://tomcat.apache.org/)
- tomcat-embed-websocket (from http://tomcat.apache.org/)
- x-content (from https://github.com/elastic/elasticsearch)
- x-content (from https://github.com/elastic/elasticsearch)
========================================================================
BSD-2-Clause
......@@ -413,7 +388,7 @@ The following software have components provided under the terms of this license:
- GAX (Google Api eXtensions) (from https://github.com/googleapis)
- Hamcrest Core (from http://hamcrest.org/)
- Lucene Common Analyzers (from )
- Lucene Common Analyzers (from )
- Lucene Core (from )
- StAX (from http://stax.codehaus.org/)
- Stax2 API (from http://github.com/FasterXML/stax2-api)
- jersey-ext-bean-validation (from )
......@@ -440,10 +415,7 @@ The following software have components provided under the terms of this license:
- JavaBeans Activation Framework (from )
- JavaBeans Activation Framework API jar (from )
- Lucene Common Analyzers (from )
- Lucene Common Analyzers (from )
- Lucene Core (from )
- Lucene Core (from )
- Lucene Suggest (from )
- Lucene Suggest (from )
- Microsoft Application Insights Java SDK Core (from https://github.com/Microsoft/ApplicationInsights-Java)
- Microsoft Application Insights Java SDK Spring Boot starter (from https://github.com/Microsoft/ApplicationInsights-Java)
......@@ -745,7 +717,6 @@ The following software have components provided under the terms of this license:
- Azure Spring Boot AutoConfigure (from https://github.com/Microsoft/azure-spring-boot)
- Bouncy Castle Provider (from http://www.bouncycastle.org/java.html)
- Checker Qual (from https://checkerframework.org)
- Elasticsearch: 5.0.0-alpha5 (from https://github.com/elastic/elasticsearch)
- Extensions on Apache Proton-J library (from https://github.com/Azure/qpid-proton-j-extensions)
- JCL 1.1.1 implemented over SLF4J (from http://www.slf4j.org)
- JOpt Simple (from http://pholser.github.io/jopt-simple)
......@@ -753,9 +724,6 @@ The following software have components provided under the terms of this license:
- Java Client Runtime for AutoRest (from https://github.com/Azure/autorest-clientruntime-for-java)
- Java JWT (from http://www.jwt.io)
- Lucene Core (from )
- Lucene Core (from )
- Lucene Sandbox (from )
- Lucene Sandbox (from )
- Microsoft Application Insights Java SDK Core (from https://github.com/Microsoft/ApplicationInsights-Java)
- Microsoft Application Insights Java SDK Spring Boot starter (from https://github.com/Microsoft/ApplicationInsights-Java)
- Microsoft Application Insights Java SDK Web Module (from https://github.com/Microsoft/ApplicationInsights-Java)
......
......@@ -34,7 +34,7 @@
<skip.integration.tests>true</skip.integration.tests>
<jackson.version>2.11.2</jackson.version>
<resteasy.version>3.12.0.Final</resteasy.version>
<elasticsearch.version>6.8.1</elasticsearch.version>
<elasticsearch.version>7.8.1</elasticsearch.version>
<snakeyaml.version>1.26</snakeyaml.version>
<commons-codec.version>1.14</commons-codec.version>
<hibernate-validator.version>6.1.5.Final</hibernate-validator.version>
......
......@@ -74,7 +74,7 @@ public class QueryServiceAwsImpl extends QueryBase implements IQueryService {
List<AggregationResponse> aggregations = getAggregationFromSearchResponse(searchResponse);
QueryResponse queryResponse = QueryResponse.getEmptyResponse();
queryResponse.setTotalCount(searchResponse.getHits().getTotalHits());
queryResponse.setTotalCount(searchResponse.getHits().getTotalHits().value);
if (results != null) {
queryResponse.setAggregations(aggregations);
queryResponse.setResults(results);
......@@ -94,7 +94,7 @@ public class QueryServiceAwsImpl extends QueryBase implements IQueryService {
sourceBuilder.from(searchRequest.getFrom());
if (StringUtils.isNotEmpty(searchRequest.getAggregateBy())) {
TermsAggregationBuilder termsAggregationBuilder = new TermsAggregationBuilder(AGGREGATION_NAME, ValueType.STRING);
TermsAggregationBuilder termsAggregationBuilder = new TermsAggregationBuilder(AGGREGATION_NAME);
termsAggregationBuilder.field(searchRequest.getAggregateBy());
termsAggregationBuilder.size(configurationProperties.getAggregationSize());
sourceBuilder.aggregation(termsAggregationBuilder);
......
......@@ -88,7 +88,7 @@ public class ScrollQueryServiceAwsImpl extends QueryBase implements IScrollQuery
SearchResponse searchScrollResponse = client.scroll(scrollRequest, RequestOptions.DEFAULT);
List<Map<String, Object>> results = getHitsFromSearchResponse(searchScrollResponse);
queryResponse.setTotalCount(searchScrollResponse.getHits().getTotalHits());
queryResponse.setTotalCount(searchScrollResponse.getHits().getTotalHits().value);
if (results != null) {
queryResponse.setResults(results);
queryResponse.setCursor(this.refreshCursorCache(searchScrollResponse.getScrollId(), dpsHeaders.getUserEmail()));
......@@ -129,7 +129,7 @@ public class ScrollQueryServiceAwsImpl extends QueryBase implements IScrollQuery
return CursorQueryResponse.builder()
.cursor(refreshCursorCache(searchResponse.getScrollId(), dpsHeaders.getUserEmail()))
.results(results)
.totalCount(searchResponse.getHits().getTotalHits())
.totalCount(searchResponse.getHits().getTotalHits().value)
.build();
}
return CursorQueryResponse.getEmptyResponse();
......
......@@ -40,7 +40,6 @@ public class ElasticClientHandlerAws extends ElasticClientHandler {
RestClientBuilder builder = RestClient.builder(new HttpHost(host, port, protocolScheme));
builder.setRequestConfigCallback(requestConfigBuilder -> requestConfigBuilder.setConnectTimeout(REST_CLIENT_CONNECT_TIMEOUT)
.setSocketTimeout(REST_CLIENT_SOCKET_TIMEOUT));
builder.setMaxRetryTimeoutMillis(REST_CLIENT_RETRY_TIMEOUT);
if(isLocalHost(host)) {
builder.setHttpClientConfigCallback(httpAsyncClientBuilder -> httpAsyncClientBuilder.setSSLHostnameVerifier((s, sslSession) -> true));
......
......@@ -44,13 +44,13 @@ public class FieldMappingTypeService {
request.fields(fieldName);
if (!Strings.isNullOrEmpty(indexPattern)) request.indices(indexPattern);
GetFieldMappingsResponse response = restClient.indices().getFieldMapping(request, RequestOptions.DEFAULT);
Map<String, Map<String, Map<String, GetFieldMappingsResponse.FieldMappingMetaData>>> mappings = response.mappings();
Map<String, Map<String, Map<String, GetFieldMappingsResponse.FieldMappingMetadata>>> mappings = response.mappings();
for (Map.Entry<String, Map<String, Map<String, GetFieldMappingsResponse.FieldMappingMetaData>>> indexMapping : mappings.entrySet()) {
for (Map.Entry<String, Map<String, Map<String, GetFieldMappingsResponse.FieldMappingMetadata>>> indexMapping : mappings.entrySet()) {
if (indexMapping.getValue().isEmpty()) continue;
Map<String, Map<String, GetFieldMappingsResponse.FieldMappingMetaData>> typeMapping = indexMapping.getValue();
Map<String, GetFieldMappingsResponse.FieldMappingMetaData> fieldMapping = typeMapping.values().iterator().next();
GetFieldMappingsResponse.FieldMappingMetaData fieldMappingMetaData = fieldMapping.get(fieldName);
Map<String, Map<String, GetFieldMappingsResponse.FieldMappingMetadata>> typeMapping = indexMapping.getValue();
Map<String, GetFieldMappingsResponse.FieldMappingMetadata> fieldMapping = typeMapping.values().iterator().next();
GetFieldMappingsResponse.FieldMappingMetadata fieldMappingMetaData = fieldMapping.get(fieldName);
if (fieldMappingMetaData == null) continue;
Map<String, Object> mapping = fieldMappingMetaData.sourceAsMap();
LinkedHashMap<String, Object> typeMap = (LinkedHashMap<String, Object>) mapping.get(fieldLeafNodeLabel);
......
......@@ -68,7 +68,7 @@ public class QueryServiceImpl extends QueryBase implements IQueryService {
List<AggregationResponse> aggregations = getAggregationFromSearchResponse(searchResponse);
QueryResponse queryResponse = QueryResponse.getEmptyResponse();
queryResponse.setTotalCount(searchResponse.getHits().getTotalHits());
queryResponse.setTotalCount(searchResponse.getHits().getTotalHits().value);
if (results != null) {
queryResponse.setAggregations(aggregations);
queryResponse.setResults(results);
......@@ -89,7 +89,7 @@ public class QueryServiceImpl extends QueryBase implements IQueryService {
// aggregation
if (!Strings.isNullOrEmpty(searchRequest.getAggregateBy())) {
TermsAggregationBuilder termsAggregationBuilder = new TermsAggregationBuilder(AGGREGATION_NAME, ValueType.STRING);
TermsAggregationBuilder termsAggregationBuilder = new TermsAggregationBuilder(AGGREGATION_NAME);
termsAggregationBuilder.field(searchRequest.getAggregateBy());
termsAggregationBuilder.size(configurationProperties.getAggregationSize());
sourceBuilder.aggregation(termsAggregationBuilder);
......
......@@ -89,7 +89,7 @@ public class ScrollQueryServiceImpl extends QueryBase implements IScrollQuerySer
SearchResponse searchScrollResponse = client.scroll(scrollRequest, RequestOptions.DEFAULT);
List<Map<String, Object>> results = getHitsFromSearchResponse(searchScrollResponse);
queryResponse.setTotalCount(searchScrollResponse.getHits().getTotalHits());
queryResponse.setTotalCount(searchScrollResponse.getHits().getTotalHits().value);
if (results != null) {
queryResponse.setResults(results);
queryResponse.setCursor(this.refreshCursorCache(searchScrollResponse.getScrollId(), dpsHeaders.getUserEmail()));
......@@ -126,7 +126,7 @@ public class ScrollQueryServiceImpl extends QueryBase implements IScrollQuerySer
return CursorQueryResponse.builder()
.cursor(refreshCursorCache(searchResponse.getScrollId(), dpsHeaders.getUserEmail()))
.results(results)
.totalCount(searchResponse.getHits().getTotalHits())
.totalCount(searchResponse.getHits().getTotalHits().value)
.build();
}
return CursorQueryResponse.getEmptyResponse();
......
......@@ -44,13 +44,13 @@ public class FieldMappingTypeService {
request.fields(fieldName);
if (!Strings.isNullOrEmpty(indexPattern)) request.indices(indexPattern);
GetFieldMappingsResponse response = restClient.indices().getFieldMapping(request, RequestOptions.DEFAULT);
Map<String, Map<String, Map<String, GetFieldMappingsResponse.FieldMappingMetaData>>> mappings = response.mappings();
Map<String, Map<String, Map<String, GetFieldMappingsResponse.FieldMappingMetadata>>> mappings = response.mappings();
for (Map.Entry<String, Map<String, Map<String, GetFieldMappingsResponse.FieldMappingMetaData>>> indexMapping : mappings.entrySet()) {
for (Map.Entry<String, Map<String, Map<String, GetFieldMappingsResponse.FieldMappingMetadata>>> indexMapping : mappings.entrySet()) {
if (indexMapping.getValue().isEmpty()) continue;
Map<String, Map<String, GetFieldMappingsResponse.FieldMappingMetaData>> typeMapping = indexMapping.getValue();
Map<String, GetFieldMappingsResponse.FieldMappingMetaData> fieldMapping = typeMapping.values().iterator().next();
GetFieldMappingsResponse.FieldMappingMetaData fieldMappingMetaData = fieldMapping.get(fieldName);
Map<String, Map<String, GetFieldMappingsResponse.FieldMappingMetadata>> typeMapping = indexMapping.getValue();
Map<String, GetFieldMappingsResponse.FieldMappingMetadata> fieldMapping = typeMapping.values().iterator().next();
GetFieldMappingsResponse.FieldMappingMetadata fieldMappingMetaData = fieldMapping.get(fieldName);
if (fieldMappingMetaData == null) continue;
Map<String, Object> mapping = fieldMappingMetaData.sourceAsMap();
LinkedHashMap<String, Object> typeMap = (LinkedHashMap<String, Object>) mapping.get(fieldLeafNodeLabel);
......
// Copyright © Microsoft Corporation
//
// 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.search.provider.azure.provider.impl;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.model.search.CcsQueryRequest;
import org.opengroup.osdu.core.common.model.search.CcsQueryResponse;
import org.opengroup.osdu.core.common.model.search.ClusterSettings;
import org.opengroup.osdu.core.common.model.search.QueryRequest;
import org.opengroup.osdu.core.common.model.search.QueryResponse;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.core.common.provider.interfaces.IElasticRepository;
import org.opengroup.osdu.core.common.provider.interfaces.ITenantFactory;
import org.opengroup.osdu.search.config.SearchConfigurationProperties;
import org.opengroup.osdu.search.provider.interfaces.IQueryService;
import java.util.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.times;
@RunWith(MockitoJUnitRunner.class)
public class CcsQueryServiceImplTest {
private static final String dataPartitionId = "data-partition-id";
private static final String partitionIdWithFallbackToAccountId = "partition-id-with-fallback";
private static final String partitionIdWithFallbackToAccountIdMultipleAccounts = "partition-id1, partition-id2";
private static class DummyObject {
private String id;
public DummyObject(String id) {
this.id = id;
}
public String getId() {
return this.id;
}
}
@Mock
private DpsHeaders dpsHeaders;
@Mock
private ITenantFactory tenantStorageFactory;
@Mock
private IQueryService queryService;
@Mock
private IElasticRepository elasticRepository;
@Mock
private SearchConfigurationProperties configurationProperties;
@InjectMocks
CcsQueryServiceImpl sut;
@Before
public void init() {
doReturn(partitionIdWithFallbackToAccountId).when(dpsHeaders).getPartitionIdWithFallbackToAccountId();
}
@Test
public void testCcsQueryResponse_whenSingleAccountProvided() throws Exception {
QueryResponse queryResponse = mock(QueryResponse.class);
CcsQueryRequest ccsQueryRequest = mock(CcsQueryRequest.class);
mockCcsQueryRequest(ccsQueryRequest,1, "kind", 100, "query");
long totalCount = 100L;
List<Map<String, Object>> results = getDummyResults("dummy-object-key", "dummy-id");
ClusterSettings clusterSettings = getClusterSettings("host", 1111, "username-and-password");
TenantInfo tenantInfo = getTenantInfo(1L, "tenant1", "project-id1");
doReturn(totalCount).when(queryResponse).getTotalCount();
doReturn(results).when(queryResponse).getResults();
doReturn(clusterSettings).when(elasticRepository).getElasticClusterSettings(eq(tenantInfo));
doReturn(tenantInfo).when(tenantStorageFactory).getTenantInfo(eq(partitionIdWithFallbackToAccountId));
doReturn(queryResponse).when(queryService).queryIndex(any(), any());
CcsQueryResponse ccsQueryResponse = sut.makeRequest(ccsQueryRequest);
ArgumentCaptor<QueryRequest> searchRequestArgCaptor = ArgumentCaptor.forClass(QueryRequest.class);
ArgumentCaptor<ClusterSettings> clusterSettingsArgCaptor = ArgumentCaptor.forClass(ClusterSettings.class);
verify(queryService).queryIndex(searchRequestArgCaptor.capture(), clusterSettingsArgCaptor.capture());
QueryRequest obtainedQueryRequest = searchRequestArgCaptor.getValue();
ClusterSettings obtainedClusterSettings = clusterSettingsArgCaptor.getValue();
validateQueryRequestAndCcsQueryRequestCorrespondence(obtainedQueryRequest, ccsQueryRequest);
assertEquals(obtainedClusterSettings, clusterSettings);
assertEquals(ccsQueryResponse.getResults().size(), 1);
assertEquals(ccsQueryResponse.getResults(), results);
assertEquals(ccsQueryResponse.getTotalCount(), totalCount);
}
@Test
public void testCcsQueryResponse_whenMultipleAccountsProvided() throws Exception {
doReturn(partitionIdWithFallbackToAccountIdMultipleAccounts).when(dpsHeaders).getPartitionIdWithFallbackToAccountId();
QueryResponse queryResponse1 = mock(QueryResponse.class);
QueryResponse queryResponse2 = mock(QueryResponse.class);
CcsQueryRequest ccsQueryRequest = mock(CcsQueryRequest.class);
mockCcsQueryRequest(ccsQueryRequest, 1, "kind", 100, "query");
List<Map<String, Object>> results1 = getDummyResults("dummy-object-key-1", "dummy-id-1");
List<Map<String, Object>> results2 = getDummyResults("dummy-object-key-2", "dummy-id-2");
String[] accounts = partitionIdWithFallbackToAccountIdMultipleAccounts.split("\\s*,\\s*");
ClusterSettings clusterSettings1 = getClusterSettings("host1", 1111, "secret1");
ClusterSettings clusterSettings2 = getClusterSettings("host2", 2222, "secret2");
long totalCount1 = 100L;
long totalCount2 = 200L;
doReturn(totalCount1).when(queryResponse1).getTotalCount();
doReturn(results1).when(queryResponse1).getResults();
doReturn(totalCount2).when(queryResponse2).getTotalCount();
doReturn(results2).when(queryResponse2).getResults();
TenantInfo tenant1 = getTenantInfo(1L, "tenant1", "project-id1");
TenantInfo tenant2 = getTenantInfo(2L, "tenant2", "project-id2");
doReturn(tenant1).when(tenantStorageFactory).getTenantInfo(eq(accounts[0]));
doReturn(tenant2).when(tenantStorageFactory).getTenantInfo(eq(accounts[1]));
doReturn(clusterSettings1).when(elasticRepository).getElasticClusterSettings(eq(tenant1));
doReturn(clusterSettings2).when(elasticRepository).getElasticClusterSettings(eq(tenant2));
doReturn(queryResponse1).doReturn(queryResponse2).when(queryService).queryIndex(any(), any());
CcsQueryResponse ccsQueryResponse = sut.makeRequest(ccsQueryRequest);
ArgumentCaptor<QueryRequest> searchRequestArgCaptor = ArgumentCaptor.forClass(QueryRequest.class);
ArgumentCaptor<ClusterSettings> clusterSettingsArgCaptor = ArgumentCaptor.forClass(ClusterSettings.class);
verify(queryService, times(2)).queryIndex(searchRequestArgCaptor.capture(), clusterSettingsArgCaptor.capture());
QueryRequest queryRequest = searchRequestArgCaptor.getValue();
List<ClusterSettings> clusterSettings = clusterSettingsArgCaptor.getAllValues();
validateQueryRequestAndCcsQueryRequestCorrespondence(queryRequest, ccsQueryRequest);
assertEquals(clusterSettings.size(), 2);
assertTrue(clusterSettings.contains(clusterSettings1));
assertTrue(clusterSettings.contains(clusterSettings2));
assertEquals(ccsQueryResponse.getResults().size(), 2);
assertTrue(ccsQueryResponse.getResults().contains(results1.get(0)));
assertTrue(ccsQueryResponse.getResults().contains(results2.get(0)));
assertEquals(ccsQueryResponse.getTotalCount(), totalCount1 + totalCount2);
}
private void mockCcsQueryRequest(CcsQueryRequest ccsQueryRequest, int offset, String kind, int limit, String query) {
doReturn(offset).when(ccsQueryRequest).getFrom();
doReturn(kind).when(ccsQueryRequest).getKind();
doReturn(limit).when(ccsQueryRequest).getLimit();
doReturn(query).when(ccsQueryRequest).getQuery();
}
private void validateQueryRequestAndCcsQueryRequestCorrespondence(QueryRequest queryRequest, CcsQueryRequest ccsQueryRequest) {
assertEquals(queryRequest.getFrom(), ccsQueryRequest.getFrom());
assertEquals(queryRequest.getLimit(), ccsQueryRequest.getLimit());
assertEquals(queryRequest.getKind(), ccsQueryRequest.getKind());
assertEquals(queryRequest.getQuery(), ccsQueryRequest.getQuery());
}
private List<Map<String, Object>> getDummyResults(String dummyObjectKey, String dummyObjectId) {
Map<String, Object> result = new HashMap<>();
Object dummyObject = new DummyObject(dummyObjectId);
result.put(dummyObjectKey, dummyObject);
List<Map<String, Object>> results = Arrays.asList(result);
return results;
}
private TenantInfo getTenantInfo(Long id, String name, String projectId) {
TenantInfo tenantInfo = new TenantInfo();
tenantInfo.setId(id);
tenantInfo.setDataPartitionId(dataPartitionId);
tenantInfo.setName(name);
tenantInfo.setProjectId(projectId);
return tenantInfo;
}
private ClusterSettings getClusterSettings(String host, int port, String userNameAndPassword) {
ClusterSettings clusterSettings = new ClusterSettings(host, port, userNameAndPassword);
return clusterSettings;
}
}
\ No newline at end of file
// Copyright © Microsoft Corporation
//
// 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.search.provider.azure.provider.impl;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.opengroup.osdu.core.common.model.http.AppError;
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 java.util.*;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.lenient;
@RunWith(MockitoJUnitRunner.class)
public class CrossTenantInfoServiceImplTest {
private static final String dataPartitionId = "data-partition-id";
private static final String partitionIdWithFallbackToAccountId = "partition-id-with-fallback";
// Note [aaljain]: Inconsistent behaviour in splitting and obtaining account IDs
// .split(',') vs .split("\\s*,\\s*")
private static final String partitionIdWithFallbackToAccountIdMultipleAccounts = "partition-id1,partition-id2";
@Mock
private ITenantFactory tenantFactory;
@Mock
private DpsHeaders dpsHeaders;
@InjectMocks
CrossTenantInfoServiceImpl sut;
@Before
public void init() {
lenient().doReturn(dataPartitionId).when(dpsHeaders).getPartitionId();
lenient().doReturn(partitionIdWithFallbackToAccountId).when(dpsHeaders).getPartitionIdWithFallbackToAccountId();
}
@Test(expected = AppException.class)
public void testGetTenantInfo_whenTenantInfoIsNull_throwsException() {
try {