2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2018 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.Mockito.mock;
26 import static org.mockito.Mockito.when;
28 import java.util.ArrayList;
29 import java.util.Arrays;
30 import java.util.List;
31 import javax.ws.rs.core.Response;
32 import org.junit.Test;
33 import org.onap.vid.aai.AaiClientInterface;
34 import org.onap.vid.aai.AaiGetVnfResponse;
35 import org.onap.vid.aai.AaiOverTLSClientInterface;
36 import org.onap.vid.aai.AaiResponse;
37 import org.onap.vid.aai.AaiResponseTranslator;
38 import org.onap.vid.aai.model.AaiGetTenatns.GetTenantsResponse;
39 import org.onap.vid.aai.model.VnfResult;
40 import org.onap.vid.roles.RoleValidator;
42 public class AaiServiceImplTest {
44 private AaiClientInterface aaiClient = mock(AaiClientInterface.class);
45 private AaiOverTLSClientInterface aaiSslClient = mock(AaiOverTLSClientInterface.class);
46 private AaiResponseTranslator aaiResponseTranslator = mock(AaiResponseTranslator.class);
47 private AAITreeNodeBuilder aaiTreeNode = mock(AAITreeNodeBuilder.class);
48 private AAIServiceTree aaiServiceTree = mock(AAIServiceTree.class);
50 private AaiServiceImpl aaiService = new AaiServiceImpl(
51 aaiClient, aaiSslClient, aaiResponseTranslator, aaiTreeNode, aaiServiceTree
55 public void shouldRetrievePnf() {
57 String globalCustomerId = "global_customer";
58 String serviceType = "service_type";
59 String modelVersionId = "model_version";
60 String modelInvariantId = "model_invariant_id";
61 String cloudRegion = "cloud_region";
62 String equipVendor = "equip_vendor";
63 String equipModel = "equip_model";
65 AaiResponse response = mock(AaiResponse.class);
66 when(aaiClient.getPNFData(
67 globalCustomerId, serviceType, modelVersionId, modelInvariantId, cloudRegion, equipVendor, equipModel
68 )).thenReturn(response);
71 AaiResponse actual = aaiService.getPNFData(
72 globalCustomerId, serviceType, modelVersionId, modelInvariantId, cloudRegion, equipVendor, equipModel
76 assertThat(response).isEqualTo(actual);
80 @SuppressWarnings("unchecked")
81 public void shouldRetrieveSpecificPnf() {
83 String pnfId = "some_pnf_id";
85 AaiResponse response = mock(AaiResponse.class);
86 when(aaiClient.getSpecificPnf(pnfId)).thenReturn(response);
89 AaiResponse actual = aaiService.getSpecificPnf(pnfId);
92 assertThat(response).isEqualTo(actual);
96 public void shouldRetrieveTenantsByInvariantId() {
98 List<String> modelInvariantId = new ArrayList<>();
100 Response response = mock(Response.class);
101 when(aaiClient.getVersionByInvariantId(modelInvariantId)).thenReturn(response);
104 Response actual = aaiService.getVersionByInvariantId(modelInvariantId);
107 assertThat(response).isEqualTo(actual);
111 @SuppressWarnings("unchecked")
112 public void shouldRetrieveTenants() {
114 String globalCustomerId = "global_customer";
115 String serviceType = "service_type";
117 GetTenantsResponse permittedTenant = new GetTenantsResponse(
118 "cloud_region", "cloud_owner", "permitted_tenant", "tenant_id", false
120 GetTenantsResponse unpermittedTenant = new GetTenantsResponse(
121 "cloud_region", "cloud_owner", "unpermitted_tenant", "tenant_id", false
124 AaiResponse<GetTenantsResponse[]> response = mock(AaiResponse.class);
125 when(response.getT()).thenReturn(new GetTenantsResponse[]{ permittedTenant, unpermittedTenant });
126 when(aaiClient.getTenants(globalCustomerId, serviceType)).thenReturn(response);
128 RoleValidator roleValidator = mock(RoleValidator.class);
129 when(roleValidator.isTenantPermitted(globalCustomerId, serviceType, "permitted_tenant")).thenReturn(true);
130 when(roleValidator.isTenantPermitted(globalCustomerId, serviceType, "unpermitted_tenant")).thenReturn(false);
133 AaiResponse actual = aaiService.getTenants(globalCustomerId, serviceType, roleValidator);
136 assertThat(response).isEqualTo(actual);
137 assertThat(permittedTenant.isPermitted).isTrue();
138 assertThat(unpermittedTenant.isPermitted).isFalse();
142 public void shouldRetrieveVNFs() {
144 String globalSubscriber = "global_subscriber";
145 String serviceType = "service_type";
146 String serviceInstanceId = "service_instance";
148 AaiResponse response = mock(AaiResponse.class);
149 when(aaiClient.getVNFData(globalSubscriber, serviceType, serviceInstanceId)).thenReturn(response);
152 AaiResponse actual = aaiService.getVNFData(globalSubscriber, serviceType, serviceInstanceId);
155 assertThat(response).isEqualTo(actual);
159 @SuppressWarnings("unchecked")
160 public void shouldRetrieveAndFilterVNFsBySubscriberAndServiceType() {
162 String globalSubscriber = "global_subscriber";
163 String serviceType = "service_type";
165 VnfResult genericVnf = new VnfResult();
166 genericVnf.nodeType = "generic-vnf";
168 VnfResult serviceInstance = new VnfResult();
169 serviceInstance.nodeType = "service-instance";
171 VnfResult someVnf = new VnfResult();
172 someVnf.nodeType = "some-vnf";
174 AaiResponse<AaiGetVnfResponse> response = mock(AaiResponse.class);
175 AaiGetVnfResponse vnfs = new AaiGetVnfResponse();
176 vnfs.results = Arrays.asList(genericVnf, serviceInstance, someVnf);
177 when(response.getT()).thenReturn(vnfs);
179 when(aaiClient.getVNFData(globalSubscriber, serviceType)).thenReturn(response);
182 AaiResponse actual = aaiService.getVNFData(globalSubscriber, serviceType);
185 assertThat(response).isEqualTo(actual);
186 assertThat(response.getT().results).containsOnly(genericVnf, serviceInstance);