summaryrefslogtreecommitdiffstats
path: root/so-cnf-adapter-application/src
diff options
context:
space:
mode:
authorGrzegorz Wielgosinski <g.wielgosins@samsung.com>2021-08-26 14:59:48 +0200
committerGrzegorz Wielgosinski <g.wielgosins@samsung.com>2021-08-26 15:24:14 +0200
commit66d661ae03fee02d573146f7a3438e6b7feb2ee7 (patch)
treef0ab87a83c0578f17a051e86611faac3b14f057d /so-cnf-adapter-application/src
parentbd0b3c7cac499f4d24c536afa0b98be82a6acae8 (diff)
Add tests for AAI and SimpleStatusCheckService
Issue-ID: SO-3747 Signed-off-by: Grzegorz Wielgosinski <g.wielgosins@samsung.com> Change-Id: I25db2c9a46deb964de5e25f5e01871e1c7279d39
Diffstat (limited to 'so-cnf-adapter-application/src')
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/AaiRequestSender.java40
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/AaiResponseParser.java44
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/AaiService.java161
-rw-r--r--so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/ParseResult.java78
-rw-r--r--so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/aai/AaiIdGeneratorServiceTest.java51
-rw-r--r--so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/aai/AaiResponseParserTest.java101
-rw-r--r--so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/aai/AaiServiceTest.java90
-rw-r--r--so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/statuscheck/SimpleStatusCheckServiceTest.java83
8 files changed, 503 insertions, 145 deletions
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/AaiRequestSender.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/AaiRequestSender.java
new file mode 100644
index 0000000..8dd7647
--- /dev/null
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/AaiRequestSender.java
@@ -0,0 +1,40 @@
+package org.onap.so.adapters.cnf.service.aai;
+
+import com.google.gson.Gson;
+import org.onap.aaiclient.client.aai.AAIResourcesClient;
+import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri;
+import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory;
+import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder;
+import org.onap.so.adapters.cnf.model.instantiation.AaiRequest;
+import org.springframework.stereotype.Component;
+
+@Component
+class AaiRequestSender {
+
+ private final static Gson gson = new Gson();
+ private AAIResourcesClient aaiClient;
+
+ void sendUpdateRequestToAai(ParseResult parseResult, AaiRequest aaiRequest) {
+ AAIResourceUri aaiUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure()
+ .cloudRegion(aaiRequest.getCloudOwner(), aaiRequest.getCloudRegion())
+ .tenant(aaiRequest.getTenantId())
+ .build());
+ String payload = gson.toJson(parseResult);
+ getAaiClient().create(aaiUri, payload);
+ }
+
+ void sendDeleteRequestToAai(AaiRequest aaiRequest) {
+ AAIResourceUri aaiUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure()
+ .cloudRegion(aaiRequest.getCloudOwner(), aaiRequest.getCloudRegion())
+ .tenant(aaiRequest.getTenantId())
+ .build());
+ getAaiClient().delete(aaiUri);
+ }
+
+ private AAIResourcesClient getAaiClient() {
+ if (aaiClient == null) {
+ aaiClient = new AAIResourcesClient();
+ }
+ return aaiClient;
+ }
+}
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/AaiResponseParser.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/AaiResponseParser.java
new file mode 100644
index 0000000..304c023
--- /dev/null
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/AaiResponseParser.java
@@ -0,0 +1,44 @@
+package org.onap.so.adapters.cnf.service.aai;
+
+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.model.statuscheck.K8sStatus;
+import org.onap.so.adapters.cnf.model.statuscheck.K8sStatusMetadata;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+@Component
+public class AaiResponseParser {
+
+ private final AaiIdGeneratorService aaiIdGeneratorService;
+
+ public AaiResponseParser(AaiIdGeneratorService aaiIdGeneratorService) {
+ this.aaiIdGeneratorService = aaiIdGeneratorService;
+ }
+
+ 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;
+ }
+
+}
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/AaiService.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/AaiService.java
index effecce..4827578 100644
--- a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/AaiService.java
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/AaiService.java
@@ -1,176 +1,47 @@
package org.onap.so.adapters.cnf.service.aai;
-import com.google.gson.Gson;
-import org.onap.aaiclient.client.aai.AAIResourcesClient;
-import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri;
-import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory;
-import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder;
import org.onap.so.adapters.cnf.client.MulticloudClient;
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.model.statuscheck.K8sRbInstanceStatus;
-import org.onap.so.adapters.cnf.model.statuscheck.K8sStatusMetadata;
import org.onap.so.client.exception.BadResponseException;
import org.springframework.stereotype.Service;
-import java.util.*;
+import java.util.List;
import java.util.stream.Collectors;
@Service
public class AaiService {
- private final static Gson gson = new Gson();
private final MulticloudClient multicloudClient;
- private final AaiIdGeneratorService aaiIdGeneratorService;
- private AAIResourcesClient aaiClient;
+ private final AaiRequestSender aaiRequestSender;
+ private final AaiResponseParser responseParser;
- public AaiService(MulticloudClient multicloudClient, AaiIdGeneratorService aaiIdGeneratorService) {
+ public AaiService(MulticloudClient multicloudClient, AaiRequestSender aaiRequestSender, AaiResponseParser responseParser) {
this.multicloudClient = multicloudClient;
- this.aaiIdGeneratorService = aaiIdGeneratorService;
+ this.aaiRequestSender = aaiRequestSender;
+ this.responseParser = responseParser;
}
public void aaiUpdate(AaiRequest aaiRequest) throws BadResponseException {
- String instanceId = aaiRequest.getInstanceId();
- K8sRbInstanceStatus instanceStatus = multicloudClient.getInstanceStatus(instanceId);
-
- List<K8sRbInstanceResourceStatus> resourcesStatus = instanceStatus.getResourcesStatus();
- List<ParseResult> parsedStatus = resourcesStatus.stream()
- .map(status -> parse(status, aaiRequest))
- .collect(Collectors.toList());
+ List<ParseResult> parseStatus = parseStatus(aaiRequest);
- parsedStatus.forEach(status -> sendUpdateRequestToAai(status, aaiRequest));
+ parseStatus.forEach(status -> aaiRequestSender.sendUpdateRequestToAai(status, aaiRequest));
}
public void aaiDelete(AaiRequest aaiRequest) throws BadResponseException {
+ List<ParseResult> parseStatus = parseStatus(aaiRequest);
+
+ parseStatus.forEach(status -> aaiRequestSender.sendDeleteRequestToAai(aaiRequest));
+ }
+
+ private List<ParseResult> parseStatus(AaiRequest aaiRequest) throws BadResponseException {
String instanceId = aaiRequest.getInstanceId();
K8sRbInstanceStatus instanceStatus = multicloudClient.getInstanceStatus(instanceId);
List<K8sRbInstanceResourceStatus> resourcesStatus = instanceStatus.getResourcesStatus();
- List<ParseResult> parsedStatus = resourcesStatus.stream()
- .map(status -> parse(status, aaiRequest))
+ return resourcesStatus.stream()
+ .map(status -> responseParser.parse(status, aaiRequest))
.collect(Collectors.toList());
-
- parsedStatus.forEach(status -> sendDeleteRequestToAai(aaiRequest));
- }
-
- private void sendDeleteRequestToAai(AaiRequest aaiRequest) {
- AAIResourceUri aaiUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure()
- .cloudRegion(aaiRequest.getCloudOwner(), aaiRequest.getCloudRegion())
- .tenant(aaiRequest.getTenantId())
- .build());
- getAaiClient().delete(aaiUri);
- }
-
- private void sendUpdateRequestToAai(ParseResult parseResult, AaiRequest aaiRequest) {
- AAIResourceUri aaiUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure()
- .cloudRegion(aaiRequest.getCloudOwner(), aaiRequest.getCloudRegion())
- .tenant(aaiRequest.getTenantId())
- .build());
- String payload = gson.toJson(parseResult);
- getAaiClient().create(aaiUri, payload);
- }
-
- private AAIResourcesClient getAaiClient() {
- if (aaiClient == null) {
- aaiClient = new AAIResourcesClient();
- }
- return aaiClient;
- }
-
- private ParseResult parse(K8sRbInstanceResourceStatus status, AaiRequest aaiRequest) {
- ParseResult result = new ParseResult();
- K8sRbInstanceGvk gvk = status.getGvk();
- K8sStatusMetadata metadata = status.getStatus().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;
- }
-
- private class ParseResult {
- private String id;
- private String name;
- private String group;
- private String version;
- private String kind;
- private String namespace;
- private Collection<String> labels;
- private String k8sResourceSelfLink;
-
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getGroup() {
- return group;
- }
-
- public void setGroup(String group) {
- this.group = group;
- }
-
- public String getVersion() {
- return version;
- }
-
- public void setVersion(String version) {
- this.version = version;
- }
-
- public String getKind() {
- return kind;
- }
-
- public void setKind(String kind) {
- this.kind = kind;
- }
-
- public String getNamespace() {
- return namespace;
- }
-
- public void setNamespace(String namespace) {
- this.namespace = namespace;
- }
-
- public Collection<String> getLabels() {
- return labels;
- }
-
- public void setLabels(Collection<String> labels) {
- this.labels = labels;
- }
-
- public String getK8sResourceSelfLink() {
- return k8sResourceSelfLink;
- }
-
- public void setK8sResourceSelfLink(String k8sResourceSelfLink) {
- this.k8sResourceSelfLink = k8sResourceSelfLink;
- }
}
}
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/ParseResult.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/ParseResult.java
new file mode 100644
index 0000000..e44a885
--- /dev/null
+++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/aai/ParseResult.java
@@ -0,0 +1,78 @@
+package org.onap.so.adapters.cnf.service.aai;
+
+import java.util.Collection;
+
+class ParseResult {
+ private String id;
+ private String name;
+ private String group;
+ private String version;
+ private String kind;
+ private String namespace;
+ private Collection<String> labels;
+ private String k8sResourceSelfLink;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getGroup() {
+ return group;
+ }
+
+ public void setGroup(String group) {
+ this.group = group;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public void setVersion(String version) {
+ this.version = version;
+ }
+
+ public String getKind() {
+ return kind;
+ }
+
+ public void setKind(String kind) {
+ this.kind = kind;
+ }
+
+ public String getNamespace() {
+ return namespace;
+ }
+
+ public void setNamespace(String namespace) {
+ this.namespace = namespace;
+ }
+
+ public Collection<String> getLabels() {
+ return labels;
+ }
+
+ public void setLabels(Collection<String> labels) {
+ this.labels = labels;
+ }
+
+ public String getK8sResourceSelfLink() {
+ return k8sResourceSelfLink;
+ }
+
+ public void setK8sResourceSelfLink(String k8sResourceSelfLink) {
+ this.k8sResourceSelfLink = k8sResourceSelfLink;
+ }
+} \ No newline at end of file
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
new file mode 100644
index 0000000..70070e4
--- /dev/null
+++ b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/aai/AaiIdGeneratorServiceTest.java
@@ -0,0 +1,51 @@
+package org.onap.so.adapters.cnf.service.aai;
+
+import org.junit.Assert;
+import org.junit.Test;
+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.springframework.test.context.junit4.SpringRunner;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@RunWith(SpringRunner.class)
+public class AaiIdGeneratorServiceTest {
+
+ private AaiIdGeneratorService tested = new AaiIdGeneratorService();
+
+ @Test
+ public void shouldGenerateId() {
+ // given
+ String name = "name";
+ String kind = "kind";
+ String group = "group";
+ String version = "version";
+ String instanceId = "instanceId";
+ String cloudOwner = "cloudOwner";
+ String cloudRegion = "cloudRegion";
+ String tenantId = "tenantId";
+ K8sRbInstanceResourceStatus resourceStatus = mock(K8sRbInstanceResourceStatus.class);
+ AaiRequest aaiRequest = mock(AaiRequest.class);
+ K8sRbInstanceGvk gvk = mock(K8sRbInstanceGvk.class);
+
+ // when
+ when(resourceStatus.getGvk()).thenReturn(gvk);
+ when(resourceStatus.getName()).thenReturn(name);
+ when(gvk.getKind()).thenReturn(kind);
+ when(gvk.getGroup()).thenReturn(group);
+ when(gvk.getVersion()).thenReturn(version);
+ when(aaiRequest.getInstanceId()).thenReturn(instanceId);
+ when(aaiRequest.getCloudOwner()).thenReturn(cloudOwner);
+ when(aaiRequest.getCloudRegion()).thenReturn(cloudRegion);
+ when(aaiRequest.getTenantId()).thenReturn(tenantId);
+
+ // then
+ String actual = tested.generateId(resourceStatus, aaiRequest);
+ String expected = "a1b2c1f3dd0c76d65c6dbe97b17e0239163bc2c08e8e88e167bb90de9c7b0da1";
+
+ Assert.assertEquals(expected, actual);
+ }
+} \ No newline at end of file
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
new file mode 100644
index 0000000..f3c0558
--- /dev/null
+++ b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/aai/AaiResponseParserTest.java
@@ -0,0 +1,101 @@
+package org.onap.so.adapters.cnf.service.aai;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+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.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;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@RunWith(SpringRunner.class)
+public class AaiResponseParserTest {
+
+ @InjectMocks
+ private AaiResponseParser aaiResponseParser;
+
+ @Mock
+ private AaiIdGeneratorService aaiIdGeneratorService;
+
+
+ @Test
+ public void shouldParseAaiResponse() {
+ // given
+ String id = "id";
+ String name = "name";
+ String group = "group";
+ String version = "version";
+ String kind = "kind";
+ String namespace = "namespace";
+ Map<String, String> labelsMap = new HashMap<>();
+ labelsMap.put("key", "value");
+ K8sRbInstanceResourceStatus status = mock(K8sRbInstanceResourceStatus.class);
+ AaiRequest aaiRequest = mock(AaiRequest.class);
+ K8sRbInstanceGvk gvk = mock(K8sRbInstanceGvk.class);
+ K8sStatusMetadata metadata = mock(K8sStatusMetadata.class);
+ K8sStatus k8sStatus = mock(K8sStatus.class);
+
+ // when
+ when(status.getGvk()).thenReturn(gvk);
+ when(status.getStatus()).thenReturn(k8sStatus);
+ when(k8sStatus.getK8sStatusMetadata()).thenReturn(metadata);
+ when(aaiIdGeneratorService.generateId(status, aaiRequest)).thenReturn(id);
+ when(status.getName()).thenReturn(name);
+ when(gvk.getGroup()).thenReturn(group);
+ when(gvk.getVersion()).thenReturn(version);
+ when(gvk.getKind()).thenReturn(kind);
+ when(metadata.getNamespace()).thenReturn(namespace);
+ when(aaiRequest.getInstanceId()).thenReturn(id);
+
+ when(metadata.getLabels()).thenReturn(labelsMap);
+
+ // then
+ ParseResult actual = aaiResponseParser.parse(status, aaiRequest);
+
+ Assert.assertNotNull(actual);
+ assertEquals(id, actual.getId());
+ assertEquals(name, actual.getName());
+ assertEquals(group, actual.getGroup());
+ 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;
+ }
+} \ 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
new file mode 100644
index 0000000..976fc52
--- /dev/null
+++ b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/aai/AaiServiceTest.java
@@ -0,0 +1,90 @@
+package org.onap.so.adapters.cnf.service.aai;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.onap.so.adapters.cnf.client.MulticloudClient;
+import org.onap.so.adapters.cnf.model.instantiation.AaiRequest;
+import org.onap.so.adapters.cnf.model.statuscheck.K8sRbInstanceResourceStatus;
+import org.onap.so.adapters.cnf.model.statuscheck.K8sRbInstanceStatus;
+import org.onap.so.client.exception.BadResponseException;
+import org.springframework.test.context.junit4.SpringRunner;
+
+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;
+
+@RunWith(SpringRunner.class)
+public class AaiServiceTest {
+
+ @InjectMocks
+ private AaiService aaiServiceTested;
+
+ @Mock
+ private MulticloudClient multicloudClient;
+ @Mock
+ private AaiRequestSender aaiRequestSender;
+ @Mock
+ private AaiResponseParser responseParser;
+
+ @Test
+ public void shouldTestAaiUpdate() throws BadResponseException {
+ // given
+ String instanceId = "instanceId";
+ AaiRequest aaiRequest = mock(AaiRequest.class);
+ K8sRbInstanceStatus instanceStatus = mock(K8sRbInstanceStatus.class);
+ K8sRbInstanceResourceStatus status = mock(K8sRbInstanceResourceStatus.class);
+ List<K8sRbInstanceResourceStatus> resourcesStatus = new ArrayList<>();
+ resourcesStatus.add(status);
+ ParseResult parseResult = mock(ParseResult.class);
+ List<ParseResult> parseResultList = new ArrayList<>();
+ parseResultList.add(parseResult);
+
+ // when
+ when(aaiRequest.getInstanceId()).thenReturn(instanceId);
+ when(multicloudClient.getInstanceStatus(instanceId)).thenReturn(instanceStatus);
+ when(instanceStatus.getResourcesStatus()).thenReturn(resourcesStatus);
+ when(responseParser.parse(status, aaiRequest)).thenReturn(parseResult);
+ doNothing().when(aaiRequestSender).sendUpdateRequestToAai(parseResult, aaiRequest);
+
+ // then
+ aaiServiceTested.aaiUpdate(aaiRequest);
+
+ verify(responseParser, atLeast(1)).parse(status, aaiRequest);
+ verify(aaiRequestSender, atLeast(1)).sendUpdateRequestToAai(parseResult, aaiRequest);
+ }
+
+
+ @Test
+ public void shouldTestAaiDelete() throws BadResponseException {
+ // given
+ String instanceId = "instanceId";
+ AaiRequest aaiRequest = mock(AaiRequest.class);
+ K8sRbInstanceStatus instanceStatus = mock(K8sRbInstanceStatus.class);
+ K8sRbInstanceResourceStatus status = mock(K8sRbInstanceResourceStatus.class);
+ List<K8sRbInstanceResourceStatus> resourcesStatus = new ArrayList<>();
+ resourcesStatus.add(status);
+ ParseResult parseResult = mock(ParseResult.class);
+ List<ParseResult> parseResultList = new ArrayList<>();
+ parseResultList.add(parseResult);
+
+ // when
+ when(aaiRequest.getInstanceId()).thenReturn(instanceId);
+ when(multicloudClient.getInstanceStatus(instanceId)).thenReturn(instanceStatus);
+ when(instanceStatus.getResourcesStatus()).thenReturn(resourcesStatus);
+ when(responseParser.parse(status, aaiRequest)).thenReturn(parseResult);
+ 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/statuscheck/SimpleStatusCheckServiceTest.java b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/statuscheck/SimpleStatusCheckServiceTest.java
new file mode 100644
index 0000000..f9fbe31
--- /dev/null
+++ b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/service/statuscheck/SimpleStatusCheckServiceTest.java
@@ -0,0 +1,83 @@
+package org.onap.so.adapters.cnf.service.statuscheck;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+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.statuscheck.K8sRbInstanceStatus;
+import org.onap.so.adapters.cnf.model.statuscheck.StatusCheckResponse;
+import org.onap.so.client.exception.BadResponseException;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@RunWith(SpringRunner.class)
+public class SimpleStatusCheckServiceTest {
+
+ @InjectMocks
+ private SimpleStatusCheckService tested;
+
+ @Mock
+ private MulticloudClient instanceApi;
+
+
+ @Test
+ public void shouldReturnTrueStatusCheck() throws BadResponseException {
+ // given
+ String instanceId = "instanceId";
+ boolean isReady = true;
+ K8sRbInstanceStatus instanceStatus = mock(K8sRbInstanceStatus.class);
+ CheckInstanceRequest instanceIds = mock(CheckInstanceRequest.class);
+ List<InstanceRequest> instanceRequests = new ArrayList<>();
+ InstanceRequest instanceRequest = mock(InstanceRequest.class);
+ instanceRequests.add(instanceRequest);
+
+ // when
+ when(instanceIds.getInstances()).thenReturn(instanceRequests);
+ when(instanceRequest.getInstanceId()).thenReturn(instanceId);
+ when(instanceApi.getInstanceStatus(instanceId)).thenReturn(instanceStatus);
+ when(instanceStatus.isReady()).thenReturn(isReady);
+
+ // then
+ StatusCheckResponse actual = tested.statusCheck(instanceIds);
+
+ Assert.assertFalse(actual.getInstanceResponse().isEmpty());
+ Assert.assertEquals(1, actual.getInstanceResponse().size());
+ Assert.assertTrue(actual.getInstanceResponse().get(0).isStatus());
+ Assert.assertEquals(instanceId, actual.getInstanceResponse().get(0).getInstanceId());
+ }
+
+ @Test
+ public void shouldReturnFalseStatusCheck() throws BadResponseException {
+ // given
+ String instanceId = "instanceId";
+ boolean isReady = false;
+ K8sRbInstanceStatus instanceStatus = mock(K8sRbInstanceStatus.class);
+ CheckInstanceRequest instanceIds = mock(CheckInstanceRequest.class);
+ List<InstanceRequest> instanceRequests = new ArrayList<>();
+ InstanceRequest instanceRequest = mock(InstanceRequest.class);
+ instanceRequests.add(instanceRequest);
+
+ // when
+ when(instanceIds.getInstances()).thenReturn(instanceRequests);
+ when(instanceRequest.getInstanceId()).thenReturn(instanceId);
+ when(instanceApi.getInstanceStatus(instanceId)).thenReturn(instanceStatus);
+ when(instanceStatus.isReady()).thenReturn(isReady);
+
+ // then
+ StatusCheckResponse actual = tested.statusCheck(instanceIds);
+
+ Assert.assertFalse(actual.getInstanceResponse().isEmpty());
+ Assert.assertEquals(1, actual.getInstanceResponse().size());
+ Assert.assertFalse(actual.getInstanceResponse().get(0).isStatus());
+ Assert.assertEquals(instanceId, actual.getInstanceResponse().get(0).getInstanceId());
+ }
+} \ No newline at end of file