Search in sources :

Example 56 with Painting

use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.

the class ASTEqualTest method testEvaluate_BigDecimal.

@Test
public void testEvaluate_BigDecimal() {
    BigDecimal bd1 = new BigDecimal("2.0");
    BigDecimal bd2 = new BigDecimal("2.0");
    BigDecimal bd3 = new BigDecimal("2.00");
    BigDecimal bd4 = new BigDecimal("2.01");
    ASTEqual equalTo = new ASTEqual(new ASTObjPath(Painting.ESTIMATED_PRICE.getName()), bd1);
    Painting p = new Painting();
    p.setEstimatedPrice(bd2);
    assertTrue(equalTo.match(p));
    // BigDecimals must compare regardless of the number of trailing zeros
    // (see CAY-280)
    p.setEstimatedPrice(bd3);
    assertTrue(equalTo.match(p));
    p.setEstimatedPrice(bd4);
    assertFalse(equalTo.match(p));
}
Also used : BigDecimal(java.math.BigDecimal) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 57 with Painting

use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.

the class ASTGreaterOrEqualTest method testEvaluate_Null.

@Test
public void testEvaluate_Null() {
    Expression gtNull = new ASTGreaterOrEqual(new ASTObjPath("estimatedPrice"), null);
    Expression gtNotNull = new ASTGreaterOrEqual(new ASTObjPath("estimatedPrice"), new BigDecimal(10000d));
    Painting noMatch = new Painting();
    assertFalse(gtNull.match(noMatch));
    assertFalse(gtNotNull.match(noMatch));
}
Also used : Expression(org.apache.cayenne.exp.Expression) BigDecimal(java.math.BigDecimal) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 58 with Painting

use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.

the class ASTInTest method testEvaluate_Null.

@Test
public void testEvaluate_Null() {
    Expression in = new ASTIn(new ASTObjPath("estimatedPrice"), new ASTList(new Object[] { new BigDecimal("10"), new BigDecimal("20") }));
    Expression notIn = new ASTNotIn(new ASTObjPath("estimatedPrice"), new ASTList(new Object[] { new BigDecimal("10"), new BigDecimal("20") }));
    Painting noMatch = new Painting();
    assertFalse(in.match(noMatch));
    assertFalse(notIn.match(noMatch));
}
Also used : Expression(org.apache.cayenne.exp.Expression) BigDecimal(java.math.BigDecimal) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 59 with Painting

use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.

the class ASTLessTest method testEvaluate.

@Test
public void testEvaluate() {
    Expression e = new ASTLess(new ASTObjPath("estimatedPrice"), new BigDecimal(10000d));
    Painting noMatch = new Painting();
    noMatch.setEstimatedPrice(new BigDecimal(10001));
    assertFalse("Failed: " + e, e.match(noMatch));
    Painting noMatch1 = new Painting();
    noMatch1.setEstimatedPrice(new BigDecimal(10000));
    assertFalse("Failed: " + e, e.match(noMatch1));
    Painting match = new Painting();
    match.setEstimatedPrice(new BigDecimal(9999));
    assertTrue("Failed: " + e, e.match(match));
}
Also used : Expression(org.apache.cayenne.exp.Expression) BigDecimal(java.math.BigDecimal) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 60 with Painting

use of org.apache.cayenne.testdo.testmap.Painting in project cayenne by apache.

the class ColumnSelectIT method testObjPropertyInWhere.

@Test
public void testObjPropertyInWhere() {
    Artist artist = ObjectSelect.query(Artist.class, Artist.ARTIST_NAME.eq("artist1")).selectFirst(context);
    Property<Painting> paintingProperty = Property.createSelf(Painting.class);
    List<Painting> result = ObjectSelect.query(Painting.class).column(paintingProperty).where(Painting.TO_ARTIST.eq(artist)).select(context);
    assertEquals(4, result.size());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Aggregations

Painting (org.apache.cayenne.testdo.testmap.Painting)222 Test (org.junit.Test)218 Artist (org.apache.cayenne.testdo.testmap.Artist)144 SelectQuery (org.apache.cayenne.query.SelectQuery)75 UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)35 List (java.util.List)30 Expression (org.apache.cayenne.exp.Expression)29 ArrayList (java.util.ArrayList)21 BigDecimal (java.math.BigDecimal)19 PaintingInfo (org.apache.cayenne.testdo.testmap.PaintingInfo)14 ObjectContext (org.apache.cayenne.ObjectContext)13 EJBQLQuery (org.apache.cayenne.query.EJBQLQuery)13 Gallery (org.apache.cayenne.testdo.testmap.Gallery)13 ValueHolder (org.apache.cayenne.ValueHolder)12 ROPainting (org.apache.cayenne.testdo.testmap.ROPainting)12 SQLTemplate (org.apache.cayenne.query.SQLTemplate)11 DataRow (org.apache.cayenne.DataRow)7 ProcedureQuery (org.apache.cayenne.query.ProcedureQuery)6 LifecycleCallbackRegistry (org.apache.cayenne.reflect.LifecycleCallbackRegistry)6 RefreshQuery (org.apache.cayenne.query.RefreshQuery)5