Search in sources :

Example 11 with GraphDatabaseService

use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.

the class DatabaseImporterTest method provideStoreDirectory.

private File provideStoreDirectory() {
    File storeDir = testDir.graphDbDir();
    GraphDatabaseService db = null;
    try {
        db = new TestGraphDatabaseFactory().newEmbeddedDatabase(storeDir);
        try (Transaction transaction = db.beginTx()) {
            db.createNode();
            transaction.success();
        }
    } finally {
        if (db != null) {
            db.shutdown();
        }
    }
    return storeDir;
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) File(java.io.File)

Example 12 with GraphDatabaseService

use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.

the class GraphDatabaseServiceExecuteTest method shouldExecuteCypher.

@Test
public void shouldExecuteCypher() throws Exception {
    // given
    GraphDatabaseService graphDb = new TestGraphDatabaseFactory().newImpermanentDatabase();
    final long before, after;
    try (Transaction tx = graphDb.beginTx()) {
        before = Iterables.count(graphDb.getAllNodes());
        tx.success();
    }
    // when
    graphDb.execute("CREATE (n:Foo{bar:\"baz\"})");
    // then
    try (Transaction tx = graphDb.beginTx()) {
        after = Iterables.count(graphDb.getAllNodes());
        tx.success();
    }
    assertEquals(before + 1, after);
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Test(org.junit.Test)

Example 13 with GraphDatabaseService

use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.

the class GraphDatabaseServiceExecuteTest method shouldBeAbleToUseExternalGeometryAsParameterToQuery.

@Test
public void shouldBeAbleToUseExternalGeometryAsParameterToQuery() throws Exception {
    // given a point created from public interface
    GraphDatabaseService graphDb = new TestGraphDatabaseFactory().newImpermanentDatabase();
    Geometry geometry = makeFakePointAsGeometry(144.317718, -37.031738, makeWGS84());
    // when passing as params to a distance function
    Result result = graphDb.execute("RETURN distance(point({longitude: 144.317718, latitude: -37.031738}),{previous}) AS dist", map("previous", geometry));
    // then
    Double dist = (Double) result.next().get("dist");
    assertThat(dist, equalTo(0.0));
}
Also used : Geometry(org.neo4j.graphdb.spatial.Geometry) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Result(org.neo4j.graphdb.Result) Test(org.junit.Test)

Example 14 with GraphDatabaseService

use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.

the class GraphDatabaseServiceExecuteTest method shouldNotReturnInternalPointWhenInMap.

@SuppressWarnings("unchecked")
@Test
public void shouldNotReturnInternalPointWhenInMap() throws Exception {
    // given
    GraphDatabaseService graphDb = new TestGraphDatabaseFactory().newImpermanentDatabase();
    // when
    Result execute = graphDb.execute("RETURN {p: point({longitude: 144.317718, latitude: -37.031738})} AS m");
    // then
    Map<String, Object> points = (Map<String, Object>) execute.next().get("m");
    assertThat(points.get("p"), Matchers.instanceOf(Point.class));
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Point(org.neo4j.graphdb.spatial.Point) Map(java.util.Map) Result(org.neo4j.graphdb.Result) Test(org.junit.Test)

Example 15 with GraphDatabaseService

use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.

the class GraphDatabaseServiceExecuteTest method shouldBeAbleToUseResultsOfPointGeometryProcedureAsInputToDistanceFunction.

@Test
public void shouldBeAbleToUseResultsOfPointGeometryProcedureAsInputToDistanceFunction() throws Exception {
    // given procedure that produces a point
    GraphDatabaseService graphDb = new TestGraphDatabaseFactory().newImpermanentDatabase();
    Procedures procedures = ((GraphDatabaseAPI) graphDb).getDependencyResolver().resolveDependency(Procedures.class);
    procedures.registerProcedure(PointProcs.class);
    // when calling procedure that produces a point
    Result result = graphDb.execute("CALL spatial.pointGeometry(144.317718, -37.031738) YIELD geometry " + "RETURN distance(point({longitude: 144.317718, latitude: -37.031738}), geometry) AS dist");
    // then
    Double dist = (Double) result.next().get("dist");
    assertThat(dist, equalTo(0.0));
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Procedures(org.neo4j.kernel.impl.proc.Procedures) Result(org.neo4j.graphdb.Result) Test(org.junit.Test)

Aggregations

GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)322 Test (org.junit.Test)225 Transaction (org.neo4j.graphdb.Transaction)182 Node (org.neo4j.graphdb.Node)142 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)77 File (java.io.File)70 Relationship (org.neo4j.graphdb.Relationship)49 EmbeddedGraphDatabase (org.neo4j.kernel.EmbeddedGraphDatabase)32 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)17 Result (org.neo4j.graphdb.Result)14 Label (org.neo4j.graphdb.Label)13 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)12 HashMap (java.util.HashMap)11 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)11 ArrayList (java.util.ArrayList)10 Map (java.util.Map)10 PageCache (org.neo4j.io.pagecache.PageCache)10 DbRepresentation (org.neo4j.test.DbRepresentation)10 GraphDatabaseFactory (org.neo4j.graphdb.factory.GraphDatabaseFactory)9 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)8