Search in sources :

Example 76 with Expression

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

the class TokenizerTest method testTokenizePairIncludeTokens.

public void testTokenizePairIncludeTokens() throws Exception {
    Expression exp = TokenizeLanguage.tokenizePair("[START]", "[END]", true);
    exchange.getIn().setBody("2011-11-11\n[START]James[END]\n[START]Claus[END]\n2 records");
    List<?> names = exp.evaluate(exchange, List.class);
    assertEquals(2, names.size());
    assertEquals("[START]James[END]", names.get(0));
    assertEquals("[START]Claus[END]", names.get(1));
}
Also used : Expression(org.apache.camel.Expression)

Example 77 with Expression

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

the class TokenizerTest method testTokenizeXMLPairWithLocalAndNotInheritedNamespace.

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

Example 78 with Expression

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

the class TokenizerTest method testTokenizeHeader.

public void testTokenizeHeader() throws Exception {
    Expression exp = TokenizeLanguage.tokenize("names", ",");
    List<?> names = exp.evaluate(exchange, List.class);
    assertEquals(3, names.size());
    assertEquals("Claus", names.get(0));
    assertEquals("James", names.get(1));
    assertEquals("Willem", names.get(2));
}
Also used : Expression(org.apache.camel.Expression)

Example 79 with Expression

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

the class TokenizerTest method testTokenizeXMLPairWithSimilarChildNames.

public void testTokenizeXMLPairWithSimilarChildNames() throws Exception {
    Expression exp = TokenizeLanguage.tokenizeXML("Trip", "Trips");
    exchange.getIn().setBody("<?xml version='1.0' encoding='UTF-8'?>\n<Trips>\n<Trip>\n<TripType>\n</TripType>\n</Trip>\n</Trips>");
    List<?> names = exp.evaluate(exchange, List.class);
    assertEquals(1, names.size());
}
Also used : Expression(org.apache.camel.Expression)

Example 80 with Expression

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

the class TokenizerTest method testTokenizeXMLPairWithDefaultNamespaceNotInherit.

public void testTokenizeXMLPairWithDefaultNamespaceNotInherit() throws Exception {
    Expression exp = TokenizeLanguage.tokenizeXML("<person>", null);
    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>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)

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