Skip to content
Snippets Groups Projects
Commit 4d53a194 authored by Alan Braz's avatar Alan Braz
Browse files

test classes

parent b628a214
No related branches found
No related tags found
1 merge request!6Trusted ibm
......@@ -14,16 +14,7 @@
package org.opengroup.osdu.indexer.ibm.service;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.powermock.api.mockito.PowerMockito.mockStatic;
import java.io.IOException;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import com.google.common.collect.Lists;
import org.elasticsearch.client.RestHighLevelClient;
import org.junit.Before;
import org.junit.Ignore;
......@@ -31,18 +22,24 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.indexer.service.CronServiceImpl;
import org.opengroup.osdu.core.common.model.search.IndexInfo;
import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo;
import org.opengroup.osdu.core.common.search.Config;
import org.opengroup.osdu.core.common.search.IndicesService;
import org.opengroup.osdu.indexer.service.CronServiceImpl;
import org.opengroup.osdu.core.common.search.Config;
import org.opengroup.osdu.indexer.util.ElasticClientHandler;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.springframework.test.context.junit4.SpringRunner;
import com.google.common.collect.Lists;
import java.io.IOException;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import static org.powermock.api.mockito.PowerMockito.mockStatic;
@Ignore
......@@ -141,4 +138,4 @@ public class CronServiceImplTest {
verify(this.indicesService, times(0)).deleteIndex(any(), any());
}
}
\ No newline at end of file
}
......@@ -29,16 +29,16 @@ import org.opengroup.osdu.core.common.model.search.ClusterSettings;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.core.common.provider.interfaces.IElasticCredentialsCache;
import org.opengroup.osdu.core.common.provider.interfaces.IElasticRepository;
import org.opengroup.osdu.indexer.ibm.di.TenantInfoService;
import org.opengroup.osdu.indexer.ibm.util.IHeadersInfo;
import org.opengroup.osdu.indexer.service.ElasticSettingServiceImpl;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
public class ElasticSettingServiceTest {
// TODO alanbraz: investigate this
//@Mock
//private TenantInfoService tenantInfoService;
@Mock
private TenantInfoService tenantInfoService;
@Mock
private IElasticRepository elasticRepository;
@Mock
......@@ -69,7 +69,7 @@ public class ElasticSettingServiceTest {
public void setup() {
when(tenantInfo.getName()).thenReturn("tenant1");
when(this.headersInfo.getPartitionId()).thenReturn("tenant1");
//when(this.tenantInfoService.getTenantInfo()).thenReturn(tenantInfo);
when(this.tenantInfoService.getTenantInfo()).thenReturn(tenantInfo);
sut.GAE_SERVICE = "indexer";
clusterSettings = ClusterSettings.builder().host(host).port(port).userNameAndPassword(credentials).build();
cacheKey = String.format("%s-%s", GAE_SERVICE, tenantInfo.getName());
......
......@@ -14,16 +14,8 @@
package org.opengroup.osdu.indexer.ibm.service;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.powermock.api.mockito.PowerMockito.when;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.apache.http.HttpEntity;
import org.apache.http.util.EntityUtils;
import org.elasticsearch.client.Request;
......@@ -38,21 +30,29 @@ import org.junit.runner.RunWith;
import org.mockito.ArgumentMatchers;
import org.mockito.InjectMocks;
import org.mockito.Mock;
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.search.ClusterSettings;
import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo;
import org.opengroup.osdu.core.common.search.ElasticIndexNameResolver;
import org.opengroup.osdu.core.common.search.IndicesService;
import org.opengroup.osdu.indexer.logging.AuditLogger;
import org.opengroup.osdu.indexer.service.IndexCopyServiceImpl;
import org.opengroup.osdu.indexer.service.IndexerMappingService;
import org.opengroup.osdu.core.common.model.search.ClusterSettings;
import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo;
import org.opengroup.osdu.core.common.model.indexer.IElasticSettingService;
import org.opengroup.osdu.core.common.search.IndicesService;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.indexer.util.ElasticClientHandler;
import org.opengroup.osdu.core.common.search.ElasticIndexNameResolver;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.springframework.test.context.junit4.SpringRunner;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.powermock.api.mockito.PowerMockito.when;
@RunWith(SpringRunner.class)
@PrepareForTest({RestHighLevelClient.class, Response.class, RestClient.class, HttpEntity.class, EntityUtils.class})
......@@ -65,8 +65,8 @@ public class IndexCopyServiceImplTest {
private HttpEntity httpEntityRequest;
@Mock
private IRequestInfo requestInfo;
//@Mock TODO
//private IHeadersInfo headersInfo;
@Mock
private DpsHeaders dpsHeaders;
@Mock
private RestClient restClient;
@Mock
......@@ -81,9 +81,8 @@ public class IndexCopyServiceImplTest {
private ElasticIndexNameResolver elasticIndexNameResolver;
@Mock
private Response response;
// TODO alanbrazL investigate this
//@Mock
//private ElasticSettingService elasticSettingService;
@Mock
private IElasticSettingService elasticSettingService;
@Mock
private AuditLogger auditLogger;
@Mock
......@@ -103,8 +102,6 @@ public class IndexCopyServiceImplTest {
httpHeaders = new HashMap<>();
httpHeaders.put(DpsHeaders.AUTHORIZATION, "testAuth");
httpHeaders.put(DpsHeaders.CORRELATION_ID, correlationId);
DpsHeaders standardHeaders = DpsHeaders.createFromMap(httpHeaders);
//when(headersInfo.getHeaders()).thenReturn(standardHeaders);
when(requestInfo.getHeadersMapWithDwdAuthZ()).thenReturn(httpHeaders);
when(response.getEntity()).thenReturn(httpEntity);
......@@ -116,7 +113,7 @@ public class IndexCopyServiceImplTest {
}
// @Test(expected = IOException.class)
@Test(expected = IOException.class)
public void should_throwIOException_when_indexMappingNotFound() throws Exception {
IOException exception = new IOException("Fail to get mapping for the given index from common cluster.");
......@@ -146,14 +143,14 @@ public class IndexCopyServiceImplTest {
}
}
//@Test
@Test
public void should_returnClusterInfo_getCommonClusterInformationtest() {
try {
String[] correctCommonCluster = {"https://commonhost:8080", "username", "pwd"};
when(elasticClientHandler.createRestClient()).thenReturn(restHighLevelClient);
//when(elasticSettingService.getElasticClusterInformation()).thenReturn(commonCluster);
when(elasticSettingService.getElasticClusterInformation()).thenReturn(commonCluster);
String[] resultCommonCluster = this.sut.getCommonClusterInformation();
Assert.assertEquals(correctCommonCluster[0], resultCommonCluster[0]);
......@@ -164,7 +161,7 @@ public class IndexCopyServiceImplTest {
}
}
//@Test(expected = AppException.class)
@Test(expected = AppException.class)
public void should_throwException_failToCreateIndexInTenantCluster_createIndexInTenantClustertest() {
try {
when(elasticClientHandler.createRestClient()).thenReturn(restHighLevelClient);
......
......@@ -175,7 +175,7 @@ public class IndexerMappingServiceTest {
doReturn(response).when(this.restHighLevelClient).updateByQuery(ArgumentMatchers.any(), ArgumentMatchers.any(RequestOptions.class));
when(response.getBulkFailures()).thenReturn(new ArrayList<Failure>());
when(elasticClientHandler.createRestClient()).thenReturn(restHighLevelClient);
this.sut.updateIndexMappingForIndicesOfSameType( indices,"any field");
} catch (Exception e) {
fail("Should not throw this exception" + e.getMessage());
......@@ -209,8 +209,8 @@ public class IndexerMappingServiceTest {
doReturn(response).when(this.restHighLevelClient).updateByQuery(ArgumentMatchers.any(), ArgumentMatchers.any(RequestOptions.class));
when(response.getBulkFailures()).thenReturn(new ArrayList<Failure>());
when(elasticClientHandler.createRestClient()).thenReturn(restHighLevelClient);
this.sut.updateIndexMappingForIndicesOfSameType(indices,"any field");
this.sut.updateIndexMappingForIndicesOfSameType(indices,"any field");
} catch (Exception e) {
throw e;
}
......@@ -220,7 +220,7 @@ public class IndexerMappingServiceTest {
public void should_throw_exception_if_type_of_index_is_invalid_andWeIndexfield_with_keyword() throws Exception {
try {
Set<String> indices = new HashSet<String>();
indices.add("indices 1");
indices.add("indices 1");
GetFieldMappingsResponse getFieldMappingsResponse = mock(GetFieldMappingsResponse.class);
doReturn(this.indicesClient).when(this.restHighLevelClient).indices();
when(this.indicesClient.getFieldMapping(ArgumentMatchers.any(), ArgumentMatchers.any())).thenReturn(getFieldMappingsResponse);
......
......@@ -14,25 +14,6 @@
package org.opengroup.osdu.indexer.ibm.service;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.MockitoAnnotations.initMocks;
import static org.powermock.api.mockito.PowerMockito.mock;
import static org.powermock.api.mockito.PowerMockito.when;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;
import org.apache.http.HttpStatus;
import org.elasticsearch.client.RestHighLevelClient;
import org.junit.Assert;
......@@ -42,21 +23,33 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
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.RequestStatus;
import org.opengroup.osdu.core.common.model.indexer.IndexSchema;
import org.opengroup.osdu.core.common.model.indexer.OperationType;
import org.opengroup.osdu.core.common.search.ElasticIndexNameResolver;
import org.opengroup.osdu.core.common.search.IndicesService;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.indexer.provider.interfaces.ISchemaCache;
import org.opengroup.osdu.indexer.service.IndexSchemaServiceImpl;
import org.opengroup.osdu.indexer.service.IndexerMappingService;
import org.opengroup.osdu.indexer.service.StorageService;
import org.opengroup.osdu.core.common.model.http.RequestStatus;
import org.opengroup.osdu.core.common.search.IndicesService;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.indexer.util.ElasticClientHandler;
import org.opengroup.osdu.core.common.search.ElasticIndexNameResolver;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import static org.mockito.MockitoAnnotations.initMocks;
import static org.powermock.api.mockito.PowerMockito.mock;
import static org.powermock.api.mockito.PowerMockito.when;
@Ignore
@RunWith(SpringRunner.class)
@PrepareForTest({RestHighLevelClient.class})
......
......@@ -15,17 +15,6 @@
package org.opengroup.osdu.indexer.ibm.service;
import static org.junit.Assert.fail;
import static org.mockito.MockitoAnnotations.initMocks;
import static org.powermock.api.mockito.PowerMockito.mockStatic;
import static org.powermock.api.mockito.PowerMockito.when;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
......@@ -34,16 +23,23 @@ import org.junit.runner.RunWith;
import org.mockito.ArgumentMatchers;
import org.mockito.InjectMocks;
import org.mockito.Mock;
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.RecordQueryResponse;
import org.opengroup.osdu.core.common.model.indexer.RecordReindexRequest;
import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.indexer.service.ReindexServiceImpl;
import org.opengroup.osdu.indexer.service.StorageService;
import org.opengroup.osdu.indexer.util.IndexerQueueTaskBuilder;
import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.*;
import static org.junit.Assert.fail;
import static org.mockito.MockitoAnnotations.initMocks;
import static org.powermock.api.mockito.PowerMockito.mockStatic;
import static org.powermock.api.mockito.PowerMockito.when;
@Ignore
@RunWith(SpringRunner.class)
public class ReindexServiceTest {
......
/*
* // Copyright 2017-2019, Schlumberger // // 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.ibm.service;
*
* import static org.mockito.Mockito.when;
*
* import org.junit.Before; import org.junit.Ignore; import org.junit.Test;
* import org.junit.runner.RunWith; import org.mockito.InjectMocks; import
* org.mockito.Mock; 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.opengroup.osdu.indexer.ibm.util.IHeadersInfo; import
* org.springframework.http.HttpHeaders; import
* org.springframework.test.context.junit4.SpringRunner;
*
* @RunWith(SpringRunner.class) public class TenantInfoServiceTest {
*
* private static final String HEADER_NAME = "ANY_HEADER"; private static final
* String HEADER_VALUE = "ANY_VALUE";
*
* @Mock private ITenantFactory tenantFactory;
*
* @Mock private IHeadersInfo headersInfo; // TODO alanbraz investigate
* //@InjectMocks // private TenantInfoService sut;
*
* @Mock private TenantInfo info;
*
* @Mock private HttpHeaders httpHeaders;
*
* @InjectMocks private DpsHeaders HEADERS;
*
* @Before public void setup() { HEADERS.put(HEADER_NAME, HEADER_VALUE); }
*
* @Ignore
*
* @Test public void should_return_validTenant_given_validAccountId() {
*
* when(this.info.getName()).thenReturn("tenant1");
* when(tenantFactory.getTenantInfo("tenant1")).thenReturn(info);
*
* //when(this.headersInfo.getHeaders()).thenReturn(HEADERS);
*
* //when(this.headersInfo.getPartitionId()).thenReturn("tenant1");
*
* //when(this.sut.getTenantInfo()).thenReturn(info);
*
* //assertNotNull(this.sut.getTenantInfo()); assertEquals("tenant1",
* this.sut.getTenantInfo().getName()); }
*
* @Test(expected = AppException.class) public void
* should_throwException_given_invalidAccountId() {
*
* when(this.info.getName()).thenReturn("tenant2");
* when(tenantFactory.getTenantInfo("tenant1")).thenReturn(null);
*
* //when(this.sut.getTenantInfo()).thenReturn(info);
*
* //assertNotNull(this.sut.getTenantInfo()); } }
*/
\ No newline at end of file
// Copyright 2017-2019, Schlumberger
//
// 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.ibm.service;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.when;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
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.opengroup.osdu.indexer.ibm.di.TenantInfoService;
import org.opengroup.osdu.indexer.ibm.util.IHeadersInfo;
import org.springframework.http.HttpHeaders;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
public class TenantInfoServiceTest {
private static final String HEADER_NAME = "ANY_HEADER";
private static final String HEADER_VALUE = "ANY_VALUE";
@Mock
private ITenantFactory tenantFactory;
@Mock
private IHeadersInfo headersInfo;
@InjectMocks
private TenantInfoService sut;
@Mock
private TenantInfo info;
@Mock
private HttpHeaders httpHeaders;
@InjectMocks
private DpsHeaders HEADERS;
@Before
public void setup() {
HEADERS.put(HEADER_NAME, HEADER_VALUE);
}
@Ignore
@Test
public void should_return_validTenant_given_validAccountId() {
when(this.info.getName()).thenReturn("tenant1");
when(tenantFactory.getTenantInfo("tenant1")).thenReturn(info);
when(this.headersInfo.getHeaders()).thenReturn(HEADERS);
when(this.headersInfo.getPartitionId()).thenReturn("tenant1");
when(this.sut.getTenantInfo()).thenReturn(info);
assertNotNull(this.sut.getTenantInfo());
assertEquals("tenant1", this.sut.getTenantInfo().getName());
}
@Ignore
@Test(expected = AppException.class)
public void should_throwException_given_invalidAccountId() {
when(this.info.getName()).thenReturn("tenant2");
when(tenantFactory.getTenantInfo("tenant1")).thenReturn(null);
when(this.sut.getTenantInfo()).thenReturn(info);
assertNotNull(this.sut.getTenantInfo());
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment