diff options
Diffstat (limited to 'so-cnf-adapter-application/src/test')
8 files changed, 106 insertions, 94 deletions
diff --git a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/exceptions/ApplicationExceptionTest.java b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/exceptions/ApplicationExceptionTest.java index bc39e95..495c913 100644 --- a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/exceptions/ApplicationExceptionTest.java +++ b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/exceptions/ApplicationExceptionTest.java @@ -22,8 +22,11 @@ package org.onap.so.adapters.cnf.exceptions; import org.junit.Test;
import org.junit.runner.RunWith;
-import org.onap.so.adapters.cnf.model.*;
-import org.springframework.http.HttpStatus;
+import org.onap.so.adapters.cnf.model.GroupVersionKind;
+import org.onap.so.adapters.cnf.model.InstanceStatusResponse;
+import org.onap.so.adapters.cnf.model.MulticloudInstanceRequest;
+import org.onap.so.adapters.cnf.model.PodStatus;
+import org.onap.so.adapters.cnf.model.Resource;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.List;
@@ -89,4 +92,5 @@ public class ApplicationExceptionTest { applicationexception.buildErrorResponse();
}
-}
\ No newline at end of file +
+}
diff --git a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/rest/CnfAdapterRestTest.java b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/rest/CnfAdapterRestTest.java index 48eecaa..e5c50c4 100644 --- a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/rest/CnfAdapterRestTest.java +++ b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/rest/CnfAdapterRestTest.java @@ -27,7 +27,21 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.onap.so.adapters.cnf.MulticloudConfiguration; -import org.onap.so.adapters.cnf.model.*; +import org.onap.so.adapters.cnf.model.BpmnInstanceRequest; +import org.onap.so.adapters.cnf.model.CheckInstanceRequest; +import org.onap.so.adapters.cnf.model.ConfigTemplateEntity; +import org.onap.so.adapters.cnf.model.ConfigurationEntity; +import org.onap.so.adapters.cnf.model.ConfigurationRollbackEntity; +import org.onap.so.adapters.cnf.model.ConnectivityInfo; +import org.onap.so.adapters.cnf.model.InstanceMiniResponse; +import org.onap.so.adapters.cnf.model.InstanceMiniResponseList; +import org.onap.so.adapters.cnf.model.InstanceResponse; +import org.onap.so.adapters.cnf.model.InstanceStatusResponse; +import org.onap.so.adapters.cnf.model.MulticloudInstanceRequest; +import org.onap.so.adapters.cnf.model.ProfileEntity; +import org.onap.so.adapters.cnf.model.Resource; +import org.onap.so.adapters.cnf.model.ResourceBundleEntity; +import org.onap.so.adapters.cnf.model.Tag; import org.onap.so.adapters.cnf.model.healthcheck.HealthCheckResponse; import org.onap.so.adapters.cnf.service.CnfAdapterService; import org.springframework.http.HttpStatus; @@ -35,12 +49,14 @@ import org.springframework.http.ResponseEntity; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.context.request.async.DeferredResult; import org.springframework.web.multipart.MultipartFile; + import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import static org.junit.Assert.assertEquals; + import static org.assertj.core.api.Java6Assertions.assertThat; +import static org.junit.Assert.assertEquals; @RunWith(SpringRunner.class) diff --git a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/CnfAdapterServiceTest.java b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/CnfAdapterServiceTest.java index f049310..7d161bc 100644 --- a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/CnfAdapterServiceTest.java +++ b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/CnfAdapterServiceTest.java @@ -20,12 +20,7 @@ package org.onap.so.adapters.cnf.service; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.spy; - +import lombok.Data; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -37,20 +32,21 @@ import org.onap.so.adapters.cnf.service.healthcheck.HealthCheckService; import org.onap.so.adapters.cnf.service.statuscheck.SimpleStatusCheckService; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.HttpServerErrorException; import org.springframework.web.client.HttpStatusCodeException; import org.springframework.web.client.RestTemplate; +import javax.persistence.EntityNotFoundException; import java.io.IOException; import java.util.HashMap; import java.util.Map; -import javax.persistence.EntityNotFoundException; - -import lombok.Data; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; @RunWith(SpringRunner.class) public class CnfAdapterServiceTest { diff --git a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/aai/AaiIdGeneratorServiceTest.java b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/aai/AaiIdGeneratorServiceTest.java index 70070e4..948bc0b 100644 --- a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/aai/AaiIdGeneratorServiceTest.java +++ b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/aai/AaiIdGeneratorServiceTest.java @@ -6,8 +6,10 @@ import org.junit.runner.RunWith; import org.onap.so.adapters.cnf.model.instantiation.AaiRequest; import org.onap.so.adapters.cnf.model.statuscheck.K8sRbInstanceGvk; import org.onap.so.adapters.cnf.model.statuscheck.K8sRbInstanceResourceStatus; +import org.onap.so.adapters.cnf.util.IAaiRepository; import org.springframework.test.context.junit4.SpringRunner; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/aai/AaiResponseParserTest.java b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/aai/AaiResponseParserTest.java index f3c0558..e962848 100644 --- a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/aai/AaiResponseParserTest.java +++ b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/aai/AaiResponseParserTest.java @@ -1,3 +1,23 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2021 Samsung Electronics Co. Ltd. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + package org.onap.so.adapters.cnf.service.aai; import org.junit.Assert; @@ -12,8 +32,6 @@ import org.onap.so.adapters.cnf.model.statuscheck.K8sStatus; import org.onap.so.adapters.cnf.model.statuscheck.K8sStatusMetadata; import org.springframework.test.context.junit4.SpringRunner; -import java.util.ArrayList; -import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -24,6 +42,9 @@ import static org.mockito.Mockito.when; @RunWith(SpringRunner.class) public class AaiResponseParserTest { + private final static String INSTANCE_ID = "k8splugin.io/rb-instance-id"; + private final static String INSTANCE_ID_VALUE = "rb-instance-id_value"; + @InjectMocks private AaiResponseParser aaiResponseParser; @@ -42,6 +63,7 @@ public class AaiResponseParserTest { String namespace = "namespace"; Map<String, String> labelsMap = new HashMap<>(); labelsMap.put("key", "value"); + labelsMap.put(INSTANCE_ID, INSTANCE_ID_VALUE); K8sRbInstanceResourceStatus status = mock(K8sRbInstanceResourceStatus.class); AaiRequest aaiRequest = mock(AaiRequest.class); K8sRbInstanceGvk gvk = mock(K8sRbInstanceGvk.class); @@ -63,7 +85,7 @@ public class AaiResponseParserTest { when(metadata.getLabels()).thenReturn(labelsMap); // then - ParseResult actual = aaiResponseParser.parse(status, aaiRequest); + KubernetesResource actual = aaiResponseParser.parse(status, aaiRequest); Assert.assertNotNull(actual); assertEquals(id, actual.getId()); @@ -72,30 +94,9 @@ public class AaiResponseParserTest { assertEquals(version, actual.getVersion()); assertEquals(kind, actual.getKind()); assertEquals(namespace, actual.getNamespace()); - assertEquals(2, actual.getLabels().size()); - assertEquals("http://so-cnf-adapter:8090/api/cnf-adapter/v1/instance/id/query", actual.getK8sResourceSelfLink()); - - } - - ParseResult parse(K8sRbInstanceResourceStatus status, AaiRequest aaiRequest) { - ParseResult result = new ParseResult(); - K8sRbInstanceGvk gvk = status.getGvk(); - K8sStatus k8sStatus = status.getStatus(); - K8sStatusMetadata metadata = k8sStatus.getK8sStatusMetadata(); - String id = aaiIdGeneratorService.generateId(status, aaiRequest); - result.setId(id); - result.setName(status.getName()); - result.setGroup(gvk.getGroup()); - result.setVersion(gvk.getVersion()); - result.setKind(gvk.getKind()); - result.setNamespace(metadata.getNamespace()); - Collection<String> labels = new ArrayList<>(); - metadata.getLabels().forEach((key, value) -> { - labels.add(key); - labels.add(value); - }); - result.setLabels(labels); - result.setK8sResourceSelfLink(String.format("http://so-cnf-adapter:8090/api/cnf-adapter/v1/instance/%s/query", aaiRequest.getInstanceId())); - return result; + assertEquals(4, actual.getLabels().size()); + assertEquals(INSTANCE_ID, actual.getLabels().get(0)); + assertEquals(INSTANCE_ID_VALUE, actual.getLabels().get(1)); + assertEquals("http://so-cnf-adapter:8090/api/cnf-adapter/v1/instance/id/query?ApiVersion=version&Kind=kind&Name=name&Namespace=namespace", actual.getK8sResourceSelfLink()); } -}
\ No newline at end of file +} diff --git a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/aai/AaiServiceTest.java b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/aai/AaiServiceTest.java index f8f9597..a4e0625 100644 --- a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/aai/AaiServiceTest.java +++ b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/aai/AaiServiceTest.java @@ -16,7 +16,6 @@ import java.util.ArrayList; import java.util.List; import static org.mockito.Mockito.atLeast; -import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -30,8 +29,6 @@ public class AaiServiceTest { @Mock private MulticloudClient multicloudClient; @Mock - private AaiRequestSender aaiRequestSender; - @Mock private AaiResponseParser responseParser; @Mock private AaiConfiguration aaiConfiguration; @@ -45,8 +42,8 @@ public class AaiServiceTest { K8sRbInstanceResourceStatus status = mock(K8sRbInstanceResourceStatus.class); List<K8sRbInstanceResourceStatus> resourcesStatus = new ArrayList<>(); resourcesStatus.add(status); - ParseResult parseResult = mock(ParseResult.class); - List<ParseResult> parseResultList = new ArrayList<>(); + KubernetesResource parseResult = mock(KubernetesResource.class); + List<KubernetesResource> parseResultList = new ArrayList<>(); parseResultList.add(parseResult); // when @@ -54,14 +51,11 @@ public class AaiServiceTest { when(multicloudClient.getInstanceStatus(instanceId)).thenReturn(instanceStatus); when(instanceStatus.getResourcesStatus()).thenReturn(resourcesStatus); when(responseParser.parse(status, aaiRequest)).thenReturn(parseResult); - when(aaiConfiguration.isEnabled()).thenReturn(true); - doNothing().when(aaiRequestSender).sendUpdateRequestToAai(parseResult, aaiRequest); // then aaiServiceTested.aaiUpdate(aaiRequest); verify(responseParser, atLeast(1)).parse(status, aaiRequest); - verify(aaiRequestSender, atLeast(1)).sendUpdateRequestToAai(parseResult, aaiRequest); } @@ -74,8 +68,8 @@ public class AaiServiceTest { K8sRbInstanceResourceStatus status = mock(K8sRbInstanceResourceStatus.class); List<K8sRbInstanceResourceStatus> resourcesStatus = new ArrayList<>(); resourcesStatus.add(status); - ParseResult parseResult = mock(ParseResult.class); - List<ParseResult> parseResultList = new ArrayList<>(); + KubernetesResource parseResult = mock(KubernetesResource.class); + List<KubernetesResource> parseResultList = new ArrayList<>(); parseResultList.add(parseResult); // when @@ -83,13 +77,10 @@ public class AaiServiceTest { when(multicloudClient.getInstanceStatus(instanceId)).thenReturn(instanceStatus); when(instanceStatus.getResourcesStatus()).thenReturn(resourcesStatus); when(responseParser.parse(status, aaiRequest)).thenReturn(parseResult); - when(aaiConfiguration.isEnabled()).thenReturn(true); - doNothing().when(aaiRequestSender).sendUpdateRequestToAai(parseResult, aaiRequest); // then aaiServiceTested.aaiDelete(aaiRequest); verify(responseParser, atLeast(1)).parse(status, aaiRequest); - verify(aaiRequestSender, atLeast(1)).sendDeleteRequestToAai(aaiRequest); } -}
\ No newline at end of file +} diff --git a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/healthcheck/HealthCheckServiceTest.java b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/healthcheck/HealthCheckServiceTest.java index 9a043ba..33d3104 100644 --- a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/healthcheck/HealthCheckServiceTest.java +++ b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/healthcheck/HealthCheckServiceTest.java @@ -1,81 +1,79 @@ package org.onap.so.adapters.cnf.service.healthcheck; -import static java.util.Arrays.asList; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.UUID; - -import org.junit.jupiter.api.BeforeEach; +import com.github.tomakehurst.wiremock.junit.WireMockRule; +import org.junit.Rule; import org.junit.jupiter.api.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.onap.so.adapters.cnf.client.MulticloudClient; import org.onap.so.adapters.cnf.model.CheckInstanceRequest; import org.onap.so.adapters.cnf.model.InstanceRequest; import org.onap.so.adapters.cnf.model.healthcheck.HealthCheckResponse; import org.onap.so.adapters.cnf.model.healthcheck.K8sRbInstanceHealthCheck; import org.onap.so.adapters.cnf.model.healthcheck.K8sRbInstanceHealthCheckSimple; -import org.onap.so.client.exception.BadResponseException; +import org.springframework.boot.test.context.SpringBootTest; + +import java.util.UUID; + +import static java.util.Arrays.asList; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +@SpringBootTest +@RunWith(MockitoJUnitRunner.class) class HealthCheckServiceTest { + private final int portNumber = 8443; + @Rule + public WireMockRule wireMockRule = new WireMockRule(portNumber); @InjectMocks - HealthCheckService healthCheckService; + private HealthCheckService healthCheckService; @Mock - MulticloudClient multicloudClient; - - @BeforeEach - void setUp() { - MockitoAnnotations.initMocks(this); - } + private MulticloudClient multicloudClient; @Test - void healthCheckTest() { + public void healthCheckTest() { try { doReturn(getK8sRbInstanceHealthCheckSimple()).when(multicloudClient).startInstanceHealthCheck(any()); - doReturn(getK8sRbInstanceHealthCheck()).when(multicloudClient).getInstanceHealthCheck(any(),any()); + doReturn(getK8sRbInstanceHealthCheck()).when(multicloudClient).getInstanceHealthCheck(any(), any()); HealthCheckResponse response = healthCheckService.healthCheck(getTestCheckInstanceRequest()); verify(multicloudClient, times(3)).startInstanceHealthCheck(any()); - verify(multicloudClient, times(3)).getInstanceHealthCheck(any(),any()); + verify(multicloudClient, times(3)).getInstanceHealthCheck(any(), any()); assertThat(response.getInstanceResponse()).hasSize(getTestCheckInstanceRequest().getInstances().size()); } catch (Exception e) { e.printStackTrace(); } } - private CheckInstanceRequest getTestCheckInstanceRequest(){ - CheckInstanceRequest checkInstanceRequest=new CheckInstanceRequest() ; - checkInstanceRequest.setInstances(asList(getRandomInstance(),getRandomInstance(),getRandomInstance())); + private CheckInstanceRequest getTestCheckInstanceRequest() { + CheckInstanceRequest checkInstanceRequest = new CheckInstanceRequest(); + checkInstanceRequest.setInstances(asList(getRandomInstance(), getRandomInstance(), getRandomInstance())); return checkInstanceRequest; } - private InstanceRequest getRandomInstance(){ - InstanceRequest instanceRequest=new InstanceRequest(); + private InstanceRequest getRandomInstance() { + InstanceRequest instanceRequest = new InstanceRequest(); instanceRequest.setInstanceId(UUID.randomUUID().toString()); return instanceRequest; } - private K8sRbInstanceHealthCheckSimple getK8sRbInstanceHealthCheckSimple(){ - K8sRbInstanceHealthCheckSimple k8sRbInstanceHealthCheckSimple=new K8sRbInstanceHealthCheckSimple(); + private K8sRbInstanceHealthCheckSimple getK8sRbInstanceHealthCheckSimple() { + K8sRbInstanceHealthCheckSimple k8sRbInstanceHealthCheckSimple = new K8sRbInstanceHealthCheckSimple(); k8sRbInstanceHealthCheckSimple.setId(UUID.randomUUID().toString()); k8sRbInstanceHealthCheckSimple.setStatus("RUNNING"); return k8sRbInstanceHealthCheckSimple; } - private K8sRbInstanceHealthCheck getK8sRbInstanceHealthCheck(){ - K8sRbInstanceHealthCheck k8sRbInstanceHealthCheck=new K8sRbInstanceHealthCheck(); + private K8sRbInstanceHealthCheck getK8sRbInstanceHealthCheck() { + K8sRbInstanceHealthCheck k8sRbInstanceHealthCheck = new K8sRbInstanceHealthCheck(); k8sRbInstanceHealthCheck.setStatus("STOPPED"); return k8sRbInstanceHealthCheck; } -}
\ No newline at end of file +} diff --git a/so-cnf-adapter-application/src/test/resources/application.properties b/so-cnf-adapter-application/src/test/resources/application.properties new file mode 100644 index 0000000..154283c --- /dev/null +++ b/so-cnf-adapter-application/src/test/resources/application.properties @@ -0,0 +1,4 @@ +aai.enabled=true +aai.endpoint=http://localhost:8443 +aai.auth=5E12ACACBD552A415E081E29F2C4772F9835792A51C766CCFDD7433DB5220B59969CB2798C +mso.msoKey=07a7159d3bf51a0e53be7a8f89699be7
\ No newline at end of file |