use of com.synopsys.integration.alert.api.common.model.ValidationResponseModel 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.api.common.model.ValidationResponseModel in project hub-alert by blackducksoftware.
the class EnvironmentVariableHandler method updateFromEnvironment.
public EnvironmentProcessingResult updateFromEnvironment() {
boolean configurationMissing = configurationMissingCheck();
if (configurationMissing) {
T configurationModel = configureModel();
ValidationResponseModel validationResponseModel = validateConfiguration(configurationModel);
if (validationResponseModel.hasErrors()) {
logger.error("Error inserting startup values: {}", validationResponseModel.getMessage());
for (AlertFieldStatus errorStatus : validationResponseModel.getErrors().values()) {
logger.error("Field: '{}' failed with the error: {}", errorStatus.getFieldName(), errorStatus.getFieldMessage());
}
return EnvironmentProcessingResult.empty();
}
EnvironmentProcessingResult processingResult = buildProcessingResult(configurationModel.obfuscate());
if (processingResult.hasValues()) {
saveConfiguration(configurationModel, processingResult);
}
return processingResult;
}
return EnvironmentProcessingResult.empty();
}
use of com.synopsys.integration.alert.api.common.model.ValidationResponseModel in project hub-alert by blackducksoftware.
the class JiraServerGlobalConfigurationValidatorTest method nameNotUniqueButUpdatingValidTest.
@Test
void nameNotUniqueButUpdatingValidTest() {
JiraServerGlobalConfigAccessor jiraServerGlobalConfigAccessor = Mockito.mock(JiraServerGlobalConfigAccessor.class);
JiraServerGlobalConfigModel existingModel = new JiraServerGlobalConfigModel(ID, NAME, CREATED_AT, LAST_UPDATED, URL, USER_NAME, PASSWORD, Boolean.FALSE, Boolean.FALSE);
Mockito.when(jiraServerGlobalConfigAccessor.getConfigurationByName(NAME)).thenReturn(Optional.of(existingModel));
JiraServerGlobalConfigurationValidator validator = new JiraServerGlobalConfigurationValidator(jiraServerGlobalConfigAccessor);
JiraServerGlobalConfigModel model = new JiraServerGlobalConfigModel(ID, NAME, CREATED_AT, LAST_UPDATED, URL, "new" + USER_NAME, PASSWORD, Boolean.FALSE, Boolean.FALSE);
ValidationResponseModel validationResponseModel = validator.validate(model, ID);
Collection<AlertFieldStatus> alertFieldStatuses = validationResponseModel.getErrors().values();
assertEquals(0, alertFieldStatuses.size(), "Did not expect to find any errors.");
}
use of com.synopsys.integration.alert.api.common.model.ValidationResponseModel in project hub-alert by blackducksoftware.
the class JiraServerGlobalConfigurationValidatorTest method verifyPasswordIsMissingAndNotSaved.
@Test
void verifyPasswordIsMissingAndNotSaved() {
JiraServerGlobalConfigAccessor jiraServerGlobalConfigAccessor = Mockito.mock(JiraServerGlobalConfigAccessor.class);
Mockito.when(jiraServerGlobalConfigAccessor.getConfigurationByName(Mockito.anyString())).thenReturn(Optional.empty());
JiraServerGlobalConfigurationValidator validator = new JiraServerGlobalConfigurationValidator(jiraServerGlobalConfigAccessor);
JiraServerGlobalConfigModel model = new JiraServerGlobalConfigModel(ID, NAME, URL, USER_NAME, null);
ValidationResponseModel validationResponseModel = validator.validate(model, null);
Collection<AlertFieldStatus> alertFieldStatuses = validationResponseModel.getErrors().values();
assertEquals(1, alertFieldStatuses.size(), "There were errors in the configuration when none were expected.");
for (AlertFieldStatus status : alertFieldStatuses) {
assertEquals("password", status.getFieldName(), "Validation reported an error for an unexpected field.");
}
}
use of com.synopsys.integration.alert.api.common.model.ValidationResponseModel in project hub-alert by blackducksoftware.
the class JobConfigActions method validateWithoutChecks.
@Override
protected ValidationActionResponse validateWithoutChecks(JobFieldModel resource) {
UUID jobId = null;
if (StringUtils.isNotBlank(resource.getJobId())) {
jobId = UUID.fromString(resource.getJobId());
}
List<AlertFieldStatus> fieldStatuses = new ArrayList<>();
validateJobNameUnique(jobId, resource).ifPresent(fieldStatuses::add);
List<AlertFieldStatus> descriptorValidationResults = validateDescriptorFields(resource);
fieldStatuses.addAll(descriptorValidationResults);
if (!fieldStatuses.isEmpty()) {
ValidationResponseModel responseModel = ValidationResponseModel.fromStatusCollection("Invalid Configuration", fieldStatuses);
return new ValidationActionResponse(HttpStatus.BAD_REQUEST, responseModel);
}
ValidationResponseModel responseModel = ValidationResponseModel.success("Valid");
return new ValidationActionResponse(HttpStatus.OK, responseModel);
}
Aggregations