Search in sources :

Example 1 with ValidationResult

use of com.redhat.service.bridge.actions.ValidationResult in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class KafkaTopicActionValidatorTest method isValid_noTopicIsNotValid.

@Test
public void isValid_noTopicIsNotValid() {
    ProcessorDTO processor = createProcessorWithActionForTopic("myTopic");
    processor.getDefinition().getResolvedAction().getParameters().remove(KafkaTopicAction.TOPIC_PARAM);
    ValidationResult validationResult = validator.isValid(processor.getDefinition().getResolvedAction());
    assertThat(validationResult.isValid()).isFalse();
    assertThat(validationResult.getMessage()).isEqualTo(KafkaTopicActionValidator.INVALID_TOPIC_PARAM_MESSAGE);
}
Also used : ProcessorDTO(com.redhat.service.bridge.infra.models.dto.ProcessorDTO) ValidationResult(com.redhat.service.bridge.actions.ValidationResult) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Example 2 with ValidationResult

use of com.redhat.service.bridge.actions.ValidationResult in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class WebhookActionValidatorTest method assertIsValid.

private void assertIsValid(String endpoint) {
    BaseAction action = createActionWithEndpoint(endpoint);
    ValidationResult validationResult = validator.isValid(action);
    assertThat(validationResult.isValid()).isTrue();
}
Also used : BaseAction(com.redhat.service.bridge.infra.models.actions.BaseAction) ValidationResult(com.redhat.service.bridge.actions.ValidationResult)

Example 3 with ValidationResult

use of com.redhat.service.bridge.actions.ValidationResult in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class WebhookActionValidatorTest method assertIsInvalid.

private void assertIsInvalid(String endpoint, String errorMessage, Map<String, String> params) {
    BaseAction action = createActionWithEndpoint(endpoint);
    params.forEach((k, v) -> action.getParameters().put(k, v));
    ValidationResult validationResult = validator.isValid(action);
    assertThat(validationResult.isValid()).isFalse();
    assertThat(validationResult.getMessage()).startsWith(errorMessage);
}
Also used : BaseAction(com.redhat.service.bridge.infra.models.actions.BaseAction) ValidationResult(com.redhat.service.bridge.actions.ValidationResult)

Example 4 with ValidationResult

use of com.redhat.service.bridge.actions.ValidationResult in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class SlackActionValidatorTest method assertIsInvalid.

private void assertIsInvalid(BaseAction action, String errorMessage) {
    ValidationResult validationResult = validator.isValid(action);
    assertThat(validationResult.isValid()).isFalse();
    if (errorMessage == null) {
        assertThat(validationResult.getMessage()).isNull();
    } else {
        assertThat(validationResult.getMessage()).startsWith(errorMessage);
    }
}
Also used : ValidationResult(com.redhat.service.bridge.actions.ValidationResult)

Example 5 with ValidationResult

use of com.redhat.service.bridge.actions.ValidationResult in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ActionParamValidatorContainer method isValid.

@Override
public boolean isValid(ProcessorRequest value, ConstraintValidatorContext context) {
    /*
         * Centralised handling of Action parameters. The idea here being that for each Action we support, we
         * provide the ability to check:
         *
         * - The action 'type' is recognised
         * - The parameters supplied to configure the Action are valid.
         */
    BaseAction baseAction = value.getAction();
    if (baseAction == null) {
        return false;
    }
    if (baseAction.getParameters() == null) {
        return false;
    }
    ActionProvider actionProvider;
    try {
        actionProvider = actionProviderFactory.getActionProvider(baseAction.getType());
    } catch (ActionProviderException e) {
        context.disableDefaultConstraintViolation();
        HibernateConstraintValidatorContext hibernateContext = context.unwrap(HibernateConstraintValidatorContext.class);
        hibernateContext.addMessageParameter(TYPE_PARAM, baseAction.getType());
        hibernateContext.buildConstraintViolationWithTemplate(ACTION_TYPE_NOT_RECOGNISED_ERROR).addConstraintViolation();
        return false;
    }
    ValidationResult v = actionProvider.getParameterValidator().isValid(baseAction);
    if (!v.isValid()) {
        String message = v.getMessage();
        context.disableDefaultConstraintViolation();
        if (message == null) {
            message = ACTION_PARAMETERS_NOT_VALID_ERROR;
            HibernateConstraintValidatorContext hibernateContext = context.unwrap(HibernateConstraintValidatorContext.class);
            hibernateContext.addMessageParameter(TYPE_PARAM, baseAction.getType());
        } else {
            message = InterpolationHelper.escapeMessageParameter(message);
        }
        context.buildConstraintViolationWithTemplate(message).addConstraintViolation();
    }
    return v.isValid();
}
Also used : ActionProvider(com.redhat.service.bridge.actions.ActionProvider) ActionProviderException(com.redhat.service.bridge.infra.exceptions.definitions.user.ActionProviderException) HibernateConstraintValidatorContext(org.hibernate.validator.constraintvalidation.HibernateConstraintValidatorContext) BaseAction(com.redhat.service.bridge.infra.models.actions.BaseAction) ValidationResult(com.redhat.service.bridge.actions.ValidationResult)

Aggregations

ValidationResult (com.redhat.service.bridge.actions.ValidationResult)9 BaseAction (com.redhat.service.bridge.infra.models.actions.BaseAction)3 ProcessorDTO (com.redhat.service.bridge.infra.models.dto.ProcessorDTO)2 QuarkusTest (io.quarkus.test.junit.QuarkusTest)2 Test (org.junit.jupiter.api.Test)2 ActionProvider (com.redhat.service.bridge.actions.ActionProvider)1 ActionProviderException (com.redhat.service.bridge.infra.exceptions.definitions.user.ActionProviderException)1 HibernateConstraintValidatorContext (org.hibernate.validator.constraintvalidation.HibernateConstraintValidatorContext)1