org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper Java Examples

The following examples show how to use org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GeoshapeTest.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testGeoJsonPolygonNotBox2() throws IOException {
    Geoshape.GeoshapeSerializer s = new Geoshape.GeoshapeSerializer();
    Map json = new ObjectMapper().readValue("{\n" +
            "  \"type\": \"Feature\",\n" +
            "  \"geometry\": {\n" +
            "    \"type\": \"Polygon\",\n" +
            "    \"coordinates\": [[20.5, 10.5],[22.5, 10.5],[22.5, 12.5]]\n" +
            "  },\n" +
            "  \"properties\": {\n" +
            "    \"name\": \"Dinagat Islands\"\n" +
            "  }\n" +
            "}", HashMap.class);
     s.convert(json);

}
 
Example #2
Source File: SerializationTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldSerializeTraversalMetrics() throws Exception {
    final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().version(GraphSONVersion.V2_0).create().createMapper();
    final TraversalMetrics before = g.V().both().profile().next();
    final String json = mapper.writeValueAsString(before);
    final TraversalMetrics after = mapper.readValue(json, TraversalMetrics.class);

    assertNotNull(after);
    assertEquals(before.getMetrics().size(), after.getMetrics().size());
    assertEquals(before.getDuration(TimeUnit.MILLISECONDS), after.getDuration(TimeUnit.MILLISECONDS));
    assertEquals(before.getMetrics().size(), after.getMetrics().size());

    before.getMetrics().forEach(b -> {
        final Optional<? extends Metrics> mFromA = after.getMetrics().stream().filter(a -> b.getId().equals(a.getId())).findFirst();
        if (mFromA.isPresent()) {
            final Metrics m = mFromA.get();
            assertEquals(b.getAnnotations(), m.getAnnotations());
            assertEquals(b.getCounts(), m.getCounts());
            assertEquals(b.getName(), m.getName());
            assertEquals(b.getDuration(TimeUnit.MILLISECONDS), m.getDuration(TimeUnit.MILLISECONDS));
        } else {
            fail("Metrics were not present after deserialization");
        }
    });
}
 
Example #3
Source File: GraphSONMapperPartialEmbeddedTypeTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@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"));
}
 
Example #4
Source File: GraphSONMapperPartialEmbeddedTypeTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@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"));
}
 
Example #5
Source File: GraphSONMapperPartialEmbeddedTypeTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldNotHandleMapWithTypesUsingEmbedTypeSettingV2d0() throws Exception {
    final ObjectMapper mapper = GraphSONMapper.build()
            .version(GraphSONVersion.V2_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"));
}
 
Example #6
Source File: GraphSONMapperPartialEmbeddedTypeTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldHandleMapWithTypesUsingEmbedTypeSettingV2d0() throws Exception {
    final ObjectMapper mapper = GraphSONMapper.build()
            .version(GraphSONVersion.V2_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"));
}
 
Example #7
Source File: SerializationTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldSerializeVertex() throws Exception {
    final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V1_0)).mapper().version(GraphSONVersion.V1_0).create().createMapper();
    final Vertex v = graph.vertices(convertToVertexId("marko")).next();
    final String json = mapper.writeValueAsString(v);
    final Map<String, Object> m = mapper.readValue(json, mapTypeReference);

    assertEquals(GraphSONTokens.VERTEX, m.get(GraphSONTokens.TYPE));
    assertEquals(v.label(), m.get(GraphSONTokens.LABEL));
    assertNotNull(m.get(GraphSONTokens.ID));
    final Map<String,List<Map<String,Object>>> properties = (Map<String,List<Map<String,Object>>>) m.get(GraphSONTokens.PROPERTIES);
    assertEquals(v.value("name").toString(), properties.get("name").get(0).get(GraphSONTokens.VALUE).toString());
    assertEquals((Integer) v.value("age"), properties.get("age").get(0).get(GraphSONTokens.VALUE));
    assertEquals(1, properties.get("name").size());
    assertEquals(1, properties.get("age").size());
    assertEquals(2, properties.size());
}
 
Example #8
Source File: GraphSONMessageSerializerV2d0Test.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldSerializeAndDeserializeResponseMessageFromObjectMapper() throws IOException {
    final ObjectMapper om = GraphSONMapper.build().version(GraphSONVersion.V2_0)
            .addCustomModule(new GraphSONMessageSerializerGremlinV2d0.GremlinServerModule())
            .create().createMapper();
    final Graph graph = TinkerFactory.createModern();

    final ResponseMessage responseMessage = ResponseMessage.build(UUID.fromString("41d2e28a-20a4-4ab0-b379-d810dede3786")).
            code(org.apache.tinkerpop.gremlin.driver.message.ResponseStatusCode.SUCCESS).
            result(Collections.singletonList(graph.vertices().next())).create();

    final String respJson = om.writeValueAsString(responseMessage);
    final ResponseMessage responseMessageRead = om.readValue(respJson, ResponseMessage.class);

    assertEquals(responseMessage.getRequestId(), responseMessageRead.getRequestId());
    assertEquals(responseMessage.getResult().getMeta(), responseMessageRead.getResult().getMeta());
    assertEquals(responseMessage.getResult().getData(), responseMessageRead.getResult().getData());
    assertEquals(responseMessage.getStatus().getAttributes(), responseMessageRead.getStatus().getAttributes());
    assertEquals(responseMessage.getStatus().getCode().getValue(), responseMessageRead.getStatus().getCode().getValue());
    assertEquals(responseMessage.getStatus().getCode().isSuccess(), responseMessageRead.getStatus().getCode().isSuccess());
    assertEquals(responseMessage.getStatus().getMessage(), responseMessageRead.getStatus().getMessage());
}
 
Example #9
Source File: GraphSONMessageSerializerV2d0Test.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldSerializeAndDeserializeRequestMessageFromObjectMapper() throws IOException {
    final ObjectMapper om = GraphSONMapper.build().version(GraphSONVersion.V2_0)
            .addCustomModule(new GraphSONMessageSerializerGremlinV2d0.GremlinServerModule())
            .create().createMapper();

    final Map<String, Object> requestBindings = new HashMap<>();
    requestBindings.put("x", 1);

    final Map<String, Object> requestAliases = new HashMap<>();
    requestAliases.put("g", "social");

    final RequestMessage requestMessage = RequestMessage.build("eval").processor("session").
            overrideRequestId(UUID.fromString("cb682578-9d92-4499-9ebc-5c6aa73c5397")).
            add("gremlin", "social.V(x)", "bindings", requestBindings, "language", "gremlin-groovy", "aliases", requestAliases, "session", UUID.fromString("41d2e28a-20a4-4ab0-b379-d810dede3786")).create();

    final String json = om.writeValueAsString(requestMessage);
    final RequestMessage readRequestMessage = om.readValue(json, RequestMessage.class);

    assertEquals(requestMessage.getOp(), readRequestMessage.getOp());
    assertEquals(requestMessage.getProcessor(), readRequestMessage.getProcessor());
    assertEquals(requestMessage.getRequestId(), readRequestMessage.getRequestId());
    assertEquals(requestMessage.getArgs(), readRequestMessage.getArgs());
}
 
Example #10
Source File: SerializationTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
@LoadGraphWith(LoadGraphWith.GraphData.CREW)
public void shouldSerializeVertexPropertyWithProperties() throws Exception {
    final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V3_0)).mapper().version(GraphSONVersion.V3_0).create().createMapper();
    final VertexProperty vp = IteratorUtils.filter(graph.vertices(convertToVertexId("marko")).next().properties("location"), p -> p.value().equals("brussels")).next();
    final String json = mapper.writeValueAsString(vp);
    final VertexProperty<?> detached = mapper.readValue(json, VertexProperty.class);

    assertNotNull(detached);
    assertEquals(vp.label(), detached.label());
    assertEquals(vp.id(), detached.id());
    assertEquals(vp.value(), detached.value());
    assertEquals(vp.values("startTime").next(), detached.values("startTime").next());
    assertEquals(((Property) vp.properties("startTime").next()).key(), ((Property) detached.properties("startTime").next()).key());
    assertEquals(vp.values("endTime").next(), detached.values("endTime").next());
    assertEquals(((Property) vp.properties("endTime").next()).key(), ((Property) detached.properties("endTime").next()).key());
}
 
Example #11
Source File: GeoshapeTest.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
@Test(expected = IllegalArgumentException.class)
public void testGeoJsonPolygonNotBox1() throws IOException {
    Geoshape.GeoshapeSerializer s = new Geoshape.GeoshapeSerializer();
    Map json = new ObjectMapper().readValue("{\n" +
            "  \"type\": \"Feature\",\n" +
            "  \"geometry\": {\n" +
            "    \"type\": \"Polygon\",\n" +
            "    \"coordinates\": [[20.5, 12.5],[22.5, 12.5],[22.5, 10.5],[20.5, 10.6]]\n" +
            "  },\n" +
            "  \"properties\": {\n" +
            "    \"name\": \"Dinagat Islands\"\n" +
            "  }\n" +
            "}", HashMap.class);
    s.convert(json);

}
 
Example #12
Source File: SerializationTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
@LoadGraphWith(LoadGraphWith.GraphData.CREW)
public void shouldSerializeVertexPropertyWithProperties() throws Exception {
    final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().version(GraphSONVersion.V2_0).create().createMapper();
    final VertexProperty vp = IteratorUtils.filter(graph.vertices(convertToVertexId("marko")).next().properties("location"), p -> p.value().equals("brussels")).next();
    final String json = mapper.writeValueAsString(vp);
    final VertexProperty<?> detached = mapper.readValue(json, VertexProperty.class);

    assertNotNull(detached);
    assertEquals(vp.label(), detached.label());
    assertEquals(vp.id(), detached.id());
    assertEquals(vp.value(), detached.value());
    assertEquals(vp.values("startTime").next(), detached.values("startTime").next());
    assertEquals(((Property) vp.properties("startTime").next()).key(), ((Property) detached.properties("startTime").next()).key());
    assertEquals(vp.values("endTime").next(), detached.values("endTime").next());
    assertEquals(((Property) vp.properties("endTime").next()).key(), ((Property) detached.properties("endTime").next()).key());
}
 
Example #13
Source File: SerializationTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldSerializeTraversalMetrics() throws Exception {
    final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V3_0)).mapper().version(GraphSONVersion.V3_0).create().createMapper();
    final TraversalMetrics before = g.V().both().profile().next();
    final String json = mapper.writeValueAsString(before);
    final TraversalMetrics after = mapper.readValue(json, TraversalMetrics.class);

    assertNotNull(after);
    assertEquals(before.getMetrics().size(), after.getMetrics().size());
    assertEquals(before.getDuration(TimeUnit.MILLISECONDS), after.getDuration(TimeUnit.MILLISECONDS));
    assertEquals(before.getMetrics().size(), after.getMetrics().size());

    before.getMetrics().forEach(b -> {
        final Optional<? extends Metrics> mFromA = after.getMetrics().stream().filter(a -> b.getId().equals(a.getId())).findFirst();
        if (mFromA.isPresent()) {
            final Metrics m = mFromA.get();
            assertEquals(b.getAnnotations(), m.getAnnotations());
            assertEquals(b.getCounts(), m.getCounts());
            assertEquals(b.getName(), m.getName());
            assertEquals(b.getDuration(TimeUnit.MILLISECONDS), m.getDuration(TimeUnit.MILLISECONDS));
        } else {
            fail("Metrics were not present after deserialization");
        }
    });
}
 
Example #14
Source File: GeoshapeTest.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
@Test
public void testGeoJsonCircle() throws IOException {
    Geoshape.GeoshapeSerializer s = new Geoshape.GeoshapeSerializer();
    Map json = new ObjectMapper().readValue("{\n" +
            "  \"type\": \"Feature\",\n" +
            "  \"geometry\": {\n" +
            "    \"type\": \"Circle\",\n" +
            "    \"radius\": 30.5, " +
            "    \"coordinates\": [20.5, 10.5]\n" +
            "  },\n" +
            "  \"properties\": {\n" +
            "    \"name\": \"Dinagat Islands\"\n" +
            "  }\n" +
            "}", HashMap.class);
    assertEquals(Geoshape.circle(10.5, 20.5, 30.5), s.convert(json));
}
 
Example #15
Source File: CustomTest.java    From hgraphdb with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Ignore
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldSerializeTraversalMetrics() throws Exception {
    final ObjectMapper mapper = graph.io(GraphSONIo.build()).mapper().create().createMapper();
    final TraversalMetrics tm = (TraversalMetrics) g.V().both().profile().next();
    final String json = mapper.writeValueAsString(tm);
    final Map<String, Object> m = mapper.readValue(json, mapTypeReference);

    assertTrue(m.containsKey(GraphSONTokens.DURATION));
    assertTrue(m.containsKey(GraphSONTokens.METRICS));

    final List<Map<String, Object>> metrics = (List<Map<String, Object>>) m.get(GraphSONTokens.METRICS);
    assertEquals(2, metrics.size());

    final Map<String, Object> metrics0 = metrics.get(0);
    assertTrue(metrics0.containsKey(GraphSONTokens.ID));
    assertTrue(metrics0.containsKey(GraphSONTokens.NAME));
    assertTrue(metrics0.containsKey(GraphSONTokens.COUNTS));
    assertTrue(metrics0.containsKey(GraphSONTokens.DURATION));
}
 
Example #16
Source File: SerializationTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldSerializeTraversalMetrics() throws Exception {
    final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V1_0)).mapper().version(GraphSONVersion.V1_0).create().createMapper();
    final TraversalMetrics tm = g.V().both().profile().next();
    final String json = mapper.writeValueAsString(tm);
    final Map<String, Object> m = mapper.readValue(json, mapTypeReference);

    assertTrue(m.containsKey(GraphSONTokens.DURATION));
    assertTrue(m.containsKey(GraphSONTokens.METRICS));

    final List<Map<String, Object>> metrics = (List<Map<String, Object>>) m.get(GraphSONTokens.METRICS);
    assertEquals(tm.getMetrics().size(), metrics.size());

    final Map<String, Object> metrics0 = metrics.get(0);
    assertTrue(metrics0.containsKey(GraphSONTokens.ID));
    assertTrue(metrics0.containsKey(GraphSONTokens.NAME));
    assertTrue(metrics0.containsKey(GraphSONTokens.COUNTS));
    assertTrue(metrics0.containsKey(GraphSONTokens.DURATION));
}
 
Example #17
Source File: SerializationTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldSerializeProperty() throws Exception {
    final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V3_0)).mapper().version(GraphSONVersion.V3_0).create().createMapper();
    final Property p = g.E(convertToEdgeId("marko", "knows", "vadas")).next().property("weight");
    final String json = mapper.writeValueAsString(p);
    final Property detached = mapper.readValue(json, Property.class);

    assertNotNull(detached);
    assertEquals(p.key(), detached.key());
    assertEquals(p.value(), detached.value());
}
 
Example #18
Source File: SerializationTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldSerializePath() throws Exception {
    final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().version(GraphSONVersion.V2_0).create().createMapper();
    final Path p = g.V(convertToVertexId("marko")).as("a").outE().as("b").inV().as("c").path()
            .filter(t -> ((Vertex) t.get().objects().get(2)).value("name").equals("lop")).next();
    final String json = mapper.writeValueAsString(p);
    final Path detached = mapper.readValue(json, Path.class);

    assertNotNull(detached);
    assertEquals(p.labels().size(), detached.labels().size());
    assertEquals(p.labels().get(0).size(), detached.labels().get(0).size());
    assertEquals(p.labels().get(1).size(), detached.labels().get(1).size());
    assertEquals(p.labels().get(2).size(), detached.labels().get(2).size());
    assertTrue(p.labels().stream().flatMap(Collection::stream).allMatch(detached::hasLabel));

    final Vertex vOut = p.get("a");
    final Vertex detachedVOut = detached.get("a");
    assertEquals(vOut.label(), detachedVOut.label());
    assertEquals(vOut.id(), detachedVOut.id());

    // this is a SimpleTraverser so no properties are present in detachment
    assertFalse(detachedVOut.properties().hasNext());

    final Edge e = p.get("b");
    final Edge detachedE = detached.get("b");
    assertEquals(e.label(), detachedE.label());
    assertEquals(e.id(), detachedE.id());

    // this is a SimpleTraverser so no properties are present in detachment
    assertFalse(detachedE.properties().hasNext());

    final Vertex vIn = p.get("c");
    final Vertex detachedVIn = detached.get("c");
    assertEquals(vIn.label(), detachedVIn.label());
    assertEquals(vIn.id(), detachedVIn.id());

    // this is a SimpleTraverser so no properties are present in detachment
    assertFalse(detachedVIn.properties().hasNext());
}
 
Example #19
Source File: SerializationTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldSerializeVertexProperty() throws Exception {
    final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().version(GraphSONVersion.V2_0).create().createMapper();
    final VertexProperty vp = graph.vertices(convertToVertexId("marko")).next().property("name");
    final String json = mapper.writeValueAsString(vp);
    final VertexProperty detached = mapper.readValue(json, VertexProperty.class);

    assertNotNull(detached);
    assertEquals(vp.label(), detached.label());
    assertEquals(vp.id(), detached.id());
    assertEquals(vp.value(), detached.value());
}
 
Example #20
Source File: SerializationTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldSerializeProperty() throws Exception {
    final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().version(GraphSONVersion.V2_0).create().createMapper();
    final Property p = g.E(convertToEdgeId("marko", "knows", "vadas")).next().property("weight");
    final String json = mapper.writeValueAsString(p);
    final Property detached = mapper.readValue(json, Property.class);

    assertNotNull(detached);
    assertEquals(p.key(), detached.key());
    assertEquals(p.value(), detached.value());
}
 
Example #21
Source File: SerializationTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldSerializeEdge() throws Exception {
    final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().version(GraphSONVersion.V2_0).create().createMapper();
    final Edge e = g.E(convertToEdgeId("marko", "knows", "vadas")).next();
    final String json = mapper.writeValueAsString(e);
    final Edge detached = mapper.readValue(json, Edge.class);

    assertNotNull(detached);
    assertEquals(e.label(), detached.label());
    assertEquals(e.id(), detached.id());
    assertEquals((Double) e.value("weight"), detached.value("weight"));
}
 
Example #22
Source File: SerializationTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldSerializeVertex() throws Exception {
    final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V3_0)).mapper().version(GraphSONVersion.V3_0).create().createMapper();
    final Vertex v = graph.vertices(convertToVertexId("marko")).next();
    final String json = mapper.writeValueAsString(v);
    final Vertex detached = mapper.readValue(json, Vertex.class);

    assertNotNull(detached);
    assertEquals(v.label(), detached.label());
    assertEquals(v.id(), detached.id());
    assertEquals(v.value("name").toString(), detached.value("name"));
    assertEquals((Integer) v.value("age"), detached.value("age"));
}
 
Example #23
Source File: SerializationTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldSerializeEdge() throws Exception {
    final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V3_0)).mapper().version(GraphSONVersion.V3_0).create().createMapper();
    final Edge e = g.E(convertToEdgeId("marko", "knows", "vadas")).next();
    final String json = mapper.writeValueAsString(e);
    final Edge detached = mapper.readValue(json, Edge.class);

    assertNotNull(detached);
    assertEquals(e.label(), detached.label());
    assertEquals(e.id(), detached.id());
    assertEquals((Double) e.value("weight"), detached.value("weight"));
}
 
Example #24
Source File: SerializationTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldSerializeVertexProperty() throws Exception {
    final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V1_0)).mapper().version(GraphSONVersion.V1_0).create().createMapper();
    final VertexProperty vp = graph.vertices(convertToVertexId("marko")).next().property("name");
    final String json = mapper.writeValueAsString(vp);
    final Map<String, Object> m = mapper.readValue(json, mapTypeReference);

    assertEquals(vp.label(), m.get(GraphSONTokens.LABEL));
    assertNotNull(m.get(GraphSONTokens.ID));
    assertEquals(vp.value(), m.get(GraphSONTokens.VALUE));
}
 
Example #25
Source File: SerializationTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldSerializeVertexProperty() throws Exception {
    final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V3_0)).mapper().version(GraphSONVersion.V3_0).create().createMapper();
    final VertexProperty vp = graph.vertices(convertToVertexId("marko")).next().property("name");
    final String json = mapper.writeValueAsString(vp);
    final VertexProperty detached = mapper.readValue(json, VertexProperty.class);

    assertNotNull(detached);
    assertEquals(vp.label(), detached.label());
    assertEquals(vp.id(), detached.id());
    assertEquals(vp.value(), detached.value());
}
 
Example #26
Source File: SerializationTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldSerializePath() throws Exception {
    final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V3_0)).mapper().version(GraphSONVersion.V3_0).create().createMapper();
    final Path p = g.V(convertToVertexId("marko")).as("a").outE().as("b").inV().as("c").path()
            .filter(t -> ((Vertex) t.get().objects().get(2)).value("name").equals("lop")).next();
    final String json = mapper.writeValueAsString(p);
    final Path detached = mapper.readValue(json, Path.class);

    assertNotNull(detached);
    assertEquals(p.labels().size(), detached.labels().size());
    assertEquals(p.labels().get(0).size(), detached.labels().get(0).size());
    assertEquals(p.labels().get(1).size(), detached.labels().get(1).size());
    assertEquals(p.labels().get(2).size(), detached.labels().get(2).size());
    assertTrue(p.labels().stream().flatMap(Collection::stream).allMatch(detached::hasLabel));

    final Vertex vOut = p.get("a");
    final Vertex detachedVOut = detached.get("a");
    assertEquals(vOut.label(), detachedVOut.label());
    assertEquals(vOut.id(), detachedVOut.id());

    // this is a SimpleTraverser so no properties are present in detachment
    assertFalse(detachedVOut.properties().hasNext());

    final Edge e = p.get("b");
    final Edge detachedE = detached.get("b");
    assertEquals(e.label(), detachedE.label());
    assertEquals(e.id(), detachedE.id());

    // this is a SimpleTraverser so no properties are present in detachment
    assertFalse(detachedE.properties().hasNext());

    final Vertex vIn = p.get("c");
    final Vertex detachedVIn = detached.get("c");
    assertEquals(vIn.label(), detachedVIn.label());
    assertEquals(vIn.id(), detachedVIn.id());

    // this is a SimpleTraverser so no properties are present in detachment
    assertFalse(detachedVIn.properties().hasNext());
}
 
Example #27
Source File: TinkerGraphTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldSerializeTinkerGraphToGraphSONWithTypes() throws Exception {
    final TinkerGraph graph = TinkerFactory.createModern();
    final Mapper<ObjectMapper> mapper = graph.io(IoCore.graphson()).mapper().typeInfo(TypeInfo.PARTIAL_TYPES).create();
    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        final GraphWriter writer = GraphSONWriter.build().mapper(mapper).create();
        writer.writeObject(out, graph);
        try (final ByteArrayInputStream inputStream = new ByteArrayInputStream(out.toByteArray())) {
            final GraphReader reader = GraphSONReader.build().mapper(mapper).create();
            final TinkerGraph target = reader.readObject(inputStream, TinkerGraph.class);
            IoTest.assertModernGraph(target, true, false);
        }
    }
}
 
Example #28
Source File: DatabaseFixerTest.java    From timbuctoo with GNU General Public License v3.0 5 votes vote down vote up
private String changeStringWithTimestamp(long timestamp) {
  try {
    return new ObjectMapper().writeValueAsString(changeWithTimestamp(timestamp));
  } catch (JsonProcessingException e) {
    throw new RuntimeException(e);
  }
}
 
Example #29
Source File: DatabaseLogTest.java    From timbuctoo with GNU General Public License v3.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  objectMapper = new ObjectMapper();
  logEntryFactory = mock(LogEntryFactory.class);
  vertexLogEntry = mock(LogEntry.class);
  given(logEntryFactory.createForVertex(any(Vertex.class))).willReturn(vertexLogEntry);
  given(logEntryFactory.createForEdge(any(Edge.class))).willReturn(mock(LogEntry.class));
}
 
Example #30
Source File: DatabaseLogIntegrationTest.java    From timbuctoo with GNU General Public License v3.0 5 votes vote down vote up
private String changeStringWithTimestamp(long timeStamp) {
  try {
    return new ObjectMapper().writeValueAsString(changeWithTimestamp(timeStamp));
  } catch (JsonProcessingException e) {
    throw new RuntimeException(e);
  }
}