You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2016/08/23 10:44:20 UTC
[2/4] tinkerpop git commit: Refactor and combine some graphson 2.0
tests.
Refactor and combine some graphson 2.0 tests.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/5739326b
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/5739326b
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/5739326b
Branch: refs/heads/TINKERPOP-1278
Commit: 5739326b381e92da700ceda38e4cb24e37f2e59e
Parents: 4eff70d
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue Aug 23 06:32:56 2016 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue Aug 23 06:32:56 2016 -0400
----------------------------------------------------------------------
.../GraphSONTraversalSerializersV2d0.java | 67 +++++----
.../GraphSONMapperEmbeddedTypeTest.java | 3 +-
...hSONMapperV1d0ToV2d0BuilderSettingsTest.java | 86 -----------
...aphSONMapperV2d0PartialEmbeddedTypeTest.java | 144 ++++++-------------
4 files changed, 79 insertions(+), 221 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5739326b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTraversalSerializersV2d0.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTraversalSerializersV2d0.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTraversalSerializersV2d0.java
index 6bad444..796e225 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTraversalSerializersV2d0.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONTraversalSerializersV2d0.java
@@ -29,7 +29,6 @@ import org.apache.tinkerpop.gremlin.process.traversal.SackFunctions;
import org.apache.tinkerpop.gremlin.process.traversal.Scope;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
-import org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree;
import org.apache.tinkerpop.gremlin.process.traversal.util.AndP;
import org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP;
import org.apache.tinkerpop.gremlin.process.traversal.util.OrP;
@@ -92,7 +91,7 @@ final class GraphSONTraversalSerializersV2d0 {
public void serialize(final Bytecode bytecode, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
throws IOException {
jsonGenerator.writeStartObject();
- jsonGenerator.writeStringField("@type", "Bytecode");
+ jsonGenerator.writeStringField(GraphSONTokens.VALUETYPE, "Bytecode");
if (bytecode.getSourceInstructions().iterator().hasNext()) {
jsonGenerator.writeArrayFieldStart("source");
for (final Bytecode.Instruction instruction : bytecode.getSourceInstructions()) {
@@ -132,8 +131,8 @@ final class GraphSONTraversalSerializersV2d0 {
public void serialize(final Enum enumInstance, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
throws IOException {
jsonGenerator.writeStartObject();
- jsonGenerator.writeObjectField("@type", enumInstance.getDeclaringClass().getSimpleName());
- jsonGenerator.writeObjectField("value", enumInstance.name());
+ jsonGenerator.writeObjectField(GraphSONTokens.VALUETYPE, enumInstance.getDeclaringClass().getSimpleName());
+ jsonGenerator.writeObjectField(GraphSONTokens.VALUE, enumInstance.name());
jsonGenerator.writeEndObject();
}
@@ -149,9 +148,9 @@ final class GraphSONTraversalSerializersV2d0 {
public void serialize(final P p, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
throws IOException {
jsonGenerator.writeStartObject();
- jsonGenerator.writeStringField("@type", "P");
+ jsonGenerator.writeStringField(GraphSONTokens.VALUETYPE, "P");
jsonGenerator.writeStringField("predicate", p instanceof ConnectiveP ? p instanceof AndP ? "and" : "or" : p.getBiPredicate().toString());
- jsonGenerator.writeObjectField("value", p instanceof ConnectiveP ? ((ConnectiveP) p).getPredicates() : p.getValue());
+ jsonGenerator.writeObjectField(GraphSONTokens.VALUE, p instanceof ConnectiveP ? ((ConnectiveP) p).getPredicates() : p.getValue());
jsonGenerator.writeEndObject();
}
@@ -167,8 +166,8 @@ final class GraphSONTraversalSerializersV2d0 {
public void serialize(final Lambda lambda, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
throws IOException {
jsonGenerator.writeStartObject();
- jsonGenerator.writeStringField("@type", "Lambda");
- jsonGenerator.writeStringField("value", lambda.getLambdaScript());
+ jsonGenerator.writeStringField(GraphSONTokens.VALUETYPE, "Lambda");
+ jsonGenerator.writeStringField(GraphSONTokens.VALUE, lambda.getLambdaScript());
jsonGenerator.writeStringField("language", lambda.getLambdaLanguage());
jsonGenerator.writeNumberField("arguments", lambda.getLambdaArguments());
jsonGenerator.writeEndObject();
@@ -186,9 +185,9 @@ final class GraphSONTraversalSerializersV2d0 {
public void serialize(final Bytecode.Binding binding, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider)
throws IOException {
jsonGenerator.writeStartObject();
- jsonGenerator.writeStringField("@type", "Binding");
+ jsonGenerator.writeStringField(GraphSONTokens.VALUETYPE, "Binding");
jsonGenerator.writeStringField("variable", binding.variable());
- jsonGenerator.writeObjectField("value", binding.value());
+ jsonGenerator.writeObjectField(GraphSONTokens.VALUE, binding.value());
jsonGenerator.writeEndObject();
}
@@ -214,9 +213,9 @@ final class GraphSONTraversalSerializersV2d0 {
private void ser(final Traverser traverserInstance, final JsonGenerator jsonGenerator) throws IOException {
jsonGenerator.writeStartObject();
- jsonGenerator.writeStringField("@type", "Traverser");
+ jsonGenerator.writeStringField(GraphSONTokens.VALUETYPE, "Traverser");
jsonGenerator.writeObjectField("bulk", traverserInstance.bulk());
- jsonGenerator.writeObjectField("value", traverserInstance.get());
+ jsonGenerator.writeObjectField(GraphSONTokens.VALUE, traverserInstance.get());
jsonGenerator.writeEndObject();
}
}
@@ -237,8 +236,8 @@ final class GraphSONTraversalSerializersV2d0 {
for (int j = 1; j < instruction.size(); j++) {
final JsonNode argument = instruction.get(j);
if (argument.getNodeType().equals(JsonNodeType.OBJECT)) {
- if (argument.has("@type")) {
- final String type = argument.get("@type").textValue();
+ if (argument.has(GraphSONTokens.VALUETYPE)) {
+ final String type = argument.get(GraphSONTokens.VALUETYPE).textValue();
if (type.equals("Bytecode"))
arguments.add(oc.readValue(argument.traverse(oc), Bytecode.class));
else if (type.equals("Binding"))
@@ -280,7 +279,7 @@ final class GraphSONTraversalSerializersV2d0 {
final Bytecode bytecode = new Bytecode();
final ObjectCodec oc = jsonParser.getCodec();
final JsonNode node = oc.readTree(jsonParser);
- assert node.get("@type").textValue().equals("Bytecode");
+ assert node.get(GraphSONTokens.VALUETYPE).textValue().equals("Bytecode");
if (node.has("source")) {
final JsonNode source = node.get("source");
for (int i = 0; i < source.size(); i++) {
@@ -309,25 +308,25 @@ final class GraphSONTraversalSerializersV2d0 {
final ObjectCodec oc = jsonParser.getCodec();
final JsonNode node = oc.readTree(jsonParser);
- final String type = node.get("@type").textValue();
+ final String type = node.get(GraphSONTokens.VALUETYPE).textValue();
if (type.equals("Cardinality"))
- return VertexProperty.Cardinality.valueOf(node.get("value").textValue());
+ return VertexProperty.Cardinality.valueOf(node.get(GraphSONTokens.VALUE).textValue());
else if (type.equals("Column"))
- return Column.valueOf(node.get("value").textValue());
+ return Column.valueOf(node.get(GraphSONTokens.VALUE).textValue());
else if (type.equals("Direction"))
- return Direction.valueOf(node.get("value").textValue());
+ return Direction.valueOf(node.get(GraphSONTokens.VALUE).textValue());
else if (type.equals("Barrier"))
- return SackFunctions.Barrier.valueOf(node.get("value").textValue());
+ return SackFunctions.Barrier.valueOf(node.get(GraphSONTokens.VALUE).textValue());
else if (type.equals("Operator"))
- return Operator.valueOf(node.get("value").textValue());
+ return Operator.valueOf(node.get(GraphSONTokens.VALUE).textValue());
else if (type.equals("Order"))
- return Order.valueOf(node.get("value").textValue());
+ return Order.valueOf(node.get(GraphSONTokens.VALUE).textValue());
else if (type.equals("Pop"))
- return Pop.valueOf(node.get("value").textValue());
+ return Pop.valueOf(node.get(GraphSONTokens.VALUE).textValue());
else if (type.equals("Scope"))
- return Scope.valueOf(node.get("value").textValue());
+ return Scope.valueOf(node.get(GraphSONTokens.VALUE).textValue());
else if (type.equals("T"))
- return T.valueOf(node.get("value").textValue());
+ return T.valueOf(node.get(GraphSONTokens.VALUE).textValue());
else
throw new IOException("Unknown enum type: " + type);
@@ -345,17 +344,17 @@ final class GraphSONTraversalSerializersV2d0 {
final ObjectCodec oc = jsonParser.getCodec();
final JsonNode node = oc.readTree(jsonParser);
- assert node.get("@type").textValue().equals("P");
+ assert node.get(GraphSONTokens.VALUETYPE).textValue().equals("P");
final JsonNode predicate = node.get("predicate");
if (predicate.textValue().equals("and") || predicate.textValue().equals("or")) {
final List<P<?>> arguments = new ArrayList<>();
- for (int i = 0; i < node.get("value").size(); i++) {
- arguments.add(oc.readValue(node.get("value").get(i).traverse(oc), P.class));
+ for (int i = 0; i < node.get(GraphSONTokens.VALUE).size(); i++) {
+ arguments.add(oc.readValue(node.get(GraphSONTokens.VALUE).get(i).traverse(oc), P.class));
}
return predicate.textValue().equals("and") ? new AndP(arguments) : new OrP(arguments);
} else {
try {
- final Object argument = oc.readValue(node.get("value").traverse(oc), Object.class);
+ final Object argument = oc.readValue(node.get(GraphSONTokens.VALUE).traverse(oc), Object.class);
return (P) P.class.getMethod(predicate.textValue(), argument instanceof Collection ? Collection.class : Object.class).invoke(null, argument); // TODO: number stuff, eh?
} catch (final Exception e) {
throw new IOException(e.getMessage(), e);
@@ -375,8 +374,8 @@ final class GraphSONTraversalSerializersV2d0 {
final ObjectCodec oc = jsonParser.getCodec();
final JsonNode node = oc.readTree(jsonParser);
- assert node.get("@type").textValue().equals("Lambda");
- final String lambdaScript = node.get("value").textValue();
+ assert node.get(GraphSONTokens.VALUETYPE).textValue().equals("Lambda");
+ final String lambdaScript = node.get(GraphSONTokens.VALUE).textValue();
final String lambdaLanguage = node.get("language").textValue();
final int lambdaArguments = node.get("arguments").intValue();
if (-1 == lambdaArguments || lambdaArguments > 2)
@@ -400,9 +399,9 @@ final class GraphSONTraversalSerializersV2d0 {
public Bytecode.Binding deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
final ObjectCodec oc = jsonParser.getCodec();
final JsonNode node = oc.readTree(jsonParser);
- assert node.get("@type").textValue().equals("Binding");
+ assert node.get(GraphSONTokens.VALUETYPE).textValue().equals("Binding");
final String variable = node.get("variable").textValue();
- final Object value = oc.readValue(node.get("value").traverse(oc), Object.class);
+ final Object value = oc.readValue(node.get(GraphSONTokens.VALUE).traverse(oc), Object.class);
return new Bytecode.Binding<>(variable, value);
}
}
@@ -418,7 +417,7 @@ final class GraphSONTraversalSerializersV2d0 {
jsonParser.nextToken();
// This will automatically parse all typed stuff.
final Map<String, Object> mapData = deserializationContext.readValue(jsonParser, Map.class);
- return new DefaultRemoteTraverser<>(mapData.get("value"), (Long) mapData.get("bulk"));
+ return new DefaultRemoteTraverser<>(mapData.get(GraphSONTokens.VALUE), (Long) mapData.get("bulk"));
}
}
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5739326b/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 7b197b6..6060a6d 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
@@ -53,8 +53,7 @@ public class GraphSONMapperEmbeddedTypeTest {
public static Iterable<Object[]> data() {
return Arrays.asList(new Object[][]{
{GraphSONMapper.build().version(GraphSONVersion.V1_0).embedTypes(true).create().createMapper()},
- {GraphSONMapper.build().version(GraphSONVersion.V2_0).typeInfo(TypeInfo.PARTIAL_TYPES).create()
- .createMapper()},
+ {GraphSONMapper.build().version(GraphSONVersion.V2_0).typeInfo(TypeInfo.PARTIAL_TYPES).create().createMapper()},
});
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5739326b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperV1d0ToV2d0BuilderSettingsTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperV1d0ToV2d0BuilderSettingsTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperV1d0ToV2d0BuilderSettingsTest.java
deleted file mode 100644
index 50600ee..0000000
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapperV1d0ToV2d0BuilderSettingsTest.java
+++ /dev/null
@@ -1,86 +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
- *
- * 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 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;
-import java.time.LocalDateTime;
-import java.time.LocalTime;
-import java.time.MonthDay;
-import java.time.OffsetDateTime;
-import java.time.OffsetTime;
-import java.time.Period;
-import java.time.Year;
-import java.time.YearMonth;
-import java.time.ZoneOffset;
-import java.time.ZonedDateTime;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.junit.Assert.assertEquals;
-
-/**
- * @author Stephen Mallette (http://stephen.genoprime.com)
- */
-public class GraphSONMapperV1d0ToV2d0BuilderSettingsTest {
-
- @Test
- public void shouldHandleMapWithTypesUsingEmbedTypeSetting() throws Exception {
- final ObjectMapper mapper = GraphSONMapper.build()
- .version(GraphSONVersion.V1_0)
- .typeInfo(TypeInfo.PARTIAL_TYPES)
- .create()
- .createMapper();
-
- final Map<String,Object> m = new HashMap<>();
- m.put("test", 100L);
-
- final String json = mapper.writeValueAsString(m);
- final Map read = mapper.readValue(json, HashMap.class);
-
- assertEquals(100L, read.get("test"));
- }
-
- @Test
- public void shouldNotHandleMapWithTypesUsingEmbedTypeSetting() throws Exception {
- final ObjectMapper mapper = GraphSONMapper.build()
- .version(GraphSONVersion.V1_0)
- .typeInfo(TypeInfo.NO_TYPES)
- .create()
- .createMapper();
-
- final Map<String,Object> m = new HashMap<>();
- m.put("test", 100L);
-
- final String json = mapper.writeValueAsString(m);
- final Map read = mapper.readValue(json, HashMap.class);
-
- assertEquals(100, read.get("test"));
- }
-}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5739326b/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 c78505b..d1b7b52 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
@@ -27,17 +27,7 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.time.Duration;
import java.time.Instant;
-import java.time.LocalDate;
-import java.time.LocalDateTime;
-import java.time.LocalTime;
-import java.time.MonthDay;
-import java.time.OffsetDateTime;
-import java.time.OffsetTime;
-import java.time.Period;
-import java.time.Year;
-import java.time.YearMonth;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.ArrayList;
@@ -65,94 +55,16 @@ public class GraphSONMapperV2d0PartialEmbeddedTypeTest {
.createMapper();
@Test
- public void shouldHandleDurationAuto() throws Exception {
- final Duration o = Duration.ZERO;
- assertEquals(o, serializeDeserializeAuto(o));
- }
-
- @Test
- public void shouldHandleInstantAuto() throws Exception {
- final Instant o = Instant.ofEpochMilli(System.currentTimeMillis());
- assertEquals(o, serializeDeserializeAuto(o));
- }
-
- @Test
- public void shouldHandleLocalDateAuto() throws Exception {
- final LocalDate o = LocalDate.now();
- assertEquals(o, serializeDeserializeAuto(o));
- }
-
- @Test
- public void shouldHandleLocalDateTimeAuto() throws Exception {
- final LocalDateTime o = LocalDateTime.now();
- assertEquals(o, serializeDeserializeAuto(o));
- }
-
- @Test
- public void shouldHandleLocalTimeAuto() throws Exception {
- final LocalTime o = LocalTime.now();
- assertEquals(o, serializeDeserializeAuto(o));
- }
-
- @Test
- public void shouldHandleMonthDayAuto() throws Exception {
- final MonthDay o = MonthDay.now();
- assertEquals(o, serializeDeserializeAuto(o));
- }
-
- @Test
- public void shouldHandleOffsetDateTimeAuto() throws Exception {
- final OffsetDateTime o = OffsetDateTime.now();
- assertEquals(o, serializeDeserializeAuto(o));
- }
-
- @Test
- public void shouldHandleOffsetTimeAuto() throws Exception {
- final OffsetTime o = OffsetTime.now();
- assertEquals(o, serializeDeserializeAuto(o));
- }
-
- @Test
- public void shouldHandlePeriodAuto() throws Exception {
- final Period o = Period.ofDays(3);
- assertEquals(o, serializeDeserializeAuto(o));
- }
-
- @Test
- public void shouldHandleYearAuto() throws Exception {
- final Year o = Year.now();
- assertEquals(o, serializeDeserializeAuto(o));
- }
-
- @Test
- public void shouldHandleYearMonthAuto() throws Exception {
- final YearMonth o = YearMonth.now();
- assertEquals(o, serializeDeserializeAuto(o));
- }
-
- @Test
- public void shouldHandleZonedDateTimeAuto() throws Exception {
- final ZonedDateTime o = ZonedDateTime.now();
- assertEquals(o, serializeDeserializeAuto(o));
- }
-
- @Test
- public void shouldHandleZonedOffsetAuto() throws Exception {
- final ZoneOffset o = ZonedDateTime.now().getOffset();
- assertEquals(o, serializeDeserializeAuto(o));
- }
-
- @Test
- // Trying to fail the TypeDeserializer type detection
public void shouldSerializeDeserializeNestedCollectionsAndMapAndTypedValuesCorrectly() throws Exception {
+ // Trying to fail the TypeDeserializer type detection
final UUID uuid = UUID.randomUUID();
- final List myList = new ArrayList<>();
+ final List<Object> myList = new ArrayList<>();
- final List myList2 = new ArrayList<>();
+ final List<Object> myList2 = new ArrayList<>();
myList2.add(UUID.randomUUID());
myList2.add(33L);
myList2.add(84);
- final Map map2 = new HashMap<>();
+ final Map<String,Object> map2 = new HashMap<>();
map2.put("eheh", UUID.randomUUID());
map2.put("normal", "normal");
myList2.add(map2);
@@ -169,7 +81,7 @@ public class GraphSONMapperV2d0PartialEmbeddedTypeTest {
// no "@value" property
String s = "{\""+GraphSONTokens.VALUETYPE+"\":\""+GraphSONTokens.GREMLIN_TYPE_NAMESPACE +":uuid\", \"test\":2}";
- Map map = new LinkedHashMap<>();
+ Map<String,Object> map = new LinkedHashMap<>();
map.put(GraphSONTokens.VALUETYPE, "gremlin:uuid");
map.put("test", 2);
Object res = mapper.readValue(s, Object.class);
@@ -232,7 +144,7 @@ public class GraphSONMapperV2d0PartialEmbeddedTypeTest {
}
@Test
- public void shouldHandleMapWithTypesUsingEmbedTypeSetting() throws Exception {
+ public void shouldHandleMapWithTypesUsingEmbedTypeSettingV2d0() throws Exception {
final ObjectMapper mapper = GraphSONMapper.build()
.version(GraphSONVersion.V2_0)
.embedTypes(true)
@@ -249,7 +161,7 @@ public class GraphSONMapperV2d0PartialEmbeddedTypeTest {
}
@Test
- public void shouldNotHandleMapWithTypesUsingEmbedTypeSetting() throws Exception {
+ public void shouldNotHandleMapWithTypesUsingEmbedTypeSettingV2d0() throws Exception {
final ObjectMapper mapper = GraphSONMapper.build()
.version(GraphSONVersion.V2_0)
.embedTypes(false)
@@ -266,6 +178,40 @@ public class GraphSONMapperV2d0PartialEmbeddedTypeTest {
}
@Test
+ public void shouldHandleMapWithTypesUsingEmbedTypeSettingV1d0() throws Exception {
+ final ObjectMapper mapper = GraphSONMapper.build()
+ .version(GraphSONVersion.V1_0)
+ .typeInfo(TypeInfo.PARTIAL_TYPES)
+ .create()
+ .createMapper();
+
+ final Map<String,Object> m = new HashMap<>();
+ m.put("test", 100L);
+
+ final String json = mapper.writeValueAsString(m);
+ final Map read = mapper.readValue(json, HashMap.class);
+
+ assertEquals(100L, read.get("test"));
+ }
+
+ @Test
+ public void shouldNotHandleMapWithTypesUsingEmbedTypeSettingV1d0() throws Exception {
+ final ObjectMapper mapper = GraphSONMapper.build()
+ .version(GraphSONVersion.V1_0)
+ .typeInfo(TypeInfo.NO_TYPES)
+ .create()
+ .createMapper();
+
+ final Map<String,Object> m = new HashMap<>();
+ m.put("test", 100L);
+
+ final String json = mapper.writeValueAsString(m);
+ final Map read = mapper.readValue(json, HashMap.class);
+
+ assertEquals(100, read.get("test"));
+ }
+
+ @Test
public void shouldLooseTypesInfoWithGraphSONNoType() throws Exception {
final ObjectMapper mapper = GraphSONMapper.build()
.version(GraphSONVersion.V2_0)
@@ -274,13 +220,13 @@ public class GraphSONMapperV2d0PartialEmbeddedTypeTest {
.createMapper();
final UUID uuid = UUID.randomUUID();
- final List myList = new ArrayList<>();
+ final List<Object> myList = new ArrayList<>();
- final List myList2 = new ArrayList<>();
+ final List<Object> myList2 = new ArrayList<>();
myList2.add(UUID.randomUUID());
myList2.add(33L);
myList2.add(84);
- final Map map2 = new HashMap<>();
+ final Map<String,Object> map2 = new HashMap<>();
map2.put("eheh", UUID.randomUUID());
map2.put("normal", "normal");
myList2.add(map2);
@@ -330,7 +276,7 @@ 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);
-
+ final String s=mapper.writeValueAsString(o);
try (final InputStream inputStream = new ByteArrayInputStream(stream.toByteArray())) {
return mapper.readValue(inputStream, clazz);
}