This is an automated email from the ASF dual-hosted git repository.

jorgebg pushed a commit to branch TINKERPOP-1942
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git


The following commit(s) were added to refs/heads/TINKERPOP-1942 by this push:
     new 95ce2b8  Test custom type support
95ce2b8 is described below

commit 95ce2b8dda6e395fc42ec67934eaa5a39519756b
Author: Jorge Bay Gondra <jorgebaygon...@gmail.com>
AuthorDate: Wed Nov 28 16:46:59 2018 +0100

    Test custom type support
---
 .../driver/ser/binary/types/sample/SamplePair.java |  0
 .../binary/types/sample/SamplePairSerializer.java  |  0
 .../ser/binary/types/sample/SamplePerson.java      |  3 ++
 .../types/sample/SamplePersonSerializer.java       |  3 ++
 .../types/sample/SamplePersonSerializerTest.java   | 55 ++++++++++++++++++++++
 5 files changed, 61 insertions(+)

diff --git 
a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/binary/types/sample/SamplePair.java
 
b/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/binary/types/sample/SamplePair.java
similarity index 100%
rename from 
gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/binary/types/sample/SamplePair.java
rename to 
gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/binary/types/sample/SamplePair.java
diff --git 
a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/binary/types/sample/SamplePairSerializer.java
 
b/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/binary/types/sample/SamplePairSerializer.java
similarity index 100%
rename from 
gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/binary/types/sample/SamplePairSerializer.java
rename to 
gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/binary/types/sample/SamplePairSerializer.java
diff --git 
a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/binary/types/sample/SamplePerson.java
 
b/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/binary/types/sample/SamplePerson.java
similarity index 92%
rename from 
gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/binary/types/sample/SamplePerson.java
rename to 
gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/binary/types/sample/SamplePerson.java
index 2784623..6f75f38 100644
--- 
a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/binary/types/sample/SamplePerson.java
+++ 
b/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/binary/types/sample/SamplePerson.java
@@ -19,6 +19,7 @@
 package org.apache.tinkerpop.gremlin.driver.ser.binary.types.sample;
 
 import java.util.Date;
+import java.util.Objects;
 
 /**
  * A sample custom data type containing few properties.
@@ -28,6 +29,8 @@ class SamplePerson {
     private final Date birthDate;
 
     SamplePerson(String name, Date birthDate) {
+        Objects.requireNonNull(name);
+        Objects.requireNonNull(birthDate);
 
         this.name = name;
         this.birthDate = birthDate;
diff --git 
a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/binary/types/sample/SamplePersonSerializer.java
 
b/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/binary/types/sample/SamplePersonSerializer.java
similarity index 97%
rename from 
gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/binary/types/sample/SamplePersonSerializer.java
rename to 
gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/binary/types/sample/SamplePersonSerializer.java
index 72375eb..07f678e 100644
--- 
a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/binary/types/sample/SamplePersonSerializer.java
+++ 
b/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/binary/types/sample/SamplePersonSerializer.java
@@ -56,6 +56,9 @@ class SamplePersonSerializer implements 
CustomTypeSerializer<SamplePerson> {
             return null;
         }
 
+        // Read the buffer int, no necessary in this case
+        buffer.readInt();
+
         return new SamplePerson(
                 context.readValue(buffer, String.class, false), 
context.readValue(buffer, Date.class,false));
     }
diff --git 
a/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/binary/types/sample/SamplePersonSerializerTest.java
 
b/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/binary/types/sample/SamplePersonSerializerTest.java
new file mode 100644
index 0000000..30b58b6
--- /dev/null
+++ 
b/gremlin-driver/src/test/java/org/apache/tinkerpop/gremlin/driver/ser/binary/types/sample/SamplePersonSerializerTest.java
@@ -0,0 +1,55 @@
+/*
+ * 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.
+ */
+package org.apache.tinkerpop.gremlin.driver.ser.binary.types.sample;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufAllocator;
+import org.apache.tinkerpop.gremlin.driver.message.ResponseMessage;
+import org.apache.tinkerpop.gremlin.driver.ser.GraphBinaryMessageSerializerV1;
+import org.apache.tinkerpop.gremlin.driver.ser.SerializationException;
+import org.apache.tinkerpop.gremlin.driver.ser.binary.TypeSerializerRegistry;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.internal.matchers.apachecommons.ReflectionEquals;
+
+import java.time.LocalDateTime;
+import java.time.ZoneOffset;
+import java.util.Date;
+import java.util.UUID;
+
+public class SamplePersonSerializerTest {
+
+    private final ByteBufAllocator allocator = ByteBufAllocator.DEFAULT;
+    private final GraphBinaryMessageSerializerV1 serializer = new 
GraphBinaryMessageSerializerV1(
+            TypeSerializerRegistry.build().addCustomType(SamplePerson.class, 
new SamplePersonSerializer()).create());
+
+    @Test
+    public void customSerializationWithPersonTest() throws 
SerializationException {
+        Date birthDate = Date.from(LocalDateTime.of(2010, 4, 29, 5, 
30).toInstant(ZoneOffset.UTC));
+        SamplePerson person = new SamplePerson("Olivia", birthDate);
+
+        ByteBuf serialized = serializer.serializeResponseAsBinary(
+                
ResponseMessage.build(UUID.randomUUID()).result(person).create(), allocator);
+
+        ResponseMessage deserialized = 
serializer.deserializeResponse(serialized);
+
+        SamplePerson actual = (SamplePerson) 
deserialized.getResult().getData();
+        Assert.assertThat(actual, new ReflectionEquals(person));
+    }
+}

Reply via email to