
com.tinkerpop.gremlin.structure.FeatureSupportTest Maven / Gradle / Ivy
package com.tinkerpop.gremlin.structure;
import com.tinkerpop.gremlin.AbstractGremlinTest;
import com.tinkerpop.gremlin.GraphManager;
import com.tinkerpop.gremlin.structure.Graph.Features.EdgeFeatures;
import com.tinkerpop.gremlin.structure.Graph.Features.EdgePropertyFeatures;
import com.tinkerpop.gremlin.structure.Graph.Features.GraphFeatures;
import com.tinkerpop.gremlin.structure.Graph.Features.VertexFeatures;
import com.tinkerpop.gremlin.structure.Graph.Features.VertexPropertyFeatures;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import static com.tinkerpop.gremlin.structure.Graph.Features.VariableFeatures.FEATURE_VARIABLES;
import static com.tinkerpop.gremlin.structure.Graph.Features.GraphFeatures.FEATURE_COMPUTER;
import static com.tinkerpop.gremlin.structure.Graph.Features.GraphFeatures.FEATURE_THREADED_TRANSACTIONS;
import static com.tinkerpop.gremlin.structure.Graph.Features.GraphFeatures.FEATURE_TRANSACTIONS;
import static com.tinkerpop.gremlin.structure.Graph.Features.VertexFeatures.FEATURE_USER_SUPPLIED_IDS;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeThat;
/**
* Tests that do basic validation of proper Feature settings in Graph implementations.
*
* @author Stephen Mallette (http://stephen.genoprime.com)
*/
@RunWith(Enclosed.class)
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public class FeatureSupportTest {
private static final String INVALID_FEATURE_SPECIFICATION = "Features for %s specify that %s is false, but the feature appears to be implemented. Reconsider this setting or throw the standard Exception.";
public static class FeatureToStringTest extends AbstractGremlinTest {
/**
* A rough test to ensure that StringFactory is being used to toString Features.
*/
@Test
public void shouldHaveStandardToStringRepresentation() {
assertTrue(g.getFeatures().toString().startsWith("FEATURES"));
}
}
/**
* Feature checks that test {@link com.tinkerpop.gremlin.structure.Graph} functionality to determine if a feature should be on when it is marked
* as not supported.
*/
@ExceptionCoverage(exceptionClass = Graph.Exceptions.class, methods = {
"variablesNotSupported",
"graphComputerNotSupported",
"transactionsNotSupported"
})
public static class GraphFunctionalityTest extends AbstractGremlinTest {
/**
* This isn't really a test. It just pretty prints the features for the graph for reference. Of course,
* if the implementing classes use anonymous inner classes it will
*/
@Test
public void printTheFeatureList() {
System.out.println(String.format("Printing Features of %s for reference: ", g.getClass().getSimpleName()));
System.out.println(g.getFeatures());
assertTrue(true);
}
/**
* A {@link com.tinkerpop.gremlin.structure.Graph} that does not support {@link com.tinkerpop.gremlin.structure.Graph.Features.GraphFeatures#FEATURE_COMPUTER} must call
* {@link com.tinkerpop.gremlin.structure.Graph.Exceptions#graphComputerNotSupported()}.
*/
@Test
@FeatureRequirement(featureClass = GraphFeatures.class, feature = FEATURE_COMPUTER, supported = false)
public void ifAGraphCanComputeThenItMustSupportComputer() throws Exception {
try {
g.compute();
fail(String.format(INVALID_FEATURE_SPECIFICATION, GraphFeatures.class.getSimpleName(), FEATURE_COMPUTER));
} catch (UnsupportedOperationException e) {
assertEquals(Graph.Exceptions.graphComputerNotSupported().getMessage(), e.getMessage());
}
}
/**
* A {@link com.tinkerpop.gremlin.structure.Graph} that does not support {@link com.tinkerpop.gremlin.structure.Graph.Features.GraphFeatures#FEATURE_TRANSACTIONS} must call
* {@link com.tinkerpop.gremlin.structure.Graph.Exceptions#transactionsNotSupported()}.
*/
@Test
@FeatureRequirement(featureClass = GraphFeatures.class, feature = FEATURE_TRANSACTIONS, supported = false)
public void ifAGraphConstructsATxThenItMustSupportTransactions() throws Exception {
try {
g.tx();
fail(String.format(INVALID_FEATURE_SPECIFICATION, GraphFeatures.class.getSimpleName(), FEATURE_TRANSACTIONS));
} catch (UnsupportedOperationException e) {
assertEquals(Graph.Exceptions.transactionsNotSupported().getMessage(), e.getMessage());
}
}
/**
* A {@link com.tinkerpop.gremlin.structure.Graph} that does not support {@link com.tinkerpop.gremlin.structure.Graph.Features.VariableFeatures#FEATURE_VARIABLES} must call
* {@link com.tinkerpop.gremlin.structure.Graph.Exceptions#variablesNotSupported()}.
*/
@Test
@FeatureRequirement(featureClass = Graph.Features.VariableFeatures.class, feature = FEATURE_VARIABLES, supported = false)
public void ifAGraphAcceptsMemoryThenItMustSupportMemory() throws Exception {
try {
g.variables();
fail(String.format(INVALID_FEATURE_SPECIFICATION, Graph.Features.VariableFeatures.class.getSimpleName(), FEATURE_VARIABLES));
} catch (UnsupportedOperationException e) {
assertEquals(Graph.Exceptions.variablesNotSupported().getMessage(), e.getMessage());
}
}
@Test
@FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = FEATURE_TRANSACTIONS)
@FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = FEATURE_THREADED_TRANSACTIONS, supported = false)
public void testThreadedTransactionNotSupported() {
try {
g.tx().create();
fail("An exception should be thrown since the threaded transaction feature is not supported");
} catch (Exception ex) {
final Exception expectedException = Transaction.Exceptions.threadedTransactionsNotSupported();
assertEquals(expectedException.getClass(), ex.getClass());
assertEquals(expectedException.getMessage(), ex.getMessage());
}
}
}
/**
* Feature checks that test {@link com.tinkerpop.gremlin.structure.Vertex} functionality to determine if a feature
* should be on when it is marked as not supported.
*/
public static class VertexFunctionalityTest extends AbstractGremlinTest {
@Test
@FeatureRequirement(featureClass = VertexFeatures.class, feature = FEATURE_USER_SUPPLIED_IDS, supported = false)
public void ifAnIdCanBeAssignedToVertexThenItMustSupportUserSuppliedIds() throws Exception {
try {
g.addVertex(Element.ID, GraphManager.get().convertId(99999943835l));
fail(String.format(INVALID_FEATURE_SPECIFICATION, VertexFeatures.class.getSimpleName(), FEATURE_USER_SUPPLIED_IDS));
} catch (Exception ex) {
assertEquals(Vertex.Exceptions.userSuppliedIdsNotSupported().getMessage(), ex.getMessage());
}
}
}
/**
* Feature checks that test {@link com.tinkerpop.gremlin.structure.Edge} functionality to determine if a feature
* should be on when it is marked as not supported.
*/
public static class EdgeFunctionalityTest extends AbstractGremlinTest {
@Test
@FeatureRequirement(featureClass = EdgeFeatures.class, feature = EdgeFeatures.FEATURE_USER_SUPPLIED_IDS, supported = false)
public void ifAnIdCanBeAssignedToEdgeThenItMustSupportUserSuppliedIds() throws Exception {
try {
final Vertex v = g.addVertex();
v.addEdge("friend", v, Element.ID, GraphManager.get().convertId(99999943835l));
fail(String.format(INVALID_FEATURE_SPECIFICATION, VertexFeatures.class.getSimpleName(), EdgeFeatures.FEATURE_USER_SUPPLIED_IDS));
} catch (Exception ex) {
assertEquals(Edge.Exceptions.userSuppliedIdsNotSupported().getMessage(), ex.getMessage());
}
}
}
/**
* Feature checks that test {@link com.tinkerpop.gremlin.structure.Element} {@link com.tinkerpop.gremlin.structure.Property} functionality to determine if a feature should be on
* when it is marked as not supported.
*/
@RunWith(Parameterized.class)
@ExceptionCoverage(exceptionClass = Property.Exceptions.class, methods = {
"dataTypeOfPropertyValueNotSupported"
})
public static class ElementPropertyFunctionalityTest extends AbstractGremlinTest {
private static final String INVALID_FEATURE_SPECIFICATION = "Features for %s specify that %s is false, but the feature appears to be implemented. Reconsider this setting or throw the standard Exception.";
@Parameterized.Parameters(name = "{index}: supports{0}({1})")
public static Iterable
© 2015 - 2025 Weber Informatics LLC | Privacy Policy