Search in sources :

Example 81 with Session

use of com.google.spanner.v1.Session in project cypher-for-gremlin by opencypher.

the class GremlinNeo4jDriverTest method returnNodeAndRelationship.

@Test
public void returnNodeAndRelationship() {
    Driver driver = GremlinDatabase.driver("//localhost:" + server.getPort());
    try (Session session = driver.session()) {
        StatementResult result = session.run("CREATE (n1:Person {name: 'Marko'})-[r:knows {since:1999}]->(n2:Person)" + "RETURN n1,r,n2", parameters("message", "Hello"));
        Record record = result.single();
        Node n1 = record.get("n1").asNode();
        Relationship r = record.get("r").asRelationship();
        Node n2 = record.get("n2").asNode();
        assertThat(n1.hasLabel("Person")).isTrue();
        assertThat(n1.get("name").asString()).isEqualTo("Marko");
        assertThat(r.hasType("knows")).isTrue();
        assertThat(r.startNodeId()).isEqualTo(n1.id());
        assertThat(r.endNodeId()).isEqualTo(n2.id());
        assertThat(r.get("since").asLong()).isEqualTo(1999L);
        assertThat(n2.hasLabel("Person")).isTrue();
    }
}
Also used : StatementResult(org.neo4j.driver.v1.StatementResult) Node(org.neo4j.driver.v1.types.Node) Relationship(org.neo4j.driver.v1.types.Relationship) Driver(org.neo4j.driver.v1.Driver) Record(org.neo4j.driver.v1.Record) Session(org.neo4j.driver.v1.Session) Test(org.junit.Test)

Example 82 with Session

use of com.google.spanner.v1.Session in project cypher-for-gremlin by opencypher.

the class GremlinNeo4jDriverTest method withMultipleParameters.

@Test
public void withMultipleParameters() {
    Driver driver = GremlinDatabase.driver("//localhost:" + server.getPort());
    Map<String, Object> properties = new HashMap<>();
    properties.put("p1", 1L);
    properties.put("p2", 2L);
    try (Session session = driver.session()) {
        StatementResult result = session.run("CREATE (a:Greeting) " + "SET a.p1 = $p1, " + "a.p2 = $p2 " + "RETURN a.p1, a.p2", properties);
        Record record = result.single();
        assertThat(record.get("a.p1").asLong()).isEqualTo(1L);
        assertThat(record.get("a.p2").asLong()).isEqualTo(2L);
    }
}
Also used : StatementResult(org.neo4j.driver.v1.StatementResult) HashMap(java.util.HashMap) Driver(org.neo4j.driver.v1.Driver) Record(org.neo4j.driver.v1.Record) Session(org.neo4j.driver.v1.Session) Test(org.junit.Test)

Example 83 with Session

use of com.google.spanner.v1.Session in project cypher-for-gremlin by opencypher.

the class GremlinNeo4jDriverTest method invalidSyntax.

@Test
public void invalidSyntax() {
    Driver driver = GremlinDatabase.driver("//localhost:" + server.getPort());
    try (Session session = driver.session()) {
        StatementResult result = session.run("INVALID");
        Throwable throwable = catchThrowable(result::list);
        assertThat(throwable).hasMessageContaining("Invalid input");
    }
}
Also used : StatementResult(org.neo4j.driver.v1.StatementResult) Driver(org.neo4j.driver.v1.Driver) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Session(org.neo4j.driver.v1.Session) Test(org.junit.Test)

Example 84 with Session

use of com.google.spanner.v1.Session in project cypher-for-gremlin by opencypher.

the class GremlinNeo4jDriverTest method invalidSyntaxInTranslation.

@Test
public void invalidSyntaxInTranslation() {
    Config config = Config.build().withTranslation(TranslatorFlavor.gremlinServer()).toConfig();
    Driver driver = GremlinDatabase.driver("//localhost:" + server.getPort(), config);
    try (Session session = driver.session()) {
        StatementResult result = session.run("INVALID");
        Throwable throwable = catchThrowable(result::list);
        assertThat(throwable).hasMessageContaining("Invalid input");
    }
}
Also used : StatementResult(org.neo4j.driver.v1.StatementResult) Config(org.opencypher.Config) Driver(org.neo4j.driver.v1.Driver) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Session(org.neo4j.driver.v1.Session) Test(org.junit.Test)

Example 85 with Session

use of com.google.spanner.v1.Session in project cypher-for-gremlin by opencypher.

the class GremlinNeo4jDriverTest method simple.

@Test
public void simple() {
    Driver adam = GremlinDatabase.driver("//localhost:" + server.getPort());
    try (Session session = adam.session()) {
        StatementResult result = session.run("MATCH (n:person) RETURN count(n) as count");
        int count = result.single().get("count").asInt();
        assertThat(count).isEqualTo(4);
    }
}
Also used : StatementResult(org.neo4j.driver.v1.StatementResult) Driver(org.neo4j.driver.v1.Driver) Session(org.neo4j.driver.v1.Session) Test(org.junit.Test)

Aggregations

Session (com.trilead.ssh2.Session)43 Session (org.neo4j.driver.v1.Session)38 Connection (com.trilead.ssh2.Connection)32 IOException (java.io.IOException)30 Test (org.junit.Test)29 InputStream (java.io.InputStream)28 Driver (org.neo4j.driver.v1.Driver)27 StatementResult (org.neo4j.driver.v1.StatementResult)20 Record (org.neo4j.driver.v1.Record)12 Session (iaik.pkcs.pkcs11.Session)10 TokenException (iaik.pkcs.pkcs11.TokenException)10 P11TokenException (org.xipki.security.exception.P11TokenException)10 CoreClusterMember (org.neo4j.causalclustering.discovery.CoreClusterMember)9 RoutingNetworkSession (org.neo4j.driver.internal.RoutingNetworkSession)9 Session (ch.ethz.ssh2.Session)8 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)8 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)8 HttpException (org.apache.commons.httpclient.HttpException)8 Transaction (org.neo4j.driver.v1.Transaction)7 SCPClient (com.trilead.ssh2.SCPClient)6