Search in sources :

Example 76 with UnitTestClosure

use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.

the class DataContextRefreshingIT method testInvalidateThenModify.

@Test
public void testInvalidateThenModify() throws Exception {
    createSingleArtistDataSet();
    final Artist artist = (Artist) context.performQuery(new SelectQuery(Artist.class)).get(0);
    assertNotNull(artist);
    context.invalidateObjects(artist);
    assertEquals(PersistenceState.HOLLOW, artist.getPersistenceState());
    int queries = queryInterceptor.runWithQueryCounter(new UnitTestClosure() {

        public void execute() {
            // this must trigger a fetch
            artist.setArtistName("new name");
        }
    });
    assertEquals(1, queries);
    assertEquals(PersistenceState.MODIFIED, artist.getPersistenceState());
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) SelectQuery(org.apache.cayenne.query.SelectQuery) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) Test(org.junit.Test)

Example 77 with UnitTestClosure

use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.

the class DataContextRefreshingIT method testModifyHollow.

@Test
public void testModifyHollow() throws Exception {
    createSingleArtistAndPaintingDataSet();
    Painting painting = (Painting) context.performQuery(new SelectQuery(Painting.class)).get(0);
    final Artist artist = painting.getToArtist();
    assertEquals(PersistenceState.HOLLOW, artist.getPersistenceState());
    assertNull(artist.readPropertyDirectly("artistName"));
    int queries = queryInterceptor.runWithQueryCounter(new UnitTestClosure() {

        public void execute() {
            // this must trigger a fetch
            artist.setDateOfBirth(new Date());
        }
    });
    assertEquals(1, queries);
    assertEquals(PersistenceState.MODIFIED, artist.getPersistenceState());
    assertNotNull(artist.readPropertyDirectly("artistName"));
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) Artist(org.apache.cayenne.testdo.testmap.Artist) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) Date(java.util.Date) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 78 with UnitTestClosure

use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.

the class CayenneDataObjectFlattenedRelIT method testAddRemoveFlattenedRelationship1.

@Test
public void testAddRemoveFlattenedRelationship1() throws Exception {
    create1Artist1ArtGroupDataSet();
    Artist a1 = Cayenne.objectForPK(context, Artist.class, 33001);
    SelectQuery q = new SelectQuery(ArtGroup.class, ExpressionFactory.matchExp("name", "g1"));
    List<?> results = context.performQuery(q);
    assertEquals(1, results.size());
    ArtGroup group = (ArtGroup) results.get(0);
    a1.addToGroupArray(group);
    group.removeFromArtistArray(a1);
    queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            context.commitChanges();
        }
    });
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) SelectQuery(org.apache.cayenne.query.SelectQuery) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) ArtGroup(org.apache.cayenne.testdo.testmap.ArtGroup) Test(org.junit.Test)

Example 79 with UnitTestClosure

use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.

the class DataContextMaxIdQualifierIT method testIncrementalFaultList_Higher.

@Test
public void testIncrementalFaultList_Higher() throws Exception {
    insertData_OneBag_100Boxes();
    runtime.getDataDomain().setMaxIdQualifierSize(101);
    final SelectQuery query = new SelectQuery(Painting.class);
    query.setPageSize(10);
    int queriesCount = queryInterceptor.runWithQueryCounter(new UnitTestClosure() {

        public void execute() {
            final List<Painting> boxes = context.performQuery(query);
            for (Painting box : boxes) {
                box.getToArtist();
            }
        }
    });
    assertEquals(11, queriesCount);
    queriesCount = queryInterceptor.runWithQueryCounter(new UnitTestClosure() {

        public void execute() {
            final List<Painting> boxes = context.performQuery(query);
            List<Painting> tempList = new ArrayList<Painting>();
            tempList.addAll(boxes);
        }
    });
    assertEquals(2, queriesCount);
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 80 with UnitTestClosure

use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.

the class DataContextMaxIdQualifierIT method testDisjointByIdPrefetch_Negative.

@Test
public void testDisjointByIdPrefetch_Negative() throws Exception {
    insertData();
    runtime.getDataDomain().setMaxIdQualifierSize(-1);
    final SelectQuery query = new SelectQuery(Artist.class);
    query.addPrefetch(Artist.PAINTING_ARRAY.disjointById());
    int queriesCount = queryInterceptor.runWithQueryCounter(new UnitTestClosure() {

        public void execute() {
            context.performQuery(query);
        }
    });
    assertEquals(2, queriesCount);
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) Test(org.junit.Test)

Aggregations

UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)107 Test (org.junit.Test)107 SelectQuery (org.apache.cayenne.query.SelectQuery)64 List (java.util.List)48 Artist (org.apache.cayenne.testdo.testmap.Artist)47 Painting (org.apache.cayenne.testdo.testmap.Painting)35 ValueHolder (org.apache.cayenne.ValueHolder)23 ClientMtTable1 (org.apache.cayenne.testdo.mt.ClientMtTable1)19 ArrayList (java.util.ArrayList)15 ObjectContext (org.apache.cayenne.ObjectContext)14 ClientMtTable2 (org.apache.cayenne.testdo.mt.ClientMtTable2)9 ArtGroup (org.apache.cayenne.testdo.testmap.ArtGroup)8 Iterator (java.util.Iterator)7 AbstractPerson (org.apache.cayenne.testdo.inheritance_people.AbstractPerson)7 Expression (org.apache.cayenne.exp.Expression)6 ObjectIdQuery (org.apache.cayenne.query.ObjectIdQuery)6 PaintingInfo (org.apache.cayenne.testdo.testmap.PaintingInfo)6 EJBQLQuery (org.apache.cayenne.query.EJBQLQuery)5 RemoteIncrementalFaultList (org.apache.cayenne.remote.RemoteIncrementalFaultList)5 PersonNotes (org.apache.cayenne.testdo.inheritance_people.PersonNotes)5