2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 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
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.roles;
23 import static java.util.Collections.emptyList;
24 import static org.hamcrest.MatcherAssert.assertThat;
25 import static org.hamcrest.Matchers.instanceOf;
26 import static org.mockito.Mockito.when;
28 import java.util.Collections;
29 import java.util.List;
30 import org.mockito.InjectMocks;
31 import org.mockito.Mock;
32 import org.mockito.Mockito;
33 import org.mockito.MockitoAnnotations;
34 import org.onap.vid.properties.Features;
35 import org.testng.annotations.AfterMethod;
36 import org.testng.annotations.BeforeClass;
37 import org.testng.annotations.DataProvider;
38 import org.testng.annotations.Test;
39 import org.togglz.core.manager.FeatureManager;
41 public class RoleValidatorFactoryTest {
44 private RoleValidatorFactory roleValidatorFactory;
47 private FeatureManager featureManager;
50 public void initMocks() {
51 MockitoAnnotations.initMocks(this);
56 Mockito.reset(featureManager);
59 @Test (dataProvider = "presetRoleValidatorClass")
60 public void returnRoleValidatorByGivenClass_And_RoleManagementActivated_And_FeatureFlag(Class expectedClass,boolean isDisabledRoles, boolean flagActive ) {
62 when(featureManager.isActive(Features.FLAG_2006_USER_PERMISSIONS_BY_OWNING_ENTITY)).thenReturn(flagActive);
63 RoleValidator roleValidator = roleValidatorFactory.by(emptyList(), isDisabledRoles);
64 assertThat(roleValidator, instanceOf(expectedClass));
68 public static Object[][] presetRoleValidatorClass() {
69 return new Object[][] {
70 {RoleValidatorsComposer.class, false, true},
71 {AlwaysValidRoleValidator.class, true, true},
72 {RoleValidatorBySubscriberAndServiceType.class, false, false},
73 {AlwaysValidRoleValidator.class, true, false}