Search in sources :

Example 1 with UnitTestClosure

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

the class CayenneContextGraphDiffCompressorIT method testMultipleSimpleProperties.

@Test
public void testMultipleSimpleProperties() {
    ClientMtTable1 o1 = context.newObject(ClientMtTable1.class);
    o1.setGlobalAttribute1("v1");
    o1.setGlobalAttribute1("v2");
    DataChannelSyncStats stats = clientServerInterceptor.runWithSyncStatsCollection(new UnitTestClosure() {

        public void execute() {
            context.commitChanges();
        }
    });
    assertEquals(1, stats.nodePropertiesChanged);
    assertEquals(1, stats.nodesCreated);
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) DataChannelSyncStats(org.apache.cayenne.unit.di.DataChannelSyncStats) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) Test(org.junit.Test)

Example 2 with UnitTestClosure

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

the class CayenneContextGraphDiffCompressorIT method testComplimentaryArcs.

@Test
public void testComplimentaryArcs() {
    ClientMtTable1 o1 = context.newObject(ClientMtTable1.class);
    ClientMtTable2 o2 = context.newObject(ClientMtTable2.class);
    o2.setTable1(o1);
    o2.setTable1(null);
    DataChannelSyncStats stats = clientServerInterceptor.runWithSyncStatsCollection(new UnitTestClosure() {

        public void execute() {
            context.commitChanges();
        }
    });
    assertEquals(0, stats.nodePropertiesChanged);
    assertEquals(2, stats.nodesCreated);
    assertEquals(0, stats.arcsCreated);
    assertEquals(0, stats.arcsDeleted);
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) DataChannelSyncStats(org.apache.cayenne.unit.di.DataChannelSyncStats) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) Test(org.junit.Test)

Example 3 with UnitTestClosure

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

the class CayenneContextNamedQueryCachingIT method testLocalCacheParameterized.

@Test
public void testLocalCacheParameterized() throws Exception {
    createThreeMtTable1sDataSet();
    final MappedSelect q1 = MappedSelect.query("ParameterizedMtQueryWithLocalCache").param("g", "g1");
    final MappedSelect q2 = MappedSelect.query("ParameterizedMtQueryWithLocalCache").param("g", "g2");
    final List<?> result1 = context.performQuery(q1);
    assertEquals(1, result1.size());
    clientServerInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            List<?> result2 = context.performQuery(q1);
            assertSame(result1, result2);
        }
    });
    final List<?> result3 = context.performQuery(q2);
    assertNotSame(result1, result3);
    assertEquals(1, result3.size());
    clientServerInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            List<?> result4 = context.performQuery(q2);
            assertSame(result3, result4);
            List<?> result5 = context.performQuery(q1);
            assertSame(result1, result5);
        }
    });
}
Also used : UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) List(java.util.List) MappedSelect(org.apache.cayenne.query.MappedSelect) Test(org.junit.Test)

Example 4 with UnitTestClosure

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

the class CayenneContextNamedQueryCachingIT method testLocalCache.

@Test
public void testLocalCache() throws Exception {
    createThreeMtTable1sDataSet();
    final MappedSelect q1 = MappedSelect.query("MtQueryWithLocalCache");
    final List<?> result1 = context.performQuery(q1);
    assertEquals(3, result1.size());
    clientServerInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            List<?> result2 = context.performQuery(q1);
            assertSame(result1, result2);
        }
    });
    // refresh
    q1.forceNoCache();
    List<?> result3 = context.performQuery(q1);
    assertNotSame(result1, result3);
    assertEquals(3, result3.size());
}
Also used : UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) List(java.util.List) MappedSelect(org.apache.cayenne.query.MappedSelect) Test(org.junit.Test)

Example 5 with UnitTestClosure

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

the class CayenneContextWithDataContextIT method testPrefetchingToMany.

@Test
public void testPrefetchingToMany() 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 o1 = results.get(0);
            assertEquals(PersistenceState.COMMITTED, o1.getPersistenceState());
            assertSame(clientContext, o1.getObjectContext());
            List<?> children1 = o1.getTable2Array();
            assertEquals(2, children1.size());
            Iterator<?> it = children1.iterator();
            while (it.hasNext()) {
                ClientMtTable2 o = (ClientMtTable2) it.next();
                assertEquals(PersistenceState.COMMITTED, o.getPersistenceState());
                assertSame(clientContext, o.getObjectContext());
            // TODO: fixme... reverse relationship is not connected and will
            // cause a fetch
            // assertEquals(o1, o.getTable1());
            }
        }
    });
}
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) RemoteIncrementalFaultList(org.apache.cayenne.remote.RemoteIncrementalFaultList) List(java.util.List) 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