Search in sources :

Example 26 with UnitTestClosure

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

the class SelectById_RunIT method testLocalCache.

@Test
public void testLocalCache() throws Exception {
    createTwoArtists();
    final Artist[] a3 = new Artist[1];
    assertEquals(1, interceptor.runWithQueryCounter(new UnitTestClosure() {

        @Override
        public void execute() {
            a3[0] = SelectById.query(Artist.class, 3).localCache("g1").selectOne(context);
            assertNotNull(a3[0]);
            assertEquals("artist3", a3[0].getArtistName());
        }
    }));
    interceptor.runWithQueriesBlocked(new UnitTestClosure() {

        @Override
        public void execute() {
            Artist a3cached = SelectById.query(Artist.class, 3).localCache("g1").selectOne(context);
            assertSame(a3[0], a3cached);
        }
    });
    context.performGenericQuery(new RefreshQuery("g1"));
    assertEquals(1, interceptor.runWithQueryCounter(new UnitTestClosure() {

        @Override
        public void execute() {
            SelectById.query(Artist.class, 3).localCache("g1").selectOne(context);
        }
    }));
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) Test(org.junit.Test)

Example 27 with UnitTestClosure

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

the class DataContextIT method testPerformPaginatedQueryBigPage.

@Test
public void testPerformPaginatedQueryBigPage() throws Exception {
    createArtistsDataSet();
    SelectQuery query = new SelectQuery(Artist.class);
    query.setPageSize(5);
    final List<?> objects = context.performQuery(query);
    assertNotNull(objects);
    assertTrue(objects instanceof IncrementalFaultList<?>);
    queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            assertEquals(7, objects.size());
        }
    });
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) Test(org.junit.Test)

Example 28 with UnitTestClosure

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

the class DataContextLocalObjectIT method testLocalObject_TempId_NestedContext.

@Test
public void testLocalObject_TempId_NestedContext() throws Exception {
    final Artist a1 = context1.newObject(Artist.class);
    final ObjectContext nestedContext = runtime.newContext(context1);
    interceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            Artist a3 = nestedContext.localObject(a1);
            assertNotSame(a3, a1);
            assertEquals(a3.getObjectId(), a1.getObjectId());
            assertSame(nestedContext, a3.getObjectContext());
        }
    });
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) ObjectContext(org.apache.cayenne.ObjectContext) Test(org.junit.Test)

Example 29 with UnitTestClosure

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

the class DataContextLocalObjectIT method testLocalObject_SameContext.

@Test
public void testLocalObject_SameContext() throws Exception {
    tArtist.insert(456, "Bla");
    final Artist a1 = Cayenne.objectForPK(context1, Artist.class, 456);
    interceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            Artist a2 = context1.localObject(a1);
            assertSame(a2, a1);
        }
    });
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) Test(org.junit.Test)

Example 30 with UnitTestClosure

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

the class DataContextLocalObjectIT method testLocalObject_NotInCache.

@Test
public void testLocalObject_NotInCache() throws Exception {
    tArtist.insert(456, "Bla");
    final Artist a1 = Cayenne.objectForPK(context1, Artist.class, 456);
    interceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            Artist a3 = context2.localObject(a1);
            assertNotSame(a3, a1);
            assertEquals(a3.getObjectId(), a1.getObjectId());
            assertSame(context2, a3.getObjectContext());
        }
    });
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) 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