@Test public void calls_simplistic_procedure() { try ( Driver driver = GraphDatabase.driver( graphDb.boltURI(), configuration() ); Session session = driver.session() ) { StatementResult result = session.run( "CALL " + procedureNamespace + ".theAnswer()" ); assertThat( result.single().get( "value" ).asLong() ).isEqualTo( 42L ); } }
@Test public void shouldStart() { boolean actual = neo4jContainer.isRunning(); assertThat(actual).isTrue(); try (Driver driver = GraphDatabase .driver(neo4jContainer.getBoltUrl(), AuthTokens.basic("neo4j", "password")); Session session = driver.session() ) { long one = session.run("RETURN 1", Collections.emptyMap()).next().get(0).asLong(); assertThat(one).isEqualTo(1L); } catch (Exception e) { fail(e.getMessage()); } }
@Test public void shouldDisableAuthentication() { try ( Neo4jContainer neo4jContainer = new Neo4jContainer().withAdminPassword(null); ) { neo4jContainer.start(); try (Driver driver = getDriver(neo4jContainer); Session session = driver.session() ) { long one = session.run("RETURN 1", Collections.emptyMap()).next().get(0).asLong(); assertThat(one).isEqualTo(1L); } } }
@Test public void shouldRunEnterprise() { assumeThat(Neo4jContainerTest.class.getResource(ACCEPTANCE_FILE_LOCATION)).isNotNull(); try ( Neo4jContainer neo4jContainer = new Neo4jContainer() .withEnterpriseEdition() .withAdminPassword("Picard123") ) { neo4jContainer.start(); try ( Driver driver = getDriver(neo4jContainer); Session session = driver.session() ) { String edition = session .run("CALL dbms.components() YIELD edition RETURN edition", Collections.emptyMap()) .next().get(0).asString(); assertThat(edition).isEqualTo("enterprise"); } } }
@Override public T apply( Record record ) { return mapFunction.apply( record.get( index ) ); } };
@Override public T apply( Record recordAccessor ) { return mapFunction.apply( recordAccessor.get( key ) ); } };
@SuppressWarnings("unchecked") private <T> List<T> asList(Record embeddeds, String alias) { Value value = embeddeds.get( alias ); if ( value.isNull() ) { return Collections.emptyList(); } return (List<T>) value.asList(); }
private Relationship asRelationship(Record record, String alias) { Value value = record.get( alias ); if ( value.isNull() ) { return null; } return value.asRelationship(); }
@Override @Nonnull public Optional set(@Nonnull String name, @Nonnull String valueString) throws CommandException { final BoltResult result = setParamsAndValidate(name, valueString); String parameterName = CypherVariablesFormatter.unescapedCypherVariable(name); final Object value = result.getRecords().get(0).get(parameterName).asObject(); queryParams.put(parameterName, new ParamValue(valueString, value)); return Optional.ofNullable(value); }
private Relationship relationship(StatementResult result) { if ( result.hasNext() ) { return result.next().get( 0 ).asRelationship(); } return null; }
private int getTotalRelationships() { Session session = this.driver.session(); int count = session.run("MATCH ()-[r]-() RETURN count(r) AS count").peek().get("count").asInt(); session.close(); return count; // return this.session.run("MATCH ()-[r]-() RETURN count(r) AS count").peek().get("count").asInt(); }
private int getTotalXrefRelationships() { Session session = this.driver.session(); int count = session.run("MATCH (n:" + NodeTypes.PHYSICAL_ENTITY + ")-[r:" + RelTypes.XREF + "]->(m:" + NodeTypes.XREF + ") RETURN count(r) AS count").peek().get("count").asInt(); session.close(); return count; // return this.session.run("MATCH (n:" // + NodeTypes.PHYSICAL_ENTITY + ")-[r:" + RelTypes.XREF + "]->(m:" // + NodeTypes.XREF + ") RETURN count(r) AS count").peek().get("count").asInt(); }
private int getTotalCelLocationNodes() { Session session = this.driver.session(); int count = session.run("MATCH (n:" + NodeTypes.CELLULAR_LOCATION + ") RETURN count(n) AS count") .peek().get("count").asInt(); session.close(); return count; // return this.session.run("MATCH (n:" + NodeTypes.CELLULAR_LOCATION + ") RETURN count(n) AS count") // .peek().get("count").asInt(); }
private int getTotalNodes() { Session session = this.driver.session(); int count = session.run("MATCH (n) RETURN count(n) AS count").peek().get("count").asInt(); session.close(); return count; // return this.session.run("MATCH (n) RETURN count(n) AS count").peek().get("count").asInt(); }
private int getTotalOntologyRelationships() { Session session = this.driver.session(); int count = session.run("MATCH (n)-[r:" + RelTypes.ONTOLOGY + "|" + RelTypes.CELLOC_ONTOLOGY + "]->(m:" + NodeTypes.ONTOLOGY + ") RETURN count(r) AS count").peek().get("count").asInt(); session.close(); return count; // return this.session.run("MATCH (n)-[r:" + RelTypes.ONTOLOGY + "|" + RelTypes.CELLOC_ONTOLOGY // + "]->(m:" + NodeTypes.ONTOLOGY + ") RETURN count(r) AS count").peek().get("count").asInt(); }
@Test public void single() { List<Map<String, Object>> results = singletonList(getRow(1)); StatementResult statementResult = new GremlinServerStatementResult(serverInfo, statement, results.iterator(), converter); assertThat(statementResult.single().get(KEY1).asInt()).isEqualTo(1); }
public Node findAssociatedEntity(Transaction tx, Object[] keyValues, String associationrole) { Map<String, Object> params = params( keyValues ); String query = getFindAssociatedEntityQuery( associationrole ); if ( query != null ) { StatementResult statementResult = tx.run( query, params ); if ( statementResult.hasNext() ) { return statementResult.single().get( 0 ).asNode(); } } return null; }
@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); } }
@Test public void shouldCreateAnRNodeConnectedToTheEntity() throws Throwable { try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) { StatementResult result = session.run("CALL graph.versioner.init('Entity')"); StatementResult rPath = session.run("MATCH rPath = (:R)-[:FOR]->(:Entity) RETURN rPath"); Assertions.assertThat(result.single().get("node").asNode().id()).isEqualTo(0L); Assertions.assertThat(rPath) .hasSize(1) .allMatch(path -> path.get("rPath").asPath().length() == 1); } } }
@Test public void translating() { 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("MATCH (n:person) RETURN count(n) as count"); int count = result.single().get("count").asInt(); assertThat(count).isEqualTo(4); } }