2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2018 - 2019 Nokia. All rights reserved.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.vid.services;
24 import com.fasterxml.jackson.core.JsonProcessingException;
25 import com.fasterxml.jackson.databind.JsonNode;
26 import com.fasterxml.jackson.databind.ObjectMapper;
27 import io.joshworks.restclient.http.HttpResponse;
28 import org.apache.http.HttpStatus;
29 import org.jetbrains.annotations.NotNull;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.mockito.InjectMocks;
33 import org.mockito.Mock;
34 import org.mockito.junit.MockitoJUnitRunner;
35 import org.onap.vid.aai.AaiClientInterface;
36 import org.onap.vid.aai.AaiGetVnfResponse;
37 import org.onap.vid.aai.AaiOverTLSClientInterface;
38 import org.onap.vid.aai.AaiResponse;
39 import org.onap.vid.aai.AaiResponseTranslator;
40 import org.onap.vid.aai.ServiceInstancesSearchResults;
41 import org.onap.vid.aai.ServiceSubscription;
42 import org.onap.vid.aai.ServiceSubscriptions;
43 import org.onap.vid.aai.Services;
44 import org.onap.vid.aai.SubscriberFilteredResults;
45 import org.onap.vid.aai.model.AaiGetInstanceGroupsByCloudRegion;
46 import org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.AaiGetRelatedInstanceGroupsByVnfId;
47 import org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.RelatedToProperty;
48 import org.onap.vid.aai.model.AaiGetOperationalEnvironments.OperationalEnvironmentList;
49 import org.onap.vid.aai.model.AaiGetPnfs.Pnf;
50 import org.onap.vid.aai.model.AaiGetServicesRequestModel.GetServicesAAIRespone;
51 import org.onap.vid.aai.model.AaiGetTenatns.GetTenantsResponse;
52 import org.onap.vid.aai.model.GetServiceModelsByDistributionStatusResponse;
53 import org.onap.vid.aai.model.InstanceGroupInfo;
54 import org.onap.vid.aai.model.LogicalLinkResponse;
55 import org.onap.vid.aai.model.Model;
56 import org.onap.vid.aai.model.ModelVer;
57 import org.onap.vid.aai.model.ModelVers;
58 import org.onap.vid.aai.model.PortDetailsTranslator;
59 import org.onap.vid.aai.model.Properties;
60 import org.onap.vid.aai.model.Relationship;
61 import org.onap.vid.aai.model.RelationshipData;
62 import org.onap.vid.aai.model.RelationshipList;
63 import org.onap.vid.aai.model.Result;
64 import org.onap.vid.aai.model.ServiceRelationships;
65 import org.onap.vid.aai.model.VnfResult;
66 import org.onap.vid.asdc.beans.Service;
67 import org.onap.vid.model.Subscriber;
68 import org.onap.vid.model.SubscriberList;
69 import org.onap.vid.model.aaiTree.AAITreeNode;
70 import org.onap.vid.model.aaiTree.RelatedVnf;
71 import org.onap.vid.model.aaiTree.ServiceInstance;
72 import org.onap.vid.roles.RoleValidator;
74 import javax.ws.rs.core.Response;
75 import java.util.Arrays;
76 import java.util.Collection;
77 import java.util.Collections;
78 import java.util.HashMap;
79 import java.util.List;
82 import static org.assertj.core.api.Assertions.assertThat;
83 import static org.mockito.ArgumentMatchers.any;
84 import static org.mockito.ArgumentMatchers.anyString;
85 import static org.mockito.ArgumentMatchers.eq;
86 import static org.mockito.Mockito.mock;
87 import static org.mockito.Mockito.when;
89 @RunWith(MockitoJUnitRunner.class)
90 public class AaiServiceImplTest {
92 private static final String GLOBAL_CUSTOMER_ID = "GLOBAL_CUSTOMER_ID";
93 private static final String CLOUD_REGION_ID = "CLOUD_REGION_ID";
94 private static final String VNF_TYPE = "VNF_TYPE";
95 private static final String TENANT_ID = "TENANT_ID";
96 private static final String TENANT_NAME = "TENANT_NAME";
97 private static final String SERVICE_TYPE = "SERVICE_TYPE";
98 private static final String CORRECT_VALUE = "CORRECT_VALUE";
99 private static final String SUBSCRIBER_ID = "SUBSCRIBER_ID_EXPECTED";
100 private static final String STATUS_TEXT = "STATUS_TEXT";
101 private static final String GLOBAL_SUBSCRIBER_ID = "GLOBAL_SUBSCRIBER_ID";
102 private static final String GLOBAL_SUBSCRIBER_ID_NULL_RESPONSE = "ID_NULL";
103 private static final String VNF_INSTANCE_ID_OK = "VNF_INSTANCE_ID_OK";
104 private static final String VNF_INSTANCE_ID_FAIL = "VNF_INSTANCE_ID_FAIL";
105 private static final String PARENT_NAME = "PARENT_NAME";
106 private static final String PARENT_ID = "PARENT_ID";
107 private static final String INVARIANT_ID = "INVARIANT_ID";
108 private static final String GROUP_TYPE_FAILING = "GROUP_TYPE_FAILING";
109 private static final String GROUP_ROLE_OK = "GROUP_ROLE_OK";
110 private static final String GROUP_ROLE_FAILING = "GROUP_ROLE_FAILING";
111 private static final String group_type_ok = "GROUP_TYPE_OK";
112 private static final String CLOUD_TYPE = "CLOUD_TYPE";
115 private HttpResponse<SubscriberList> responseAllSubscribers;
117 private AaiResponse<OperationalEnvironmentList> aaiResponseOpEnvList;
119 private AaiResponse aaiResponse;
121 private AaiResponse<JsonNode> aaiResponseJsonNode;
123 private RoleValidator roleValidator;
126 private AaiClientInterface aaiClient;
128 private AaiOverTLSClientInterface aaiOverTLSClient;
130 private AaiResponseTranslator aaiResponseTranslator;
132 private AAIServiceTree aaiServiceTree;
135 private AaiServiceImpl aaiService;
139 public void shouldGetFullSubscriberListWithoutValidator() {
140 when(aaiOverTLSClient.getAllSubscribers()).thenReturn(responseAllSubscribers);
142 HttpResponse<SubscriberList> actualResponse = aaiService.getFullSubscriberList();
144 assertThat(actualResponse).isEqualTo(responseAllSubscribers);
148 public void shouldGetFullSubscriberListWithValidator() {
149 Subscriber subscriber = createSubscriber();
150 SubscriberList subscriberList = new SubscriberList(Collections.singletonList(subscriber));
152 when(aaiOverTLSClient.getAllSubscribers()).thenReturn(responseAllSubscribers);
153 when(responseAllSubscribers.getBody()).thenReturn(subscriberList);
154 when(responseAllSubscribers.getStatusText()).thenReturn(STATUS_TEXT);
155 when(responseAllSubscribers.getStatus()).thenReturn(HttpStatus.SC_OK);
156 SubscriberFilteredResults expectedSubscribers = new SubscriberFilteredResults(roleValidator, subscriberList,
157 STATUS_TEXT, HttpStatus.SC_OK);
159 SubscriberFilteredResults actualSubscribers = aaiService.getFullSubscriberList(roleValidator);
161 assertThat(actualSubscribers.getHttpCode()).isEqualTo(expectedSubscribers.getHttpCode());
162 assertThat(actualSubscribers.getErrorMessage()).isEqualTo(expectedSubscribers.getErrorMessage());
166 public void shouldGetOperationalEnvironments() {
167 when(aaiClient.getOperationalEnvironments(anyString(), anyString()))
168 .thenReturn(aaiResponseOpEnvList);
170 AaiResponse<OperationalEnvironmentList> expectedEnvList =
171 aaiService.getOperationalEnvironments(anyString(), anyString());
173 assertThat(expectedEnvList).isEqualTo(aaiResponseOpEnvList);
177 public void shouldGetSubscriberData() {
178 Services services = createAaiResponseServices();
179 AaiResponse<Services> aaiResponseServices = new AaiResponse<>(services, null, HttpStatus.SC_OK);
181 when(aaiClient.getSubscriberData(SUBSCRIBER_ID)).thenReturn(aaiResponseServices);
182 when(roleValidator.isServicePermitted(eq(GLOBAL_CUSTOMER_ID), anyString())).thenReturn(Boolean.TRUE);
184 AaiResponse actualResponse = aaiService.getSubscriberData(SUBSCRIBER_ID, roleValidator);
185 List<ServiceSubscription> actualServiceSubscriptions = ((AaiResponse<Services>) actualResponse)
186 .getT().serviceSubscriptions.serviceSubscription;
188 assertThat(actualResponse).isEqualTo(aaiResponseServices);
189 assertThat(actualServiceSubscriptions).allMatch(s -> s.isPermitted);
193 public void shouldGetServiceInstanceEmptySearchResults() {
194 ServiceInstancesSearchResults serviceInstancesSearchResults = new ServiceInstancesSearchResults();
195 AaiResponse<ServiceInstancesSearchResults> emptyResponse = new AaiResponse<>(serviceInstancesSearchResults,
196 null, HttpStatus.SC_OK);
198 AaiResponse actualResponse = aaiService.getServiceInstanceSearchResults(null, null,
201 assertThat(actualResponse).isEqualToComparingFieldByFieldRecursively(emptyResponse);
205 public void shouldGetVersionByInvariantId() {
206 Response response = mock(Response.class);
207 when(aaiClient.getVersionByInvariantId(any())).thenReturn(response);
209 Response actualResponse = aaiService.getVersionByInvariantId(any());
211 assertThat(actualResponse).isEqualTo(response);
215 public void shouldGetSpecificPnf() {
216 AaiResponse<Pnf> expectedResponse = new AaiResponse<>(Pnf.builder().build(), null, HttpStatus.SC_OK);
217 when(aaiClient.getSpecificPnf(anyString())).thenReturn(expectedResponse);
219 AaiResponse<Pnf> actualResponse = aaiService.getSpecificPnf(anyString());
221 assertThat(actualResponse).isEqualTo(expectedResponse);
225 public void shouldGetPnfData() {
226 when(aaiClient.getPNFData(anyString(), anyString(), anyString(), anyString(), anyString(), anyString(),
227 anyString())).thenReturn(aaiResponse);
229 AaiResponse actualResponse = aaiService.getPNFData(anyString(), anyString(), anyString(), anyString(),
230 anyString(), anyString(), anyString());
232 assertThat(actualResponse).isEqualTo(aaiResponse);
236 public void shouldGetServices() {
237 org.onap.vid.aai.model.AaiGetServicesRequestModel.Service s1 =
238 createService("ID1", "V1", "D1");
239 org.onap.vid.aai.model.AaiGetServicesRequestModel.Service s2 =
240 createService("ID2", "V2", "D2");
242 GetServicesAAIRespone services = new GetServicesAAIRespone();
243 services.service = Arrays.asList(s1, s2);
245 AaiResponse<GetServicesAAIRespone> aaiResponseServices =
246 new AaiResponse<>(services, null, HttpStatus.SC_OK);
248 when(aaiClient.getServices()).thenReturn(aaiResponseServices);
250 Object actualObjectOfResponse = aaiService.getServices(roleValidator).getT();
252 assertThat(actualObjectOfResponse).isNotNull();
253 assertThat(((GetServicesAAIRespone) actualObjectOfResponse).service).allMatch(s -> s.isPermitted);
257 public void shouldGetTenants() {
258 GetTenantsResponse tenant1 = new GetTenantsResponse("REGION_ID1", "CLOUD_OWNER1",
259 "TENANT_NAME1", "TENANT_ID1", true);
260 GetTenantsResponse tenant2 = new GetTenantsResponse("REGION_ID2", "CLOUD_OWNER2",
261 "TENANT_NAME2", "TENANT_ID2", false);
262 GetTenantsResponse[] tenants = {tenant1, tenant2};
263 AaiResponse<GetTenantsResponse[]> aaiGetTenantsResponse = new AaiResponse<>(tenants,
264 null, HttpStatus.SC_OK);
266 when(aaiClient.getTenants(anyString(), anyString())).thenReturn(aaiGetTenantsResponse);
267 when(roleValidator.isTenantPermitted(anyString(), anyString(), anyString()))
268 .thenReturn(Boolean.TRUE);
270 GetTenantsResponse[] actualResponses = aaiService
271 .getTenants(anyString(), anyString(), roleValidator).getT();
273 assertThat(actualResponses).isNotNull();
274 assertThat(actualResponses.length).isEqualTo(2);
275 assertThat(actualResponses).allMatch(tenant -> tenant.isPermitted);
279 public void shouldGetVNFDataWithoutFiltering() {
280 when(aaiClient.getVNFData(anyString(), anyString(), anyString())).thenReturn(aaiResponse);
282 AaiResponse actualResponse = aaiService.getVNFData(anyString(), anyString(), anyString());
284 assertThat(actualResponse).isEqualTo(aaiResponse);
288 public void shouldGetVNFDataWithFiltering() {
289 VnfResult vnfResult1 = createVnfResult("ID1", "generic-vnf");
290 VnfResult vnfResult2 = createVnfResult("ID2", "service-instance");
291 VnfResult vnfResult3 = createVnfResult("ID3", "anything-else");
293 List<VnfResult> vnfResults = Arrays.asList(vnfResult1, vnfResult2, vnfResult3);
294 AaiResponse<AaiGetVnfResponse> aaiResponseGetVnfResponse = createAaiResponseVnfResponse(vnfResults);
296 vnfResults = Arrays.asList(vnfResult1, vnfResult2);
297 AaiResponse<AaiGetVnfResponse> expectedResponseWithReturnedVnfs = createAaiResponseVnfResponse(vnfResults);
298 AaiResponse expectedResponseWithoutReturnedVnfs = new AaiResponse();
300 when(aaiClient.getVNFData(GLOBAL_SUBSCRIBER_ID, SERVICE_TYPE)).thenReturn(aaiResponseGetVnfResponse);
301 when(aaiClient.getVNFData(GLOBAL_SUBSCRIBER_ID_NULL_RESPONSE, SERVICE_TYPE)).thenReturn(null);
303 AaiResponse<AaiGetVnfResponse> actualResponseWithReturnedVnfs =
304 aaiService.getVNFData(GLOBAL_SUBSCRIBER_ID, SERVICE_TYPE);
305 AaiResponse<AaiGetVnfResponse> actualResponseWithoutReturnedVnfs =
306 aaiService.getVNFData(GLOBAL_SUBSCRIBER_ID_NULL_RESPONSE, SERVICE_TYPE);
308 assertThat(actualResponseWithReturnedVnfs)
309 .isEqualToComparingFieldByFieldRecursively(expectedResponseWithReturnedVnfs);
310 assertThat(actualResponseWithoutReturnedVnfs)
311 .isEqualToComparingFieldByField(expectedResponseWithoutReturnedVnfs);
315 public void shouldGetAaiZones() {
316 when(aaiClient.getAllAicZones()).thenReturn(aaiResponse);
318 AaiResponse actualResponse = aaiService.getAaiZones();
320 assertThat(actualResponse).isEqualTo(aaiResponse);
324 public void shouldGetAicZoneForPnf() {
325 ServiceRelationships relationsService = createServiceRelationships();
326 AaiResponse<ServiceRelationships> expectedServiceInstanceResp =
327 new AaiResponse<>(relationsService, null, HttpStatus.SC_OK);
328 AaiResponse<String> expectedResponse = new AaiResponse<>(CORRECT_VALUE, null, HttpStatus.SC_OK);
330 when(aaiClient.getServiceInstance(anyString(), anyString(), anyString()))
331 .thenReturn(expectedServiceInstanceResp);
333 AaiResponse actualResponse = aaiService.getAicZoneForPnf(anyString(), anyString(), anyString());
335 assertThat(actualResponse).isEqualToComparingFieldByField(expectedResponse);
339 public void shouldGetNodeTemplateInstances() {
340 when(aaiClient.getNodeTemplateInstances(anyString(), anyString(), anyString(),
341 anyString(), anyString())).thenReturn(aaiResponse);
343 AaiResponse expectedResponse = aaiService.getNodeTemplateInstances(anyString(), anyString(), anyString(),
344 anyString(), anyString());
346 assertThat(expectedResponse).isEqualTo(aaiResponse);
350 public void shouldGetNetworkCollectionDetails() {
351 when(aaiClient.getNetworkCollectionDetails(anyString())).thenReturn(aaiResponse);
353 AaiResponse expectedResponse = aaiService.getNetworkCollectionDetails(anyString());
355 assertThat(expectedResponse).isEqualTo(aaiResponse);
359 public void shouldGetInstanceGroupsByCloudRegion() {
360 AaiGetInstanceGroupsByCloudRegion aaiGetInstanceGroupsByCloudRegion =
361 mock(AaiGetInstanceGroupsByCloudRegion.class);
362 AaiResponse<AaiGetInstanceGroupsByCloudRegion> expectedResponse =
363 new AaiResponse<>(aaiGetInstanceGroupsByCloudRegion, null, HttpStatus.SC_OK);
365 when(aaiClient.getInstanceGroupsByCloudRegion(anyString(), anyString(), anyString()))
366 .thenReturn(expectedResponse);
367 AaiResponse<AaiGetInstanceGroupsByCloudRegion> actualResponse =
368 aaiService.getInstanceGroupsByCloudRegion(anyString(), anyString(), anyString());
370 assertThat(actualResponse).isEqualTo(expectedResponse);
374 public void shouldGetServicesByDistributionStatus() {
375 Result resultWithModelType = createResult("MODEL_TYPE1", "1");
376 Result resultWithEmptyModelType = createResult(null, "2");
377 Result resultWithoutModel = new Result();
378 resultWithoutModel.setModel(null);
379 Result resultWithoutValidModel = createResultWithoutValidModel();
380 List<Result> results = Arrays.asList(resultWithModelType, resultWithEmptyModelType, resultWithoutModel,
381 resultWithoutValidModel);
383 GetServiceModelsByDistributionStatusResponse serviceModels = new GetServiceModelsByDistributionStatusResponse();
384 serviceModels.setResults(results);
386 AaiResponse<GetServiceModelsByDistributionStatusResponse> serviceModelsByDistributionStatusResponse
387 = new AaiResponse<>(serviceModels, null, HttpStatus.SC_OK);
389 Service[] expectedServices = {
390 createService("MODEL_TYPE1", "1"),
391 createService("", "2")
394 when(aaiClient.getServiceModelsByDistributionStatus()).thenReturn(serviceModelsByDistributionStatusResponse);
395 Collection<Service> actualServices = aaiService.getServicesByDistributionStatus();
397 assertThat(actualServices)
399 .usingFieldByFieldElementComparator()
400 .containsExactly(expectedServices);
404 public void shouldReturnEmptyListOfServices() {
405 AaiResponse<GetServiceModelsByDistributionStatusResponse> emptyResponse
406 = new AaiResponse<>(null, null, HttpStatus.SC_OK);
408 when(aaiClient.getServiceModelsByDistributionStatus()).thenReturn(emptyResponse);
409 Collection<Service> actualServices = aaiService.getServicesByDistributionStatus();
411 assertThat(actualServices).isEqualTo(Collections.EMPTY_LIST);
415 public void shouldGetServiceInstanceAssociatedPnfs() {
416 ServiceRelationships relationsList = createServiceRelationships();
417 LogicalLinkResponse logicalLinkResponse = new LogicalLinkResponse();
418 logicalLinkResponse.setRelationshipList(relationsList.getRelationshipList());
420 AaiResponse<LogicalLinkResponse> aaiResponseLogicalLinkResponse =
421 new AaiResponse<>(logicalLinkResponse, null, HttpStatus.SC_OK);
422 AaiResponse<ServiceRelationships> aaiResponseServiceRelations =
423 new AaiResponse<>(relationsList, null, HttpStatus.SC_OK);
425 when(aaiClient.getServiceInstance(anyString(), anyString(), anyString()))
426 .thenReturn(aaiResponseServiceRelations);
427 when(aaiClient.getLogicalLink(anyString())).thenReturn(aaiResponseLogicalLinkResponse);
430 List<String> expectedPnfs = Collections.singletonList(CORRECT_VALUE);
431 List<String> actualPnfs = aaiService.getServiceInstanceAssociatedPnfs(anyString(), anyString(), anyString());
433 assertThat(actualPnfs).isEqualTo(expectedPnfs);
437 public void shouldGetPortMirroringConfigData() {
438 AaiResponseTranslator.PortMirroringConfigData expectedData
439 = mock(AaiResponseTranslator.PortMirroringConfigData.class);
441 when(aaiClient.getCloudRegionAndSourceByPortMirroringConfigurationId(anyString())).thenReturn(aaiResponseJsonNode);
442 when(aaiResponseTranslator.extractPortMirroringConfigData(aaiResponseJsonNode)).thenReturn(expectedData);
444 AaiResponseTranslator.PortMirroringConfigData actualData = aaiService.getPortMirroringConfigData(anyString());
445 assertThat(actualData).isEqualTo(expectedData);
450 public void shouldGetInstanceGroupsByVnfInstanceId() {
451 List<InstanceGroupInfo> instanceGroupInfo = Collections.singletonList(new InstanceGroupInfo(CORRECT_VALUE));
452 AaiGetRelatedInstanceGroupsByVnfId relatedInstanceGroups = new AaiGetRelatedInstanceGroupsByVnfId();
453 relatedInstanceGroups.setRelationshipList(createRelationshipList());
455 AaiResponse<AaiGetRelatedInstanceGroupsByVnfId> correctCodeResponse =
456 new AaiResponse<>(relatedInstanceGroups, null, HttpStatus.SC_OK);
458 AaiResponse<List<InstanceGroupInfo>> expectedCorrectCodeResponse =
459 new AaiResponse<>(instanceGroupInfo, null, HttpStatus.SC_OK);
460 AaiResponse<AaiGetRelatedInstanceGroupsByVnfId> expectedIncorrectCodeResponse =
461 new AaiResponse<>(relatedInstanceGroups, null, HttpStatus.SC_PAYMENT_REQUIRED);
462 List<InstanceGroupInfo> expectedCorrectResponseObject = expectedCorrectCodeResponse.getT();
464 when(aaiClient.getInstanceGroupsByVnfInstanceId(VNF_INSTANCE_ID_OK)).thenReturn(correctCodeResponse);
465 when(aaiClient.getInstanceGroupsByVnfInstanceId(VNF_INSTANCE_ID_FAIL)).thenReturn(expectedIncorrectCodeResponse);
467 AaiResponse actualCorrectCodeResponse = aaiService.getInstanceGroupsByVnfInstanceId(VNF_INSTANCE_ID_OK);
468 AaiResponse actualIncorrectCodeResponse = aaiService.getInstanceGroupsByVnfInstanceId(VNF_INSTANCE_ID_FAIL);
470 List<InstanceGroupInfo> actualCorrectResponseObject =
471 (List<InstanceGroupInfo>) actualCorrectCodeResponse.getT();
473 assertThat(actualCorrectResponseObject)
474 .usingFieldByFieldElementComparator()
475 .hasSameElementsAs(expectedCorrectResponseObject);
477 assertThat(actualIncorrectCodeResponse).isEqualTo(expectedIncorrectCodeResponse);
481 public void shouldGetHomingDataByVfModule() {
482 GetTenantsResponse expectedResponse = new GetTenantsResponse();
483 when(aaiClient.getHomingDataByVfModule(anyString(), anyString())).thenReturn(expectedResponse);
485 GetTenantsResponse actualResponse = aaiService.getHomingDataByVfModule(anyString(), anyString());
486 assertThat(actualResponse).isEqualTo(expectedResponse);
490 public void shouldSearchGroupMembers() {
491 Properties properties = createProperties();
492 Map<String, Properties> regionsAndTenants = createRegionsAndTenantsMap(properties);
494 AAITreeNode validTreeNode = new AAITreeNode();
495 addAdditionalPropertiesToAaiTreeNode(validTreeNode);
496 List<AAITreeNode> validNodes = Arrays.asList(validTreeNode, validTreeNode);
498 AAITreeNode validBranch = createTree(validNodes);
499 addAdditionalPropertiesToAaiTreeNode(validBranch);
500 List<AAITreeNode> testedBranches = Collections.singletonList(validBranch);
502 AAITreeNode testedTree = createTree(testedBranches);
504 RelatedVnf expectedVnf = createExpectedVnf(validBranch);
505 List<RelatedVnf> expectedResult = Collections.singletonList(expectedVnf);
507 when(aaiServiceTree.buildAAITree(anyString(), any())).thenReturn(Collections.singletonList(testedTree));
508 when(aaiClient.getCloudRegionAndTenantByVnfId(anyString())).thenReturn(regionsAndTenants);
510 List<RelatedVnf> actualGroupMembers = aaiService.searchGroupMembers(GLOBAL_CUSTOMER_ID, SERVICE_TYPE,
511 INVARIANT_ID, GROUP_TYPE_FAILING, GROUP_ROLE_FAILING);
513 assertThat(actualGroupMembers)
514 .usingFieldByFieldElementComparator()
515 .hasSameElementsAs(expectedResult);
519 public void shouldGetPortMirroringSourcePorts() {
520 PortDetailsTranslator.PortDetails details = mock(PortDetailsTranslator.PortDetails.class);
521 List<PortDetailsTranslator.PortDetails> expectedDetailsList = Arrays.asList(
522 details, details, details
525 when(aaiClient.getPortMirroringSourcePorts(anyString())).thenReturn(expectedDetailsList);
526 List<PortDetailsTranslator.PortDetails> actualDetails = aaiService.getPortMirroringSourcePorts(anyString());
528 assertThat(actualDetails).isEqualTo(expectedDetailsList);
532 public void shouldGetAAIServiceTree() throws JsonProcessingException {
533 ServiceInstance serviceInstance = mock(ServiceInstance.class);
534 String expectedResult = new ObjectMapper().writeValueAsString(serviceInstance);
536 when(aaiServiceTree.getServiceInstanceTopology(anyString(), anyString(), anyString()))
537 .thenReturn(serviceInstance);
538 String actualResult = aaiService.getAAIServiceTree(anyString(), anyString(), anyString());
540 assertThat(actualResult).isEqualTo(expectedResult);
544 private Map<String, Properties> createRegionsAndTenantsMap(Properties properties) {
545 Map<String, Properties> regionsAndTenants = new HashMap<>();
546 regionsAndTenants.put("tenant", properties);
547 regionsAndTenants.put("cloud-region", properties);
548 return regionsAndTenants;
551 private Properties createProperties() {
552 Properties properties = new Properties();
553 properties.setTenantId(TENANT_ID);
554 properties.setTenantName(TENANT_NAME);
555 properties.setCloudRegionId(CLOUD_REGION_ID);
560 private RelatedVnf createExpectedVnf(AAITreeNode validBranch) {
561 RelatedVnf expectedVnf = RelatedVnf.from(validBranch);
562 expectedVnf.setTenantId(TENANT_ID);
563 expectedVnf.setTenantName(TENANT_NAME);
564 expectedVnf.setLcpCloudRegionId(CLOUD_REGION_ID);
565 expectedVnf.setServiceInstanceId(PARENT_ID);
566 expectedVnf.setServiceInstanceName(PARENT_NAME);
567 expectedVnf.setInstanceType(VNF_TYPE);
573 private AAITreeNode createTree(List<AAITreeNode> children) {
574 AAITreeNode tree = new AAITreeNode();
575 tree.addChildren(children);
576 tree.setId(PARENT_ID);
577 tree.setName(PARENT_NAME);
581 private void addAdditionalPropertiesToAaiTreeNode(AAITreeNode tree) {
582 Map<String, Object> additionalProperties = new HashMap<>();
583 additionalProperties.put("instance-group-role", GROUP_ROLE_OK);
584 additionalProperties.put("instance-group-type", group_type_ok);
585 additionalProperties.put("vnf-type", VNF_TYPE);
586 additionalProperties.put("cloud-region", CLOUD_TYPE);
587 tree.setAdditionalProperties(additionalProperties);
590 private org.onap.vid.asdc.beans.Service createService(String category, String suffix) {
591 return new Service.ServiceBuilder()
592 .setUuid("MODELVER_VERSION_ID" + suffix)
593 .setInvariantUUID("MODEL_INVARIANT_NAME" + suffix)
594 .setCategory(category)
595 .setVersion("MODELVER_VERSION" + suffix)
596 .setName("MODELVER_NAME" + suffix)
597 .setDistributionStatus("MODELVER_DIST_STATUS" + suffix)
598 .setToscaModelURL(null)
599 .setLifecycleState(null)
606 private Result createResultWithoutValidModel() {
607 ModelVers modelVers = new ModelVers();
608 modelVers.setModelVer(Collections.singletonList(new ModelVer()));
610 Model model = new Model();
611 model.setModelVers(modelVers);
613 Result result1 = new Result();
614 result1.setModel(model);
619 private Result createResult(String modelType, String suffix) {
620 ModelVer modelVer = new ModelVer();
621 modelVer.setModelVersionId("MODELVER_VERSION_ID" + suffix);
622 modelVer.setModelVersion("MODELVER_VERSION" + suffix);
623 modelVer.setModelName("MODELVER_NAME" + suffix);
624 modelVer.setDistributionStatus("MODELVER_DIST_STATUS" + suffix);
626 ModelVers modelVers = new ModelVers();
627 modelVers.setModelVer(Collections.singletonList(modelVer));
629 Model model = new Model();
630 model.setModelType(modelType);
631 model.setModelInvariantId("MODEL_INVARIANT_NAME" + suffix);
632 model.setModelVers(modelVers);
634 Result result = new Result();
635 result.setModel(model);
640 private ServiceRelationships createServiceRelationships() {
641 RelationshipList relationsList = createRelationshipList(CORRECT_VALUE);
642 ServiceRelationships relationsService = new ServiceRelationships();
643 relationsService.setRelationshipList(relationsList);
644 return relationsService;
648 private RelationshipList createRelationshipList(String expectedValue) {
649 List<RelationshipData> relationsDataList = createRelationshipDataList(expectedValue);
650 return createRelationshipList(relationsDataList);
654 private RelationshipList createRelationshipList(List<RelationshipData> relationsDataList) {
655 Relationship relation1 = crateRelationship("any", relationsDataList);
656 Relationship relation2 = crateRelationship("zone", relationsDataList);
657 Relationship relation3 = crateRelationship("logical-link", relationsDataList);
658 Relationship relation4 = crateRelationship("lag-interface", relationsDataList);
659 Relationship relation5 = crateRelationship("pnf", relationsDataList);
661 RelationshipList relationsList = new RelationshipList();
662 relationsList.setRelationship(Arrays.asList(relation1, relation2, relation3, relation4, relation5));
663 return relationsList;
667 private List<RelationshipData> createRelationshipDataList(String expectedValue) {
668 RelationshipData relationData1 = createRelationshipData("any-key", "incorrect_key");
669 RelationshipData relationData2 = createRelationshipData("zone.zone-id", expectedValue);
670 RelationshipData relationData3 = createRelationshipData("logical-link.link-name", expectedValue);
671 RelationshipData relationData4 = createRelationshipData("pnf.pnf-name", expectedValue);
673 return Arrays.asList(relationData1, relationData2, relationData3, relationData4);
677 private Relationship crateRelationship(String relatedTo, List<RelationshipData> relationsDataList) {
678 Relationship relation = new Relationship();
679 relation.setRelatedTo(relatedTo);
680 relation.setRelationDataList(relationsDataList);
685 private RelationshipData createRelationshipData(String key, String value) {
686 RelationshipData relationData = new RelationshipData();
687 relationData.setRelationshipKey(key);
688 relationData.setRelationshipValue(value);
692 private org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.RelationshipList createRelationshipList() {
693 RelatedToProperty property1 =
694 createRelatedToProperty("instance-group.instance-group-name", CORRECT_VALUE);
695 RelatedToProperty property2 =
696 createRelatedToProperty("anything-key", "anything-value");
697 List<RelatedToProperty> properties = Arrays.asList(property1, property2);
699 org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.Relationship relationship1 =
700 createRelationship("instance-group", properties);
701 org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.Relationship relationship2 =
702 createRelationship("any-key", properties);
704 List<org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.Relationship> relationships =
705 Arrays.asList(relationship1, relationship2);
707 org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.RelationshipList relationshipList =
708 new org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.RelationshipList();
709 relationshipList.setRelationship(relationships);
711 return relationshipList;
715 private org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.Relationship createRelationship(String relatedTo,
716 List<RelatedToProperty> relatedToPropertyList) {
717 org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.Relationship relationship1 =
718 new org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.Relationship();
719 relationship1.setRelatedTo(relatedTo);
720 relationship1.setRelatedToPropertyList(relatedToPropertyList);
721 return relationship1;
725 private RelatedToProperty createRelatedToProperty(String key, String value) {
726 RelatedToProperty prop = new RelatedToProperty();
727 prop.setPropertyKey(key);
728 prop.setPropertyValue(value);
733 private AaiResponse<AaiGetVnfResponse> createAaiResponseVnfResponse(List<VnfResult> vnfResults) {
734 AaiGetVnfResponse vnfResponse = new AaiGetVnfResponse();
735 vnfResponse.setResults(vnfResults);
736 return new AaiResponse<>(vnfResponse, null, HttpStatus.SC_OK);
739 private VnfResult createVnfResult(String id, String nodeType) {
740 VnfResult result = new VnfResult();
741 result.setJsonId(id);
742 result.setJsonNodeType(nodeType);
747 private org.onap.vid.aai.model.AaiGetServicesRequestModel.Service createService(String serviceId,
748 String resourceVersion,
749 String serviceDescription) {
750 org.onap.vid.aai.model.AaiGetServicesRequestModel.Service service
751 = new org.onap.vid.aai.model.AaiGetServicesRequestModel.Service();
752 service.isPermitted = false;
753 service.resourceVersion = resourceVersion;
754 service.serviceDescription = serviceDescription;
755 service.serviceId = serviceId;
760 private Services createAaiResponseServices() {
761 ServiceSubscription sub1 = new ServiceSubscription();
762 sub1.isPermitted = false;
763 sub1.serviceType = "serviceSubsType1";
765 ServiceSubscription sub2 = new ServiceSubscription();
766 sub2.isPermitted = true;
767 sub2.serviceType = "serviceSubsType2";
769 ServiceSubscriptions serviceSubs = new ServiceSubscriptions();
770 serviceSubs.serviceSubscription = Collections.singletonList(sub2);
772 Services services = new Services();
773 services.globalCustomerId = GLOBAL_CUSTOMER_ID;
774 services.resourceVersion = "v-1";
775 services.subscriberName = "name-1";
776 services.subscriberType = "type-1";
777 services.serviceSubscriptions = serviceSubs;
782 private Subscriber createSubscriber() {
783 Subscriber subscriber = new Subscriber();
784 subscriber.globalCustomerId = "id-1";
785 subscriber.resourceVersion = "v-1";
786 subscriber.subscriberName = "name-1";
787 subscriber.subscriberType = "type-1";