Java Code Examples for org.apache.tinkerpop.gremlin.structure.io.GraphWriter#writeObject()
The following examples show how to use
org.apache.tinkerpop.gremlin.structure.io.GraphWriter#writeObject() .
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: GraphSONMessageSerializerV2d0Test.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test public void shouldToStringUnknownObjects() { GraphSONMapper gm20 = GraphSONMapper.build().version(GraphSONVersion.V2_0).create(); GraphSONMapper gm10 = GraphSONMapper.build().version(GraphSONVersion.V1_0).create(); GraphWriter writer = GraphSONWriter.build().mapper(gm20).create(); // subsequent creations of GraphWriters and GraphSONMappers should not affect // each other. GraphWriter writer2 = GraphSONWriter.build().mapper(gm10).create(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { writer.writeObject(baos, new FunObject("value")); assertEquals(baos.toString(), "\"value\""); } catch (Exception e) { fail("should have succeeded serializing the unknown object to a string"); } }
Example 2
Source File: TinkerGraphGraphSONSerializerV2d0Test.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test @org.junit.Ignore("https://issues.apache.org/jira/browse/TINKERPOP-1509") public void deserializersTestsTree() { final TinkerGraph tg = TinkerFactory.createModern(); final GraphWriter writer = getWriter(defaultMapperV2d0); final GraphReader reader = getReader(defaultMapperV2d0); final Tree t = tg.traversal().V().out().out().tree().next(); try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) { writer.writeObject(out, t); final String json = out.toString(); final Tree treeRead = (Tree)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class); //Map's equals should check each component of the tree recursively //on each it will call "equals()" which for Vertices will compare ids, which //is ok. Complete vertex deser is checked elsewhere. assertEquals(t, treeRead); } catch (IOException e) { e.printStackTrace(); fail("Should not have thrown exception: " + e.getMessage()); } }
Example 3
Source File: TinkerGraphGraphSONSerializerV2d0Test.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test public void deserializersTestsTraversalMetrics() { final TinkerGraph tg = TinkerFactory.createModern(); final GraphWriter writer = getWriter(defaultMapperV2d0); final GraphReader reader = getReader(defaultMapperV2d0); final TraversalMetrics tm = tg.traversal().V(1).as("a").has("name").as("b"). out("knows").out("created").as("c"). has("name", "ripple").values("name").as("d"). identity().as("e").profile().next(); try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) { writer.writeObject(out, tm); final String json = out.toString(); final TraversalMetrics traversalMetricsRead = (TraversalMetrics)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class); // toString should be enough to compare TraversalMetrics assertTrue(tm.toString().equals(traversalMetricsRead.toString())); } catch (IOException e) { e.printStackTrace(); fail("Should not have thrown exception: " + e.getMessage()); } }
Example 4
Source File: TinkerGraphGraphSONSerializerV2d0Test.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test public void deserializersTestsVertexProperty() { final TinkerGraph tg = TinkerGraph.open(); final Vertex v = tg.addVertex("vertexTest"); final GraphWriter writer = getWriter(defaultMapperV2d0); final GraphReader reader = getReader(defaultMapperV2d0); final VertexProperty prop = v.property("born", LocalDateTime.of(1971, 1, 2, 20, 50)); try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) { writer.writeObject(out, prop); final String json = out.toString(); final VertexProperty vPropRead = (VertexProperty)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class); //only classes and ids are checked, that's ok, full vertex property ser/de //is checked elsewhere. assertEquals(prop, vPropRead); } catch (IOException e) { e.printStackTrace(); fail("Should not have thrown exception: " + e.getMessage()); } }
Example 5
Source File: TinkerGraphGraphSONSerializerV2d0Test.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test public void deserializersTestsTinkerGraph() { final TinkerGraph tg = TinkerGraph.open(); final Vertex v = tg.addVertex("vertexTest"); final Vertex v2 = tg.addVertex("vertexTest"); v.addEdge("knows", v2); final GraphWriter writer = getWriter(defaultMapperV2d0); final GraphReader reader = getReader(defaultMapperV2d0); try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) { writer.writeObject(out, tg); final String json = out.toString(); final Graph gRead = (Graph)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class); assertTrue(approximateGraphsCheck(tg, gRead)); } catch (IOException e) { e.printStackTrace(); fail("Should not have thrown exception: " + e.getMessage()); } }
Example 6
Source File: TinkerGraphGraphSONSerializerV2d0Test.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test public void deserializersTestsEdge() { final TinkerGraph tg = TinkerGraph.open(); final Vertex v = tg.addVertex("vertexTest"); final Vertex v2 = tg.addVertex("vertexTest"); final Edge ed = v.addEdge("knows", v2, "time", LocalDateTime.now()); final GraphWriter writer = getWriter(defaultMapperV2d0); final GraphReader reader = getReader(defaultMapperV2d0); try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) { writer.writeObject(out, ed); final String json = out.toString(); // Object works, because there's a type in the payload now // Edge.class would work as well // Anything else would not because we check the type in param here with what's in the JSON, for safety. final Edge eRead = (Edge)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class); assertEquals(ed, eRead); } catch (IOException e) { e.printStackTrace(); fail("Should not have thrown exception: " + e.getMessage()); } }
Example 7
Source File: TinkerGraphGraphSONSerializerV2d0Test.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test public void deserializersTestsVertex() { final TinkerGraph tg = TinkerGraph.open(); final Vertex v = tg.addVertex("vertexTest"); v.property("born", LocalDateTime.of(1971, 1, 2, 20, 50)); v.property("dead", LocalDateTime.of(1971, 1, 7, 20, 50)); final GraphWriter writer = getWriter(defaultMapperV2d0); final GraphReader reader = getReader(defaultMapperV2d0); try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) { writer.writeObject(out, v); final String json = out.toString(); // Object works, because there's a type in the payload now // Vertex.class would work as well // Anything else would not because we check the type in param here with what's in the JSON, for safety. final Vertex vRead = (Vertex)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class); assertEquals(v, vRead); } catch (IOException e) { e.printStackTrace(); fail("Should not have thrown exception: " + e.getMessage()); } }
Example 8
Source File: TinkerGraphGraphSONSerializerV2d0Test.java From tinkerpop with Apache License 2.0 | 6 votes |
/** * Thorough types verification for Vertex ids, Vertex props, Edge ids, Edge props */ @Test public void shouldDeserializeGraphSONIntoTinkerGraphKeepingTypes() throws IOException { final GraphWriter writer = getWriter(defaultMapperV2d0); final GraphReader reader = getReader(defaultMapperV2d0); final Graph sampleGraph1 = TinkerFactory.createModern(); final Vertex v1 = sampleGraph1.addVertex(T.id, 100, "name", "kevin", "theUUID", UUID.randomUUID()); final Vertex v2 = sampleGraph1.addVertex(T.id, 101L, "name", "henri", "theUUID", UUID.randomUUID()); v1.addEdge("hello", v2, T.id, 101L, "uuid", UUID.randomUUID()); try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) { writer.writeObject(out, sampleGraph1); final String json = out.toString(); final TinkerGraph read = reader.readObject(new ByteArrayInputStream(json.getBytes()), TinkerGraph.class); assertTrue(approximateGraphsCheck(sampleGraph1, read)); } }
Example 9
Source File: TinkerGraphGraphSONSerializerV2d0Test.java From tinkergraph-gremlin with Apache License 2.0 | 6 votes |
/** * Thorough types verification for Vertex ids, Vertex props, Edge ids, Edge props */ @Test public void shouldDeserializeGraphSONIntoTinkerGraphKeepingTypes() throws IOException { final GraphWriter writer = getWriter(defaultMapperV2d0); final GraphReader reader = getReader(defaultMapperV2d0); final Graph sampleGraph1 = TinkerFactory.createModern(); final Vertex v1 = sampleGraph1.addVertex(T.id, 100, "name", "kevin", "theUUID", UUID.randomUUID()); final Vertex v2 = sampleGraph1.addVertex(T.id, 101L, "name", "henri", "theUUID", UUID.randomUUID()); v1.addEdge("hello", v2, T.id, 101L, "uuid", UUID.randomUUID()); try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) { writer.writeObject(out, sampleGraph1); final String json = out.toString(); final TinkerGraph read = reader.readObject(new ByteArrayInputStream(json.getBytes()), TinkerGraph.class); assertTrue(approximateGraphsCheck(sampleGraph1, read)); } }
Example 10
Source File: TinkerGraphGraphSONSerializerV2d0Test.java From tinkergraph-gremlin with Apache License 2.0 | 6 votes |
@Test @org.junit.Ignore("https://issues.apache.org/jira/browse/TINKERPOP-1509") public void deserializersTestsTree() { final TinkerGraph tg = TinkerFactory.createModern(); final GraphWriter writer = getWriter(defaultMapperV2d0); final GraphReader reader = getReader(defaultMapperV2d0); final Tree t = tg.traversal().V().out().out().tree().next(); try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) { writer.writeObject(out, t); final String json = out.toString(); final Tree treeRead = (Tree)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class); //Map's equals should check each component of the tree recursively //on each it will call "equals()" which for Vertices will compare ids, which //is ok. Complete vertex deser is checked elsewhere. assertEquals(t, treeRead); } catch (IOException e) { e.printStackTrace(); fail("Should not have thrown exception: " + e.getMessage()); } }
Example 11
Source File: TinkerGraphGraphSONSerializerV2d0Test.java From tinkergraph-gremlin with Apache License 2.0 | 6 votes |
@Test public void deserializersTestsTraversalMetrics() { final TinkerGraph tg = TinkerFactory.createModern(); final GraphWriter writer = getWriter(defaultMapperV2d0); final GraphReader reader = getReader(defaultMapperV2d0); final TraversalMetrics tm = tg.traversal().V(1).as("a").has("name").as("b"). out("knows").out("created").as("c"). has("name", "ripple").values("name").as("d"). identity().as("e").profile().next(); try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) { writer.writeObject(out, tm); final String json = out.toString(); final TraversalMetrics traversalMetricsRead = (TraversalMetrics)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class); // toString should be enough to compare TraversalMetrics assertTrue(tm.toString().equals(traversalMetricsRead.toString())); } catch (IOException e) { e.printStackTrace(); fail("Should not have thrown exception: " + e.getMessage()); } }
Example 12
Source File: TinkerGraphGraphSONSerializerV2d0Test.java From tinkergraph-gremlin with Apache License 2.0 | 6 votes |
@Test public void deserializersTestsVertexProperty() { final TinkerGraph tg = TinkerGraph.open(); final Vertex v = tg.addVertex("vertexTest"); final GraphWriter writer = getWriter(defaultMapperV2d0); final GraphReader reader = getReader(defaultMapperV2d0); final VertexProperty prop = v.property("born", LocalDateTime.of(1971, 1, 2, 20, 50)); try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) { writer.writeObject(out, prop); final String json = out.toString(); final VertexProperty vPropRead = (VertexProperty)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class); //only classes and ids are checked, that's ok, full vertex property ser/de //is checked elsewhere. assertEquals(prop, vPropRead); } catch (IOException e) { e.printStackTrace(); fail("Should not have thrown exception: " + e.getMessage()); } }
Example 13
Source File: TinkerGraphGraphSONSerializerV2d0Test.java From tinkergraph-gremlin with Apache License 2.0 | 6 votes |
@Test public void deserializersTestsTinkerGraph() { final TinkerGraph tg = TinkerGraph.open(); final Vertex v = tg.addVertex("vertexTest"); final Vertex v2 = tg.addVertex("vertexTest"); v.addEdge("knows", v2); final GraphWriter writer = getWriter(defaultMapperV2d0); final GraphReader reader = getReader(defaultMapperV2d0); try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) { writer.writeObject(out, tg); final String json = out.toString(); final Graph gRead = (Graph)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class); assertTrue(approximateGraphsCheck(tg, gRead)); } catch (IOException e) { e.printStackTrace(); fail("Should not have thrown exception: " + e.getMessage()); } }
Example 14
Source File: TinkerGraphGraphSONSerializerV2d0Test.java From tinkergraph-gremlin with Apache License 2.0 | 6 votes |
@Test public void deserializersTestsEdge() { final TinkerGraph tg = TinkerGraph.open(); final Vertex v = tg.addVertex("vertexTest"); final Vertex v2 = tg.addVertex("vertexTest"); final Edge ed = v.addEdge("knows", v2, "time", LocalDateTime.now()); final GraphWriter writer = getWriter(defaultMapperV2d0); final GraphReader reader = getReader(defaultMapperV2d0); try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) { writer.writeObject(out, ed); final String json = out.toString(); // Object works, because there's a type in the payload now // Edge.class would work as well // Anything else would not because we check the type in param here with what's in the JSON, for safety. final Edge eRead = (Edge)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class); assertEquals(ed, eRead); } catch (IOException e) { e.printStackTrace(); fail("Should not have thrown exception: " + e.getMessage()); } }
Example 15
Source File: TinkerGraphTest.java From tinkergraph-gremlin with Apache License 2.0 | 5 votes |
@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 16
Source File: TinkerGraphGraphSONSerializerV2d0Test.java From tinkergraph-gremlin with Apache License 2.0 | 5 votes |
@Test public void deserializersTestsMetrics() { final TinkerGraph tg = TinkerFactory.createModern(); final GraphWriter writer = getWriter(defaultMapperV2d0); final GraphReader reader = getReader(defaultMapperV2d0); final TraversalMetrics tm = tg.traversal().V(1).as("a").has("name").as("b"). out("knows").out("created").as("c"). has("name", "ripple").values("name").as("d"). identity().as("e").profile().next(); final MutableMetrics m = new MutableMetrics(tm.getMetrics(0)); // making sure nested metrics are included in serde m.addNested(new MutableMetrics(tm.getMetrics(1))); try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) { writer.writeObject(out, m); final String json = out.toString(); final Metrics metricsRead = (Metrics)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class); // toString should be enough to compare Metrics assertTrue(m.toString().equals(metricsRead.toString())); } catch (IOException e) { e.printStackTrace(); fail("Should not have thrown exception: " + e.getMessage()); } }
Example 17
Source File: TinkerGraphGraphSONSerializerV2d0Test.java From tinkergraph-gremlin with Apache License 2.0 | 5 votes |
@Test public void deserializersTestsProperty() { final TinkerGraph tg = TinkerGraph.open(); final Vertex v = tg.addVertex("vertexTest"); final Vertex v2 = tg.addVertex("vertexTest"); final Edge ed = v.addEdge("knows", v2); final GraphWriter writer = getWriter(defaultMapperV2d0); final GraphReader reader = getReader(defaultMapperV2d0); final Property prop = ed.property("since", Year.parse("1993")); try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) { writer.writeObject(out, prop); final String json = out.toString(); final Property pRead = (Property)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class); //can't use equals here, because pRead is detached, its parent element has not been intentionally //serialized and "equals()" checks that. assertTrue(prop.key().equals(pRead.key()) && prop.value().equals(pRead.value())); } catch (IOException e) { e.printStackTrace(); fail("Should not have thrown exception: " + e.getMessage()); } }
Example 18
Source File: TinkerGraphGraphSONSerializerV2d0Test.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test public void deserializersTestsProperty() { final TinkerGraph tg = TinkerGraph.open(); final Vertex v = tg.addVertex("vertexTest"); final Vertex v2 = tg.addVertex("vertexTest"); final Edge ed = v.addEdge("knows", v2); final GraphWriter writer = getWriter(defaultMapperV2d0); final GraphReader reader = getReader(defaultMapperV2d0); final Property prop = ed.property("since", Year.parse("1993")); try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) { writer.writeObject(out, prop); final String json = out.toString(); final Property pRead = (Property)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class); //can't use equals here, because pRead is detached, its parent element has not been intentionally //serialized and "equals()" checks that. assertTrue(prop.key().equals(pRead.key()) && prop.value().equals(pRead.value())); } catch (IOException e) { e.printStackTrace(); fail("Should not have thrown exception: " + e.getMessage()); } }
Example 19
Source File: TinkerGraphGraphSONSerializerV2d0Test.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test public void deserializersTestsMetrics() { final TinkerGraph tg = TinkerFactory.createModern(); final GraphWriter writer = getWriter(defaultMapperV2d0); final GraphReader reader = getReader(defaultMapperV2d0); final TraversalMetrics tm = tg.traversal().V(1).as("a").has("name").as("b"). out("knows").out("created").as("c"). has("name", "ripple").values("name").as("d"). identity().as("e").profile().next(); final MutableMetrics m = new MutableMetrics(tm.getMetrics(0)); // making sure nested metrics are included in serde m.addNested(new MutableMetrics(tm.getMetrics(1))); try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) { writer.writeObject(out, m); final String json = out.toString(); final Metrics metricsRead = (Metrics)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class); // toString should be enough to compare Metrics assertTrue(m.toString().equals(metricsRead.toString())); } catch (IOException e) { e.printStackTrace(); fail("Should not have thrown exception: " + e.getMessage()); } }
Example 20
Source File: TinkerGraphTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@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); } } }