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 static org.assertj.core.api.Assertions.assertThat;
25 import static org.mockito.ArgumentMatchers.any;
26 import static org.mockito.ArgumentMatchers.anyBoolean;
27 import static org.mockito.ArgumentMatchers.anyString;
28 import static org.mockito.ArgumentMatchers.eq;
29 import static org.mockito.ArgumentMatchers.isNull;
30 import static org.mockito.Mockito.mock;
31 import static org.mockito.Mockito.when;
32 import static org.onap.vid.model.aaiTree.NodeType.SERVICE_INSTANCE;
34 import com.fasterxml.jackson.core.JsonProcessingException;
35 import com.fasterxml.jackson.databind.JsonNode;
36 import com.fasterxml.jackson.databind.ObjectMapper;
37 import java.util.Arrays;
38 import java.util.Collection;
39 import java.util.Collections;
40 import java.util.HashMap;
41 import java.util.List;
43 import java.util.concurrent.ExecutorService;
44 import java.util.concurrent.Executors;
45 import java.util.function.Function;
46 import javax.ws.rs.core.Response;
47 import org.apache.http.HttpStatus;
48 import org.jetbrains.annotations.NotNull;
49 import org.junit.Test;
50 import org.junit.runner.RunWith;
51 import org.mockito.InjectMocks;
52 import org.mockito.Mock;
53 import org.mockito.Spy;
54 import org.mockito.junit.MockitoJUnitRunner;
55 import org.onap.vid.aai.AaiClientInterface;
56 import org.onap.vid.aai.AaiGetVnfResponse;
57 import org.onap.vid.aai.AaiResponse;
58 import org.onap.vid.aai.AaiResponseTranslator;
59 import org.onap.vid.aai.ServiceInstancesSearchResults;
60 import org.onap.vid.aai.ServiceSubscription;
61 import org.onap.vid.aai.ServiceSubscriptions;
62 import org.onap.vid.aai.Services;
63 import org.onap.vid.aai.SubscriberFilteredResults;
64 import org.onap.vid.aai.model.AaiGetInstanceGroupsByCloudRegion;
65 import org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.AaiGetRelatedInstanceGroupsByVnfId;
66 import org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.RelatedToProperty;
67 import org.onap.vid.aai.model.AaiGetOperationalEnvironments.OperationalEnvironmentList;
68 import org.onap.vid.aai.model.AaiGetPnfs.Pnf;
69 import org.onap.vid.aai.model.AaiGetServicesRequestModel.GetServicesAAIRespone;
70 import org.onap.vid.aai.model.AaiGetTenatns.GetTenantsResponse;
71 import org.onap.vid.aai.model.GetServiceModelsByDistributionStatusResponse;
72 import org.onap.vid.aai.model.InstanceGroupInfo;
73 import org.onap.vid.aai.model.LogicalLinkResponse;
74 import org.onap.vid.aai.model.Model;
75 import org.onap.vid.aai.model.ModelVer;
76 import org.onap.vid.aai.model.ModelVers;
77 import org.onap.vid.aai.model.PortDetailsTranslator;
78 import org.onap.vid.aai.model.Properties;
79 import org.onap.vid.aai.model.Relationship;
80 import org.onap.vid.aai.model.RelationshipData;
81 import org.onap.vid.aai.model.RelationshipList;
82 import org.onap.vid.aai.model.Result;
83 import org.onap.vid.aai.model.ServiceRelationships;
84 import org.onap.vid.aai.model.VnfResult;
85 import org.onap.vid.asdc.beans.Service;
86 import org.onap.vid.model.Subscriber;
87 import org.onap.vid.model.SubscriberList;
88 import org.onap.vid.model.aaiTree.AAITreeNode;
89 import org.onap.vid.model.aaiTree.RelatedVnf;
90 import org.onap.vid.model.aaiTree.ServiceInstance;
91 import org.onap.vid.roles.RoleValidator;
92 import org.onap.vid.utils.Logging;
93 import org.springframework.http.HttpMethod;
95 @RunWith(MockitoJUnitRunner.class)
96 public class AaiServiceImplTest {
98 private static final String GLOBAL_CUSTOMER_ID = "GLOBAL_CUSTOMER_ID";
99 private static final String CLOUD_REGION_ID = "CLOUD_REGION_ID";
100 private static final String VNF_TYPE = "VNF_TYPE";
101 private static final String TENANT_ID = "TENANT_ID";
102 private static final String TENANT_NAME = "TENANT_NAME";
103 private static final String SERVICE_TYPE = "SERVICE_TYPE";
104 private static final String CORRECT_VALUE = "CORRECT_VALUE";
105 private static final String SUBSCRIBER_ID = "SUBSCRIBER_ID_EXPECTED";
106 private static final String STATUS_TEXT = "STATUS_TEXT";
107 private static final String GLOBAL_SUBSCRIBER_ID = "GLOBAL_SUBSCRIBER_ID";
108 private static final String VNF_INSTANCE_ID_OK = "VNF_INSTANCE_ID_OK";
109 private static final String VNF_INSTANCE_ID_FAIL = "VNF_INSTANCE_ID_FAIL";
110 private static final String PARENT_NAME = "PARENT_NAME";
111 private static final String PARENT_ID = "PARENT_ID";
112 private static final String INVARIANT_ID = "INVARIANT_ID";
113 private static final String GROUP_TYPE_FAILING = "GROUP_TYPE_FAILING";
114 private static final String GROUP_ROLE_OK = "GROUP_ROLE_OK";
115 private static final String GROUP_ROLE_FAILING = "GROUP_ROLE_FAILING";
116 private static final String group_type_ok = "GROUP_TYPE_OK";
117 private static final String CLOUD_TYPE = "CLOUD_TYPE";
120 private AaiResponse<SubscriberList> responseAllSubscribers;
122 private AaiResponse<OperationalEnvironmentList> aaiResponseOpEnvList;
124 private AaiResponse aaiResponse;
126 private AaiResponse<JsonNode> aaiResponseJsonNode;
128 private RoleValidator roleValidator;
131 private AaiClientInterface aaiClient;
134 private AaiResponseTranslator aaiResponseTranslator;
136 private Logging logging;
138 private AAIServiceTree aaiServiceTree;
140 private ExecutorService executorService = Executors.newFixedThreadPool(1);
143 private AaiServiceImpl aaiService;
146 public void shouldGetFullSubscriberListWithoutValidator() {
147 when(aaiClient.getAllSubscribers()).thenReturn(responseAllSubscribers);
148 assertThat(aaiService.getFullSubscriberList()).isEqualTo(responseAllSubscribers);
152 public void shouldGetFullSubscriberListWithValidator() {
153 Subscriber subscriber = createSubscriber();
154 SubscriberList subscriberList = new SubscriberList(Collections.singletonList(subscriber));
156 when(aaiClient.getAllSubscribers()).thenReturn(responseAllSubscribers);
157 when(responseAllSubscribers.getT()).thenReturn(subscriberList);
158 when(responseAllSubscribers.getErrorMessage()).thenReturn(STATUS_TEXT);
159 when(responseAllSubscribers.getHttpCode()).thenReturn(HttpStatus.SC_OK);
160 SubscriberFilteredResults expectedSubscribers = new SubscriberFilteredResults(roleValidator, subscriberList,
161 STATUS_TEXT, HttpStatus.SC_OK);
163 SubscriberFilteredResults actualSubscribers = aaiService.getFullSubscriberList(roleValidator);
165 assertThat(actualSubscribers.getHttpCode()).isEqualTo(expectedSubscribers.getHttpCode());
166 assertThat(actualSubscribers.getErrorMessage()).isEqualTo(expectedSubscribers.getErrorMessage());
170 public void shouldGetOperationalEnvironments() {
171 when(aaiClient.getOperationalEnvironments(anyString(), anyString()))
172 .thenReturn(aaiResponseOpEnvList);
174 AaiResponse<OperationalEnvironmentList> expectedEnvList =
175 aaiService.getOperationalEnvironments(anyString(), anyString());
177 assertThat(expectedEnvList).isEqualTo(aaiResponseOpEnvList);
181 public void shouldGetSubscriberData() {
182 Services services = createAaiResponseServices();
183 AaiResponse<Services> aaiResponseServices = new AaiResponse<>(services, null, HttpStatus.SC_OK);
185 when(aaiClient.getSubscriberData(SUBSCRIBER_ID, false)).thenReturn(aaiResponseServices);
186 when(roleValidator.isServicePermitted(any())).thenReturn(Boolean.TRUE);
188 AaiResponse actualResponse = aaiService.getSubscriberData(SUBSCRIBER_ID, roleValidator, false);
189 List<ServiceSubscription> actualServiceSubscriptions = ((AaiResponse<Services>) actualResponse)
190 .getT().serviceSubscriptions.serviceSubscription;
192 assertThat(actualResponse).isEqualTo(aaiResponseServices);
193 assertThat(actualServiceSubscriptions).allMatch(s -> s.isPermitted);
197 public void shouldGetServiceInstanceEmptySearchResults() {
198 ServiceInstancesSearchResults serviceInstancesSearchResults = new ServiceInstancesSearchResults();
199 AaiResponse<ServiceInstancesSearchResults> emptyResponse = new AaiResponse<>(serviceInstancesSearchResults,
200 null, HttpStatus.SC_OK);
202 AaiResponse actualResponse = aaiService.getServiceInstanceSearchResults(null, null,
205 assertThat(actualResponse).isEqualToComparingFieldByFieldRecursively(emptyResponse);
209 public void shouldGetVersionByInvariantId() {
210 Response response = mock(Response.class);
211 when(aaiClient.getVersionByInvariantId(any())).thenReturn(response);
213 Response actualResponse = aaiService.getVersionByInvariantId(any());
215 assertThat(actualResponse).isEqualTo(response);
219 public void shouldGetSpecificPnf() {
220 AaiResponse<Pnf> expectedResponse = new AaiResponse<>(Pnf.builder().build(), null, HttpStatus.SC_OK);
221 when(aaiClient.getSpecificPnf(anyString())).thenReturn(expectedResponse);
223 AaiResponse<Pnf> actualResponse = aaiService.getSpecificPnf(anyString());
225 assertThat(actualResponse).isEqualTo(expectedResponse);
229 public void shouldGetPnfData() {
230 when(aaiClient.getPNFData(anyString(), anyString(), anyString(), anyString(), anyString(), anyString(),
231 anyString())).thenReturn(aaiResponse);
233 AaiResponse actualResponse = aaiService.getPNFData(anyString(), anyString(), anyString(), anyString(),
234 anyString(), anyString(), anyString());
236 assertThat(actualResponse).isEqualTo(aaiResponse);
240 public void shouldGetServices() {
241 org.onap.vid.aai.model.AaiGetServicesRequestModel.Service s1 =
242 createService("ID1", "V1", "D1");
243 org.onap.vid.aai.model.AaiGetServicesRequestModel.Service s2 =
244 createService("ID2", "V2", "D2");
246 GetServicesAAIRespone services = new GetServicesAAIRespone();
247 services.service = Arrays.asList(s1, s2);
249 AaiResponse<GetServicesAAIRespone> aaiResponseServices =
250 new AaiResponse<>(services, null, HttpStatus.SC_OK);
252 when(aaiClient.getServices()).thenReturn(aaiResponseServices);
254 Object actualObjectOfResponse = aaiService.getServices(roleValidator).getT();
256 assertThat(actualObjectOfResponse).isNotNull();
257 assertThat(((GetServicesAAIRespone) actualObjectOfResponse).service).allMatch(s -> s.isPermitted);
261 public void shouldGetTenants() {
262 GetTenantsResponse tenant1 = new GetTenantsResponse("REGION_ID1", "CLOUD_OWNER1",
263 "TENANT_NAME1", "TENANT_ID1", true);
264 GetTenantsResponse tenant2 = new GetTenantsResponse("REGION_ID2", "CLOUD_OWNER2",
265 "TENANT_NAME2", "TENANT_ID2", false);
266 GetTenantsResponse[] tenants = {tenant1, tenant2};
267 AaiResponse<GetTenantsResponse[]> aaiGetTenantsResponse = new AaiResponse<>(tenants,
268 null, HttpStatus.SC_OK);
270 when(aaiClient.getTenants(anyString(), anyString())).thenReturn(aaiGetTenantsResponse);
271 when(roleValidator.isTenantPermitted(anyString(), anyString(), anyString()))
272 .thenReturn(Boolean.TRUE);
274 GetTenantsResponse[] actualResponses = aaiService
275 .getTenants(anyString(), anyString(), roleValidator).getT();
277 assertThat(actualResponses).isNotNull();
278 assertThat(actualResponses.length).isEqualTo(2);
279 assertThat(actualResponses).allMatch(tenant -> tenant.isPermitted);
283 public void shouldGetVNFDataOfInstanceWithoutFiltering() {
284 when(aaiClient.getVNFData(anyString(), anyString(), anyString())).thenReturn(aaiResponse);
286 AaiResponse actualResponse = aaiService.getVNFData(anyString(), anyString(), anyString());
288 assertThat(actualResponse).isEqualTo(aaiResponse);
292 public void shouldGetVNFDataOfServiceWithoutFiltering() {
293 VnfResult vnfResult1 = createVnfResult("ID1", "generic-vnf");
294 VnfResult vnfResult2 = createVnfResult("ID2", "service-instance");
295 VnfResult vnfResult3 = createVnfResult("ID3", "anything-else");
297 AaiResponse<AaiGetVnfResponse> aaiResponseGetVnfResponse = createAaiResponseVnfResponse(
298 Arrays.asList(vnfResult1, vnfResult2, vnfResult3));
300 when(aaiClient.getVNFData(GLOBAL_SUBSCRIBER_ID, SERVICE_TYPE)).thenReturn(aaiResponseGetVnfResponse);
302 assertThat(aaiService.getVNFData(GLOBAL_SUBSCRIBER_ID, SERVICE_TYPE))
303 .isEqualTo(aaiResponseGetVnfResponse);
307 public void shouldGetNonNullVNFDataOfServiceWhenNoResult() {
308 when(aaiClient.getVNFData(GLOBAL_SUBSCRIBER_ID, SERVICE_TYPE)).thenReturn(null);
310 assertThat(aaiService.getVNFData(GLOBAL_SUBSCRIBER_ID, SERVICE_TYPE))
311 .isEqualToComparingFieldByField(new AaiResponse());
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);
429 List<String> expectedPnfs = Collections.singletonList(CORRECT_VALUE);
430 List<String> actualPnfs = aaiService.getServiceInstanceAssociatedPnfs(anyString(), anyString(), anyString());
432 assertThat(actualPnfs).isEqualTo(expectedPnfs);
436 public void shouldGetPortMirroringConfigData() {
437 AaiResponseTranslator.PortMirroringConfigData expectedData
438 = mock(AaiResponseTranslator.PortMirroringConfigData.class);
440 when(aaiClient.getCloudRegionAndSourceByPortMirroringConfigurationId(anyString()))
441 .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))
466 .thenReturn(expectedIncorrectCodeResponse);
468 AaiResponse actualCorrectCodeResponse = aaiService.getInstanceGroupsByVnfInstanceId(VNF_INSTANCE_ID_OK);
469 AaiResponse actualIncorrectCodeResponse = aaiService.getInstanceGroupsByVnfInstanceId(VNF_INSTANCE_ID_FAIL);
471 List<InstanceGroupInfo> actualCorrectResponseObject =
472 (List<InstanceGroupInfo>) actualCorrectCodeResponse.getT();
474 assertThat(actualCorrectResponseObject)
475 .usingFieldByFieldElementComparator()
476 .hasSameElementsAs(expectedCorrectResponseObject);
478 assertThat(actualIncorrectCodeResponse).isEqualTo(expectedIncorrectCodeResponse);
482 public void shouldGetHomingDataByVfModule() {
483 GetTenantsResponse expectedResponse = new GetTenantsResponse();
484 when(aaiClient.getHomingDataByVfModule(anyString(), anyString())).thenReturn(expectedResponse);
486 GetTenantsResponse actualResponse = aaiService.getHomingDataByVfModule(anyString(), anyString());
487 assertThat(actualResponse).isEqualTo(expectedResponse);
491 public void shouldSearchGroupMembers() {
492 Properties properties = createProperties();
493 Map<String, Properties> regionsAndTenants = createRegionsAndTenantsMap(properties);
495 AAITreeNode validTreeNode = new AAITreeNode();
496 addAdditionalPropertiesToAaiTreeNode(validTreeNode);
497 List<AAITreeNode> validNodes = Arrays.asList(validTreeNode, validTreeNode);
499 AAITreeNode validBranch = createTree(validNodes);
500 addAdditionalPropertiesToAaiTreeNode(validBranch);
501 List<AAITreeNode> testedBranches = Collections.singletonList(validBranch);
503 AAITreeNode testedTree = createTree(testedBranches);
505 RelatedVnf expectedVnf = createExpectedVnf(validBranch);
506 List<RelatedVnf> expectedResult = Collections.singletonList(expectedVnf);
508 when(aaiServiceTree.buildAAITree(anyString(), isNull(), eq(HttpMethod.GET), any(), anyBoolean()))
509 .thenReturn(Collections.singletonList(testedTree));
510 when(aaiClient.getCloudRegionAndTenantByVnfId(anyString())).thenReturn(regionsAndTenants);
511 when(logging.withMDC(any(), any(Function.class))).thenAnswer(invocation -> invocation.getArgument(1));
513 List<RelatedVnf> actualGroupMembers = aaiService.searchGroupMembers(GLOBAL_CUSTOMER_ID, SERVICE_TYPE,
514 INVARIANT_ID, GROUP_TYPE_FAILING, GROUP_ROLE_FAILING);
516 assertThat(actualGroupMembers)
517 .usingFieldByFieldElementComparator()
518 .hasSameElementsAs(expectedResult);
522 public void shouldGetPortMirroringSourcePorts() {
523 PortDetailsTranslator.PortDetails details = mock(PortDetailsTranslator.PortDetails.class);
524 List<PortDetailsTranslator.PortDetails> expectedDetailsList = Arrays.asList(
525 details, details, details
528 when(aaiClient.getPortMirroringSourcePorts(anyString())).thenReturn(expectedDetailsList);
529 List<PortDetailsTranslator.PortDetails> actualDetails = aaiService.getPortMirroringSourcePorts(anyString());
531 assertThat(actualDetails).isEqualTo(expectedDetailsList);
535 public void shouldGetAAIServiceTree() throws JsonProcessingException {
536 ServiceInstance serviceInstance = mock(ServiceInstance.class);
537 String expectedResult = new ObjectMapper().writeValueAsString(serviceInstance);
539 when(aaiServiceTree.getServiceInstanceTopology(anyString(), anyString(), anyString()))
540 .thenReturn(serviceInstance);
541 String actualResult = aaiService.getAAIServiceTree(anyString(), anyString(), anyString());
543 assertThat(actualResult).isEqualTo(expectedResult);
547 private Map<String, Properties> createRegionsAndTenantsMap(Properties properties) {
548 Map<String, Properties> regionsAndTenants = new HashMap<>();
549 regionsAndTenants.put("tenant", properties);
550 regionsAndTenants.put("cloud-region", properties);
551 return regionsAndTenants;
554 private Properties createProperties() {
555 Properties properties = new Properties();
556 properties.setTenantId(TENANT_ID);
557 properties.setTenantName(TENANT_NAME);
558 properties.setCloudRegionId(CLOUD_REGION_ID);
563 private RelatedVnf createExpectedVnf(AAITreeNode validBranch) {
564 RelatedVnf expectedVnf = RelatedVnf.from(validBranch);
565 expectedVnf.setTenantId(TENANT_ID);
566 expectedVnf.setTenantName(TENANT_NAME);
567 expectedVnf.setLcpCloudRegionId(CLOUD_REGION_ID);
568 expectedVnf.setServiceInstanceId(PARENT_ID);
569 expectedVnf.setServiceInstanceName(PARENT_NAME);
570 expectedVnf.setInstanceType(VNF_TYPE);
576 private AAITreeNode createTree(List<AAITreeNode> children) {
577 AAITreeNode tree = new AAITreeNode();
578 tree.addChildren(children);
579 tree.setId(PARENT_ID);
580 tree.setName(PARENT_NAME);
581 tree.setType(SERVICE_INSTANCE);
585 private void addAdditionalPropertiesToAaiTreeNode(AAITreeNode tree) {
586 Map<String, Object> additionalProperties = new HashMap<>();
587 additionalProperties.put("instance-group-role", GROUP_ROLE_OK);
588 additionalProperties.put("instance-group-type", group_type_ok);
589 additionalProperties.put("vnf-type", VNF_TYPE);
590 additionalProperties.put("cloud-region", CLOUD_TYPE);
591 tree.setAdditionalProperties(additionalProperties);
594 private org.onap.vid.asdc.beans.Service createService(String category, String suffix) {
595 return new Service.ServiceBuilder()
596 .setUuid("MODELVER_VERSION_ID" + suffix)
597 .setInvariantUUID("MODEL_INVARIANT_NAME" + suffix)
598 .setCategory(category)
599 .setVersion("MODELVER_VERSION" + suffix)
600 .setName("MODELVER_NAME" + suffix)
601 .setDistributionStatus("MODELVER_DIST_STATUS" + suffix)
602 .setToscaModelURL(null)
603 .setLifecycleState(null)
610 private Result createResultWithoutValidModel() {
611 ModelVers modelVers = new ModelVers();
612 modelVers.setModelVer(Collections.singletonList(new ModelVer()));
614 Model model = new Model();
615 model.setModelVers(modelVers);
617 Result result1 = new Result();
618 result1.setModel(model);
623 private Result createResult(String modelType, String suffix) {
624 ModelVer modelVer = new ModelVer();
625 modelVer.setModelVersionId("MODELVER_VERSION_ID" + suffix);
626 modelVer.setModelVersion("MODELVER_VERSION" + suffix);
627 modelVer.setModelName("MODELVER_NAME" + suffix);
628 modelVer.setDistributionStatus("MODELVER_DIST_STATUS" + suffix);
630 ModelVers modelVers = new ModelVers();
631 modelVers.setModelVer(Collections.singletonList(modelVer));
633 Model model = new Model();
634 model.setModelType(modelType);
635 model.setModelInvariantId("MODEL_INVARIANT_NAME" + suffix);
636 model.setModelVers(modelVers);
638 Result result = new Result();
639 result.setModel(model);
644 private ServiceRelationships createServiceRelationships() {
645 RelationshipList relationsList = createRelationshipList(CORRECT_VALUE);
646 ServiceRelationships relationsService = new ServiceRelationships();
647 relationsService.setRelationshipList(relationsList);
648 return relationsService;
652 private RelationshipList createRelationshipList(String expectedValue) {
653 List<RelationshipData> relationsDataList = createRelationshipDataList(expectedValue);
654 return createRelationshipList(relationsDataList);
658 private RelationshipList createRelationshipList(List<RelationshipData> relationsDataList) {
659 Relationship relation1 = crateRelationship("any", relationsDataList);
660 Relationship relation2 = crateRelationship("zone", relationsDataList);
661 Relationship relation3 = crateRelationship("logical-link", relationsDataList);
662 Relationship relation4 = crateRelationship("lag-interface", relationsDataList);
663 Relationship relation5 = crateRelationship("pnf", relationsDataList);
665 RelationshipList relationsList = new RelationshipList();
666 relationsList.setRelationship(Arrays.asList(relation1, relation2, relation3, relation4, relation5));
667 return relationsList;
671 private List<RelationshipData> createRelationshipDataList(String expectedValue) {
672 RelationshipData relationData1 = createRelationshipData("any-key", "incorrect_key");
673 RelationshipData relationData2 = createRelationshipData("zone.zone-id", expectedValue);
674 RelationshipData relationData3 = createRelationshipData("logical-link.link-name", expectedValue);
675 RelationshipData relationData4 = createRelationshipData("pnf.pnf-name", expectedValue);
677 return Arrays.asList(relationData1, relationData2, relationData3, relationData4);
681 private Relationship crateRelationship(String relatedTo, List<RelationshipData> relationsDataList) {
682 Relationship relation = new Relationship();
683 relation.setRelatedTo(relatedTo);
684 relation.setRelationDataList(relationsDataList);
689 private RelationshipData createRelationshipData(String key, String value) {
690 RelationshipData relationData = new RelationshipData();
691 relationData.setRelationshipKey(key);
692 relationData.setRelationshipValue(value);
696 private org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.RelationshipList createRelationshipList() {
697 RelatedToProperty property1 =
698 createRelatedToProperty("instance-group.instance-group-name", CORRECT_VALUE);
699 RelatedToProperty property2 =
700 createRelatedToProperty("anything-key", "anything-value");
701 List<RelatedToProperty> properties = Arrays.asList(property1, property2);
703 org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.Relationship relationship1 =
704 createRelationship("instance-group", properties);
705 org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.Relationship relationship2 =
706 createRelationship("any-key", properties);
708 List<org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.Relationship> relationships =
709 Arrays.asList(relationship1, relationship2);
711 org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.RelationshipList relationshipList =
712 new org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.RelationshipList();
713 relationshipList.setRelationship(relationships);
715 return relationshipList;
719 private org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.Relationship createRelationship(String relatedTo,
720 List<RelatedToProperty> relatedToPropertyList) {
721 org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.Relationship relationship1 =
722 new org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.Relationship();
723 relationship1.setRelatedTo(relatedTo);
724 relationship1.setRelatedToPropertyList(relatedToPropertyList);
725 return relationship1;
729 private RelatedToProperty createRelatedToProperty(String key, String value) {
730 RelatedToProperty prop = new RelatedToProperty();
732 prop.setValue(value);
737 private AaiResponse<AaiGetVnfResponse> createAaiResponseVnfResponse(List<VnfResult> vnfResults) {
738 AaiGetVnfResponse vnfResponse = new AaiGetVnfResponse();
739 vnfResponse.setResults(vnfResults);
740 return new AaiResponse<>(vnfResponse, null, HttpStatus.SC_OK);
743 private VnfResult createVnfResult(String id, String nodeType) {
744 VnfResult result = new VnfResult();
745 result.setJsonId(id);
746 result.setJsonNodeType(nodeType);
751 private org.onap.vid.aai.model.AaiGetServicesRequestModel.Service createService(String serviceId,
752 String resourceVersion,
753 String serviceDescription) {
754 org.onap.vid.aai.model.AaiGetServicesRequestModel.Service service
755 = new org.onap.vid.aai.model.AaiGetServicesRequestModel.Service();
756 service.isPermitted = false;
757 service.resourceVersion = resourceVersion;
758 service.serviceDescription = serviceDescription;
759 service.serviceId = serviceId;
764 private Services createAaiResponseServices() {
765 ServiceSubscription sub1 = new ServiceSubscription();
766 sub1.isPermitted = false;
767 sub1.serviceType = "serviceSubsType1";
769 ServiceSubscription sub2 = new ServiceSubscription();
770 sub2.isPermitted = true;
771 sub2.serviceType = "serviceSubsType2";
773 ServiceSubscriptions serviceSubs = new ServiceSubscriptions();
774 serviceSubs.serviceSubscription = Collections.singletonList(sub2);
776 Services services = new Services();
777 services.globalCustomerId = GLOBAL_CUSTOMER_ID;
778 services.resourceVersion = "v-1";
779 services.subscriberName = "name-1";
780 services.subscriberType = "type-1";
781 services.serviceSubscriptions = serviceSubs;
786 private Subscriber createSubscriber() {
787 Subscriber subscriber = new Subscriber();
788 subscriber.globalCustomerId = "id-1";
789 subscriber.resourceVersion = "v-1";
790 subscriber.subscriberName = "name-1";
791 subscriber.subscriberType = "type-1";
796 public void whenGetNewestModelVersionByInvariantId_thenReturnSameValueAsAaiClient() {
797 String modelInvariantId = "123";
798 ModelVer modelVer = mock(ModelVer.class);
799 when(aaiClient.getLatestVersionByInvariantId(eq(modelInvariantId))).thenReturn(modelVer);
800 assertThat(aaiService.getNewestModelVersionByInvariantId(modelInvariantId)).isEqualTo(modelVer);