use of org.datanucleus.query.expression.Expression.Operator in project tests by datanucleus.
the class JPQLCompilerTest method testUpdateSimple.
/**
* Test for use of update clause.
*/
public void testUpdateSimple() {
// Test use of UPDATE clause
try {
JPQLCompiler compiler = new JPQLCompiler(nucCtx, nucCtx.getClassLoaderResolver(null), null, Project.class, null, null, null, null, null, null, null, null, "name = \"Sample Name\"");
QueryCompilation compilation = compiler.compile(null, null);
Expression[] updateExprs = compilation.getExprUpdate();
assertNotNull("Update clause is null but shouldnt be", updateExprs);
assertEquals("Number of update expressions is incorrect", 1, updateExprs.length);
assertTrue("Update expression is of incorrect type " + updateExprs[0].getClass().getName(), updateExprs[0] instanceof DyadicExpression);
DyadicExpression updateExpr = (DyadicExpression) updateExprs[0];
Expression left = updateExpr.getLeft();
Expression right = updateExpr.getRight();
Operator op = updateExpr.getOperator();
assertEquals("Operator in update expression is wrong", op, Expression.OP_EQ);
assertTrue("Left hand side in update is wrong", left instanceof PrimaryExpression);
assertTrue("Right hand side in update is wrong", right instanceof Literal);
PrimaryExpression primExpr = (PrimaryExpression) left;
assertEquals("Left hand side primary is wrong", "name", primExpr.getId());
Literal lit = (Literal) right;
assertEquals("Right hand side literal is wrong", "Sample Name", lit.getLiteral());
} catch (NucleusUserException ne) {
fail("Exception thrown in compile of update clause : " + ne.getMessage());
}
}
Aggregations