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());
}
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));
}
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));
}
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));
}
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));
}
Aggregations