Added oparent to sdc main
[sdc.git] / openecomp-be / lib / openecomp-item-permissions-lib / openecomp-item-permissions-impl / src / test / java / org / openecomp / sdc / itempermissions / impl / PermissionsRulesImplTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
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.openecomp.sdc.itempermissions.impl;
22
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;
32
33 import java.util.HashSet;
34
35
36 /**
37  * Created by ayalaben on 7/10/2017
38  */
39 public class PermissionsRulesImplTest {
40
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";
50
51   @Mock
52   private PermissionsServicesImpl permissionsServices;
53
54   @InjectMocks
55   @Spy
56   private PermissionsRulesImpl permissionsRules;
57
58
59   @BeforeMethod
60   public void setUp() throws Exception {
61
62     MockitoAnnotations.initMocks(this);
63   }
64
65   @Test(expectedExceptions = CoreException.class,expectedExceptionsMessageRegExp =
66       "Invalid permission type")
67   public void testIsAllowedWhenInvalidPermission() {
68       permissionsRules.isAllowed(INVALID_PERMISSION, EDIT_ACTION);
69     }
70
71   @Test(expectedExceptions = CoreException.class,expectedExceptionsMessageRegExp =
72       "Invalid action type")
73   public void testIsAllowedWhenInvalidAction() {
74     permissionsRules.isAllowed(PERMISSION_CONTRIBUTOR, INVALID_ACTION);
75   }
76
77   @Test
78   public void testIsAllowedCaseSubmitOwner(){
79     Assert.assertTrue(permissionsRules.isAllowed(PERMISSION_OWNER,SUBMIT_ACTION));
80   }
81
82   @Test
83   public void testIsAllowedCaseSubmitNotOwner(){
84     Assert.assertTrue(permissionsRules.isAllowed(PERMISSION_CONTRIBUTOR,SUBMIT_ACTION));
85   }
86
87   @Test
88   public void testIsAllowedCaseEditOwner(){
89     Assert.assertTrue(permissionsRules.isAllowed(PERMISSION_OWNER,EDIT_ACTION));
90   }
91
92   @Test
93   public void testIsAllowedCaseEditContributer(){
94     Assert.assertTrue(permissionsRules.isAllowed(PERMISSION_CONTRIBUTOR,EDIT_ACTION));
95   }
96
97   @Test
98   public void testIsAllowedCaseChangePermissionsContributer(){
99     Assert.assertFalse(permissionsRules.isAllowed(PERMISSION_CONTRIBUTOR,CHANGE_PERMISSIONS_ACTION));
100   }
101
102   @Test
103   public void testIsAllowedCaseChangePermissionsOwner(){
104     Assert.assertTrue(permissionsRules.isAllowed(PERMISSION_OWNER,CHANGE_PERMISSIONS_ACTION));
105   }
106
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>());
112   }
113
114   @Test(expectedExceptions = CoreException.class,expectedExceptionsMessageRegExp =
115       "Invalid action type")
116   public void testExecuteActionInvalidAction(){
117     permissionsRules.executeAction(ITEM1_ID,USER1_ID,INVALID_ACTION);
118   }
119
120
121 }