Search in sources :

Example 91 with Expression

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

the class SimpleParserExpressionTest method testSimpleParserEol.

public void testSimpleParserEol() throws Exception {
    SimpleExpressionParser parser = new SimpleExpressionParser("Hello", true);
    Expression exp = parser.parseExpression();
    assertEquals("Hello", exp.evaluate(exchange, String.class));
}
Also used : Expression(org.apache.camel.Expression)

Example 92 with Expression

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

the class SimpleParserExpressionTest method testThreeNestedFunctions.

public void testThreeNestedFunctions() throws Exception {
    exchange.getIn().setBody("123");
    exchange.getIn().setHeader("foo", "Int");
    exchange.getIn().setHeader("bar", "e");
    exchange.getIn().setHeader("baz", "ger");
    SimpleExpressionParser parser = new SimpleExpressionParser("${bodyAs(${header.foo}${header.bar}${header.baz})}", true);
    Expression exp = parser.parseExpression();
    Object obj = exp.evaluate(exchange, Object.class);
    assertNotNull(obj);
    Integer num = assertIsInstanceOf(Integer.class, obj);
    assertEquals(123, num.intValue());
}
Also used : Expression(org.apache.camel.Expression)

Example 93 with Expression

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

the class SimpleParserExpressionTest method testSimpleUnaryInc.

public void testSimpleUnaryInc() throws Exception {
    exchange.getIn().setBody("122");
    SimpleExpressionParser parser = new SimpleExpressionParser("${body}++", true);
    Expression exp = parser.parseExpression();
    assertEquals("123", exp.evaluate(exchange, String.class));
}
Also used : Expression(org.apache.camel.Expression)

Example 94 with Expression

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

the class SimpleParserExpressionTest method testHeaderNestedFunction.

public void testHeaderNestedFunction() throws Exception {
    exchange.getIn().setBody("foo");
    exchange.getIn().setHeader("foo", "abc");
    SimpleExpressionParser parser = new SimpleExpressionParser("${header.${body}}", true);
    Expression exp = parser.parseExpression();
    Object obj = exp.evaluate(exchange, Object.class);
    assertNotNull(obj);
    assertEquals("abc", obj);
}
Also used : Expression(org.apache.camel.Expression)

Example 95 with Expression

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

the class SimpleParserExpressionTest method testBodyAsNestedFunction.

public void testBodyAsNestedFunction() throws Exception {
    exchange.getIn().setBody("123");
    exchange.getIn().setHeader("foo", "Integer");
    SimpleExpressionParser parser = new SimpleExpressionParser("${bodyAs(${header.foo})}", true);
    Expression exp = parser.parseExpression();
    Object obj = exp.evaluate(exchange, Object.class);
    assertNotNull(obj);
    Integer num = assertIsInstanceOf(Integer.class, obj);
    assertEquals(123, num.intValue());
}
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