use of com.synopsys.integration.alert.common.persistence.model.UserModel in project hub-alert by blackducksoftware.
the class UserActionsTest method testDeleteWithoutChecksException.
@Test
public void testDeleteWithoutChecksException() throws AlertForbiddenOperationException {
UserModel userModel = UserModel.existingUser(id, name, password, emailAddress, authenticationType, roles, true);
Mockito.when(userAccessor.getUser(id)).thenReturn(Optional.of(userModel));
Mockito.doThrow(new AlertForbiddenOperationException("Exception for test")).when(userAccessor).deleteUser(id);
UserActions userActions = new UserActions(userManagementDescriptorKey, userAccessor, roleAccessor, authorizationManager, authenticationTypeAccessor, userSystemValidator);
ActionResponse<UserConfig> userConfigActionResponse = userActions.deleteWithoutChecks(id);
assertFalse(userConfigActionResponse.hasContent());
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, userConfigActionResponse.getHttpStatus());
}
use of com.synopsys.integration.alert.common.persistence.model.UserModel in project hub-alert by blackducksoftware.
the class UserActionsTest method testFindExisting.
@Test
public void testFindExisting() {
UserModel userModel = UserModel.existingUser(id, name, password, emailAddress, authenticationType, roles, true);
Mockito.when(userAccessor.getUser(Mockito.anyLong())).thenReturn(Optional.of(userModel));
UserActions userActions = new UserActions(userManagementDescriptorKey, userAccessor, roleAccessor, authorizationManager, authenticationTypeAccessor, userSystemValidator);
Optional<UserConfig> userConfigOptional = userActions.findExisting(id);
assertTrue(userConfigOptional.isPresent());
UserConfig userConfig = userConfigOptional.get();
assertUserConfig(userConfig);
}
use of com.synopsys.integration.alert.common.persistence.model.UserModel in project hub-alert by blackducksoftware.
the class UserActionsTest method testUpdateWithoutChecksDatabaseError.
@Test
public void testUpdateWithoutChecksDatabaseError() throws Exception {
UserModel userModel = UserModel.existingUser(id, name, password, emailAddress, authenticationType, roles, true);
Mockito.when(userAccessor.getUser(id)).thenReturn(Optional.of(userModel));
Mockito.when(userAccessor.updateUser(Mockito.any(), Mockito.anyBoolean())).thenThrow(new AlertConfigurationException("Exception for test"));
Set<String> roleNames = roles.stream().map(UserRoleModel::getName).collect(Collectors.toSet());
UserConfig userConfig = new UserConfig(id.toString(), name, "newPassword", "newEmailAddress", roleNames, false, false, false, true, false, authenticationType.name(), false);
UserActions userActions = new UserActions(userManagementDescriptorKey, userAccessor, roleAccessor, authorizationManager, authenticationTypeAccessor, userSystemValidator);
ActionResponse<UserConfig> userConfigActionResponse = userActions.updateWithoutChecks(id, userConfig);
assertTrue(userConfigActionResponse.isError());
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, userConfigActionResponse.getHttpStatus());
}
use of com.synopsys.integration.alert.common.persistence.model.UserModel in project hub-alert by blackducksoftware.
the class UserActionsTest method testInternalUserNoEmailValidation.
@Test
public void testInternalUserNoEmailValidation() throws Exception {
UserModel userModel = UserModel.existingUser(id, name, password, null, authenticationType, roles, true);
Mockito.when(authorizationManager.hasExecutePermission(Mockito.any(ConfigContextEnum.class), Mockito.any(DescriptorKey.class))).thenReturn(true);
Mockito.when(userAccessor.getUser(Mockito.anyLong())).thenReturn(Optional.of(userModel));
Set<String> roleNames = roles.stream().map(UserRoleModel::getName).collect(Collectors.toSet());
UserConfig userConfig = new UserConfig(id.toString(), name, "newPassword", null, roleNames, false, false, false, true, false, authenticationType.name(), false);
UserActions userActions = new UserActions(userManagementDescriptorKey, userAccessor, roleAccessor, authorizationManager, authenticationTypeAccessor, userSystemValidator);
ValidationActionResponse validationActionResponse = userActions.validate(userConfig);
assertFalse(validationActionResponse.isError());
assertTrue(validationActionResponse.hasContent());
ValidationResponseModel validationResponseModel = validationActionResponse.getContent().get();
assertTrue(validationResponseModel.hasErrors());
assertTrue(validationResponseModel.getErrors().containsKey(UserActions.FIELD_KEY_USER_MGMT_EMAILADDRESS));
}
use of com.synopsys.integration.alert.common.persistence.model.UserModel in project hub-alert by blackducksoftware.
the class UserActionsTest method testCreateWithoutChecks.
@Test
public void testCreateWithoutChecks() throws Exception {
UserModel userModel = UserModel.existingUser(id, name, password, emailAddress, authenticationType, roles, true);
Mockito.when(userAccessor.addUser(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenReturn(userModel);
Mockito.when(userAccessor.getUser(Mockito.anyLong())).thenReturn(Optional.of(userModel));
Set<String> roleNames = roles.stream().map(UserRoleModel::getName).collect(Collectors.toSet());
UserConfig userConfig = new UserConfig(id.toString(), name, "newPassword", emailAddress, roleNames, false, false, false, true, false, authenticationType.name(), false);
UserActions userActions = new UserActions(userManagementDescriptorKey, userAccessor, roleAccessor, authorizationManager, authenticationTypeAccessor, userSystemValidator);
ActionResponse<UserConfig> userConfigActionResponse = userActions.createWithoutChecks(userConfig);
assertFalse(userConfigActionResponse.isError());
assertTrue(userConfigActionResponse.hasContent());
UserConfig testUserConfig = userConfigActionResponse.getContent().get();
assertUserConfig(testUserConfig);
assertEquals(HttpStatus.CREATED, userConfigActionResponse.getHttpStatus());
}
Aggregations