use of com.synopsys.integration.alert.common.persistence.model.UserRoleModel in project hub-alert by blackducksoftware.
the class RoleActionsTest method deleteErrorTest.
@Test
public void deleteErrorTest() throws Exception {
PermissionModel permissionModel = createPermissionModel();
UserRoleModel userRoleModel = new UserRoleModel(1L, roleName, false, PermissionModelUtil.convertToPermissionMatrixModel(Set.of(permissionModel)));
Mockito.when(roleAccessor.getRoles(Mockito.anyCollection())).thenReturn(Set.of(userRoleModel));
Mockito.doThrow(new AlertForbiddenOperationException("Exception for test")).when(authorizationManager).deleteRole(Mockito.anyLong());
RoleActions roleActions = new RoleActions(userManagementDescriptorKey, roleAccessor, authorizationManager, descriptorMap);
ActionResponse<RolePermissionModel> rolePermissionModelActionResponse = roleActions.delete(1L);
assertTrue(rolePermissionModelActionResponse.isError());
assertFalse(rolePermissionModelActionResponse.hasContent());
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, rolePermissionModelActionResponse.getHttpStatus());
}
use of com.synopsys.integration.alert.common.persistence.model.UserRoleModel in project hub-alert by blackducksoftware.
the class RoleActionsTest method updateErrorTest.
@Test
public void updateErrorTest() throws Exception {
String newRoleName = "newRoleName";
Long longId = 1L;
PermissionModel permissionModel = createPermissionModel();
RolePermissionModel rolePermissionModel = new RolePermissionModel(null, newRoleName, Set.of(permissionModel));
UserRoleModel userRoleModel = new UserRoleModel(longId, roleName, false, PermissionModelUtil.convertToPermissionMatrixModel(Set.of(permissionModel)));
Mockito.when(roleAccessor.getRoles(Mockito.anyCollection())).thenReturn(Set.of(userRoleModel));
Mockito.when(roleAccessor.getRoles()).thenReturn(Set.of());
Mockito.doThrow(new AlertConfigurationException("Exception for test")).when(authorizationManager).updatePermissionsForRole(Mockito.anyString(), Mockito.any());
RoleActions roleActions = new RoleActions(userManagementDescriptorKey, roleAccessor, authorizationManager, descriptorMap);
ActionResponse<RolePermissionModel> rolePermissionModelActionResponse = roleActions.update(1L, rolePermissionModel);
Mockito.verify(authorizationManager).updateRoleName(Mockito.eq(longId), Mockito.eq(newRoleName));
assertTrue(rolePermissionModelActionResponse.isError());
assertFalse(rolePermissionModelActionResponse.hasContent());
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, rolePermissionModelActionResponse.getHttpStatus());
}
use of com.synopsys.integration.alert.common.persistence.model.UserRoleModel in project hub-alert by blackducksoftware.
the class RoleActionsTest method createTest.
@Test
public void createTest() throws Exception {
PermissionModel permissionModel = createPermissionModel();
RolePermissionModel rolePermissionModel = new RolePermissionModel(null, roleName, Set.of(permissionModel));
UserRoleModel userRoleModel = new UserRoleModel(1L, roleName, false, PermissionModelUtil.convertToPermissionMatrixModel(Set.of(permissionModel)));
Mockito.when(roleAccessor.doesRoleNameExist(Mockito.anyString())).thenReturn(false);
Mockito.when(authorizationManager.createRoleWithPermissions(Mockito.eq(roleName), Mockito.any())).thenReturn(userRoleModel);
RoleActions roleActions = new RoleActions(userManagementDescriptorKey, roleAccessor, authorizationManager, descriptorMap);
ActionResponse<RolePermissionModel> rolePermissionModelActionResponse = roleActions.create(rolePermissionModel);
assertTrue(rolePermissionModelActionResponse.isSuccessful());
assertTrue(rolePermissionModelActionResponse.hasContent());
}
use of com.synopsys.integration.alert.common.persistence.model.UserRoleModel in project hub-alert by blackducksoftware.
the class RoleActionsTest method findExistingTest.
@Test
public void findExistingTest() {
PermissionModel permissionModel = createPermissionModel();
UserRoleModel userRoleModel = new UserRoleModel(1L, roleName, false, PermissionModelUtil.convertToPermissionMatrixModel(Set.of(permissionModel)));
Mockito.when(roleAccessor.getRoles(Mockito.anyCollection())).thenReturn(Set.of(userRoleModel));
RoleActions roleActions = new RoleActions(userManagementDescriptorKey, roleAccessor, authorizationManager, descriptorMap);
Optional<RolePermissionModel> rolePermissionModel = roleActions.findExisting(1L);
assertTrue(rolePermissionModel.isPresent());
}
use of com.synopsys.integration.alert.common.persistence.model.UserRoleModel in project hub-alert by blackducksoftware.
the class UserModelTest method testUserModelNullRoles.
@Test
public void testUserModelNullRoles() {
String expectedUserName = "expectedUser";
String expectedPassword = "expectedPassword";
String expectedEmail = "expectedEmail";
Set<String> roleNames = null;
Set<UserRoleModel> expectedRoles = null;
UserModel userModel = UserModel.newUser(expectedUserName, expectedPassword, expectedEmail, AuthenticationType.DATABASE, expectedRoles, true);
assertEquals(expectedUserName, userModel.getName());
assertEquals(expectedPassword, userModel.getPassword());
assertEquals(expectedEmail, userModel.getEmailAddress());
assertNull(userModel.getRoles());
assertFalse(userModel.hasRole(DefaultUserRole.ALERT_ADMIN.name()));
assertFalse(userModel.hasRole("UNKNOWN_ROLE"));
assertFalse(userModel.isExpired());
assertFalse(userModel.isLocked());
assertFalse(userModel.isPasswordExpired());
assertTrue(userModel.isEnabled());
assertFalse(userModel.isExternal());
}
Aggregations