Java Code Examples for org.apache.tinkerpop.gremlin.TestHelper#validateVertexEquality()
The following examples show how to use
org.apache.tinkerpop.gremlin.TestHelper#validateVertexEquality() .
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: DetachedGraphTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_USER_SUPPLIED_IDS) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexPropertyFeatures.FEATURE_USER_SUPPLIED_IDS) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_USER_SUPPLIED_IDS) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_PROPERTY) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_MULTI_PROPERTIES) @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES) @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_PROPERTY) public void testAttachableCreateMethod() { final Random random = TestHelper.RANDOM; StarGraph starGraph = StarGraph.open(); Vertex starVertex = starGraph.addVertex(T.label, "person", "name", "stephen", "name", "spmallete"); starVertex.property("acl", true, "timestamp", random.nextLong(), "creator", "marko"); for (int i = 0; i < 100; i++) { starVertex.addEdge("knows", starGraph.addVertex("person", "name", new UUID(random.nextLong(), random.nextLong()), "since", random.nextLong())); starGraph.addVertex(T.label, "project").addEdge("developedBy", starVertex, "public", random.nextBoolean()); } final DetachedVertex detachedVertex = DetachedFactory.detach(starGraph.getStarVertex(), true); final Vertex createdVertex = detachedVertex.attach(Attachable.Method.create(graph)); TestHelper.validateVertexEquality(detachedVertex, createdVertex, false); TestHelper.validateVertexEquality(detachedVertex, starVertex, false); starGraph.getStarVertex().edges(Direction.BOTH).forEachRemaining(starEdge -> { final DetachedEdge detachedEdge = DetachedFactory.detach(starEdge, true); final Edge createdEdge = detachedEdge.attach(Attachable.Method.create(random.nextBoolean() ? graph : createdVertex)); TestHelper.validateEdgeEquality(detachedEdge, starEdge); TestHelper.validateEdgeEquality(detachedEdge, createdEdge); }); }
Example 2
Source File: StarGraphTest.java From tinkerpop with Apache License 2.0 | 4 votes |
@Test @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_PROPERTY) @FeatureRequirement(featureClass = Graph.Features.VertexPropertyFeatures.class, feature = Graph.Features.VertexPropertyFeatures.FEATURE_STRING_VALUES) @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES) @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_PROPERTY) @FeatureRequirement(featureClass = Graph.Features.EdgePropertyFeatures.class, feature = Graph.Features.EdgePropertyFeatures.FEATURE_STRING_VALUES) public void shouldHandleSelfLoops() { assertEquals(0l, IteratorUtils.count(graph.vertices())); assertEquals(0l, IteratorUtils.count(graph.edges())); final Vertex vertex = graph.addVertex("person"); final VertexProperty<String> vertexProperty = vertex.property("name", "furnace"); final Edge edge = vertex.addEdge("self", vertex); final Property<String> edgeProperty = edge.property("acl", "private"); assertEquals(1l, IteratorUtils.count(graph.vertices())); assertEquals(1l, IteratorUtils.count(graph.edges())); assertEquals(1l, IteratorUtils.count(vertex.properties())); assertEquals(1l, IteratorUtils.count(edge.properties())); assertEquals(vertexProperty, vertex.properties().next()); assertEquals(edgeProperty, edge.properties().next()); /// final StarGraph starGraph = StarGraph.of(vertex); final StarGraph.StarVertex starVertex = starGraph.getStarVertex(); final Edge starEdge = starVertex.edges(Direction.OUT).next(); assertEquals(vertex, starVertex); assertEquals(edge, starEdge); assertEquals(1l, IteratorUtils.count(starVertex.properties())); assertEquals("furnace", starVertex.value("name")); assertEquals(2l, IteratorUtils.count(starVertex.vertices(Direction.BOTH, "self"))); assertEquals(1l, IteratorUtils.count(starVertex.vertices(Direction.OUT, "self"))); assertEquals(1l, IteratorUtils.count(starVertex.vertices(Direction.IN, "self"))); Iterator<Vertex> vertexIterator = starVertex.vertices(Direction.BOTH, "self"); assertEquals(starVertex, vertexIterator.next()); assertEquals(starVertex, vertexIterator.next()); assertFalse(vertexIterator.hasNext()); assertEquals(starVertex, starVertex.vertices(Direction.OUT, "self").next()); assertEquals(starVertex, starVertex.vertices(Direction.IN, "self").next()); /// assertEquals(2l, IteratorUtils.count(starVertex.vertices(Direction.BOTH))); assertEquals(1l, IteratorUtils.count(starVertex.vertices(Direction.OUT))); assertEquals(1l, IteratorUtils.count(starVertex.vertices(Direction.IN))); vertexIterator = starVertex.vertices(Direction.BOTH); assertEquals(starVertex, vertexIterator.next()); assertEquals(starVertex, vertexIterator.next()); assertFalse(vertexIterator.hasNext()); assertEquals(starVertex, starVertex.vertices(Direction.OUT).next()); assertEquals(starVertex, starVertex.vertices(Direction.IN).next()); /// assertEquals(2l, IteratorUtils.count(starVertex.edges(Direction.BOTH, "self", "nothing"))); assertEquals(1l, IteratorUtils.count(starVertex.edges(Direction.OUT, "self", "nothing"))); assertEquals(1l, IteratorUtils.count(starVertex.edges(Direction.IN, "self", "nothing"))); Iterator<Edge> edgeIterator = starVertex.edges(Direction.BOTH, "self", "nothing"); Edge tempEdge = edgeIterator.next(); assertEquals(1l, IteratorUtils.count(tempEdge.properties())); assertEquals("private", tempEdge.value("acl")); assertEquals(starEdge, tempEdge); tempEdge = edgeIterator.next(); assertEquals(1l, IteratorUtils.count(tempEdge.properties())); assertEquals("private", tempEdge.value("acl")); assertEquals(starEdge, tempEdge); assertFalse(edgeIterator.hasNext()); assertEquals(starEdge, starVertex.edges(Direction.OUT, "self", "nothing").next()); assertEquals(starEdge, starVertex.edges(Direction.IN, "self", "nothing").next()); // final StarGraph starGraphCopy = serializeDeserialize(starGraph).getValue0(); TestHelper.validateVertexEquality(vertex, starGraph.getStarVertex(), true); TestHelper.validateVertexEquality(vertex, starGraphCopy.getStarVertex(), true); TestHelper.validateVertexEquality(starGraph.getStarVertex(), starGraphCopy.getStarVertex(), true); // test native non-clone-based methods final StarGraph starGraphNative = StarGraph.open(); Vertex v1 = starGraphNative.addVertex(T.label, "thing", T.id, "v1"); assertEquals("v1", v1.id()); assertEquals("thing", v1.label()); Edge e1 = v1.addEdge("self", v1, "name", "pipes"); assertEquals(2l, IteratorUtils.count(v1.vertices(Direction.BOTH, "self", "nothing"))); assertEquals(1l, IteratorUtils.count(v1.vertices(Direction.OUT))); assertEquals(1l, IteratorUtils.count(v1.vertices(Direction.IN, "self"))); edgeIterator = v1.edges(Direction.BOTH); TestHelper.validateEdgeEquality(e1, edgeIterator.next()); TestHelper.validateEdgeEquality(e1, edgeIterator.next()); assertFalse(edgeIterator.hasNext()); TestHelper.validateEdgeEquality(e1, v1.edges(Direction.OUT, "self", "nothing").next()); TestHelper.validateEdgeEquality(e1, v1.edges(Direction.IN).next()); }