Search in sources :

Example 81 with Expression

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

the class TokenizerTest method testTokenizeManualConfiguration.

public void testTokenizeManualConfiguration() throws Exception {
    TokenizeLanguage lan = new TokenizeLanguage();
    lan.setHeaderName("names");
    lan.setRegex(false);
    lan.setToken(",");
    Expression exp = lan.createExpression();
    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));
    assertEquals("names", lan.getHeaderName());
    assertEquals(",", lan.getToken());
    assertEquals(false, lan.isRegex());
    assertEquals(false, lan.isSingleton());
}
Also used : TokenizeLanguage(org.apache.camel.language.tokenizer.TokenizeLanguage) Expression(org.apache.camel.Expression)

Example 82 with Expression

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

the class TokenizerTest method testTokenizePairSimple.

public void testTokenizePairSimple() throws Exception {
    Expression exp = TokenizeLanguage.tokenizePair("${header.foo}", "${header.bar}", false);
    exchange.getIn().setHeader("foo", "[START]");
    exchange.getIn().setHeader("bar", "[END]");
    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("James", names.get(0));
    assertEquals("Claus", names.get(1));
}
Also used : Expression(org.apache.camel.Expression)

Example 83 with Expression

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

the class TokenizerTest method testTokenizeXMLPairWithDefaultAndFooNamespace.

public void testTokenizeXMLPairWithDefaultAndFooNamespace() throws Exception {
    Expression exp = TokenizeLanguage.tokenizeXML("<person>", "<persons>");
    exchange.getIn().setBody("<?xml version=\"1.0\"?><persons xmlns=\"http:acme.com/persons\" xmlns:foo=\"http:foo.com\">\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\" xmlns:foo=\"http:foo.com\">James</person>", names.get(0));
    assertEquals("<person xmlns=\"http:acme.com/persons\" xmlns:foo=\"http:foo.com\">Claus</person>", names.get(1));
    assertEquals("<person xmlns=\"http:acme.com/persons\" xmlns:foo=\"http:foo.com\">Jonathan</person>", names.get(2));
    assertEquals("<person xmlns=\"http:acme.com/persons\" xmlns:foo=\"http:foo.com\">Hadrian</person>", names.get(3));
}
Also used : Expression(org.apache.camel.Expression)

Example 84 with Expression

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

the class TokenizerTest method testTokenizeXMLPairWithLocalAndInheritedNamespace.

public void testTokenizeXMLPairWithLocalAndInheritedNamespace() throws Exception {
    Expression exp = TokenizeLanguage.tokenizeXML("<person>", "<persons>");
    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\" 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:bar=\"http:bar.com\" xmlns=\"http:acme.com/persons\">Hadrian</person>", names.get(3));
}
Also used : Expression(org.apache.camel.Expression)

Example 85 with Expression

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

the class TokenizerTest method testTokenizePairSpecial.

public void testTokenizePairSpecial() throws Exception {
    Expression exp = TokenizeLanguage.tokenizePair("!", "@", false);
    exchange.getIn().setBody("2011-11-11\n!James@!Claus@\n2 records");
    List<?> names = exp.evaluate(exchange, List.class);
    assertEquals(2, names.size());
    assertEquals("James", names.get(0));
    assertEquals("Claus", names.get(1));
}
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