Search in sources :

Example 96 with TestGraphDatabaseFactory

use of org.neo4j.test.TestGraphDatabaseFactory in project neo4j by neo4j.

the class GraphDatabaseServiceExecuteTest method shouldBeAbleToUseResultingPointFromOneQueryAsParameterToNext.

@Test
public void shouldBeAbleToUseResultingPointFromOneQueryAsParameterToNext() throws Exception {
    // given a point create by one cypher query
    GraphDatabaseService graphDb = new TestGraphDatabaseFactory().newImpermanentDatabase();
    Result execute = graphDb.execute("RETURN point({longitude: 144.317718, latitude: -37.031738}) AS p");
    Point point = (Point) execute.next().get("p");
    // 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", point));
    // 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) Point(org.neo4j.graphdb.spatial.Point) Result(org.neo4j.graphdb.Result) Test(org.junit.Test)

Example 97 with TestGraphDatabaseFactory

use of org.neo4j.test.TestGraphDatabaseFactory in project neo4j by neo4j.

the class GraphDatabaseServiceExecuteTest method shouldBeAbleToUseExternalPointArrayAsParameterToQuery.

@Test
public void shouldBeAbleToUseExternalPointArrayAsParameterToQuery() throws Exception {
    // given a point created from public interface
    GraphDatabaseService graphDb = new TestGraphDatabaseFactory().newImpermanentDatabase();
    Point point = makeFakePoint(144.317718, -37.031738, makeWGS84());
    Point[] points = new Point[] { point, point };
    // when passing as params to a distance function
    Result result = graphDb.execute("RETURN distance({points}[0],{points}[1]) AS dist", map("points", points));
    // 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) Point(org.neo4j.graphdb.spatial.Point) Result(org.neo4j.graphdb.Result) Test(org.junit.Test)

Example 98 with TestGraphDatabaseFactory

use of org.neo4j.test.TestGraphDatabaseFactory in project neo4j by neo4j.

the class GraphDatabaseServiceExecuteTest method shouldBeAbleToUseExternalPointAsParameterToQuery.

@Test
public void shouldBeAbleToUseExternalPointAsParameterToQuery() throws Exception {
    // given a point created from public interface
    GraphDatabaseService graphDb = new TestGraphDatabaseFactory().newImpermanentDatabase();
    Point point = makeFakePoint(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", point));
    // 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) Point(org.neo4j.graphdb.spatial.Point) Result(org.neo4j.graphdb.Result) Test(org.junit.Test)

Example 99 with TestGraphDatabaseFactory

use of org.neo4j.test.TestGraphDatabaseFactory in project neo4j by neo4j.

the class GraphDatabaseServiceExecuteTest method shouldBeAbleToUseResultsOfPointProcedureAsInputToDistanceFunction.

@Test
public void shouldBeAbleToUseResultsOfPointProcedureAsInputToDistanceFunction() 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.point(144.317718, -37.031738) YIELD point " + "RETURN distance(point({longitude: 144.317718, latitude: -37.031738}), point) 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)

Example 100 with TestGraphDatabaseFactory

use of org.neo4j.test.TestGraphDatabaseFactory in project neo4j by neo4j.

the class GraphDatabaseServiceExecuteTest method shouldNotReturnInternalPointWhenInArray.

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

Aggregations

TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)154 Test (org.junit.Test)83 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)77 Transaction (org.neo4j.graphdb.Transaction)56 File (java.io.File)40 Node (org.neo4j.graphdb.Node)32 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)25 Before (org.junit.Before)23 Result (org.neo4j.graphdb.Result)13 EphemeralFileSystemAbstraction (org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction)11 Relationship (org.neo4j.graphdb.Relationship)9 GraphDatabaseBuilder (org.neo4j.graphdb.factory.GraphDatabaseBuilder)9 UncloseableDelegatingFileSystemAbstraction (org.neo4j.graphdb.mockfs.UncloseableDelegatingFileSystemAbstraction)9 BeforeClass (org.junit.BeforeClass)8 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)8 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)8 HashMap (java.util.HashMap)7 Point (org.neo4j.graphdb.spatial.Point)7 DependencyResolver (org.neo4j.graphdb.DependencyResolver)6 PageCache (org.neo4j.io.pagecache.PageCache)6