summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-item-permissions-lib
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-item-permissions-lib')
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/test/java/org/openecomp/sdc/itempermissions/impl/PermissionsRulesImplTest.java161
1 files changed, 78 insertions, 83 deletions
diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/test/java/org/openecomp/sdc/itempermissions/impl/PermissionsRulesImplTest.java b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/test/java/org/openecomp/sdc/itempermissions/impl/PermissionsRulesImplTest.java
index a70c91c107..57339012f4 100644
--- a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/test/java/org/openecomp/sdc/itempermissions/impl/PermissionsRulesImplTest.java
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/test/java/org/openecomp/sdc/itempermissions/impl/PermissionsRulesImplTest.java
@@ -7,9 +7,9 @@
* 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.
@@ -20,102 +20,97 @@
package org.openecomp.sdc.itempermissions.impl;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.HashSet;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
+import org.mockito.junit.jupiter.MockitoExtension;
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;
+@ExtendWith(MockitoExtension.class)
+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;
+
+ @Test
+ void testIsAllowedWhenInvalidPermission() {
+ Assertions.assertThrows(CoreException.class, () -> {
+ permissionsRules.isAllowed(INVALID_PERMISSION, EDIT_ACTION);
+ });
+ }
-/**
- * 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";
+ @Test
+ void testIsAllowedWhenInvalidAction() {
+ Assertions.assertThrows(CoreException.class, () -> {
+ permissionsRules.isAllowed(PERMISSION_CONTRIBUTOR, INVALID_ACTION);
+ });
+ }
- @Mock
- private PermissionsServicesImpl permissionsServices;
+ @Test
+ void testIsAllowedCaseSubmitOwner() {
+ assertTrue(permissionsRules.isAllowed(PERMISSION_OWNER, SUBMIT_ACTION));
+ }
- @InjectMocks
- @Spy
- private PermissionsRulesImpl permissionsRules;
+ @Test
+ void testIsAllowedCaseSubmitNotOwner() {
+ assertTrue(permissionsRules.isAllowed(PERMISSION_CONTRIBUTOR, SUBMIT_ACTION));
+ }
+ @Test
+ void testIsAllowedCaseEditOwner() {
+ assertTrue(permissionsRules.isAllowed(PERMISSION_OWNER, EDIT_ACTION));
+ }
- @BeforeMethod
- public void setUp() throws Exception {
+ @Test
+ void testIsAllowedCaseEditContributer() {
+ assertTrue(permissionsRules.isAllowed(PERMISSION_CONTRIBUTOR, EDIT_ACTION));
+ }
- MockitoAnnotations.initMocks(this);
- }
+ @Test
+ void testIsAllowedCaseChangePermissionsContributer() {
+ assertFalse(permissionsRules.isAllowed(PERMISSION_CONTRIBUTOR, CHANGE_PERMISSIONS_ACTION));
+ }
- @Test(expectedExceptions = CoreException.class,expectedExceptionsMessageRegExp =
- "Invalid permission type")
- public void testIsAllowedWhenInvalidPermission() {
- permissionsRules.isAllowed(INVALID_PERMISSION, EDIT_ACTION);
+ @Test
+ void testIsAllowedCaseChangePermissionsOwner() {
+ assertTrue(permissionsRules.isAllowed(PERMISSION_OWNER, CHANGE_PERMISSIONS_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);
- }
+ @Test
+ void testUpdatePermissionWhenInvalidPermission() {
+ final HashSet<String> stringHashSet = new HashSet<>();
+ Assertions.assertThrows(CoreException.class, () -> {
+ permissionsRules.updatePermission(ITEM1_ID, USER1_ID, INVALID_PERMISSION, stringHashSet, stringHashSet);
+ });
+ }
+ @Test
+ void testExecuteActionInvalidAction() {
+ Assertions.assertThrows(CoreException.class, () -> {
+ permissionsRules.executeAction(ITEM1_ID, USER1_ID, INVALID_ACTION);
+ });
+ }
}