Search in sources :

Example 1 with Neo4jRule

use of org.neo4j.harness.junit.Neo4jRule in project neo4j by neo4j.

the class JUnitRuleTest method shouldRuleWorkWithExsitingDirectory.

@Test
public void shouldRuleWorkWithExsitingDirectory() {
    // given
    GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder(testDirectory.directory()).newGraphDatabase();
    try {
        db.execute("CREATE ()");
    } finally {
        db.shutdown();
    }
    // When a rule with an pre-populated graph db directory is used
    final Neo4jRule ruleWithDirectory = new Neo4jRule(testDirectory.directory()).copyFrom(testDirectory.directory());
    ruleWithDirectory.apply(new Statement() {

        @Override
        public void evaluate() throws Throwable {
            // Then the database is not empty
            Result result = ruleWithDirectory.getGraphDatabaseService().execute("match (n) return count(n) as " + "count");
            List<Object> column = Iterators.asList(result.columnAs("count"));
            assertEquals(1, column.size());
            assertEquals(1, column.get(0));
        }
    }, null);
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Neo4jRule(org.neo4j.harness.junit.Neo4jRule) Statement(org.junit.runners.model.Statement) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) List(java.util.List) Result(org.neo4j.graphdb.Result) Test(org.junit.Test)

Aggregations

List (java.util.List)1 Test (org.junit.Test)1 Statement (org.junit.runners.model.Statement)1 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)1 Result (org.neo4j.graphdb.Result)1 Neo4jRule (org.neo4j.harness.junit.Neo4jRule)1 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)1