Search in sources :

Example 46 with ClientMtTable2

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

the class RemoteRollbackIT method testRollbackNew.

@Test
public void testRollbackNew() {
    ClientMtTable1 o1 = clientContext.newObject(ClientMtTable1.class);
    o1.setGlobalAttribute1("a");
    ClientMtTable2 p1 = clientContext.newObject(ClientMtTable2.class);
    p1.setGlobalAttribute("p1");
    p1.setTable1(o1);
    ClientMtTable2 p2 = clientContext.newObject(ClientMtTable2.class);
    p2.setGlobalAttribute("p2");
    p2.setTable1(o1);
    ClientMtTable2 p3 = clientContext.newObject(ClientMtTable2.class);
    p3.setGlobalAttribute("p3");
    p3.setTable1(o1);
    // before:
    assertEquals(o1, p1.getTable1());
    assertEquals(3, o1.getTable2Array().size());
    clientContext.rollbackChanges();
    // after:
    assertEquals(PersistenceState.TRANSIENT, o1.getPersistenceState());
// TODO: should we expect relationships to be unset?
// assertNull(p1.getToClientMtTable1());
// assertEquals(0, o1.getClientMtTable2Array().size());
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) Test(org.junit.Test)

Example 47 with ClientMtTable2

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

the class HessianROPSerializationServiceIT method testStreamSerialization.

@Test
public void testStreamSerialization() throws Exception {
    ClientMtTable1 table1 = context.newObject(ClientMtTable1.class);
    table1.setGlobalAttribute1("Test table1");
    ClientMtTable2 table2 = context.newObject(ClientMtTable2.class);
    table2.setGlobalAttribute("Test table2");
    table2.setTable1(table1);
    ROPSerializationService clientService = createClientSerializationService();
    ROPSerializationService serverService = createServerSerializationService();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    // test client to server serialization
    clientService.serialize(table2, out);
    out.flush();
    ClientMtTable2 serverTable2 = serverService.deserialize(new ByteArrayInputStream(out.toByteArray()), ClientMtTable2.class);
    assertEquals("Test table2", serverTable2.getGlobalAttribute());
    assertEquals("Test table1", serverTable2.getTable1().getGlobalAttribute1());
    // test server to client serialization
    out = new ByteArrayOutputStream();
    serverService.serialize(table2, out);
    out.flush();
    ClientMtTable2 clientTable2 = clientService.deserialize(new ByteArrayInputStream(out.toByteArray()), ClientMtTable2.class);
    assertEquals("Test table2", clientTable2.getGlobalAttribute());
    assertEquals("Test table1", clientTable2.getTable1().getGlobalAttribute1());
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) ByteArrayInputStream(java.io.ByteArrayInputStream) ROPSerializationService(org.apache.cayenne.rop.ROPSerializationService) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 48 with ClientMtTable2

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

the class ShallowMergeOperation_ClientIT method testMerge_Relationship.

@Test
public void testMerge_Relationship() throws Exception {
    ObjectContext childContext = runtime.newContext(context);
    final ShallowMergeOperation op = new ShallowMergeOperation(childContext);
    ClientMtTable1 _new = context.newObject(ClientMtTable1.class);
    final ClientMtTable2 _new2 = context.newObject(ClientMtTable2.class);
    _new.addToTable2Array(_new2);
    queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {

        public void execute() {
            ClientMtTable2 child2 = op.merge(_new2);
            assertEquals(PersistenceState.COMMITTED, child2.getPersistenceState());
            assertNotNull(child2.getTable1());
            assertEquals(PersistenceState.COMMITTED, child2.getTable1().getPersistenceState());
        }
    });
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) UnitTestClosure(org.apache.cayenne.unit.di.UnitTestClosure) ObjectContext(org.apache.cayenne.ObjectContext) Test(org.junit.Test)

Aggregations

ClientMtTable2 (org.apache.cayenne.testdo.mt.ClientMtTable2)48 Test (org.junit.Test)48 ClientMtTable1 (org.apache.cayenne.testdo.mt.ClientMtTable1)46 UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)9 Expression (org.apache.cayenne.exp.Expression)7 SelectQuery (org.apache.cayenne.query.SelectQuery)7 ObjectContext (org.apache.cayenne.ObjectContext)6 ObjectIdQuery (org.apache.cayenne.query.ObjectIdQuery)6 Iterator (java.util.Iterator)3 List (java.util.List)3 GraphDiff (org.apache.cayenne.graph.GraphDiff)3 PersistentObjectHolder (org.apache.cayenne.util.PersistentObjectHolder)3 GraphChangeHandler (org.apache.cayenne.graph.GraphChangeHandler)2 LifecycleCallbackRegistry (org.apache.cayenne.reflect.LifecycleCallbackRegistry)2 ClientChannelServerDiffsListener1 (org.apache.cayenne.remote.ClientChannelServerDiffsListener1)2 ROPSerializationService (org.apache.cayenne.rop.ROPSerializationService)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 CayenneContext (org.apache.cayenne.CayenneContext)1 ValueHolder (org.apache.cayenne.ValueHolder)1