Search in sources :

Example 61 with Predicate

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));
}
Also used : Predicate(org.apache.camel.Predicate)

Example 62 with Predicate

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));
}
Also used : Predicate(org.apache.camel.Predicate)

Example 63 with Predicate

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));
}
Also used : Predicate(org.apache.camel.Predicate)

Example 64 with Predicate

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));
}
Also used : HashMap(java.util.HashMap) Predicate(org.apache.camel.Predicate)

Example 65 with Predicate

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));
}
Also used : Predicate(org.apache.camel.Predicate)

Aggregations

Predicate (org.apache.camel.Predicate)124 Exchange (org.apache.camel.Exchange)70 Test (org.junit.Test)40 HashMap (java.util.HashMap)25 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)23 Expression (org.apache.camel.Expression)22 Processor (org.apache.camel.Processor)19 DefaultExchange (org.apache.camel.impl.DefaultExchange)10 RouteBuilder (org.apache.camel.builder.RouteBuilder)9 File (java.io.File)8 Matchers.containsString (org.hamcrest.Matchers.containsString)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 Map (java.util.Map)7 Ignore (org.junit.Ignore)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 AggregateProcessor (org.apache.camel.processor.aggregate.AggregateProcessor)6 AggregationStrategy (org.apache.camel.processor.aggregate.AggregationStrategy)6 PDDocument (org.apache.pdfbox.pdmodel.PDDocument)6 BodyInAggregatingStrategy (org.apache.camel.processor.BodyInAggregatingStrategy)5