Skip to content

Property Graph Model Test Suite

okram edited this page Mar 11, 2011 · 15 revisions

Blueprints 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 applications that depend on Blueprints. 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. AutomaticIndexTestSuite: ensures that automatic indices are managed property.
  2. EdgeTestSuite: ensure that edges and their properties are added and removed properly.
  3. GraphMLReaderTestSuite: ensure that GraphML files are read properly from disk and represented properly.
  4. GraphTestSuite: ensure that vertices and edges work together properly.
  5. IndexableGraphTestSuite: ensures that graphs that support indices behave properly.
  6. IndexTestSuite: ensure that the index system works properly.
  7. TransactionalGraphTestSuite: ensures that graphs that support transactions behave properly.
  8. VertexTestSuite: ensure that vertices and their properties are added and removed properly.

Blueprints-Tests Dependency

It is necessary that the Blueprints test suite is depended when testing a Blueprints-enabled graph framework. Simply import the blueprints-tests. With this dependency the test suite is available.

<dependency>
  <groupId>com.tinkerpop</groupId>
  <artifactId>blueprints-tests</artifactId>
  <version>0.5</version>
  <scope>test</scope>
</dependency>

Testing a Property Graph Model Implementation

To ensure that an implementation of the property graph model is implemented correctly, 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, a GraphTest has public boolean fields that need to be set that specify the peculiarities of the graph framework.

public class TinkerGraphTest extends GraphTest {

    public TinkerGraphTest() {
        this.allowsDuplicateEdges = true;
        this.allowsSelfLoops = true;
        this.ignoresSuppliedIds = false;
        this.isPersistent = false;
        this.isRDFModel = false;
        this.supportsVertexIteration = true;
        this.supportsEdgeIteration = true;
        this.supportsVertexIndex = true;
        this.supportsEdgeIndex = true;
        this.supportsTransactions = false;
    }

    public void testVertexTestSuite() throws Exception {
        this.stopWatch();
        doTestSuite(new VertexTestSuite(this));
        printTestPerformance("VertexTestSuite", this.stopWatch());
    }

    public void testEdgeTestSuite() throws Exception {
        this.stopWatch();
        doTestSuite(new EdgeTestSuite(this));
        printTestPerformance("EdgeTestSuite", this.stopWatch());
    }

    public void testGraphTestSuite() throws Exception {
        this.stopWatch();
        doTestSuite(new GraphTestSuite(this));
        printTestPerformance("GraphTestSuite", this.stopWatch());
    }

    public void testIndexableGraphTestSuite() throws Exception {
        this.stopWatch();
        doTestSuite(new IndexableGraphTestSuite(this));
        printTestPerformance("IndexableGraphTestSuite", this.stopWatch());
    }

    public void testIndexTestSuite() throws Exception {
        this.stopWatch();
        doTestSuite(new IndexTestSuite(this));
        printTestPerformance("IndexTestSuite", this.stopWatch());
    }

    public void testAutomaticIndexTestSuite() throws Exception {
        this.stopWatch();
        doTestSuite(new AutomaticIndexTestSuite(this));
        printTestPerformance("AutomaticIndexTestSuite", this.stopWatch());
    }

    public void testGraphMLReaderTestSuite() throws Exception {
        this.stopWatch();
        doTestSuite(new GraphMLReaderTestSuite(this));
        printTestPerformance("GraphMLReaderTestSuite", this.stopWatch());
    }

    public Graph getGraphInstance() {
        return new TinkerGraph();
    }

    public void doTestSuite(final TestSuite testSuite) throws Exception {
        String doTest = System.getProperty("testTinkerGraph");
        if (doTest == null || doTest.equals("true")) {
            for (Method method : testSuite.getClass().getDeclaredMethods()) {
                if (method.getName().startsWith("test")) {
                    System.out.println("Testing " + method.getName() + "...");
                    method.invoke(testSuite);
                }
            }
        }
    }
}

In the pom.xml of Blueprints, you will notice a collection of defined system properties. Use these to ensure that the test cases run correctly 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/blueprints_test</value>
                      </property>
                      <!-- SAIL TEST PROPERTIES -->
                      <property>
                          <name>testSail</name>
                          <value>true</value>
                      </property>
                      <!-- ORIENTGRAPH TEST PROPERTIES -->
                      <property>
                          <name>testOrientGraph</name>
                          <value>true</value>
                      </property>
                      <property>
                          <name>orientGraphDirectory</name>
                          <value>/tmp/blueprints_test</value>
                      </property>
                  </systemProperties>
              </configuration>
          </plugin>