Search in sources :

Example 71 with Expression

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

the class BeanTest method testBeanInstanceAndMethodExpression.

public void testBeanInstanceAndMethodExpression() throws Exception {
    MyUser user = new MyUser();
    Expression exp = BeanLanguage.bean(user, "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 72 with Expression

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

the class BeanTest method testNoMethod.

public void testNoMethod() throws Exception {
    MyUser user = new MyUser();
    Expression exp = BeanLanguage.bean(user, "unknown");
    Exchange exchange = createExchangeWithBody("Claus");
    Object result = exp.evaluate(exchange, Object.class);
    assertNull(result);
    assertNotNull(exchange.getException());
    MethodNotFoundException e = assertIsInstanceOf(MethodNotFoundException.class, exchange.getException());
    assertSame(user, e.getBean());
    assertEquals("unknown", e.getMethodName());
}
Also used : Exchange(org.apache.camel.Exchange) Expression(org.apache.camel.Expression) MethodNotFoundException(org.apache.camel.component.bean.MethodNotFoundException)

Example 73 with Expression

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

the class SimpleTest method testBodyExpression.

public void testBodyExpression() throws Exception {
    Expression exp = SimpleLanguage.simple("${body}");
    assertNotNull(exp);
}
Also used : Expression(org.apache.camel.Expression)

Example 74 with Expression

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

the class SimpleTest method testListRemoveIndex.

public void testListRemoveIndex() 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(0)}");
    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 75 with Expression

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

the class TokenizerTest method testTokenizeXMLPairWithAttributes2InheritNamespace.

public void testTokenizeXMLPairWithAttributes2InheritNamespace() throws Exception {
    Expression exp = TokenizeLanguage.tokenizeXML("<person>", "<persons>");
    exchange.getIn().setBody("<persons riders=\"true\" xmlns=\"http:acme.com/persons\"><person id=\"1\">James</person><person id=\"2\">Claus</person>" + "<person id=\"3\">Jonathan</person><person id=\"4\">Hadrian</person></persons>");
    List<?> names = exp.evaluate(exchange, List.class);
    assertEquals(4, names.size());
    assertEquals("<person id=\"1\" xmlns=\"http:acme.com/persons\">James</person>", names.get(0));
    assertEquals("<person id=\"2\" xmlns=\"http:acme.com/persons\">Claus</person>", names.get(1));
    assertEquals("<person id=\"3\" xmlns=\"http:acme.com/persons\">Jonathan</person>", names.get(2));
    assertEquals("<person id=\"4\" xmlns=\"http:acme.com/persons\">Hadrian</person>", names.get(3));
}
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