Search in sources :

Example 1 with Client

use of org.apache.tinkerpop.gremlin.driver.Client in project cypher-for-gremlin by opencypher.

the class OpProcessorCypherGremlinClientTest method submitToNonExistentAlias.

@Test
public void submitToNonExistentAlias() {
    Client gremlinClient = gremlinServer.gremlinClient().alias("does_not_exist");
    OpProcessorCypherGremlinClient client = new OpProcessorCypherGremlinClient(gremlinClient);
    String cypher = "MATCH (p:person) RETURN p.name AS name";
    assertThatThrownBy(() -> client.submit(cypher).all()).hasMessageContaining("Traversable alias 'does_not_exist' not found");
}
Also used : Client(org.apache.tinkerpop.gremlin.driver.Client) Test(org.junit.Test)

Example 2 with Client

use of org.apache.tinkerpop.gremlin.driver.Client in project cypher-for-gremlin by opencypher.

the class OpProcessorCypherGremlinClientTest method invalidSyntax.

@Test
public void invalidSyntax() {
    Client gremlinClient = gremlinServer.gremlinClient();
    OpProcessorCypherGremlinClient client = new OpProcessorCypherGremlinClient(gremlinClient);
    CypherResultSet resultSet = client.submit("INVALID");
    Throwable throwable = catchThrowable(resultSet::all);
    assertThat(throwable).hasMessageContaining("Invalid input");
}
Also used : Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Client(org.apache.tinkerpop.gremlin.driver.Client) Test(org.junit.Test)

Example 3 with Client

use of org.apache.tinkerpop.gremlin.driver.Client in project cypher-for-gremlin by opencypher.

the class OpProcessorCypherGremlinClientTest method submitToAlias.

private void submitToAlias(String alias) {
    Client gremlinClient = gremlinServer.gremlinClient().alias(alias);
    OpProcessorCypherGremlinClient client = new OpProcessorCypherGremlinClient(gremlinClient);
    String cypher = "MATCH (p:person) RETURN p.name AS name";
    List<Map<String, Object>> results = client.submit(cypher).all();
    assertThat(results).extracting("name").containsExactlyInAnyOrder("marko", "vadas", "josh", "peter");
}
Also used : Client(org.apache.tinkerpop.gremlin.driver.Client) Map(java.util.Map)

Example 4 with Client

use of org.apache.tinkerpop.gremlin.driver.Client in project cypher-for-gremlin by opencypher.

the class CypherGremlinServerClient method gremlinStyle.

@Test
public void gremlinStyle() throws Exception {
    BaseConfiguration configuration = new BaseConfiguration();
    configuration.setProperty("port", gremlinServer.getPort());
    configuration.setProperty("hosts", Arrays.asList("localhost"));
    // freshReadmeSnippet: gremlinStyle
    Cluster cluster = Cluster.open(configuration);
    Client gremlinClient = cluster.connect();
    CypherGremlinClient cypherGremlinClient = CypherGremlinClient.plugin(gremlinClient);
    String cypher = "MATCH (p:person) WHERE p.age > 25 RETURN p.name";
    CypherResultSet resultSet = cypherGremlinClient.submit(cypher);
    List<Map<String, Object>> results = resultSet.all();
    // freshReadmeSnippet: gremlinStyle
    assertThat(results).extracting("p.name").containsExactly("marko", "vadas", "josh", "peter");
}
Also used : BaseConfiguration(org.apache.commons.configuration.BaseConfiguration) CypherResultSet(org.opencypher.gremlin.client.CypherResultSet) Cluster(org.apache.tinkerpop.gremlin.driver.Cluster) CypherGremlinClient(org.opencypher.gremlin.client.CypherGremlinClient) CypherGremlinClient(org.opencypher.gremlin.client.CypherGremlinClient) Client(org.apache.tinkerpop.gremlin.driver.Client) Map(java.util.Map) Test(org.junit.Test)

Example 5 with Client

use of org.apache.tinkerpop.gremlin.driver.Client in project cypher-for-gremlin by opencypher.

the class GremlinServerDriver method session.

@Override
public Session session() {
    Client gremlinClient = cluster.connect();
    CypherGremlinClient cypherGremlinClient = config.translationEnabled() ? CypherGremlinClient.translating(gremlinClient, config.flavor()) : CypherGremlinClient.plugin(gremlinClient);
    return new GremlinServerSession(serverInfo, cypherGremlinClient);
}
Also used : CypherGremlinClient(org.opencypher.gremlin.client.CypherGremlinClient) CypherGremlinClient(org.opencypher.gremlin.client.CypherGremlinClient) Client(org.apache.tinkerpop.gremlin.driver.Client)

Aggregations

Client (org.apache.tinkerpop.gremlin.driver.Client)14 Cluster (org.apache.tinkerpop.gremlin.driver.Cluster)7 Test (org.junit.Test)5 CypherGremlinClient (org.opencypher.gremlin.client.CypherGremlinClient)5 Test (org.junit.jupiter.api.Test)4 Map (java.util.Map)3 BaseConfiguration (org.apache.commons.configuration.BaseConfiguration)2 ExecutionException (java.util.concurrent.ExecutionException)1 GraphTraversalSource (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource)1 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)1 Before (org.junit.Before)1 CypherResultSet (org.opencypher.gremlin.client.CypherResultSet)1