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;
}
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);
}
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));
}
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));
}
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));
}
Aggregations