Merge "create unit test for shouldShowUpgrade function"
[vid.git] / vid-app-common / src / test / java / org / onap / vid / roles / RoleValidatorFactoryTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
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
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
21 package org.onap.vid.roles;
22
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;
27
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;
40
41 public class RoleValidatorFactoryTest {
42
43     @InjectMocks
44     private RoleValidatorFactory roleValidatorFactory;
45
46     @Mock
47     private FeatureManager featureManager;
48
49     @BeforeClass
50     public void initMocks() {
51         MockitoAnnotations.initMocks(this);
52     }
53
54     @AfterMethod
55     public void reset() {
56         Mockito.reset(featureManager);
57     }
58
59     @Test (dataProvider = "presetRoleValidatorClass")
60     public void returnRoleValidatorByGivenClass_And_RoleManagementActivated_And_FeatureFlag(Class expectedClass,boolean isDisabledRoles, boolean flagActive ) {
61
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));
65     }
66
67     @DataProvider
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}
74         };
75     }
76
77 }