use of com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus in project hub-alert by blackducksoftware.
the class JiraServerGlobalConfigurationValidatorTest method verifyPasswordIsMissingAndNotSaved.
@Test
void verifyPasswordIsMissingAndNotSaved() {
JiraServerGlobalConfigurationValidator validator = new JiraServerGlobalConfigurationValidator();
JiraServerGlobalConfigModel model = new JiraServerGlobalConfigModel(ID, NAME, URL, USER_NAME, null);
ValidationResponseModel validationResponseModel = validator.validate(model);
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.common.descriptor.config.field.errors.AlertFieldStatus in project hub-alert by blackducksoftware.
the class MsTeamsDistributionConfigurationValidatorTest method testValidate.
@MethodSource("getFieldsAndExpectedErrors")
@ParameterizedTest()
public void testValidate(Map<String, FieldValueModel> fieldModelMap, Set<AlertFieldStatus> expectedValidationErrors) {
JobFieldModel testJobFieldModel = FieldModelUtils.createJobFieldModel(ValidationConstants.COMMON_CHANNEL_FIELDS, fieldModelMap);
CommonChannelDistributionValidator commonChannelDistributionValidator = new CommonChannelDistributionValidator();
MsTeamsDistributionConfigurationValidator msTeamsDistributionConfigurationValidator = new MsTeamsDistributionConfigurationValidator(commonChannelDistributionValidator);
Set<AlertFieldStatus> validationErrors = msTeamsDistributionConfigurationValidator.validate(testJobFieldModel);
Assertions.assertEquals(expectedValidationErrors, validationErrors);
}
use of com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus in project hub-alert by blackducksoftware.
the class AlertFieldExceptionTest method getFieldErrorsTest.
@Test
public void getFieldErrorsTest() {
final String key1 = "key1";
final String key2 = "key2";
AlertFieldStatus value1 = AlertFieldStatus.warning(key1, "value1");
AlertFieldStatus value2 = AlertFieldStatus.error(key2, "value2");
List<AlertFieldStatus> fieldErrors = new ArrayList<>();
fieldErrors.add(value1);
fieldErrors.add(value2);
AlertFieldException alertFieldException = new AlertFieldException(fieldErrors);
assertEquals(2, alertFieldException.getFieldErrors().size());
assertTrue(alertFieldException.getFieldErrors().contains(value1));
assertTrue(alertFieldException.getFieldErrors().contains(value2));
}
use of com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus in project hub-alert by blackducksoftware.
the class UserActions method validateWithoutChecks.
@Override
protected ValidationActionResponse validateWithoutChecks(UserConfig resource) {
ValidationResponseModel responseModel;
if (StringUtils.isNotBlank(resource.getId()) && !NumberUtils.isCreatable(resource.getId())) {
responseModel = ValidationResponseModel.generalError("Invalid resource id");
return new ValidationActionResponse(HttpStatus.BAD_REQUEST, responseModel);
}
List<AlertFieldStatus> fieldErrors = validateCreationRequiredFields(resource);
validateUserRole(resource).ifPresent(fieldErrors::add);
if (fieldErrors.isEmpty()) {
responseModel = ValidationResponseModel.success("The user is valid");
return new ValidationActionResponse(HttpStatus.OK, responseModel);
}
responseModel = ValidationResponseModel.fromStatusCollection("There were problems validating this user.", fieldErrors);
return new ValidationActionResponse(HttpStatus.BAD_REQUEST, responseModel);
}
use of com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus in project hub-alert by blackducksoftware.
the class ProxySettingsEnvironmentHandlerFactory method updateFunction.
private EnvironmentProcessingResult updateFunction() {
EnvironmentProcessingResult.Builder builder = new EnvironmentProcessingResult.Builder(PROXY_CONFIGURATION_KEYSET);
SettingsProxyModel configModel = new SettingsProxyModel();
configModel.setName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
configureProxySettings(configModel);
// TODO: Refactor and remove duplicate code after 6.10.0 model package refactor
ValidationResponseModel validationResponseModel = validator.validate(configModel);
if (validationResponseModel.hasErrors()) {
logger.error("Error inserting startup values: {}", validationResponseModel.getMessage());
Map<String, AlertFieldStatus> errors = validationResponseModel.getErrors();
for (Map.Entry<String, AlertFieldStatus> error : errors.entrySet()) {
AlertFieldStatus status = error.getValue();
logger.error("Field: '{}' failed with the error: {}", status.getFieldName(), status.getFieldMessage());
}
return EnvironmentProcessingResult.empty();
}
SettingsProxyModel obfuscatedModel = configModel.obfuscate();
obfuscatedModel.getProxyHost().ifPresent(value -> builder.addVariableValue(PROXY_HOST_KEY, value));
obfuscatedModel.getProxyPort().map(String::valueOf).ifPresent(value -> builder.addVariableValue(PROXY_PORT_KEY, value));
obfuscatedModel.getProxyUsername().ifPresent(value -> builder.addVariableValue(PROXY_USERNAME_KEY, value));
obfuscatedModel.getNonProxyHosts().map(String::valueOf).ifPresent(value -> builder.addVariableValue(PROXY_NON_PROXY_HOSTS_KEY, value));
if (Boolean.TRUE.equals(obfuscatedModel.getIsProxyPasswordSet())) {
builder.addVariableValue(PROXY_PASSWORD_KEY, AlertConstants.MASKED_VALUE);
}
EnvironmentProcessingResult result = builder.build();
if (result.hasValues()) {
try {
configAccessor.createConfiguration(configModel);
} catch (AlertConfigurationException ex) {
logger.error("Error creating the configuration: {}", ex.getMessage());
}
}
return result;
}
Aggregations