Search in sources :

Example 56 with Expression

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

the class ExpressionBuilderTest method testTokenize.

public void testTokenize() throws Exception {
    Expression expression = tokenizeExpression(headerExpression("location"), ",");
    List<String> expected = new ArrayList<String>(Arrays.asList(new String[] { "Islington", "London", "UK" }));
    assertExpression(expression, exchange, expected);
    Predicate predicate = contains(tokenizeExpression(headerExpression("location"), ","), constantExpression("London"));
    assertPredicate(predicate, exchange, true);
    predicate = contains(tokenizeExpression(headerExpression("location"), ","), constantExpression("Manchester"));
    assertPredicate(predicate, exchange, false);
}
Also used : Expression(org.apache.camel.Expression) ArrayList(java.util.ArrayList) Predicate(org.apache.camel.Predicate)

Example 57 with Expression

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

the class ValueBuilderTest method testMatches.

public void testMatches() throws Exception {
    context.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").to("mock:result");
        }
    });
    context.start();
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.message(0).body().matches(new Expression() {

        public <T> T evaluate(Exchange exchange, Class<T> type) {
            String body = exchange.getIn().getBody(String.class);
            Boolean answer = body.contains("Camel");
            return type.cast(answer);
        }
    });
    template.sendBody("direct:start", "Camel rocks");
    mock.assertIsSatisfied();
    // send in a false test
    mock.reset();
    mock.message(0).body().matches(new Expression() {

        public <T> T evaluate(Exchange exchange, Class<T> type) {
            String body = exchange.getIn().getBody(String.class);
            Boolean answer = body.contains("Camel");
            return type.cast(answer);
        }
    });
    template.sendBody("direct:start", "Hello World");
    mock.assertIsNotSatisfied();
}
Also used : Exchange(org.apache.camel.Exchange) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Expression(org.apache.camel.Expression)

Example 58 with Expression

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

the class PredicateBinaryCoerceTypeTest method testGreatherThanOrEqual.

public void testGreatherThanOrEqual() throws Exception {
    // greather than
    Expression a = ExpressionBuilder.constantExpression("200");
    Expression b = ExpressionBuilder.constantExpression(Integer.valueOf("100"));
    assertMatches(PredicateBuilder.isGreaterThanOrEqualTo(a, b));
    assertDoesNotMatch(PredicateBuilder.isGreaterThanOrEqualTo(b, a));
    // reverse the types and try again
    a = ExpressionBuilder.constantExpression(Integer.valueOf("100"));
    b = ExpressionBuilder.constantExpression("200");
    assertDoesNotMatch(PredicateBuilder.isGreaterThanOrEqualTo(a, b));
    assertMatches(PredicateBuilder.isGreaterThanOrEqualTo(b, a));
    // equal
    a = ExpressionBuilder.constantExpression("100");
    b = ExpressionBuilder.constantExpression(Integer.valueOf("100"));
    assertMatches(PredicateBuilder.isGreaterThanOrEqualTo(a, b));
    assertMatches(PredicateBuilder.isGreaterThanOrEqualTo(b, a));
    // reverse the types and try again
    a = ExpressionBuilder.constantExpression(Integer.valueOf("100"));
    b = ExpressionBuilder.constantExpression("100");
    assertMatches(PredicateBuilder.isGreaterThanOrEqualTo(a, b));
    assertMatches(PredicateBuilder.isGreaterThanOrEqualTo(b, a));
}
Also used : Expression(org.apache.camel.Expression)

Example 59 with Expression

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

the class PredicateBinaryCoerceTypeTest method testEqual.

public void testEqual() throws Exception {
    Expression a = ExpressionBuilder.constantExpression("123");
    Expression b = ExpressionBuilder.constantExpression(Integer.valueOf("123"));
    assertMatches(PredicateBuilder.isEqualTo(a, b));
    // reverse the type and try again
    a = ExpressionBuilder.constantExpression(Integer.valueOf("123"));
    b = ExpressionBuilder.constantExpression("123");
    assertMatches(PredicateBuilder.isEqualTo(a, b));
}
Also used : Expression(org.apache.camel.Expression)

Example 60 with Expression

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

the class PredicateBinaryCoerceTypeTest method testIsNotNull.

public void testIsNotNull() throws Exception {
    Expression a = ExpressionBuilder.constantExpression("123");
    assertMatches(PredicateBuilder.isNotNull(a));
    a = ExpressionBuilder.constantExpression(null);
    assertDoesNotMatch(PredicateBuilder.isNotNull(a));
}
Also used : Expression(org.apache.camel.Expression)

Aggregations

Expression (org.apache.camel.Expression)184 Exchange (org.apache.camel.Exchange)44 Processor (org.apache.camel.Processor)24 Predicate (org.apache.camel.Predicate)22 DefaultExchange (org.apache.camel.impl.DefaultExchange)21 AggregationStrategy (org.apache.camel.processor.aggregate.AggregationStrategy)18 Language (org.apache.camel.spi.Language)16 ArrayList (java.util.ArrayList)15 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)15 AggregateProcessor (org.apache.camel.processor.aggregate.AggregateProcessor)15 BodyInAggregatingStrategy (org.apache.camel.processor.BodyInAggregatingStrategy)14 SendProcessor (org.apache.camel.processor.SendProcessor)14 Test (org.junit.Test)8 SimpleParserException (org.apache.camel.language.simple.types.SimpleParserException)7 File (java.io.File)4 ExecutorService (java.util.concurrent.ExecutorService)4 SimpleIllegalSyntaxException (org.apache.camel.language.simple.types.SimpleIllegalSyntaxException)4 HashMap (java.util.HashMap)3 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)3 CamelExchangeException (org.apache.camel.CamelExchangeException)3