This is an automated email from the ASF dual-hosted git repository. spmallette pushed a commit to branch TINKERPOP-2235 in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
commit 185a32db316a0a5eabf589a52aeeb1b2188e53bb Author: stephen <[email protected]> AuthorDate: Tue Nov 26 08:02:40 2019 -0500 TINKERPOP-2235 Ensured null defaults to default vertex label for all overloads of addV() --- CHANGELOG.asciidoc | 3 +- .../traversal/dsl/graph/GraphTraversalSource.java | 6 ++- .../traversal/step/map/AddVertexStartStep.java | 2 +- .../process/traversal/step/map/AddVertexStep.java | 2 +- .../traversal/step/map/AddVertexStepTest.java | 48 ++++++++++++++++++++++ 5 files changed, 56 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index b88d717..c7a2b36 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -25,7 +25,8 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima This release also includes changes from <<release-3-4-3, 3.4.3>>. -* Allowed the possibility for the user of `null` in Gremlin. +* Allowed the possibility for the propagation of `null` as a `Traverser` in Gremlin. +* Ensured better consistency of the use of `null` as arguments to mutation steps. * Added a `Graph.Feature` for `supportsNullPropertyValues`. * Refactored `MapStep` to move its logic to `ScalarMapStep` so that the old behavior could be preserved while allow other implementations to have more flexibility. * Modified TinkerGraph to support `null` property values and can be configured to disable that feature. diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSource.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSource.java index 0b2398f..011bae7 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSource.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSource.java @@ -297,7 +297,8 @@ public class GraphTraversalSource implements TraversalSource { /** - * Spawns a {@link GraphTraversal} by adding a vertex with the specified label. + * Spawns a {@link GraphTraversal} by adding a vertex with the specified label. If the {@code label} is + * {@code null} then it will default to {@link Vertex#DEFAULT_LABEL}. */ public GraphTraversal<Vertex, Vertex> addV(final String label) { final GraphTraversalSource clone = this.clone(); @@ -307,7 +308,8 @@ public class GraphTraversalSource implements TraversalSource { } /** - * Spawns a {@link GraphTraversal} by adding a vertex with the label as determined by a {@link Traversal}. + * Spawns a {@link GraphTraversal} by adding a vertex with the label as determined by a {@link Traversal}. If the + * {@code vertexLabelTraversal} is {@code null} then it will default to {@link Vertex#DEFAULT_LABEL}. */ public GraphTraversal<Vertex, Vertex> addV(final Traversal<?, String> vertexLabelTraversal) { final GraphTraversalSource clone = this.clone(); diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddVertexStartStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddVertexStartStep.java index 547517c..6273fa2 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddVertexStartStep.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddVertexStartStep.java @@ -58,7 +58,7 @@ public class AddVertexStartStep extends AbstractStep<Vertex, Vertex> public AddVertexStartStep(final Traversal.Admin traversal, final Traversal<?, String> vertexLabelTraversal) { super(traversal); - this.parameters.set(this, T.label, vertexLabelTraversal); + this.parameters.set(this, T.label, null == vertexLabelTraversal ? Vertex.DEFAULT_LABEL : vertexLabelTraversal); } @Override diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddVertexStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddVertexStep.java index 296e8b5..b963db2 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddVertexStep.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddVertexStep.java @@ -53,7 +53,7 @@ public class AddVertexStep<S> extends ScalarMapStep<S, Vertex> public AddVertexStep(final Traversal.Admin traversal, final Traversal.Admin<S,String> vertexLabelTraversal) { super(traversal); - this.parameters.set(this, T.label, vertexLabelTraversal); + this.parameters.set(this, T.label, null == vertexLabelTraversal ? Vertex.DEFAULT_LABEL : vertexLabelTraversal); } @Override diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddVertexStepTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddVertexStepTest.java new file mode 100644 index 0000000..7022bc8 --- /dev/null +++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddVertexStepTest.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tinkerpop.gremlin.process.traversal.step.map; + +import org.apache.tinkerpop.gremlin.process.traversal.Traversal; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; + +public class AddVertexStepTest { + + @Test + public void shouldDefaultTheLabelIfNullString() { + final Traversal.Admin t = mock(Traversal.Admin.class); + final AddVertexStartStep starStep = new AddVertexStartStep(t, (String) null); + assertEquals(Vertex.DEFAULT_LABEL, starStep.getParameters().getRaw().get(T.label).get(0)); + final AddVertexStep step = new AddVertexStep(t, (String) null); + assertEquals(Vertex.DEFAULT_LABEL, starStep.getParameters().getRaw().get(T.label).get(0)); + } + + @Test + public void shouldDefaultTheLabelIfNullTraversal() { + final Traversal.Admin t = mock(Traversal.Admin.class); + final AddVertexStartStep starStep = new AddVertexStartStep(t, (Traversal<?,String>) null); + assertEquals(Vertex.DEFAULT_LABEL, starStep.getParameters().getRaw().get(T.label).get(0)); + final AddVertexStep step = new AddVertexStep(t, (String) null); + assertEquals(Vertex.DEFAULT_LABEL, starStep.getParameters().getRaw().get(T.label).get(0)); + } +}
