Search in sources :

Example 1 with ValidationResult

use of com.redhat.service.smartevents.infra.validations.ValidationResult in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class KafkaTopicActionValidatorTest method isInvalid_noTopicIsNotValid.

@Test
void isInvalid_noTopicIsNotValid() {
    Action action = createActionWithTopic("myTopic");
    action.getParameters().remove(KafkaTopicAction.TOPIC_PARAM);
    ValidationResult validationResult = validator.isValid(action);
    assertThat(validationResult.isValid()).isFalse();
    assertThat(validationResult.getMessage()).isEqualTo("$.topic: is missing but it is required");
}
Also used : Action(com.redhat.service.smartevents.infra.models.gateways.Action) ValidationResult(com.redhat.service.smartevents.infra.validations.ValidationResult) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Example 2 with ValidationResult

use of com.redhat.service.smartevents.infra.validations.ValidationResult in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class KafkaTopicActionValidatorTest method isInvalid_nullParametersMapIsNotValid.

@Test
void isInvalid_nullParametersMapIsNotValid() {
    Action action = new Action();
    action.setType(KafkaTopicAction.TYPE);
    action.setMapParameters(new HashMap<>());
    ValidationResult validationResult = validator.isValid(action);
    assertThat(validationResult.isValid()).isFalse();
}
Also used : Action(com.redhat.service.smartevents.infra.models.gateways.Action) ValidationResult(com.redhat.service.smartevents.infra.validations.ValidationResult) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Example 3 with ValidationResult

use of com.redhat.service.smartevents.infra.validations.ValidationResult in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class BaseGatewayConstraintValidator method isValidGateway.

protected <T extends Gateway> boolean isValidGateway(T gateway, ConstraintValidatorContext context, Function<String, GatewayValidator<T>> validatorGetter) {
    if (gateway.getType() == null) {
        addConstraintViolation(context, GATEWAY_TYPE_MISSING_ERROR, Collections.singletonMap(GATEWAY_CLASS_PARAM, gateway.getClass().getSimpleName()));
        return false;
    }
    if (gateway.getParameters() == null) {
        addConstraintViolation(context, GATEWAY_PARAMETERS_MISSING_ERROR, Collections.singletonMap(GATEWAY_CLASS_PARAM, gateway.getClass().getSimpleName()));
        return false;
    }
    GatewayValidator<T> validator;
    try {
        validator = validatorGetter.apply(gateway.getType());
    } catch (GatewayProviderException e) {
        addConstraintViolation(context, GATEWAY_TYPE_NOT_RECOGNISED_ERROR, Map.of(GATEWAY_CLASS_PARAM, gateway.getClass().getSimpleName(), TYPE_PARAM, gateway.getType()));
        return false;
    }
    ValidationResult v = validator.isValid(gateway);
    if (!v.isValid()) {
        String message = v.getMessage();
        if (message == null) {
            addConstraintViolation(context, GATEWAY_PARAMETERS_NOT_VALID_ERROR, Map.of(GATEWAY_CLASS_PARAM, gateway.getClass().getSimpleName(), TYPE_PARAM, gateway.getType()));
        } else {
            addConstraintViolation(context, InterpolationHelper.escapeMessageParameter(message), Collections.emptyMap());
        }
    }
    return v.isValid();
}
Also used : GatewayProviderException(com.redhat.service.smartevents.infra.exceptions.definitions.user.GatewayProviderException) ValidationResult(com.redhat.service.smartevents.infra.validations.ValidationResult)

Example 4 with ValidationResult

use of com.redhat.service.smartevents.infra.validations.ValidationResult in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class TransformationEvaluatorFactoryQuteTest method validateTemplate.

@Test
public void validateTemplate() {
    TransformationEvaluatorFactoryQute factory = new TransformationEvaluatorFactoryQute();
    String template = "Hi {key} how are you?";
    ValidationResult result = factory.validate(template);
    assertThat(result).isNotNull();
    assertThat(result.isValid()).isTrue();
    assertThat(result.getMessage()).isNull();
}
Also used : ValidationResult(com.redhat.service.smartevents.infra.validations.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 5 with ValidationResult

use of com.redhat.service.smartevents.infra.validations.ValidationResult in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class SendToBridgeActionValidatorTest method assertIsValid.

private void assertIsValid(Action action) {
    ValidationResult validationResult = validator.isValid(action);
    assertThat(validationResult.isValid()).isTrue();
}
Also used : ValidationResult(com.redhat.service.smartevents.infra.validations.ValidationResult)

Aggregations

ValidationResult (com.redhat.service.smartevents.infra.validations.ValidationResult)17 Test (org.junit.jupiter.api.Test)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 MethodSource (org.junit.jupiter.params.provider.MethodSource)4 Action (com.redhat.service.smartevents.infra.models.gateways.Action)3 QuarkusTest (io.quarkus.test.junit.QuarkusTest)3 GatewayProviderException (com.redhat.service.smartevents.infra.exceptions.definitions.user.GatewayProviderException)1 HibernateConstraintValidatorContext (org.hibernate.validator.constraintvalidation.HibernateConstraintValidatorContext)1