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