Skip to content
Snippets Groups Projects
Commit a40eb2d2 authored by Anastasiia Gelmut's avatar Anastasiia Gelmut Committed by Rostislav Dublin (EPAM)
Browse files

GONRG-844 Rewrite ElasticClientHandlerTest

-Updated ElasticClientHandlerTest.java.
parent ba0dd9d6
No related branches found
No related tags found
No related merge requests found
...@@ -19,29 +19,30 @@ import org.elasticsearch.client.RestClient; ...@@ -19,29 +19,30 @@ import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder; import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.client.RestHighLevelClient;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.Mock; import org.mockito.Mock;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.indexer.IElasticSettingService; import org.opengroup.osdu.core.common.model.indexer.IElasticSettingService;
import org.opengroup.osdu.core.common.model.search.ClusterSettings; import org.opengroup.osdu.core.common.model.search.ClusterSettings;
import org.opengroup.osdu.core.common.model.search.DeploymentEnvironment; import org.opengroup.osdu.core.common.model.search.DeploymentEnvironment;
import org.opengroup.osdu.indexer.config.IndexerConfigurationProperties; import org.opengroup.osdu.indexer.config.IndexerConfigurationProperties;
import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.core.classloader.annotations.PrepareForTest;
import org.springframework.test.context.junit4.SpringRunner; import org.powermock.modules.junit4.PowerMockRunner;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks; import static org.mockito.MockitoAnnotations.initMocks;
import static org.powermock.api.mockito.PowerMockito.mockStatic;
@Ignore @RunWith(PowerMockRunner.class)
@RunWith(SpringRunner.class) @PrepareForTest({RestClient.class, RestHighLevelClient.class})
@PrepareForTest({RestClientBuilder.class, RestClient.class, RestHighLevelClient.class})
public class ElasticClientHandlerTest { public class ElasticClientHandlerTest {
private static final boolean SECURITY_HTTPS_CERTIFICATE_TRUST = false;
@Mock @Mock
private IndexerConfigurationProperties configurationProperties; private IndexerConfigurationProperties configurationProperties;
@Mock @Mock
...@@ -62,7 +63,9 @@ public class ElasticClientHandlerTest { ...@@ -62,7 +63,9 @@ public class ElasticClientHandlerTest {
public void setup() { public void setup() {
initMocks(this); initMocks(this);
// mockStatic(RestClient.class); mockStatic(RestClient.class);
elasticClientHandler.setSecurityHttpsCertificateTrust(SECURITY_HTTPS_CERTIFICATE_TRUST);
} }
@Test @Test
...@@ -70,7 +73,7 @@ public class ElasticClientHandlerTest { ...@@ -70,7 +73,7 @@ public class ElasticClientHandlerTest {
ClusterSettings clusterSettings = new ClusterSettings("H", 1, "U:P"); ClusterSettings clusterSettings = new ClusterSettings("H", 1, "U:P");
when(configurationProperties.getDeploymentEnvironment()).thenReturn(DeploymentEnvironment.CLOUD); when(configurationProperties.getDeploymentEnvironment()).thenReturn(DeploymentEnvironment.CLOUD);
when(elasticSettingService.getElasticClusterInformation()).thenReturn(clusterSettings); when(elasticSettingService.getElasticClusterInformation()).thenReturn(clusterSettings);
when(RestClient.builder(new HttpHost("H", 1, "https"))).thenReturn(builder); when(RestClient.builder(new HttpHost("H", 1, "https"))).thenAnswer(invocation -> builder);
when(builder.setRequestConfigCallback(requestConfigBuilder -> requestConfigBuilder.setConnectTimeout(5000).setSocketTimeout(60000))).thenReturn(builder); when(builder.setRequestConfigCallback(requestConfigBuilder -> requestConfigBuilder.setConnectTimeout(5000).setSocketTimeout(60000))).thenReturn(builder);
when(builder.build()).thenReturn(restClient); when(builder.build()).thenReturn(restClient);
...@@ -84,7 +87,7 @@ public class ElasticClientHandlerTest { ...@@ -84,7 +87,7 @@ public class ElasticClientHandlerTest {
ClusterSettings clusterSettings = new ClusterSettings("H", 1, "U:P"); ClusterSettings clusterSettings = new ClusterSettings("H", 1, "U:P");
when(configurationProperties.getDeploymentEnvironment()).thenReturn(DeploymentEnvironment.CLOUD); when(configurationProperties.getDeploymentEnvironment()).thenReturn(DeploymentEnvironment.CLOUD);
when(elasticSettingService.getElasticClusterInformation()).thenReturn(clusterSettings); when(elasticSettingService.getElasticClusterInformation()).thenReturn(clusterSettings);
when(RestClient.builder(new HttpHost("H", 1, "https"))).thenReturn(builder); when(RestClient.builder(new HttpHost("H", 1, "https"))).thenAnswer(invocation -> builder);
when(builder.build()).thenReturn(null); when(builder.build()).thenReturn(null);
this.elasticClientHandler.createRestClient(); this.elasticClientHandler.createRestClient();
...@@ -94,7 +97,7 @@ public class ElasticClientHandlerTest { ...@@ -94,7 +97,7 @@ public class ElasticClientHandlerTest {
public void failed_createRestClientForSaaS_when_getcluster_info_throws_exception() { public void failed_createRestClientForSaaS_when_getcluster_info_throws_exception() {
when(configurationProperties.getDeploymentEnvironment()).thenReturn(DeploymentEnvironment.CLOUD); when(configurationProperties.getDeploymentEnvironment()).thenReturn(DeploymentEnvironment.CLOUD);
when(elasticSettingService.getElasticClusterInformation()).thenThrow(new AppException(1, "", "")); when(elasticSettingService.getElasticClusterInformation()).thenThrow(new AppException(1, "", ""));
when(RestClient.builder(new HttpHost("H", 1, "https"))).thenReturn(builder); when(RestClient.builder(new HttpHost("H", 1, "https"))).thenAnswer(invocation -> builder);
this.elasticClientHandler.createRestClient(); this.elasticClientHandler.createRestClient();
} }
......
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