Skip to content
Snippets Groups Projects
Commit 3f674b27 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-4906 update unittests

parent 3d269293
No related branches found
No related tags found
No related merge requests found
......@@ -26,18 +26,16 @@ public class OzgCloudElasticsearchService {
private final OzgCloudElasticsearchSecretHelper secretHelper;
private final OzgCloudElasticsearchProperties properties;
private final OzgCloudElasticsearchServerProperties serverProperties;
private final ElasticsearchRemoteService remoteService;
private final KubernetesRemoteService kubernetesService;
public void copyElasticCertificate(String namespace) {
try {
LOG.debug("Copy elasticseaerch ssl certificate from namespace: {}" , serverProperties.getCertificateNamespace());
LOG.debug("Copy elasticseaerch ssl certificate secret: {}" , serverProperties.getCertificateSecretName());
LOG.debug("Copy elasticseaerch ssl certificate from namespace: {}" , properties.getServer().getCertificateNamespace());
LOG.debug("Copy elasticseaerch ssl certificate secret: {}" , properties.getServer().getCertificateSecretName());
var secretResource = kubernetesService.getSecretResource(serverProperties.getCertificateNamespace(), serverProperties.getCertificateSecretName());
var secretResource = kubernetesService.getSecretResource(properties.getServer().getCertificateNamespace(), properties.getServer().getCertificateSecretName());
LOG.info("{}: Create certificate secret", namespace);
createCredentialSecret(secretResource,namespace);
} catch (ElasticsearchException e) {
......
......@@ -56,10 +56,6 @@ class OzgCloudElasticsearchServiceTest {
private Context<OzgCloudElasticsearchCustomResource> context;
@Mock
private ResourceAdapter<Secret> resourceAdapter;
//@Mock
//private Resource<Secret> secretResource;
private final OzgCloudElasticsearchCustomResource resource = ElasticsearchCustomResourceTestFactory.create();
......@@ -127,6 +123,7 @@ class OzgCloudElasticsearchServiceTest {
void shouldCheckIfIndexExists() {
when(kubernetesService.getSecretResource(any(), any())).thenReturn(secretResource);
when(serverProperties.getCertificateNamespace()).thenReturn(NAMESPACE);
when(properties.getServer()).thenReturn(serverProperties);
service.createIndexIfMissing(NAMESPACE);
......@@ -139,6 +136,7 @@ class OzgCloudElasticsearchServiceTest {
when(kubernetesService.getSecretResource(any(), any())).thenReturn(secretResource);
when(serverProperties.getCertificateNamespace()).thenReturn(NAMESPACE);
when(remoteService.existsIndex(any())).thenReturn(false);
when(properties.getServer()).thenReturn(serverProperties);
service.createIndexIfMissing(NAMESPACE);
......@@ -149,6 +147,7 @@ class OzgCloudElasticsearchServiceTest {
@Test
void shouldCallCopyElasticCertificate() {
when(kubernetesService.getSecretResource(any(), any())).thenReturn(secretResource);
when(properties.getServer()).thenReturn(serverProperties);
service.createIndexIfMissing(NAMESPACE);
......@@ -168,6 +167,7 @@ class OzgCloudElasticsearchServiceTest {
doReturn(putRoleRequest).when(service).buildPutRoleRequestData(any());
when(kubernetesService.getSecretResource(any(), any())).thenReturn(secretResource);
when(properties.getServer()).thenReturn(serverProperties);
service.createSecurityRoleIfMissing(NAMESPACE);
......@@ -179,6 +179,7 @@ class OzgCloudElasticsearchServiceTest {
void shouldCallCopyElasticCertificate() {
when(kubernetesService.getSecretResource(any(), any())).thenReturn(secretResource);
when(properties.getServer()).thenReturn(serverProperties);
service.createSecurityRoleIfMissing(NAMESPACE);
......@@ -232,6 +233,7 @@ class OzgCloudElasticsearchServiceTest {
void shouldCreateSecurityUserIfMissing() {
doReturn(putUserRequestData).when(service).buildPutUserRequestData(any(), any());
when(kubernetesService.getSecretResource(any(), any())).thenReturn(secretResource);
when(properties.getServer()).thenReturn(serverProperties);
service.createSecurityUserIfMissing(NAMESPACE, PutUserRequestDataTestFactory.PASSWORD);
......@@ -242,6 +244,7 @@ class OzgCloudElasticsearchServiceTest {
@Test
void shouldCallCopyElasticCertificate() {
when(kubernetesService.getSecretResource(any(), any())).thenReturn(secretResource);
when(properties.getServer()).thenReturn(serverProperties);
service.createSecurityUserIfMissing(NAMESPACE, PutUserRequestDataTestFactory.PASSWORD);
......@@ -287,6 +290,7 @@ class OzgCloudElasticsearchServiceTest {
@Test
void shouldDeleteSecurityUserIfExists() {
when(kubernetesService.getSecretResource(any(), any())).thenReturn(secretResource);
when(properties.getServer()).thenReturn(serverProperties);
service.deleteSecurityUserIfExists(PutUserRequestDataTestFactory.USERNAME);
......@@ -297,6 +301,7 @@ class OzgCloudElasticsearchServiceTest {
@Test
void shouldCallCopyElasticCertificate() {
when(kubernetesService.getSecretResource(any(), any())).thenReturn(secretResource);
when(properties.getServer()).thenReturn(serverProperties);
service.deleteSecurityUserIfExists(PutUserRequestDataTestFactory.USERNAME);
......@@ -311,9 +316,11 @@ class OzgCloudElasticsearchServiceTest {
@SneakyThrows
@Test
void shouldDeleteSecurityRoleIfExists() {
when(properties.getServer()).thenReturn(serverProperties);
when(kubernetesService.getSecretResource(any(), any())).thenReturn(secretResource);
service.deleteSecurityRoleIfExists(PutRoleRequestDataTestFactory.NAME);
verify(remoteService).deleteSecurityRole(PutRoleRequestDataTestFactory.NAME);
}
......@@ -321,6 +328,7 @@ class OzgCloudElasticsearchServiceTest {
@Test
void shouldCallCopyElasticCertificate() {
when(kubernetesService.getSecretResource(any(), any())).thenReturn(secretResource);
when(properties.getServer()).thenReturn(serverProperties);
service.deleteSecurityRoleIfExists(PutRoleRequestDataTestFactory.NAME);
......@@ -338,6 +346,7 @@ class OzgCloudElasticsearchServiceTest {
@Test
void shouldCheckIfIndexExists() {
when(kubernetesService.getSecretResource(any(), any())).thenReturn(secretResource);
when(properties.getServer()).thenReturn(serverProperties);
service.deleteIndexIfExists(INDEX_NAME);
......@@ -348,12 +357,24 @@ class OzgCloudElasticsearchServiceTest {
@Test
void shouldDeleteIndexIfExists() {
when(kubernetesService.getSecretResource(any(), any())).thenReturn(secretResource);
when(properties.getServer()).thenReturn(serverProperties);
when(remoteService.existsIndex(any())).thenReturn(true);
service.deleteIndexIfExists(INDEX_NAME);
verify(remoteService).deleteIndex(INDEX_NAME);
}
@SneakyThrows
@Test
void shouldCallCopyElasticCertificate() {
when(kubernetesService.getSecretResource(any(), any())).thenReturn(secretResource);
when(properties.getServer()).thenReturn(serverProperties);
service.deleteIndexIfExists(INDEX_NAME);
verify(service).copyElasticCertificate(INDEX_NAME);
}
}
@DisplayName("Create certificate if missing")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment