Skip to content

Property Graph Model Test Suite

okram edited this page Sep 14, 2010 · 15 revisions

Gremlin comes with a suite of test cases to ensure that any implementation of the property graph model interfaces behaves as required in order to work seamlessly within Gremlin. This section will discuss the test suites and how to build a simple JUnit test class to validate an implementation of this model.

There currently exists the following test suites:

  1. VertexTestSuite: ensure that vertices and their properties are added and removed properly.
  2. EdgeTestSuite: ensure that edges and their properties are added and removed properly.
  3. IndexTestSuite: ensure that the index system works properly.
  4. GraphTestSuite: ensure that all previous components interact correctly together.
  5. GraphMLReaderTestSuite: ensure that GraphML files are read properly from disk and represented correctly.

Testing a Property Graph Model Implementation

To ensure that an implementation of the property graph model is implemented correctly and will work as expected in Gremlin, a simple JUnit test case of the following form will determine its compliance. Unfortunately, there is no perfect general interface solution that will work regardless of the underlying graph framework, while being specific enough to be useful. For this reason, the SuiteConfiguration object is used to specify peculiarities of the underlying framework so that the test suites will known what to expect from the underlying graph.

public class TinkerGraphTest extends TestCase {
    private static final SuiteConfiguration config = new SuiteConfiguration();
    static {
        config.allowsDuplicateEdges = true;
        config.allowsSelfLoops = true;
        config.requiresRDFIds = false;
        config.isRDFModel = false;
        config.supportsVertexIteration = true;
        config.supportsEdgeIteration = true;
        config.supportsVertexIndex = true;
        config.supportsEdgeIndex = false;
        config.ignoresSuppliedIds = false;
    }
    public void testVertexSuite() throws Exception {
        doSuiteTest(new VertexTestSuite(config));
    }
    public void testEdgeSuite() throws Exception {
        doSuiteTest(new EdgeTestSuite(config));
    }
    public void testGraphSuite() throws Exception {
        doSuiteTest(new GraphTestSuite(config));
    }
    public void testIndexSuite() throws Exception {
        doSuiteTest(new IndexTestSuite(config));
    } 
   public void testGraphMLReaderSuite() throws Exception {
        doSuiteTest(new GraphMLReaderTestSuite(config));
    }
   private static void doSuiteTest(ModelTestSuite suite) throws Exception {
        String doTest = System.getProperty("testTinkerGraph");
        if (doTest == null || doTest.equals("true")) {
            for (Method method : suite.getClass().getDeclaredMethods()) {
                if (method.getName().startsWith("test")) {
                    System.out.println("Testing " + method.getName() + "...");
                    method.invoke(suite, new TinkerGraph());
                }
            }
        }
    }
}

In the pom.xml for Gremlin, you will notice a collection of defined system properties. Use these to ensure that the test cases run properly on your particular system when running mvn install.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.4.2</version>
    <configuration>
        <systemProperties>
            <!-- TINKERGRAPH TEST PROPERTIES -->
            <property>
                <name>testTinkerGraph</name>
                <value>true</value>
            </property>
            <!-- NEO4J TEST PROPERTIES -->
            <property>
                <name>testNeo4j</name>
                <value>true</value>
            </property>
            <property>
                <name>neo4jDirectory</name>
                <value>/tmp/gremlin_test</value>
            </property>
            <!-- SAIL TEST PROPERTIES -->
            <property>
                <name>testSail</name>
                <value>true</value>
            </property>
        </systemProperties>
    </configuration>
</plugin>