Search in sources :

Example 96 with UnitTestClosure

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

the class ShallowMergeOperationIT method testMerge_Relationship.

@Test
public void testMerge_Relationship() throws Exception {
    ObjectContext childContext = runtime.newContext(context);
    final ShallowMergeOperation op = new ShallowMergeOperation(childContext);
    Artist _new = context.newObject(Artist.class);
    final Painting _newP = context.newObject(Painting.class);
    _new.addToPaintingArray(_newP);
    queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            Painting painting = op.merge(_newP);
            assertEquals(PersistenceState.COMMITTED, painting.getPersistenceState());
            assertNotNull(painting.getToArtist());
            assertEquals(PersistenceState.COMMITTED, painting.getToArtist().getPersistenceState());
        }
    });
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) ObjectContext(org.apache.cayenne.ObjectContext) Painting(org.apache.cayenne.testdo.testmap.Painting) Test(org.junit.Test)

Example 97 with UnitTestClosure

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

the class SelectById_RunIT method testPrefetch.

@Test
public void testPrefetch() throws Exception {
    createTwoArtists();
    tPainting.insert(45, 3, "One");
    tPainting.insert(48, 3, "Two");
    final Artist a3 = SelectById.query(Artist.class, 3).prefetch(Artist.PAINTING_ARRAY.joint()).selectOne(context);
    interceptor.runWithQueriesBlocked(new UnitTestClosure() {

        @Override
        public void execute() {
            assertNotNull(a3);
            assertEquals("artist3", a3.getArtistName());
            assertEquals(2, a3.getPaintingArray().size());
            a3.getPaintingArray().get(0).getPaintingTitle();
            a3.getPaintingArray().get(1).getPaintingTitle();
        }
    });
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) Test(org.junit.Test)

Example 98 with UnitTestClosure

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

the class EJBQLQueryIT method testCacheStrategy.

@Test
public void testCacheStrategy() throws Exception {
    // insertValue();
    createArtistsDataSet();
    final String ejbql = "select a FROM Artist a";
    EJBQLQuery query = new EJBQLQuery(ejbql);
    query.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
    final List<Artist> artist1 = context.performQuery(query);
    queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            List<Artist> artist2;
            EJBQLQuery query1 = new EJBQLQuery(ejbql);
            query1.setCacheStrategy(QueryCacheStrategy.LOCAL_CACHE);
            artist2 = context.performQuery(query1);
            assertEquals(artist1.get(0).getArtistName(), artist2.get(0).getArtistName());
        }
    });
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) List(java.util.List) Test(org.junit.Test)

Example 99 with UnitTestClosure

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

the class CayenneContextWithDataContextIT method testPrefetchingToManyEmpty.

@Test
public void testPrefetchingToManyEmpty() throws Exception {
    createTwoMtTable1sAnd2sDataSet();
    SelectQuery q = new SelectQuery(ClientMtTable1.class);
    q.addOrdering(ClientMtTable1.GLOBAL_ATTRIBUTE1_PROPERTY, SortOrder.ASCENDING);
    q.addPrefetch(ClientMtTable1.TABLE2ARRAY_PROPERTY);
    final List<ClientMtTable1> results = clientContext.performQuery(q);
    clientServerInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            ClientMtTable1 o2 = results.get(1);
            assertEquals(PersistenceState.COMMITTED, o2.getPersistenceState());
            assertSame(clientContext, o2.getObjectContext());
            List<ClientMtTable2> children2 = o2.getTable2Array();
            assertFalse(((ValueHolder) children2).isFault());
            assertEquals(0, children2.size());
        }
    });
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) RemoteIncrementalFaultList(org.apache.cayenne.remote.RemoteIncrementalFaultList) List(java.util.List) Test(org.junit.Test)

Example 100 with UnitTestClosure

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

the class CayenneContextWithDataContextIT method testOIDQueryInterception.

@Test
public void testOIDQueryInterception() throws Exception {
    final ClientMtTable1 o = clientContext.newObject(ClientMtTable1.class);
    o.setGlobalAttribute1("aaa");
    // fetch new
    final ObjectIdQuery q1 = new ObjectIdQuery(o.getObjectId(), false, ObjectIdQuery.CACHE);
    clientServerInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            List<?> objects = clientContext.performQuery(q1);
            assertEquals(1, objects.size());
            assertSame(o, objects.get(0));
        }
    });
    clientContext.commitChanges();
    // fetch committed
    final ObjectIdQuery q2 = new ObjectIdQuery(o.getObjectId(), false, ObjectIdQuery.CACHE);
    clientServerInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            List<?> objects = clientContext.performQuery(q2);
            assertEquals(1, objects.size());
            assertSame(o, objects.get(0));
        }
    });
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) RemoteIncrementalFaultList(org.apache.cayenne.remote.RemoteIncrementalFaultList) List(java.util.List) ObjectIdQuery(org.apache.cayenne.query.ObjectIdQuery) 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