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");
}
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();
}
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();
}
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();
}
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();
}
Aggregations