use of org.apache.cayenne.exp.Expression in project cayenne by apache.
the class ASTBetweenTest method testEvaluate.
@Test
public void testEvaluate() {
// evaluate both BETWEEN and NOT_BETWEEN
Expression between = new ASTBetween(new ASTObjPath("estimatedPrice"), new BigDecimal(10d), new BigDecimal(20d));
Expression notBetween = new ASTNotBetween(new ASTObjPath("estimatedPrice"), new BigDecimal(10d), new BigDecimal(20d));
Painting noMatch = new Painting();
noMatch.setEstimatedPrice(new BigDecimal(21));
assertFalse(between.match(noMatch));
assertTrue(notBetween.match(noMatch));
Painting match1 = new Painting();
match1.setEstimatedPrice(new BigDecimal(20));
assertTrue(between.match(match1));
assertFalse(notBetween.match(match1));
Painting match2 = new Painting();
match2.setEstimatedPrice(new BigDecimal(10));
assertTrue("Failed: " + between, between.match(match2));
assertFalse("Failed: " + notBetween, notBetween.match(match2));
Painting match3 = new Painting();
match3.setEstimatedPrice(new BigDecimal(11));
assertTrue("Failed: " + between, between.match(match3));
assertFalse("Failed: " + notBetween, notBetween.match(match3));
}
use of org.apache.cayenne.exp.Expression in project cayenne by apache.
the class ASTConcatTest method parseTest.
@Test
public void parseTest() throws Exception {
String expString = "concat(xyz , \" \" , abc)";
Expression exp = ExpressionFactory.exp(expString);
assertTrue(exp instanceof ASTConcat);
String toString = exp.toString();
assertEquals(expString, toString);
}
use of org.apache.cayenne.exp.Expression in project cayenne by apache.
the class ASTConcatTest method testParseConcat.
@Test
public void testParseConcat() throws Exception {
Expression exp = ExpressionFactory.exp("concat(artistName, ' ', 'test')");
assertEquals(ASTConcat.class, exp.getClass());
assertEquals(3, exp.getOperandCount());
Artist a = new Artist();
a.setArtistName("name");
Object res = exp.evaluate(a);
assertTrue(res instanceof String);
assertEquals("name test", res);
}
use of org.apache.cayenne.exp.Expression in project cayenne by apache.
the class ASTCurrentTimeTest method testParse.
@Test
public void testParse() {
Expression exp2 = ExpressionFactory.exp("currentTime()");
assertTrue(exp2 instanceof ASTCurrentTime);
assertEquals("currentTime()", exp2.toString());
}
use of org.apache.cayenne.exp.Expression in project cayenne by apache.
the class ASTCurrentTimeTest method testEvaluate.
@Test
public void testEvaluate() {
Expression exp = new ASTCurrentTime();
Object result = exp.evaluate(new Object());
assertTrue(result instanceof Date);
}
Aggregations