2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.vid.controller;
23 import static java.lang.Boolean.FALSE;
24 import static java.lang.Boolean.TRUE;
25 import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
26 import static org.hamcrest.MatcherAssert.assertThat;
27 import static org.hamcrest.Matchers.is;
28 import static org.mockito.ArgumentMatchers.any;
29 import static org.mockito.Mockito.mock;
30 import static org.mockito.Mockito.when;
32 import org.jetbrains.annotations.NotNull;
33 import org.onap.vid.aai.model.Permissions;
34 import org.onap.vid.roles.PermissionProperties;
35 import org.onap.vid.roles.RoleProvider;
36 import org.onap.vid.roles.RoleValidator;
37 import org.springframework.mock.web.MockHttpServletRequest;
38 import org.testng.annotations.DataProvider;
39 import org.testng.annotations.Test;
41 public class ServicePermissionsTest {
44 public static Object[][] trueAndFalse() {
45 return new Object[][]{{TRUE}, {FALSE}};
49 @Test(dataProvider = "trueAndFalse")
50 public void servicePermissions_responseMatchesMockedRoleValidator(boolean expected) {
51 String subscriberId = randomAlphanumeric(8);
52 String serviceType = randomAlphanumeric(8);
54 RoleProvider roleProvider = mock(RoleProvider.class);
55 RoleValidator roleValidator = mock(RoleValidator.class);
56 when(roleProvider.getUserRolesValidator(any())).thenReturn(roleValidator);
57 when(roleValidator.isServicePermitted(new PermissionProperties(subscriberId, serviceType))).thenReturn(expected);
59 AaiController2 aaiController2 = new AaiController2(null, roleProvider, null, null);
61 Permissions permissions = aaiController2.servicePermissions(unimportantRequest(), subscriberId, serviceType);
62 assertThat(permissions, is(new Permissions(expected)));
66 private MockHttpServletRequest unimportantRequest() {
67 return new MockHttpServletRequest("", "");