Search in sources :

Example 46 with AlertFieldStatus

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.");
    }
}
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 47 with AlertFieldStatus

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);
}
Also used : CommonChannelDistributionValidator(com.synopsys.integration.alert.api.channel.CommonChannelDistributionValidator) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) MethodSource(org.junit.jupiter.params.provider.MethodSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 48 with AlertFieldStatus

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));
}
Also used : ArrayList(java.util.ArrayList) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) Test(org.junit.jupiter.api.Test)

Example 49 with AlertFieldStatus

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);
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus)

Example 50 with AlertFieldStatus

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;
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) SettingsProxyModel(com.synopsys.integration.alert.common.rest.model.SettingsProxyModel) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) EnvironmentProcessingResult(com.synopsys.integration.alert.environment.EnvironmentProcessingResult) Map(java.util.Map) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)

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