Package org.apache.camel

Examples of org.apache.camel.Predicate.matches()


    public void testSimpleExpressionPredicate() throws Exception {
        exchange.getIn().setBody("Hello");
        exchange.getIn().setHeader("number", "1234");
        SimplePredicateParser parser = new SimplePredicateParser("${in.header.number} regex '\\d{4}'");
        Predicate pre = parser.parsePredicate();
        assertTrue("Should match", pre.matches(exchange));
    }

}
View Full Code Here


        exchange.getIn().setHeader("foo", 123);

        SimplePredicateParser parser = new SimplePredicateParser("${header.high} == true and ${header.foo} == 123");
        Predicate pre = parser.parsePredicate();

        assertTrue("Should match", pre.matches(exchange));
    }

    public void testSimpleLogicalOr() throws Exception {
        exchange.getIn().setBody("Hello");
        exchange.getIn().setHeader("high", true);
View Full Code Here

        exchange.getIn().setHeader("foo", 123);

        SimplePredicateParser parser = new SimplePredicateParser("${header.high} == false or ${header.foo} == 123");
        Predicate pre = parser.parsePredicate();

        assertTrue("Should match", pre.matches(exchange));
    }

}
View Full Code Here

        exchange.getIn().setBody("12.34.5678");

        SimplePredicateParser parser = new SimplePredicateParser("${body} regex '^\\d{2}\\.\\d{2}\\.\\d{4}$'");
        Predicate pre = parser.parsePredicate();

        assertTrue(pre.matches(exchange));
       
        exchange.getIn().setBody("12.2a.22ab");
        assertFalse(pre.matches(exchange));
    }
View Full Code Here

        Predicate pre = parser.parsePredicate();

        assertTrue(pre.matches(exchange));
       
        exchange.getIn().setBody("12.2a.22ab");
        assertFalse(pre.matches(exchange));
    }

}
View Full Code Here

        return jndi;
    }

    public void testSimpleExpressionOrPredicate() throws Exception {
        Predicate predicate = SimpleLanguage.predicate("${header.bar} == 123");
        assertTrue(predicate.matches(exchange));

        predicate = SimpleLanguage.predicate("${header.bar} == 124");
        assertFalse(predicate.matches(exchange));

        Expression expression = SimpleLanguage.expression("${body}");
View Full Code Here

    public void testSimpleExpressionOrPredicate() throws Exception {
        Predicate predicate = SimpleLanguage.predicate("${header.bar} == 123");
        assertTrue(predicate.matches(exchange));

        predicate = SimpleLanguage.predicate("${header.bar} == 124");
        assertFalse(predicate.matches(exchange));

        Expression expression = SimpleLanguage.expression("${body}");
        assertEquals("<hello id='m123'>world!</hello>", expression.evaluate(exchange, String.class));

        expression = SimpleLanguage.simple("${body}");
View Full Code Here

            boolean matches = false;
            try {
                // ensure we handle exceptions thrown when matching predicate
                if (predicate != null) {
                    matches = predicate.matches(exchange);
                }
            } catch (Throwable e) {
                exchange.setException(e);
                callback.done(true);
                return true;
View Full Code Here

                if (predicate == null) {
                    throw new IllegalArgumentException("Unsupported operator: " + operatorText + " for expression: " + expression);
                }

                boolean matches = predicate.matches(exchange);
                return exchange.getContext().getTypeConverter().convertTo(type, matches);
            }

            @Override
            public String toString() {
View Full Code Here

            boolean matches = false;
            try {
                // ensure we handle exceptions thrown when matching predicate
                if (predicate != null) {
                    matches = predicate.matches(exchange);
                }
            } catch (Throwable e) {
                exchange.setException(e);
                callback.done(true);
                return true;
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.