/*
   * Extract variables from the static neo4j service instance for local usage and insert test data from child test class
   *
   * */
  @Before
  public void beforeEachTest() {

    api = NEO4J_SERVER.getServer().getDatabase().getGraph();
    Assert.assertNotNull(api);

    engine = new ExecutionEngine(api);
    Assert.assertNotNull(engine);

    insertTestData();
  }
  /*
   * Clean up index and delete the whole data directory
   *
   * */
  @After
  public void afterEachTest() throws IOException {

    ExecutionResult result = executeQuery("start n=node:__types__(type='user') return n");
    final Set<Node> nodes = nodeSetFromResult(result, "n");

    doInTransaction(
        new TransactionCallback() {

          public void execute(GraphDatabaseAPI api) {
            for (Node node : nodes) api.index().forNodes("__types__").remove(node, "type");
          }
        });

    FileUtils.deleteRecursively(new File(NEO4J_SERVER.getServer().getDatabase().getLocation()));
  }
 /*
  * Start the Neo4j before the test begins
  *
  * */
 @BeforeClass
 public static void setup() {
   GraphDatabaseAPI gda = GET_GRAPH_DATABASE_API();
   NEO4J_SERVER = new WrappingNeoServerBootstrapper(gda);
   NEO4J_SERVER.start();
 }
 /*
  * Stop server after test
  *
  * */
 @AfterClass
 public static void tearDown() {
   NEO4J_SERVER.stop();
 }