@Test public void calls_procedures_with_simple_input_type_returning_void() { try ( Driver driver = GraphDatabase.driver( graphDb.boltURI(), configuration() ); Session session = driver.session() ) { session.run( "CALL " + procedureNamespace + ".simpleInput00()" ); session.run( "CALL " + procedureNamespace + ".simpleInput01('string')" ); session.run( "CALL " + procedureNamespace + ".simpleInput02(42)" ); session.run( "CALL " + procedureNamespace + ".simpleInput03(42)" ); session.run( "CALL " + procedureNamespace + ".simpleInput04(4.2)" ); session.run( "CALL " + procedureNamespace + ".simpleInput05(true)" ); session.run( "CALL " + procedureNamespace + ".simpleInput06(false)" ); session.run( "CALL " + procedureNamespace + ".simpleInput07({foo:'bar'})" ); session.run( "MATCH (n) CALL " + procedureNamespace + ".simpleInput08(n) RETURN n" ); session.run( "MATCH p=(()-[r]->()) CALL " + procedureNamespace + ".simpleInput09(p) RETURN p" ); session.run( "MATCH ()-[r]->() CALL " + procedureNamespace + ".simpleInput10(r) RETURN r" ); } }
@Test public void calls_procedures_with_different_modes_returning_void() { try ( Driver driver = GraphDatabase.driver( graphDb.boltURI(), configuration() ); Session session = driver.session() ) { session.run( "CALL " + procedureNamespace + ".performsWrites()" ); session.run( "CALL " + procedureNamespace + ".defaultMode()" ); session.run( "CALL " + procedureNamespace + ".readMode()" ); session.run( "CALL " + procedureNamespace + ".writeMode()" ); session.run( "CALL " + procedureNamespace + ".schemaMode()" ); session.run( "CALL " + procedureNamespace + ".dbmsMode()" ); } }
@Test public void calls_procedures_with_simple_input_type_returning_record_with_primitive_fields() { try ( Driver driver = GraphDatabase.driver( graphDb.boltURI(), configuration() ); Session session = driver.session() ) { assertThat( session.run( "CALL " + procedureNamespace + ".simpleInput11('string') YIELD field04 AS p RETURN p" ).single() ).isNotNull(); assertThat( session.run( "CALL " + procedureNamespace + ".simpleInput12(42)" ).single() ).isNotNull(); assertThat( session.run( "CALL " + procedureNamespace + ".simpleInput13(42)" ).single() ).isNotNull(); assertThat( session.run( "CALL " + procedureNamespace + ".simpleInput14(4.2)" ).single() ).isNotNull(); assertThat( session.run( "CALL " + procedureNamespace + ".simpleInput15(true)" ).single() ).isNotNull(); assertThat( session.run( "CALL " + procedureNamespace + ".simpleInput16(false)" ).single() ).isNotNull(); assertThat( session.run( "CALL " + procedureNamespace + ".simpleInput17({foo:'bar'})" ).single() ) .isNotNull(); assertThat( session.run( "CALL " + procedureNamespace + ".simpleInput21()" ).single() ).isNotNull(); } }
@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 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 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"); } } }
private Driver stubVersionInAnOpenSession(StatementResult versionMock, Session sessionMock, String value) { Driver driverMock = mock(Driver.class); ResultSummary resultSummary = mock(ResultSummary.class); ServerInfo serverInfo = mock(ServerInfo.class); when(resultSummary.server()).thenReturn(serverInfo); when(serverInfo.version()).thenReturn(value); when(versionMock.summary()).thenReturn(resultSummary); when(sessionMock.isOpen()).thenReturn(true); when(sessionMock.run("RETURN 1")).thenReturn(versionMock); when(driverMock.session(any(), anyString())).thenReturn(sessionMock); return driverMock; }
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 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 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"); } }
@Test public void withParameter() { Driver driver = GremlinDatabase.driver("//localhost:" + server.getPort()); try (Session session = driver.session()) { StatementResult result = session.run("CREATE (a:Greeting) " + "SET a.message = $message " + "RETURN a.message", parameters("message", "Hello")); String message = result.single().get(0).asString(); assertThat(message).isEqualTo("Hello"); } }
@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); } }
@Test public void shouldDiffGetNoDiffIfOneOfTheTwoStatesIsNull() { // This is in a try-block, to make sure we close the driver after the test try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) { // Given // An empty database // When StatementResult result = session .run("MATCH (stateTo:Entity), (stateFrom:State:From) WITH stateFrom, stateTo CALL graph.versioner.diff(stateFrom, stateTo) YIELD operation, label, oldValue, newValue RETURN operation, label, oldValue, newValue"); // Then assertThat(result.hasNext(), is(false)); } }
@Test public void shouldDiffFromCurrentGetNoDiffIfInputStateDoesNotExist() { // This is in a try-block, to make sure we close the driver after the test try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), Config.build().withEncryption().toConfig()); Session session = driver.session()) { // Given // A db with no states // When StatementResult result = session .run("MATCH (stateTo:Entity) WITH stateTo CALL graph.versioner.diff.from.current(stateTo) YIELD operation, label, oldValue, newValue RETURN operation, label, oldValue, newValue"); // Then assertThat(result.hasNext(), is(false)); } }