aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/test/java/org/openecomp/sdc/itempermissions/impl/PermissionsRulesImplTest.java
blob: a70c91c1071992476075d27215b9233b3f33de49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*-
 * ============LICENSE_START=======================================================
 * SDC
 * ================================================================================
 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.openecomp.sdc.itempermissions.impl;

import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
import org.openecomp.sdc.common.errors.CoreException;
import org.openecomp.sdc.itempermissions.dao.impl.PermissionsServicesImpl;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import java.util.HashSet;


/**
 * Created by ayalaben on 7/10/2017
 */
public class PermissionsRulesImplTest {

  private static final String ITEM1_ID = "1";
  private static final String USER1_ID = "testUser1";
  private static final String PERMISSION_OWNER = "Owner";
  private static final String PERMISSION_CONTRIBUTOR = "Contributor";
  private static final String INVALID_PERMISSION = "Invalid_Permission";
  private static final String SUBMIT_ACTION = "Submit_Item";
  private static final String EDIT_ACTION = "Edit_Item";
  private static final String CHANGE_PERMISSIONS_ACTION = "Change_Item_Permissions";
  private static final String INVALID_ACTION = "Invalid_Action";

  @Mock
  private PermissionsServicesImpl permissionsServices;

  @InjectMocks
  @Spy
  private PermissionsRulesImpl permissionsRules;


  @BeforeMethod
  public void setUp() throws Exception {

    MockitoAnnotations.initMocks(this);
  }

  @Test(expectedExceptions = CoreException.class,expectedExceptionsMessageRegExp =
      "Invalid permission type")
  public void testIsAllowedWhenInvalidPermission() {
      permissionsRules.isAllowed(INVALID_PERMISSION, EDIT_ACTION);
    }

  @Test(expectedExceptions = CoreException.class,expectedExceptionsMessageRegExp =
      "Invalid action type")
  public void testIsAllowedWhenInvalidAction() {
    permissionsRules.isAllowed(PERMISSION_CONTRIBUTOR, INVALID_ACTION);
  }

  @Test
  public void testIsAllowedCaseSubmitOwner(){
    Assert.assertTrue(permissionsRules.isAllowed(PERMISSION_OWNER,SUBMIT_ACTION));
  }

  @Test
  public void testIsAllowedCaseSubmitNotOwner(){
    Assert.assertTrue(permissionsRules.isAllowed(PERMISSION_CONTRIBUTOR,SUBMIT_ACTION));
  }

  @Test
  public void testIsAllowedCaseEditOwner(){
    Assert.assertTrue(permissionsRules.isAllowed(PERMISSION_OWNER,EDIT_ACTION));
  }

  @Test
  public void testIsAllowedCaseEditContributer(){
    Assert.assertTrue(permissionsRules.isAllowed(PERMISSION_CONTRIBUTOR,EDIT_ACTION));
  }

  @Test
  public void testIsAllowedCaseChangePermissionsContributer(){
    Assert.assertFalse(permissionsRules.isAllowed(PERMISSION_CONTRIBUTOR,CHANGE_PERMISSIONS_ACTION));
  }

  @Test
  public void testIsAllowedCaseChangePermissionsOwner(){
    Assert.assertTrue(permissionsRules.isAllowed(PERMISSION_OWNER,CHANGE_PERMISSIONS_ACTION));
  }

  @Test(expectedExceptions = CoreException.class,expectedExceptionsMessageRegExp =
      "Invalid permission type")
  public void testUpdatePermissionWhenInvalidPermission()  {
    permissionsRules.updatePermission(ITEM1_ID,USER1_ID,INVALID_PERMISSION,new HashSet<String>(),
        new HashSet<String>());
  }

  @Test(expectedExceptions = CoreException.class,expectedExceptionsMessageRegExp =
      "Invalid action type")
  public void testExecuteActionInvalidAction(){
    permissionsRules.executeAction(ITEM1_ID,USER1_ID,INVALID_ACTION);
  }


}