diff options
author | vasraz <vasyl.razinkov@est.tech> | 2021-02-19 19:04:13 +0000 |
---|---|---|
committer | Christophe Closset <christophe.closset@intl.att.com> | 2021-02-20 07:46:00 +0000 |
commit | db65955fc93a81911ef66ab88b380dc1a5926dce (patch) | |
tree | dbc27f8b2b5cd72fbb825288dc0c4a4ade3d1ad9 /openecomp-be/lib | |
parent | d6992c860be02a4c88b8f49234d8ee7e117dd60a (diff) |
Fix BLOCKER BUGs reported by Sonar
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Change-Id: I00c466ac3fcbe8fab4629aed3a36bb2d8af3a970
Issue-ID: SDC-3472
Diffstat (limited to 'openecomp-be/lib')
4 files changed, 138 insertions, 130 deletions
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/test/java/org/openecomp/core/util/UniqueValueUtilTest.java b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/test/java/org/openecomp/core/util/UniqueValueUtilTest.java index eeae2f75b0..72ae4e7227 100644 --- a/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/test/java/org/openecomp/core/util/UniqueValueUtilTest.java +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-nosqldb-lib/openecomp-nosqldb-api/src/test/java/org/openecomp/core/util/UniqueValueUtilTest.java @@ -19,17 +19,20 @@ package org.openecomp.core.util; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.jupiter.MockitoExtension; import org.openecomp.core.dao.UniqueValueDao; import org.openecomp.core.dao.types.UniqueValueEntity; import org.openecomp.sdc.common.errors.CoreException; import org.testng.Assert; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; -public class UniqueValueUtilTest { +@ExtendWith(MockitoExtension.class) +class UniqueValueUtilTest { private static final String ENTITLEMENT_POOL_NAME = "Entitlement Pool name"; private static final String ORIGINAL_ENTITY_NAME = "originalEntityName"; @@ -39,30 +42,31 @@ public class UniqueValueUtilTest { private UniqueValueUtil uniqueValueUtil; - @BeforeMethod + @BeforeEach public void setUp() { - MockitoAnnotations.initMocks(this); uniqueValueUtil = new UniqueValueUtil(uniqueValueDao); } @Test - public void testCreateUniqueValue() { + void testCreateUniqueValue() { Mockito.when(uniqueValueDao.get(Mockito.any())).thenReturn(null); uniqueValueUtil.createUniqueValue(ENTITLEMENT_POOL_NAME, ORIGINAL_ENTITY_NAME); Mockito.verify(uniqueValueDao, Mockito.times(1)).create(Mockito.any()); } - @Test(expectedExceptions = CoreException.class) - public void testCreateUniqueValueNotUnique() { + @Test + void testCreateUniqueValueNotUnique() { Mockito.when(uniqueValueDao.get(Mockito.any())).thenReturn(new UniqueValueEntity()); - uniqueValueUtil.createUniqueValue(ENTITLEMENT_POOL_NAME, ORIGINAL_ENTITY_NAME); + Assertions.assertThrows(CoreException.class, () -> { + uniqueValueUtil.createUniqueValue(ENTITLEMENT_POOL_NAME, ORIGINAL_ENTITY_NAME); + }); - Mockito.verify(uniqueValueDao, Mockito.times(1)).create(Mockito.any()); + Mockito.verify(uniqueValueDao, Mockito.times(1)).get(Mockito.any()); } @Test - public void testDeleteUniqueValue() { + void testDeleteUniqueValue() { Mockito.doNothing().when(uniqueValueDao).delete(Mockito.any()); uniqueValueUtil.deleteUniqueValue(ENTITLEMENT_POOL_NAME, ORIGINAL_ENTITY_NAME); @@ -70,13 +74,13 @@ public class UniqueValueUtilTest { } @Test - public void testDeleteUniqueValueNoValue() { + void testDeleteUniqueValueNoValue() { uniqueValueUtil.deleteUniqueValue(ENTITLEMENT_POOL_NAME); Mockito.verify(uniqueValueDao, Mockito.times(0)).delete(Mockito.any()); } @Test - public void testUpdateUniqueValue() { + void testUpdateUniqueValue() { Mockito.when(uniqueValueDao.get(Mockito.any())).thenReturn(null); Mockito.doNothing().when(uniqueValueDao).delete(Mockito.any()); @@ -87,29 +91,31 @@ public class UniqueValueUtilTest { } @Test - public void testValidateUniqueValue() { + void testValidateUniqueValue() { Mockito.when(uniqueValueDao.get(Mockito.any())).thenReturn(null); uniqueValueUtil.validateUniqueValue(ENTITLEMENT_POOL_NAME, ORIGINAL_ENTITY_NAME); Mockito.verify(uniqueValueDao, Mockito.times(1)).get(Mockito.any()); } - @Test(expectedExceptions = CoreException.class) - public void testValidateUniqueValueNotUnique() { + @Test + void testValidateUniqueValueNotUnique() { Mockito.when(uniqueValueDao.get(Mockito.any())).thenReturn(new UniqueValueEntity()); - uniqueValueUtil.createUniqueValue(ENTITLEMENT_POOL_NAME, ORIGINAL_ENTITY_NAME); + Assertions.assertThrows(CoreException.class, () -> { + uniqueValueUtil.createUniqueValue(ENTITLEMENT_POOL_NAME, ORIGINAL_ENTITY_NAME); + }); Mockito.verify(uniqueValueDao, Mockito.times(1)).get(Mockito.any()); } @Test - public void testIsUniqueValueOccupied() { + void testIsUniqueValueOccupied() { Mockito.when(uniqueValueDao.get(Mockito.any())).thenReturn(new UniqueValueEntity()); Assert.assertTrue(uniqueValueUtil.isUniqueValueOccupied(ENTITLEMENT_POOL_NAME, ORIGINAL_ENTITY_NAME)); } @Test - public void testIsUniqueValueOccupiedFalse() { + void testIsUniqueValueOccupiedFalse() { Mockito.when(uniqueValueDao.get(Mockito.any())).thenReturn(null); Assert.assertFalse(uniqueValueUtil.isUniqueValueOccupied(ENTITLEMENT_POOL_NAME, ORIGINAL_ENTITY_NAME)); } diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/test/java/org/openecomp/sdc/common/session/impl/AsdcSessionContextProviderTest.java b/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/test/java/org/openecomp/sdc/common/session/impl/AsdcSessionContextProviderTest.java index f0a9d2dcf7..80b62c7409 100644 --- a/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/test/java/org/openecomp/sdc/common/session/impl/AsdcSessionContextProviderTest.java +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/test/java/org/openecomp/sdc/common/session/impl/AsdcSessionContextProviderTest.java @@ -19,45 +19,48 @@ package org.openecomp.sdc.common.session.impl; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertSame; + +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.MockitoAnnotations; +import org.mockito.junit.jupiter.MockitoExtension; import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.common.session.SessionContext; -import org.testng.Assert; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; -public class AsdcSessionContextProviderTest { +@ExtendWith(MockitoExtension.class) +class AsdcSessionContextProviderTest { private static final String USER_ID = "cs0008"; @InjectMocks private AsdcSessionContextProvider asdcSessionContextProvider; - @BeforeMethod - public void setUp() { - MockitoAnnotations.initMocks(this); - } - - @Test(expectedExceptions = CoreException.class) - public void testGetUserIdNull() { + @Test + void testGetUserIdNull() { asdcSessionContextProvider.create(null, null); - asdcSessionContextProvider.get(); + Assertions.assertThrows(CoreException.class, () -> { + asdcSessionContextProvider.get(); + }); } - @Test(expectedExceptions = CoreException.class) - public void testGetTenantNull() { + @Test + void testGetTenantNull() { asdcSessionContextProvider.create(USER_ID, null); - asdcSessionContextProvider.get(); + Assertions.assertThrows(CoreException.class, () -> { + asdcSessionContextProvider.get(); + }); } @Test - public void testGet() { + void testGet() { asdcSessionContextProvider.create(USER_ID, "tenant"); SessionContext sessionContext = asdcSessionContextProvider.get(); - Assert.assertNotNull(sessionContext); - Assert.assertSame(USER_ID, sessionContext.getUser().getUserId()); - Assert.assertSame("tenant", sessionContext.getTenant()); + assertNotNull(sessionContext); + assertSame(USER_ID, sessionContext.getUser().getUserId()); + assertSame("tenant", sessionContext.getTenant()); } } diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/test/java/org/openecomp/sdc/common/session/impl/SessionContextProviderFactoryImplTest.java b/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/test/java/org/openecomp/sdc/common/session/impl/SessionContextProviderFactoryImplTest.java index eec7bd02ad..74cf8d3446 100644 --- a/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/test/java/org/openecomp/sdc/common/session/impl/SessionContextProviderFactoryImplTest.java +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/test/java/org/openecomp/sdc/common/session/impl/SessionContextProviderFactoryImplTest.java @@ -19,27 +19,31 @@ package org.openecomp.sdc.common.session.impl; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.MockitoAnnotations; +import org.mockito.junit.jupiter.MockitoExtension; import org.openecomp.sdc.common.session.SessionContextProvider; -import org.testng.Assert; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; -public class SessionContextProviderFactoryImplTest { +@ExtendWith(MockitoExtension.class) +class SessionContextProviderFactoryImplTest { @InjectMocks private SessionContextProviderFactoryImpl sessionContextProviderFactoryImpl; - @BeforeMethod + @BeforeEach public void setUp() { MockitoAnnotations.initMocks(this); } @Test - public void testCreateInterface() { + void testCreateInterface() { SessionContextProvider sessionContextProvider = sessionContextProviderFactoryImpl.createInterface(); - Assert.assertTrue(sessionContextProvider instanceof AsdcSessionContextProvider); + assertTrue(sessionContextProvider instanceof AsdcSessionContextProvider); } } 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); + }); + } } |