Search in sources :

Example 66 with Expression

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

the class SimpleTest method testListRemoveByInstance.

public void testListRemoveByInstance() throws Exception {
    List<Object> data = new ArrayList<Object>();
    data.add("A");
    data.add("B");
    exchange.getIn().setBody(data);
    assertEquals(2, data.size());
    Expression expression = SimpleLanguage.simple("${body.remove('A')}");
    expression.evaluate(exchange, Object.class);
    assertEquals(1, data.size());
    assertEquals("B", data.get(0));
}
Also used : Expression(org.apache.camel.Expression) ArrayList(java.util.ArrayList)

Example 67 with Expression

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

the class ExpressionListComparator method compare.

public int compare(Exchange e1, Exchange e2) {
    for (Expression expression : expressions) {
        Object o1 = expression.evaluate(e1, Object.class);
        Object o2 = expression.evaluate(e2, Object.class);
        int answer = ObjectHelper.compare(o1, o2);
        if (answer != 0) {
            return answer;
        }
    }
    return 0;
}
Also used : Expression(org.apache.camel.Expression)

Example 68 with Expression

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

the class BeanTest method testBeanTypeAndMethodExpression.

public void testBeanTypeAndMethodExpression() throws Exception {
    Expression exp = BeanLanguage.bean(MyUser.class, "hello");
    Exchange exchange = createExchangeWithBody("Claus");
    Object result = exp.evaluate(exchange, Object.class);
    assertEquals("Hello Claus", result);
}
Also used : Exchange(org.apache.camel.Exchange) Expression(org.apache.camel.Expression)

Example 69 with Expression

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

the class BeanTest method testBeanTypeExpression.

public void testBeanTypeExpression() throws Exception {
    Expression exp = BeanLanguage.bean(MyUser.class, null);
    Exchange exchange = createExchangeWithBody("Claus");
    Object result = exp.evaluate(exchange, Object.class);
    assertEquals("Hello Claus", result);
}
Also used : Exchange(org.apache.camel.Exchange) Expression(org.apache.camel.Expression)

Example 70 with Expression

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

the class BeanTest method testNoMethodBeanLookup.

public void testNoMethodBeanLookup() throws Exception {
    Expression exp = BeanLanguage.bean("foo.cake");
    Exchange exchange = createExchangeWithBody("Claus");
    Object result = exp.evaluate(exchange, Object.class);
    assertNull(result);
    assertNotNull(exchange.getException());
    MethodNotFoundException e = assertIsInstanceOf(MethodNotFoundException.class, exchange.getException());
    assertSame(context.getRegistry().lookupByName("foo"), e.getBean());
    assertEquals("cake", e.getMethodName());
}
Also used : Exchange(org.apache.camel.Exchange) Expression(org.apache.camel.Expression) MethodNotFoundException(org.apache.camel.component.bean.MethodNotFoundException)

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