Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

Commit 721cfaf

Browse files
committed
tests fixes
1 parent ad93347 commit 721cfaf

File tree

11 files changed

+166
-47
lines changed

11 files changed

+166
-47
lines changed

src/main/java/com/arangodb/tinkerpop/gremlin/structure/ArangoDBGraph.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,6 @@ public boolean supportsNumericIds() {
185185

186186
@Override
187187
public boolean supportsUuidIds() {
188-
/* We can not use Java Objects as keys, ergo we can not support UUID and Integer
189-
* the string representation of these is fine for ArangoDB, which makes the test
190-
* complain because it expects the actual class to be deserialized. We can test
191-
* to see if a string is accepted for deserialization.
192-
* TODO As with properties, a way to support this is to store the id value class
193-
*/
194188
return false;
195189
}
196190
}
@@ -239,12 +233,6 @@ public boolean supportsNumericIds() {
239233

240234
@Override
241235
public boolean supportsUuidIds() {
242-
/* We can not use Java Objects as keys, ergo we can not support UUID and Integer
243-
* the string representation of these is fine for ArangoDB, which makes the test
244-
* complain because it expects the actual class to be deserialized. We can test
245-
* to see if a string is accepted for deserialization.
246-
* TODO As with properties, a way to support this is to store the id value class
247-
*/
248236
return false;
249237
}
250238
}

src/main/java/com/arangodb/tinkerpop/gremlin/utils/ArangoDBUtil.java

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -581,43 +581,50 @@ public static String extractCollection(final String id) {
581581
}
582582
}
583583

584+
// FIXME: review
584585
public static Optional<String> extractLabel(final String id, final String label) {
585586
String col = extractCollection(id);
586587
if (col != null) {
587-
if (label != null && !label.equals(col)) {
588+
String labelFromId = col.replaceFirst("^.*_", "");
589+
if (label != null && !label.equals(labelFromId)) {
588590
throw new IllegalArgumentException("Invalid label: [" + label + "] for id: [" + id + "]");
589591
}
590-
return Optional.of(col);
592+
return Optional.of(labelFromId);
591593
}
592594
return Optional.ofNullable(label);
593595
}
594596

595-
// FIXME: DE-996
597+
// FIXME: use com.arangodb.tinkerpop.gremlin.utils.ArangoDBUtil.extractKey() and com.arangodb.tinkerpop.gremlin.utils.ArangoDBUtil.extractLabel()
596598
public static String getId(Graph.Features.ElementFeatures features, String label, Object... keyValues) {
597599
Optional<Object> optionalId = ElementHelper.getIdValue(keyValues);
598600
if (!optionalId.isPresent()) {
599601
return null;
600602
}
601-
Object id = optionalId.get();
602-
if (features.willAllowId(id)) {
603-
if (id.toString().contains("/")) {
604-
String fullId = id.toString();
605-
String[] parts = fullId.split("/");
606-
// The collection name is the last part of the full name
607-
String[] collectionParts = parts[0].split("_");
608-
String collectionName = collectionParts[collectionParts.length - 1];
609-
if (collectionName.contains(label)) {
603+
String id = optionalId
604+
.filter(features::willAllowId)
605+
.map(Object::toString)
606+
.orElseThrow(Vertex.Exceptions::userSuppliedIdsOfThisTypeNotSupported);
607+
608+
if (id.contains("/")) {
609+
String fullId = id;
610+
String[] parts = fullId.split("/");
611+
// The collection name is the last part of the full name
612+
String[] collectionParts = parts[0].split("_");
613+
String collectionName = collectionParts[collectionParts.length - 1];
614+
Optional<String> inferredLabel = extractLabel(id, label);
615+
if(inferredLabel.isPresent()) {
616+
if (collectionName.contains(inferredLabel.get())) {
610617
id = parts[1];
611618
}
612619
}
613-
Matcher m = ArangoDBUtil.DOCUMENT_KEY.matcher(id.toString());
614-
if (m.matches()) {
615-
return id.toString();
616-
} else {
617-
throw new ArangoDBGraphException(String.format("Given id (%s) has unsupported characters.", id));
618-
}
620+
}
621+
622+
// FIXME: review
623+
Matcher m = ArangoDBUtil.DOCUMENT_KEY.matcher(id);
624+
if (m.matches()) {
625+
return id;
619626
} else {
620-
throw Vertex.Exceptions.userSuppliedIdsOfThisTypeNotSupported();
627+
throw new ArangoDBGraphException(String.format("Given id (%s) has unsupported characters.", id));
621628
}
622629
}
623630

src/test/java/com/arangodb/tinkerpop/gremlin/TestGraph.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929
@Graph.OptOut(
3030
test = "org.apache.tinkerpop.gremlin.structure.util.star.StarGraphTest",
3131
method = "shouldAttachWithCreateMethod",
32-
reason = "FIXME: DE-997")
32+
reason = "replaced by com.arangodb.tinkerpop.gremlin.custom.structure.util.star.StarGraphTest.shouldAttachWithCreateMethod")
3333
@Graph.OptOut(
3434
test = "org.apache.tinkerpop.gremlin.structure.util.star.StarGraphTest",
3535
method = "shouldCopyFromGraphAToGraphB",
36-
reason = "FIXME: DE-996")
36+
reason = "replaced by com.arangodb.tinkerpop.gremlin.custom.structure.util.star.StarGraphTest.shouldCopyFromGraphAToGraphB")
3737
@Graph.OptOut(
3838
test = "org.apache.tinkerpop.gremlin.structure.VertexTest$BasicVertexTest",
3939
method = "shouldEvaluateEquivalentVertexHashCodeWithSuppliedIds",

src/test/java/com/arangodb/tinkerpop/gremlin/custom/CustomGraphProvider.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class CustomGraphProvider extends BaseGraphProvider {
1313
@Override
1414
public Configuration newGraphConfiguration(String graphName, Class<?> test, String testMethodName, Map<String, Object> configurationOverrides, LoadGraphWith.GraphData loadGraphWith) {
1515
Configuration conf = super.newGraphConfiguration(graphName, test, testMethodName, configurationOverrides, loadGraphWith);
16-
conf.setProperty(Graph.GRAPH, CustomGraph.class.getName());
16+
conf.setProperty(Graph.GRAPH, CustomTestGraph.class.getName());
1717
return conf;
1818
}
1919

@@ -35,13 +35,24 @@ protected void configure(ArangoDBConfigurationBuilder builder, Class<?> test, St
3535
builder.configureEdge("self", "person", "person");
3636
break;
3737
case "testAttachableCreateMethod":
38+
case "shouldAttachWithCreateMethod":
39+
builder.withVertexCollection("vertex");
3840
builder.withVertexCollection("person");
3941
builder.withVertexCollection("project");
4042
builder.withEdgeCollection("knows");
4143
builder.withEdgeCollection("developedBy");
4244
builder.configureEdge("knows", "person", "person");
4345
builder.configureEdge("developedBy", "project", "person");
4446
break;
47+
case "shouldCopyFromGraphAToGraphB":
48+
builder.withVertexCollection("vertex");
49+
builder.withVertexCollection("person");
50+
builder.withVertexCollection("software");
51+
builder.withEdgeCollection("knows");
52+
builder.withEdgeCollection("created");
53+
builder.configureEdge("knows", "person", "person");
54+
builder.configureEdge("created", "person", "software");
55+
break;
4556
}
4657
}
4758
}

src/test/java/com/arangodb/tinkerpop/gremlin/custom/CustomStandardSuite.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.arangodb.tinkerpop.gremlin.custom.process.traversal.step.OrderabilityTest;
44
import com.arangodb.tinkerpop.gremlin.custom.process.traversal.step.map.MergeEdgeTest;
55
import com.arangodb.tinkerpop.gremlin.custom.structure.util.detached.DetachedGraphTest;
6+
import com.arangodb.tinkerpop.gremlin.custom.structure.util.star.StarGraphTest;
67
import org.apache.tinkerpop.gremlin.AbstractGremlinSuite;
78
import org.apache.tinkerpop.gremlin.process.traversal.TraversalEngine;
89
import org.junit.runners.model.InitializationError;
@@ -14,7 +15,8 @@ public class CustomStandardSuite extends AbstractGremlinSuite {
1415
private static final Class<?>[] allTests = new Class<?>[]{
1516
MergeEdgeTest.Traversals.class,
1617
OrderabilityTest.Traversals.class,
17-
DetachedGraphTest.class
18+
DetachedGraphTest.class,
19+
StarGraphTest.class
1820
};
1921

2022
public CustomStandardSuite(final Class<?> klass, final RunnerBuilder builder) throws InitializationError {

src/test/java/com/arangodb/tinkerpop/gremlin/custom/CustomStandardSuiteTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import org.junit.runner.RunWith;
55

66
@RunWith(CustomStandardSuite.class)
7-
@GraphProviderClass(provider = CustomGraphProvider.class, graph = CustomGraph.class)
7+
@GraphProviderClass(provider = CustomGraphProvider.class, graph = CustomTestGraph.class)
88
public class CustomStandardSuiteTest {
99

1010
}

src/test/java/com/arangodb/tinkerpop/gremlin/custom/CustomGraph.java renamed to src/test/java/com/arangodb/tinkerpop/gremlin/custom/CustomTestGraph.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
import org.apache.tinkerpop.gremlin.structure.Graph;
66

77
@Graph.OptIn("com.arangodb.tinkerpop.gremlin.custom.CustomStandardSuite")
8-
public class CustomGraph extends ArangoDBGraph {
8+
public class CustomTestGraph extends ArangoDBGraph {
99

1010
@SuppressWarnings("unused")
11-
public static CustomGraph open(Configuration configuration) {
12-
return new CustomGraph(configuration);
11+
public static CustomTestGraph open(Configuration configuration) {
12+
return new CustomTestGraph(configuration);
1313
}
1414

15-
public CustomGraph(Configuration configuration) {
15+
public CustomTestGraph(Configuration configuration) {
1616
super(configuration);
1717
}
1818

src/test/java/com/arangodb/tinkerpop/gremlin/custom/structure/util/detached/DetachedGraphTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@
1818
*/
1919
package com.arangodb.tinkerpop.gremlin.custom.structure.util.detached;
2020

21-
import com.arangodb.tinkerpop.gremlin.structure.ArangoDBGraph;
2221
import org.apache.tinkerpop.gremlin.AbstractGremlinTest;
2322
import org.apache.tinkerpop.gremlin.FeatureRequirement;
24-
import org.apache.tinkerpop.gremlin.LoadGraphWith;
2523
import org.apache.tinkerpop.gremlin.TestHelper;
2624
import org.apache.tinkerpop.gremlin.structure.Direction;
2725
import org.apache.tinkerpop.gremlin.structure.Edge;
@@ -44,7 +42,7 @@
4442
*/
4543
public class DetachedGraphTest extends AbstractGremlinTest {
4644

47-
// FIXME: review after DE-996 and DE-997
45+
// FIXME: review after DE-996
4846
@Ignore("FIXME")
4947
@Test
5048
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_USER_SUPPLIED_IDS)
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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+
}

src/test/java/com/arangodb/tinkerpop/gremlin/structure/StructureGraphProvider.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ protected void configure(ArangoDBConfigurationBuilder builder, Class<?> test, St
144144
builder.withVertexCollection("person");
145145
builder.withEdgeCollection("self");
146146
break;
147-
case "shouldAttachWithCreateMethod":
148147
case "testAttachableCreateMethod":
149148
builder.withVertexCollection("person");
150149
builder.withVertexCollection("project");

0 commit comments

Comments
 (0)