private static final Logger log = Logger
.getLogger(SimpleSqlExpressionTest.class);
public void testSqlExpressionBuilder() throws ExpressionEvaluationException {
// build expression
Expression expr = new AndExpression().add(
new ComparedEqualsExpression(new VariableExpression("name"),
new ValueExpression("James Bond"), ComparatorFactory
.getStringComparator(false, true, null))).add(
new GreaterThanExpression(new VariableExpression("age"),
new ValueExpression(new Long(25)))).add(
new EqualsExpression(new VariableExpression("licenseToKill"),
new ValueExpression(Boolean.TRUE)));
// evaluate expression in memory
Object value = expr.evaluate(new VariableResolver() {
public Object resolve(Variable variable) {
if (variable.getName().equals("name")) {
return "James Bond";
}
if (variable.getName().equals("age")) {
return new Long(30);
}
if (variable.getName().equals("licenseToKill")) {
return Boolean.TRUE;
}
return null;
}
});
assertEquals(value, Boolean.TRUE);
// evaluate expression in memory
value = expr.evaluate(new VariableResolver() {
public Object resolve(Variable variable) {
if (variable.getName().equals("name")) {
return "Bond, James";
}
return null;