Search in sources :

Example 51 with Expression

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));
}
Also used : Expression(org.apache.cayenne.exp.Expression) BigDecimal(java.math.BigDecimal) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 52 with Expression

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);
}
Also used : Expression(org.apache.cayenne.exp.Expression) Test(org.junit.Test)

Example 53 with Expression

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);
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) Expression(org.apache.cayenne.exp.Expression) Test(org.junit.Test)

Example 54 with Expression

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());
}
Also used : Expression(org.apache.cayenne.exp.Expression) Test(org.junit.Test)

Example 55 with Expression

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);
}
Also used : Expression(org.apache.cayenne.exp.Expression) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Expression (org.apache.cayenne.exp.Expression)298 Test (org.junit.Test)265 Artist (org.apache.cayenne.testdo.testmap.Artist)69 SelectQuery (org.apache.cayenne.query.SelectQuery)47 Painting (org.apache.cayenne.testdo.testmap.Painting)29 BigDecimal (java.math.BigDecimal)23 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)17 DateTestEntity (org.apache.cayenne.testdo.date_time.DateTestEntity)16 ObjEntity (org.apache.cayenne.map.ObjEntity)13 ClientMtTable1 (org.apache.cayenne.testdo.mt.ClientMtTable1)12 DbEntity (org.apache.cayenne.map.DbEntity)10 List (java.util.List)9 HashMap (java.util.HashMap)8 DataRow (org.apache.cayenne.DataRow)8 DbAttribute (org.apache.cayenne.map.DbAttribute)8 ClientMtTable2 (org.apache.cayenne.testdo.mt.ClientMtTable2)7 DbRelationship (org.apache.cayenne.map.DbRelationship)6 ObjAttribute (org.apache.cayenne.map.ObjAttribute)6 ObjRelationship (org.apache.cayenne.map.ObjRelationship)6 Gallery (org.apache.cayenne.testdo.testmap.Gallery)6