use of org.apache.camel.Predicate in project camel by apache.
the class BeanProcessorSpecializedMessageTest method testBeanSpecializedMessage.
public void testBeanSpecializedMessage() throws Exception {
MockEndpoint foo = getMockEndpoint("mock:foo");
foo.expectedBodiesReceived("Hello World");
foo.expectedHeaderReceived("foo", 123);
foo.message(0).predicate(new Predicate() {
public boolean matches(Exchange exchange) {
// this time we should have the specialized message
return exchange.getIn() instanceof MyMessage;
}
});
MockEndpoint result = getMockEndpoint("mock:result");
result.message(0).body().isNull();
result.expectedHeaderReceived("foo", 123);
result.message(0).predicate(new Predicate() {
public boolean matches(Exchange exchange) {
// this time we should have lost the specialized message
return !(exchange.getIn() instanceof MyMessage);
}
});
template.send("direct:start", new Processor() {
public void process(Exchange exchange) throws Exception {
MyMessage my = new MyMessage();
my.setBody("Hello World");
my.setHeader("foo", 123);
exchange.setIn(my);
}
});
assertMockEndpointsSatisfied();
}
use of org.apache.camel.Predicate in project camel by apache.
the class OnExceptionContinueTwoPredicateTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
// use a predicate instance
Predicate predicate = new Predicate() {
@Override
public boolean matches(Exchange exchange) {
predicateInvoked.incrementAndGet();
return true;
}
};
// tell Camel to handle and continue when this exception is thrown
onException(IllegalArgumentException.class).continued(predicate).process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
processorInvoked.incrementAndGet();
}
}).to("mock:me");
from("direct:start").to("mock:start").throwException(new IllegalArgumentException("Forced")).to("mock:middle").throwException(new IllegalArgumentException("Forced Again")).to("mock:result");
}
};
}
use of org.apache.camel.Predicate in project camel by apache.
the class CamelConverterTest method testToProcessorPredicate.
public void testToProcessorPredicate() throws Exception {
Predicate pred = PredicateBuilder.isEqualTo(headerExpression("foo"), constant("bar"));
Exchange exchange = new DefaultExchange(context);
exchange.getIn().setHeader("foo", "bar");
exchange.getIn().setBody("Hello World");
Processor pro = CamelConverter.toProcessor(pred);
pro.process(exchange);
assertEquals(true, exchange.getOut().getBody());
}
use of org.apache.camel.Predicate in project camel by apache.
the class SimpleParserRegexpPredicateTest method testSimpleRegexp.
public void testSimpleRegexp() throws Exception {
exchange.getIn().setBody("12.34.5678");
SimplePredicateParser parser = new SimplePredicateParser("${body} regex '^\\d{2}\\.\\d{2}\\.\\d{4}$'", true);
Predicate pre = parser.parsePredicate();
assertTrue(pre.matches(exchange));
exchange.getIn().setBody("12.2a.22ab");
assertFalse(pre.matches(exchange));
}
use of org.apache.camel.Predicate in project camel by apache.
the class SimpleBackwardsCompatibleTest method testSimpleLogicalAnd.
public void testSimpleLogicalAnd() throws Exception {
exchange.getIn().setBody("Hello");
exchange.getIn().setHeader("high", true);
exchange.getIn().setHeader("foo", 123);
SimplePredicateParser parser = new SimplePredicateParser("${header.high} == true and ${header.foo} == 123", true);
Predicate pre = parser.parsePredicate();
assertTrue("Should match", pre.matches(exchange));
}
Aggregations