use of org.apache.camel.Expression in project camel by apache.
the class ExpressionBuilderTest method testTokenize.
public void testTokenize() throws Exception {
Expression expression = tokenizeExpression(headerExpression("location"), ",");
List<String> expected = new ArrayList<String>(Arrays.asList(new String[] { "Islington", "London", "UK" }));
assertExpression(expression, exchange, expected);
Predicate predicate = contains(tokenizeExpression(headerExpression("location"), ","), constantExpression("London"));
assertPredicate(predicate, exchange, true);
predicate = contains(tokenizeExpression(headerExpression("location"), ","), constantExpression("Manchester"));
assertPredicate(predicate, exchange, false);
}
use of org.apache.camel.Expression in project camel by apache.
the class ValueBuilderTest method testMatches.
public void testMatches() throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").to("mock:result");
}
});
context.start();
MockEndpoint mock = getMockEndpoint("mock:result");
mock.message(0).body().matches(new Expression() {
public <T> T evaluate(Exchange exchange, Class<T> type) {
String body = exchange.getIn().getBody(String.class);
Boolean answer = body.contains("Camel");
return type.cast(answer);
}
});
template.sendBody("direct:start", "Camel rocks");
mock.assertIsSatisfied();
// send in a false test
mock.reset();
mock.message(0).body().matches(new Expression() {
public <T> T evaluate(Exchange exchange, Class<T> type) {
String body = exchange.getIn().getBody(String.class);
Boolean answer = body.contains("Camel");
return type.cast(answer);
}
});
template.sendBody("direct:start", "Hello World");
mock.assertIsNotSatisfied();
}
use of org.apache.camel.Expression in project camel by apache.
the class PredicateBinaryCoerceTypeTest method testGreatherThanOrEqual.
public void testGreatherThanOrEqual() throws Exception {
// greather than
Expression a = ExpressionBuilder.constantExpression("200");
Expression b = ExpressionBuilder.constantExpression(Integer.valueOf("100"));
assertMatches(PredicateBuilder.isGreaterThanOrEqualTo(a, b));
assertDoesNotMatch(PredicateBuilder.isGreaterThanOrEqualTo(b, a));
// reverse the types and try again
a = ExpressionBuilder.constantExpression(Integer.valueOf("100"));
b = ExpressionBuilder.constantExpression("200");
assertDoesNotMatch(PredicateBuilder.isGreaterThanOrEqualTo(a, b));
assertMatches(PredicateBuilder.isGreaterThanOrEqualTo(b, a));
// equal
a = ExpressionBuilder.constantExpression("100");
b = ExpressionBuilder.constantExpression(Integer.valueOf("100"));
assertMatches(PredicateBuilder.isGreaterThanOrEqualTo(a, b));
assertMatches(PredicateBuilder.isGreaterThanOrEqualTo(b, a));
// reverse the types and try again
a = ExpressionBuilder.constantExpression(Integer.valueOf("100"));
b = ExpressionBuilder.constantExpression("100");
assertMatches(PredicateBuilder.isGreaterThanOrEqualTo(a, b));
assertMatches(PredicateBuilder.isGreaterThanOrEqualTo(b, a));
}
use of org.apache.camel.Expression in project camel by apache.
the class PredicateBinaryCoerceTypeTest method testEqual.
public void testEqual() throws Exception {
Expression a = ExpressionBuilder.constantExpression("123");
Expression b = ExpressionBuilder.constantExpression(Integer.valueOf("123"));
assertMatches(PredicateBuilder.isEqualTo(a, b));
// reverse the type and try again
a = ExpressionBuilder.constantExpression(Integer.valueOf("123"));
b = ExpressionBuilder.constantExpression("123");
assertMatches(PredicateBuilder.isEqualTo(a, b));
}
use of org.apache.camel.Expression in project camel by apache.
the class PredicateBinaryCoerceTypeTest method testIsNotNull.
public void testIsNotNull() throws Exception {
Expression a = ExpressionBuilder.constantExpression("123");
assertMatches(PredicateBuilder.isNotNull(a));
a = ExpressionBuilder.constantExpression(null);
assertDoesNotMatch(PredicateBuilder.isNotNull(a));
}
Aggregations