use of org.datanucleus.query.expression.DyadicExpression in project tests by datanucleus.
the class JDOQLCompilerTest method testFilterImplicitParameter.
/**
* Test for use of an implicit parameter in the filter.
*/
public void testFilterImplicitParameter() {
// Test use of implicit variable in filter
JavaQueryCompiler compiler = null;
QueryCompilation compilation = null;
try {
compiler = new JDOQLCompiler(nucCtx, nucCtx.getClassLoaderResolver(null), null, Product.class, null, "name == :param1", null, null, null, null, null, null, null, null);
compilation = compiler.compile(null, null);
} catch (NucleusUserException ne) {
// TODO Debatable if this should throw a JDOUserException since the "notaField" is not bound, nor typed
NucleusLogger.QUERY.error("Exception thrown during compilation", ne);
fail("compilation of filter with valid field threw exception : " + ne.getMessage());
}
Expression expr = compilation.getExprFilter();
assertTrue("Compiled expression should have been DyadicExpression but wasnt", expr instanceof DyadicExpression);
DyadicExpression dyExpr = (DyadicExpression) expr;
assertTrue("Compiled left expression should be PrimaryExpression but isnt", dyExpr.getLeft() instanceof PrimaryExpression);
assertTrue("Compiled right expression should be ParameterExpression but isnt", dyExpr.getRight() instanceof ParameterExpression);
PrimaryExpression left = (PrimaryExpression) dyExpr.getLeft();
assertEquals("Primary expression name is wrong", left.getId(), "name");
ParameterExpression right = (ParameterExpression) dyExpr.getRight();
assertEquals("ParameterExpression has wrong value", "param1", right.getId());
}
Aggregations