use of org.apache.camel.model.validator.EndpointValidatorDefinition in project camel by apache.
the class ValidatorListCommandTest method doTest.
private String doTest(boolean verbose) throws Exception {
CamelContext context = new DefaultCamelContext();
EndpointValidatorDefinition evd = new EndpointValidatorDefinition();
evd.setType("xml:foo");
evd.setUri("direct:validator");
context.getValidators().add(evd);
PredicateValidatorDefinition pvd = new PredicateValidatorDefinition();
pvd.setType(this.getClass());
pvd.setExpression(new ExpressionDefinition(ExpressionBuilder.bodyExpression()));
context.getValidators().add(pvd);
CustomValidatorDefinition cvd = new CustomValidatorDefinition();
cvd.setType("custom");
cvd.setClassName(MyValidator.class.getName());
context.getValidators().add(cvd);
context.setNameStrategy(new ExplicitCamelContextNameStrategy("foobar"));
context.start();
CamelController controller = new DummyCamelController(context);
OutputStream os = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(os);
ValidatorListCommand command = new ValidatorListCommand(null, false, verbose, false);
command.execute(controller, ps, null);
String out = os.toString();
assertNotNull(out);
LOG.info("\n\n{}\n", out);
context.stop();
return out;
}
use of org.apache.camel.model.validator.EndpointValidatorDefinition in project camel by apache.
the class ValidatorBuilder method configure.
/**
* Configure a Validator according to the configurations built on this builder
* and register it into given {@code CamelContext}.
*
* @param camelContext {@code CamelContext}
*/
public void configure(CamelContext camelContext) {
ValidatorDefinition validator;
if (uri != null) {
EndpointValidatorDefinition etd = new EndpointValidatorDefinition();
etd.setUri(uri);
validator = etd;
} else if (expression != null) {
PredicateValidatorDefinition dtd = new PredicateValidatorDefinition();
dtd.setExpression(expression);
validator = dtd;
} else if (clazz != null) {
CustomValidatorDefinition ctd = new CustomValidatorDefinition();
ctd.setClassName(clazz.getName());
validator = ctd;
} else if (beanRef != null) {
CustomValidatorDefinition ctd = new CustomValidatorDefinition();
ctd.setRef(beanRef);
validator = ctd;
} else {
throw new IllegalArgumentException("No Validator type was specified");
}
validator.setType(type);
camelContext.getValidators().add(validator);
}
Aggregations