|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | +package com.arangodb.tinkerpop.gremlin.custom.structure.util.star; |
| 20 | + |
| 21 | +import org.apache.commons.configuration2.Configuration; |
| 22 | +import org.apache.tinkerpop.gremlin.AbstractGremlinTest; |
| 23 | +import org.apache.tinkerpop.gremlin.FeatureRequirement; |
| 24 | +import org.apache.tinkerpop.gremlin.LoadGraphWith; |
| 25 | +import org.apache.tinkerpop.gremlin.TestHelper; |
| 26 | +import org.apache.tinkerpop.gremlin.structure.Direction; |
| 27 | +import org.apache.tinkerpop.gremlin.structure.Edge; |
| 28 | +import org.apache.tinkerpop.gremlin.structure.Graph; |
| 29 | +import org.apache.tinkerpop.gremlin.structure.T; |
| 30 | +import org.apache.tinkerpop.gremlin.structure.Vertex; |
| 31 | +import org.apache.tinkerpop.gremlin.structure.util.Attachable; |
| 32 | +import org.apache.tinkerpop.gremlin.structure.util.star.StarGraph; |
| 33 | +import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; |
| 34 | +import org.junit.Ignore; |
| 35 | +import org.junit.Test; |
| 36 | + |
| 37 | +import java.util.List; |
| 38 | +import java.util.Random; |
| 39 | +import java.util.UUID; |
| 40 | +import java.util.stream.Collectors; |
| 41 | + |
| 42 | +import static org.junit.Assert.assertEquals; |
| 43 | + |
| 44 | +/** |
| 45 | + * @author Marko A. Rodriguez (http://markorodriguez.com) |
| 46 | + */ |
| 47 | +public class StarGraphTest extends AbstractGremlinTest { |
| 48 | + |
| 49 | + @Ignore("FIXME: DE-996") |
| 50 | + @Test |
| 51 | + @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_USER_SUPPLIED_IDS) |
| 52 | + @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexPropertyFeatures.FEATURE_USER_SUPPLIED_IDS) |
| 53 | + @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_USER_SUPPLIED_IDS) |
| 54 | + @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) |
| 55 | + @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_PROPERTY) |
| 56 | + @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES) |
| 57 | + @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_MULTI_PROPERTIES) |
| 58 | + @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES) |
| 59 | + @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_PROPERTY) |
| 60 | + @LoadGraphWith(LoadGraphWith.GraphData.MODERN) |
| 61 | + public void shouldCopyFromGraphAToGraphB() throws Exception { |
| 62 | + final List<StarGraph> starGraphs = IteratorUtils.stream(graph.vertices()).map(StarGraph::of).collect(Collectors.toList()); |
| 63 | + |
| 64 | + // via vertices and then edges |
| 65 | + final Configuration g1Configuration = graphProvider.newGraphConfiguration("readGraph", this.getClass(), name.getMethodName(), null); |
| 66 | + Graph g1 = graphProvider.openTestGraph(g1Configuration); |
| 67 | + starGraphs.stream().map(StarGraph::getStarVertex).forEach(vertex -> vertex.attach(Attachable.Method.getOrCreate(g1))); |
| 68 | + starGraphs.stream().forEach(starGraph -> starGraph.edges().forEachRemaining(edge -> ((Attachable<Edge>) edge).attach(Attachable.Method.getOrCreate(g1)))); |
| 69 | + assertEquals(IteratorUtils.count(graph.vertices()), IteratorUtils.count(g1.vertices())); |
| 70 | + assertEquals(IteratorUtils.count(graph.edges()), IteratorUtils.count(g1.edges())); |
| 71 | + graph.vertices().forEachRemaining(vertex -> TestHelper.validateVertexEquality(vertex, g1.vertices(vertex.id()).next(), true)); |
| 72 | + graphProvider.clear(g1, g1Configuration); |
| 73 | + |
| 74 | + // via edges only |
| 75 | + final Configuration g2Configuration = graphProvider.newGraphConfiguration("readGraph", this.getClass(), name.getMethodName(), null); |
| 76 | + final Graph g2 = graphProvider.openTestGraph(g2Configuration); |
| 77 | + starGraphs.stream().forEach(starGraph -> starGraph.edges().forEachRemaining(edge -> ((Attachable<Edge>) edge).attach(Attachable.Method.getOrCreate(g2)))); |
| 78 | + assertEquals(IteratorUtils.count(graph.vertices()), IteratorUtils.count(g2.vertices())); |
| 79 | + assertEquals(IteratorUtils.count(graph.edges()), IteratorUtils.count(g2.edges())); |
| 80 | + // TODO: you can't get adjacent labels -- graph.vertices().forEachRemaining(vertex -> TestHelper.validateVertexEquality(vertex, g1.vertices(vertex.id()).next(), true)); |
| 81 | + graphProvider.clear(g2, g2Configuration); |
| 82 | + } |
| 83 | + |
| 84 | + @Ignore("FIXME: DE-996") |
| 85 | + @Test |
| 86 | + @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_USER_SUPPLIED_IDS) |
| 87 | + @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexPropertyFeatures.FEATURE_USER_SUPPLIED_IDS) |
| 88 | + @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_USER_SUPPLIED_IDS) |
| 89 | + @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) |
| 90 | + @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_PROPERTY) |
| 91 | + @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES) |
| 92 | + @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_MULTI_PROPERTIES) |
| 93 | + @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES) |
| 94 | + @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_PROPERTY) |
| 95 | + public void shouldAttachWithCreateMethod() { |
| 96 | + final Random random = TestHelper.RANDOM; |
| 97 | + StarGraph starGraph = StarGraph.open(); |
| 98 | + Vertex starVertex = starGraph.addVertex(T.id, "person/" + UUID.randomUUID(), T.label, "person", "name", "stephen", "name", "spmallete"); |
| 99 | + starVertex.property("acl", true, "timestamp", random.nextLong(), "creator", "marko"); |
| 100 | + for (int i = 0; i < 100; i++) { |
| 101 | + starVertex.addEdge( |
| 102 | + "knows", |
| 103 | + starGraph.addVertex(T.id, "person/" + UUID.randomUUID(), T.label, "person", "name", new UUID(random.nextLong(), random.nextLong()), "since", random.nextLong()), |
| 104 | + T.id, "knows/" + UUID.randomUUID() |
| 105 | + ); |
| 106 | + starGraph |
| 107 | + .addVertex(T.id, "project/" + UUID.randomUUID(), T.label, "project") |
| 108 | + .addEdge("developedBy", starVertex, T.id, "developedBy/" + UUID.randomUUID(), "public", random.nextBoolean()); |
| 109 | + } |
| 110 | + final Vertex createdVertex = starGraph.getStarVertex().attach(Attachable.Method.create(graph)); |
| 111 | + starGraph.getStarVertex().edges(Direction.BOTH).forEachRemaining(edge -> ((Attachable<Edge>) edge).attach(Attachable.Method.create(random.nextBoolean() ? graph : createdVertex))); |
| 112 | + TestHelper.validateEquality(starVertex, createdVertex); |
| 113 | + } |
| 114 | + |
| 115 | +} |
0 commit comments