Search in sources :

Example 36 with AlertFieldStatus

use of com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus in project hub-alert by blackducksoftware.

the class EmailGlobalConfigurationValidatorTest method verifyMissingAuthPassword.

@Test
void verifyMissingAuthPassword() {
    EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
    EmailGlobalConfigModel model = new EmailGlobalConfigModel();
    model.setName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
    model.setSmtpHost("host");
    model.setSmtpFrom("from");
    model.setSmtpAuth(true);
    model.setSmtpUsername("user");
    ValidationResponseModel validationResponseModel = validator.validate(model);
    Collection<AlertFieldStatus> alertFieldStatuses = validationResponseModel.getErrors().values();
    assertEquals(1, alertFieldStatuses.size(), "Validation found more or fewer errors than expected.");
    for (AlertFieldStatus status : alertFieldStatuses) {
        assertEquals("password", status.getFieldName(), "Validation reported an error for an unexpected field.");
        assertEquals(EmailGlobalConfigurationValidator.REQUIRED_BECAUSE_AUTH, status.getFieldMessage(), "Validation had unexpected field message.");
    }
}
Also used : EmailGlobalConfigModel(com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel) ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) Test(org.junit.jupiter.api.Test)

Example 37 with AlertFieldStatus

use of com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus in project hub-alert by blackducksoftware.

the class EmailGlobalConfigurationValidatorTest method verifyIsPasswordSet.

@Test
void verifyIsPasswordSet() {
    EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
    EmailGlobalConfigModel model = new EmailGlobalConfigModel();
    model.setName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
    model.setSmtpHost("host");
    model.setSmtpFrom("from");
    model.setSmtpAuth(true);
    model.setSmtpUsername("user");
    model.setIsSmtpPasswordSet(true);
    ValidationResponseModel validationResponseModel = validator.validate(model);
    Collection<AlertFieldStatus> alertFieldStatuses = validationResponseModel.getErrors().values();
    assertEquals(0, alertFieldStatuses.size(), "There were errors in the configuration when none were expected.");
}
Also used : EmailGlobalConfigModel(com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel) ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) Test(org.junit.jupiter.api.Test)

Example 38 with AlertFieldStatus

use of com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus in project hub-alert by blackducksoftware.

the class EmailGlobalConfigurationValidatorTest method verifyValidConfig.

/*
     * Email host: Required
     * Email from: Required
     *
     * Email user: Required if email auth is true
     * Email password: Required if email auth is true
     */
@Test
void verifyValidConfig() {
    EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
    EmailGlobalConfigModel model = new EmailGlobalConfigModel();
    model.setName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
    model.setSmtpHost("host");
    model.setSmtpFrom("from");
    model.setSmtpAuth(true);
    model.setSmtpUsername("user");
    model.setSmtpPassword("password");
    ValidationResponseModel validationResponseModel = validator.validate(model);
    Collection<AlertFieldStatus> alertFieldStatuses = validationResponseModel.getErrors().values();
    assertEquals(0, alertFieldStatuses.size(), "There were errors in the configuration when none were expected.");
}
Also used : EmailGlobalConfigModel(com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel) ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) Test(org.junit.jupiter.api.Test)

Example 39 with AlertFieldStatus

use of com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus in project hub-alert by blackducksoftware.

the class EmailGlobalConfigurationValidatorTest method verifyNameMissingConfig.

@Test
void verifyNameMissingConfig() {
    EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
    EmailGlobalConfigModel model = new EmailGlobalConfigModel();
    model.setSmtpHost("host");
    model.setSmtpFrom("from");
    model.setSmtpAuth(true);
    model.setSmtpUsername("user");
    model.setSmtpPassword("password");
    ValidationResponseModel validationResponseModel = validator.validate(model);
    Collection<AlertFieldStatus> alertFieldStatuses = validationResponseModel.getErrors().values();
    assertEquals(1, alertFieldStatuses.size(), "There were errors no errors when 1 for the name was expected.");
}
Also used : EmailGlobalConfigModel(com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel) ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) Test(org.junit.jupiter.api.Test)

Example 40 with AlertFieldStatus

use of com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus in project hub-alert by blackducksoftware.

the class VulnerabilityNotificationFilterCustomFunctionAction method validateRelatedFields.

@Override
protected Collection<AlertFieldStatus> validateRelatedFields(FieldModel fieldModel) {
    Optional<String> providerConfigId = fieldModel.getFieldValue(ProviderDescriptor.KEY_PROVIDER_CONFIG_ID);
    Optional<String> notificationTypes = fieldModel.getFieldValue(ProviderDescriptor.KEY_NOTIFICATION_TYPES);
    Set<AlertFieldStatus> errors = new HashSet<>();
    if (providerConfigId.isEmpty()) {
        AlertFieldStatus missingProviderConfig = AlertFieldStatus.error(BlackDuckDescriptor.KEY_BLACKDUCK_POLICY_NOTIFICATION_TYPE_FILTER, String.format("Missing %s", ProviderDescriptor.LABEL_PROVIDER_CONFIG_NAME));
        errors.add(missingProviderConfig);
    }
    if (notificationTypes.isEmpty()) {
        AlertFieldStatus missingNotificationTypes = AlertFieldStatus.error(BlackDuckDescriptor.KEY_BLACKDUCK_POLICY_NOTIFICATION_TYPE_FILTER, String.format("Missing %s", ProviderDescriptor.KEY_NOTIFICATION_TYPES));
        errors.add(missingNotificationTypes);
    }
    return errors;
}
Also used : AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) HashSet(java.util.HashSet)

Aggregations

AlertFieldStatus (com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus)50 ValidationResponseModel (com.synopsys.integration.alert.common.rest.model.ValidationResponseModel)23 Test (org.junit.jupiter.api.Test)23 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)11 ArrayList (java.util.ArrayList)11 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)10 FieldValueModel (com.synopsys.integration.alert.common.rest.model.FieldValueModel)9 HashSet (java.util.HashSet)9 Set (java.util.Set)9 Autowired (org.springframework.beans.factory.annotation.Autowired)9 Component (org.springframework.stereotype.Component)9 AlertFieldException (com.synopsys.integration.alert.common.exception.AlertFieldException)8 EmailGlobalConfigModel (com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel)8 IntegrationException (com.synopsys.integration.exception.IntegrationException)8 List (java.util.List)8 Optional (java.util.Optional)8 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)7 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)7 JobFieldModel (com.synopsys.integration.alert.common.rest.model.JobFieldModel)7 FieldModelTestAction (com.synopsys.integration.alert.common.action.FieldModelTestAction)6