Search in sources :

Example 91 with Expression

use of org.apache.cayenne.exp.Expression in project cayenne by apache.

the class ASTLikeTest method testEvaluate_SingleCharMatch.

@Test
public void testEvaluate_SingleCharMatch() {
    Expression like = new ASTLike(new ASTObjPath("artistName"), "abc?d");
    Expression notLike = new ASTNotLike(new ASTObjPath("artistName"), "abc?d");
    Artist noMatch1 = new Artist();
    noMatch1.setArtistName("dabc");
    assertFalse(like.match(noMatch1));
    assertTrue(notLike.match(noMatch1));
    Artist noMatch2 = new Artist();
    noMatch2.setArtistName("abc123d");
    assertFalse("Failed: " + like, like.match(noMatch2));
    assertTrue("Failed: " + notLike, notLike.match(noMatch2));
    Artist match = new Artist();
    match.setArtistName("abcXd");
    assertTrue("Failed: " + like, like.match(match));
    assertFalse("Failed: " + notLike, notLike.match(match));
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) Expression(org.apache.cayenne.exp.Expression) Test(org.junit.Test)

Example 92 with Expression

use of org.apache.cayenne.exp.Expression in project cayenne by apache.

the class ASTLikeTest method testEvaluateUnicode.

@Test
public void testEvaluateUnicode() {
    Expression like = new ASTLike(new ASTObjPath("artistName"), "àбğþ%");
    Expression notLike = new ASTNotLike(new ASTObjPath("artistName"), "àбğþ%");
    Artist noMatch1 = new Artist();
    noMatch1.setArtistName("àbğþd");
    assertFalse(like.match(noMatch1));
    assertTrue(notLike.match(noMatch1));
    Artist match1 = new Artist();
    match1.setArtistName("àбğþ");
    assertTrue("Failed: " + like, like.match(match1));
    assertFalse("Failed: " + notLike, notLike.match(match1));
    Artist match2 = new Artist();
    match2.setArtistName("àбğþa");
    assertTrue("Failed: " + like, like.match(match2));
    assertFalse("Failed: " + notLike, notLike.match(match2));
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) Expression(org.apache.cayenne.exp.Expression) Test(org.junit.Test)

Example 93 with Expression

use of org.apache.cayenne.exp.Expression in project cayenne by apache.

the class ASTLocateTest method parseTest.

@Test
public void parseTest() throws Exception {
    String expString = "locate(\"xyz\" , abc , 4)";
    Expression exp = ExpressionFactory.exp(expString);
    assertTrue(exp instanceof ASTLocate);
    String toString = exp.toString();
    assertEquals(expString, toString);
}
Also used : Expression(org.apache.cayenne.exp.Expression) Test(org.junit.Test)

Example 94 with Expression

use of org.apache.cayenne.exp.Expression in project cayenne by apache.

the class ASTNotEqualTest method testEvaluate.

@Test
public void testEvaluate() {
    Expression notEqualTo = new ASTNotEqual(new ASTObjPath("artistName"), "abc");
    Artist match = new Artist();
    match.setArtistName("abc");
    assertFalse(notEqualTo.match(match));
    Artist noMatch = new Artist();
    noMatch.setArtistName("123");
    assertTrue("Failed: " + notEqualTo, notEqualTo.match(noMatch));
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) Expression(org.apache.cayenne.exp.Expression) Test(org.junit.Test)

Example 95 with Expression

use of org.apache.cayenne.exp.Expression in project cayenne by apache.

the class ASTOrTest method testEvaluateOR.

@Test
public void testEvaluateOR() {
    Expression e1 = new ASTEqual(new ASTObjPath("artistName"), "abc");
    Expression e2 = new ASTEqual(new ASTObjPath("artistName"), "xyz");
    ASTOr e = new ASTOr(new Object[] { e1, e2 });
    Artist match1 = new Artist();
    match1.setArtistName("abc");
    assertTrue("Failed: " + e, e.match(match1));
    Artist match2 = new Artist();
    match2.setArtistName("xyz");
    assertTrue("Failed: " + e, e.match(match2));
    Artist noMatch = new Artist();
    noMatch.setArtistName("123");
    assertFalse("Failed: " + e, e.match(noMatch));
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) Expression(org.apache.cayenne.exp.Expression) 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