Search in sources :

Example 86 with Expression

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

the class TokenizerTest method testTokenizeBody.

public void testTokenizeBody() throws Exception {
    Expression exp = TokenizeLanguage.tokenize(",");
    exchange.getIn().setBody("Hadrian,Charles");
    List<?> names = exp.evaluate(exchange, List.class);
    assertEquals(2, names.size());
    assertEquals("Hadrian", names.get(0));
    assertEquals("Charles", names.get(1));
}
Also used : Expression(org.apache.camel.Expression)

Example 87 with Expression

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

the class TokenizerTest method testTokenizeXMLPairWithAttributesInheritNamespace.

public void testTokenizeXMLPairWithAttributesInheritNamespace() throws Exception {
    Expression exp = TokenizeLanguage.tokenizeXML("<person>", "<persons>");
    exchange.getIn().setBody("<persons 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)

Example 88 with Expression

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

the class TokenizerTest method testTokenizeXMLPairWithDefaultNamespace.

public void testTokenizeXMLPairWithDefaultNamespace() throws Exception {
    Expression exp = TokenizeLanguage.tokenizeXML("<person>", "<persons>");
    exchange.getIn().setBody("<?xml version=\"1.0\"?><persons xmlns=\"http:acme.com/persons\">\n<person>James</person>\n<person>Claus</person>\n" + "<person>Jonathan</person>\n<person>Hadrian</person>\n</persons>\n");
    List<?> names = exp.evaluate(exchange, List.class);
    assertEquals(4, names.size());
    assertEquals("<person xmlns=\"http:acme.com/persons\">James</person>", names.get(0));
    assertEquals("<person xmlns=\"http:acme.com/persons\">Claus</person>", names.get(1));
    assertEquals("<person xmlns=\"http:acme.com/persons\">Jonathan</person>", names.get(2));
    assertEquals("<person xmlns=\"http:acme.com/persons\">Hadrian</person>", names.get(3));
}
Also used : Expression(org.apache.camel.Expression)

Example 89 with Expression

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

the class TokenizerTest method testTokenizeXMLPairSimple.

public void testTokenizeXMLPairSimple() throws Exception {
    Expression exp = TokenizeLanguage.tokenizeXML("${header.foo}", null);
    exchange.getIn().setHeader("foo", "<person>");
    exchange.getIn().setBody("<persons><person>James</person><person>Claus</person><person>Jonathan</person><person>Hadrian</person></persons>");
    List<?> names = exp.evaluate(exchange, List.class);
    assertEquals(4, names.size());
    assertEquals("<person>James</person>", names.get(0));
    assertEquals("<person>Claus</person>", names.get(1));
    assertEquals("<person>Jonathan</person>", names.get(2));
    assertEquals("<person>Hadrian</person>", names.get(3));
}
Also used : Expression(org.apache.camel.Expression)

Example 90 with Expression

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

the class SimpleParserExpressionTest method testSimpleSingleQuoteDollarEnd.

public void testSimpleSingleQuoteDollarEnd() throws Exception {
    SimpleExpressionParser parser = new SimpleExpressionParser("Pay 200$", true);
    Expression exp = parser.parseExpression();
    assertEquals("Pay 200$", exp.evaluate(exchange, String.class));
}
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