Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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.structure;
import org.apache.tinkerpop.gremlin.AbstractGremlinTest;
import org.apache.tinkerpop.gremlin.ExceptionCoverage;
import org.apache.tinkerpop.gremlin.FeatureRequirement;
import org.apache.tinkerpop.gremlin.FeatureRequirementSet;
import org.apache.tinkerpop.gremlin.GraphManager;
import org.apache.tinkerpop.gremlin.structure.Graph.Features.EdgePropertyFeatures;
import org.apache.tinkerpop.gremlin.structure.Graph.Features.PropertyFeatures;
import org.apache.tinkerpop.gremlin.structure.Graph.Features.VertexPropertyFeatures;
import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.apache.tinkerpop.gremlin.structure.Graph.Features.PropertyFeatures.FEATURE_PROPERTIES;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeThat;
/**
* Gremlin Test Suite for {@link org.apache.tinkerpop.gremlin.structure.Property} operations.
*
* @author Stephen Mallette (http://stephen.genoprime.com)
*/
@RunWith(Enclosed.class)
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public class PropertyTest {
/**
* Basic tests for the {@link org.apache.tinkerpop.gremlin.structure.Property} class.
*/
public static class BasicPropertyTest extends AbstractGremlinTest {
@Test
@FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
public void shouldHaveStandardStringRepresentation() {
final Vertex v = graph.addVertex("name", "marko");
final Property p = v.property("name");
assertEquals(StringFactory.propertyString(p), p.toString());
}
@Test
@FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
public void shouldReturnEmptyPropertyIfKeyNonExistent() {
final Vertex v = graph.addVertex("name", "marko");
tryCommit(graph, (graph) -> {
final Vertex v1 = graph.vertices(v.id()).next();
final VertexProperty p = v1.property("nonexistent-key");
assertEquals(VertexProperty.empty(), p);
});
}
@Test
@FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_REMOVE_PROPERTY)
public void shouldAllowRemovalFromVertexWhenAlreadyRemoved() {
final Vertex v = graph.addVertex("name", "marko");
tryCommit(graph);
final Vertex v1 = graph.vertices(v.id()).next();
try {
final Property p = v1.property("name");
p.remove();
p.remove();
v1.property("name").remove();
v1.property("name").remove();
} catch (Exception ex) {
fail("Removing a vertex property that was already removed should not throw an exception");
}
}
@Test
@FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_REMOVE_PROPERTY)
public void shouldAllowRemovalFromEdgeWhenAlreadyRemoved() {
final Vertex v = graph.addVertex("name", "marko");
tryCommit(graph);
final Vertex v1 = graph.vertices(v.id()).next();
try {
final Edge edge = v1.addEdge("knows", graph.addVertex());
final Property p = edge.property("stars", 5);
p.remove();
p.remove();
edge.property("stars").remove();
edge.property("stars").remove();
} catch (Exception ex) {
fail("Removing an edge property that was already removed should not throw an exception");
}
}
}
/**
* Checks that properties added to an {@link org.apache.tinkerpop.gremlin.structure.Element} are validated in a consistent way when they are added at
* {@link org.apache.tinkerpop.gremlin.structure.Vertex} or {@link org.apache.tinkerpop.gremlin.structure.Edge} construction by throwing an appropriate exception.
*/
@RunWith(Parameterized.class)
@ExceptionCoverage(exceptionClass = Element.Exceptions.class, methods = {
"providedKeyValuesMustBeAMultipleOfTwo",
"providedKeyValuesMustHaveALegalKeyOnEvenIndices"
})
@ExceptionCoverage(exceptionClass = Property.Exceptions.class, methods = {
"propertyValueCanNotBeNull",
"propertyKeyCanNotBeEmpty"
})
public static class PropertyValidationOnAddExceptionConsistencyTest extends AbstractGremlinTest {
@Parameterized.Parameters(name = "expect({0})")
public static Iterable