org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONVersion Java Examples

The following examples show how to use org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONVersion. 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: IoTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = EdgePropertyFeatures.class, feature = FEATURE_STRING_VALUES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
public void shouldReadWriteSelfLoopingEdges() throws Exception {
    final GraphSONMapper mapper = graph.io(graphson).mapper().version(GraphSONVersion.V2_0).create();
    final Graph source = graph;
    final Vertex v1 = source.addVertex();
    final Vertex v2 = source.addVertex();
    v1.addEdge("CONTROL", v2);
    v1.addEdge("SELFLOOP", v1);

    final Configuration targetConf = graphProvider.newGraphConfiguration("target", this.getClass(), name.getMethodName(), null);
    final Graph target = graphProvider.openTestGraph(targetConf);
    try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
        source.io(IoCore.graphson()).writer().mapper(mapper).create().writeGraph(os, source);
        try (ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray())) {
            target.io(IoCore.graphson()).reader().mapper(mapper).create().readGraph(is, target);
        }
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }

    assertEquals(IteratorUtils.count(source.vertices()), IteratorUtils.count(target.vertices()));
    assertEquals(IteratorUtils.count(source.edges()), IteratorUtils.count(target.edges()));
}
 
Example #2
Source File: IoVertexTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Parameterized.Parameters(name = "{0}")
public static Iterable<Object[]> data() {
    return Arrays.asList(new Object[][]{
            {"graphson-v1", false, false,
                    (Function<Graph, GraphReader>) g -> g.io(GraphSONIo.build(GraphSONVersion.V1_0)).reader().create(),
                    (Function<Graph, GraphWriter>) g -> g.io(GraphSONIo.build(GraphSONVersion.V1_0)).writer().create()},
            {"graphson-v1-embedded", true, false,
                    (Function<Graph, GraphReader>) g -> g.io(GraphSONIo.build(GraphSONVersion.V1_0)).reader().mapper(g.io(GraphSONIo.build(GraphSONVersion.V1_0)).mapper().typeInfo(TypeInfo.PARTIAL_TYPES).create()).create(),
                    (Function<Graph, GraphWriter>) g -> g.io(GraphSONIo.build(GraphSONVersion.V1_0)).writer().mapper(g.io(GraphSONIo.build(GraphSONVersion.V1_0)).mapper().typeInfo(TypeInfo.PARTIAL_TYPES).create()).create()},
            {"graphson-v2", false, false,
                    (Function<Graph, GraphReader>) g -> g.io(GraphSONIo.build(GraphSONVersion.V2_0)).reader().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.NO_TYPES).create()).create(),
                    (Function<Graph, GraphWriter>) g -> g.io(GraphSONIo.build(GraphSONVersion.V2_0)).writer().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.NO_TYPES).create()).create()},
            {"graphson-v2-embedded", true, false,
                    (Function<Graph, GraphReader>) g -> g.io(GraphSONIo.build(GraphSONVersion.V2_0)).reader().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.PARTIAL_TYPES).create()).create(),
                    (Function<Graph, GraphWriter>) g -> g.io(GraphSONIo.build(GraphSONVersion.V2_0)).writer().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.PARTIAL_TYPES).create()).create()},
            {"graphson-v3", true, false,
                    (Function<Graph, GraphReader>) g -> g.io(GraphSONIo.build(GraphSONVersion.V3_0)).reader().mapper(g.io(GraphSONIo.build(GraphSONVersion.V3_0)).mapper().create()).create(),
                    (Function<Graph, GraphWriter>) g -> g.io(GraphSONIo.build(GraphSONVersion.V3_0)).writer().mapper(g.io(GraphSONIo.build(GraphSONVersion.V3_0)).mapper().create()).create()},
            {"gryo-v1", true, true,
                    (Function<Graph, GraphReader>) g -> g.io(GryoIo.build(GryoVersion.V1_0)).reader().create(),
                    (Function<Graph, GraphWriter>) g -> g.io(GryoIo.build(GryoVersion.V1_0)).writer().create()},
            {"gryo-v3", true, true,
                    (Function<Graph, GraphReader>) g -> g.io(GryoIo.build(GryoVersion.V3_0)).reader().create(),
                    (Function<Graph, GraphWriter>) g -> g.io(GryoIo.build(GryoVersion.V3_0)).writer().create()}
    });
}
 
Example #3
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 #4
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 #5
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 #6
Source File: TestIoAgain.java    From sqlg with MIT License 6 votes vote down vote up
@Parameterized.Parameters(name = "{0}")
public static Iterable<Object[]> data() {
    return Arrays.asList(new Object[][]{
            {"graphson-v1", false, false,
                    (Function<Graph, GraphReader>) g -> g.io(GraphSONIo.build(GraphSONVersion.V1_0)).reader().create(),
                    (Function<Graph, GraphWriter>) g -> g.io(GraphSONIo.build(GraphSONVersion.V1_0)).writer().create()},
            {"graphson-v1-embedded", true, false,
                    (Function<Graph, GraphReader>) g -> g.io(GraphSONIo.build(GraphSONVersion.V1_0)).reader().mapper(g.io(GraphSONIo.build(GraphSONVersion.V1_0)).mapper().typeInfo(TypeInfo.PARTIAL_TYPES).create()).create(),
                    (Function<Graph, GraphWriter>) g -> g.io(GraphSONIo.build(GraphSONVersion.V1_0)).writer().mapper(g.io(GraphSONIo.build(GraphSONVersion.V1_0)).mapper().typeInfo(TypeInfo.PARTIAL_TYPES).create()).create()},
            {"graphson-v2", false, false,
                    (Function<Graph, GraphReader>) g -> g.io(GraphSONIo.build(GraphSONVersion.V2_0)).reader().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.NO_TYPES).create()).create(),
                    (Function<Graph, GraphWriter>) g -> g.io(GraphSONIo.build(GraphSONVersion.V2_0)).writer().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.NO_TYPES).create()).create()},
            {"graphson-v2-embedded", true, false,
                    (Function<Graph, GraphReader>) g -> g.io(GraphSONIo.build(GraphSONVersion.V2_0)).reader().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.PARTIAL_TYPES).create()).create(),
                    (Function<Graph, GraphWriter>) g -> g.io(GraphSONIo.build(GraphSONVersion.V2_0)).writer().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.PARTIAL_TYPES).create()).create()},
            {"graphson-v3", true, false,
                    (Function<Graph, GraphReader>) g -> g.io(GraphSONIo.build(GraphSONVersion.V3_0)).reader().mapper(g.io(GraphSONIo.build(GraphSONVersion.V3_0)).mapper().create()).create(),
                    (Function<Graph, GraphWriter>) g -> g.io(GraphSONIo.build(GraphSONVersion.V3_0)).writer().mapper(g.io(GraphSONIo.build(GraphSONVersion.V3_0)).mapper().create()).create()},
            {"gryo-v1", true, true,
                    (Function<Graph, GraphReader>) g -> g.io(GryoIo.build(GryoVersion.V1_0)).reader().create(),
                    (Function<Graph, GraphWriter>) g -> g.io(GryoIo.build(GryoVersion.V1_0)).writer().create()},
            {"gryo-v3", true, true,
                    (Function<Graph, GraphReader>) g -> g.io(GryoIo.build(GryoVersion.V3_0)).reader().create(),
                    (Function<Graph, GraphWriter>) g -> g.io(GryoIo.build(GryoVersion.V3_0)).writer().create()}
    });
}
 
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 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 #8
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 #9
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 #10
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 #11
Source File: TestIoEdge.java    From sqlg with MIT License 6 votes vote down vote up
@Parameterized.Parameters(name = "{0}")
public static Iterable<Object[]> data() {
    return Arrays.asList(new Object[][]{
            {"graphson-v1", false, false,
                    (Function<Graph, GraphReader>) g -> g.io(GraphSONIo.build(GraphSONVersion.V1_0)).reader().create(),
                    (Function<Graph, GraphWriter>) g -> g.io(GraphSONIo.build(GraphSONVersion.V1_0)).writer().create()},
            {"graphson-v1-embedded", true, true,
                    (Function<Graph, GraphReader>) g -> g.io(GraphSONIo.build(GraphSONVersion.V1_0)).reader().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.PARTIAL_TYPES).create()).create(),
                    (Function<Graph, GraphWriter>) g -> g.io(GraphSONIo.build(GraphSONVersion.V1_0)).writer().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.PARTIAL_TYPES).create()).create()},
            {"graphson-v2", false, false,
                    (Function<Graph, GraphReader>) g -> g.io(GraphSONIo.build(GraphSONVersion.V2_0)).reader().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.NO_TYPES).create()).create(),
                    (Function<Graph, GraphWriter>) g -> g.io(GraphSONIo.build(GraphSONVersion.V2_0)).writer().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.NO_TYPES).create()).create()},
            {"graphson-v2-embedded", true, true,
                    (Function<Graph, GraphReader>) g -> g.io(GraphSONIo.build(GraphSONVersion.V2_0)).reader().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.PARTIAL_TYPES).create()).create(),
                    (Function<Graph, GraphWriter>) g -> g.io(GraphSONIo.build(GraphSONVersion.V2_0)).writer().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.PARTIAL_TYPES).create()).create()},
            {"graphson-v3", true, true,
                    (Function<Graph, GraphReader>) g -> g.io(GraphSONIo.build(GraphSONVersion.V3_0)).reader().mapper(g.io(GraphSONIo.build(GraphSONVersion.V3_0)).mapper().create()).create(),
                    (Function<Graph, GraphWriter>) g -> g.io(GraphSONIo.build(GraphSONVersion.V3_0)).writer().mapper(g.io(GraphSONIo.build(GraphSONVersion.V3_0)).mapper().create()).create()},
            {"gryo-v1", true, true,
                    (Function<Graph, GraphReader>) g -> g.io(GryoIo.build(GryoVersion.V1_0)).reader().create(),
                    (Function<Graph, GraphWriter>) g -> g.io(GryoIo.build(GryoVersion.V1_0)).writer().create()},
            {"gryo-v3", true, true,
                    (Function<Graph, GraphReader>) g -> g.io(GryoIo.build(GryoVersion.V3_0)).reader().create(),
                    (Function<Graph, GraphWriter>) g -> g.io(GryoIo.build(GryoVersion.V3_0)).writer().create()}
    });
}
 
Example #12
Source File: IoEdgeTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Parameterized.Parameters(name = "{0}")
public static Iterable<Object[]> data() {
    return Arrays.asList(new Object[][]{
            {"graphson-v1", false, false,
                    (Function<Graph,GraphReader>) g -> g.io(GraphSONIo.build(GraphSONVersion.V1_0)).reader().create(),
                    (Function<Graph, GraphWriter>) g -> g.io(GraphSONIo.build(GraphSONVersion.V1_0)).writer().create()},
            {"graphson-v1-embedded", true, true,
                    (Function<Graph,GraphReader>) g -> g.io(GraphSONIo.build(GraphSONVersion.V1_0)).reader().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.PARTIAL_TYPES).create()).create(),
                    (Function<Graph, GraphWriter>) g -> g.io(GraphSONIo.build(GraphSONVersion.V1_0)).writer().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.PARTIAL_TYPES).create()).create()},
            {"graphson-v2", false, false,
                    (Function<Graph, GraphReader>) g -> g.io(GraphSONIo.build(GraphSONVersion.V2_0)).reader().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.NO_TYPES).create()).create(),
                    (Function<Graph, GraphWriter>) g -> g.io(GraphSONIo.build(GraphSONVersion.V2_0)).writer().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.NO_TYPES).create()).create()},
            {"graphson-v2-embedded", true, true,
                    (Function<Graph, GraphReader>) g -> g.io(GraphSONIo.build(GraphSONVersion.V2_0)).reader().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.PARTIAL_TYPES).create()).create(),
                    (Function<Graph, GraphWriter>) g -> g.io(GraphSONIo.build(GraphSONVersion.V2_0)).writer().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.PARTIAL_TYPES).create()).create()},
            {"graphson-v3", true, true,
                    (Function<Graph, GraphReader>) g -> g.io(GraphSONIo.build(GraphSONVersion.V3_0)).reader().mapper(g.io(GraphSONIo.build(GraphSONVersion.V3_0)).mapper().create()).create(),
                    (Function<Graph, GraphWriter>) g -> g.io(GraphSONIo.build(GraphSONVersion.V3_0)).writer().mapper(g.io(GraphSONIo.build(GraphSONVersion.V3_0)).mapper().create()).create()},
            {"gryo-v1", true, true,
                    (Function<Graph,GraphReader>) g -> g.io(GryoIo.build(GryoVersion.V1_0)).reader().create(),
                    (Function<Graph, GraphWriter>) g -> g.io(GryoIo.build(GryoVersion.V1_0)).writer().create()},
            {"gryo-v3", true, true,
                    (Function<Graph,GraphReader>) g -> g.io(GryoIo.build(GryoVersion.V3_0)).reader().create(),
                    (Function<Graph, GraphWriter>) g -> g.io(GryoIo.build(GryoVersion.V3_0)).writer().create()}
    });
}
 
Example #13
Source File: IoCustomTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Parameterized.Parameters(name = "{0}")
public static Iterable<Object[]> data() {
    final SimpleModule moduleV1d0 = new SimpleModule();
    moduleV1d0.addSerializer(CustomId.class, new CustomId.CustomIdJacksonSerializerV1d0());

    final SimpleModule moduleV2d0 = new CustomId.CustomIdTinkerPopJacksonModuleV2d0();
    final SimpleModule modulev3d0 = new CustomId.CustomIdTinkerPopJacksonModuleV3d0();

    return Arrays.asList(new Object[][]{
            {"graphson-v1-embedded", true,
                    (Function<Graph, GraphReader>) g -> g.io(GraphSONIo.build(GraphSONVersion.V1_0)).reader().mapper(g.io(GraphSONIo.build(GraphSONVersion.V1_0)).mapper().addCustomModule(moduleV1d0).typeInfo(TypeInfo.PARTIAL_TYPES).create()).create(),
                    (Function<Graph, GraphWriter>) g -> g.io(GraphSONIo.build(GraphSONVersion.V1_0)).writer().mapper(g.io(GraphSONIo.build(GraphSONVersion.V1_0)).mapper().addCustomModule(moduleV1d0).typeInfo(TypeInfo.PARTIAL_TYPES).create()).create()},
            {"graphson-v2-embedded", true,
                    (Function<Graph, GraphReader>) g -> g.io(GraphSONIo.build(GraphSONVersion.V2_0)).reader().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().addCustomModule(moduleV2d0).typeInfo(TypeInfo.PARTIAL_TYPES).create()).create(),
                    (Function<Graph, GraphWriter>) g -> g.io(GraphSONIo.build(GraphSONVersion.V2_0)).writer().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().addCustomModule(moduleV2d0).typeInfo(TypeInfo.PARTIAL_TYPES).create()).create()},
            {"graphson-v3", true,
                    (Function<Graph, GraphReader>) g -> g.io(GraphSONIo.build(GraphSONVersion.V3_0)).reader().mapper(g.io(GraphSONIo.build(GraphSONVersion.V3_0)).mapper().addCustomModule(modulev3d0).create()).create(),
                    (Function<Graph, GraphWriter>) g -> g.io(GraphSONIo.build(GraphSONVersion.V3_0)).writer().mapper(g.io(GraphSONIo.build(GraphSONVersion.V3_0)).mapper().addCustomModule(modulev3d0).create()).create()},
            {"gryo-v1", true,
                    (Function<Graph, GraphReader>) g -> g.io(GryoIo.build(GryoVersion.V1_0)).reader().mapper(g.io(GryoIo.build(GryoVersion.V1_0)).mapper().version(GryoVersion.V1_0).addCustom(CustomId.class).create()).create(),
                    (Function<Graph, GraphWriter>) g -> g.io(GryoIo.build(GryoVersion.V1_0)).writer().mapper(g.io(GryoIo.build(GryoVersion.V1_0)).mapper().version(GryoVersion.V1_0).addCustom(CustomId.class).create()).create()},
            {"gryo-v3", true,
                    (Function<Graph, GraphReader>) g -> g.io(GryoIo.build(GryoVersion.V3_0)).reader().mapper(g.io(GryoIo.build(GryoVersion.V3_0)).mapper().version(GryoVersion.V3_0).addCustom(CustomId.class).create()).create(),
                    (Function<Graph, GraphWriter>) g -> g.io(GryoIo.build(GryoVersion.V3_0)).writer().mapper(g.io(GryoIo.build(GryoVersion.V3_0)).mapper().version(GryoVersion.V3_0).addCustom(CustomId.class).create()).create()}
    });
}
 
Example #14
Source File: IoTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
/**
 * Only need to execute this test with TinkerGraph or other graphs that support user supplied identifiers.
 */
@Test
@FeatureRequirement(featureClass = VertexPropertyFeatures.class, feature = FEATURE_STRING_VALUES)
@FeatureRequirement(featureClass = VertexPropertyFeatures.class, feature = FEATURE_INTEGER_VALUES)
@FeatureRequirement(featureClass = EdgePropertyFeatures.class, feature = EdgePropertyFeatures.FEATURE_FLOAT_VALUES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_USER_SUPPLIED_IDS)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_NUMERIC_IDS)
@FeatureRequirement(featureClass = Graph.Features.VertexPropertyFeatures.class, feature = Graph.Features.VertexPropertyFeatures.FEATURE_USER_SUPPLIED_IDS)
@FeatureRequirement(featureClass = Graph.Features.VariableFeatures.class, feature = FEATURE_VARIABLES)
@LoadGraphWith(LoadGraphWith.GraphData.CLASSIC)
public void shouldWriteNormalizedGraphSON() throws Exception {
    try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
        final GraphSONMapper mapper = graph.io(graphson).mapper().version(GraphSONVersion.V1_0).normalize(true).create();
        final GraphSONWriter w = graph.io(graphson).writer().mapper(mapper).create();
        w.writeGraph(bos, graph);

        final String expected = streamToString(getResourceAsStream(GraphSONResourceAccess.class, "tinkerpop-classic-normalized-v1d0.json"));
        assertEquals(expected.replace("\n", "").replace("\r", ""), bos.toString().replace("\n", "").replace("\r", ""));
    }
}
 
Example #15
Source File: IoTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
public void shouldReadWriteModernWrappedInJsonObject() throws Exception {
    final GraphSONMapper mapper = graph.io(graphson).mapper().version(GraphSONVersion.V2_0).create();
    try (final ByteArrayOutputStream os = new ByteArrayOutputStream()) {
        final GraphWriter writer = graph.io(graphson()).writer().wrapAdjacencyList(true).mapper(mapper).create();
        writer.writeGraph(os, graph);

        final Configuration configuration = graphProvider.newGraphConfiguration("readGraph", this.getClass(), name.getMethodName(), LoadGraphWith.GraphData.MODERN);
        graphProvider.clear(configuration);
        final Graph g1 = graphProvider.openTestGraph(configuration);
        final GraphReader reader = graph.io(graphson()).reader().mapper(mapper).unwrapAdjacencyList(true).create();
        try (final ByteArrayInputStream bais = new ByteArrayInputStream(os.toByteArray())) {
            reader.readGraph(bais, g1);
        }

        // modern uses double natively so always assert as such
        IoTest.assertModernGraph(g1, true, true);

        graphProvider.clear(g1, configuration);
    }
}
 
Example #16
Source File: IoTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
public void shouldReadWriteModernWrappedInJsonObject() throws Exception {
    final GraphSONMapper mapper = graph.io(graphson).mapper().version(GraphSONVersion.V3_0).create();
    try (final ByteArrayOutputStream os = new ByteArrayOutputStream()) {
        final GraphWriter writer = graph.io(graphson()).writer().wrapAdjacencyList(true).mapper(mapper).create();
        writer.writeGraph(os, graph);

        final Configuration configuration = graphProvider.newGraphConfiguration("readGraph", this.getClass(), name.getMethodName(), LoadGraphWith.GraphData.MODERN);
        graphProvider.clear(configuration);
        final Graph g1 = graphProvider.openTestGraph(configuration);
        final GraphReader reader = graph.io(graphson()).reader().mapper(mapper).unwrapAdjacencyList(true).create();
        try (final ByteArrayInputStream bais = new ByteArrayInputStream(os.toByteArray())) {
            reader.readGraph(bais, g1);
        }

        // modern uses double natively so always assert as such
        IoTest.assertModernGraph(g1, true, true);

        graphProvider.clear(g1, configuration);
    }
}
 
Example #17
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 #18
Source File: IoDataGenerationTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
/**
 * No assertions.  Just write out the graph for convenience.
 */
@Test
public void shouldWriteCrewGraphAsGraphSONV2d0WithTypes() throws IOException {
    final OutputStream os = new FileOutputStream(new File(tempPath, "tinkerpop-crew-typed-v2d0.json"));
    GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V2_0).typeInfo(TypeInfo.PARTIAL_TYPES).create()).create()
            .writeGraph(os, TinkerFactory.createTheCrew());
    os.close();
}
 
Example #19
Source File: IoDataGenerationTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
/**
 * No assertions.  Just write out the graph for convenience.
 */
@Test
public void shouldWriteModernGraphAsGraphSONV3d0() throws IOException {
    final OutputStream os = new FileOutputStream(new File(tempPath, "tinkerpop-modern-v3d0.json"));
    GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V3_0).create()).create()
            .writeGraph(os, TinkerFactory.createModern());
    os.close();
}
 
Example #20
Source File: IoDataGenerationTest.java    From tinkergraph-gremlin with Apache License 2.0 5 votes vote down vote up
/**
 * No assertions.  Just write out the graph for convenience.
 */
@Test
public void shouldWriteModernGraphNormalizedAsGraphSONV2d0() throws IOException {
    final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-modern-normalized-v2d0.json");
    GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V2_0).typeInfo(TypeInfo.NO_TYPES).normalize(true).create()).create()
            .writeGraph(os, TinkerFactory.createModern());
    os.close();
}
 
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 shouldSerializeProperty() throws Exception {
    final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V1_0)).mapper().version(GraphSONVersion.V1_0).create().createMapper();
    final Property p = g.E(convertToEdgeId("marko", "knows", "vadas")).next().property("weight");
    final String json = mapper.writeValueAsString(p);
    final Map<String, Object> m = mapper.readValue(json, mapTypeReference);

    assertEquals(p.value(), m.get(GraphSONTokens.VALUE));
    assertEquals(p.key(), m.get(GraphSONTokens.KEY));
}
 
Example #22
Source File: IoDataGenerationTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
/**
 * No assertions.  Just write out the graph for convenience.
 */
@Test
public void shouldWriteDEFAULTSinkGraphAsGraphSONV3d0() throws IOException {
    final OutputStream os = new FileOutputStream(new File(tempPath, "tinkerpop-sink.json"));
    GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V3_0).create()).create()
            .writeGraph(os, TinkerFactory.createKitchenSink());
    os.close();
}
 
Example #23
Source File: IoDataGenerationTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
/**
 * No assertions.  Just write out the graph for convenience.
 */
@Test
public void shouldWriteClassicGraphNormalizedAsGraphSONV3d0() throws IOException {
    final OutputStream os = new FileOutputStream(new File(tempPath, "tinkerpop-classic-normalized-v3d0.json"));
    GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V3_0).normalize(true).create()).create()
            .writeGraph(os, TinkerFactory.createClassic());
    os.close();
}
 
Example #24
Source File: IoDataGenerationTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
/**
 * No assertions.  Just write out the graph for convenience.
 */
@Test
public void shouldWriteClassicGraphNormalizedAsGraphSONV1d0() throws IOException {
    final OutputStream os = new FileOutputStream(new File(tempPath, "tinkerpop-classic-normalized-v1d0.json"));
    GraphSONWriter.build().mapper(GraphSONMapper.build().normalize(true).version(GraphSONVersion.V1_0).typeInfo(TypeInfo.NO_TYPES).create()).create().writeGraph(os, TinkerFactory.createClassic());
    os.close();
}
 
Example #25
Source File: IoDataGenerationTest.java    From tinkergraph-gremlin with Apache License 2.0 5 votes vote down vote up
/**
 * No assertions. Just write out the graph for convenience
 */
@Test
public void shouldWriteKitchenSinkAsGraphSONWithTypes() throws IOException {
    final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-sink-typed-v1d0.json");
    GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V1_0).typeInfo(TypeInfo.PARTIAL_TYPES).create())
            .create().writeGraph(os, TinkerFactory.createKitchenSink());
    os.close();
}
 
Example #26
Source File: IoDataGenerationTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
/**
 * No assertions.  Just write out the graph for convenience.
 */
@Test
public void shouldWriteClassicGraphAsGraphSONV1d0WithTypes() throws IOException {
    final OutputStream os = new FileOutputStream(new File(tempPath, "tinkerpop-classic-typed-v1d0.json"));
    GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V1_0).typeInfo(TypeInfo.PARTIAL_TYPES).create())
            .create().writeGraph(os, TinkerFactory.createClassic());
    os.close();
}
 
Example #27
Source File: IoDataGenerationTest.java    From tinkergraph-gremlin with Apache License 2.0 5 votes vote down vote up
/**
 * No assertions.  Just write out the graph for convenience.
 */
@Test
public void shouldWriteCrewGraphAsGraphSONV1d0WithTypes() throws IOException {
    final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-crew-typed-v1d0.json");
    GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V1_0).typeInfo(TypeInfo.PARTIAL_TYPES).create())
            .create().writeGraph(os, TinkerFactory.createTheCrew());
    os.close();
}
 
Example #28
Source File: BaseTest.java    From sqlg with MIT License 5 votes vote down vote up
protected void loadModern(SqlgGraph sqlgGraph) {
    Io.Builder<GraphSONIo> builder = GraphSONIo.build(GraphSONVersion.V3_0);
    final GraphReader reader = sqlgGraph.io(builder).reader().create();
    try (final InputStream stream = AbstractGremlinTest.class.getResourceAsStream("/tinkerpop-modern-v3d0.json")) {
        reader.readGraph(stream, sqlgGraph);
    } catch (IOException e) {
        Assert.fail(e.getMessage());
    }
}
 
Example #29
Source File: BaseTest.java    From sqlg with MIT License 5 votes vote down vote up
protected void loadGratefulDead(SqlgGraph sqlgGraph) {
    Io.Builder<GraphSONIo> builder = GraphSONIo.build(GraphSONVersion.V3_0);
    final GraphReader reader = sqlgGraph.io(builder).reader().create();
    try (final InputStream stream = AbstractGremlinTest.class.getResourceAsStream("/grateful-dead-v3d0.json")) {
        reader.readGraph(stream, sqlgGraph);
    } catch (IOException e) {
        Assert.fail(e.getMessage());
    }
}
 
Example #30
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"));
}