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