tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spmalle...@apache.org
Subject [2/2] tinkerpop git commit: Added a base graphson test class to centralize ser/der logic
Date Tue, 23 Aug 2016 10:58:17 GMT
Added a base graphson test class to centralize ser/der logic


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/0676a776
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/0676a776
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/0676a776

Branch: refs/heads/TINKERPOP-1278
Commit: 0676a77683f86c3095202e8da9486c7045205ed2
Parents: 41d79b8
Author: Stephen Mallette <spmva@genoprime.com>
Authored: Tue Aug 23 06:57:53 2016 -0400
Committer: Stephen Mallette <spmva@genoprime.com>
Committed: Tue Aug 23 06:57:53 2016 -0400

----------------------------------------------------------------------
 .../io/graphson/AbstractGraphSONTest.java       | 51 ++++++++++++++++++++
 .../GraphSONMapperEmbeddedTypeTest.java         | 41 ++++++----------
 ...aphSONMapperV2d0PartialEmbeddedTypeTest.java | 29 ++---------
 3 files changed, 70 insertions(+), 51 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0676a776/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/AbstractGraphSONTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/AbstractGraphSONTest.java
b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/AbstractGraphSONTest.java
new file mode 100644
index 0000000..dbff941
--- /dev/null
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/AbstractGraphSONTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.structure.io.graphson;
+
+import org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public abstract class AbstractGraphSONTest {
+
+    public static <T> T serializeDeserialize(final ObjectMapper mapper, final Object
o, final Class<T> clazz) throws Exception {
+        try (final ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
+            mapper.writeValue(stream, o);
+            try (final InputStream inputStream = new ByteArrayInputStream(stream.toByteArray()))
{
+                return mapper.readValue(inputStream, clazz);
+            }
+        }
+    }
+
+    public static <T> T serializeDeserializeAuto(final ObjectMapper mapper, final Object
o) throws Exception {
+        try (final ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
+            mapper.writeValue(stream, o);
+
+            try (final InputStream inputStream = new ByteArrayInputStream(stream.toByteArray()))
{
+                // Object.class is the wildcard that triggers the auto discovery.
+                return (T)mapper.readValue(inputStream, Object.class);
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0676a776/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperEmbeddedTypeTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperEmbeddedTypeTest.java
b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperEmbeddedTypeTest.java
index 6060a6d..716a803 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperEmbeddedTypeTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperEmbeddedTypeTest.java
@@ -23,9 +23,6 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
 import java.time.Duration;
 import java.time.Instant;
 import java.time.LocalDate;
@@ -47,7 +44,7 @@ import static org.junit.Assert.assertEquals;
  * @author Stephen Mallette (http://stephen.genoprime.com)
  */
 @RunWith(Parameterized.class)
-public class GraphSONMapperEmbeddedTypeTest {
+public class GraphSONMapperEmbeddedTypeTest extends AbstractGraphSONTest {
 
     @Parameterized.Parameters(name = "{0}")
     public static Iterable<Object[]> data() {
@@ -63,87 +60,77 @@ public class GraphSONMapperEmbeddedTypeTest {
     @Test
     public void shouldHandleDuration()throws Exception  {
         final Duration o = Duration.ZERO;
-        assertEquals(o, serializeDeserialize(o, Duration.class));
+        assertEquals(o, serializeDeserialize(mapper, o, Duration.class));
     }
     @Test
     public void shouldHandleInstant()throws Exception  {
         final Instant o = Instant.ofEpochMilli(System.currentTimeMillis());
-        assertEquals(o, serializeDeserialize(o, Instant.class));
+        assertEquals(o, serializeDeserialize(mapper, o, Instant.class));
     }
 
     @Test
     public void shouldHandleLocalDate()throws Exception  {
         final LocalDate o = LocalDate.now();
-        assertEquals(o, serializeDeserialize(o, LocalDate.class));
+        assertEquals(o, serializeDeserialize(mapper, o, LocalDate.class));
     }
 
     @Test
     public void shouldHandleLocalDateTime()throws Exception  {
         final LocalDateTime o = LocalDateTime.now();
-        assertEquals(o, serializeDeserialize(o, LocalDateTime.class));
+        assertEquals(o, serializeDeserialize(mapper, o, LocalDateTime.class));
     }
 
     @Test
     public void shouldHandleLocalTime()throws Exception  {
         final LocalTime o = LocalTime.now();
-        assertEquals(o, serializeDeserialize(o, LocalTime.class));
+        assertEquals(o, serializeDeserialize(mapper, o, LocalTime.class));
     }
 
     @Test
     public void shouldHandleMonthDay()throws Exception  {
         final MonthDay o = MonthDay.now();
-        assertEquals(o, serializeDeserialize(o, MonthDay.class));
+        assertEquals(o, serializeDeserialize(mapper, o, MonthDay.class));
     }
 
     @Test
     public void shouldHandleOffsetDateTime()throws Exception  {
         final OffsetDateTime o = OffsetDateTime.now();
-        assertEquals(o, serializeDeserialize(o, OffsetDateTime.class));
+        assertEquals(o, serializeDeserialize(mapper, o, OffsetDateTime.class));
     }
 
     @Test
     public void shouldHandleOffsetTime()throws Exception  {
         final OffsetTime o = OffsetTime.now();
-        assertEquals(o, serializeDeserialize(o, OffsetTime.class));
+        assertEquals(o, serializeDeserialize(mapper, o, OffsetTime.class));
     }
 
     @Test
     public void shouldHandlePeriod()throws Exception  {
         final Period o = Period.ofDays(3);
-        assertEquals(o, serializeDeserialize(o, Period.class));
+        assertEquals(o, serializeDeserialize(mapper, o, Period.class));
     }
 
     @Test
     public void shouldHandleYear()throws Exception  {
         final Year o = Year.now();
-        assertEquals(o, serializeDeserialize(o, Year.class));
+        assertEquals(o, serializeDeserialize(mapper, o, Year.class));
     }
 
     @Test
     public void shouldHandleYearMonth()throws Exception  {
         final YearMonth o = YearMonth.now();
-        assertEquals(o, serializeDeserialize(o, YearMonth.class));
+        assertEquals(o, serializeDeserialize(mapper, o, YearMonth.class));
     }
 
     @Test
     public void shouldHandleZonedDateTime()throws Exception  {
         final ZonedDateTime o = ZonedDateTime.now();
-        assertEquals(o, serializeDeserialize(o, ZonedDateTime.class));
+        assertEquals(o, serializeDeserialize(mapper, o, ZonedDateTime.class));
     }
 
     @Test
     public void shouldHandleZonedOffset()throws Exception  {
         final ZoneOffset o  = ZonedDateTime.now().getOffset();
-        assertEquals(o, serializeDeserialize(o, ZoneOffset.class));
-    }
-
-    public <T> T serializeDeserialize(final Object o, final Class<T> clazz) throws
Exception {
-        try (final ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
-            mapper.writeValue(stream, o);
-
-            try (final InputStream inputStream = new ByteArrayInputStream(stream.toByteArray()))
{
-                return mapper.readValue(inputStream, clazz);
-            }
-        }
+        assertEquals(o, serializeDeserialize(mapper, o, ZoneOffset.class));
     }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0676a776/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperV2d0PartialEmbeddedTypeTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperV2d0PartialEmbeddedTypeTest.java
b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperV2d0PartialEmbeddedTypeTest.java
index 0654283..ed10a93 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperV2d0PartialEmbeddedTypeTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperV2d0PartialEmbeddedTypeTest.java
@@ -46,7 +46,7 @@ import static org.junit.Assert.fail;
 /**
  * Tests automatic typed serialization/deserialization for GraphSON 2.0.
  */
-public class GraphSONMapperV2d0PartialEmbeddedTypeTest {
+public class GraphSONMapperV2d0PartialEmbeddedTypeTest extends AbstractGraphSONTest {
 
     private final ObjectMapper mapper = GraphSONMapper.build()
             .version(GraphSONVersion.V2_0)
@@ -77,7 +77,7 @@ public class GraphSONMapperV2d0PartialEmbeddedTypeTest {
 
         myList.add("kjkj");
         myList.add(UUID.randomUUID());
-        assertEquals(myList, serializeDeserializeAuto(myList));
+        assertEquals(myList, serializeDeserializeAuto(mapper, myList));
 
         // no "@value" property
         String s = "{\""+GraphSONTokens.VALUETYPE+"\":\""+GraphSONTokens.GREMLIN_TYPE_NAMESPACE
+":uuid\", \"test\":2}";
@@ -139,8 +139,8 @@ public class GraphSONMapperV2d0PartialEmbeddedTypeTest {
     public void shouldHandleRawPOJOs() throws Exception {
         final FunObject funObject = new FunObject();
         funObject.setVal("test");
-        assertEquals(funObject.toString(), serializeDeserialize(funObject, FunObject.class).toString());
-        assertEquals(funObject.getClass(), serializeDeserialize(funObject, FunObject.class).getClass());
+        assertEquals(funObject.toString(), serializeDeserialize(mapper, funObject, FunObject.class).toString());
+        assertEquals(funObject.getClass(), serializeDeserialize(mapper, funObject, FunObject.class).getClass());
     }
 
     @Test
@@ -250,7 +250,7 @@ public class GraphSONMapperV2d0PartialEmbeddedTypeTest {
     @Test
     public void shouldHandleDefaultRemoteTraverser() throws Exception {
         final DefaultRemoteTraverser<String> o = new DefaultRemoteTraverser<>("test",
100);
-        assertEquals(o, serializeDeserialize(o, Traverser.class));
+        assertEquals(o, serializeDeserialize(mapper, o, Traverser.class));
     }
 
     // Class needs to be defined as statics as it's a nested class.
@@ -273,24 +273,5 @@ public class GraphSONMapperV2d0PartialEmbeddedTypeTest {
         }
     }
 
-    public <T> T serializeDeserialize(final Object o, final Class<T> clazz) throws
Exception {
-        try (final ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
-            mapper.writeValue(stream, o);
-            try (final InputStream inputStream = new ByteArrayInputStream(stream.toByteArray()))
{
-                return mapper.readValue(inputStream, clazz);
-            }
-        }
-    }
-
-    public <T> T serializeDeserializeAuto(final Object o) throws Exception {
-        try (final ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
-            mapper.writeValue(stream, o);
-
-            try (final InputStream inputStream = new ByteArrayInputStream(stream.toByteArray()))
{
-                // Object.class is the wildcard that triggers the auto discovery.
-                return (T)mapper.readValue(inputStream, Object.class);
-            }
-        }
-    }
 
 }


Mime
View raw message