2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 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.openecomp.sdc.itempermissions.impl;
23 import org.mockito.InjectMocks;
24 import org.mockito.Mock;
25 import org.mockito.MockitoAnnotations;
26 import org.mockito.Spy;
27 import org.openecomp.sdc.common.errors.CoreException;
28 import org.openecomp.sdc.itempermissions.dao.impl.PermissionsServicesImpl;
29 import org.testng.Assert;
30 import org.testng.annotations.BeforeMethod;
31 import org.testng.annotations.Test;
33 import java.util.HashSet;
37 * Created by ayalaben on 7/10/2017
39 public class PermissionsRulesImplTest {
41 private static final String ITEM1_ID = "1";
42 private static final String USER1_ID = "testUser1";
43 private static final String PERMISSION_OWNER = "Owner";
44 private static final String PERMISSION_CONTRIBUTOR = "Contributor";
45 private static final String INVALID_PERMISSION = "Invalid_Permission";
46 private static final String SUBMIT_ACTION = "Submit_Item";
47 private static final String EDIT_ACTION = "Edit_Item";
48 private static final String CHANGE_PERMISSIONS_ACTION = "Change_Item_Permissions";
49 private static final String INVALID_ACTION = "Invalid_Action";
52 private PermissionsServicesImpl permissionsServices;
56 private PermissionsRulesImpl permissionsRules;
60 public void setUp() throws Exception {
62 MockitoAnnotations.initMocks(this);
65 @Test(expectedExceptions = CoreException.class,expectedExceptionsMessageRegExp =
66 "Invalid permission type")
67 public void testIsAllowedWhenInvalidPermission() {
68 permissionsRules.isAllowed(INVALID_PERMISSION, EDIT_ACTION);
71 @Test(expectedExceptions = CoreException.class,expectedExceptionsMessageRegExp =
72 "Invalid action type")
73 public void testIsAllowedWhenInvalidAction() {
74 permissionsRules.isAllowed(PERMISSION_CONTRIBUTOR, INVALID_ACTION);
78 public void testIsAllowedCaseSubmitOwner(){
79 Assert.assertTrue(permissionsRules.isAllowed(PERMISSION_OWNER,SUBMIT_ACTION));
83 public void testIsAllowedCaseSubmitNotOwner(){
84 Assert.assertTrue(permissionsRules.isAllowed(PERMISSION_CONTRIBUTOR,SUBMIT_ACTION));
88 public void testIsAllowedCaseEditOwner(){
89 Assert.assertTrue(permissionsRules.isAllowed(PERMISSION_OWNER,EDIT_ACTION));
93 public void testIsAllowedCaseEditContributer(){
94 Assert.assertTrue(permissionsRules.isAllowed(PERMISSION_CONTRIBUTOR,EDIT_ACTION));
98 public void testIsAllowedCaseChangePermissionsContributer(){
99 Assert.assertFalse(permissionsRules.isAllowed(PERMISSION_CONTRIBUTOR,CHANGE_PERMISSIONS_ACTION));
103 public void testIsAllowedCaseChangePermissionsOwner(){
104 Assert.assertTrue(permissionsRules.isAllowed(PERMISSION_OWNER,CHANGE_PERMISSIONS_ACTION));
107 @Test(expectedExceptions = CoreException.class,expectedExceptionsMessageRegExp =
108 "Invalid permission type")
109 public void testUpdatePermissionWhenInvalidPermission() {
110 permissionsRules.updatePermission(ITEM1_ID,USER1_ID,INVALID_PERMISSION,new HashSet<String>(),
111 new HashSet<String>());
114 @Test(expectedExceptions = CoreException.class,expectedExceptionsMessageRegExp =
115 "Invalid action type")
116 public void testExecuteActionInvalidAction(){
117 permissionsRules.executeAction(ITEM1_ID,USER1_ID,INVALID_ACTION);