use of org.apache.camel.Predicate in project camel by apache.
the class SimpleBackwardsCompatibleTest method testSimpleLogicalOr.
public void testSimpleLogicalOr() throws Exception {
exchange.getIn().setBody("Hello");
exchange.getIn().setHeader("high", true);
exchange.getIn().setHeader("foo", 123);
SimplePredicateParser parser = new SimplePredicateParser("${header.high} == false or ${header.foo} == 123", true);
Predicate pre = parser.parsePredicate();
assertTrue("Should match", pre.matches(exchange));
}
use of org.apache.camel.Predicate in project camel by apache.
the class SimpleParserPredicateTest method testSimpleEqNumeric.
public void testSimpleEqNumeric() throws Exception {
exchange.getIn().setBody(123);
SimplePredicateParser parser = new SimplePredicateParser("${body} == 123", true);
Predicate pre = parser.parsePredicate();
assertTrue("Should match", pre.matches(exchange));
}
use of org.apache.camel.Predicate in project camel by apache.
the class SimpleParserPredicateTest method testSimpleManyAndLogical.
public void testSimpleManyAndLogical() throws Exception {
exchange.getIn().setBody("Hello");
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 10; i++) {
exchange.getIn().setHeader("foo" + i, i);
sb.append("${header.foo").append(i).append("} == ").append(i);
if (i < 9) {
sb.append(" && ");
}
}
SimplePredicateParser parser = new SimplePredicateParser(sb.toString(), true);
Predicate pre = parser.parsePredicate();
assertTrue("Should match", pre.matches(exchange));
}
use of org.apache.camel.Predicate in project camel by apache.
the class SimpleParserPredicateTest method testSimpleMap.
public void testSimpleMap() throws Exception {
Map<String, String> map = new HashMap<String, String>();
map.put("foo", "123");
map.put("foo bar", "456");
exchange.getIn().setBody(map);
SimplePredicateParser parser = new SimplePredicateParser("${body[foo]} == 123", true);
Predicate pre = parser.parsePredicate();
assertTrue("Should match", pre.matches(exchange));
parser = new SimplePredicateParser("${body['foo bar']} == 456", true);
pre = parser.parsePredicate();
assertTrue("Should match", pre.matches(exchange));
// the predicate has whitespace in the function
parser = new SimplePredicateParser("${body[foo bar]} == 456", true);
pre = parser.parsePredicate();
assertTrue("Should match", pre.matches(exchange));
// no header with that name
parser = new SimplePredicateParser("${body[unknown]} == 456", true);
pre = parser.parsePredicate();
assertFalse("Should not match", pre.matches(exchange));
}
use of org.apache.camel.Predicate in project camel by apache.
the class SimpleParserPredicateTest method testSimpleInEmpty.
public void testSimpleInEmpty() throws Exception {
SimplePredicateParser parser = new SimplePredicateParser("${body} in ',,gold,silver'", true);
Predicate pre = parser.parsePredicate();
exchange.getIn().setBody("gold");
assertTrue("Should match gold", pre.matches(exchange));
exchange.getIn().setBody("silver");
assertTrue("Should match silver", pre.matches(exchange));
exchange.getIn().setBody("");
assertTrue("Should match empty", pre.matches(exchange));
exchange.getIn().setBody("bronze");
assertFalse("Should not match bronze", pre.matches(exchange));
}
Aggregations