Search in sources :

Example 56 with TestGraphDatabaseFactory

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

the class GraphDatabaseServiceExecuteTest method shouldNotReturnInternalCartesianPointType.

@Test
public void shouldNotReturnInternalCartesianPointType() throws Exception {
    // given
    GraphDatabaseService graphDb = new TestGraphDatabaseFactory().newImpermanentDatabase();
    // when
    Result execute = graphDb.execute("RETURN point({x: 13.37, y: 13.37, crs:'cartesian'}) AS p");
    // then
    Object obj = execute.next().get("p");
    assertThat(obj, Matchers.instanceOf(Point.class));
    Point point = (Point) obj;
    assertThat(point.getCoordinate(), equalTo(new Coordinate(13.37, 13.37)));
    CRS crs = point.getCRS();
    assertThat(crs.getCode(), equalTo(7203));
    assertThat(crs.getType(), equalTo("cartesian"));
    assertThat(crs.getHref(), equalTo("http://spatialreference.org/ref/sr-org/7203/"));
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Coordinate(org.neo4j.graphdb.spatial.Coordinate) CRS(org.neo4j.graphdb.spatial.CRS) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Point(org.neo4j.graphdb.spatial.Point) Result(org.neo4j.graphdb.Result) Test(org.junit.Test)

Example 57 with TestGraphDatabaseFactory

use of org.neo4j.test.TestGraphDatabaseFactory 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 58 with TestGraphDatabaseFactory

use of org.neo4j.test.TestGraphDatabaseFactory 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 59 with TestGraphDatabaseFactory

use of org.neo4j.test.TestGraphDatabaseFactory 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 60 with TestGraphDatabaseFactory

use of org.neo4j.test.TestGraphDatabaseFactory 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)

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