diff options
author | 2017-09-25 16:07:54 -0400 | |
---|---|---|
committer | 2017-09-25 16:09:15 -0400 | |
commit | 23634dba70b166ad3c79b5eadfbd32b5375d44be (patch) | |
tree | ab0ea364c8da4f91fb8c7e2819692498939fb419 /ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/UserRolesControllerTest.java | |
parent | 4ba6a0f20a190030700917a6065a6779ca9d308f (diff) |
MariaDB Connector and Sonar Scans; clean nl
PORTAL-50: Fix to get the Sonar coverage for ONAP
PORTAL-72: Sonar scan - resolving severity Blocker issues
PORTAL-86: Remove internal att.com usages from tests and other files
PORTAL-102: Fixed the page refresh issue on App Account Management page
PORTAL-103: Fix to enhanced notification ticket source for ONAP
PORTAL-104: Replaced mysql DB connector with mariaDB
Issue: PORTAL-50 PORTAL-72 PORTAL-86 PORTAL-102 PORTAL-103 PORTAL-104
Change-Id: Iae78ad34ed9ce5ae1f2d36fcbb93fbc1e39944e5
Signed-off-by: Christopher Lott (cl778h) <clott@research.att.com>
Diffstat (limited to 'ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/UserRolesControllerTest.java')
-rw-r--r-- | ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/UserRolesControllerTest.java | 178 |
1 files changed, 178 insertions, 0 deletions
diff --git a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/UserRolesControllerTest.java b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/UserRolesControllerTest.java index 1459caa4..4014f441 100644 --- a/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/UserRolesControllerTest.java +++ b/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/controller/UserRolesControllerTest.java @@ -30,29 +30,50 @@ import javax.servlet.http.HttpSession; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.openecomp.portalapp.portal.controller.UserRolesController; import org.openecomp.portalapp.portal.domain.EPUser; +import org.openecomp.portalapp.portal.domain.EcompAuditLog; +import org.openecomp.portalapp.portal.service.AdminRolesService; +import org.openecomp.portalapp.portal.service.SearchService; import org.openecomp.portalapp.portal.service.UserRolesService; import org.openecomp.portalapp.portal.test.core.MockEPUser; import org.openecomp.portalapp.portal.transport.AppWithRolesForUser; +import org.openecomp.portalapp.portal.transport.AppsListWithAdminRole; import org.openecomp.portalapp.portal.transport.FieldsValidator; import org.openecomp.portalapp.portal.transport.FieldsValidator.FieldName; import org.openecomp.portalapp.portal.transport.RoleInAppForUser; +import org.openecomp.portalapp.portal.utils.EPCommonSystemProperties; +import org.openecomp.portalapp.portal.utils.EcompPortalUtils; import org.openecomp.portalapp.test.framework.MockitoTestSuite; import org.openecomp.portalapp.util.EPUserUtils; +import org.openecomp.portalsdk.core.service.AuditService; import org.openecomp.portalsdk.core.service.DataAccessService; import org.openecomp.portalsdk.core.util.SystemProperties; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +@RunWith(PowerMockRunner.class) +@PrepareForTest({EcompPortalUtils.class, EPCommonSystemProperties.class, EcompAuditLog.class, SystemProperties.class}) public class UserRolesControllerTest extends MockitoTestSuite { String userid = "ab1234"; @Mock UserRolesService userRolesService; + + @Mock + SearchService searchService; + + @Mock + AuditService auditService; + + @Mock + AdminRolesService adminRolesService; @Mock FieldsValidator fieldsValidator; @@ -127,4 +148,161 @@ public class UserRolesControllerTest extends MockitoTestSuite { assertEquals(expectedFieldValidator.getFields(), actualFieldsValidator.getFields()); } + + @Test + public void getPhoneBookSearchResultBadPermissionsTest() { + String searchString = "test"; + String actualResult = null; + String expectedResult = null; + + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + Mockito.when(adminRolesService.isAccountAdmin(user)).thenReturn(false); + Mockito.when(searchService.searchUsersInPhoneBook(searchString)).thenReturn(actualResult); + + actualResult = userRolesController.getPhoneBookSearchResult(mockedRequest, searchString, mockedResponse); + assertEquals(expectedResult, actualResult); + + } + + @Test + public void getPhoneBookSearchResultValidationTest() { + String searchString = " t"; + String actualResult = null; + String expectedResult = null; + + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(adminRolesService.isAccountAdmin(user)).thenReturn(false); + Mockito.when(searchService.searchUsersInPhoneBook(searchString)).thenReturn(actualResult); + + actualResult = userRolesController.getPhoneBookSearchResult(mockedRequest, searchString, mockedResponse); + assertEquals(expectedResult, actualResult); + + } + + @Test + public void getPhoneBookSearchResultTest() { + String searchString = "test"; + String actualResult = null; + String expectedResult = null; + + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(adminRolesService.isAccountAdmin(user)).thenReturn(false); + Mockito.when(searchService.searchUsersInPhoneBook(searchString)).thenReturn(actualResult); + + actualResult = userRolesController.getPhoneBookSearchResult(mockedRequest, searchString, mockedResponse); + assertEquals(expectedResult, actualResult); + + } + + @Test + public void getAppsWithAdminRoleStateForUserTest(){ + + String orgUserId = "hb123f"; + AppsListWithAdminRole actualResult = new AppsListWithAdminRole(); + AppsListWithAdminRole expectedResult = new AppsListWithAdminRole(); + EPUser user = mockUser.mockEPUser(); + // PowerMockito.mockStatic(EcompPortalUtils.class); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(adminRolesService.getAppsWithAdminRoleStateForUser(orgUserId)).thenReturn(actualResult); + + actualResult = userRolesController.getAppsWithAdminRoleStateForUser(mockedRequest, orgUserId, mockedResponse); + assertEquals(expectedResult, actualResult); + } + + /*@Test + public void getAppsWithAdminRoleStateForUserBadRequestTest(){ + + String orgUserId = "hb123f"; + AppsListWithAdminRole actualResult = null; + AppsListWithAdminRole expectedResult = null; + EPUser user = mockUser.mockEPUser(); + PowerMockito.mockStatic(EcompPortalUtils.class); + PowerMockito.when(EcompPortalUtils.legitimateUserId(orgUserId)).thenReturn(false); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(adminRolesService.getAppsWithAdminRoleStateForUser(orgUserId)).thenReturn(actualResult); + + actualResult = userRolesController.getAppsWithAdminRoleStateForUser(mockedRequest, orgUserId, mockedResponse); + assertEquals(expectedResult, actualResult); + }*/ + + @Test + public void putAppsWithAdminRoleStateForUserBadStatusCodeTest(){ + FieldsValidator actualFieldsValidator = null; + AppsListWithAdminRole newAppsListWithAdminRoles = new AppsListWithAdminRole(); + FieldsValidator expectedFieldsValidator = new FieldsValidator(); + List<FieldName> fieldNames = new ArrayList<FieldName>(); + expectedFieldsValidator.setErrorCode(null); + expectedFieldsValidator.setFields(fieldNames); + expectedFieldsValidator.setHttpStatusCode((long)200); + + EPUser user = mockUser.mockEPUser(); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(false); + + actualFieldsValidator = userRolesController.putAppsWithAdminRoleStateForUser(mockedRequest, newAppsListWithAdminRoles, mockedResponse); + assertEquals(expectedFieldsValidator, actualFieldsValidator); + } + + + /*@Test + public void putAppsWithAdminRoleStateForUserTest() { + + FieldsValidator actualFieldsValidator = null; + AppsListWithAdminRole newAppsListWithAdminRoles = new AppsListWithAdminRole(); + EPUser user = mockUser.mockEPUser(); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(adminRolesService.isAccountAdmin(user)).thenReturn(false); + PowerMockito.mockStatic(EPCommonSystemProperties.class); + PowerMockito.mockStatic(EcompAuditLog.class); + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(SystemProperties.getProperty(EcompAuditLog.CD_ACTIVITY_UPDATE_ACCOUNT_ADMIN)).thenReturn("1400"); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP)).thenReturn("1400"); + Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP)).thenReturn("1400"); + Mockito.when(SystemProperties.getProperty(SystemProperties.MDC_TIMER)).thenReturn("1400"); + + actualFieldsValidator = userRolesController.putAppsWithAdminRoleStateForUser(mockedRequest, newAppsListWithAdminRoles, mockedResponse); + + System.out.println(actualFieldsValidator); + Mockito.when(searchService.searchUsersInPhoneBook(searchString)).thenReturn(actualResult); + + actualResult = userRolesController.getPhoneBookSearchResult(mockedRequest, searchString, mockedResponse); + assertEquals(expectedResult, actualResult); + + }*/ + + /*@Test + public void putAppsWithAdminRoleStateForUserTest(){ + FieldsValidator actualFieldsValidator = null; + AppsListWithAdminRole newAppsListWithAdminRoles = new AppsListWithAdminRole(); + FieldsValidator expectedFieldsValidator = new FieldsValidator(); + List<FieldName> fieldNames = new ArrayList<FieldName>(); + expectedFieldsValidator.setErrorCode(null); + expectedFieldsValidator.setFields(fieldNames); + expectedFieldsValidator.setHttpStatusCode((long)200); + + EPUser user = mockUser.mockEPUser(); + PowerMockito.mockStatic(EPCommonSystemProperties.class); + PowerMockito.mockStatic(EcompAuditLog.class); + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true); + Mockito.when(adminRolesService.setAppsWithAdminRoleStateForUser(newAppsListWithAdminRoles)); + Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user); + + // Mockito.call(auditService.logActivity(auditLog, null)); +// Mockito.when(SystemProperties.getProperty(EcompAuditLog.CD_ACTIVITY_UPDATE_ACCOUNT_ADMIN)).thenReturn("1400"); +// Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP)).thenReturn("1400"); +// Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP)).thenReturn("1400"); +// Mockito.when(SystemProperties.getProperty(SystemProperties.MDC_TIMER)).thenReturn("1400"); + + actualFieldsValidator = userRolesController.putAppsWithAdminRoleStateForUser(mockedRequest, newAppsListWithAdminRoles, mockedResponse); + assertEquals(expectedFieldsValidator, actualFieldsValidator); + }*/ } |