|
| 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.detached; |
| 20 | + |
| 21 | +import com.arangodb.tinkerpop.gremlin.structure.ArangoDBGraph; |
| 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.detached.DetachedEdge; |
| 33 | +import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedFactory; |
| 34 | +import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex; |
| 35 | +import org.apache.tinkerpop.gremlin.structure.util.star.StarGraph; |
| 36 | +import org.junit.Ignore; |
| 37 | +import org.junit.Test; |
| 38 | + |
| 39 | +import java.util.Random; |
| 40 | +import java.util.UUID; |
| 41 | + |
| 42 | +/** |
| 43 | + * @author Marko A. Rodriguez (http://markorodriguez.com) |
| 44 | + */ |
| 45 | +public class DetachedGraphTest extends AbstractGremlinTest { |
| 46 | + |
| 47 | + // FIXME: review after DE-996 and DE-997 |
| 48 | + @Ignore("FIXME") |
| 49 | + @Test |
| 50 | + @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_USER_SUPPLIED_IDS) |
| 51 | + @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexPropertyFeatures.FEATURE_USER_SUPPLIED_IDS) |
| 52 | + @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_USER_SUPPLIED_IDS) |
| 53 | + @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES) |
| 54 | + @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_PROPERTY) |
| 55 | + @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES) |
| 56 | + @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_MULTI_PROPERTIES) |
| 57 | + @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES) |
| 58 | + @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_PROPERTY) |
| 59 | + public void testAttachableCreateMethod() { |
| 60 | + final Random random = TestHelper.RANDOM; |
| 61 | + StarGraph starGraph = StarGraph.open(); |
| 62 | + final String label = "person"; |
| 63 | + final String id = label + "/" + UUID.randomUUID(); |
| 64 | + Vertex starVertex = starGraph.addVertex(T.id, id, T.label, label, "name", "stephen", "name", "spmallete"); |
| 65 | + starVertex.property("acl", true, "timestamp", random.nextLong(), "creator", "marko"); |
| 66 | + for (int i = 0; i < 100; i++) { |
| 67 | + starVertex.addEdge("knows", starGraph.addVertex("person", "name", new UUID(random.nextLong(), random.nextLong()), "since", random.nextLong())); |
| 68 | + starGraph.addVertex(T.label, "project").addEdge("developedBy", starVertex, "public", random.nextBoolean()); |
| 69 | + } |
| 70 | + final DetachedVertex detachedVertex = DetachedFactory.detach(starGraph.getStarVertex(), true); |
| 71 | + final Vertex createdVertex = detachedVertex.attach(Attachable.Method.create(graph)); |
| 72 | + TestHelper.validateVertexEquality(detachedVertex, createdVertex, false); |
| 73 | + TestHelper.validateVertexEquality(detachedVertex, starVertex, false); |
| 74 | + |
| 75 | + starGraph.getStarVertex().edges(Direction.BOTH).forEachRemaining(starEdge -> { |
| 76 | + final DetachedEdge detachedEdge = DetachedFactory.detach(starEdge, true); |
| 77 | + final Edge createdEdge = detachedEdge.attach(Attachable.Method.create(random.nextBoolean() ? graph : createdVertex)); |
| 78 | + TestHelper.validateEdgeEquality(detachedEdge, starEdge); |
| 79 | + TestHelper.validateEdgeEquality(detachedEdge, createdEdge); |
| 80 | + }); |
| 81 | + |
| 82 | + } |
| 83 | +} |
0 commit comments