Search in sources :

Example 46 with Predicate

use of org.apache.camel.Predicate in project camel by apache.

the class ValueBuilder method in.

public Predicate in(Object... values) {
    List<Predicate> predicates = new ArrayList<Predicate>();
    for (Object value : values) {
        Expression right = asExpression(value);
        right = ExpressionBuilder.convertToExpression(right, expression);
        Predicate predicate = onNewPredicate(PredicateBuilder.isEqualTo(expression, right));
        predicates.add(predicate);
    }
    return in(predicates.toArray(new Predicate[predicates.size()]));
}
Also used : Expression(org.apache.camel.Expression) ArrayList(java.util.ArrayList) Predicate(org.apache.camel.Predicate)

Example 47 with Predicate

use of org.apache.camel.Predicate in project camel by apache.

the class PredicateBuilder method regex.

/**
     * Returns a predicate which is true if the expression matches the given
     * regular expression
     *
     * @param expression the expression to evaluate
     * @param pattern the regular expression to match against
     * @return a new predicate
     */
public static Predicate regex(final Expression expression, final Pattern pattern) {
    notNull(expression, "expression");
    notNull(pattern, "pattern");
    return new Predicate() {

        public boolean matches(Exchange exchange) {
            String value = expression.evaluate(exchange, String.class);
            if (value != null) {
                Matcher matcher = pattern.matcher(value);
                return matcher.matches();
            }
            return false;
        }

        @Override
        public String toString() {
            return expression + ".matches('" + pattern + "')";
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Matcher(java.util.regex.Matcher) Predicate(org.apache.camel.Predicate)

Example 48 with Predicate

use of org.apache.camel.Predicate in project camel by apache.

the class PredicateAssertHelperTest method testPredicateAssertHelper.

public void testPredicateAssertHelper() throws Exception {
    Exchange exchange = new DefaultExchange(context);
    Predicate notNull = PredicateBuilder.isNotNull(constant("foo"));
    PredicateAssertHelper.assertMatches(notNull, "foo is not null", exchange);
    PredicateAssertHelper.assertMatches(notNull, null, exchange);
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) Predicate(org.apache.camel.Predicate)

Example 49 with Predicate

use of org.apache.camel.Predicate in project camel by apache.

the class HipchatConsumerIntegrationTest method sendInOnly.

@Test
public void sendInOnly() throws Exception {
    result.expectedMessageCount(1);
    result.expectedMessagesMatches(new Predicate() {

        @Override
        public boolean matches(Exchange exchange) {
            StatusLine status = (StatusLine) exchange.getIn().getHeader(HipchatConstants.FROM_USER_RESPONSE_STATUS);
            return 200 == status.getStatusCode();
        }
    });
    assertMockEndpointsSatisfied();
}
Also used : Exchange(org.apache.camel.Exchange) StatusLine(org.apache.http.StatusLine) Predicate(org.apache.camel.Predicate) Test(org.junit.Test)

Example 50 with Predicate

use of org.apache.camel.Predicate in project camel by apache.

the class BacklogDebugger method addConditionalBreakpoint.

public void addConditionalBreakpoint(String nodeId, String language, String predicate) {
    Predicate condition = camelContext.resolveLanguage(language).createPredicate(predicate);
    NodeBreakpoint breakpoint = breakpoints.get(nodeId);
    if (breakpoint == null) {
        logger.log("Adding conditional breakpoint " + nodeId + " [" + predicate + "]");
        breakpoint = new NodeBreakpoint(nodeId, condition);
        breakpoints.put(nodeId, breakpoint);
        debugger.addBreakpoint(breakpoint, breakpoint);
    } else if (breakpoint.getCondition() == null) {
        logger.log("Updating to conditional breakpoint " + nodeId + " [" + predicate + "]");
        debugger.removeBreakpoint(breakpoint);
        breakpoints.put(nodeId, breakpoint);
        debugger.addBreakpoint(breakpoint, breakpoint);
    } else if (breakpoint.getCondition() != null) {
        logger.log("Updating conditional breakpoint " + nodeId + " [" + predicate + "]");
        breakpoint.setCondition(condition);
    }
}
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