Search in sources :

Example 11 with ValidationResult

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

the class TransformationTemplateConstraintValidator method isValid.

@Override
public boolean isValid(String transformationTemplate, ConstraintValidatorContext context) {
    if (transformationTemplate == null) {
        return true;
    }
    ValidationResult validationResult = transformationEvaluatorFactory.validate(transformationTemplate);
    if (validationResult.isValid()) {
        return true;
    }
    context.disableDefaultConstraintViolation();
    HibernateConstraintValidatorContext hibernateContext = context.unwrap(HibernateConstraintValidatorContext.class);
    hibernateContext.addMessageParameter(ERROR_PARAM, validationResult.getMessage());
    hibernateContext.buildConstraintViolationWithTemplate(TRANSFORMATION_TEMPLATE_MALFORMED_ERROR).addConstraintViolation();
    return false;
}
Also used : HibernateConstraintValidatorContext(org.hibernate.validator.constraintvalidation.HibernateConstraintValidatorContext) ValidationResult(com.redhat.service.smartevents.infra.validations.ValidationResult)

Example 12 with ValidationResult

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

the class TransformationEvaluatorFactoryQuteTest method validateInvalidTemplate.

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

Example 13 with ValidationResult

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

the class SendToBridgeActionValidatorTest method assertIsInvalid.

private void assertIsInvalid(Action 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.smartevents.infra.validations.ValidationResult)

Example 14 with ValidationResult

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

the class SlackActionValidatorTest 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)

Example 15 with ValidationResult

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

the class SlackActionValidatorTest method assertIsInvalid.

private void assertIsInvalid(Action 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.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