cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From skolbac...@apache.org
Subject [1/4] cayenne git commit: update Protostuff version; cleanup; add more tests;
Date Mon, 23 May 2016 14:42:36 GMT
Repository: cayenne
Updated Branches:
  refs/heads/master c117eb1e5 -> 9d24d06ce


update Protostuff version;
cleanup;
add more tests;


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/9d24d06c
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/9d24d06c
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/9d24d06c

Branch: refs/heads/master
Commit: 9d24d06ce68935013e6b572345761f0d2ebf1b4b
Parents: 5ce1af2
Author: Savva Kolbachev <s.kolbachev@gmail.com>
Authored: Mon May 23 17:18:09 2016 +0300
Committer: Savva Kolbachev <s.kolbachev@gmail.com>
Committed: Mon May 23 17:23:08 2016 +0300

----------------------------------------------------------------------
 cayenne-protostuff/pom.xml                      |   8 +-
 .../rop/client/ProtostuffModule.java            |   8 +-
 .../ProtostuffROPSerializationService.java      |  10 +-
 .../apache/cayenne/rop/protostuff/Wrapper.java  |   2 +
 .../query/PrefetchTreeNodeSchemaTest.java       |  62 ++++++
 .../ProtostuffPrefetchTreeNodeSchemaIT.java     |  62 ------
 .../service/ProtostuffLocalConnection.java      |  78 +++++++
 .../ProtostuffLocalConnectionProvider.java      |  40 ++++
 ...otostuffPersistentObjectCollectionsTest.java | 221 +++++++++++++++++++
 .../ProtostuffROPSerializationServiceIT.java    | 144 ++++--------
 .../ProtostuffROPSerializationTest.java         | 123 +++++++++++
 .../cayenne/rop/protostuff/RuntimeBase.java     |  75 +++++++
 .../src/test/resources/cayenne-protostuff.xml   |  13 ++
 13 files changed, 680 insertions(+), 166 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/9d24d06c/cayenne-protostuff/pom.xml
----------------------------------------------------------------------
diff --git a/cayenne-protostuff/pom.xml b/cayenne-protostuff/pom.xml
index 0934f64..23bc2d2 100644
--- a/cayenne-protostuff/pom.xml
+++ b/cayenne-protostuff/pom.xml
@@ -21,7 +21,7 @@
     <name>Cayenne Protostuff Extension</name>
 
     <properties>
-        <protostuff.version>1.4.2</protostuff.version>
+        <protostuff.version>1.4.3</protostuff.version>
     </properties>
 
     <dependencyManagement>
@@ -71,6 +71,12 @@
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>org.apache.cayenne</groupId>
+            <artifactId>cayenne-java8</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <scope>test</scope>

http://git-wip-us.apache.org/repos/asf/cayenne/blob/9d24d06c/cayenne-protostuff/src/main/java/org/apache/cayenne/configuration/rop/client/ProtostuffModule.java
----------------------------------------------------------------------
diff --git a/cayenne-protostuff/src/main/java/org/apache/cayenne/configuration/rop/client/ProtostuffModule.java
b/cayenne-protostuff/src/main/java/org/apache/cayenne/configuration/rop/client/ProtostuffModule.java
index 45d6d65..ccc5510 100644
--- a/cayenne-protostuff/src/main/java/org/apache/cayenne/configuration/rop/client/ProtostuffModule.java
+++ b/cayenne-protostuff/src/main/java/org/apache/cayenne/configuration/rop/client/ProtostuffModule.java
@@ -27,8 +27,12 @@ import org.apache.cayenne.rop.protostuff.ProtostuffROPSerializationService;
  * A DI module that uses Protostuff Object Graph Serialization as Cayenne {@link ROPSerializationService}.
  * <a href="http://www.protostuff.io/">
  *
- * Note the you usually have to add -Dprotostuff.runtime.collection_schema_on_repeated_fields=true
as VM option
- * because Cayenne objects might have cyclic collection fields.
+ * To use this module you should add the following system properties:
+ *      -Dprotostuff.runtime.collection_schema_on_repeated_fields=true
+ *      -Dprotostuff.runtime.morph_collection_interfaces=true
+ *      -Dprotostuff.runtime.morph_map_interfaces=true
+ *      -Dprotostuff.runtime.pojo_schema_on_collection_fields=true
+ *      -Dprotostuff.runtime.pojo_schema_on_map_fields=true
  *
  * @since 4.0
  */

http://git-wip-us.apache.org/repos/asf/cayenne/blob/9d24d06c/cayenne-protostuff/src/main/java/org/apache/cayenne/rop/protostuff/ProtostuffROPSerializationService.java
----------------------------------------------------------------------
diff --git a/cayenne-protostuff/src/main/java/org/apache/cayenne/rop/protostuff/ProtostuffROPSerializationService.java
b/cayenne-protostuff/src/main/java/org/apache/cayenne/rop/protostuff/ProtostuffROPSerializationService.java
index 371c42f..5e4a468 100644
--- a/cayenne-protostuff/src/main/java/org/apache/cayenne/rop/protostuff/ProtostuffROPSerializationService.java
+++ b/cayenne-protostuff/src/main/java/org/apache/cayenne/rop/protostuff/ProtostuffROPSerializationService.java
@@ -22,10 +22,13 @@ import io.protostuff.GraphIOUtil;
 import io.protostuff.LinkedBuffer;
 import io.protostuff.Schema;
 import io.protostuff.runtime.RuntimeSchema;
+import org.apache.cayenne.access.ToManyList;
 import org.apache.cayenne.query.PrefetchTreeNode;
 import org.apache.cayenne.query.PrefetchTreeNodeSchema;
 import org.apache.cayenne.rop.ROPSerializationService;
 import org.apache.cayenne.util.PersistentObjectList;
+import org.apache.cayenne.util.PersistentObjectMap;
+import org.apache.cayenne.util.PersistentObjectSet;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -42,13 +45,16 @@ public class ProtostuffROPSerializationService implements ROPSerializationServic
     protected Schema<Wrapper> wrapperSchema;
 
     public ProtostuffROPSerializationService() {
-        this.wrapperSchema = RuntimeSchema.getSchema(Wrapper.class);
         registerSchemas();
     }
 
     protected void registerSchemas() {
-        RuntimeSchema.register(PersistentObjectList.class, RuntimeSchema.getSchema(PersistentObjectList.class));
+        this.wrapperSchema = RuntimeSchema.getSchema(Wrapper.class);
         RuntimeSchema.register(PrefetchTreeNode.class, new PrefetchTreeNodeSchema());
+        RuntimeSchema.register(PersistentObjectList.class);
+        RuntimeSchema.register(PersistentObjectMap.class);
+        RuntimeSchema.register(PersistentObjectSet.class);
+        RuntimeSchema.register(ToManyList.class);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cayenne/blob/9d24d06c/cayenne-protostuff/src/main/java/org/apache/cayenne/rop/protostuff/Wrapper.java
----------------------------------------------------------------------
diff --git a/cayenne-protostuff/src/main/java/org/apache/cayenne/rop/protostuff/Wrapper.java
b/cayenne-protostuff/src/main/java/org/apache/cayenne/rop/protostuff/Wrapper.java
index c3679b0..3205b6d 100644
--- a/cayenne-protostuff/src/main/java/org/apache/cayenne/rop/protostuff/Wrapper.java
+++ b/cayenne-protostuff/src/main/java/org/apache/cayenne/rop/protostuff/Wrapper.java
@@ -26,6 +26,8 @@ import java.io.Serializable;
  * a simple wrapper for the root message.
  *
  * <a href="http://www.protostuff.io/documentation/object-graphs/">
+ *
+ * @since 4.0
  */
 public class Wrapper implements Serializable {
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/9d24d06c/cayenne-protostuff/src/test/java/org/apache/cayenne/query/PrefetchTreeNodeSchemaTest.java
----------------------------------------------------------------------
diff --git a/cayenne-protostuff/src/test/java/org/apache/cayenne/query/PrefetchTreeNodeSchemaTest.java
b/cayenne-protostuff/src/test/java/org/apache/cayenne/query/PrefetchTreeNodeSchemaTest.java
new file mode 100644
index 0000000..31365b2
--- /dev/null
+++ b/cayenne-protostuff/src/test/java/org/apache/cayenne/query/PrefetchTreeNodeSchemaTest.java
@@ -0,0 +1,62 @@
+/*****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ****************************************************************/
+
+package org.apache.cayenne.query;
+
+import org.apache.cayenne.rop.ROPSerializationService;
+import org.apache.cayenne.rop.protostuff.ProtostuffROPSerializationService;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+public class PrefetchTreeNodeSchemaTest {
+
+    private ROPSerializationService clientService;
+    private ROPSerializationService serverService;
+
+    @Before
+    public void setUp() throws Exception {
+        clientService = new ProtostuffROPSerializationService();
+        serverService = new ProtostuffROPSerializationService();
+    }
+
+    @Test
+    public void testPrefetchTreeNodeSchema() throws IOException {
+        PrefetchTreeNode parent = new PrefetchTreeNode(null, "parent");
+        PrefetchTreeNode child = new PrefetchTreeNode(parent, "child");
+        parent.addChild(child);
+
+        byte[] data = clientService.serialize(parent);
+        PrefetchTreeNode parent0 = serverService.deserialize(data, PrefetchTreeNode.class);
+
+        assertNotNull(parent0);
+        assertTrue(parent0.hasChildren());
+
+        PrefetchTreeNode child0 = parent0.getChild("child");
+        assertNotNull(child0);
+        assertNotNull(child0.parent);
+        assertEquals(child0.parent, parent0);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/9d24d06c/cayenne-protostuff/src/test/java/org/apache/cayenne/query/ProtostuffPrefetchTreeNodeSchemaIT.java
----------------------------------------------------------------------
diff --git a/cayenne-protostuff/src/test/java/org/apache/cayenne/query/ProtostuffPrefetchTreeNodeSchemaIT.java
b/cayenne-protostuff/src/test/java/org/apache/cayenne/query/ProtostuffPrefetchTreeNodeSchemaIT.java
deleted file mode 100644
index 3f182b4..0000000
--- a/cayenne-protostuff/src/test/java/org/apache/cayenne/query/ProtostuffPrefetchTreeNodeSchemaIT.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- ****************************************************************/
-
-package org.apache.cayenne.query;
-
-import org.apache.cayenne.rop.ROPSerializationService;
-import org.apache.cayenne.rop.protostuff.ProtostuffROPSerializationService;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.io.IOException;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-public class ProtostuffPrefetchTreeNodeSchemaIT {
-
-    private ROPSerializationService clientService;
-    private ROPSerializationService serverService;
-
-    @Before
-    public void setUp() throws Exception {
-        clientService = new ProtostuffROPSerializationService();
-        serverService = new ProtostuffROPSerializationService();
-    }
-
-    @Test
-    public void testPrefetchTreeNodeSchema() throws IOException {
-        PrefetchTreeNode parent = new PrefetchTreeNode(null, "parent");
-        PrefetchTreeNode child = new PrefetchTreeNode(parent, "child");
-        parent.addChild(child);
-
-        byte[] data = clientService.serialize(parent);
-        PrefetchTreeNode parent0 = serverService.deserialize(data, PrefetchTreeNode.class);
-
-        assertNotNull(parent0);
-        assertTrue(parent0.hasChildren());
-
-        PrefetchTreeNode child0 = parent0.getChild("child");
-        assertNotNull(child0);
-        assertNotNull(child0.parent);
-        assertEquals(child0.parent, parent0);
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/9d24d06c/cayenne-protostuff/src/test/java/org/apache/cayenne/remote/service/ProtostuffLocalConnection.java
----------------------------------------------------------------------
diff --git a/cayenne-protostuff/src/test/java/org/apache/cayenne/remote/service/ProtostuffLocalConnection.java
b/cayenne-protostuff/src/test/java/org/apache/cayenne/remote/service/ProtostuffLocalConnection.java
new file mode 100644
index 0000000..0545308
--- /dev/null
+++ b/cayenne-protostuff/src/test/java/org/apache/cayenne/remote/service/ProtostuffLocalConnection.java
@@ -0,0 +1,78 @@
+/*****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ****************************************************************/
+
+package org.apache.cayenne.remote.service;
+import org.apache.cayenne.CayenneRuntimeException;
+import org.apache.cayenne.DataChannel;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.event.EventBridge;
+import org.apache.cayenne.remote.BaseConnection;
+import org.apache.cayenne.remote.ClientMessage;
+import org.apache.cayenne.rop.ROPSerializationService;
+
+import java.io.IOException;
+
+/**
+ * A ClientConnection that connects to a DataChannel. Used as an emulator of a remote
+ * service. Emulation includes serialization/deserialization of objects via {@link ROPSerializationService}.
+ *
+ * {@link LocalConnection} should be replaced by this one after moving all ROP functionality
to the separate module.
+ * It'll provide more flexibility around which serialization should be used.
+ */
+public class ProtostuffLocalConnection extends BaseConnection {
+
+    protected DataChannel channel;
+
+    @Inject
+    private ROPSerializationService serializationService;
+
+    public ProtostuffLocalConnection(DataChannel channel) {
+        this.channel = channel;
+    }
+
+    @Override
+    public EventBridge getServerEventBridge() throws CayenneRuntimeException {
+        return null;
+    }
+
+    @Override
+    protected void beforeSendMessage(ClientMessage message) throws CayenneRuntimeException
{
+        // noop
+    }
+
+    @Override
+    protected Object doSendMessage(ClientMessage message) throws CayenneRuntimeException
{
+        try {
+            ClientMessage processedMessage = (ClientMessage) cloneViaSerializationService(message);
+
+            Object result = DispatchHelper.dispatch(channel, processedMessage);
+
+            return cloneViaSerializationService(result);
+        }
+        catch (Exception ex) {
+            throw new CayenneRuntimeException("Error deserializing result", ex);
+        }
+    }
+
+    public Object cloneViaSerializationService(Object object) throws IOException {
+        byte[] data = serializationService.serialize(object);
+        return serializationService.deserialize(data, object.getClass());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/9d24d06c/cayenne-protostuff/src/test/java/org/apache/cayenne/remote/service/ProtostuffLocalConnectionProvider.java
----------------------------------------------------------------------
diff --git a/cayenne-protostuff/src/test/java/org/apache/cayenne/remote/service/ProtostuffLocalConnectionProvider.java
b/cayenne-protostuff/src/test/java/org/apache/cayenne/remote/service/ProtostuffLocalConnectionProvider.java
new file mode 100644
index 0000000..9cae2d1
--- /dev/null
+++ b/cayenne-protostuff/src/test/java/org/apache/cayenne/remote/service/ProtostuffLocalConnectionProvider.java
@@ -0,0 +1,40 @@
+/*****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ****************************************************************/
+
+package org.apache.cayenne.remote.service;
+
+import org.apache.cayenne.ConfigurationException;
+import org.apache.cayenne.DataChannel;
+import org.apache.cayenne.configuration.rop.client.ClientLocalRuntime;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.di.Provider;
+import org.apache.cayenne.remote.ClientConnection;
+
+public class ProtostuffLocalConnectionProvider implements Provider<ClientConnection>
{
+
+    @Inject(ClientLocalRuntime.CLIENT_SERVER_CHANNEL_KEY)
+    protected Provider<DataChannel> clientServerChannelProvider;
+
+    @Override
+    public ClientConnection get() throws ConfigurationException {
+        DataChannel clientServerChannel = clientServerChannelProvider.get();
+        return new ProtostuffLocalConnection(clientServerChannel);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/9d24d06c/cayenne-protostuff/src/test/java/org/apache/cayenne/rop/protostuff/ProtostuffPersistentObjectCollectionsTest.java
----------------------------------------------------------------------
diff --git a/cayenne-protostuff/src/test/java/org/apache/cayenne/rop/protostuff/ProtostuffPersistentObjectCollectionsTest.java
b/cayenne-protostuff/src/test/java/org/apache/cayenne/rop/protostuff/ProtostuffPersistentObjectCollectionsTest.java
new file mode 100644
index 0000000..0e70ac4
--- /dev/null
+++ b/cayenne-protostuff/src/test/java/org/apache/cayenne/rop/protostuff/ProtostuffPersistentObjectCollectionsTest.java
@@ -0,0 +1,221 @@
+/*****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ****************************************************************/
+
+package org.apache.cayenne.rop.protostuff;
+
+import org.apache.cayenne.PersistentObject;
+import org.apache.cayenne.reflect.MapAccessor;
+import org.apache.cayenne.rop.ROPSerializationService;
+import org.apache.cayenne.util.PersistentObjectList;
+import org.apache.cayenne.util.PersistentObjectMap;
+import org.apache.cayenne.util.PersistentObjectSet;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+public class ProtostuffPersistentObjectCollectionsTest {
+
+    static {
+        System.setProperty("protostuff.runtime.collection_schema_on_repeated_fields", "true");
+        System.setProperty("protostuff.runtime.morph_collection_interfaces", "true");
+        System.setProperty("protostuff.runtime.morph_map_interfaces", "true");
+        System.setProperty("protostuff.runtime.pojo_schema_on_collection_fields", "true");
+        System.setProperty("protostuff.runtime.pojo_schema_on_map_fields", "true");
+    }
+
+    private ROPSerializationService clientService;
+    private ROPSerializationService serverService;
+
+    private TestObject object1;
+    private TestObject object2;
+
+    @Before
+    public void setUp() throws Exception {
+        clientService = new ProtostuffROPSerializationService();
+        serverService = new ProtostuffROPSerializationService();
+
+        object1 = new TestObject();
+        object2 = new TestObject();
+        object1.name = "object1";
+        object2.name = "object2";
+        object1.object = object2;
+    }
+
+    @Test
+    public void testPersistentObjectList() throws IOException {
+        PersistentObjectList list = new PersistentObjectList(object1, "test");
+        list.add(object2);
+
+        byte[] bytes = serverService.serialize(list);
+        PersistentObjectList list0 = clientService.deserialize(bytes, PersistentObjectList.class);
+
+        assertNotNull(list0);
+        assertEquals(list.getRelationshipName(), list0.getRelationshipName());
+        assertEquals(list.getRelationshipOwner(), list0.getRelationshipOwner());
+
+        Object object0 = list0.get(0);
+        assertEquals(object2, object0);
+    }
+
+    @Test
+    public void testPersistentObjectListWithWrapper() throws IOException {
+        PersistentObjectList list = new PersistentObjectList(object1, "test");
+        list.add(object2);
+
+        byte[] bytes = serverService.serialize(new ListWrapper(list));
+        ListWrapper lw = clientService.deserialize(bytes, ListWrapper.class);
+
+        assertNotNull(lw.object);
+        assertTrue(lw.object instanceof PersistentObjectList);
+
+        PersistentObjectList list0 = (PersistentObjectList) lw.object;
+        assertEquals(list.getRelationshipName(), list0.getRelationshipName());
+        assertEquals(list.getRelationshipOwner(), list0.getRelationshipOwner());
+
+        Object object0 = list0.get(0);
+        assertEquals(object2, object0);
+    }
+
+    @Test
+    public void testPersistentObjectSet() throws IOException {
+        PersistentObjectSet set = new PersistentObjectSet(object1, "test");
+        set.add(object2);
+
+        byte[] bytes = serverService.serialize(set);
+        PersistentObjectSet set0 = clientService.deserialize(bytes, PersistentObjectSet.class);
+
+        assertNotNull(set0);
+        assertEquals(set.getRelationshipName(), set0.getRelationshipName());
+        assertEquals(set.getRelationshipOwner(), set0.getRelationshipOwner());
+
+        Object object0 = set0.toArray()[0];
+        assertEquals(object2, object0);
+    }
+
+    @Test
+    public void testPersistentObjectSetWithWrapper() throws IOException {
+        PersistentObjectSet set = new PersistentObjectSet(object1, "test");
+        set.add(object2);
+
+        byte[] bytes = serverService.serialize(new SetWrapper(set));
+        SetWrapper sw = clientService.deserialize(bytes, SetWrapper.class);
+
+        assertNotNull(sw.object);
+        assertTrue(sw.object instanceof PersistentObjectSet);
+
+        PersistentObjectSet set0 = (PersistentObjectSet) sw.object;
+        assertNotNull(set0);
+        assertEquals(set.getRelationshipName(), set0.getRelationshipName());
+        assertEquals(set.getRelationshipOwner(), set0.getRelationshipOwner());
+
+        Object object0 = set0.toArray()[0];
+        assertEquals(object2, object0);
+    }
+
+    @Test
+    public void testPersistentObjectMap() throws IOException {
+        PersistentObjectMap map = new PersistentObjectMap(object1, "test", new MapAccessor("test"));
+        map.put(object2.name, object2);
+
+        byte[] bytes = serverService.serialize(map);
+        PersistentObjectMap map0 = clientService.deserialize(bytes, PersistentObjectMap.class);
+
+        assertNotNull(map0);
+        assertEquals(map0.getRelationshipName(), map0.getRelationshipName());
+        assertEquals(map0.getRelationshipOwner(), map0.getRelationshipOwner());
+
+        Object object0 = map0.get(object2.name);
+        assertEquals(object2, object0);
+    }
+
+    @Test
+    public void testPersistentObjectMapWithWrapper() throws IOException {
+        PersistentObjectMap map = new PersistentObjectMap(object1, "test", new MapAccessor("test"));
+        map.put(object2.name, object2);
+
+        byte[] bytes = serverService.serialize(new MapWrapper(map));
+        MapWrapper mw = clientService.deserialize(bytes, MapWrapper.class);
+
+        assertNotNull(mw.object);
+        assertTrue(mw.object instanceof PersistentObjectMap);
+
+        PersistentObjectMap map0 = (PersistentObjectMap) mw.object;
+        assertEquals(map0.getRelationshipName(), map0.getRelationshipName());
+        assertEquals(map0.getRelationshipOwner(), map0.getRelationshipOwner());
+
+        Object object0 = map0.get(object2.name);
+        assertEquals(object2, object0);
+    }
+
+    private static class TestObject extends PersistentObject {
+        public String name;
+        public TestObject object;
+
+        @Override
+        public boolean equals(Object o) {
+            if (this == o) return true;
+            if (!(o instanceof TestObject)) return false;
+
+            TestObject that = (TestObject) o;
+
+            if (name != null ? !name.equals(that.name) : that.name != null) return false;
+            return object != null ? object.equals(that.object) : that.object == null;
+
+        }
+
+        @Override
+        public int hashCode() {
+            int result = name != null ? name.hashCode() : 0;
+            result = 31 * result + (object != null ? object.hashCode() : 0);
+            return result;
+        }
+    }
+
+    private static class ListWrapper {
+        List<?> object;
+
+        public ListWrapper(List<?> object) {
+            this.object = object;
+        }
+    }
+
+    private static class SetWrapper {
+        Set<?> object;
+
+        public SetWrapper(Set<?> object) {
+            this.object = object;
+        }
+    }
+
+    private static class MapWrapper {
+        Map<?, ?> object;
+
+        public MapWrapper(Map<?, ?> object) {
+            this.object = object;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/9d24d06c/cayenne-protostuff/src/test/java/org/apache/cayenne/rop/protostuff/ProtostuffROPSerializationServiceIT.java
----------------------------------------------------------------------
diff --git a/cayenne-protostuff/src/test/java/org/apache/cayenne/rop/protostuff/ProtostuffROPSerializationServiceIT.java
b/cayenne-protostuff/src/test/java/org/apache/cayenne/rop/protostuff/ProtostuffROPSerializationServiceIT.java
index 0b73dd6..578b4fa 100644
--- a/cayenne-protostuff/src/test/java/org/apache/cayenne/rop/protostuff/ProtostuffROPSerializationServiceIT.java
+++ b/cayenne-protostuff/src/test/java/org/apache/cayenne/rop/protostuff/ProtostuffROPSerializationServiceIT.java
@@ -1,137 +1,83 @@
 /*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
  ****************************************************************/
 package org.apache.cayenne.rop.protostuff;
 
-import org.apache.cayenne.ObjectContext;
-import org.apache.cayenne.configuration.rop.client.ClientLocalRuntime;
-import org.apache.cayenne.configuration.rop.client.ClientRuntime;
-import org.apache.cayenne.configuration.rop.client.ProtostuffModule;
-import org.apache.cayenne.configuration.server.ServerRuntime;
-import org.apache.cayenne.rop.ROPSerializationService;
+import org.apache.cayenne.query.ObjectSelect;
 import org.apache.cayenne.rop.protostuff.persistent.ClientMtTable1;
 import org.apache.cayenne.rop.protostuff.persistent.ClientMtTable2;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.time.LocalDate;
-import java.time.LocalDateTime;
-import java.time.LocalTime;
-import java.util.Collections;
-import java.util.Date;
 
 import static org.junit.Assert.assertEquals;
 
-public class ProtostuffROPSerializationServiceIT {
-
-    private static final String GLOBAL_ATTRIBUTE1 = "Test table1";
-    private static final String GLOBAL_ATTRIBUTE2 = "Test table2";
+public class ProtostuffROPSerializationServiceIT extends RuntimeBase {
 
     private ClientMtTable1 table1;
     private ClientMtTable2 table2;
 
-    private Date oldDate;
-    private LocalDate localDate;
-    private LocalTime localTime;
-    private LocalDateTime localDateTime;
-
-    private ROPSerializationService clientService;
-    private ROPSerializationService serverService;
-
     @Before
     public void setUp() throws Exception {
-        ClientRuntime clientRuntime = new ClientLocalRuntime(
-                new ServerRuntime("cayenne-protostuff.xml").getInjector(),
-                Collections.emptyMap(),
-                new ProtostuffModule());
-
-        ObjectContext context = clientRuntime.newContext();
-
-        oldDate = new Date();
-        localDate = LocalDate.now();
-        localTime = LocalTime.now();
-        localDateTime = LocalDateTime.now();
+        context = clientRuntime.newContext();
 
         table1 = context.newObject(ClientMtTable1.class);
-        table1.setGlobalAttribute(GLOBAL_ATTRIBUTE1);
-        table1.setOldDateAttribute(oldDate);
-        table1.setDateAttribute(localDate);
-        table1.setTimeAttribute(localTime);
-        table1.setTimestampAttribute(localDateTime);
+        table1.setGlobalAttribute("table1");
+        table1.setDateAttribute(LocalDate.now());
 
         table2 = context.newObject(ClientMtTable2.class);
+        table2.setGlobalAttribute("table2");
+
+        table1.addToTable2Array(table2);
         table2.setTable1(table1);
-        table2.setGlobalAttribute(GLOBAL_ATTRIBUTE2);
 
-        clientService = new ProtostuffROPSerializationService();
-        serverService = new ProtostuffROPSerializationService();
+        context.commitChanges();
     }
 
-    @Test
-    public void testByteArraySerialization() throws Exception {
-        // test client to server serialization
-        byte[] data = clientService.serialize(table2);
-        ClientMtTable2 serverTable2 = serverService.deserialize(data, ClientMtTable2.class);
-
-        assertCorrectness(serverTable2);
-
-        // test server to client serialization
-        data = serverService.serialize(table2);
-        ClientMtTable2 clientTable2 = clientService.deserialize(data, ClientMtTable2.class);
-
-        assertCorrectness(clientTable2);
+    @After
+    public void setDown() throws Exception {
+        context.deleteObjects(table2, table1);
+        context.commitChanges();
     }
 
     @Test
-    public void testStreamSerialization() throws Exception {
-
-        // test client to server serialization
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        clientService.serialize(table2, out);
-        out.flush();
-
-        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
-        ClientMtTable2 serverTable2 = serverService.deserialize(in, ClientMtTable2.class);
-
-        assertCorrectness(serverTable2);
+    public void testSerializationWithPrefetch1() throws Exception {
+        ClientMtTable1 table1 = ObjectSelect.query(ClientMtTable1.class)
+                .prefetch(ClientMtTable1.TABLE2ARRAY.joint())
+                .selectOne(context);
 
-        // test server to client serialization
-        out = new ByteArrayOutputStream();
-        serverService.serialize(table2, out);
-        out.flush();
+        ClientMtTable2 table2 = table1.getTable2Array().get(0);
 
-        in = new ByteArrayInputStream(out.toByteArray());
-        ClientMtTable2 clientTable2 = clientService.deserialize(in, ClientMtTable2.class);
-
-        assertCorrectness(clientTable2);
+        assertEquals(this.table1, table1);
+        assertEquals(this.table2, table2);
     }
 
-    private void assertCorrectness(ClientMtTable2 table2) {
+    @Test
+    public void testSerializationWithPrefetch2() throws Exception {
+        ClientMtTable2 table2 = ObjectSelect.query(ClientMtTable2.class)
+                .prefetch(ClientMtTable2.TABLE1.joint())
+                .selectOne(context);
+
         ClientMtTable1 table1 = table2.getTable1();
 
-        assertEquals(GLOBAL_ATTRIBUTE2, table2.getGlobalAttribute());
-        assertEquals(GLOBAL_ATTRIBUTE1, table1.getGlobalAttribute());
-        assertEquals(oldDate, table1.getOldDateAttribute());
-        assertEquals(localDate, table1.getDateAttribute());
-        assertEquals(localTime, table1.getTimeAttribute());
-        assertEquals(localDateTime, table1.getTimestampAttribute());
+        assertEquals(this.table1, table1);
+        assertEquals(this.table2, table2);
     }
-
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/9d24d06c/cayenne-protostuff/src/test/java/org/apache/cayenne/rop/protostuff/ProtostuffROPSerializationTest.java
----------------------------------------------------------------------
diff --git a/cayenne-protostuff/src/test/java/org/apache/cayenne/rop/protostuff/ProtostuffROPSerializationTest.java
b/cayenne-protostuff/src/test/java/org/apache/cayenne/rop/protostuff/ProtostuffROPSerializationTest.java
new file mode 100644
index 0000000..8fc5bce
--- /dev/null
+++ b/cayenne-protostuff/src/test/java/org/apache/cayenne/rop/protostuff/ProtostuffROPSerializationTest.java
@@ -0,0 +1,123 @@
+/*****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ****************************************************************/
+
+package org.apache.cayenne.rop.protostuff;
+
+import org.apache.cayenne.rop.ROPSerializationService;
+import org.apache.cayenne.rop.protostuff.persistent.ClientMtTable1;
+import org.apache.cayenne.rop.protostuff.persistent.ClientMtTable2;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.util.Date;
+
+import static org.junit.Assert.assertEquals;
+
+public class ProtostuffROPSerializationTest {
+
+    private static final String GLOBAL_ATTRIBUTE1 = "Test table1";
+    private static final String GLOBAL_ATTRIBUTE2 = "Test table2";
+
+    private ClientMtTable1 table1;
+    private ClientMtTable2 table2;
+
+    private Date oldDate;
+    private LocalDate localDate;
+    private LocalTime localTime;
+    private LocalDateTime localDateTime;
+
+    private ROPSerializationService clientService;
+    private ROPSerializationService serverService;
+
+    @Before
+    public void setUpData() throws Exception {
+        oldDate = new Date();
+        localDate = LocalDate.now();
+        localTime = LocalTime.now();
+        localDateTime = LocalDateTime.now();
+
+        table1 = new ClientMtTable1();
+        table1.setGlobalAttribute(GLOBAL_ATTRIBUTE1);
+        table1.setOldDateAttribute(oldDate);
+        table1.setDateAttribute(localDate);
+        table1.setTimeAttribute(localTime);
+        table1.setTimestampAttribute(localDateTime);
+
+        table2 = new ClientMtTable2();
+        table2.setTable1(table1);
+        table2.setGlobalAttribute(GLOBAL_ATTRIBUTE2);
+
+        clientService = new ProtostuffROPSerializationService();
+        serverService = new ProtostuffROPSerializationService();
+    }
+
+    @Test
+    public void testByteArraySerialization() throws Exception {
+        // test client to server serialization
+        byte[] data = clientService.serialize(table2);
+        ClientMtTable2 serverTable2 = serverService.deserialize(data, ClientMtTable2.class);
+
+        assertCorrectness(serverTable2);
+
+        // test server to client serialization
+        data = serverService.serialize(table2);
+        ClientMtTable2 clientTable2 = clientService.deserialize(data, ClientMtTable2.class);
+
+        assertCorrectness(clientTable2);
+    }
+
+    @Test
+    public void testStreamSerialization() throws Exception {
+        // test client to server serialization
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        clientService.serialize(table2, out);
+        out.flush();
+
+        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+        ClientMtTable2 serverTable2 = serverService.deserialize(in, ClientMtTable2.class);
+
+        assertCorrectness(serverTable2);
+
+        // test server to client serialization
+        out = new ByteArrayOutputStream();
+        serverService.serialize(table2, out);
+        out.flush();
+
+        in = new ByteArrayInputStream(out.toByteArray());
+        ClientMtTable2 clientTable2 = clientService.deserialize(in, ClientMtTable2.class);
+
+        assertCorrectness(clientTable2);
+    }
+
+    private void assertCorrectness(ClientMtTable2 table2) {
+        ClientMtTable1 table1 = table2.getTable1();
+        assertEquals(GLOBAL_ATTRIBUTE2, table2.getGlobalAttribute());
+        assertEquals(GLOBAL_ATTRIBUTE1, table1.getGlobalAttribute());
+        assertEquals(oldDate, table1.getOldDateAttribute());
+        assertEquals(localDate, table1.getDateAttribute());
+        assertEquals(localTime, table1.getTimeAttribute());
+        assertEquals(localDateTime, table1.getTimestampAttribute());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/9d24d06c/cayenne-protostuff/src/test/java/org/apache/cayenne/rop/protostuff/RuntimeBase.java
----------------------------------------------------------------------
diff --git a/cayenne-protostuff/src/test/java/org/apache/cayenne/rop/protostuff/RuntimeBase.java
b/cayenne-protostuff/src/test/java/org/apache/cayenne/rop/protostuff/RuntimeBase.java
new file mode 100644
index 0000000..5207ef1
--- /dev/null
+++ b/cayenne-protostuff/src/test/java/org/apache/cayenne/rop/protostuff/RuntimeBase.java
@@ -0,0 +1,75 @@
+/*****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ****************************************************************/
+
+package org.apache.cayenne.rop.protostuff;
+
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.configuration.Constants;
+import org.apache.cayenne.configuration.rop.client.ClientLocalRuntime;
+import org.apache.cayenne.configuration.rop.client.ClientRuntime;
+import org.apache.cayenne.configuration.rop.client.ProtostuffModule;
+import org.apache.cayenne.configuration.server.ServerRuntime;
+import org.apache.cayenne.di.Module;
+import org.apache.cayenne.java8.CayenneJava8Module;
+import org.apache.cayenne.remote.ClientConnection;
+import org.apache.cayenne.remote.service.ProtostuffLocalConnectionProvider;
+import org.junit.Before;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class RuntimeBase {
+
+    protected ServerRuntime serverRuntime;
+    protected ClientRuntime clientRuntime;
+    protected ObjectContext context;
+
+
+    static {
+        System.setProperty("protostuff.runtime.collection_schema_on_repeated_fields", "true");
+        System.setProperty("protostuff.runtime.morph_collection_interfaces", "true");
+        System.setProperty("protostuff.runtime.morph_map_interfaces", "true");
+        System.setProperty("protostuff.runtime.pojo_schema_on_collection_fields", "true");
+        System.setProperty("protostuff.runtime.pojo_schema_on_map_fields", "true");
+    }
+
+    @Before
+    public void setUpRuntimes() throws Exception {
+        this.serverRuntime = new ServerRuntime("cayenne-protostuff.xml",
+                new ProtostuffModule(),
+                new CayenneJava8Module());
+
+        Map<String, String> properties = new HashMap<>();
+        properties.put(Constants.ROP_CHANNEL_EVENTS_PROPERTY, Boolean.TRUE.toString());
+
+        Module module = binder -> binder.bind(ClientConnection.class)
+                .toProviderInstance(new ProtostuffLocalConnectionProvider());
+
+        this.clientRuntime = new ClientLocalRuntime(
+                serverRuntime.getInjector(),
+                properties,
+                new ProtostuffModule(),
+                new CayenneJava8Module(),
+                module);
+
+        this.context = clientRuntime.newContext();
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/9d24d06c/cayenne-protostuff/src/test/resources/cayenne-protostuff.xml
----------------------------------------------------------------------
diff --git a/cayenne-protostuff/src/test/resources/cayenne-protostuff.xml b/cayenne-protostuff/src/test/resources/cayenne-protostuff.xml
index 3d2049e..e585624 100644
--- a/cayenne-protostuff/src/test/resources/cayenne-protostuff.xml
+++ b/cayenne-protostuff/src/test/resources/cayenne-protostuff.xml
@@ -1,4 +1,17 @@
 <?xml version="1.0" encoding="utf-8"?>
 <domain project-version="8">
 	<map name="protostuff"/>
+
+	<node name="datanode"
+		  factory="org.apache.cayenne.configuration.server.XMLPoolingDataSourceFactory"
+		  schema-update-strategy="org.apache.cayenne.access.dbsync.CreateIfNoSchemaStrategy"
+	>
+		<map-ref name="protostuff"/>
+		<data-source>
+			<driver value="org.hsqldb.jdbcDriver"/>
+			<url value="jdbc:hsqldb:mem:protostuff"/>
+			<connectionPool min="1" max="1"/>
+			<login userName="sa"/>
+		</data-source>
+	</node>
 </domain>


Mime
View raw message