private void assertGeoshape(Function<Geoshape,Geoshape> makeGeoshape) { graph.traversal().E().has("place").toList().forEach(e-> { assertTrue(e.property("shape").isPresent()); Geoshape place = (Geoshape) e.property("place").value(); Geoshape expected = makeGeoshape.apply(place); Geoshape actual = (Geoshape) e.property("shape").value(); assertEquals(expected, actual); }); }
@Test @LoadGraphWith(MODERN) public void shouldLoadEdgesViaIds() { final List<Edge> edges = g.E().toList(); final List<Object> ids = edges.stream().map(Edge::id).collect(Collectors.toList()); final List<Edge> edgesReloaded = g.E(ids.toArray()).toList(); assertEquals(edges.size(), edgesReloaded.size()); assertEquals(new HashSet<>(edges), new HashSet<>(edgesReloaded)); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldHaveSameHashCode() { assertEquals(ReferenceFactory.detach(g.E(convertToEdgeId("josh", "created", "lop")).next()).hashCode(), ReferenceFactory.detach(g.E(convertToEdgeId("josh", "created", "lop")).next()).hashCode()); assertEquals(ReferenceFactory.detach(g.E(convertToEdgeId("josh", "created", "lop")).next()).hashCode(), g.E(convertToEdgeId("josh", "created", "lop")).next().hashCode()); assertEquals(ReferenceFactory.detach(g.E(convertToEdgeId("josh", "created", "lop")).next()).hashCode(), DetachedFactory.detach(g.E(convertToEdgeId("josh", "created", "lop")).next(), false).hashCode()); }
@Test public void testAddEdgeWithProp() { HugeGraph graph = graph(); Vertex james = graph.addVertex(T.label, "author", "id", 1, "name", "James Gosling", "age", 62, "lived", "Canadian"); Vertex book = graph.addVertex(T.label, "book", "name", "Test-Book-1"); james.addEdge("write", book, "time", "2017-4-28"); List<Edge> edges = graph.traversal().E().toList(); Assert.assertEquals(1, edges.size()); assertContains(edges, "write", james, book, "time", "2017-4-28"); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldEvaluateToEqual() { assertTrue(ReferenceFactory.detach(g.E(convertToEdgeId("josh", "created", "lop")).next()).equals(ReferenceFactory.detach(g.E(convertToEdgeId("josh", "created", "lop")).next()))); assertTrue(ReferenceFactory.detach(g.E(convertToEdgeId("josh", "created", "lop")).next()).equals(g.E(convertToEdgeId("josh", "created", "lop")).next())); assertTrue(ReferenceFactory.detach(g.E(convertToEdgeId("josh", "created", "lop")).next()).equals(DetachedFactory.detach(g.E(convertToEdgeId("josh", "created", "lop")).next(), true))); // assertTrue(ReferenceFactory.detach(g.E(convertToEdgeId("josh", "created", "lop")).next()).equals(ReferenceFactory.detach(g.E(convertToEdgeId("josh", "created", "lop")).next()))); assertTrue(g.E(convertToEdgeId("josh", "created", "lop")).next().equals(ReferenceFactory.detach(g.E(convertToEdgeId("josh", "created", "lop")).next()))); assertTrue(DetachedFactory.detach(g.E(convertToEdgeId("josh", "created", "lop")).next(), true).equals(ReferenceFactory.detach(g.E(convertToEdgeId("josh", "created", "lop")).next()))); }
@Parameterized.Parameters(name = "expectInterruption({0})") public static Iterable<Object[]> data() { return Arrays.asList(new Object[][]{ {"g_V", (Function<GraphTraversalSource, GraphTraversal<?,?>>) g -> g.V(), (UnaryOperator<GraphTraversal<?,?>>) t -> t}, {"g_V_out", (Function<GraphTraversalSource, GraphTraversal<?,?>>) g -> g.V(), (UnaryOperator<GraphTraversal<?,?>>) t -> t.out()}, {"g_V_outE", (Function<GraphTraversalSource, GraphTraversal<?,?>>) g -> g.V(), (UnaryOperator<GraphTraversal<?,?>>) t -> t.outE()}, {"g_V_in", (Function<GraphTraversalSource, GraphTraversal<?,?>>) g -> g.V(), (UnaryOperator<GraphTraversal<?,?>>) t -> t.in()}, {"g_V_inE", (Function<GraphTraversalSource, GraphTraversal<?,?>>) g -> g.V(), (UnaryOperator<GraphTraversal<?,?>>) t -> t.inE()}, {"g_V_properties", (Function<GraphTraversalSource, GraphTraversal<?,?>>) g -> g.V(), (UnaryOperator<GraphTraversal<?,?>>) t -> t.properties()}, {"g_E", (Function<GraphTraversalSource, GraphTraversal<?,?>>) g -> g.E(), (UnaryOperator<GraphTraversal<?,?>>) t -> t}, {"g_E_outV", (Function<GraphTraversalSource, GraphTraversal<?,?>>) g -> g.E(), (UnaryOperator<GraphTraversal<?,?>>) t -> t.outV()}, {"g_E_inV", (Function<GraphTraversalSource, GraphTraversal<?,?>>) g -> g.E(), (UnaryOperator<GraphTraversal<?,?>>) t -> t.inV()}, {"g_E_properties", (Function<GraphTraversalSource, GraphTraversal<?,?>>) g -> g.E(), (UnaryOperator<GraphTraversal<?,?>>) t -> t.properties()}, }); }
@Test @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_IO_READ) public void g_io_readXjsonX() throws IOException { final String fileToRead = TestHelper.generateTempFileFromResource(ReadTest.class, GraphSONResourceAccess.class, "tinkerpop-modern-v3d0.json", "").getAbsolutePath().replace('\\', '/'); final Traversal<Object,Object> traversal = get_g_io_readXjsonX(fileToRead); printTraversalForm(traversal); traversal.iterate(); if (graph instanceof RemoteGraph) { assertEquals(6L, g.V().count().next().longValue()); assertEquals(6L, g.E().count().next().longValue()); } else { IoTest.assertModernGraph(graph, false, true); } }
@Test public void testAddEdgeWithProps() { HugeGraph graph = graph(); Vertex james = graph.addVertex(T.label, "author", "id", 1, "name", "James Gosling", "age", 62, "lived", "Canadian"); Vertex book = graph.addVertex(T.label, "book", "name", "Test-Book-1"); james.addEdge("authored", book, "contribution", "1990-1-1", "score", 5); List<Edge> edges = graph.traversal().E().toList(); Assert.assertEquals(1, edges.size()); assertContains(edges, "authored", james, book, "contribution", "1990-1-1", "score", 5); }
@Test @LoadGraphWith(MODERN) public void shouldLoadEdgesViaEdges() { final List<Edge> edges = g.E().toList(); final List<Edge> edgesReloaded = g.E(edges.toArray()).toList(); assertEquals(edges.size(), edgesReloaded.size()); assertEquals(new HashSet<>(edges), new HashSet<>(edgesReloaded)); }
@Test public void testQueryEdgesByIdNotFound() { HugeGraph graph = graph(); init18Edges(); String id = graph.traversal().E().toList().get(0).id() + "-not-exist"; Assert.assertTrue(graph.traversal().E(id).toList().isEmpty()); Assert.assertThrows(NoSuchElementException.class, () -> { graph.traversal().E(id).next(); }); }
@Test @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_IO_READ) public void g_io_readXxmlX() throws IOException { final String fileToRead = TestHelper.generateTempFileFromResource(ReadTest.class, GraphMLResourceAccess.class, "tinkerpop-modern.xml", "").getAbsolutePath().replace('\\', '/'); final Traversal<Object,Object> traversal = get_g_io_readXxmlX(fileToRead); printTraversalForm(traversal); traversal.iterate(); if (graph instanceof RemoteGraph) { assertEquals(6L, g.V().count().next().longValue()); assertEquals(6L, g.E().count().next().longValue()); } else { IoTest.assertModernGraph(graph, false, true); } }
@Test public void testAddEdgeToSameVerticesWithMultiTimesAndOverrideEdge() { HugeGraph graph = graph(); Vertex james = graph.addVertex(T.label, "author", "id", 1, "name", "James Gosling", "age", 62, "lived", "Canadian"); Vertex book = graph.addVertex(T.label, "book", "name", "Test-Book-1"); james.addEdge("write", book, "time", "2017-4-28"); james.addEdge("write", book, "time", "2017-5-21"); james.addEdge("write", book, "time", "2017-5-25"); james.addEdge("write", book, "time", "2017-4-28"); james.addEdge("write", book, "time", "2017-5-21"); List<Edge> edges = graph.traversal().E().toList(); Assert.assertEquals(3, edges.size()); assertContains(edges, "write", james, book, "time", "2017-4-28"); assertContains(edges, "write", james, book, "time", "2017-5-21"); assertContains(edges, "write", james, book, "time", "2017-5-25"); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldBeEqualProperties() { assertTrue(DetachedFactory.detach(g.E(convertToEdgeId("josh", "created", "lop")).next().property("weight")).equals(DetachedFactory.detach(g.E(convertToEdgeId("josh", "created", "lop")).next().property("weight")))); }
@Test @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_IO_READ) public void g_io_read_withXreader_graphmlX() throws IOException { final String fileToRead = TestHelper.generateTempFileFromResource(ReadTest.class, GraphMLResourceAccess.class, "tinkerpop-modern.xml", "").getAbsolutePath().replace('\\', '/'); final Traversal<Object,Object> traversal = get_g_io_read_withXreader_graphmlX(fileToRead); printTraversalForm(traversal); traversal.iterate(); if (graph instanceof RemoteGraph) { assertEquals(6L, g.V().count().next().longValue()); assertEquals(6L, g.E().count().next().longValue()); } else { IoTest.assertModernGraph(graph, false, true); } }
@Test public void testQueryByLongPropOfOverrideEdge() { HugeGraph graph = graph(); initTransferIndex(); Vertex louise = graph.addVertex(T.label, "person", "name", "Louise", "city", "Beijing", "age", 21); Vertex sean = graph.addVertex(T.label, "person", "name", "Sean", "city", "Beijing", "age", 23); long current = System.currentTimeMillis(); louise.addEdge("strike", sean, "id", 1, "timestamp", current, "place", "park", "tool", "shovel", "reason", "jeer", "arrested", false); louise.addEdge("strike", sean, "id", 1, "timestamp", current + 1, "place", "park", "tool", "shovel", "reason", "jeer", "arrested", false); List<Edge> edges = graph.traversal().E().has("timestamp", current) .toList(); Assert.assertEquals(0, edges.size()); edges = graph.traversal().E().has("timestamp", current + 1).toList(); Assert.assertEquals(1, edges.size()); }
@Test @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_IO_READ) public void g_io_readXkryoX() throws IOException { final String fileToRead = TestHelper.generateTempFileFromResource(ReadTest.class, GryoResourceAccess.class, "tinkerpop-modern-v3d0.kryo", "").getAbsolutePath().replace('\\', '/'); final Traversal<Object,Object> traversal = get_g_io_readXkryoX(fileToRead); printTraversalForm(traversal); traversal.iterate(); if (graph instanceof RemoteGraph) { assertEquals(6L, g.V().count().next().longValue()); assertEquals(6L, g.E().count().next().longValue()); } else { IoTest.assertModernGraph(graph, false, true); } }
@Test public void testQueryByStringPropOfOverrideEdge() { HugeGraph graph = graph(); initStrikeIndex(); Vertex louise = graph.addVertex(T.label, "person", "name", "Louise", "city", "Beijing", "age", 21); Vertex sean = graph.addVertex(T.label, "person", "name", "Sean", "city", "Beijing", "age", 23); long current = System.currentTimeMillis(); louise.addEdge("strike", sean, "id", 1, "timestamp", current, "place", "park", "tool", "shovel", "reason", "jeer", "arrested", false); louise.addEdge("strike", sean, "id", 1, "timestamp", current, "place", "street", "tool", "shovel", "reason", "jeer", "arrested", false); List<Edge> edges = graph.traversal().E().has("place", "park") .toList(); Assert.assertEquals(0, edges.size()); edges = graph.traversal().E().has("place", "street").toList(); Assert.assertEquals(1, edges.size()); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldNotBeEqualPropertiesAsThereIsDifferentId() { assertFalse(DetachedFactory.detach(g.E(convertToEdgeId("marko", "created", "lop")).next().property("weight")).equals(DetachedFactory.detach(g.E(convertToEdgeId("josh", "created", "lop")).next().property("weight")))); }
@Test @FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_IO_READ) public void g_io_read_withXreader_gryoX() throws IOException { final String fileToRead = TestHelper.generateTempFileFromResource(ReadTest.class, GryoResourceAccess.class, "tinkerpop-modern-v3d0.kryo", "").getAbsolutePath().replace('\\', '/'); final Traversal<Object,Object> traversal = get_g_io_read_withXreader_gryoX(fileToRead); printTraversalForm(traversal); traversal.iterate(); if (graph instanceof RemoteGraph) { assertEquals(6L, g.V().count().next().longValue()); assertEquals(6L, g.E().count().next().longValue()); } else { IoTest.assertModernGraph(graph, false, true); } }