use of org.apache.camel.Expression in project camel by apache.
the class BeanTest method testBeanInstanceAndMethodExpression.
public void testBeanInstanceAndMethodExpression() throws Exception {
MyUser user = new MyUser();
Expression exp = BeanLanguage.bean(user, "hello");
Exchange exchange = createExchangeWithBody("Claus");
Object result = exp.evaluate(exchange, Object.class);
assertEquals("Hello Claus", result);
}
use of org.apache.camel.Expression in project camel by apache.
the class BeanTest method testNoMethod.
public void testNoMethod() throws Exception {
MyUser user = new MyUser();
Expression exp = BeanLanguage.bean(user, "unknown");
Exchange exchange = createExchangeWithBody("Claus");
Object result = exp.evaluate(exchange, Object.class);
assertNull(result);
assertNotNull(exchange.getException());
MethodNotFoundException e = assertIsInstanceOf(MethodNotFoundException.class, exchange.getException());
assertSame(user, e.getBean());
assertEquals("unknown", e.getMethodName());
}
use of org.apache.camel.Expression in project camel by apache.
the class SimpleTest method testBodyExpression.
public void testBodyExpression() throws Exception {
Expression exp = SimpleLanguage.simple("${body}");
assertNotNull(exp);
}
use of org.apache.camel.Expression in project camel by apache.
the class SimpleTest method testListRemoveIndex.
public void testListRemoveIndex() throws Exception {
List<Object> data = new ArrayList<Object>();
data.add("A");
data.add("B");
exchange.getIn().setBody(data);
assertEquals(2, data.size());
Expression expression = SimpleLanguage.simple("${body.remove(0)}");
expression.evaluate(exchange, Object.class);
assertEquals(1, data.size());
assertEquals("B", data.get(0));
}
use of org.apache.camel.Expression in project camel by apache.
the class TokenizerTest method testTokenizeXMLPairWithAttributes2InheritNamespace.
public void testTokenizeXMLPairWithAttributes2InheritNamespace() throws Exception {
Expression exp = TokenizeLanguage.tokenizeXML("<person>", "<persons>");
exchange.getIn().setBody("<persons riders=\"true\" 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));
}
Aggregations