Search in sources :

Example 56 with ClientMtTable1

use of org.apache.cayenne.testdo.mt.ClientMtTable1 in project cayenne by apache.

the class PersistentObjectHolderTest method testInvalidate.

@Test
public void testInvalidate() {
    ObjectContext context = mock(ObjectContext.class);
    ClientMtTable2 o = new ClientMtTable2();
    o.setPersistenceState(PersistenceState.COMMITTED);
    o.setObjectContext(context);
    PersistentObjectHolder holder = new PersistentObjectHolder(o, ClientMtTable2.TABLE1_PROPERTY);
    assertTrue(holder.isFault());
    ClientMtTable1 o1 = new ClientMtTable1();
    o1.setObjectContext(context);
    holder.setValueDirectly(o1);
    holder.invalidate();
    assertTrue(holder.isFault());
    assertNull(holder.value);
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) ObjectContext(org.apache.cayenne.ObjectContext) Test(org.junit.Test)

Example 57 with ClientMtTable1

use of org.apache.cayenne.testdo.mt.ClientMtTable1 in project cayenne by apache.

the class CayenneContextClientChannelEventsIT method testSyncToManyRelationship.

@Test
public void testSyncToManyRelationship() throws Exception {
    tMtTable1.insert(1, "g1", "s1");
    tMtTable2.insert(1, 1, "g1");
    CayenneContext c1 = (CayenneContext) runtime.newContext();
    CayenneContext c2 = (CayenneContext) runtime.newContext();
    ClientMtTable1 o1 = (ClientMtTable1) Cayenne.objectForQuery(c1, new ObjectIdQuery(new ObjectId("MtTable1", "TABLE1_ID", 1)));
    ClientMtTable1 o2 = (ClientMtTable1) Cayenne.objectForQuery(c2, new ObjectIdQuery(new ObjectId("MtTable1", "TABLE1_ID", 1)));
    assertEquals(1, o1.getTable2Array().size());
    assertEquals(1, o2.getTable2Array().size());
    ClientMtTable2 o1r = c1.newObject(ClientMtTable2.class);
    o1r.setGlobalAttribute("X");
    o1.addToTable2Array(o1r);
    c1.commitChanges();
    // let the events propagate to peers
    Thread.sleep(500);
    assertEquals(2, o1.getTable2Array().size());
    assertEquals(2, o2.getTable2Array().size());
    assertFalse(c1.internalGraphManager().hasChanges());
    assertFalse(c2.internalGraphManager().hasChanges());
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) ObjectIdQuery(org.apache.cayenne.query.ObjectIdQuery) Test(org.junit.Test)

Example 58 with ClientMtTable1

use of org.apache.cayenne.testdo.mt.ClientMtTable1 in project cayenne by apache.

the class CayenneContextEJBQLIT method testEJBQLSelect.

@Test
public void testEJBQLSelect() throws Exception {
    createTwoRecords();
    EJBQLQuery query = new EJBQLQuery("SELECT a FROM MtTable1 a");
    List<ClientMtTable1> results = context.performQuery(query);
    assertEquals(2, results.size());
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) EJBQLQuery(org.apache.cayenne.query.EJBQLQuery) Test(org.junit.Test)

Example 59 with ClientMtTable1

use of org.apache.cayenne.testdo.mt.ClientMtTable1 in project cayenne by apache.

the class CayenneContextGraphDiffCompressorIT method testDelete.

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

        public void execute() {
            context.commitChanges();
        }
    });
    assertEquals(0, stats.nodePropertiesChanged);
    assertEquals(0, stats.nodesCreated);
    assertEquals(0, stats.nodesRemoved);
}
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 60 with ClientMtTable1

use of org.apache.cayenne.testdo.mt.ClientMtTable1 in project cayenne by apache.

the class CayenneContextIT method testBeforeHollowDeleteShouldChangeStateToCommited.

@Test
public void testBeforeHollowDeleteShouldChangeStateToCommited() {
    ObjectId gid = new ObjectId("MtTable1", "a", "b");
    final ClientMtTable1 inflated = new ClientMtTable1();
    inflated.setPersistenceState(PersistenceState.COMMITTED);
    inflated.setObjectId(gid);
    inflated.setGlobalAttribute1("abc");
    ClientConnection connection = mock(ClientConnection.class);
    when(connection.sendMessage((ClientMessage) any())).thenAnswer(new Answer<Object>() {

        public Object answer(InvocationOnMock invocation) {
            ClientMessage arg = (ClientMessage) invocation.getArguments()[0];
            if (arg instanceof BootstrapMessage) {
                return new EntityResolver();
            } else {
                return new GenericResponse(Arrays.asList(inflated));
            }
        }
    });
    ClientChannel channel = new ClientChannel(connection, false, new MockEventManager(), false);
    CayenneContext context = new CayenneContext(channel);
    context.setEntityResolver(serverContext.getEntityResolver().getClientEntityResolver());
    ClientMtTable1 hollow = context.localObject(inflated);
    assertEquals(PersistenceState.HOLLOW, hollow.getPersistenceState());
    // testing this...
    context.deleteObjects(hollow);
    assertSame(hollow, context.getGraphManager().getNode(gid));
    assertEquals(inflated.getGlobalAttribute1Direct(), hollow.getGlobalAttribute1Direct());
    assertEquals(PersistenceState.DELETED, hollow.getPersistenceState());
}
Also used : GenericResponse(org.apache.cayenne.util.GenericResponse) BootstrapMessage(org.apache.cayenne.remote.BootstrapMessage) ClientMessage(org.apache.cayenne.remote.ClientMessage) EntityResolver(org.apache.cayenne.map.EntityResolver) ClientChannel(org.apache.cayenne.remote.ClientChannel) ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ClientConnection(org.apache.cayenne.remote.ClientConnection) MockEventManager(org.apache.cayenne.event.MockEventManager) Test(org.junit.Test)

Aggregations

ClientMtTable1 (org.apache.cayenne.testdo.mt.ClientMtTable1)112 Test (org.junit.Test)112 ClientMtTable2 (org.apache.cayenne.testdo.mt.ClientMtTable2)46 SelectQuery (org.apache.cayenne.query.SelectQuery)26 UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)19 ObjectContext (org.apache.cayenne.ObjectContext)12 Expression (org.apache.cayenne.exp.Expression)12 ObjectIdQuery (org.apache.cayenne.query.ObjectIdQuery)11 List (java.util.List)8 ObjectId (org.apache.cayenne.ObjectId)7 EntityResolver (org.apache.cayenne.map.EntityResolver)7 LifecycleCallbackRegistry (org.apache.cayenne.reflect.LifecycleCallbackRegistry)7 RemoteIncrementalFaultList (org.apache.cayenne.remote.RemoteIncrementalFaultList)6 GraphDiff (org.apache.cayenne.graph.GraphDiff)5 MockEventManager (org.apache.cayenne.event.MockEventManager)4 ClientChannelServerDiffsListener1 (org.apache.cayenne.remote.ClientChannelServerDiffsListener1)4 ArrayList (java.util.ArrayList)3 Iterator (java.util.Iterator)3 GraphChangeHandler (org.apache.cayenne.graph.GraphChangeHandler)3 MtTable1 (org.apache.cayenne.testdo.mt.MtTable1)3