Search in sources :

Example 6 with AlertFieldStatus

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

the class AlertFieldStatusTest method getSeverityTest.

@Test
public void getSeverityTest() {
    AlertFieldStatus alertFieldStatusError = AlertFieldStatus.error(FIELD_NAME, FIELD_ERROR_MESSAGE);
    AlertFieldStatus alertFieldStatusWarning = AlertFieldStatus.warning(FIELD_NAME, FIELD_WARNING_MESSAGE);
    assertEquals(FieldStatusSeverity.ERROR, alertFieldStatusError.getSeverity());
    assertEquals(FieldStatusSeverity.WARNING, alertFieldStatusWarning.getSeverity());
}
Also used : AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) Test(org.junit.jupiter.api.Test)

Example 7 with AlertFieldStatus

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

the class ResponseBodyBuilder method putErrors.

public ResponseBodyBuilder putErrors(List<AlertFieldStatus> errors) {
    JsonObject element = new JsonObject();
    for (AlertFieldStatus alertFieldStatus : errors) {
        JsonObject statusObject = new JsonObject();
        statusObject.addProperty(PROPERTY_KEY_SEVERITY, alertFieldStatus.getSeverity().name());
        statusObject.addProperty(PROPERTY_KEY_FIELD_MESSAGE, alertFieldStatus.getFieldMessage());
        element.add(alertFieldStatus.getFieldName(), statusObject);
    }
    map.add(PROPERTY_KEY_ERRORS, element);
    return this;
}
Also used : JsonObject(com.google.gson.JsonObject) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus)

Example 8 with AlertFieldStatus

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

the class JiraServerDistributionConfigurationValidator method validate.

@Override
public Set<AlertFieldStatus> validate(JobFieldModel jobFieldModel) {
    HashSet<AlertFieldStatus> validationResults = new HashSet<>();
    ConfigurationFieldValidator configurationFieldValidator = ConfigurationFieldValidator.fromJobFieldModel(jobFieldModel);
    commonChannelDistributionValidator.validate(configurationFieldValidator);
    configurationFieldValidator.validateRequiredFieldsAreNotBlank(JiraServerDescriptor.KEY_JIRA_PROJECT_NAME, JiraServerDescriptor.KEY_ISSUE_TYPE);
    configurationFieldValidator.validateRequiredRelatedSet(JiraServerDescriptor.KEY_OPEN_WORKFLOW_TRANSITION, JiraServerDescriptor.LABEL_OPEN_WORKFLOW_TRANSITION, JiraServerDescriptor.KEY_RESOLVE_WORKFLOW_TRANSITION);
    // Validate custom field mappings
    jobFieldModel.getFieldModels().stream().filter(fieldModel -> jiraServerChannelKey.getUniversalKey().equals(fieldModel.getDescriptorName())).findFirst().flatMap(fieldModel -> fieldModel.getFieldValueModel(JiraServerDescriptor.KEY_FIELD_MAPPING)).flatMap(fieldValueModel -> jiraFieldMappingValidator.validateFieldMappings(JiraServerDescriptor.KEY_FIELD_MAPPING, fieldValueModel)).ifPresent(validationResults::add);
    validationResults.addAll(configurationFieldValidator.getValidationResults());
    return validationResults;
}
Also used : HashSet(java.util.HashSet) CommonChannelDistributionValidator(com.synopsys.integration.alert.api.channel.CommonChannelDistributionValidator) JiraServerDescriptor(com.synopsys.integration.alert.channel.jira.server.descriptor.JiraServerDescriptor) Component(org.springframework.stereotype.Component) JiraServerChannelKey(com.synopsys.integration.alert.descriptor.api.JiraServerChannelKey) JiraFieldMappingValidator(com.synopsys.integration.alert.api.channel.jira.validation.JiraFieldMappingValidator) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) DistributionConfigurationValidator(com.synopsys.integration.alert.common.descriptor.validator.DistributionConfigurationValidator) ConfigurationFieldValidator(com.synopsys.integration.alert.common.descriptor.validator.ConfigurationFieldValidator) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) ConfigurationFieldValidator(com.synopsys.integration.alert.common.descriptor.validator.ConfigurationFieldValidator) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) HashSet(java.util.HashSet)

Example 9 with AlertFieldStatus

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

the class JiraServerGlobalConfigurationValidatorTest method verifyPasswordIsSavedAndMissingFromModel.

@Test
void verifyPasswordIsSavedAndMissingFromModel() {
    JiraServerGlobalConfigurationValidator validator = new JiraServerGlobalConfigurationValidator();
    JiraServerGlobalConfigModel model = new JiraServerGlobalConfigModel(ID, NAME, CREATED_AT, LAST_UPDATED, URL, USER_NAME, null, Boolean.TRUE, Boolean.FALSE);
    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 : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) JiraServerGlobalConfigModel(com.synopsys.integration.alert.channel.jira.server.model.JiraServerGlobalConfigModel) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) Test(org.junit.jupiter.api.Test)

Example 10 with AlertFieldStatus

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

the class JiraServerGlobalConfigurationValidatorTest method verifyEmptyConfig.

@Test
void verifyEmptyConfig() {
    JiraServerGlobalConfigurationValidator validator = new JiraServerGlobalConfigurationValidator();
    JiraServerGlobalConfigModel model = new JiraServerGlobalConfigModel();
    ValidationResponseModel validationResponseModel = validator.validate(model);
    Collection<AlertFieldStatus> alertFieldStatuses = validationResponseModel.getErrors().values();
    assertEquals(4, alertFieldStatuses.size(), "There were errors in the configuration when none were expected.");
    for (AlertFieldStatus status : alertFieldStatuses) {
        assertEquals(ConfigurationFieldValidator.REQUIRED_FIELD_MISSING_MESSAGE, status.getFieldMessage(), "Validation had unexpected field message.");
    }
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) JiraServerGlobalConfigModel(com.synopsys.integration.alert.channel.jira.server.model.JiraServerGlobalConfigModel) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) Test(org.junit.jupiter.api.Test)

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