Search in sources :

Example 1 with ROPSerializationService

use of org.apache.cayenne.rop.ROPSerializationService in project cayenne by apache.

the class HessianROPSerializationServiceIT method testByteArraySerialization.

@Test
public void testByteArraySerialization() 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();
    // test client to server serialization
    byte[] data = clientService.serialize(table2);
    ClientMtTable2 serverTable2 = serverService.deserialize(data, ClientMtTable2.class);
    assertEquals("Test table2", serverTable2.getGlobalAttribute());
    assertEquals("Test table1", serverTable2.getTable1().getGlobalAttribute1());
    // test server to client serialization
    data = serverService.serialize(table2);
    ClientMtTable2 clientTable2 = clientService.deserialize(data, 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) ROPSerializationService(org.apache.cayenne.rop.ROPSerializationService) Test(org.junit.Test)

Example 2 with ROPSerializationService

use of org.apache.cayenne.rop.ROPSerializationService 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)

Aggregations

ROPSerializationService (org.apache.cayenne.rop.ROPSerializationService)2 ClientMtTable1 (org.apache.cayenne.testdo.mt.ClientMtTable1)2 ClientMtTable2 (org.apache.cayenne.testdo.mt.ClientMtTable2)2 Test (org.junit.Test)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1