Search in sources :

Example 11 with UnitTestClosure

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

the class NestedCayenneContextIT method testPrefetchingToMany.

@Test
public void testPrefetchingToMany() throws Exception {
    ClientMtTable1 mt11 = clientContext.newObject(ClientMtTable1.class);
    mt11.setGlobalAttribute1("1");
    ClientMtTable1 mt12 = clientContext.newObject(ClientMtTable1.class);
    mt12.setGlobalAttribute1("2");
    ClientMtTable2 mt21 = clientContext.newObject(ClientMtTable2.class);
    ClientMtTable2 mt22 = clientContext.newObject(ClientMtTable2.class);
    mt21.setTable1(mt11);
    mt22.setTable1(mt11);
    clientContext.commitChanges();
    final ObjectContext child = runtime.newContext(clientContext);
    SelectQuery<ClientMtTable1> q = new SelectQuery<ClientMtTable1>(ClientMtTable1.class);
    q.addOrdering("globalAttribute1", SortOrder.ASCENDING);
    q.addPrefetch(ClientMtTable1.TABLE2ARRAY_PROPERTY);
    final List<ClientMtTable1> results = child.select(q);
    queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            ClientMtTable1 o1 = results.get(0);
            assertEquals(PersistenceState.COMMITTED, o1.getPersistenceState());
            assertSame(child, o1.getObjectContext());
            List<ClientMtTable2> children1 = o1.getTable2Array();
            assertEquals(2, children1.size());
            Iterator<ClientMtTable2> it = children1.iterator();
            while (it.hasNext()) {
                ClientMtTable2 o = it.next();
                assertEquals(PersistenceState.COMMITTED, o.getPersistenceState());
                assertSame(child, o.getObjectContext());
                assertEquals(o1, o.getTable1());
            }
            ClientMtTable1 o2 = results.get(1);
            assertEquals(PersistenceState.COMMITTED, o2.getPersistenceState());
            assertSame(child, o2.getObjectContext());
            List<?> children2 = o2.getTable2Array();
            assertEquals(0, children2.size());
        }
    });
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) Iterator(java.util.Iterator) List(java.util.List) Test(org.junit.Test)

Example 12 with UnitTestClosure

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

the class ClientServerChannelIT method testOnQueryPrefetchingToManyEmpty.

@Test
public void testOnQueryPrefetchingToManyEmpty() throws Exception {
    createTwoMtTable1sAnd2sDataSet();
    SelectQuery q = new SelectQuery(ClientMtTable1.class);
    q.addOrdering(ClientMtTable1.GLOBAL_ATTRIBUTE1_PROPERTY, SortOrder.ASCENDING);
    q.addPrefetch(ClientMtTable1.TABLE2ARRAY_PROPERTY);
    final List<?> results = clientServerChannel.onQuery(null, q).firstList();
    queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            ClientMtTable1 o2 = (ClientMtTable1) results.get(1);
            assertNull(o2.getObjectContext());
            List<?> children2 = o2.getTable2Array();
            assertNotNull(children2);
            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) List(java.util.List) ValueHolder(org.apache.cayenne.ValueHolder) Test(org.junit.Test)

Example 13 with UnitTestClosure

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

the class ClientObjectSelectIT method testPageSelect.

@Test
public void testPageSelect() throws Exception {
    final ObjectSelect<ClientMtTable1> objectSelect = ObjectSelect.query(ClientMtTable1.class).pageSize(5);
    final List<ClientMtTable1> list = objectSelect.select(context);
    assertNotNull(list);
    assertEquals(RemoteIncrementalFaultList.class, list.getClass());
    int count = serverCaseDataChannelInterceptor.runWithQueryCounter(new UnitTestClosure() {

        @Override
        public void execute() {
            assertNotNull(list.get(0));
            assertNotNull(list.get(4));
            assertNotNull(list.get(5));
            assertNotNull(list.get(6));
        }
    });
    assertEquals(1, count);
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) Test(org.junit.Test)

Example 14 with UnitTestClosure

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

the class DeepMergeOperationIT method testDeepMergeModified.

@Test
public void testDeepMergeModified() {
    final Artist a = context.newObject(Artist.class);
    a.setArtistName("AAA");
    context.commitChanges();
    final Artist a1 = (Artist) Cayenne.objectForPK(context1, a.getObjectId());
    a1.setArtistName("BBB");
    final DeepMergeOperation op = new DeepMergeOperation(context1);
    queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            Artist a2 = (Artist) op.merge(a);
            assertNotNull(a2);
            assertEquals(PersistenceState.MODIFIED, a2.getPersistenceState());
            assertSame(a1, a2);
            assertEquals("BBB", a2.getArtistName());
        }
    });
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) Test(org.junit.Test)

Example 15 with UnitTestClosure

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

the class DeepMergeOperationIT method testDeepMergeNonExistent.

@Test
public void testDeepMergeNonExistent() {
    final Artist a = context.newObject(Artist.class);
    a.setArtistName("AAA");
    context.commitChanges();
    final DeepMergeOperation op = new DeepMergeOperation(context1);
    queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            Artist a2 = (Artist) op.merge(a);
            assertNotNull(a2);
            assertEquals(PersistenceState.COMMITTED, a2.getPersistenceState());
            assertEquals(a.getArtistName(), a2.getArtistName());
        }
    });
}
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