use of com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus in project hub-alert by blackducksoftware.
the class EmailGlobalConfigurationValidatorTest method verifyMissingAuth.
@Test
void verifyMissingAuth() {
EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
EmailGlobalConfigModel model = new EmailGlobalConfigModel();
model.setName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
model.setSmtpHost("host");
model.setSmtpFrom("from");
model.setSmtpAuth(true);
ValidationResponseModel validationResponseModel = validator.validate(model);
Collection<AlertFieldStatus> alertFieldStatuses = validationResponseModel.getErrors().values();
assertEquals(2, alertFieldStatuses.size(), "Validation found more or fewer errors than expected.");
for (AlertFieldStatus status : alertFieldStatuses) {
assertEquals(EmailGlobalConfigurationValidator.REQUIRED_BECAUSE_AUTH, status.getFieldMessage(), "Validation had unexpected field message.");
}
}
use of com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus in project hub-alert by blackducksoftware.
the class GlobalConfigurationValidatorAsserter method assertMissingValue.
public void assertMissingValue(String key) {
defaultKeyToValues.remove(key);
Set<AlertFieldStatus> alertFieldStatuses = runValidation();
assertEquals(1, alertFieldStatuses.size(), alertFieldStatuses.toString());
AlertFieldStatus alertFieldStatus = alertFieldStatuses.stream().findFirst().orElseThrow();
assertEquals(key, alertFieldStatus.getFieldName());
}
use of com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus in project hub-alert by blackducksoftware.
the class GlobalConfigurationValidatorAsserter method assertInvalidValue.
public void assertInvalidValue(String key, String invalidValue, Consumer<AlertFieldStatus> additionalAsserts) {
FieldValueModel apiKeyFieldValueModel = new FieldValueModel(List.of(invalidValue), true);
defaultKeyToValues.put(key, apiKeyFieldValueModel);
Set<AlertFieldStatus> alertFieldStatuses = runValidation();
assertEquals(1, alertFieldStatuses.size(), alertFieldStatuses.toString());
AlertFieldStatus alertFieldStatus = alertFieldStatuses.stream().findFirst().orElseThrow();
assertEquals(key, alertFieldStatus.getFieldName());
additionalAsserts.accept(alertFieldStatus);
}
use of com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus in project hub-alert by blackducksoftware.
the class AlertFieldStatusTest method getFieldErrorMessage.
@Test
public void getFieldErrorMessage() {
AlertFieldStatus alertFieldStatus = AlertFieldStatus.error(FIELD_NAME, FIELD_ERROR_MESSAGE);
assertEquals(FIELD_ERROR_MESSAGE, alertFieldStatus.getFieldMessage());
}
use of com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus in project hub-alert by blackducksoftware.
the class JobConfigActions method testProviderConfig.
private MessageResult testProviderConfig(FieldUtility fieldUtility, String jobId, FieldModel fieldModel) throws IntegrationException {
Optional<FieldModelTestAction> providerTestAction = fieldUtility.getString(ChannelDescriptor.KEY_PROVIDER_TYPE).flatMap(providerName -> descriptorProcessor.retrieveTestAction(providerName, ConfigContextEnum.DISTRIBUTION));
if (providerTestAction.isPresent()) {
MessageResult providerConfigTestResult = providerTestAction.get().testConfig(jobId, fieldModel, fieldUtility);
if (!providerConfigTestResult.hasErrors()) {
return providerConfigTestResult;
} else {
List<AlertFieldStatus> deescalatedErrors = providerConfigTestResult.fieldErrors().stream().map(fieldStatus -> AlertFieldStatus.warning(fieldStatus.getFieldName(), fieldStatus.getFieldMessage())).collect(Collectors.toList());
List<AlertFieldStatus> allWarnings = ListUtils.union(providerConfigTestResult.fieldWarnings(), deescalatedErrors);
return new MessageResult("Provider Config Invalid", allWarnings);
}
}
return new MessageResult("Provider Config Valid");
}
Aggregations