Test AaiController's get-tenants existing flow
[vid.git] / vid-app-common / src / test / java / org / onap / vid / controller / GetTenantsTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.vid.controller;
21
22 import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals;
23 import static org.assertj.core.util.Arrays.array;
24 import static org.assertj.core.util.Lists.list;
25 import static org.mockito.ArgumentMatchers.any;
26 import static org.mockito.Mockito.when;
27 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
28 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
29 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
30
31 import org.mockito.InjectMocks;
32 import org.mockito.Mock;
33 import org.onap.vid.aai.AaiResponse;
34 import org.onap.vid.aai.model.AaiGetTenatns.GetTenantsResponse;
35 import org.onap.vid.aai.util.AAIRestInterface;
36 import org.onap.vid.roles.RoleProvider;
37 import org.onap.vid.roles.RoleValidator;
38 import org.onap.vid.services.AaiService;
39 import org.onap.vid.testUtils.TestUtils;
40 import org.onap.vid.utils.SystemPropertiesWrapper;
41 import org.springframework.test.web.servlet.MockMvc;
42 import org.springframework.test.web.servlet.setup.MockMvcBuilders;
43 import org.testng.annotations.BeforeMethod;
44 import org.testng.annotations.Test;
45 import org.togglz.core.manager.FeatureManager;
46
47 public class GetTenantsTest {
48     @Mock private AaiService aaiService;
49     @Mock private AAIRestInterface aaiRestInterface;
50     @Mock private RoleProvider roleProvider;
51     @Mock private SystemPropertiesWrapper systemPropertiesWrapper;
52     @Mock private FeatureManager featureManager;
53     @Mock private RoleValidator roleValidator;
54
55     @InjectMocks
56     AaiController aaiController;
57
58     private MockMvc aaiControllerMvc;
59
60     private final GetTenantsResponse oneTenant =
61         TestUtils.setStringsInStringFields(new GetTenantsResponse());
62
63     @BeforeMethod
64     public void setUp() {
65         TestUtils.initMockitoMocks(this);
66         when(roleProvider.getUserRolesValidator(any())).thenReturn(roleValidator);
67         aaiControllerMvc = MockMvcBuilders.standaloneSetup(aaiController).build();
68     }
69
70     @Test
71     public void givenOneTenant_itIsReturned() throws Exception {
72         AaiResponse<GetTenantsResponse[]> aaiResponse =
73             new AaiResponse<>(array(oneTenant), null, 200);
74
75         when(aaiService.getTenants("global-customer-id", "service-type", roleValidator))
76             .thenReturn(aaiResponse);
77
78         aaiControllerMvc.perform(get("/aai_get_tenants/global-customer-id/service-type"))
79             .andExpect(status().isOk())
80             .andExpect(content().string(jsonEquals(list(oneTenant))));
81     }
82
83 }