create RoleValidatorFactory component.
[vid.git] / vid-app-common / src / test / java / org / onap / vid / controller / AaiControllerTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2019 Nokia.
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
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  */
21
22 package org.onap.vid.controller;
23
24 import static org.hamcrest.MatcherAssert.assertThat;
25 import static org.hamcrest.core.Is.is;
26 import static org.mockito.ArgumentMatchers.any;
27 import static org.mockito.ArgumentMatchers.anyString;
28 import static org.mockito.ArgumentMatchers.eq;
29 import static org.mockito.ArgumentMatchers.isA;
30 import static org.mockito.BDDMockito.given;
31 import static org.mockito.Mockito.mock;
32 import static org.mockito.Mockito.when;
33 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
34 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
35 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
36 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
37
38 import com.fasterxml.jackson.databind.ObjectMapper;
39 import com.google.common.collect.ImmutableList;
40 import com.google.common.collect.ImmutableMap;
41 import com.google.common.collect.ImmutableMultimap;
42 import com.google.common.collect.Lists;
43 import com.google.common.collect.Multimap;
44 import java.util.List;
45 import java.util.Map;
46 import java.util.UUID;
47 import javax.ws.rs.core.Response;
48 import org.junit.Before;
49 import org.junit.Test;
50 import org.junit.runner.RunWith;
51 import org.mockito.Answers;
52 import org.mockito.Mock;
53 import org.mockito.Mockito;
54 import org.mockito.junit.MockitoJUnitRunner;
55 import org.onap.portalsdk.core.domain.User;
56 import org.onap.portalsdk.core.util.SystemProperties;
57 import org.onap.vid.aai.AaiResponse;
58 import org.onap.vid.aai.AaiResponseTranslator;
59 import org.onap.vid.aai.AaiResponseTranslator.PortMirroringConfigData;
60 import org.onap.vid.aai.AaiResponseTranslator.PortMirroringConfigDataError;
61 import org.onap.vid.aai.AaiResponseTranslator.PortMirroringConfigDataOk;
62 import org.onap.vid.aai.OperationalEnvironment;
63 import org.onap.vid.aai.model.AaiGetAicZone.AicZones;
64 import org.onap.vid.aai.model.AaiGetAicZone.Zone;
65 import org.onap.vid.aai.model.AaiGetOperationalEnvironments.OperationalEnvironmentList;
66 import org.onap.vid.aai.model.AaiGetPnfs.Pnf;
67 import org.onap.vid.aai.model.PortDetailsTranslator.PortDetails;
68 import org.onap.vid.aai.model.PortDetailsTranslator.PortDetailsError;
69 import org.onap.vid.aai.model.PortDetailsTranslator.PortDetailsOk;
70 import org.onap.vid.aai.util.AAIRestInterface;
71 import org.onap.vid.model.VersionByInvariantIdsRequest;
72 import org.onap.vid.properties.Features;
73 import org.onap.vid.roles.AlwaysValidRoleValidator;
74 import org.onap.vid.roles.RoleProvider;
75 import org.onap.vid.roles.RoleValidator;
76 import org.onap.vid.roles.RoleValidatorBySubscriberAndServiceType;
77 import org.onap.vid.roles.RoleValidatorFactory;
78 import org.onap.vid.services.AaiService;
79 import org.onap.vid.utils.SystemPropertiesWrapper;
80 import org.onap.vid.utils.Unchecked;
81 import org.springframework.http.HttpStatus;
82 import org.springframework.http.MediaType;
83 import org.springframework.test.web.servlet.MockMvc;
84 import org.springframework.test.web.servlet.setup.MockMvcBuilders;
85 import org.togglz.core.manager.FeatureManager;
86
87 @RunWith(MockitoJUnitRunner.class)
88 public class AaiControllerTest {
89
90     private static final String ID_1 = "id1";
91     private static final String ID_2 = "id2";
92     private final ObjectMapper objectMapper = new ObjectMapper();
93     @Mock
94     private AaiService aaiService;
95     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
96     private AAIRestInterface aaiRestInterface;
97     @Mock
98     private RoleProvider roleProvider;
99     @Mock
100     private RoleValidator roleValidator;
101     @Mock
102     private SystemPropertiesWrapper systemPropertiesWrapper;
103     @Mock
104     private FeatureManager featureManager;
105
106     private MockMvc mockMvc;
107     private AaiController aaiController;
108
109     @Before
110     public void setUp() {
111         aaiController = new AaiController(aaiService, aaiRestInterface, roleProvider, systemPropertiesWrapper,
112             featureManager);
113         when(roleProvider.getUserRolesValidator(any())).thenReturn(roleValidator);
114         mockMvc = MockMvcBuilders.standaloneSetup(aaiController).build();
115     }
116
117     @Test
118     public void getAicZoneForPnf_shouldReturnOKResponse() throws Exception {
119         String globalCustomerId = "testCustomerId";
120         String serviceType = "testServiceType";
121         String serviceId = "testServiceId";
122         String expectedResponseBody = "OK_RESPONSE";
123         AaiResponse<String> aaiResponse = new AaiResponse<>(expectedResponseBody, null, HttpStatus.OK.value());
124         given(aaiService.getAicZoneForPnf(globalCustomerId, serviceType, serviceId)).willReturn(aaiResponse);
125
126         mockMvc.perform(
127             get("/aai_get_aic_zone_for_pnf/{globalCustomerId}/{serviceType}/{serviceId}", globalCustomerId, serviceType,
128                 serviceId)
129                 .contentType(MediaType.APPLICATION_JSON)
130                 .accept(MediaType.APPLICATION_JSON))
131             .andExpect(status().isOk())
132             .andExpect(content().string(objectMapper.writeValueAsString(expectedResponseBody)));
133     }
134
135     @Test
136     public void getInstanceGroupsByVnfInstanceId_shouldReturnOKResponse() throws Exception {
137         String vnfInstanceId = "testVndInstanceId";
138         String expectedResponseBody = "OK_RESPONSE";
139         AaiResponse<String> aaiResponse = new AaiResponse<>(expectedResponseBody, null, HttpStatus.OK.value());
140         given(aaiService.getInstanceGroupsByVnfInstanceId(vnfInstanceId)).willReturn(aaiResponse);
141
142         mockMvc.perform(get("/aai_get_instance_groups_by_vnf_instance_id/{vnfInstanceId}", vnfInstanceId)
143             .contentType(MediaType.APPLICATION_JSON)
144             .accept(MediaType.APPLICATION_JSON))
145             .andExpect(status().isOk())
146             .andExpect(content().string(objectMapper.writeValueAsString(expectedResponseBody)));
147     }
148
149     @Test
150     public void doGetServiceInstance_shouldFetchServiceInstance_byServiceInstanceId() throws Exception {
151         String serviceInstanceId = "testServiceInstanceId";
152         String serviceInstanceType = "Service Instance Id";
153         String expectedResponseBody = "OK_RESPONSE";
154         Response response = mock(Response.class);
155         given(response.readEntity(String.class)).willReturn(expectedResponseBody);
156         given(response.getStatus()).willReturn(HttpStatus.OK.value());
157
158         given(aaiRestInterface.RestGet(eq("VidAaiController"), anyString(), eq(Unchecked.toURI(
159             "search/nodes-query?search-node-type=service-instance&filter=service-instance-id:EQUALS:"
160                 + serviceInstanceId)),
161             eq(false)).getResponse()).willReturn(response);
162
163         mockMvc
164             .perform(get("/aai_get_service_instance/{service-instance-id}/{service-instance-type}", serviceInstanceId,
165                 serviceInstanceType)
166                 .contentType(MediaType.APPLICATION_JSON)
167                 .accept(MediaType.APPLICATION_JSON))
168             .andExpect(status().isOk())
169             .andExpect(content().string(expectedResponseBody));
170     }
171
172     @Test
173     public void doGetServiceInstance_shouldFetchServiceInstance_byServiceInstanceName() throws Exception {
174         String serviceInstanceId = "testServiceInstanceId";
175         String serviceInstanceType = "testServiceInstanceType";
176         String expectedResponseBody = "OK_RESPONSE";
177         Response response = mock(Response.class);
178         given(response.readEntity(String.class)).willReturn(expectedResponseBody);
179         given(response.getStatus()).willReturn(HttpStatus.OK.value());
180
181         given(aaiRestInterface.RestGet(eq("VidAaiController"), anyString(), eq(Unchecked.toURI(
182             "search/nodes-query?search-node-type=service-instance&filter=service-instance-name:EQUALS:"
183                 + serviceInstanceId)),
184             eq(false)).getResponse()).willReturn(response);
185
186         mockMvc
187             .perform(get("/aai_get_service_instance/{service-instance-id}/{service-instance-type}", serviceInstanceId,
188                 serviceInstanceType)
189                 .contentType(MediaType.APPLICATION_JSON)
190                 .accept(MediaType.APPLICATION_JSON))
191             .andExpect(status().isOk())
192             .andExpect(content().string(expectedResponseBody));
193     }
194
195     @Test
196     public void doGetServices_shouldReturnOkResponse() throws Exception {
197         String globalCustomerId = "testGlobalCustomerId";
198         String serviceSubscriptionId = "testServiceSubscriptionId";
199         String expectedResponseBody = "OK_RESPONSE";
200         Response response = mock(Response.class);
201         given(response.readEntity(String.class)).willReturn(expectedResponseBody);
202         given(response.getStatus()).willReturn(HttpStatus.OK.value());
203
204         given(aaiRestInterface.RestGet(
205             eq("VidAaiController"),
206             anyString(),
207             eq(Unchecked.toURI(
208                 "business/customers/customer/" + globalCustomerId + "/service-subscriptions/service-subscription/"
209                     + serviceSubscriptionId + "?depth=0")),
210             eq(false)).getResponse()).willReturn(response);
211
212         mockMvc
213             .perform(
214                 get("/aai_get_service_subscription/{global-customer-id}/{service-subscription-id}", globalCustomerId,
215                     serviceSubscriptionId)
216                     .contentType(MediaType.APPLICATION_JSON)
217                     .accept(MediaType.APPLICATION_JSON))
218             .andExpect(status().isOk())
219             .andExpect(content().string(expectedResponseBody));
220     }
221
222     @Test
223     public void doGetServices_shouldReturnInternalServerError_forEmptyResponse() throws Exception {
224         String globalCustomerId = "testGlobalCustomerId";
225         String serviceSubscriptionId = "testServiceSubscriptionId";
226         String expectedResponseBody = "Failed to fetch data from A&AI, check server logs for details.";
227         given(aaiRestInterface.RestGet(
228             eq("VidAaiController"),
229             anyString(),
230             eq(Unchecked.toURI(
231                 "business/customers/customer/" + globalCustomerId + "/service-subscriptions/service-subscription/"
232                     + serviceSubscriptionId + "?depth=0")),
233             eq(false)).getResponse()).willReturn(null);
234
235         mockMvc
236             .perform(
237                 get("/aai_get_service_subscription/{global-customer-id}/{service-subscription-id}", globalCustomerId,
238                     serviceSubscriptionId)
239                     .contentType(MediaType.APPLICATION_JSON)
240                     .accept(MediaType.APPLICATION_JSON))
241             .andExpect(status().isInternalServerError())
242             .andExpect(content().string(expectedResponseBody));
243     }
244
245     @Test
246     public void getPortMirroringConfigData_givenIds_shouldReturnConfigDataMappedById() throws Exception {
247         PortMirroringConfigDataOk okConfigData = new PortMirroringConfigDataOk("foo");
248         PortMirroringConfigDataError errorConfigData = new PortMirroringConfigDataError("bar", "{ baz: qux }");
249         Map<String, PortMirroringConfigData> expectedJson = ImmutableMap.of(
250             ID_1, okConfigData,
251             ID_2, errorConfigData);
252         given(aaiService.getPortMirroringConfigData(ID_1)).willReturn(okConfigData);
253         given(aaiService.getPortMirroringConfigData(ID_2)).willReturn(errorConfigData);
254
255         mockMvc
256             .perform(get("/aai_getPortMirroringConfigsData")
257                 .param("configurationIds", ID_1, ID_2)
258                 .contentType(MediaType.APPLICATION_JSON)
259                 .accept(MediaType.APPLICATION_JSON))
260             .andExpect(status().isOk())
261             .andExpect(content().json(objectMapper.writeValueAsString(expectedJson)));
262     }
263
264     @Test
265     public void getPortMirroringSourcePorts_givenIds_shouldReturnPortDetailsMappedById() throws Exception {
266         PortDetailsOk portDetailsOk = new PortDetailsOk("foo", "testInterface", true);
267         PortDetailsError portDetailsError = new PortDetailsError("bar", "{ baz: qux }");
268         Multimap<String, PortDetails> expectedJson = ImmutableMultimap.of(
269             ID_1, portDetailsOk,
270             ID_2, portDetailsError);
271         given(aaiService.getPortMirroringSourcePorts(ID_1)).willReturn(Lists.newArrayList(portDetailsOk));
272         given(aaiService.getPortMirroringSourcePorts(ID_2)).willReturn(Lists.newArrayList(portDetailsError));
273
274         mockMvc
275             .perform(get("/aai_getPortMirroringSourcePorts")
276                 .param("configurationIds", ID_1, ID_2)
277                 .contentType(MediaType.APPLICATION_JSON)
278                 .accept(MediaType.APPLICATION_JSON))
279             .andExpect(status().isOk())
280             .andExpect(content().json(objectMapper.writeValueAsString(expectedJson.asMap())));
281     }
282
283     @Test
284     public void getNodeTemplateInstances_givenParams_shouldReturnCorrectResponse() throws Exception {
285         String globalCustomerId = "testCustomerId";
286         String serviceType = "testServiceType";
287         String modelVersionId = UUID.nameUUIDFromBytes("modelVersionId".getBytes()).toString();
288         String modelInvariantId = UUID.nameUUIDFromBytes("modelInvariantId".getBytes()).toString();
289         String cloudRegion = "testRegion";
290         String urlTemplate = "/aai_get_vnf_instances/{globalCustomerId}/{serviceType}/{modelVersionId}/{modelInvariantId}/{cloudRegion}";
291         String expectedResponseBody = "myResponse";
292         AaiResponse<String> aaiResponse = new AaiResponse<>(expectedResponseBody, "", HttpStatus.OK.value());
293         given(aaiService
294             .getNodeTemplateInstances(globalCustomerId, serviceType, modelVersionId, modelInvariantId, cloudRegion))
295             .willReturn(aaiResponse);
296
297         mockMvc
298             .perform(get(urlTemplate, globalCustomerId, serviceType, modelVersionId, modelInvariantId, cloudRegion)
299                 .contentType(MediaType.APPLICATION_JSON)
300                 .accept(MediaType.APPLICATION_JSON))
301             .andExpect(status().isOk())
302             .andExpect(content().string(expectedResponseBody));
303     }
304
305     @Test
306     public void getAicZones_shouldReturnAaiZones_whenAaiHttpStatusIsOK() throws Exception {
307         AicZones aicZones = new AicZones(ImmutableList.of(new Zone("TEST_ZONE_ID", "TEST_ZONE_NAME")));
308         given(aaiService.getAaiZones()).willReturn(new AaiResponse(aicZones, "", HttpStatus.OK.value()));
309
310         mockMvc.perform(get("/aai_get_aic_zones")
311             .contentType(MediaType.APPLICATION_JSON)
312             .accept(MediaType.APPLICATION_JSON))
313             .andExpect(status().isOk())
314             .andExpect(content().json(objectMapper.writeValueAsString(aicZones)));
315     }
316
317     @Test
318     public void getAicZones_shouldReturnErrorResponse_whenAaiHttpStatusOtherThanOK() throws Exception {
319         String expectedErrorMessage = "Calling AAI Failed";
320         given(aaiService.getAaiZones())
321             .willReturn(new AaiResponse(null, expectedErrorMessage, HttpStatus.INTERNAL_SERVER_ERROR.value()));
322
323         mockMvc.perform(get("/aai_get_aic_zones")
324             .contentType(MediaType.APPLICATION_JSON)
325             .accept(MediaType.APPLICATION_JSON))
326             .andExpect(status().isInternalServerError())
327             .andExpect(content().string(expectedErrorMessage));
328     }
329
330     @Test
331     public void getSpecificPnf_shouldReturnPnfObjectForPnfId() throws Exception {
332         String pnfId = "MyPnfId";
333         Pnf pnf = Pnf.builder()
334             .withPnfId(pnfId)
335             .withPnfName("TestPnf")
336             .withPnfName2("pnfName2")
337             .withPnfName2Source("pnfNameSource")
338             .withEquipModel("model")
339             .withEquipType("type")
340             .withEquipVendor("vendor")
341             .build();
342         AaiResponse<Pnf> aaiResponse = new AaiResponse<>(pnf, "", HttpStatus.OK.value());
343         given(aaiService.getSpecificPnf(pnfId)).willReturn(aaiResponse);
344
345         mockMvc.perform(get("/aai_get_pnfs/pnf/{pnf_id}", pnfId)
346             .contentType(MediaType.APPLICATION_JSON)
347             .accept(MediaType.APPLICATION_JSON))
348             .andExpect(status().isOk())
349             .andExpect(content().json(objectMapper.writeValueAsString(pnf)));
350     }
351
352     @Test
353     public void getSpecificPnf_shouldHandleAAIServiceException() throws Exception {
354         String pnfId = "MyPnfId";
355         String expectedErrorMessage = "AAI Service Error";
356         given(aaiService.getSpecificPnf(pnfId)).willThrow(new RuntimeException(expectedErrorMessage));
357
358         mockMvc.perform(get("/aai_get_pnfs/pnf/{pnf_id}", pnfId)
359             .contentType(MediaType.APPLICATION_JSON)
360             .accept(MediaType.APPLICATION_JSON))
361             .andExpect(status().isInternalServerError())
362             .andExpect(content().string(expectedErrorMessage));
363     }
364
365     public void getPNFInstances_shouldReturnOKResponseFromAAIService() throws Exception {
366         String globalCustomerId = "testCustomerId";
367         String serviceType = "testServiceType";
368         String modelVersionId = UUID.nameUUIDFromBytes("modelVersionId".getBytes()).toString();
369         String modelInvariantId = UUID.nameUUIDFromBytes("modelInvariantId".getBytes()).toString();
370         String cloudRegion = "testRegion";
371         String equipVendor = "testVendor";
372         String equipModel = "model123";
373         String urlTemplate = "/aai_get_pnf_instances/{globalCustomerId}/{serviceType}/{modelVersionId}/{modelInvariantId}/{cloudRegion}/{equipVendor}/{equipModel}";
374         String expectedResponseBody = "myResponse";
375         AaiResponse<String> aaiResponse = new AaiResponse<>(expectedResponseBody, "", HttpStatus.OK.value());
376
377         given(aaiService
378             .getPNFData(globalCustomerId, serviceType, modelVersionId, modelInvariantId, cloudRegion, equipVendor,
379                 equipModel)).willReturn(aaiResponse);
380
381         mockMvc.perform(
382             get(urlTemplate, globalCustomerId, serviceType, modelVersionId,
383                 modelInvariantId, cloudRegion, equipVendor, equipModel)
384                 .contentType(MediaType.APPLICATION_JSON)
385                 .accept(MediaType.APPLICATION_JSON))
386             .andExpect(status().isOk())
387             .andExpect(content().string(expectedResponseBody));
388     }
389
390     @Test
391     public void getVersionByInvariantId_shouldReturnOKResponse() throws Exception {
392         String expectedResponse = "OKResponse";
393         VersionByInvariantIdsRequest request = new VersionByInvariantIdsRequest();
394         request.versions = ImmutableList.of("ver1", "ver2");
395         Response response = mock(Response.class);
396         given(response.readEntity(String.class)).willReturn(expectedResponse);
397         given(aaiService
398             .getVersionByInvariantId(request.versions)).willReturn(response);
399
400         mockMvc.perform(
401             post("/aai_get_version_by_invariant_id")
402                 .content(objectMapper.writeValueAsString(request))
403                 .contentType(MediaType.APPLICATION_JSON)
404                 .accept(MediaType.APPLICATION_JSON))
405             .andExpect(status().isOk())
406             .andExpect(content().string(expectedResponse));
407     }
408
409     @Test
410     public void getSubscriberDetails_shouldOmitServiceInstancesFromSubscriberData_whenFeatureEnabled_andOmitFlagIsTrue()
411         throws Exception {
412         boolean isFeatureActive = true;
413         boolean omitServiceInstances = true;
414
415         String subscriberId = "subscriberId";
416         String okResponseBody = "OK_RESPONSE";
417         AaiResponse<String> aaiResponse = new AaiResponse<>(okResponseBody, "", HttpStatus.OK.value());
418         given(featureManager.isActive(Features.FLAG_1906_AAI_SUB_DETAILS_REDUCE_DEPTH)).willReturn(isFeatureActive);
419         given(aaiService.getSubscriberData(eq(subscriberId), isA(RoleValidator.class),
420             eq(isFeatureActive && omitServiceInstances)))
421             .willReturn(aaiResponse);
422
423         mockMvc.perform(
424             get("/aai_sub_details/{subscriberId}", subscriberId)
425                 .param("omitServiceInstances", Boolean.toString(omitServiceInstances))
426                 .contentType(MediaType.APPLICATION_JSON)
427                 .accept(MediaType.APPLICATION_JSON))
428             .andExpect(status().isOk())
429             .andExpect(content().string(objectMapper.writeValueAsString(okResponseBody)));
430     }
431
432     @Test
433     public void getSubscriberDetails_shouldIncludeServiceInstancesFromSubscriberData_whenFeatureEnabled_andOmitFlagIsFalse()
434         throws Exception {
435         boolean isFeatureActive = true;
436         boolean omitServiceInstances = false;
437
438         getSubscriberDetails_assertServiceInstancesInclusion(isFeatureActive, omitServiceInstances);
439     }
440
441     @Test
442     public void getSubscriberDetails_shouldIncludeServiceInstancesFromSubscriberData_whenFeatureDisabled_andOmitFlagIsTrue()
443         throws Exception {
444         boolean isFeatureActive = false;
445         boolean omitServiceInstances = true;
446
447         getSubscriberDetails_assertServiceInstancesInclusion(isFeatureActive, omitServiceInstances);
448     }
449
450     @Test
451     public void getPortMirroringConfigData_givenThreeIds_ReturnsThreeResults() {
452
453         final AaiResponseTranslator.PortMirroringConfigDataOk toBeReturnedForA = new AaiResponseTranslator.PortMirroringConfigDataOk(
454             "foobar");
455         final AaiResponseTranslator.PortMirroringConfigDataError toBeReturnedForB = new AaiResponseTranslator.PortMirroringConfigDataError(
456             "foo", "{ baz: qux }");
457         final AaiResponseTranslator.PortMirroringConfigDataOk toBeReturnedForC = new AaiResponseTranslator.PortMirroringConfigDataOk(
458             "corge");
459
460         Mockito
461             .doReturn(toBeReturnedForA)
462             .doReturn(toBeReturnedForB)
463             .doReturn(toBeReturnedForC)
464             .when(aaiService).getPortMirroringConfigData(Mockito.anyString());
465
466         final Map<String, AaiResponseTranslator.PortMirroringConfigData> result = aaiController
467             .getPortMirroringConfigsData(ImmutableList.of("a", "b", "c"));
468
469         assertThat(result, is(ImmutableMap.of(
470             "a", toBeReturnedForA,
471             "b", toBeReturnedForB,
472             "c", toBeReturnedForC
473         )));
474     }
475
476     @Test
477     public void getSubscriberDetails_shouldIncludeServiceInstancesFromSubscriberData_whenFeatureDisabled_andOmitFlagIsFalse()
478         throws Exception {
479         boolean isFeatureActive = false;
480         boolean omitServiceInstances = false;
481         getSubscriberDetails_assertServiceInstancesInclusion(isFeatureActive, omitServiceInstances);
482     }
483
484     private void getSubscriberDetails_assertServiceInstancesInclusion(boolean isFeatureActive,
485         boolean omitServiceInstances) throws Exception {
486         String subscriberId = "subscriberId";
487         String okResponseBody = "OK_RESPONSE";
488         AaiResponse<String> aaiResponse = new AaiResponse<>(okResponseBody, "", HttpStatus.OK.value());
489         given(featureManager.isActive(Features.FLAG_1906_AAI_SUB_DETAILS_REDUCE_DEPTH)).willReturn(isFeatureActive);
490         given(aaiService.getSubscriberData(eq(subscriberId), isA(RoleValidator.class),
491             eq(isFeatureActive && omitServiceInstances)))
492             .willReturn(aaiResponse);
493
494         mockMvc.perform(
495             get("/aai_sub_details/{subscriberId}", subscriberId)
496                 .param("omitServiceInstances", Boolean.toString(omitServiceInstances))
497                 .contentType(MediaType.APPLICATION_JSON)
498                 .accept(MediaType.APPLICATION_JSON))
499             .andExpect(status().isOk())
500             .andExpect(content().string(objectMapper.writeValueAsString(okResponseBody)));
501     }
502
503     @Test
504     public void getSpecificConfiguration_shouldReturnOkResponse() throws Exception {
505         String configurationId = "testGlobalCustomerId";
506         String expectedResponseBody = "OK_RESPONSE";
507         Response response = mock(Response.class);
508         given(response.readEntity(String.class)).willReturn(expectedResponseBody);
509         given(response.getStatus()).willReturn(HttpStatus.OK.value());
510
511         given(aaiRestInterface.RestGet(
512             eq("VidAaiController"),
513             anyString(),
514             eq(Unchecked.toURI("network/configurations/configuration/" + configurationId)),
515             eq(false)).getResponse()).willReturn(response);
516
517         mockMvc
518             .perform(
519                 get("/aai_get_configuration/{configuration_id}", configurationId)
520                     .contentType(MediaType.APPLICATION_JSON)
521                     .accept(MediaType.APPLICATION_JSON))
522             .andExpect(status().isOk())
523             .andExpect(content().string(expectedResponseBody));
524     }
525
526     @Test
527     public void getServiceInstanceAssociatedPnfs_shouldReturnPnfs() throws Exception {
528         String globalCustomerId = "testCustomerId";
529         String serviceType = "testServiceType";
530         String serviceInstanceId = "testServiceInstanceId";
531         List<String> expectedPnfs = ImmutableList.of("pnf1", "pnf2", "pnf3");
532
533         given(aaiService.getServiceInstanceAssociatedPnfs(globalCustomerId, serviceType, serviceInstanceId))
534             .willReturn(expectedPnfs);
535
536         mockMvc
537             .perform(
538                 get("/aai_get_service_instance_pnfs/{globalCustomerId}/{serviceType}/{serviceInstanceId}",
539                     globalCustomerId, serviceType, serviceInstanceId)
540                     .contentType(MediaType.APPLICATION_JSON)
541                     .accept(MediaType.APPLICATION_JSON))
542             .andExpect(status().isOk())
543             .andExpect(content().json(objectMapper.writeValueAsString(expectedPnfs)));
544     }
545
546     @Test
547     public void getUserID_shouldReturnOKResponse_withExtractedUserId() throws Exception {
548         String userPropertyKey = "user";
549         String expectedUserLoginId = "testUserLoginId";
550         User user = new User();
551         user.setLoginId(expectedUserLoginId);
552         given(systemPropertiesWrapper.getProperty(SystemProperties.USER_ATTRIBUTE_NAME)).willReturn(userPropertyKey);
553
554         mockMvc.perform(get("/getuserID")
555             .contentType(MediaType.APPLICATION_JSON)
556             .accept(MediaType.APPLICATION_JSON)
557             .sessionAttr(userPropertyKey, user))
558             .andExpect(status().isOk())
559             .andExpect(content().string(expectedUserLoginId));
560     }
561
562     @Test
563     public void getTargetProvStatus_shouldReturnProperty() throws Exception {
564         String expectedResponse = "targetProvStatus";
565         given(systemPropertiesWrapper.getProperty("aai.vnf.provstatus")).willReturn(expectedResponse);
566
567         mockMvc.perform(get("/get_system_prop_vnf_prov_status")
568             .contentType(MediaType.APPLICATION_JSON)
569             .accept(MediaType.APPLICATION_JSON))
570             .andExpect(status().isOk())
571             .andExpect(content().string(expectedResponse));
572     }
573
574     @Test
575     public void getOperationalEnvironments_shouldReturnOkResponse() throws Exception {
576         String operationalEnvironmentType = "testEnvType";
577         String operationalEnvironmentStatus = "testEnvStatus";
578         OperationalEnvironmentList operationalEnvironmentList = new OperationalEnvironmentList(
579             ImmutableList.of(OperationalEnvironment.builder()
580                 .withOperationalEnvironmentType(operationalEnvironmentType)
581                 .withOperationalEnvironmentStatus(operationalEnvironmentStatus)
582                 .build()));
583         AaiResponse<OperationalEnvironmentList> aaiResponse = new AaiResponse<>(operationalEnvironmentList, null,
584             HttpStatus.OK.value());
585         given(aaiService.getOperationalEnvironments(operationalEnvironmentType, operationalEnvironmentStatus))
586             .willReturn(aaiResponse);
587
588         mockMvc.perform(get("/get_operational_environments")
589             .contentType(MediaType.APPLICATION_JSON)
590             .accept(MediaType.APPLICATION_JSON)
591             .param("operationalEnvironmentType", operationalEnvironmentType)
592             .param("operationalEnvironmentStatus", operationalEnvironmentStatus))
593             .andExpect(status().isOk())
594             .andExpect(content().json(objectMapper.writeValueAsString(aaiResponse)));
595     }
596 }
597