diff --git a/README.md b/README.md index 2ae76d57..a7422b0a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # neosemantics (n10s) ![n10s Logo](https://guides.neo4j.com/rdf/n10s.png) neosemantics is a plugin that enables the **use of RDF in Neo4j**. [RDF is a W3C standard model](https://www.w3.org/RDF/) for data interchange. Some key features of n10s are: + * **Store RDF data in Neo4j** in a lossless manner (imported RDF can subsequently be exported without losing a single triple in the process). * On-demand **export property graph data** from Neo4j *as RDF*. diff --git a/src/test/java/n10s/ModelTestUtils.java b/src/test/java/n10s/ModelTestUtils.java index bf074d4b..fc037873 100644 --- a/src/test/java/n10s/ModelTestUtils.java +++ b/src/test/java/n10s/ModelTestUtils.java @@ -18,7 +18,6 @@ public static boolean compareModels(String expected, RDFFormat formatExpected, S Model expectedModel = createModel(expected, formatExpected); Model actualModel = createModel(actual, formatActual); - return Models.isomorphic(expectedModel, actualModel); } diff --git a/src/test/java/n10s/RDFExportTest.java b/src/test/java/n10s/RDFExportTest.java index c1e5350b..f9dd7f40 100644 --- a/src/test/java/n10s/RDFExportTest.java +++ b/src/test/java/n10s/RDFExportTest.java @@ -1,30 +1,33 @@ package n10s; +import n10s.aux.AuxProcedures; import n10s.graphconfig.GraphConfigProcedures; import n10s.mapping.MappingUtils; import n10s.nsprefixes.NsPrefixDefProcedures; +import n10s.rdf.RDFProcedures; import n10s.rdf.export.RDFExportProcedures; import n10s.rdf.load.RDFLoadProcedures; +import n10s.validation.ValidationProcedures; import org.eclipse.rdf4j.model.*; import org.eclipse.rdf4j.model.impl.SimpleValueFactory; import org.eclipse.rdf4j.model.vocabulary.FOAF; import org.eclipse.rdf4j.model.vocabulary.RDF; import org.eclipse.rdf4j.model.vocabulary.XSD; import org.eclipse.rdf4j.rio.RDFFormat; -import org.junit.Rule; -import org.junit.Test; +import org.junit.*; import org.neo4j.driver.*; import org.neo4j.driver.Record; +import org.neo4j.driver.internal.value.NodeValue; +import org.neo4j.driver.types.Node; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.harness.junit.rule.Neo4jRule; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; import static n10s.CommonProcedures.UNIQUENESS_CONSTRAINT_ON_URI; import static n10s.CommonProcedures.UNIQUENESS_CONSTRAINT_STATEMENT; @@ -32,24 +35,41 @@ import static org.junit.Assert.*; public class RDFExportTest { + public static Driver driver; + + @ClassRule + public static Neo4jRule neo4j = new Neo4jRule() + .withProcedure(RDFExportProcedures.class) + .withProcedure(MappingUtils.class) + .withProcedure(RDFLoadProcedures.class) + .withProcedure(GraphConfigProcedures.class) + .withProcedure(NsPrefixDefProcedures.class); + + @BeforeClass + public static void init() { + driver = GraphDatabase.driver(neo4j.boltURI(), + Config.builder().withoutEncryption().build()); + } + + @Before + public void cleanDatabase() { + driver.session().run("match (n) detach delete n").consume(); + driver.session().run("drop constraint n10s_unique_uri if exists").consume(); + } - @Rule - public Neo4jRule neo4j = new Neo4jRule() - .withProcedure(RDFExportProcedures.class) - .withProcedure(MappingUtils.class) - .withProcedure(RDFLoadProcedures.class) - .withProcedure(GraphConfigProcedures.class) - .withProcedure(NsPrefixDefProcedures.class); @Test public void testExportFromCypherOnLPG() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { + + Record record = session + .run("CREATE (n0:Node { a: 1, b: 'hello' })-[:CONNECTED_TO]->(n1:Node { a:2, b2:'bye@en'}) return n0, n1") + .next(); - session - .run( - "CREATE (n:Node { a: 1, b: 'hello' })-[:CONNECTED_TO]->(:Node { a:2, b2:'bye@en'})"); + Map idMap = new HashMap<>(); + idMap.put( "0", String.valueOf( ((NodeValue) record.get("n0")).asNode().id() )); + idMap.put( "1", String.valueOf( ((NodeValue) record.get("n1")).asNode().id() )); Result res = session @@ -58,13 +78,13 @@ public void testExportFromCypherOnLPG() throws Exception { final ValueFactory vf = SimpleValueFactory.getInstance(); Set expectedStatememts = new HashSet<>(Arrays.asList( - vf.createStatement(vf.createIRI(BASE_INDIV_NS + "0"), RDF.TYPE, vf.createIRI(DEFAULT_BASE_SCH_NS + "Node")), - vf.createStatement(vf.createIRI(BASE_INDIV_NS + "0"), vf.createIRI(DEFAULT_BASE_SCH_NS + "a"), vf.createLiteral(1L)), - vf.createStatement(vf.createIRI(BASE_INDIV_NS + "0"), vf.createIRI(DEFAULT_BASE_SCH_NS + "b"), vf.createLiteral("hello")), - vf.createStatement(vf.createIRI(BASE_INDIV_NS + "0"), vf.createIRI(DEFAULT_BASE_SCH_NS + "CONNECTED_TO"), vf.createIRI(BASE_INDIV_NS + "1")), - vf.createStatement(vf.createIRI(BASE_INDIV_NS + "1"), RDF.TYPE, vf.createIRI(DEFAULT_BASE_SCH_NS + "Node")), - vf.createStatement(vf.createIRI(BASE_INDIV_NS + "1"), vf.createIRI(DEFAULT_BASE_SCH_NS + "b2"), vf.createLiteral("bye","en")), - vf.createStatement(vf.createIRI(BASE_INDIV_NS + "1"), vf.createIRI(DEFAULT_BASE_SCH_NS + "a"), vf.createLiteral(2L)))); + vf.createStatement(vf.createIRI(BASE_INDIV_NS + idMap.get("0")), RDF.TYPE, vf.createIRI(DEFAULT_BASE_SCH_NS + "Node")), + vf.createStatement(vf.createIRI(BASE_INDIV_NS + idMap.get("0")), vf.createIRI(DEFAULT_BASE_SCH_NS + "a"), vf.createLiteral(1L)), + vf.createStatement(vf.createIRI(BASE_INDIV_NS + idMap.get("0")), vf.createIRI(DEFAULT_BASE_SCH_NS + "b"), vf.createLiteral("hello")), + vf.createStatement(vf.createIRI(BASE_INDIV_NS + idMap.get("0")), vf.createIRI(DEFAULT_BASE_SCH_NS + "CONNECTED_TO"), vf.createIRI(BASE_INDIV_NS + idMap.get("1"))), + vf.createStatement(vf.createIRI(BASE_INDIV_NS + idMap.get("1")), RDF.TYPE, vf.createIRI(DEFAULT_BASE_SCH_NS + "Node")), + vf.createStatement(vf.createIRI(BASE_INDIV_NS + idMap.get("1")), vf.createIRI(DEFAULT_BASE_SCH_NS + "b2"), vf.createLiteral("bye","en")), + vf.createStatement(vf.createIRI(BASE_INDIV_NS + idMap.get("1")), vf.createIRI(DEFAULT_BASE_SCH_NS + "a"), vf.createLiteral(2L)))); int resultCount = 0; while (res.hasNext()) { @@ -80,13 +100,16 @@ public void testExportFromCypherOnLPG() throws Exception { @Test public void testExportFromCypherOnLPGPropsOnRels() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { - session - .run( - "CREATE (n:Node { a: 1, b: 'hello' })-[:CONNECTED_TO" + - " { since: 12345 , kind: 'principal' }]->(:Node { a:2, b2:'bye@en'})"); + Record record = session + .run("CREATE (n0:Node { a: 1, b: 'hello' })-[:CONNECTED_TO" + + " { since: 12345 , kind: 'principal' }]->(n1:Node { a:2, b2:'bye@en'}) return n0, n1") + .next(); + + Map idMap = new HashMap<>(); + idMap.put( "0", String.valueOf( ((NodeValue) record.get("n0")).asNode().id() )); + idMap.put( "1", String.valueOf( ((NodeValue) record.get("n1")).asNode().id() )); Result res = session @@ -95,16 +118,16 @@ public void testExportFromCypherOnLPGPropsOnRels() throws Exception { final ValueFactory vf = SimpleValueFactory.getInstance(); Set expectedStatememts = new HashSet<>(Arrays.asList( - vf.createStatement(vf.createIRI(BASE_INDIV_NS + "0"), RDF.TYPE, vf.createIRI(DEFAULT_BASE_SCH_NS + "Node")), - vf.createStatement(vf.createIRI(BASE_INDIV_NS + "0"), vf.createIRI(DEFAULT_BASE_SCH_NS + "a"), vf.createLiteral(1L)), - vf.createStatement(vf.createIRI(BASE_INDIV_NS + "0"), vf.createIRI(DEFAULT_BASE_SCH_NS + "b"), vf.createLiteral("hello")), - vf.createStatement(vf.createIRI(BASE_INDIV_NS + "0"), vf.createIRI(DEFAULT_BASE_SCH_NS + "CONNECTED_TO"), vf.createIRI(BASE_INDIV_NS + "1")), - vf.createStatement(vf.createIRI(BASE_INDIV_NS + "1"), RDF.TYPE, vf.createIRI(DEFAULT_BASE_SCH_NS + "Node")), - vf.createStatement(vf.createIRI(BASE_INDIV_NS + "1"), vf.createIRI(DEFAULT_BASE_SCH_NS + "b2"), vf.createLiteral("bye","en")), - vf.createStatement(vf.createIRI(BASE_INDIV_NS + "1"), vf.createIRI(DEFAULT_BASE_SCH_NS + "a"), vf.createLiteral(2L)), - vf.createStatement(vf.createTriple(vf.createIRI(BASE_INDIV_NS + "0"), vf.createIRI(DEFAULT_BASE_SCH_NS + "CONNECTED_TO"), vf.createIRI(BASE_INDIV_NS + "1")), + vf.createStatement(vf.createIRI(BASE_INDIV_NS + idMap.get("0")), RDF.TYPE, vf.createIRI(DEFAULT_BASE_SCH_NS + "Node")), + vf.createStatement(vf.createIRI(BASE_INDIV_NS + idMap.get("0")), vf.createIRI(DEFAULT_BASE_SCH_NS + "a"), vf.createLiteral(1L)), + vf.createStatement(vf.createIRI(BASE_INDIV_NS + idMap.get("0")), vf.createIRI(DEFAULT_BASE_SCH_NS + "b"), vf.createLiteral("hello")), + vf.createStatement(vf.createIRI(BASE_INDIV_NS + idMap.get("0")), vf.createIRI(DEFAULT_BASE_SCH_NS + "CONNECTED_TO"), vf.createIRI(BASE_INDIV_NS + idMap.get("1"))), + vf.createStatement(vf.createIRI(BASE_INDIV_NS + idMap.get("1")), RDF.TYPE, vf.createIRI(DEFAULT_BASE_SCH_NS + "Node")), + vf.createStatement(vf.createIRI(BASE_INDIV_NS + idMap.get("1")), vf.createIRI(DEFAULT_BASE_SCH_NS + "b2"), vf.createLiteral("bye","en")), + vf.createStatement(vf.createIRI(BASE_INDIV_NS + idMap.get("1")), vf.createIRI(DEFAULT_BASE_SCH_NS + "a"), vf.createLiteral(2L)), + vf.createStatement(vf.createTriple(vf.createIRI(BASE_INDIV_NS + idMap.get("0")), vf.createIRI(DEFAULT_BASE_SCH_NS + "CONNECTED_TO"), vf.createIRI(BASE_INDIV_NS + idMap.get("1"))), vf.createIRI(DEFAULT_BASE_SCH_NS + "since"), vf.createLiteral(12345L)), - vf.createStatement(vf.createTriple(vf.createIRI(BASE_INDIV_NS + "0"), vf.createIRI(DEFAULT_BASE_SCH_NS + "CONNECTED_TO"), vf.createIRI(BASE_INDIV_NS + "1")), + vf.createStatement(vf.createTriple(vf.createIRI(BASE_INDIV_NS + idMap.get("0")), vf.createIRI(DEFAULT_BASE_SCH_NS + "CONNECTED_TO"), vf.createIRI(BASE_INDIV_NS + idMap.get("1"))), vf.createIRI(DEFAULT_BASE_SCH_NS + "kind"), vf.createLiteral("principal")))); int resultCount = 0; @@ -119,11 +142,7 @@ public void testExportFromCypherOnLPGPropsOnRels() throws Exception { @Test public void testCypherOnRDFGraphPropsOnRels() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - - Session session = driver.session(); - + try (Session session = driver.session();) { initialiseGraphDB(neo4j.defaultDatabaseService(), " { handleVocabUris: 'SHORTEN_STRICT' } "); @@ -133,11 +152,7 @@ public void testCypherOnRDFGraphPropsOnRels() throws Exception { } - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - - Session session = driver.session(); - + try (Session session = driver.session();) { Result importResults1 = session.run("CALL n10s.rdf.import.fetch('" + RDFExportTest.class.getClassLoader().getResource("rdfstar/beatles.ttls") .toURI() + "','Turtle-star')"); @@ -145,11 +160,7 @@ public void testCypherOnRDFGraphPropsOnRels() throws Exception { } - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - - Session session = driver.session(); - + try (Session session = driver.session();) { Result res = session .run(" CALL n10s.rdf.export.cypher(' MATCH path = (n)-[r]->(m) RETURN path ') "); @@ -177,37 +188,23 @@ public void testCypherOnRDFGraphPropsOnRels() throws Exception { @Test public void testSPOExportOnRDFGraphPropsOnRels() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - - Session session = driver.session(); - + try (Session session = driver.session();) { initialiseGraphDB(neo4j.defaultDatabaseService(), " { handleVocabUris: 'SHORTEN_STRICT' } "); session.run("call n10s.nsprefixes.add('msc','http://neo4j.com/voc/music#')"); assertEquals(1L, session.run("call n10s.nsprefixes.list() yield prefix return count(*) as ct").next().get("ct").asLong()); - } - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - - Session session = driver.session(); - + try (Session session = driver.session();) { Result importResults1 = session.run("CALL n10s.rdf.import.fetch('" + RDFExportTest.class.getClassLoader().getResource("rdfstar/beatles.ttls") .toURI() + "','Turtle-star')"); assertEquals(14L, importResults1.single().get("triplesLoaded").asLong()); - } - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - - Session session = driver.session(); - + try (Session session = driver.session();) { Result res = session.run(" CALL n10s.rdf.export.spo(null,null,null)"); @@ -229,17 +226,19 @@ public void testSPOExportOnRDFGraphPropsOnRels() throws Exception { } assertEquals(resultCount, expected.size()); } - } @Test public void testExportFromCypherOnLPGWithMappings() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { + + Record record = session + .run("CREATE (n0:Node { a: 1, b: 'hello' })-[:CONNECTED_TO]->(n1:Node { a:2, b2:'bye@en'}) return n0, n1") + .next(); - session - .run( - "CREATE (n:Node { a: 1, b: 'hello' })-[:CONNECTED_TO]->(:Node { a:2, b2:'bye@en'})"); + Map idMap = new HashMap<>(); + idMap.put( "0", String.valueOf( ((NodeValue) record.get("n0")).asNode().id() )); + idMap.put( "1", String.valueOf( ((NodeValue) record.get("n1")).asNode().id() )); session.run("call n10s.nsprefixes.add('foaf','http://xmlns.com/foaf/0.1/')"); session.run("call n10s.nsprefixes.add('myv','http://myvoc.org/testing#')"); @@ -260,13 +259,13 @@ public void testExportFromCypherOnLPGWithMappings() throws Exception { final ValueFactory vf = SimpleValueFactory.getInstance(); Set expectedStatememts = new HashSet<>(Arrays.asList( - vf.createStatement(vf.createIRI(BASE_INDIV_NS + "0"), RDF.TYPE, vf.createIRI("http://xmlns.com/foaf/0.1/Thang")), - vf.createStatement(vf.createIRI(BASE_INDIV_NS + "0"), vf.createIRI("http://myvoc.org/testing#propA"), vf.createLiteral(1L)), - vf.createStatement(vf.createIRI(BASE_INDIV_NS + "0"), vf.createIRI("http://myvoc.org/testing#propB"), vf.createLiteral("hello")), - vf.createStatement(vf.createIRI(BASE_INDIV_NS + "0"), vf.createIRI("http://xmlns.com/foaf/0.1/linkedTo"), vf.createIRI(BASE_INDIV_NS + "1")), - vf.createStatement(vf.createIRI(BASE_INDIV_NS + "1"), RDF.TYPE, vf.createIRI("http://xmlns.com/foaf/0.1/Thang")), - vf.createStatement(vf.createIRI(BASE_INDIV_NS + "1"), vf.createIRI(DEFAULT_BASE_SCH_NS + "b2"), vf.createLiteral("bye","en")), - vf.createStatement(vf.createIRI(BASE_INDIV_NS + "1"), vf.createIRI("http://myvoc.org/testing#propA"), vf.createLiteral(2L)))); + vf.createStatement(vf.createIRI(BASE_INDIV_NS + idMap.get("0")), RDF.TYPE, vf.createIRI("http://xmlns.com/foaf/0.1/Thang")), + vf.createStatement(vf.createIRI(BASE_INDIV_NS + idMap.get("0")), vf.createIRI("http://myvoc.org/testing#propA"), vf.createLiteral(1L)), + vf.createStatement(vf.createIRI(BASE_INDIV_NS + idMap.get("0")), vf.createIRI("http://myvoc.org/testing#propB"), vf.createLiteral("hello")), + vf.createStatement(vf.createIRI(BASE_INDIV_NS + idMap.get("0")), vf.createIRI("http://xmlns.com/foaf/0.1/linkedTo"), vf.createIRI(BASE_INDIV_NS + idMap.get("1"))), + vf.createStatement(vf.createIRI(BASE_INDIV_NS + idMap.get("1")), RDF.TYPE, vf.createIRI("http://xmlns.com/foaf/0.1/Thang")), + vf.createStatement(vf.createIRI(BASE_INDIV_NS + idMap.get("1")), vf.createIRI(DEFAULT_BASE_SCH_NS + "b2"), vf.createLiteral("bye","en")), + vf.createStatement(vf.createIRI(BASE_INDIV_NS + idMap.get("1")), vf.createIRI("http://myvoc.org/testing#propA"), vf.createLiteral(2L)))); int resultCount = 0; while (res.hasNext()) { @@ -280,17 +279,13 @@ public void testExportFromCypherOnLPGWithMappings() throws Exception { @Test public void testExportFromCypherOnRDF() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - - Session session = driver.session(); + try (Session session = driver.session();) { initialiseGraphDB(neo4j.defaultDatabaseService(), " { handleVocabUris: 'SHORTEN' } "); } - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { Result importResults1 = session.run("CALL n10s.rdf.import.inline('" + jsonLdFragment + "','JSON-LD')"); @@ -358,11 +353,7 @@ private Statement recordAsStatement(ValueFactory vf, Record r) { @Test public void testExportFromTriplePatternNoGraphConfig() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - - Session session = driver.session(); - + try (Session session = driver.session();) { Transaction tx = session.beginTransaction(); tx.run(Files.readString(Paths.get( RDFExportTest.class.getClassLoader().getResource("movies.cypher").getPath()))); @@ -377,11 +368,7 @@ public void testExportFromTriplePatternNoGraphConfig() throws Exception { @Test public void testExportFromTriplePatternOnRDFGraphShortenDefault() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - - Session session = driver.session(); - + try (Session session = driver.session();) { initialiseGraphDB(neo4j.defaultDatabaseService(), " {} "); @@ -391,16 +378,11 @@ public void testExportFromTriplePatternOnRDFGraphShortenDefault() throws Excepti } allTriplePatterns(1); - } @Test public void testExportFromTriplePatternOnRDFGraphShortenMultival() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - - Session session = driver.session(); - + try (Session session = driver.session();) { initialiseGraphDB(neo4j.defaultDatabaseService(), " { handleMultival: 'ARRAY'} "); @@ -410,16 +392,11 @@ public void testExportFromTriplePatternOnRDFGraphShortenMultival() throws Except } allTriplePatterns(2); - } @Test public void testExportFromTriplePatternOnRDFGraphShortenTypesAsNodes() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - - Session session = driver.session(); - + try (Session session = driver.session();) { initialiseGraphDB(neo4j.defaultDatabaseService(), " { handleRDFTypes: 'NODES'} "); @@ -429,16 +406,11 @@ public void testExportFromTriplePatternOnRDFGraphShortenTypesAsNodes() throws Ex } allTriplePatterns(1); - } @Test public void testExportFromTriplePatternOnRDFGraphKeepDefault() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - - Session session = driver.session(); - + try (Session session = driver.session();) { initialiseGraphDB(neo4j.defaultDatabaseService(), " { handleVocabUris: 'KEEP' } "); @@ -452,11 +424,7 @@ public void testExportFromTriplePatternOnRDFGraphKeepDefault() throws Exception @Test public void testExportFromTriplePatternOnRDFGraphShortenDefaultWithMappings() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - - Session session = driver.session(); - + try (Session session = driver.session();) { initialiseGraphDB(neo4j.defaultDatabaseService(), " { handleVocabUris: 'SHORTEN_STRICT' } "); @@ -465,11 +433,7 @@ public void testExportFromTriplePatternOnRDFGraphShortenDefaultWithMappings() th assertEquals(2L, session.run("call n10s.nsprefixes.list() yield prefix return count(*) as ct").next().get("ct").asLong()); } - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - - Session session = driver.session(); - + try (Session session = driver.session();) { Result importResults1 = session.run("CALL n10s.rdf.import.inline('" + jsonLdFragment + "','JSON-LD')"); assertEquals(11L, importResults1.single().get("triplesLoaded").asLong()); @@ -481,11 +445,7 @@ public void testExportFromTriplePatternOnRDFGraphShortenDefaultWithMappings() th @Test public void testExportFromTriplePatternOnRDFGraphShortenTypesAsNodes2() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - - Session session = driver.session(); - + try (Session session = driver.session();) { initialiseGraphDB(neo4j.defaultDatabaseService(), " { handleRDFTypes: 'LABELS_AND_NODES'} "); @@ -495,11 +455,7 @@ public void testExportFromTriplePatternOnRDFGraphShortenTypesAsNodes2() throws E } - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - - Session session = driver.session(); - + try (Session session = driver.session();) { String expected = "@prefix neo4voc: .\n" + "@prefix neo4ind: .\n" + "\n" + @@ -544,11 +500,7 @@ public void testExportFromTriplePatternOnRDFGraphShortenTypesAsNodes2() throws E @Test public void testExportFromTriplePatternOnRDFGraphIgnoreDefault() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - - Session session = driver.session(); - + try (Session session = driver.session();) { initialiseGraphDB(neo4j.defaultDatabaseService(), " { handleVocabUris: 'IGNORE' } "); @@ -558,16 +510,11 @@ public void testExportFromTriplePatternOnRDFGraphIgnoreDefault() throws Exceptio } allTriplePatternsIgnore(1); - } @Test public void testExportFromTriplePatternOnRDFGraphIgnoreDefaultMultivalued() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - - Session session = driver.session(); - + try (Session session = driver.session();) { initialiseGraphDB(neo4j.defaultDatabaseService(), " { handleVocabUris: 'IGNORE' , handleMultival: 'ARRAY'} "); @@ -577,14 +524,10 @@ public void testExportFromTriplePatternOnRDFGraphIgnoreDefaultMultivalued() thro } allTriplePatternsIgnore(2); - } private void allTriplePatternsOnLPG() throws IOException { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { - - + try (Session session = driver.session()) { //getting a node's assigned uri long emilId = session .run("MATCH (n:Person) WHERE n.name = \"Emil Eifrem\" RETURN id(n) as id ").next().get("id").asLong(); @@ -614,10 +557,10 @@ private void allTriplePatternsOnLPG() throws IOException { getNTriplesGraphFromSPOPattern(session,"http://base/about#nonexistingresource",DEFAULT_BASE_SCH_NS + "name", "MS", true, "http://www.w3.org/2001/XMLSchema#string", null), RDFFormat.NTRIPLES)); expected = "{\n" + - " \"@id\" : \"n4ind:8\",\n" + + " \"@id\" : \"n4ind:" + emilId + "\",\n" + " \"@type\" : \"n4sch:Person\",\n" + " \"n4sch:ACTED_IN\" : {\n" + - " \"@id\" : \"n4ind:0\"\n" + + " \"@id\" : \"n4ind:" + theMatrixId + "\"\n" + " },\n" + " \"n4sch:born\" : {\n" + " \"@type\" : \"http://www.w3.org/2001/XMLSchema#long\",\n" + @@ -635,7 +578,7 @@ private void allTriplePatternsOnLPG() throws IOException { getNTriplesGraphFromSPOPattern(session,BASE_INDIV_NS + emilId,null, null, false, null, null), RDFFormat.NTRIPLES)); expected = "{\n" + - " \"@id\" : \"n4ind:8\",\n" + + " \"@id\" : \"n4ind:" + emilId + "\",\n" + " \"n4sch:name\" : \"Emil Eifrem\",\n" + " \"@context\" : {\n" + " \"n4sch\" : \"neo4j://graph.schema#\",\n" + @@ -649,7 +592,7 @@ private void allTriplePatternsOnLPG() throws IOException { expected = "{\n" + - " \"@id\" : \"n4ind:8\",\n" + + " \"@id\" : \"n4ind:" + emilId + "\",\n" + " \"@type\" : \"n4sch:Person\",\n" + " \"@context\" : {\n" + " \"n4sch\" : \"neo4j://graph.schema#\",\n" + @@ -664,7 +607,7 @@ private void allTriplePatternsOnLPG() throws IOException { expected = "{\n" + - " \"@id\" : \"n4ind:8\",\n" + + " \"@id\" : \"n4ind:" + emilId + "\",\n" + " \"n4sch:name\" : \"Emil Eifrem\",\n" + " \"@context\" : {\n" + " \"n4sch\" : \"neo4j://graph.schema#\",\n" + @@ -677,7 +620,7 @@ private void allTriplePatternsOnLPG() throws IOException { getNTriplesGraphFromSPOPattern(session,BASE_INDIV_NS + emilId,DEFAULT_BASE_SCH_NS + "name", "Emil Eifrem", true, "http://www.w3.org/2001/XMLSchema#string", null), RDFFormat.NTRIPLES)); expected = "{\n" + - " \"@id\" : \"n4ind:8\",\n" + + " \"@id\" : \"n4ind:" + emilId + "\",\n" + " \"n4sch:born\" : {\n" + " \"@type\" : \"http://www.w3.org/2001/XMLSchema#long\",\n" + " \"@value\" : \"1978\"\n" + @@ -702,7 +645,7 @@ private void allTriplePatternsOnLPG() throws IOException { expected = "{\n" + - " \"@id\" : \"n4ind:8\",\n" + + " \"@id\" : \"n4ind:" + emilId + "\",\n" + " \"@type\" : \"n4sch:Person\",\n" + " \"@context\" : {\n" + " \"n4sch\" : \"neo4j://graph.schema#\",\n" + @@ -740,55 +683,20 @@ private void allTriplePatternsOnLPG() throws IOException { .compareModels("{}", RDFFormat.JSONLD, getNTriplesGraphFromSPOPattern(session,null,"http://undefinedvoc.org/name", null, false, null, null), RDFFormat.NTRIPLES)); + StringBuilder titleTriplesSb = new StringBuilder(); + Result titlesQueryResult = session.run("MATCH (n:Movie) RETURN id(n) as id, n.title as title "); + while(titlesQueryResult.hasNext()){ + Record movie = titlesQueryResult.next(); + titleTriplesSb.append(" \"") + .append(movie.get("title").asString()).append("\" .\n"); + } - // if we hardcode the ids here what's the point of getting them at the beginning for Emil, Renier and The Matrix? - //TODO: do this right - String titleTriples = " \"The Matrix\" .\n" + - " \"The Matrix Reloaded\" .\n" + - " \"The Matrix Revolutions\" .\n" + - " \"The Devil's Advocate\" .\n" + - " \"A Few Good Men\" .\n" + - " \"Top Gun\" .\n" + - " \"Jerry Maguire\" .\n" + - " \"Stand By Me\" .\n" + - " \"As Good as It Gets\" .\n" + - " \"What Dreams May Come\" .\n" + - " \"Snow Falling on Cedars\" .\n" + - " \"You've Got Mail\" .\n" + - " \"Sleepless in Seattle\" .\n" + - " \"Joe Versus the Volcano\" .\n" + - " \"When Harry Met Sally\" .\n" + - " \"That Thing You Do\" .\n" + - " \"The Replacements\" .\n" + - " \"RescueDawn\" .\n" + - " \"The Birdcage\" .\n" + - " \"Unforgiven\" .\n" + - " \"Johnny Mnemonic\" .\n" + - " \"Cloud Atlas\" .\n" + - " \"The Da Vinci Code\" .\n" + - " \"V for Vendetta\" .\n" + - " \"Speed Racer\" .\n" + - " \"Ninja Assassin\" .\n" + - " \"The Green Mile\" .\n" + - " \"Frost/Nixon\" .\n" + - " \"Hoffa\" .\n" + - " \"Apollo 13\" .\n" + - " \"Twister\" .\n" + - " \"Cast Away\" .\n" + - " \"One Flew Over the Cuckoo's Nest\" .\n" + - " \"Something's Gotta Give\" .\n" + - " \"Bicentennial Man\" .\n" + - " \"Charlie Wilson's War\" .\n" + - " \"The Polar Express\" .\n" + - " \"A League of Their Own\" ."; - - - assertTrue(ModelTestUtils - .compareModels(titleTriples, RDFFormat.NTRIPLES, + assertTrue(ModelTestUtils + .compareModels(titleTriplesSb.toString(), RDFFormat.NTRIPLES, getNTriplesGraphFromSPOPattern(session,null,DEFAULT_BASE_SCH_NS + "title", null, false, null, null), RDFFormat.NTRIPLES)); expected = "{\n" + - " \"@id\" : \"n4ind:8\",\n" + + " \"@id\" : \"n4ind:" + emilId + "\",\n" + " \"n4sch:born\" : {\n" + " \"@type\" : \"http://www.w3.org/2001/XMLSchema#long\",\n" + " \"@value\" : \"1978\"\n" + @@ -826,19 +734,17 @@ private void allTriplePatternsOnLPG() throws IOException { { criticTypesTriples.append("<" + BASE_INDIV_NS + id + "> <" + DEFAULT_BASE_SCH_NS + "Critic> .\n"); criticTypesTriples.append("<" + BASE_INDIV_NS + id + "> <" + DEFAULT_BASE_SCH_NS + "Person> .\n");} ); - String someMovies = " .\n" + - " .\n" + - " .\n" + - " .\n" + - " .\n" + - " .\n" + - " .\n" + - " .\n" + - " .\n" ; + StringBuilder someMoviesSb = new StringBuilder(); + Result someMoviesQueryResult = session.run("MATCH (n:Movie) RETURN id(n) as id skip 30 limit 10"); + while(someMoviesQueryResult.hasNext()){ + Record movie = someMoviesQueryResult.next(); + someMoviesSb.append(" .\n"); + } assertTrue(ModelTestUtils .modelContains(getNTriplesGraphFromSPOPattern(session,null,"http://www.w3.org/1999/02/22-rdf-syntax-ns#type", null, false, null, null), RDFFormat.NTRIPLES, - criticTypesTriples.toString() + someMovies, RDFFormat.NTRIPLES)); + criticTypesTriples.toString() + someMoviesSb.toString(), RDFFormat.NTRIPLES)); StringBuilder criticTypesTriples2 = new StringBuilder(); critics.forEach(id-> criticTypesTriples2.append("<" + BASE_INDIV_NS + id + "> <" + DEFAULT_BASE_SCH_NS + "Critic> .\n") ); @@ -849,7 +755,7 @@ private void allTriplePatternsOnLPG() throws IOException { String allGraphAsNTriples = getNTriplesGraphFromSPOPattern(session, null, null, null, false, null, null); assertTrue(ModelTestUtils.modelContains(allGraphAsNTriples, RDFFormat.NTRIPLES, - criticTypesTriples.toString() + someMovies + titleTriples, RDFFormat.NTRIPLES )); + criticTypesTriples.toString() + someMoviesSb.toString() + titleTriplesSb.toString(), RDFFormat.NTRIPLES )); assertFalse(ModelTestUtils.modelContains(allGraphAsNTriples, RDFFormat.NTRIPLES, " ." , RDFFormat.NTRIPLES )); @@ -859,8 +765,7 @@ private void allTriplePatternsOnLPG() throws IOException { private void allTriplePatterns( int mode) throws IOException { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { //getting a bnode's assigned uri String bnodeUri = session @@ -1183,8 +1088,7 @@ private void allTriplePatterns( int mode) throws IOException { private void allTriplePatternsIgnore( int mode) throws IOException { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { //getting a bnode's assigned uri String bnodeUri = session @@ -1562,11 +1466,17 @@ private String getNTriplesGraphFromSPOPatternLiteralDefaults(Session session, S @Test public void testExportFromCypherOnLPGPointTypeProperties() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { + + Map idMap = new HashMap<>(); + { + Record record = session + .run("CREATE (n0:GeoLocatedThing { hi: 'hello' , where: point({x: -0.1275, y: 51.507222222}) }) return n0") + .next(); - session.run("CREATE (n:GeoLocatedThing { hi: 'hello' , where: point({x: -0.1275, y: 51.507222222}) })"); + idMap.put("0", String.valueOf(((NodeValue) record.get("n0")).asNode().id())); + } Result res = session .run(" CALL n10s.rdf.export.cypher(' MATCH (n:GeoLocatedThing) RETURN n ', {}) "); @@ -1574,9 +1484,9 @@ public void testExportFromCypherOnLPGPointTypeProperties() throws Exception { final ValueFactory vf = SimpleValueFactory.getInstance(); Set expectedStatememts = new HashSet<>(Arrays.asList( - vf.createStatement(vf.createIRI(BASE_INDIV_NS + "0"), RDF.TYPE, vf.createIRI(DEFAULT_BASE_SCH_NS + "GeoLocatedThing")), - vf.createStatement(vf.createIRI(BASE_INDIV_NS + "0"), vf.createIRI(DEFAULT_BASE_SCH_NS + "hi"), vf.createLiteral("hello")), - vf.createStatement(vf.createIRI(BASE_INDIV_NS + "0"), vf.createIRI(DEFAULT_BASE_SCH_NS + "where"), + vf.createStatement(vf.createIRI(BASE_INDIV_NS + idMap.get("0")), RDF.TYPE, vf.createIRI(DEFAULT_BASE_SCH_NS + "GeoLocatedThing")), + vf.createStatement(vf.createIRI(BASE_INDIV_NS + idMap.get("0")), vf.createIRI(DEFAULT_BASE_SCH_NS + "hi"), vf.createLiteral("hello")), + vf.createStatement(vf.createIRI(BASE_INDIV_NS + idMap.get("0")), vf.createIRI(DEFAULT_BASE_SCH_NS + "where"), vf.createLiteral("Point(-0.1275 51.507222222)",vf.createIRI(GEOSPARQL_NS + WKTLITERAL))))); int resultCount = 0; @@ -1587,18 +1497,22 @@ public void testExportFromCypherOnLPGPointTypeProperties() throws Exception { } assertEquals(resultCount,expectedStatememts.size()); + { + Record record = session + .run("CREATE (n1:GeoLocatedThing3D { hi: 'hello' , where: point({x: -0.1275, y: 51.507222222, z: 34.0 })}) return n1") + .next(); - session.run("CREATE (n:GeoLocatedThing3D { hi: 'hello' , where: point({x: -0.1275, y: 51.507222222, z: 34.0 }) })"); - + idMap.put("1", String.valueOf(((NodeValue) record.get("n1")).asNode().id())); + } res = session .run(" CALL n10s.rdf.export.cypher(' MATCH (n:GeoLocatedThing3D) RETURN n ', {}) "); assertTrue(res.hasNext()); expectedStatememts = new HashSet<>(Arrays.asList( - vf.createStatement(vf.createIRI(BASE_INDIV_NS + "1"), RDF.TYPE, vf.createIRI(DEFAULT_BASE_SCH_NS + "GeoLocatedThing3D")), - vf.createStatement(vf.createIRI(BASE_INDIV_NS + "1"), vf.createIRI(DEFAULT_BASE_SCH_NS + "hi"), vf.createLiteral("hello")), - vf.createStatement(vf.createIRI(BASE_INDIV_NS + "1"), vf.createIRI(DEFAULT_BASE_SCH_NS + "where"), + vf.createStatement(vf.createIRI(BASE_INDIV_NS + idMap.get("1")), RDF.TYPE, vf.createIRI(DEFAULT_BASE_SCH_NS + "GeoLocatedThing3D")), + vf.createStatement(vf.createIRI(BASE_INDIV_NS + idMap.get("1")), vf.createIRI(DEFAULT_BASE_SCH_NS + "hi"), vf.createLiteral("hello")), + vf.createStatement(vf.createIRI(BASE_INDIV_NS + idMap.get("1")), vf.createIRI(DEFAULT_BASE_SCH_NS + "where"), vf.createLiteral("Point(-0.1275 51.507222222 34.0)",vf.createIRI(GEOSPARQL_NS + WKTLITERAL))))); resultCount = 0; diff --git a/src/test/java/n10s/RDFProceduresTest.java b/src/test/java/n10s/RDFProceduresTest.java index b6ed20e4..5cd0534f 100644 --- a/src/test/java/n10s/RDFProceduresTest.java +++ b/src/test/java/n10s/RDFProceduresTest.java @@ -30,13 +30,13 @@ import n10s.quadrdf.load.QuadRDFLoadProcedures; import n10s.rdf.RDFProcedures; import n10s.rdf.delete.RDFDeleteProcedures; +import n10s.rdf.export.RDFExportProcedures; import n10s.rdf.load.RDFLoadProcedures; import n10s.rdf.preview.RDFPreviewProcedures; import n10s.rdf.stream.RDFStreamProcedures; import n10s.skos.load.SKOSLoadProcedures; import org.eclipse.rdf4j.model.vocabulary.XMLSchema; -import org.junit.Rule; -import org.junit.Test; +import org.junit.*; import org.neo4j.driver.Config; import org.neo4j.driver.Driver; import org.neo4j.driver.GraphDatabase; @@ -56,21 +56,37 @@ * Created by jbarrasa on 21/03/2016. */ public class RDFProceduresTest { + public static Driver driver; + + @ClassRule + public static Neo4jRule neo4j = new Neo4jRule() + .withProcedure(RDFLoadProcedures.class) + .withProcedure(RDFDeleteProcedures.class) + .withProcedure(RDFPreviewProcedures.class) + .withProcedure(RDFStreamProcedures.class) + .withFunction(RDFProcedures.class) + .withProcedure(QuadRDFLoadProcedures.class) + .withProcedure(QuadRDFDeleteProcedures.class) + .withProcedure(MappingUtils.class) + .withProcedure(GraphConfigProcedures.class) + .withProcedure(NsPrefixDefProcedures.class) + .withProcedure(ExperimentalImports.class) + .withProcedure(SKOSLoadProcedures.class); + + @BeforeClass + public static void init() { + driver = GraphDatabase.driver(neo4j.boltURI(), + Config.builder().withoutEncryption().build()); + } + + @Before + public void cleanDatabase() { + driver.session().run("match (n) detach delete n").consume(); + driver.session().run("drop constraint n10s_unique_uri if exists").consume(); + driver.session().run("drop index uri_index if exists").consume(); + } - @Rule - public Neo4jRule neo4j = new Neo4jRule() - .withProcedure(RDFLoadProcedures.class) - .withProcedure(RDFDeleteProcedures.class) - .withProcedure(RDFPreviewProcedures.class) - .withProcedure(RDFStreamProcedures.class) - .withFunction(RDFProcedures.class) - .withProcedure(QuadRDFLoadProcedures.class) - .withProcedure(QuadRDFDeleteProcedures.class) - .withProcedure(MappingUtils.class) - .withProcedure(GraphConfigProcedures.class) - .withProcedure(NsPrefixDefProcedures.class) - .withProcedure(ExperimentalImports.class) - .withProcedure(SKOSLoadProcedures.class); + final String CREATE_URI_INDEX = "CREATE INDEX uri_index FOR (n:Resource) ON (n.uri)"; private String jsonLdFragment = "{\n" + " \"@context\": {\n" + @@ -352,8 +368,7 @@ private static URI file(String path) { @Test public void testAbortIfNoIndices() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { Result importResults = session.run("CALL n10s.rdf.import.fetch('" + @@ -373,8 +388,7 @@ public void testAbortIfNoIndices() throws Exception { @Test public void testFullTextIndexesPresent() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { session.run("CREATE FULLTEXT INDEX titlesAndDescriptions FOR (n:Movie|Book) ON EACH [n.title, n.description]"); @@ -394,10 +408,8 @@ public void testFullTextIndexesPresent() throws Exception { @Test public void testCompositeIndexesPresent() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { - - session.run("CREATE INDEX FOR (p:Person) ON (p.age, p.country)"); + try (Session session = driver.session()) { + session.run("CREATE INDEX IF NOT EXISTS FOR (n:Person) ON (n.age, n.country)"); Result importResults = session.run("CALL n10s.rdf.import.fetch('file:///fileDoesnotExist.txt','JSON-LD',{})"); @@ -416,10 +428,7 @@ public void testCompositeIndexesPresent() throws Exception { @Test public void testAbortIfNoIndicesImportSnippet() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - - Session session = driver.session(); + try (Session session = driver.session();) { Result importResults1 = session.run("CALL n10s.rdf.import.inline('" + turtleFragment + @@ -437,8 +446,7 @@ public void testAbortIfNoIndicesImportSnippet() throws Exception { @Test public void testImportJSONLD() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{ handleVocabUris: 'KEEP', handleRDFTypes: 'LABELS' }"); @@ -466,8 +474,7 @@ public void testImportJSONLD() throws Exception { @Test public void testInvalidSerialisationFormat() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{ handleVocabUris: 'KEEP', handleRDFTypes: 'LABELS' }"); @@ -524,8 +531,7 @@ public void testInvalidSerialisationFormat() throws Exception { @Test public void testImportZippedSingleFile() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{ handleVocabUris: 'KEEP', handleRDFTypes: 'LABELS' }"); @@ -605,8 +611,7 @@ public void testImportZippedSingleFile() throws Exception { @Test public void testImportZippedMultiFile() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{ handleVocabUris: 'KEEP', handleRDFTypes: 'LABELS' }"); @@ -639,8 +644,7 @@ public void testImportZippedMultiFile() throws Exception { @Test public void testImportSKOSInline() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{ handleVocabUris: 'IGNORE', handleMultival: 'ARRAY' }"); @@ -664,8 +668,7 @@ public void testImportSKOSInline() throws Exception { @Test public void testImportSKOSFetchWithParams() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{}"); @@ -695,8 +698,7 @@ public void testImportSKOSFetchWithParams() throws Exception { @Test public void testImportSKOSFetchWithParamsCustomSchemaNs() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{ baseSchemaNamespace: 'http://baseschema.mine/voc1#' , " + @@ -727,8 +729,7 @@ public void testImportSKOSFetchWithParamsCustomSchemaNs() throws Exception { @Test public void testImportRDFStar () throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{ handleVocabUris: 'IGNORE' }"); @@ -754,8 +755,7 @@ public void testImportRDFStar () throws Exception { @Test public void testImportRDFStarWithArrayMultiVal () throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{ handleVocabUris: 'IGNORE' , " + @@ -785,8 +785,7 @@ public void testImportRDFStarWithArrayMultiVal () throws Exception { @Test public void testImportSKOSFetchMultivalArray() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{ handleMultival: 'ARRAY', keepLangTag: true }"); @@ -819,11 +818,7 @@ public void testImportSKOSFetchMultivalArray() throws Exception { @Test public void testImportJSONLDImportSnippet() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - - Session session = driver.session(); - + try (Session session = driver.session();) { initialiseGraphDB(neo4j.defaultDatabaseService(), " { handleVocabUris: 'KEEP', handleRDFTypes: 'LABELS'} "); @@ -844,11 +839,7 @@ public void testImportJSONLDImportSnippet() throws Exception { @Test public void testImportTurtleSnippetWithPoints() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - - Session session = driver.session(); - + try (Session session = driver.session();) { initialiseGraphDB(neo4j.defaultDatabaseService(), " { handleVocabUris: 'SHORTEN' } "); @@ -891,8 +882,7 @@ public void testImportTurtleSnippetWithPoints() throws Exception { @Test public void testImportJSONLDShortening() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{ handleVocabUris: 'SHORTEN', handleRDFTypes: 'LABELS' }"); @@ -948,14 +938,12 @@ public void testImportJSONLDShortening() throws Exception { @Test public void testImportJSONLDShorteningStrict() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session();) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{ handleVocabUris: 'SHORTEN_STRICT', handleRDFTypes: 'LABELS' }"); } - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { Result importResults = session.run("CALL n10s.rdf.import.fetch('" + RDFProceduresTest.class.getClassLoader().getResource("mini-ld.json").toURI() @@ -972,8 +960,7 @@ public void testImportJSONLDShorteningStrict() throws Exception { + "namespace and 'handleVocabUris' is set " + "to 'SHORTEN_STRICT'", e.getMessage()); } - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { assertEquals("one", session.run("call n10s.nsprefixes.add('one','http://xmlns.com/foaf/0.1/')").next() .get("prefix").asString()); @@ -1001,8 +988,7 @@ public void testImportJSONLDShorteningStrict() throws Exception { @Test public void testImportRDFXML() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{ handleVocabUris: 'KEEP', handleRDFTypes: 'LABELS' }"); @@ -1032,8 +1018,7 @@ public void testImportRDFXML() throws Exception { @Test public void testImportRDFXMLShortening() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), null); @@ -1068,8 +1053,7 @@ public void testImportRDFXMLShortening() throws Exception { @Test public void testImportRDFXMLShorteningWithPrefixPreDefinition() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), null); session.run("call n10s.nsprefixes.add('dct','http://purl.org/dc/terms/')"); @@ -1110,8 +1094,7 @@ public void testImportRDFXMLShorteningWithPrefixPreDefinition() throws Exception @Test public void testImportRDFXMLShorteningWithPrefixPreDefinitionOneTriple() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), null); session.run("call n10s.nsprefixes.add('voc','http://neo4j.com/voc/')"); @@ -1137,8 +1120,7 @@ public void testImportRDFXMLShorteningWithPrefixPreDefinitionOneTriple() throws @Test public void testImportBadUrisTtl() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{ handleVocabUris: 'SHORTEN', handleRDFTypes: 'LABELS' }"); @@ -1161,8 +1143,7 @@ public void testImportBadUrisTtl() throws Exception { @Test public void testImportTtlBadUrisException() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), null); @@ -1186,8 +1167,7 @@ public void testImportTtlBadUrisException() throws Exception { @Test public void testImportRDFXMLBadUris() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), null); session.run("call n10s.nsprefixes.add('voc','http://neo4j.com/voc/')"); @@ -1208,8 +1188,7 @@ public void testImportRDFXMLBadUris() throws Exception { @Test public void testImportLangFilter() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), null); @@ -1280,8 +1259,7 @@ public void testImportLangFilter() throws Exception { @Test public void testImportMultivalLangTag() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{ keepLangTag : true, handleMultival: 'ARRAY'}"); @@ -1309,8 +1287,7 @@ public void testImportMultivalLangTag() throws Exception { @Test public void testImportMultivalWithMultivalList() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{ handleMultival: 'ARRAY', " + @@ -1348,8 +1325,7 @@ public void testImportMultivalWithMultivalList() throws Exception { @Test public void testImportMultivalWithExclusionList() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{ handleMultival: 'ARRAY' }"); @@ -1383,8 +1359,7 @@ public void testImportMultivalWithExclusionList() throws Exception { @Test public void testImportTurtle() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{ handleVocabUris: 'KEEP', handleRDFTypes: 'LABELS' }"); @@ -1418,8 +1393,7 @@ public void testImportTurtle() throws Exception { */ @Test public void testImportTurtle02() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), null); session.run("call n10s.nsprefixes.add('ex','http://www.example.com/ontology/1.0.0#')"); @@ -1443,8 +1417,7 @@ public void testImportTurtle02() throws Exception { @Test public void testPreviewFromSnippetPassWrongUri() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{handleVocabUris: 'KEEP', handleRDFTypes: 'NODES' }"); @@ -1464,8 +1437,7 @@ public void testPreviewFromSnippetPassWrongUri() throws Exception { @Test public void testPreviewFromSnippetFailWrongUri() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{ handleVocabUris: 'KEEP', handleRDFTypes: 'NODES'}"); @@ -1488,8 +1460,7 @@ public void testPreviewFromSnippetFailWrongUri() throws Exception { @Test public void testPreviewFromSnippet() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{ handleVocabUris: 'KEEP', handleRDFTypes: 'NODES'}"); @@ -1508,8 +1479,7 @@ public void testPreviewFromSnippet() throws Exception { @Test public void testPreviewFromSnippetLimit() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{ handleVocabUris: 'KEEP', handleRDFTypes: 'NODES'}"); @@ -1542,8 +1512,7 @@ public void testPreviewFromSnippetLimit() throws Exception { @Test public void testPreviewFromFileLimit() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{ handleVocabUris: 'KEEP', handleRDFTypes: 'NODES'}"); @@ -1580,8 +1549,7 @@ public void testPreviewFromFileLimit() throws Exception { @Test public void testPreviewRDFStarFromSnippet() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{handleVocabUris: 'IGNORE'}"); @@ -1603,8 +1571,7 @@ public void testPreviewRDFStarFromSnippet() throws Exception { @Test public void testRDFStarWithTriplesAsObjectFromSnippet() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{handleVocabUris: 'IGNORE'}"); @@ -1624,8 +1591,7 @@ public void testRDFStarWithTriplesAsObjectFromSnippet() throws Exception { @Test public void testLoadFromSnippetCreateNodes() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{ handleVocabUris: 'KEEP', handleRDFTypes: 'NODES'}"); @@ -1650,8 +1616,7 @@ public void testLoadFromSnippetCreateNodes() throws Exception { @Test public void testLoadFromSnippetCreateNodesAndLabels() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{ handleVocabUris: 'SHORTEN', handleRDFTypes: 'LABELS_AND_NODES'}"); @@ -1676,8 +1641,7 @@ public void testLoadFromSnippetCreateNodesAndLabels() throws Exception { @Test public void testPreviewFromSnippetLangFilter() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{ handleVocabUris: 'KEEP', handleRDFTypes: 'NODES' }"); @@ -1712,8 +1676,7 @@ public void testPreviewFromSnippetLangFilter() throws Exception { @Test public void testPointDatatype() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{handleVocabUris: 'IGNORE'}"); @@ -1755,8 +1718,7 @@ record = session @Test public void testPointDatatypeInMars() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{handleVocabUris: 'IGNORE'}"); @@ -1777,8 +1739,7 @@ public void testPointDatatypeInMars() throws Exception { @Test public void testPreviewFromFile() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{ handleVocabUris: 'KEEP', handleRDFTypes: 'NODES' }"); @@ -1799,8 +1760,7 @@ public void testPreviewFromFile() throws Exception { @Test public void testPreviewFromBadUriFile() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), null); @@ -1821,8 +1781,7 @@ public void testPreviewFromBadUriFile() throws Exception { @Test public void testPreviewFromBadUriFileFail() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{ handleVocabUris: 'KEEP', handleRDFTypes: 'NODES'}"); @@ -1846,8 +1805,7 @@ public void testPreviewFromBadUriFileFail() throws Exception { @Test public void testPreviewFromFileLangFilter() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{ handleVocabUris: 'KEEP', handleRDFTypes: 'NODES', keepLangTag : false }"); @@ -1878,14 +1836,12 @@ public void testPreviewFromFileLangFilter() throws Exception { @Test public void testImportFromFileWithMapping() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { session.run("call n10s.nsprefixes.add('voc','http://neo4j.com/voc/')"); session.run("call n10s.nsprefixes.add('cats','http://neo4j.com/category/')"); } - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{ handleVocabUris: 'MAP'}"); @@ -1916,8 +1872,7 @@ public void testImportFromFileWithMapping() throws Exception { @Test public void testImportFromFileIgnoreNs() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{ handleVocabUris: 'IGNORE'}"); @@ -1946,8 +1901,7 @@ public void testImportFromFileIgnoreNs() throws Exception { @Test public void testImportFromFileIgnoreNsApplyNeoNaming() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{ handleVocabUris: 'IGNORE', applyNeo4jNaming: true }"); @@ -1978,14 +1932,12 @@ public void testImportFromFileIgnoreNsApplyNeoNaming() throws Exception { @Test public void testImportFromFileWithPredFilter() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { session.run("call n10s.nsprefixes.add('sch','http://schema.org/')"); session.run("call n10s.nsprefixes.add('cats','http://neo4j.com/category/')"); } - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(),"{ handleVocabUris: 'MAP'}"); @@ -2022,8 +1974,7 @@ public void testImportFromFileWithPredFilter() throws Exception { @Test public void testStreamFromFile() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { Result importResults = session.run("CALL n10s.rdf.stream.fetch('" + @@ -2042,8 +1993,7 @@ public void testStreamFromFile() throws Exception { @Test public void testStreamFromFileWithLimit() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { Result importResults = session.run("CALL n10s.rdf.stream.fetch('" + @@ -2058,8 +2008,7 @@ public void testStreamFromFileWithLimit() throws Exception { @Test public void testStreamFromFileWithExclusionList() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { String filteredPred = "http://schema.org/image"; @@ -2102,8 +2051,7 @@ public void testStreamFromFileWithExclusionList() throws Exception { @Test public void testStreamFromString() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { String rdf = " getPrePostDelta(Map defsPre, @Test public void testIncrementalLoadArrayOnPreviouslyAtomicValue() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), null); @@ -2791,8 +2721,7 @@ public void testIncrementalLoadArrayOnPreviouslyAtomicValue() throws Exception { @Test public void testIncrementalLoadAtomicValueOnPreviouslyArray() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), null); @@ -2817,11 +2746,10 @@ public void testIncrementalLoadAtomicValueOnPreviouslyArray() throws Exception { } } - + @Test public void testLargerFileManyTransactions() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), null); @@ -2837,8 +2765,7 @@ public void testLargerFileManyTransactions() throws Exception { @Test public void dbpediaFragmentTest() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{handleMultival:'ARRAY', handleRDFTypes: 'NODES'}"); @@ -2876,8 +2803,7 @@ public void dbpediaFragmentTest() throws Exception { @Test public void multivalMultitypeSamePartialTx() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{handleMultival:'ARRAY', handleRDFTypes: 'NODES'}"); @@ -2952,8 +2878,7 @@ public void multivalMultitypeSamePartialTx() throws Exception { @Test public void homogeneousMultivalAcrossPartialCommits() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{handleMultival:'ARRAY', handleRDFTypes: 'NODES'}"); @@ -2993,8 +2918,7 @@ public void homogeneousMultivalAcrossPartialCommits() throws Exception { @Test public void heterogeneousMultivalAcrossPartialCommits() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{handleMultival:'ARRAY', handleRDFTypes: 'NODES', keepCustomDataTypes: true}"); @@ -3121,8 +3045,7 @@ public void heterogeneousMultivalAcrossPartialCommits() throws Exception { @Test public void heterogeneousMultivalAcrossPartialCommitsWithKeepURIs() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{handleMultival:'ARRAY', handleVocabUris: 'KEEP', keepCustomDataTypes: true}"); @@ -3157,8 +3080,7 @@ public void heterogeneousMultivalAcrossPartialCommitsWithKeepURIs() throws Excep @Test public void testTypesOnlySeparateTx() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{handleMultival:'ARRAY', keepCustomDataTypes: true}"); @@ -3184,8 +3106,7 @@ public void testTypesOnlySeparateTx() throws Exception { @Test public void testDeleteRelationshipKeepURIs() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{ handleVocabUris: 'KEEP', handleRDFTypes: 'LABELS', keepCustomDataTypes: true, handleMultival: 'ARRAY'}"); @@ -3226,8 +3147,7 @@ record = result.next(); @Test public void testDeleteRelationshipShortenURIs() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), null); @@ -3268,8 +3188,7 @@ record = result.next(); @Test public void testDeleteRelationshipShortenURIsFromString() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), null); @@ -3334,8 +3253,7 @@ record = result.next(); @Test public void testDeleteLiteralKeepURIs() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{ handleVocabUris: 'KEEP', handleRDFTypes: 'LABELS', " + @@ -3371,8 +3289,7 @@ record = result.next(); @Test public void testDeleteLiteralShortenURIs() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), " { handleVocabUris: 'SHORTEN', handleRDFTypes: 'LABELS', " + @@ -3408,8 +3325,7 @@ record = result.next(); @Test public void testDeleteLiteralShortenURIsFromString() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{ handleVocabUris: 'SHORTEN', handleRDFTypes: 'LABELS', keepCustomDataTypes: true, handleMultival: 'ARRAY'}"); @@ -3470,8 +3386,7 @@ record = result.next(); @Test public void testDeleteTypeFromResource() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), null); @@ -3506,8 +3421,7 @@ record = result.next(); @Test public void testDeleteAllTriplesRelatedToResource() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), null); @@ -3537,8 +3451,7 @@ public void testDeleteAllTriplesRelatedToResource() throws Exception { @Test public void testDeleteMultiLiteral() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{handleVocabUris: 'KEEP', handleRDFTypes: 'LABELS', keepCustomDataTypes: true, " + @@ -3593,8 +3506,7 @@ record = result.next(); @Test public void testDeleteSubjectNode() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), null); @@ -3628,8 +3540,7 @@ public void testDeleteSubjectNode() throws Exception { @Test public void testRepetitiveDeletion() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "" + "{ handleVocabUris: 'KEEP', handleRDFTypes: 'LABELS', keepCustomDataTypes: true, handleMultival: 'ARRAY'}"); @@ -3667,11 +3578,7 @@ public void testRepetitiveDeletion() throws Exception { @Test public void testImportDatesAndTimes() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - - Session session = driver.session(); - + try (Session session = driver.session();) { initialiseGraphDB(neo4j.defaultDatabaseService(), null); Result importResults1 = session.run("CALL n10s.rdf.import.fetch('" + @@ -3691,11 +3598,7 @@ public void testImportDatesAndTimes() throws Exception { @Test public void testImportDatesAndTimes2() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - - Session session = driver.session(); - + try (Session session = driver.session();) { initialiseGraphDB(neo4j.defaultDatabaseService(), null); Result importResults1 = session.run("CALL n10s.rdf.import.fetch('" + @@ -3715,10 +3618,7 @@ public void testImportDatesAndTimes2() throws Exception { @Test public void testImportDatesAndTimesMultivalued() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - - Session session = driver.session(); + try (Session session = driver.session();) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{ handleMultival: 'ARRAY' }"); @@ -3758,8 +3658,7 @@ public void testImportDatesAndTimesMultivalued() throws Exception { @Test public void testImportQuadRDFTriG() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDBForQuads(neo4j.defaultDatabaseService(), "{ handleVocabUris: 'KEEP', handleRDFTypes: 'LABELS', keepCustomDataTypes: true, handleMultival: 'ARRAY' }"); @@ -3830,13 +3729,11 @@ record = result.next(); @Test public void testImportInlineQuadRDFTriG() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { session.run("call n10s.nsprefixes.add('ns0','http://www.example.org/vocabulary#')"); } - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDBForQuads(neo4j.defaultDatabaseService(), "{ keepCustomDataTypes: true, handleMultival: 'ARRAY' }"); @@ -3906,8 +3803,7 @@ record = result.next(); @Test public void testImportQuadRDFNQuads() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDBForQuads(neo4j.defaultDatabaseService(), "{ handleVocabUris: 'KEEP', handleRDFTypes: 'LABELS', keepCustomDataTypes: true, handleMultival: 'ARRAY' }"); @@ -3978,8 +3874,7 @@ record = result.next(); @Test public void testDeleteQuadRDFTriG() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDBForQuads(neo4j.defaultDatabaseService(), "{ handleVocabUris: 'KEEP', handleRDFTypes: 'LABELS', keepCustomDataTypes: true, handleMultival: 'ARRAY' }"); @@ -4010,8 +3905,7 @@ public void testDeleteQuadRDFTriG() throws Exception { @Test public void testDeleteQuadRDFNQuads() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDBForQuads(neo4j.defaultDatabaseService(), " { handleVocabUris: 'KEEP', handleRDFTypes: 'LABELS', keepCustomDataTypes: true, handleMultival: 'ARRAY' } "); @@ -4042,8 +3936,7 @@ public void testDeleteQuadRDFNQuads() throws Exception { @Test public void testRepetitiveDeletionQuadRDF() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDBForQuads(neo4j.defaultDatabaseService(), "{ handleVocabUris: 'KEEP', handleRDFTypes: 'LABELS', keepCustomDataTypes: true, handleMultival: 'ARRAY'}"); @@ -4086,7 +3979,7 @@ private void initialiseGraphDB(GraphDatabaseService db, String graphConfigParams } private void initialiseGraphDBForQuads(GraphDatabaseService db, String graphConfigParams) { - db.executeTransactionally("create index for (n:Resource) on (n.uri)"); + db.executeTransactionally(CREATE_URI_INDEX); db.executeTransactionally("CALL n10s.graphconfig.init(" + (graphConfigParams != null ? graphConfigParams : "{}") + ")"); } @@ -4094,8 +3987,7 @@ private void initialiseGraphDBForQuads(GraphDatabaseService db, String graphConf @Test public void testLoadJSONAsTreeEmptyJSON() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), null); @@ -4110,8 +4002,7 @@ public void testLoadJSONAsTreeEmptyJSON() throws Exception { @Test public void testLoadJSONAsTreeListAtRoot() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{ handleVocabUris: 'IGNORE' }"); @@ -4149,8 +4040,7 @@ public void testLoadJSONAsTreeListAtRoot() throws Exception { @Test public void testLoadJSONAsTree() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{ handleVocabUris: 'IGNORE' }"); @@ -4185,8 +4075,7 @@ public void testLoadJSONAsTree() throws Exception { @Test public void testLoadJSONAsTreeWithUrisAndContext() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{ handleVocabUris: 'IGNORE' }"); @@ -4240,8 +4129,7 @@ public void testLoadJSONAsTreeWithUrisAndContext() throws Exception { @Test public void testLoadJSONAsTree2() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{ handleVocabUris: 'IGNORE' }"); @@ -4295,8 +4183,7 @@ public void testLoadJSONAsTree2() throws Exception { @Test public void testLoadJSONAsTree3() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{ handleVocabUris: 'IGNORE' }"); diff --git a/src/test/java/n10s/aggregate/CollectTriplesTest.java b/src/test/java/n10s/aggregate/CollectTriplesTest.java index 44c40f67..ad03a271 100644 --- a/src/test/java/n10s/aggregate/CollectTriplesTest.java +++ b/src/test/java/n10s/aggregate/CollectTriplesTest.java @@ -10,9 +10,9 @@ import n10s.rdf.load.RDFLoadProcedures; import n10s.rdf.stream.RDFStreamProcedures; import org.eclipse.rdf4j.rio.RDFFormat; -import org.junit.Rule; -import org.junit.Test; +import org.junit.*; import org.neo4j.driver.*; +import org.neo4j.driver.exceptions.DatabaseException; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.harness.junit.rule.Neo4jRule; @@ -63,8 +63,10 @@ public class CollectTriplesTest { " skos:prefLabel \"Business Administration and Finance Theory\" ;\n" + " a ."; - @Rule - public Neo4jRule neo4j = new Neo4jRule() + public static Driver driver; + + @ClassRule + public static Neo4jRule neo4j = new Neo4jRule() .withProcedure(RDFStreamProcedures.class) .withProcedure(RDFLoadProcedures.class) .withProcedure(GraphConfigProcedures.class) @@ -72,97 +74,88 @@ public class CollectTriplesTest { .withProcedure(NsPrefixDefProcedures.class) .withAggregationFunction(CollectTriples.class); - @Test - public void testCollectTriplesBasic() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - - Session session = driver.session(); - Result results = session.run("CALL n10s.rdf.stream.inline('"+ TURTLE_FRAGMENT +"', 'Turtle') " + - " yield subject, predicate, object, isLiteral, literalType, literalLang " - + " return n10s.rdf.collect(subject, predicate, object, isLiteral, literalType, literalLang) as rdf"); - assertEquals(true, results.hasNext()); - assertTrue(ModelTestUtils - .compareModels(results.next().get("rdf").asString(), - RDFFormat.NTRIPLES,TURTLE_FRAGMENT,RDFFormat.TURTLE)); - + @BeforeClass + public static void init() { + driver = GraphDatabase.driver(neo4j.boltURI(), + Config.builder().withoutEncryption().build()); + } + @Before + public void cleanDatabase() { + driver.session().run("match (n) detach delete n").consume(); + driver.session().run("drop constraint n10s_unique_uri if exists").consume(); + } - } + @Test + public void testCollectTriplesBasic() throws Exception { + Session session = driver.session(); + Result results = session.run("CALL n10s.rdf.stream.inline('"+ TURTLE_FRAGMENT +"', 'Turtle') " + + " yield subject, predicate, object, isLiteral, literalType, literalLang " + + " return n10s.rdf.collect(subject, predicate, object, isLiteral, literalType, literalLang) as rdf"); + assertEquals(true, results.hasNext()); + assertTrue(ModelTestUtils + .compareModels(results.next().get("rdf").asString(), + RDFFormat.NTRIPLES,TURTLE_FRAGMENT,RDFFormat.TURTLE)); } @Test public void testCollectTriplesPostFilter() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - - Session session = driver.session(); - Result results = session.run( - "call n10s.rdf.stream.fetch('" + CollectTriplesTest.class.getClassLoader() - .getResource("100k.nt") - .toURI() + "',\"N-Triples\" ,{ limit: 999999}) yield subject, predicate, object\n" + - "where predicate = \"http://www.w3.org/2004/02/skos/core#prefLabel\" and " + - "object contains \"Business Administration and Finance\"\n" + - "with collect(subject) as indivList \n" + - "call n10s.rdf.stream.fetch('"+ CollectTriplesTest.class.getClassLoader() - .getResource("100k.nt") - .toURI() + "',\"N-Triples\" ,{ limit: 999999}) yield subject, predicate, object, isLiteral, literalType, literalLang\n" + - "where subject in indivList\n" + - "return n10s.rdf.collect(subject, predicate, object, isLiteral, literalType, literalLang) as rdf"); - assertEquals(true, results.hasNext()); - assertTrue(ModelTestUtils - .compareModels(results.next().get("rdf").asString(), - RDFFormat.NTRIPLES,TURTLE_FRAGMENT_2,RDFFormat.TURTLE)); - - - - } + Session session = driver.session(); + Result results = session.run( + "call n10s.rdf.stream.fetch('" + CollectTriplesTest.class.getClassLoader() + .getResource("100k.nt") + .toURI() + "',\"N-Triples\" ,{ limit: 999999}) yield subject, predicate, object\n" + + "where predicate = \"http://www.w3.org/2004/02/skos/core#prefLabel\" and " + + "object contains \"Business Administration and Finance\"\n" + + "with collect(subject) as indivList \n" + + "call n10s.rdf.stream.fetch('"+ CollectTriplesTest.class.getClassLoader() + .getResource("100k.nt") + .toURI() + "',\"N-Triples\" ,{ limit: 999999}) yield subject, predicate, object, isLiteral, literalType, literalLang\n" + + "where subject in indivList\n" + + "return n10s.rdf.collect(subject, predicate, object, isLiteral, literalType, literalLang) as rdf"); + assertEquals(true, results.hasNext()); + assertTrue(ModelTestUtils + .compareModels(results.next().get("rdf").asString(), + RDFFormat.NTRIPLES,TURTLE_FRAGMENT_2,RDFFormat.TURTLE)); } @Test public void testCollectTriplesDataTypes() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { + Session session = driver.session(); + Result results = session.run("CALL n10s.rdf.stream.fetch('"+ CollectTriplesTest.class.getClassLoader() + .getResource("datetime/datetime-and-other.ttl") + .toURI() +"', 'Turtle') " + + " yield subject, predicate, object, isLiteral, literalType, literalLang " + + " return n10s.rdf.collect(subject, predicate, object, isLiteral, literalType, literalLang) as rdf"); + assertEquals(true, results.hasNext()); - Session session = driver.session(); - Result results = session.run("CALL n10s.rdf.stream.fetch('"+ CollectTriplesTest.class.getClassLoader() - .getResource("datetime/datetime-and-other.ttl") - .toURI() +"', 'Turtle') " + - " yield subject, predicate, object, isLiteral, literalType, literalLang " - + " return n10s.rdf.collect(subject, predicate, object, isLiteral, literalType, literalLang) as rdf"); - assertEquals(true, results.hasNext()); + String fileAsString = new String ( Files.readAllBytes( Paths.get(CollectTriplesTest.class.getClassLoader() + .getResource("datetime/datetime-and-other.ttl").toURI()) ) ); - String fileAsString = new String ( Files.readAllBytes( Paths.get(CollectTriplesTest.class.getClassLoader() - .getResource("datetime/datetime-and-other.ttl").toURI()) ) ); - - assertTrue(ModelTestUtils - .compareModels(results.next().get("rdf").asString(), - RDFFormat.NTRIPLES, fileAsString,RDFFormat.TURTLE)); - } - } + assertTrue(ModelTestUtils + .compareModels(results.next().get("rdf").asString(), + RDFFormat.NTRIPLES, fileAsString,RDFFormat.TURTLE)); +} @Test public void testCollectTriplesDataTypesTurtle() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { + Session session = driver.session(); + Result results = session.run("CALL n10s.rdf.stream.fetch('"+ CollectTriplesTest.class.getClassLoader() + .getResource("datetime/datetime-and-other.ttl") + .toURI() +"', 'Turtle') " + + " yield subject, predicate, object, isLiteral, literalType, literalLang " + + " return n10s.rdf.collect.ttl(subject, predicate, object, isLiteral, literalType, literalLang) as rdf"); + assertEquals(true, results.hasNext()); - Session session = driver.session(); - Result results = session.run("CALL n10s.rdf.stream.fetch('"+ CollectTriplesTest.class.getClassLoader() - .getResource("datetime/datetime-and-other.ttl") - .toURI() +"', 'Turtle') " + - " yield subject, predicate, object, isLiteral, literalType, literalLang " - + " return n10s.rdf.collect.ttl(subject, predicate, object, isLiteral, literalType, literalLang) as rdf"); - assertEquals(true, results.hasNext()); + String fileAsString = new String ( Files.readAllBytes( Paths.get(CollectTriplesTest.class.getClassLoader() + .getResource("datetime/datetime-and-other.ttl").toURI()) ) ); - String fileAsString = new String ( Files.readAllBytes( Paths.get(CollectTriplesTest.class.getClassLoader() - .getResource("datetime/datetime-and-other.ttl").toURI()) ) ); + assertTrue(ModelTestUtils + .compareModels(results.next().get("rdf").asString(), + RDFFormat.TURTLE, fileAsString,RDFFormat.TURTLE)); - assertTrue(ModelTestUtils - .compareModels(results.next().get("rdf").asString(), - RDFFormat.TURTLE, fileAsString,RDFFormat.TURTLE)); - } } @Test diff --git a/src/test/java/n10s/aux/AuxProceduresTest.java b/src/test/java/n10s/aux/AuxProceduresTest.java index ae6cad67..0375500e 100644 --- a/src/test/java/n10s/aux/AuxProceduresTest.java +++ b/src/test/java/n10s/aux/AuxProceduresTest.java @@ -1,8 +1,13 @@ package n10s.aux; +import n10s.graphconfig.GraphConfigProcedures; +import n10s.nsprefixes.NsPrefixDefProcedures; +import n10s.rdf.aggregate.CollectTriples; +import n10s.rdf.export.RDFExportProcedures; +import n10s.rdf.load.RDFLoadProcedures; +import n10s.rdf.stream.RDFStreamProcedures; import org.eclipse.rdf4j.model.vocabulary.XMLSchema; -import org.junit.Rule; -import org.junit.Test; +import org.junit.*; import org.neo4j.driver.*; import org.neo4j.driver.Record; import org.neo4j.harness.junit.rule.Neo4jRule; @@ -10,100 +15,112 @@ import static org.junit.Assert.*; public class AuxProceduresTest { - @Rule - public Neo4jRule neo4j = new Neo4jRule().withFunction(AuxProcedures.class); + public static Driver driver; + + @ClassRule + public static Neo4jRule neo4j = new Neo4jRule() + .withFunction(AuxProcedures.class); + + @BeforeClass + public static void init() { + driver = GraphDatabase.driver(neo4j.boltURI(), + Config.builder().withoutEncryption().build()); + } + + @Before + public void cleanDatabase() { + driver.session().run("match (n) detach delete n").consume(); + driver.session().run("drop constraint n10s_unique_uri if exists"); + } @Test public void testAddNamespacePrefixInitial() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { - - Result res = session.run("RETURN n10s.aux.dt.check('" + XMLSchema.DATETIME.stringValue() + "',datetime()) as yes," + - "n10s.aux.dt.check('"+ WKTLITERAL_URI.stringValue() +"',datetime()) as no1," + - "n10s.aux.dt.check('" + XMLSchema.DATE.stringValue() + "',datetime()) as no2," + - "n10s.aux.dt.check('" + XMLSchema.TIME.stringValue() +"',datetime()) as no3"); - assertTrue(res.hasNext()); - Record record = res.next(); - assertTrue(record.get("yes").asBoolean()); - assertFalse(record.get("no1").asBoolean()); - assertFalse(record.get("no2").asBoolean()); - assertFalse(record.get("no3").asBoolean()); - - res = session.run("RETURN n10s.aux.dt.check('" + WKTLITERAL_URI.stringValue() + "',point({x: -0.1275, y: 51.507222222})) as yes," + - "n10s.aux.dt.check('" + XMLSchema.DATETIME.stringValue() + "',point({x: -0.1275, y: 51.507222222})) as no1," + - "n10s.aux.dt.check('" + XMLSchema.DATE.stringValue() + "',point({x: -0.1275, y: 51.507222222})) as no2," + - "n10s.aux.dt.check('" + XMLSchema.TIME.stringValue() + "',point({x: -0.1275, y: 51.507222222})) as no3"); - assertTrue(res.hasNext()); - record = res.next(); - assertTrue(record.get("yes").asBoolean()); - assertFalse(record.get("no1").asBoolean()); - assertFalse(record.get("no2").asBoolean()); - assertFalse(record.get("no3").asBoolean()); - - res = session.run("RETURN n10s.aux.dt.check('" + WKTLITERAL_URI.stringValue() + "',45) as no0," + - "n10s.aux.dt.check('" + XMLSchema.DATETIME.stringValue() + "',point({x: -0.1275, y: 51.507222222})) as no1," + - "n10s.aux.dt.check('" + XMLSchema.DATE.stringValue() + "',point({x: -0.1275, y: 51.507222222})) as no2," + - "n10s.aux.dt.check('" + XMLSchema.TIME.stringValue() + "',point({x: -0.1275, y: 51.507222222})) as no3"); - assertTrue(res.hasNext()); - record = res.next(); - assertFalse(record.get("no0").asBoolean()); - assertFalse(record.get("no1").asBoolean()); - assertFalse(record.get("no2").asBoolean()); - assertFalse(record.get("no3").asBoolean()); - - res = session.run("RETURN n10s.aux.dt.check('" + WKTLITERAL_URI.stringValue() + "',true) as no0," + - "n10s.aux.dt.check('" + XMLSchema.DATETIME.stringValue() + "',point({x: -0.1275, y: 51.507222222})) as no1," + - "n10s.aux.dt.check('" + XMLSchema.DATE.stringValue() + "',point({x: -0.1275, y: 51.507222222})) as no2," + - "n10s.aux.dt.check('" + XMLSchema.TIME.stringValue() + "',point({x: -0.1275, y: 51.507222222})) as no3"); - assertTrue(res.hasNext()); - record = res.next(); - assertFalse(record.get("no0").asBoolean()); - assertFalse(record.get("no1").asBoolean()); - assertFalse(record.get("no2").asBoolean()); - assertFalse(record.get("no3").asBoolean()); - - res = session.run("RETURN n10s.aux.dt.check('" + WKTLITERAL_URI.stringValue() + "',44.56) as no0," + - "n10s.aux.dt.check('" + XMLSchema.DATETIME.stringValue() + "',point({x: -0.1275, y: 51.507222222})) as no1," + - "n10s.aux.dt.check('" + XMLSchema.DATE.stringValue() + "',point({x: -0.1275, y: 51.507222222})) as no2," + - "n10s.aux.dt.check('" + XMLSchema.TIME.stringValue() + "',point({x: -0.1275, y: 51.507222222})) as no3"); - assertTrue(res.hasNext()); - record = res.next(); - assertFalse(record.get("no0").asBoolean()); - assertFalse(record.get("no1").asBoolean()); - assertFalse(record.get("no2").asBoolean()); - assertFalse(record.get("no3").asBoolean()); - - res = session.run("RETURN n10s.aux.dt.check('" + XMLSchema.ANYURI.stringValue() + "',44.56) as no0," + - "n10s.aux.dt.check('" + XMLSchema.ANYURI.stringValue() + "',point({x: -0.1275, y: 51.507222222})) as no1," + - "n10s.aux.dt.check('" + XMLSchema.ANYURI.stringValue() + "','this is a string') as no2," + - "n10s.aux.dt.check('" + XMLSchema.ANYURI.stringValue() + "','neo4j://home.voc/123#something') as yes"); - assertTrue(res.hasNext()); - record = res.next(); - assertFalse(record.get("no0").asBoolean()); - assertFalse(record.get("no1").asBoolean()); - assertFalse(record.get("no2").asBoolean()); - assertTrue(record.get("yes").asBoolean()); - - session.run("CREATE (:Thing { dt: date(), dtm: datetime(), zdt: datetime('1956-06-25T09:00:00[Europe/Berlin]')," + - "theint: 45, thebo: false, flo: 4.567, po: point({x: -0.1275, y: 51.507222222, z: 44 }), " + - "uri: 'mail://somet hing.io#123'})"); - - assertEquals(1L,session.run("MATCH (t:Thing) RETURN count(t) as thingcount").next().get("thingcount").asInt()); - - res = session.run("MATCH (t:Thing) RETURN n10s.aux.dt.check('" + WKTLITERAL_URI.stringValue() + "',t.zdt) as no1," + - "n10s.aux.dt.check('" + XMLSchema.DATETIME.stringValue() + "',t.zdt) as yes," + - "n10s.aux.dt.check('" + XMLSchema.DATE.stringValue() + "',t.zdt) as no2," + - "n10s.aux.dt.check('" + XMLSchema.TIME.stringValue() + "',t.zdt) as no3," + - "n10s.aux.dt.check('" + XMLSchema.ANYURI.stringValue() + "',t.uri) as no4"); - assertTrue(res.hasNext()); - record = res.next(); - assertTrue(record.get("yes").asBoolean()); - assertFalse(record.get("no1").asBoolean()); - assertFalse(record.get("no2").asBoolean()); - assertFalse(record.get("no3").asBoolean()); - assertFalse(record.get("no4").asBoolean()); - - - } + Session session = driver.session(); + + Result res = session.run("RETURN n10s.aux.dt.check('" + XMLSchema.DATETIME.stringValue() + "',datetime()) as yes," + + "n10s.aux.dt.check('"+ WKTLITERAL_URI.stringValue() +"',datetime()) as no1," + + "n10s.aux.dt.check('" + XMLSchema.DATE.stringValue() + "',datetime()) as no2," + + "n10s.aux.dt.check('" + XMLSchema.TIME.stringValue() +"',datetime()) as no3"); + assertTrue(res.hasNext()); + Record record = res.next(); + assertTrue(record.get("yes").asBoolean()); + assertFalse(record.get("no1").asBoolean()); + assertFalse(record.get("no2").asBoolean()); + assertFalse(record.get("no3").asBoolean()); + + res = session.run("RETURN n10s.aux.dt.check('" + WKTLITERAL_URI.stringValue() + "',point({x: -0.1275, y: 51.507222222})) as yes," + + "n10s.aux.dt.check('" + XMLSchema.DATETIME.stringValue() + "',point({x: -0.1275, y: 51.507222222})) as no1," + + "n10s.aux.dt.check('" + XMLSchema.DATE.stringValue() + "',point({x: -0.1275, y: 51.507222222})) as no2," + + "n10s.aux.dt.check('" + XMLSchema.TIME.stringValue() + "',point({x: -0.1275, y: 51.507222222})) as no3"); + assertTrue(res.hasNext()); + record = res.next(); + assertTrue(record.get("yes").asBoolean()); + assertFalse(record.get("no1").asBoolean()); + assertFalse(record.get("no2").asBoolean()); + assertFalse(record.get("no3").asBoolean()); + + res = session.run("RETURN n10s.aux.dt.check('" + WKTLITERAL_URI.stringValue() + "',45) as no0," + + "n10s.aux.dt.check('" + XMLSchema.DATETIME.stringValue() + "',point({x: -0.1275, y: 51.507222222})) as no1," + + "n10s.aux.dt.check('" + XMLSchema.DATE.stringValue() + "',point({x: -0.1275, y: 51.507222222})) as no2," + + "n10s.aux.dt.check('" + XMLSchema.TIME.stringValue() + "',point({x: -0.1275, y: 51.507222222})) as no3"); + assertTrue(res.hasNext()); + record = res.next(); + assertFalse(record.get("no0").asBoolean()); + assertFalse(record.get("no1").asBoolean()); + assertFalse(record.get("no2").asBoolean()); + assertFalse(record.get("no3").asBoolean()); + + res = session.run("RETURN n10s.aux.dt.check('" + WKTLITERAL_URI.stringValue() + "',true) as no0," + + "n10s.aux.dt.check('" + XMLSchema.DATETIME.stringValue() + "',point({x: -0.1275, y: 51.507222222})) as no1," + + "n10s.aux.dt.check('" + XMLSchema.DATE.stringValue() + "',point({x: -0.1275, y: 51.507222222})) as no2," + + "n10s.aux.dt.check('" + XMLSchema.TIME.stringValue() + "',point({x: -0.1275, y: 51.507222222})) as no3"); + assertTrue(res.hasNext()); + record = res.next(); + assertFalse(record.get("no0").asBoolean()); + assertFalse(record.get("no1").asBoolean()); + assertFalse(record.get("no2").asBoolean()); + assertFalse(record.get("no3").asBoolean()); + + res = session.run("RETURN n10s.aux.dt.check('" + WKTLITERAL_URI.stringValue() + "',44.56) as no0," + + "n10s.aux.dt.check('" + XMLSchema.DATETIME.stringValue() + "',point({x: -0.1275, y: 51.507222222})) as no1," + + "n10s.aux.dt.check('" + XMLSchema.DATE.stringValue() + "',point({x: -0.1275, y: 51.507222222})) as no2," + + "n10s.aux.dt.check('" + XMLSchema.TIME.stringValue() + "',point({x: -0.1275, y: 51.507222222})) as no3"); + assertTrue(res.hasNext()); + record = res.next(); + assertFalse(record.get("no0").asBoolean()); + assertFalse(record.get("no1").asBoolean()); + assertFalse(record.get("no2").asBoolean()); + assertFalse(record.get("no3").asBoolean()); + + res = session.run("RETURN n10s.aux.dt.check('" + XMLSchema.ANYURI.stringValue() + "',44.56) as no0," + + "n10s.aux.dt.check('" + XMLSchema.ANYURI.stringValue() + "',point({x: -0.1275, y: 51.507222222})) as no1," + + "n10s.aux.dt.check('" + XMLSchema.ANYURI.stringValue() + "','this is a string') as no2," + + "n10s.aux.dt.check('" + XMLSchema.ANYURI.stringValue() + "','neo4j://home.voc/123#something') as yes"); + assertTrue(res.hasNext()); + record = res.next(); + assertFalse(record.get("no0").asBoolean()); + assertFalse(record.get("no1").asBoolean()); + assertFalse(record.get("no2").asBoolean()); + assertTrue(record.get("yes").asBoolean()); + + session.run("CREATE (:Thing { dt: date(), dtm: datetime(), zdt: datetime('1956-06-25T09:00:00[Europe/Berlin]')," + + "theint: 45, thebo: false, flo: 4.567, po: point({x: -0.1275, y: 51.507222222, z: 44 }), " + + "uri: 'mail://somet hing.io#123'})"); + + assertEquals(1L,session.run("MATCH (t:Thing) RETURN count(t) as thingcount").next().get("thingcount").asInt()); + + res = session.run("MATCH (t:Thing) RETURN n10s.aux.dt.check('" + WKTLITERAL_URI.stringValue() + "',t.zdt) as no1," + + "n10s.aux.dt.check('" + XMLSchema.DATETIME.stringValue() + "',t.zdt) as yes," + + "n10s.aux.dt.check('" + XMLSchema.DATE.stringValue() + "',t.zdt) as no2," + + "n10s.aux.dt.check('" + XMLSchema.TIME.stringValue() + "',t.zdt) as no3," + + "n10s.aux.dt.check('" + XMLSchema.ANYURI.stringValue() + "',t.uri) as no4"); + assertTrue(res.hasNext()); + record = res.next(); + assertTrue(record.get("yes").asBoolean()); + assertFalse(record.get("no1").asBoolean()); + assertFalse(record.get("no2").asBoolean()); + assertFalse(record.get("no3").asBoolean()); + assertFalse(record.get("no4").asBoolean()); + } } diff --git a/src/test/java/n10s/endpoint/RDFEndpointTest.java b/src/test/java/n10s/endpoint/RDFEndpointTest.java index cdb736dd..ce7f40f0 100644 --- a/src/test/java/n10s/endpoint/RDFEndpointTest.java +++ b/src/test/java/n10s/endpoint/RDFEndpointTest.java @@ -14,6 +14,7 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; +import java.text.MessageFormat; import java.util.*; import n10s.ModelTestUtils; @@ -24,15 +25,17 @@ import n10s.quadrdf.delete.QuadRDFDeleteProcedures; import n10s.quadrdf.load.QuadRDFLoadProcedures; import n10s.rdf.RDFProcedures; +import n10s.rdf.aggregate.CollectTriples; import n10s.rdf.delete.RDFDeleteProcedures; import n10s.rdf.export.ExportProcessor; import n10s.rdf.export.RDFExportProcedures; import n10s.rdf.load.RDFLoadProcedures; +import n10s.rdf.stream.RDFStreamProcedures; import n10s.validation.ValidationProcedures; import org.eclipse.rdf4j.model.vocabulary.RDF; +import org.eclipse.rdf4j.query.algebra.Str; import org.eclipse.rdf4j.rio.RDFFormat; -import org.junit.Rule; -import org.junit.Test; +import org.junit.*; import org.neo4j.driver.Config; import org.neo4j.driver.Driver; import org.neo4j.driver.GraphDatabase; @@ -51,23 +54,52 @@ */ public class RDFEndpointTest { - @Rule - public Neo4jRule neo4j = new Neo4jRule().withUnmanagedExtension("/rdf", RDFEndpoint.class) - .withProcedure(RDFLoadProcedures.class) - .withProcedure(QuadRDFLoadProcedures.class) - .withProcedure(QuadRDFDeleteProcedures.class) - .withFunction(RDFProcedures.class) - .withProcedure(MappingUtils.class) - .withProcedure(GraphConfigProcedures.class) - .withProcedure(RDFDeleteProcedures.class) - .withProcedure(OntoLoadProcedures.class) - .withProcedure(NsPrefixDefProcedures.class) - .withProcedure(ValidationProcedures.class) - .withProcedure(RDFExportProcedures.class); - - @Rule - public Neo4jRule temp = new Neo4jRule().withProcedure(RDFLoadProcedures.class) - .withProcedure(GraphConfigProcedures.class); + public static Driver driver; + public static GraphDatabaseService graphDatabaseService; + public static GraphDatabaseService tempGDBs; + public static Driver tempDriver; + + @ClassRule + public static Neo4jRule neo4j = new Neo4jRule().withUnmanagedExtension("/rdf", RDFEndpoint.class) + .withProcedure(RDFLoadProcedures.class) + .withProcedure(QuadRDFLoadProcedures.class) + .withProcedure(QuadRDFDeleteProcedures.class) + .withFunction(RDFProcedures.class) + .withProcedure(MappingUtils.class) + .withProcedure(GraphConfigProcedures.class) + .withProcedure(RDFDeleteProcedures.class) + .withProcedure(OntoLoadProcedures.class) + .withProcedure(NsPrefixDefProcedures.class) + .withProcedure(ValidationProcedures.class) + .withProcedure(RDFExportProcedures.class); + + @ClassRule + public static Neo4jRule temp = new Neo4jRule() + .withProcedure(RDFLoadProcedures.class) + .withProcedure(GraphConfigProcedures.class); + @BeforeClass + public static void init() { + driver = GraphDatabase.driver(neo4j.boltURI(), + Config.builder().withoutEncryption().build()); + + tempDriver = GraphDatabase.driver(temp.boltURI(), + Config.builder().withoutEncryption().build()); + } + @Before + public void cleanDatabase() { + driver.session().run("match (n) detach delete n").consume(); + driver.session().run("drop constraint n10s_unique_uri if exists").consume(); + driver.session().run("drop index uri_index if exists").consume(); + + + tempDriver.session().run("match (n) detach delete n").consume(); + tempDriver.session().run("drop constraint n10s_unique_uri if exists").consume(); + tempDriver.session().run("drop index uri_index if exists").consume(); + + graphDatabaseService = neo4j.defaultDatabaseService(); + tempGDBs = temp.defaultDatabaseService(); + } + private static final ObjectMapper jsonMapper = new ObjectMapper(); @@ -82,8 +114,6 @@ public class RDFEndpointTest { @Test public void testGetNodeById() throws Exception { - // Given - final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); try (Transaction tx = graphDatabaseService.beginTx()) { String ontoCreation = "MERGE (p:Category {catName: ' Person'})\n" + @@ -104,7 +134,6 @@ public void testGetNodeById() throws Exception { "CREATE (Hugo)<-[:FRIEND_OF]-(Carrie)"; tx.execute(dataInsertion); tx.commit(); - } // When @@ -112,7 +141,14 @@ public void testGetNodeById() throws Exception { try (Transaction tx = graphDatabaseService.beginTx()) { Result result = tx.execute("MATCH (n:Critic) RETURN id(n) AS id "); id = (Long) result.next().get("id"); - assertEquals(Long.valueOf(7), id); + assertNotNull(id); + } + + Map nameToId = new HashMap<>(); + try (Transaction tx = graphDatabaseService.beginTx()) { + tx.execute("match (n) return n.name as name, id(n) as id") + .stream() + .forEach(r -> nameToId.put((String) r.get("name"), String.format("#%s", (Long)r.get("id")) )); } // When @@ -120,16 +156,16 @@ public void testGetNodeById() throws Exception { HTTP.GET(neo4j.httpURI().resolve("rdf").toString()).location() + "neo4j/describe/" + id.toString()); - String expected = "[ {\n" - + " \"@id\" : \"neo4j://graph.individuals#5\",\n" + String expected = String.format("[ {\n" + + " \"@id\" : \"neo4j://graph.individuals%1$s\",\n" + " \"neo4j://graph.schema#FRIEND_OF\" : [ {\n" - + " \"@id\" : \"neo4j://graph.individuals#7\"\n" + + " \"@id\" : \"neo4j://graph.individuals%2$s\"\n" + " } ]\n" + "}, {\n" - + " \"@id\" : \"neo4j://graph.individuals#7\",\n" + + " \"@id\" : \"neo4j://graph.individuals%2$s\",\n" + " \"@type\" : [ \"neo4j://graph.schema#Critic\" ],\n" + " \"neo4j://graph.schema#WORKS_WITH\" : [ {\n" - + " \"@id\" : \"neo4j://graph.individuals#8\"\n" + + " \"@id\" : \"neo4j://graph.individuals%3$s\"\n" + " } ],\n" + " \"neo4j://graph.schema#born\" : [ {\n" + " \"@type\" : \"http://www.w3.org/2001/XMLSchema#long\",\n" @@ -138,7 +174,11 @@ public void testGetNodeById() throws Exception { + " \"neo4j://graph.schema#name\" : [ {\n" + " \"@value\" : \"Hugo Weaving\"\n" + " } ]\n" - + "} ]"; + + "} ]", + nameToId.get("Carrie-Anne Moss"), + nameToId.get("Hugo Weaving"), + nameToId.get("Andy Wachowski") + ); assertEquals(200, response.status()); assertTrue(ModelTestUtils .compareModels(expected, RDFFormat.JSONLD, response.rawContent(), RDFFormat.JSONLD)); @@ -172,8 +212,6 @@ public void testGetNodeById() throws Exception { @Test public void testGetNodeByIdFromRDFizedLPG() throws Exception { - // Given - final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); try (Transaction tx = graphDatabaseService.beginTx()) { String configCreation = "CALL n10s.graphconfig.init({handleVocabUris:'IGNORE'}) "; @@ -241,8 +279,6 @@ public void testGetNodeByIdFromRDFizedLPG() throws Exception { @Test public void testCypherCgnt() throws Exception { - // Given - final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); try (Transaction tx = graphDatabaseService.beginTx()) { tx.execute("UNWIND RANGE(1,5,1) as id\n" + @@ -259,8 +295,18 @@ public void testCypherCgnt() throws Exception { tx.commit(); } + String cableid; + String crpid; + try (Transaction tx = graphDatabaseService.beginTx()) { + Result result = tx.execute("match (c:Cable{ id: 4 })--(crp:CableRoutingPoint{id: 2 }) " + + " return id(c) as cableid, id(crp) as crpid "); + Map record = result.next(); + cableid = record.get("cableid").toString(); + crpid = record.get("crpid").toString(); + } + Map map = new HashMap<>(); - map.put("cypher", "MATCH s = ()--() RETURN s"); + map.put("cypher", "MATCH s = (:Cable{id: 4 })--(:CableRoutingPoint{id: 2 }) RETURN s"); map.put("format", "Turtle-star"); Response response = HTTP.withHeaders("Accept", "text/plain").POST( @@ -269,136 +315,21 @@ public void testCypherCgnt() throws Exception { String expected = "@prefix n4sch: .\n" + "@prefix n4ind: .\n" + "\n" + - "n4ind:3 a n4sch:CableRoutingPoint;\n" + - " n4sch:id \"2\"^^;\n" + - " n4sch:inspectionDates \"2019-04-05T12:34:00+02:00\"^^,\n" + - " \"2018-04-05T12:34:00+02:00\"^^, \"2020-04-05T12:34:00+02:00\"^^;\n" + - " n4sch:typeCodes \"C\", \"B\", \"A\";\n" + - " n4sch:location \"Point(-0.1275 51.507222222)\"^^ .\n" + - "\n" + - "n4ind:0 a n4sch:Cable;\n" + - " n4sch:id \"1\"^^;\n" + - " n4sch:HAS_ROUTING_POINT n4ind:3, n4ind:1;\n" + - " n4sch:createdAt \"2017-04-05T12:34:00+02:00\"^^;\n" + - " n4sch:name \"cable_1\" .\n" + - "\n" + - "<> n4sch:createdAt \"2018-04-05T12:34:00+02:00\"^^;\n" + - " n4sch:labels \"bar\", \"foo\" .\n" + - "\n" + - "n4ind:1 a n4sch:CableRoutingPoint;\n" + - " n4sch:id \"1\"^^;\n" + - " n4sch:inspectionDates \"2019-04-05T12:34:00+02:00\"^^,\n" + - " \"2018-04-05T12:34:00+02:00\"^^, \"2020-04-05T12:34:00+02:00\"^^;\n" + - " n4sch:location \"Point(-0.1275 51.507222222)\"^^;\n" + - " n4sch:typeCodes \"A\", \"B\", \"C\" .\n" + - "\n" + - "<> n4sch:labels \"bar\", \"foo\";\n" + - " n4sch:createdAt \"2018-04-05T12:34:00+02:00\"^^ .\n" + - "\n" + - "<> n4sch:labels \"foo\", \"bar\";\n" + - " n4sch:createdAt \"2018-04-05T12:34:00+02:00\"^^ .\n" + - "\n" + - "n4ind:6 a n4sch:CableRoutingPoint;\n" + - " n4sch:inspectionDates \"2019-04-05T12:34:00+02:00\"^^,\n" + - " \"2020-04-05T12:34:00+02:00\"^^, \"2018-04-05T12:34:00+02:00\"^^;\n" + - " n4sch:location \"Point(-0.1275 51.507222222)\"^^;\n" + - " n4sch:typeCodes \"B\", \"A\", \"C\";\n" + - " n4sch:id \"2\"^^ .\n" + - "\n" + - "n4ind:2 a n4sch:Cable;\n" + - " n4sch:id \"2\"^^;\n" + - " n4sch:createdAt \"2017-04-05T12:34:00+02:00\"^^;\n" + - " n4sch:HAS_ROUTING_POINT n4ind:6, n4ind:4;\n" + - " n4sch:name \"cable_2\" .\n" + - "\n" + - "n4ind:4 a n4sch:CableRoutingPoint;\n" + - " n4sch:inspectionDates \"2019-04-05T12:34:00+02:00\"^^,\n" + - " \"2018-04-05T12:34:00+02:00\"^^, \"2020-04-05T12:34:00+02:00\"^^;\n" + - " n4sch:id \"1\"^^;\n" + - " n4sch:typeCodes \"C\", \"A\", \"B\";\n" + - " n4sch:location \"Point(-0.1275 51.507222222)\"^^ .\n" + - "\n" + - "<> n4sch:labels \"bar\", \"foo\";\n" + - " n4sch:createdAt \"2018-04-05T12:34:00+02:00\"^^ .\n" + - "\n" + - "n4ind:7 a n4sch:CableRoutingPoint;\n" + - " n4sch:inspectionDates \"2019-04-05T12:34:00+02:00\"^^,\n" + - " \"2018-04-05T12:34:00+02:00\"^^, \"2020-04-05T12:34:00+02:00\"^^;\n" + - " n4sch:typeCodes \"A\", \"C\", \"B\";\n" + - " n4sch:location \"Point(-0.1275 51.507222222)\"^^;\n" + - " n4sch:id \"1\"^^ .\n" + - "\n" + - "<> n4sch:labels \"foo\", \"bar\";\n" + - " n4sch:createdAt \"2018-04-05T12:34:00+02:00\"^^ .\n" + - "\n" + - "n4ind:5 a n4sch:Cable;\n" + - " n4sch:createdAt \"2017-04-05T12:34:00+02:00\"^^;\n" + - " n4sch:HAS_ROUTING_POINT n4ind:7, n4ind:9;\n" + - " n4sch:id \"3\"^^;\n" + - " n4sch:name \"cable_3\" .\n" + - "\n" + - "<> n4sch:labels \"foo\", \"bar\";\n" + - " n4sch:createdAt \"2018-04-05T12:34:00+02:00\"^^ .\n" + - "\n" + - "n4ind:9 a n4sch:CableRoutingPoint;\n" + - " n4sch:inspectionDates \"2018-04-05T12:34:00+02:00\"^^,\n" + - " \"2019-04-05T12:34:00+02:00\"^^, \"2020-04-05T12:34:00+02:00\"^^;\n" + - " n4sch:id \"2\"^^;\n" + - " n4sch:typeCodes \"A\", \"B\", \"C\";\n" + - " n4sch:location \"Point(-0.1275 51.507222222)\"^^ .\n" + - "\n" + - "n4ind:8 a n4sch:Cable;\n" + + "n4ind:" + cableid + " a n4sch:Cable;\n" + " n4sch:name \"cable_4\";\n" + " n4sch:createdAt \"2017-04-05T12:34:00+02:00\"^^;\n" + " n4sch:id \"4\"^^;\n" + - " n4sch:HAS_ROUTING_POINT n4ind:12, n4ind:10 .\n" + + " n4sch:HAS_ROUTING_POINT n4ind:" + crpid + " .\n" + "\n" + - "n4ind:12 a n4sch:CableRoutingPoint;\n" + + "n4ind:" + crpid + " a n4sch:CableRoutingPoint;\n" + " n4sch:inspectionDates \"2019-04-05T12:34:00+02:00\"^^,\n" + " \"2020-04-05T12:34:00+02:00\"^^, \"2018-04-05T12:34:00+02:00\"^^;\n" + " n4sch:id \"2\"^^;\n" + " n4sch:typeCodes \"A\", \"B\", \"C\";\n" + " n4sch:location \"Point(-0.1275 51.507222222)\"^^ .\n" + - "\n" + - "<> n4sch:labels \"bar\", \"foo\";\n" + + "<> n4sch:labels \"bar\", \"foo\";\n" + " n4sch:createdAt \"2018-04-05T12:34:00+02:00\"^^ .\n" + - "\n" + - "n4ind:10 a n4sch:CableRoutingPoint;\n" + - " n4sch:inspectionDates \"2019-04-05T12:34:00+02:00\"^^,\n" + - " \"2020-04-05T12:34:00+02:00\"^^, \"2018-04-05T12:34:00+02:00\"^^;\n" + - " n4sch:id \"1\"^^;\n" + - " n4sch:typeCodes \"A\", \"C\", \"B\";\n" + - " n4sch:location \"Point(-0.1275 51.507222222)\"^^ .\n" + - "\n" + - "<> n4sch:labels \"bar\", \"foo\";\n" + - " n4sch:createdAt \"2018-04-05T12:34:00+02:00\"^^ .\n" + - "\n" + - "n4ind:13 a n4sch:CableRoutingPoint;\n" + - " n4sch:inspectionDates \"2019-04-05T12:34:00+02:00\"^^,\n" + - " \"2020-04-05T12:34:00+02:00\"^^, \"2018-04-05T12:34:00+02:00\"^^;\n" + - " n4sch:id \"1\"^^;\n" + - " n4sch:typeCodes \"A\", \"B\", \"C\";\n" + - " n4sch:location \"Point(-0.1275 51.507222222)\"^^ .\n" + - "\n" + - "n4ind:11 a n4sch:Cable;\n" + - " n4sch:id \"5\"^^;\n" + - " n4sch:HAS_ROUTING_POINT n4ind:13, n4ind:14;\n" + - " n4sch:name \"cable_5\";\n" + - " n4sch:createdAt \"2017-04-05T12:34:00+02:00\"^^ .\n" + - "\n" + - "<> n4sch:labels \"foo\", \"bar\";\n" + - " n4sch:createdAt \"2018-04-05T12:34:00+02:00\"^^ .\n" + - "\n" + - "n4ind:14 a n4sch:CableRoutingPoint;\n" + - " n4sch:inspectionDates \"2019-04-05T12:34:00+02:00\"^^,\n" + - " \"2020-04-05T12:34:00+02:00\"^^, \"2018-04-05T12:34:00+02:00\"^^;\n" + - " n4sch:id \"2\"^^;\n" + - " n4sch:typeCodes \"C\", \"B\", \"A\";\n" + - " n4sch:location \"Point(-0.1275 51.507222222)\"^^ .\n" + - "\n" + - "<> n4sch:labels \"foo\", \"bar\";\n" + - " n4sch:createdAt \"2018-04-05T12:34:00+02:00\"^^ .\n" + - "\n"; + "\n" ; assertEquals(200, response.status()); assertTrue(ModelTestUtils @@ -408,8 +339,6 @@ public void testCypherCgnt() throws Exception { @Test public void testCypherReturnsList() throws Exception { - // Given - final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); try (Transaction tx = graphDatabaseService.beginTx()) { tx.execute("call n10s.nsprefixes.add('sch','http://schema.org/')"); @@ -418,11 +347,11 @@ public void testCypherReturnsList() throws Exception { try (Transaction tx = graphDatabaseService.beginTx()) { - String dataInsertion = "CREATE (Keanu:Actor {name:'Keanu Reeves', born:1964})\n" + - "CREATE (Carrie:Director {name:'Carrie-Anne Moss', born:1967})\n" + - "CREATE (Laurence:Director {name:'Laurence Fishburne', born:1961})\n" + - "CREATE (Hugo:Critic {name:'Hugo Weaving', born:1960})\n" + - "CREATE (AndyW:Actor {name:'Andy Wachowski', born:1967})\n" + + String dataInsertion = "CREATE (Keanu:Actor {uri:'neo4j://person#1', name:'Keanu Reeves', born:1964})\n" + + "CREATE (Carrie:Director {uri:'neo4j://person#2', name:'Carrie-Anne Moss', born:1967})\n" + + "CREATE (Laurence:Director {uri:'neo4j://person#3', name:'Laurence Fishburne', born:1961})\n" + + "CREATE (Hugo:Critic {uri:'neo4j://person#4', name:'Hugo Weaving', born:1960})\n" + + "CREATE (AndyW:Actor {uri:'neo4j://person#5', name:'Andy Wachowski', born:1967})\n" + "CREATE (Hugo)-[:WORKS_WITH { hoursADay: 8 } ]->(AndyW)\n" + "CREATE (Hugo)<-[:FRIEND_OF { since: 'the early days' }]-(Carrie)"; tx.execute(dataInsertion); @@ -439,31 +368,32 @@ public void testCypherReturnsList() throws Exception { Response response = HTTP.withHeaders("Accept", "text/plain").POST( HTTP.GET(neo4j.httpURI().resolve("rdf").toString()).location() + "neo4j/cypher", map); - String expected = " .\n" - + " \"1967\"^^ .\n" - + " \"Andy Wachowski\" .\n" - + " .\n" - + " .\n" - + " \"1967\"^^ .\n" - + " \"1961\"^^ .\n" - + " \"1960\"^^ .\n" - + " \"1964\"^^ .\n" - + " \"Keanu Reeves\" .\n" - + " \"Laurence Fishburne\" .\n" - + " .\n" - + " .\n" - + " \"Hugo Weaving\" .\n" - + " \"Carrie-Anne Moss\" .\n"; + String expected = " .\n" + + " \"1967\"^^ .\n" + + " \"Andy Wachowski\" .\n" + + " .\n" + + " .\n" + + " \"1967\"^^ .\n" + + " \"1961\"^^ .\n" + + " \"1960\"^^ .\n" + + " \"1964\"^^ .\n" + + " \"Keanu Reeves\" .\n" + + " \"Laurence Fishburne\" .\n" + + " .\n" + + " .\n" + + " \"Hugo Weaving\" .\n" + + " \"Carrie-Anne Moss\" .\n"; assertEquals(200, response.status()); + + String responseString = response.rawContent(); + assertTrue(ModelTestUtils - .compareModels(expected, RDFFormat.TURTLE, response.rawContent(), RDFFormat.TURTLE)); + .compareModels(expected, RDFFormat.TURTLE, responseString, RDFFormat.TURTLE)); } @Test public void testPrefixwithHyphen() throws Exception { - // Given - final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); //first import onto try (Transaction tx = graphDatabaseService.beginTx()) { @@ -528,8 +458,6 @@ public void testPrefixwithHyphen() throws Exception { @Test public void testCypherOnMovieDBReturnsList() throws Exception { - // Given - final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); try (Transaction tx = graphDatabaseService.beginTx()) { tx.execute("call n10s.nsprefixes.add('sch','http://schema.org/')"); @@ -559,6 +487,13 @@ public void testCypherOnMovieDBReturnsList() throws Exception { tx.commit(); } + Map nameToId = new HashMap<>(); + try (Transaction tx = graphDatabaseService.beginTx()) { + tx.execute("match (n) return case n:Movie when true then n.title else n.name end as name, id(n) as id") + .stream() + .forEach(r -> nameToId.put((String) r.get("name"), String.format("#%s", (Long)r.get("id")) )); + } + Map map = new HashMap<>(); map.put("cypher", "MATCH (n:Movie { title: \"That Thing You Do\"})--(x) " + "RETURN collect(distinct n) + collect(distinct x)"); @@ -566,19 +501,25 @@ public void testCypherOnMovieDBReturnsList() throws Exception { Response response = HTTP.withHeaders("Accept", "text/plain").POST( HTTP.GET(neo4j.httpURI().resolve("rdf").toString()).location() + "neo4j/cypher", map); - String expected = " \"That Thing You Do\" .\n" - + " \"Charlize Theron\" .\n" - + " \"1977\"^^ .\n" - + " .\n" - + " \"1996\"^^ .\n" - + " \"Tom Hanks\" .\n" - + " \"Liv Tyler\" .\n" - + " .\n" - + " .\n" - + " \"1956\"^^ .\n" - + " \"In every life there comes a time when that thing you dream becomes that thing you do\" .\n" - + " .\n" - + " \"1975\"^^ ."; + String expected = String.format( + " \"That Thing You Do\" .\n" + + " \"Charlize Theron\" .\n" + + " \"1977\"^^ .\n" + + " .\n" + + " \"1996\"^^ .\n" + + " \"Tom Hanks\" .\n" + + " \"Liv Tyler\" .\n" + + " .\n" + + " .\n" + + " \"1956\"^^ .\n" + + " \"In every life there comes a time when that thing you dream becomes that thing you do\" .\n" + + " .\n" + + " \"1975\"^^ .", + nameToId.get("Charlize Theron"), + nameToId.get("Liv Tyler"), + nameToId.get("Tom Hanks"), + nameToId.get("That Thing You Do") + ); assertEquals(200, response.status()); assertTrue(ModelTestUtils @@ -588,8 +529,6 @@ public void testCypherOnMovieDBReturnsList() throws Exception { @Test public void testCypherReturnsListOnRDFGraph() throws Exception { - // Given - final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); try (Transaction tx = graphDatabaseService.beginTx()) { tx.execute(UNIQUENESS_CONSTRAINT_STATEMENT); tx.commit(); @@ -627,8 +566,6 @@ public void testCypherReturnsListOnRDFGraph() throws Exception { @Test public void testGetNodeByIdRDFStar() throws Exception { - // Given - final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); try (Transaction tx = graphDatabaseService.beginTx()) { String dataInsertion = "CREATE (Keanu:Actor {name:'Keanu Reeves', born:1964})\n" + @@ -642,35 +579,37 @@ public void testGetNodeByIdRDFStar() throws Exception { tx.commit(); } - Long id; + Long id1; + Long id4; + Long id3; try (Transaction tx = graphDatabaseService.beginTx()) { - Result result = tx.execute("MATCH (n:Critic)-[fo:FRIEND_OF]-() RETURN id(n) as id, " - + " fo.since AS since "); + Result result = tx.execute("MATCH (n3:Critic), (n4:Actor {name:'Andy Wachowski'}), (n1:Director {name:'Carrie-Anne Moss'}) " + + "return id(n1) as id1, id(n4) as id4, id(n3) as id3"); Map next = result.next(); - String since = (String) next.get("since"); - assertEquals("the early days", since); - id = (Long) next.get("id"); + id1 = (Long) next.get("id1"); + id4 = (Long) next.get("id4"); + id3 = (Long) next.get("id3"); } // When HTTP.Response response = HTTP.withHeaders("Accept", "text/x-turtlestar").GET( HTTP.GET(neo4j.httpURI().resolve("rdf").toString()).location() + "neo4j/describe/" - + id.toString()); + + id3.toString()); - String expected = "@prefix neoind: .\n" + String expected = String.format( "@prefix neoind: .\n" + "@prefix neovoc: .\n" + "@prefix rdf: .\n" + "\n" - + "neoind:3 a neovoc:Critic;\n" - + " neovoc:WORKS_WITH neoind:4;\n" + + "neoind:%2$s a neovoc:Critic;\n" + + " neovoc:WORKS_WITH neoind:%3$s;\n" + " neovoc:born \"1960\"^^;\n" + " neovoc:name \"Hugo Weaving\" .\n" + "\n" - + "<> neovoc:since \"the early days\" .\n" + + "<> neovoc:since \"the early days\" .\n" + "\n" - + "<> neovoc:hoursADay \"8\"^^ .\n" + + "<> neovoc:hoursADay \"8\"^^ .\n" + "\n" - + "neoind:1 neovoc:FRIEND_OF neoind:3 ."; + + "neoind:%1$s neovoc:FRIEND_OF neoind:%2$s .", id1, id3, id4); assertEquals(200, response.status()); assertTrue(ModelTestUtils .compareModels(expected, RDFFormat.TURTLESTAR, response.rawContent(), RDFFormat.TURTLESTAR)); @@ -679,8 +618,6 @@ public void testGetNodeByIdRDFStar() throws Exception { @Test public void ImportGetNodeById() throws Exception { - // Given - final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); try (Transaction tx = graphDatabaseService.beginTx()) { String ontoCreation = "MERGE (p:Category {catName: ' Person'})\n" + @@ -708,19 +645,17 @@ public void ImportGetNodeById() throws Exception { Result result = tx.execute("MATCH (n:Critic) RETURN id(n) AS id "); id = (Long) result.next().get("id"); - assertEquals(7, id); + assertNotNull(id); } - try (Driver driver = GraphDatabase.driver(temp.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { - session.run(UNIQUENESS_CONSTRAINT_STATEMENT); - session - .run("CALL n10s.graphconfig.init( { handleVocabUris: 'IGNORE', typesToLabels: true } )"); - org.neo4j.driver.Result importResults - = session.run("CALL n10s.rdf.import.fetch('" + - HTTP.GET(neo4j.httpURI().resolve("rdf").toString()).location() + "neo4j/describe/" - + id + - "','Turtle')"); + Session session = tempDriver.session(); + session.run(UNIQUENESS_CONSTRAINT_STATEMENT); + session.run("CALL n10s.graphconfig.init( { handleVocabUris: 'IGNORE', typesToLabels: true } )"); + org.neo4j.driver.Result importResults + = session.run("CALL n10s.rdf.import.fetch('" + + HTTP.GET(neo4j.httpURI().resolve("rdf").toString()).location() + "neo4j/describe/" + + id + + "','Turtle')"); Map singleResult = importResults .single().asMap(); @@ -740,14 +675,11 @@ public void ImportGetNodeById() throws Exception { assertEquals("neo4j://graph.individuals#" + criticPreImport.get("id"), criticPostImport.get("uri").asString()); } - } } @Test public void ImportGetNodeByIdOnImportedOnto() throws Exception { - // Given - final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); //first import onto try (Transaction tx = graphDatabaseService.beginTx()) { @@ -796,8 +728,6 @@ public void ImportGetNodeByIdOnImportedOnto() throws Exception { @Test public void ImportGetNodeByUriOnImportedOntoShorten() throws Exception { - // Given - final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); //first import onto try (Transaction tx = graphDatabaseService.beginTx()) { @@ -861,8 +791,6 @@ public void ImportGetNodeByUriOnImportedOntoShorten() throws Exception { @Test public void ImportGetNodeByUriOnImportedOntoIgnore() throws Exception { - // Given - final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); //first import onto try (Transaction tx = graphDatabaseService.beginTx()) { @@ -925,9 +853,6 @@ public void ImportGetNodeByUriOnImportedOntoIgnore() throws Exception { @Test public void ImportGetCypher() throws Exception { - final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); - final GraphDatabaseService tempGDBs = temp.defaultDatabaseService(); - try (Transaction tx = graphDatabaseService.beginTx()) { String ontoCreation = "MERGE (p:Category {catName: ' Person'})\n" + "MERGE (a:Category {catName: 'Actor'})\n" + @@ -955,21 +880,20 @@ public void ImportGetCypher() throws Exception { "MATCH (n:Critic) RETURN n.born AS born, n.name AS name , n.uri as uri, id(n) as id"); preImport = result.next(); assertEquals(1960L, preImport.get("born")); - assertEquals(7L, preImport.get("id")); + assertNotNull(preImport.get("id")); assertEquals("Hugo Weaving", preImport.get("name")); //no uri pre-import assertNull(preImport.get("uri")); } - try (Driver driver = GraphDatabase.driver(temp.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { - session.run(UNIQUENESS_CONSTRAINT_STATEMENT); - session.run("CALL n10s.graphconfig.init( { handleVocabUris: 'IGNORE' })"); - org.neo4j.driver.Result importResults - = session.run("CALL n10s.rdf.import.fetch('" + - HTTP.GET(neo4j.httpURI().resolve("rdf").toString()).location() + "neo4j/cypher" + - "','Turtle',{ headerParams: { Accept: \"text/turtle\"}," - + "payload: '{ \"cypher\": \"MATCH (x:Critic) RETURN x \"}'})"); + Session session = tempDriver.session(); + session.run(UNIQUENESS_CONSTRAINT_STATEMENT); + session.run("CALL n10s.graphconfig.init( { handleVocabUris: 'IGNORE' })"); + org.neo4j.driver.Result importResults + = session.run("CALL n10s.rdf.import.fetch('" + + HTTP.GET(neo4j.httpURI().resolve("rdf").toString()).location() + "neo4j/cypher" + + "','Turtle',{ headerParams: { Accept: \"text/turtle\"}," + + "payload: '{ \"cypher\": \"MATCH (x:Critic) RETURN x \"}'})"); Map singleResult = importResults .single().asMap(); @@ -982,15 +906,12 @@ public void ImportGetCypher() throws Exception { assertEquals(preImport.get("born"), criticPostImport.get("born").asLong()); assertEquals("neo4j://graph.individuals#" + preImport.get("id"), criticPostImport.get("uri").asString()); - } - } + @Test public void testFindNodeByLabelAndProperty() throws Exception { - final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); - try (Transaction tx = graphDatabaseService.beginTx()) { String ontoCreation = "MERGE (p:Category {catName: ' Person'})\n" + "MERGE (a:Category {catName: 'Actor'})\n" + @@ -1011,18 +932,19 @@ public void testFindNodeByLabelAndProperty() throws Exception { tx.execute(dataInsertion); tx.commit(); } - + Long id = null; try (Transaction tx = graphDatabaseService.beginTx()) { - Result result = tx.execute("MATCH (n:Critic) RETURN id(n) AS id "); - assertEquals(7L, result.next().get("id")); + Result result = tx.execute("MATCH (n:Director {name:'Laurence Fishburne'}) RETURN id(n) AS id "); + id = (Long) result.next().get("id"); + assertNotNull(id); } // When HTTP.Response response = HTTP.withHeaders("Accept", "application/ld+json").GET( HTTP.GET(neo4j.httpURI().resolve("rdf").toString()).location() + "neo4j/describe/find/Director/born/1961?valType=INTEGER"); - String expected = "[ {\n" - + " \"@id\" : \"neo4j://graph.individuals#6\",\n" + String expected = String.format("[ {\n" + + " \"@id\" : \"neo4j://graph.individuals#%s\",\n" + " \"@type\" : [ \"neo4j://graph.schema#Director\" ],\n" + " \"neo4j://graph.schema#born\" : [ {\n" + " \"@type\" : \"http://www.w3.org/2001/XMLSchema#long\",\n" @@ -1031,7 +953,7 @@ public void testFindNodeByLabelAndProperty() throws Exception { + " \"neo4j://graph.schema#name\" : [ {\n" + " \"@value\" : \"Laurence Fishburne\"\n" + " } ]\n" - + "} ]"; + + "} ]", id.toString()); assertEquals(200, response.status()); assertTrue(ModelTestUtils @@ -1042,8 +964,8 @@ public void testFindNodeByLabelAndProperty() throws Exception { HTTP.GET(neo4j.httpURI().resolve("rdf").toString()).location() + "neo4j/describe/find/Director/name/Laurence%20Fishburne"); - expected = "[ {\n" - + " \"@id\" : \"neo4j://graph.individuals#6\",\n" + expected = String.format("[ {\n" + + " \"@id\" : \"neo4j://graph.individuals#%s\",\n" + " \"@type\" : [ \"neo4j://graph.schema#Director\" ],\n" + " \"neo4j://graph.schema#born\" : [ {\n" + " \"@type\" : \"http://www.w3.org/2001/XMLSchema#long\",\n" @@ -1052,7 +974,7 @@ public void testFindNodeByLabelAndProperty() throws Exception { + " \"neo4j://graph.schema#name\" : [ {\n" + " \"@value\" : \"Laurence Fishburne\"\n" + " } ]\n" - + "} ]"; + + "} ]", id.toString()); assertEquals(200, response.status()); assertTrue(ModelTestUtils .compareModels(expected, RDFFormat.JSONLD, response.rawContent(), RDFFormat.JSONLD)); @@ -1062,8 +984,16 @@ public void testFindNodeByLabelAndProperty() throws Exception { HTTP.GET(neo4j.httpURI().resolve("rdf").toString()).location() + "neo4j/describe/find/Actor/born/1964?valType=INTEGER"); - expected = "[ {\n" - + " \"@id\" : \"neo4j://graph.individuals#4\",\n" + Map nameToId = new HashMap<>(); + try (Transaction tx = graphDatabaseService.beginTx()) { + tx.execute("match (n) return n.name as name, id(n) as id") + .stream() + .forEach(r -> nameToId.put((String) r.get("name"), String.format("#%s", (Long)r.get("id")) )); + } + + expected = String.format( + "[ {\n" + + " \"@id\" : \"neo4j://graph.individuals%1$s\",\n" + " \"@type\" : [ \"neo4j://graph.schema#Actor\" ],\n" + " \"neo4j://graph.schema#born\" : [ {\n" + " \"@type\" : \"http://www.w3.org/2001/XMLSchema#long\",\n" @@ -1073,12 +1003,12 @@ public void testFindNodeByLabelAndProperty() throws Exception { + " \"@value\" : \"Keanu Reeves\"\n" + " } ]\n" + "}, {\n" - + " \"@id\" : \"neo4j://graph.individuals#7\",\n" + + " \"@id\" : \"neo4j://graph.individuals%2$s\",\n" + " \"neo4j://graph.schema#WORKS_WITH\" : [ {\n" - + " \"@id\" : \"neo4j://graph.individuals#8\"\n" + + " \"@id\" : \"neo4j://graph.individuals%3$s\"\n" + " } ]\n" + "}, {\n" - + " \"@id\" : \"neo4j://graph.individuals#8\",\n" + + " \"@id\" : \"neo4j://graph.individuals%3$s\",\n" + " \"@type\" : [ \"neo4j://graph.schema#Actor\" ],\n" + " \"neo4j://graph.schema#born\" : [ {\n" + " \"@type\" : \"http://www.w3.org/2001/XMLSchema#long\",\n" @@ -1087,7 +1017,12 @@ public void testFindNodeByLabelAndProperty() throws Exception { + " \"neo4j://graph.schema#name\" : [ {\n" + " \"@value\" : \"Andy Wachowski\"\n" + " } ]\n" - + "} ]"; + + "} ]", + nameToId.get("Keanu Reeves"), //0 + nameToId.get("Hugo Weaving"), //1 + nameToId.get("Andy Wachowski") //2 + + ); assertEquals(200, response.status()); assertTrue(ModelTestUtils .compareModels(expected, RDFFormat.JSONLD, response.rawContent(), RDFFormat.JSONLD)); @@ -1141,7 +1076,7 @@ public void testGetNodeByUriOrIdNotFoundOrInvalid() throws Exception { assertEquals("[ ]", response.rawContent()); assertEquals(200, response.status()); - try (Transaction tx = neo4j.defaultDatabaseService().beginTx()) { + try (Transaction tx = graphDatabaseService.beginTx()) { tx.execute("CALL n10s.graphconfig.init()"); tx.commit(); } @@ -1166,7 +1101,6 @@ public void testGetNodeByUriOrIdNotFoundOrInvalid() throws Exception { @Test public void testPing() throws Exception { - // Given HTTP.Response response = HTTP.GET( HTTP.GET(neo4j.httpURI().resolve("rdf").toString()).location() + "ping"); @@ -1178,8 +1112,6 @@ public void testPing() throws Exception { @Test public void testCypherOnLPG() throws Exception { - final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); - try (Transaction tx = graphDatabaseService.beginTx()) { String ontoCreation = "MERGE (p:Category {catName: 'Person'})\n" + "MERGE (a:Category {catName: 'Actor'})\n" + @@ -1199,6 +1131,13 @@ public void testCypherOnLPG() throws Exception { tx.commit(); } + Map nameToId = new HashMap<>(); + try (Transaction tx = graphDatabaseService.beginTx()) { + tx.execute("match (n:Category) return n.catName as name, id(n) as id") + .stream() + .forEach(r -> nameToId.put((String) r.get("name"), String.format("#%s", (Long)r.get("id")) )); + } + try (Transaction tx = graphDatabaseService.beginTx()) { Result result = tx.execute("MATCH (n:Critic) RETURN id(n) AS id "); @@ -1212,14 +1151,20 @@ public void testCypherOnLPG() throws Exception { HTTP.GET(neo4j.httpURI().resolve("rdf").toString()).location() + "neo4j/cypher", map); String expected = - " .\n" - + " \"Critic\" .\n" - + " .\n" - + " \"Person\" .\n" - + " .\n" - + " \"Director\" .\n" - + " .\n" - + " \"Actor\" .\n"; + String.format( + " .\n" + + " \"Critic\" .\n" + + " .\n" + + " \"Person\" .\n" + + " .\n" + + " \"Director\" .\n" + + " .\n" + + " \"Actor\" .\n", + nameToId.get("Critic"), + nameToId.get("Person"), + nameToId.get("Director"), + nameToId.get("Actor") + ); assertEquals(200, response.status()); assertTrue(ModelTestUtils @@ -1247,7 +1192,6 @@ public void testCypherOnLPG() throws Exception { @Test public void testCypherOnLPGMappingsAndQueryParams() throws Exception { - final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); try (Transaction tx = graphDatabaseService.beginTx()) { tx.execute("call n10s.nsprefixes.add('sch','http://schema.org/')"); tx.commit(); @@ -1255,12 +1199,12 @@ public void testCypherOnLPGMappingsAndQueryParams() throws Exception { try (Transaction tx = graphDatabaseService.beginTx()) { - String dataInsertion = "CREATE (Keanu:Actor {name:'Keanu Reeves', born:1964})\n" + - "CREATE (Carrie:Director {name:'Carrie-Anne Moss', born:1967})\n" + - "CREATE (Laurence:Director {name:'Laurence Fishburne', born:1961})\n" + - "CREATE (Hugo:Critic {name:'Hugo Weaving', born:1960})\n" + - "CREATE (AndyW:Actor {name:'Andy Wachowski', born:1967}) " - + "CREATE (Keanu)-[:ACTED_IN]->(:Movie {title: 'The Matrix'})"; + String dataInsertion = "CREATE (Keanu:Actor {uri:'neo4j://graph.individuals#1', name:'Keanu Reeves', born:1964})\n" + + "CREATE (Carrie:Director {uri:'neo4j://graph.individuals#2', name:'Carrie-Anne Moss', born:1967})\n" + + "CREATE (Laurence:Director {uri:'neo4j://graph.individuals#3', name:'Laurence Fishburne', born:1961})\n" + + "CREATE (Hugo:Critic {uri:'neo4j://graph.individuals#4', name:'Hugo Weaving', born:1960})\n" + + "CREATE (AndyW:Actor {uri:'neo4j://graph.individuals#5', name:'Andy Wachowski', born:1967}) " + + "CREATE (Keanu)-[:ACTED_IN]->(:Movie {uri:'neo4j://graph.individuals#6', title: 'The Matrix'})"; tx.execute(dataInsertion); tx.execute("CALL n10s.mapping.add('http://schema.org/Person','Actor')"); @@ -1319,7 +1263,6 @@ public void testCypherOnLPGMappingsAndQueryParams() throws Exception { @Test public void testontoOnLPG() throws Exception { - final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); try (Transaction tx = graphDatabaseService.beginTx()) { String dataInsertion = "CREATE (kean:Actor:Resource {name:'Keanu Reeves', born:1964})\n" + @@ -1390,7 +1333,6 @@ public void testontoOnLPG() throws Exception { @Test public void testontoOnRDF() throws Exception { - final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); try (Transaction tx = graphDatabaseService.beginTx()) { tx.execute("CALL n10s.graphconfig.init()"); @@ -1458,7 +1400,6 @@ public void testontoOnRDF() throws Exception { @Test public void testNodeByUri() throws Exception { - final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); try (Transaction tx = graphDatabaseService.beginTx()) { tx.execute("CALL n10s.graphconfig.init()"); tx.execute("call n10s.nsprefixes.add('ns1','http://ont.thomsonreuters.com/mdaas/')"); @@ -1511,7 +1452,6 @@ public void testNodeByUri() throws Exception { @Test public void testNodeByUriAfterImport() throws Exception { - final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); try (Transaction tx = graphDatabaseService.beginTx()) { tx.execute(UNIQUENESS_CONSTRAINT_STATEMENT); tx.commit(); @@ -1562,8 +1502,6 @@ public void testNodeByUriAfterImport() throws Exception { @Test public void testNodeByUriMissingNamespaceDefinition() throws Exception { - - final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); try (Transaction tx = graphDatabaseService.beginTx()) { tx.execute(UNIQUENESS_CONSTRAINT_STATEMENT); tx.commit(); @@ -1638,7 +1576,6 @@ public void testNodeByUriMissingNamespaceDefinition() throws Exception { @Test public void testNodeByUriAfterImportWithMultilang() throws Exception { - final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); try (Transaction tx = graphDatabaseService.beginTx()) { tx.execute(UNIQUENESS_CONSTRAINT_STATEMENT); tx.commit(); @@ -1673,7 +1610,6 @@ public void testNodeByUriAfterImportWithMultilang() throws Exception { @Test public void testCypherWithUrisSerializeAsJsonLd() throws Exception { - final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); try (Transaction tx = graphDatabaseService.beginTx()) { tx.execute("CALL n10s.graphconfig.init()"); tx.execute("call n10s.nsprefixes.add('ns1','http://ont.thomsonreuters.com/mdaas/')"); @@ -1727,7 +1663,6 @@ public void testCypherWithUrisSerializeAsJsonLd() throws Exception { @Test public void testOneNodeCypherWithUrisSerializeAsJsonLd() throws Exception { - final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); try (Transaction tx = graphDatabaseService.beginTx()) { tx.execute("CALL n10s.graphconfig.init()"); @@ -1768,7 +1703,6 @@ public void testOneNodeCypherWithUrisSerializeAsJsonLd() throws Exception { @Test public void testCypherWithBNodesSerializeAsRDFXML() throws Exception { - final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); try (Transaction tx = graphDatabaseService.beginTx()) { tx.execute("CALL n10s.graphconfig.init()"); tx.execute("call n10s.nsprefixes.add('ns0','http://permid.org/ontology/organization/')"); @@ -1834,7 +1768,6 @@ public void testCypherWithBNodesSerializeAsRDFXML() throws Exception { @Test public void testNodeByUriAfterImportWithCustomDTKeepUris() throws Exception { - final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); try (Transaction tx = graphDatabaseService.beginTx()) { tx.execute(UNIQUENESS_CONSTRAINT_STATEMENT); tx.commit(); @@ -1878,7 +1811,6 @@ public void testNodeByUriAfterImportWithCustomDTKeepUris() throws Exception { @Test public void testNodeByUriAfterImportWithCustomDTShortenURIs() throws Exception { - final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); try (Transaction tx = graphDatabaseService.beginTx()) { tx.execute(UNIQUENESS_CONSTRAINT_STATEMENT); tx.commit(); @@ -1923,7 +1855,6 @@ public void testNodeByUriAfterImportWithCustomDTShortenURIs() throws Exception { @Test public void testNodeByUriAfterImportWithMultiCustomDTKeepUris() throws Exception { - final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); try (Transaction tx = graphDatabaseService.beginTx()) { tx.execute(UNIQUENESS_CONSTRAINT_STATEMENT); tx.commit(); @@ -1967,7 +1898,6 @@ public void testNodeByUriAfterImportWithMultiCustomDTKeepUris() throws Exception @Test public void testNodeByUriAfterImportWithMultiCustomDTShortenUris() throws Exception { - final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); try (Transaction tx = graphDatabaseService.beginTx()) { tx.execute(UNIQUENESS_CONSTRAINT_STATEMENT); tx.commit(); @@ -2013,7 +1943,6 @@ public void testNodeByUriAfterImportWithMultiCustomDTShortenUris() throws Except @Test public void testcypherAfterImportWithCustomDTKeepURIsSerializeAsTurtle() throws Exception { - final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); try (Transaction tx = graphDatabaseService.beginTx()) { tx.execute(UNIQUENESS_CONSTRAINT_STATEMENT); tx.commit(); @@ -2062,7 +1991,6 @@ public void testcypherAfterImportWithCustomDTKeepURIsSerializeAsTurtle() throws @Test public void testcypherDatesAndDatetimes() throws Exception { - final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); try (Transaction tx = graphDatabaseService.beginTx()) { tx.execute(UNIQUENESS_CONSTRAINT_STATEMENT); tx.commit(); @@ -2102,7 +2030,6 @@ public void testcypherDatesAndDatetimes() throws Exception { @Test public void testcypherErrorWhereModelIsNotRDF() throws Exception { - final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); String cypherCreate = " CREATE (r:Resource { uri: 'neo4j://explicit_uri#123' , name: 'the name' }) "; try (Transaction tx = graphDatabaseService.beginTx()) { @@ -2171,7 +2098,6 @@ private String getExportedAsLPG( String uri ) { @Test public void testcypherAfterImportWithCustomDTShortenURIsSerializeAsTurtle() throws Exception { - final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); try (Transaction tx = graphDatabaseService.beginTx()) { tx.execute(UNIQUENESS_CONSTRAINT_STATEMENT); tx.commit(); @@ -2220,7 +2146,6 @@ public void testcypherAfterImportWithCustomDTShortenURIsSerializeAsTurtle() @Test public void testcypherAfterImportWithMultiCustomDTKeepURIsSerializeAsTurtle() throws Exception { - final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); try (Transaction tx = graphDatabaseService.beginTx()) { tx.execute(UNIQUENESS_CONSTRAINT_STATEMENT); @@ -2270,7 +2195,6 @@ public void testcypherAfterImportWithMultiCustomDTKeepURIsSerializeAsTurtle() @Test public void testcypherAfterImportWithMultiCustomDTShortenURIsSerializeAsTurtle() throws Exception { - final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); try (Transaction tx = graphDatabaseService.beginTx()) { tx.execute(UNIQUENESS_CONSTRAINT_STATEMENT); tx.commit(); @@ -2318,7 +2242,6 @@ public void testcypherAfterImportWithMultiCustomDTShortenURIsSerializeAsTurtle() @Test public void testcypherAfterDeleteRDFBNodes() throws Exception { - final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); try (Transaction tx = graphDatabaseService.beginTx()) { tx.execute(UNIQUENESS_CONSTRAINT_STATEMENT); @@ -2380,9 +2303,8 @@ public void testcypherAfterDeleteRDFBNodes() throws Exception { @Test public void testCypherOnQuadRDFSerializeAsTriG() throws Exception { - final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); try (Transaction tx = graphDatabaseService.beginTx()) { - tx.execute("create index for (n:Resource) on (n.uri)"); + tx.execute("CREATE INDEX uri_index FOR (r:Resource) ON (r.uri)"); tx.commit(); } try (Transaction tx = graphDatabaseService.beginTx()) { @@ -2417,9 +2339,8 @@ public void testCypherOnQuadRDFSerializeAsTriG() throws Exception { @Test public void testCypherOnQuadRDFSerializeAsNQuads() throws Exception { - final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); try (Transaction tx = graphDatabaseService.beginTx()) { - tx.execute("create index for (n:Resource) on (n.uri)"); + tx.execute("CREATE INDEX uri_index FOR (r:Resource) ON (r.uri)"); tx.commit(); } try (Transaction tx = graphDatabaseService.beginTx()) { @@ -2454,9 +2375,8 @@ public void testCypherOnQuadRDFSerializeAsNQuads() throws Exception { @Test public void testNodeByUriOnQuadRDF() throws Exception { - final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); try (Transaction tx = graphDatabaseService.beginTx()) { - tx.execute("create index for (n:Resource) on (n.uri)"); + tx.execute("CREATE INDEX uri_index FOR (r:Resource) ON (r.uri)"); tx.commit(); } try (Transaction tx = graphDatabaseService.beginTx()) { @@ -2488,9 +2408,8 @@ public void testNodeByUriOnQuadRDF() throws Exception { @Test public void testNodeByUriWithGraphUriOnQuadRDFTrig() throws Exception { - final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); try (Transaction tx = graphDatabaseService.beginTx()) { - tx.execute("create index for (n:Resource) on (n.uri)"); + tx.execute("CREATE INDEX uri_index FOR (r:Resource) ON (r.uri)"); tx.commit(); } try (Transaction tx = graphDatabaseService.beginTx()) { @@ -2529,9 +2448,8 @@ public void testNodeByUriWithGraphUriOnQuadRDFTrig() throws Exception { @Test public void testNodeByUriWithGraphUriOnQuadRDFNQuads() throws Exception { - final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); try (Transaction tx = graphDatabaseService.beginTx()) { - tx.execute("create index for (n:Resource) on (n.uri)"); + tx.execute("CREATE INDEX uri_index FOR (r:Resource) ON (r.uri)"); tx.commit(); } try (Transaction tx = graphDatabaseService.beginTx()) { @@ -2567,10 +2485,8 @@ public void testNodeByUriWithGraphUriOnQuadRDFNQuads() throws Exception { @Test public void testCypherOnQuadRDFAfterDeleteRDFBNodes() throws Exception { - // Given - final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); try (Transaction tx = graphDatabaseService.beginTx()) { - tx.execute("create index for (n:Resource) on (n.uri)"); + tx.execute("CREATE INDEX uri_index FOR (r:Resource) ON (r.uri)"); tx.commit(); } try (Transaction tx = graphDatabaseService.beginTx()) { @@ -2617,8 +2533,6 @@ public void testCypherOnQuadRDFAfterDeleteRDFBNodes() throws Exception { @Test public void testTicket13061() throws Exception { - // Given - final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); //create constraint try (Transaction tx = graphDatabaseService.beginTx()) { tx.execute(UNIQUENESS_CONSTRAINT_STATEMENT); diff --git a/src/test/java/n10s/graphconfig/GraphConfigProceduresTest.java b/src/test/java/n10s/graphconfig/GraphConfigProceduresTest.java index b4fc059f..e0bb0361 100644 --- a/src/test/java/n10s/graphconfig/GraphConfigProceduresTest.java +++ b/src/test/java/n10s/graphconfig/GraphConfigProceduresTest.java @@ -6,22 +6,33 @@ import static org.junit.Assert.assertTrue; import n10s.rdf.load.RDFLoadProcedures; -import org.junit.Rule; -import org.junit.Test; +import org.junit.*; +import org.junit.jupiter.api.BeforeEach; import org.neo4j.driver.Record; import org.neo4j.driver.*; import org.neo4j.harness.junit.rule.Neo4jRule; public class GraphConfigProceduresTest { + public static Driver driver; - @Rule - public Neo4jRule neo4j = new Neo4jRule() - .withProcedure(GraphConfigProcedures.class).withProcedure(RDFLoadProcedures.class); + @ClassRule + public static Neo4jRule neo4j = new Neo4jRule() + .withProcedure(GraphConfigProcedures.class).withProcedure(RDFLoadProcedures.class); + + @BeforeClass + public static void init() { + driver = GraphDatabase.driver(neo4j.boltURI(), + Config.builder().withoutEncryption().build()); + } + + @Before + public void cleanDatabase() { + driver.session().run("match (n) detach delete n").consume(); + driver.session().run("drop constraint n10s_unique_uri if exists").consume(); + } @Test public void testInitGraphConfig() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { Session session = driver.session(); @@ -66,15 +77,10 @@ public void testInitGraphConfig() throws Exception { + " with param, value where param = 'baseSchemaNamespace' return param, value "); assertEquals(true, results.hasNext()); assertEquals("http://base#", results.next().get("value").asString()); - - } } @Test public void testModifyGraphConfigWhenDataInGraph() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - Session session = driver.session(); session.run(UNIQUENESS_CONSTRAINT_STATEMENT); @@ -95,16 +101,10 @@ public void testModifyGraphConfigWhenDataInGraph() throws Exception { assertTrue(e.getMessage().contains("n10s.graphconfig.GraphConfigProcedures$" + "GraphConfigException: The graph is non-empty. Config cannot be changed.")); } - - - } } @Test public void testForceModifyGraphConfigWhenDataInGraph() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - Session session = driver.session(); session.run(UNIQUENESS_CONSTRAINT_STATEMENT); @@ -136,18 +136,11 @@ public void testForceModifyGraphConfigWhenDataInGraph() throws Exception { if(paramVal.get("param").equals("handleMultival")){ assertEquals("ARRAY",paramVal.get("value")); } - } - - - } } @Test public void testDropGraph() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - Session session = driver.session(); Result results = session.run("CALL n10s.graphconfig.init() yield param, value " @@ -158,8 +151,5 @@ public void testDropGraph() throws Exception { results = session.run("MATCH (gc:_GraphConfig) return gc"); assertFalse(results.hasNext()); - - - } } } diff --git a/src/test/java/n10s/inference/MicroReasonersTest.java b/src/test/java/n10s/inference/MicroReasonersTest.java index 77187e59..0051fe1f 100644 --- a/src/test/java/n10s/inference/MicroReasonersTest.java +++ b/src/test/java/n10s/inference/MicroReasonersTest.java @@ -6,9 +6,9 @@ import java.util.HashSet; import java.util.Set; +import n10s.aux.AuxProcedures; import n10s.graphconfig.GraphConfigProcedures; -import org.junit.Rule; -import org.junit.Test; +import org.junit.*; import org.neo4j.driver.Config; import org.neo4j.driver.Driver; import org.neo4j.driver.GraphDatabase; @@ -19,14 +19,28 @@ public class MicroReasonersTest { - @Rule - public Neo4jRule neo4j = new Neo4jRule() - .withProcedure(MicroReasoners.class).withFunction(MicroReasoners.class).withProcedure(GraphConfigProcedures.class); + public static Driver driver; + + @ClassRule + public static Neo4jRule neo4j = new Neo4jRule() + .withProcedure(MicroReasoners.class) + .withFunction(MicroReasoners.class) + .withProcedure(GraphConfigProcedures.class); + + @BeforeClass + public static void init() { + driver = GraphDatabase.driver(neo4j.boltURI(), + Config.builder().withoutEncryption().build()); + } + + @Before + public void cleanDatabase() { + driver.session().run("match (n) detach delete n").consume(); + driver.session().run("drop constraint n10s_unique_uri if exists"); + } @Test public void testGetNodesNoOnto() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { Session session = driver.session(); session.run("CREATE (b:B {id:'iamb'}) CREATE (a:A {id: 'iama' }) "); @@ -53,13 +67,10 @@ public void testGetNodesNoOnto() throws Exception { assertEquals(expectedNodeIds, new HashSet<>(next.get("nodes").asList())); assertEquals(1L, next.get("ct").asLong()); assertEquals(false, results.hasNext()); - } } @Test public void testGetNodesDefault() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { Session session = driver.session(); session.run("call n10s.graphconfig.init({classLabel: 'Label', subClassOfRel: 'SLO'})"); @@ -76,13 +87,10 @@ public void testGetNodesDefault() throws Exception { assertEquals(expectedNodeIds, new HashSet<>(next.get("nodes").asList())); assertEquals(2L, next.get("ct").asLong()); assertEquals(false, results.hasNext()); - } } @Test public void testGetNodesCustomHierarchy() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { Session session = driver.session(); @@ -98,14 +106,10 @@ public void testGetNodesCustomHierarchy() throws Exception { assertEquals(expectedNodeIds, new HashSet<>(next.get("nodes").asList())); assertEquals(2L, next.get("ct").asLong()); assertEquals(false, results.hasNext()); - } } @Test public void testGetNodesLinkedTo() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - Session session = driver.session(); session.run("CREATE (b:Thing {id:'iamb'}) CREATE (a:Thing {id: 'iama' }) "); @@ -196,15 +200,11 @@ public void testGetNodesLinkedTo() throws Exception { assertEquals(2L, next.get("ct").asLong()); assertEquals(false, results.hasNext()); - } } @Test public void testGetNodesLinkedToOnModelWithUriNames() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - Session session = driver.session(); session @@ -216,15 +216,10 @@ public void testGetNodesLinkedToOnModelWithUriNames() throws Exception { + "subCatRel:'http://www.w3.org/2000/01/rdf-schema#subClassOf'}) yield node return node"); //just checking syntax is valid, no results expected. assertEquals(false, results.hasNext()); - - } } @Test public void testGetRelsNoOnto() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - Session session = driver.session(); session.run( @@ -241,14 +236,10 @@ public void testGetRelsNoOnto() throws Exception { assertEquals(false, session.run( "MATCH (b:B) CALL n10s.inference.getRels(b,'GENERIC',{ relLabel: 'Something', subRelRel: 'Something'}) YIELD rel, node RETURN b.id as source, type(rel) as relType, rel.prop as propVal, node.id as target") .hasNext()); - } } @Test public void testGetRels() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - Session session = driver.session(); session.run( @@ -294,14 +285,10 @@ public void testGetRels() throws Exception { assertEquals(123L, next.get("propVal").asLong()); assertEquals("iama", next.get("target").asString()); assertEquals(false, results.hasNext()); - } } @Test public void testGetRelsCustom() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - Session session = driver.session(); session.run("call n10s.graphconfig.init({ objectPropertyLabel: 'ObjectProperty', " + @@ -320,14 +307,10 @@ public void testGetRelsCustom() throws Exception { assertEquals(123L, next.get("propVal").asLong()); assertEquals("iama", next.get("target").asString()); assertEquals(false, results.hasNext()); - } } @Test public void testHasLabelNoOnto() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - Session session = driver.session(); session @@ -355,14 +338,10 @@ public void testHasLabelNoOnto() throws Exception { assertEquals(false, results.hasNext()); assertEquals(false, session.run("MATCH (n:A) WHERE n10s.inference.hasLabel(n,'C', { catLabel: 'something', catNameProp : 'something', subCatRel: 'something'}) RETURN *").hasNext()); - } } @Test public void testHasLabel() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - Session session = driver.session(); session @@ -401,14 +380,10 @@ public void testHasLabel() throws Exception { expectedNodeIds.add("iamB1"); assertEquals(expectedNodeIds, new HashSet<>(next.get("nodes").asList())); assertEquals(3L, next.get("ct").asLong()); - } } @Test public void testHasLabelCustom() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - Session session = driver.session(); session @@ -425,14 +400,10 @@ public void testHasLabelCustom() throws Exception { expectedNodeIds.add("iamB1"); assertEquals(expectedNodeIds, new HashSet<>(next.get("nodes").asList())); assertEquals(3L, next.get("ct").asLong()); - } } @Test public void testInCategory() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - Session session = driver.session(); session.run("CREATE (b:Thing {id:'iamb'}) CREATE (a:Thing {id: 'iama' }) "); @@ -499,7 +470,6 @@ public void testInCategory() throws Exception { // assertEquals(expectedNodeIds,new HashSet<>(next.get("nodes").asList())); // assertEquals(2L, next.get("ct").asLong()); // assertEquals(false, results.hasNext()); - } } //TODO: test modifying the ontology diff --git a/src/test/java/n10s/load/AddProceduresTest.java b/src/test/java/n10s/load/AddProceduresTest.java index d8985d5d..6a225197 100644 --- a/src/test/java/n10s/load/AddProceduresTest.java +++ b/src/test/java/n10s/load/AddProceduresTest.java @@ -2,11 +2,11 @@ import n10s.RDFProceduresTest; import n10s.graphconfig.GraphConfigProcedures; +import n10s.inference.MicroReasoners; import n10s.nsprefixes.NsPrefixDefProcedures; import n10s.rdf.load.AddProcedures; import n10s.rdf.load.RDFLoadProcedures; -import org.junit.Rule; -import org.junit.Test; +import org.junit.*; import org.neo4j.driver.*; import org.neo4j.driver.types.Node; import org.neo4j.driver.types.Point; @@ -20,22 +20,32 @@ import static org.junit.Assert.assertTrue; public class AddProceduresTest { + public static Driver driver; - @Rule - public Neo4jRule neo4j = new Neo4jRule() + @ClassRule + public static Neo4jRule neo4j = new Neo4jRule() .withProcedure(RDFLoadProcedures.class) .withProcedure(GraphConfigProcedures.class) .withProcedure(NsPrefixDefProcedures.class) .withProcedure(AddProcedures.class); + @BeforeClass + public static void init() { + driver = GraphDatabase.driver(neo4j.boltURI(), + Config.builder().withoutEncryption().build()); + } + + @Before + public void cleanDatabase() { + driver.session().run("match (n) detach delete n").consume(); + driver.session().run("drop constraint n10s_unique_uri if exists").consume(); + } + @Test public void testAddNodeAfterImport() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { - initialiseGraphDB(neo4j.defaultDatabaseService(), "{ handleRDFTypes: 'LABELS_AND_NODES'}"); - + Session session = driver.session(); Result importResults = session.run("CALL n10s.rdf.import.fetch('" + RDFProceduresTest.class.getClassLoader() @@ -113,7 +123,6 @@ public void testAddNodeAfterImport() throws Exception { assertEquals(7203, thepoint.srid()); assertEquals(idOf1234,rel.startNodeId()); assertEquals(idOf5678,rel.endNodeId()); - } } private void initialiseGraphDB(GraphDatabaseService db, String graphConfigParams) { diff --git a/src/test/java/n10s/mapping/MappingUtilsTest.java b/src/test/java/n10s/mapping/MappingUtilsTest.java index d453da0b..a6ec7c30 100644 --- a/src/test/java/n10s/mapping/MappingUtilsTest.java +++ b/src/test/java/n10s/mapping/MappingUtilsTest.java @@ -6,29 +6,44 @@ import java.util.HashMap; import java.util.Map; + +import n10s.graphconfig.GraphConfigProcedures; import n10s.nsprefixes.NsPrefixDefProcedures; -import org.junit.Rule; -import org.junit.Test; +import n10s.rdf.load.AddProcedures; +import n10s.rdf.load.RDFLoadProcedures; +import org.junit.*; import org.neo4j.driver.*; import org.neo4j.driver.Record; import org.neo4j.harness.junit.rule.Neo4jRule; public class MappingUtilsTest { + public static Driver driver; + + @ClassRule + public static Neo4jRule neo4j = new Neo4jRule() + .withProcedure(MappingUtils.class) + .withFunction(MappingUtils.class) + .withProcedure(NsPrefixDefProcedures.class); + + @BeforeClass + public static void init() { + driver = GraphDatabase.driver(neo4j.boltURI(), + Config.builder().withoutEncryption().build()); + } - @Rule - public Neo4jRule neo4j = new Neo4jRule() - .withProcedure(MappingUtils.class).withFunction(MappingUtils.class) - .withProcedure(NsPrefixDefProcedures.class); + @Before + public void cleanDatabase() { + driver.session().run("match (n) detach delete n").consume(); + driver.session().run("drop constraint n10s_unique_uri if exists").consume(); + } @Test public void testaddSchema() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session();) { + try (Session session = driver.session()) { assertTrue(session.run(" call n10s.nsprefixes.add(\"v1\",\"http://vocabularies.com/vocabulary1/\")").hasNext()); } - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session();) { + try (Session session = driver.session();) { Map params = new HashMap<>(); params.put("vocElem", "http://voc.new/sch1#something"); @@ -46,13 +61,9 @@ public void testaddSchema() throws Exception { @Test public void testAddMappingToSchema() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session();) { + try (Session session = driver.session();) { assertTrue(session.run(" call n10s.nsprefixes.add(\"sch1\",\"http://schemas.com/schema1/\")").hasNext()); } - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - Session session = driver.session(); // when DB is empty @@ -88,17 +99,14 @@ public void testAddMappingToSchema() throws Exception { assertTrue(session.run(existMappingAndNs, params).hasNext()); params.put("vocElem", nameInVoc); assertFalse(session.run(existMappingAndNs, params).hasNext()); - } } @Test public void testListMappings() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session();) { + try (Session session = driver.session();) { assertTrue(session.run(" call n10s.nsprefixes.add(\"sch\",\"http://schema.org/\")").hasNext()); } - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session();) { + Session session = driver.session(); // when DB is empty assertFalse(session.run("MATCH (n) WHERE not n:_NsPrefDef RETURN n").hasNext()); @@ -113,18 +121,13 @@ public void testListMappings() throws Exception { assertEquals(1, session.run( "CALL n10s.mapping.list('Person') yield elemName RETURN count(elemName) as ct ") .next().get("ct").asInt()); - } } @Test public void testDropMappings() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session();) { + try (Session session = driver.session();) { assertTrue(session.run(" call n10s.nsprefixes.add(\"sch\",\"http://schema.org/\")").hasNext()); } - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - Session session = driver.session(); // when DB is empty @@ -140,19 +143,13 @@ public void testDropMappings() throws Exception { assertEquals(2, session .run("CALL n10s.mapping.list() yield elemName RETURN count(elemName) as ct ") .next().get("ct").asInt()); - - } } @Test public void testDropMappingsAndSchemas() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session();) { + try (Session session = driver.session();) { assertTrue(session.run(" call n10s.nsprefixes.add(\"sch1\",\"http://schemas.com/schema1/\")").hasNext()); } - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - Session session = driver.session(); // when DB is empty @@ -189,14 +186,11 @@ public void testDropMappingsAndSchemas() throws Exception { assertEquals(0, session .run("CALL n10s.mapping.list() yield elemName RETURN count(elemName) as ct ") .next().get("ct").asInt()); - - } } @Test public void testBug12931() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session();) { + Session session = driver.session(); String step1 = "CALL n10s.nsprefixes.add(\"a\",\"neo4j://vocs/a/\")"; String step2 = "CALL n10s.mapping.add(\"neo4j://vocs/a/something\",\"something\")"; String step3 = "CALL n10s.mapping.add(\"neo4j://vocs/a/other\",\"other\")"; @@ -213,6 +207,4 @@ public void testBug12931() throws Exception { "return count(*) as namespacecount").next().get("namespacecount").asLong()); } - - } } diff --git a/src/test/java/n10s/nsprefixes/NsPrefixDefProceduresTest.java b/src/test/java/n10s/nsprefixes/NsPrefixDefProceduresTest.java index 2a9aaa56..a0adfb00 100644 --- a/src/test/java/n10s/nsprefixes/NsPrefixDefProceduresTest.java +++ b/src/test/java/n10s/nsprefixes/NsPrefixDefProceduresTest.java @@ -10,9 +10,9 @@ import java.util.Map; import java.util.Set; import n10s.graphconfig.GraphConfigProcedures; +import n10s.rdf.load.AddProcedures; import n10s.rdf.load.RDFLoadProcedures; -import org.junit.Rule; -import org.junit.Test; +import org.junit.*; import org.neo4j.driver.Config; import org.neo4j.driver.Driver; import org.neo4j.driver.GraphDatabase; @@ -26,16 +26,29 @@ * Created by jbarrasa on 21/03/2016. */ public class NsPrefixDefProceduresTest { + public static Driver driver; + + @ClassRule + public static Neo4jRule neo4j = new Neo4jRule() + .withProcedure(NsPrefixDefProcedures.class) + .withProcedure(RDFLoadProcedures.class) + .withProcedure(GraphConfigProcedures.class); + + @BeforeClass + public static void init() { + driver = GraphDatabase.driver(neo4j.boltURI(), + Config.builder().withoutEncryption().build()); + } - @Rule - public Neo4jRule neo4j = new Neo4jRule().withProcedure(NsPrefixDefProcedures.class) - .withProcedure(RDFLoadProcedures.class).withProcedure(GraphConfigProcedures.class); - + @Before + public void cleanDatabase() { + driver.session().run("match (n) detach delete n").consume(); + driver.session().run("drop constraint n10s_unique_uri if exists").consume(); + } @Test public void testAddNamespacePrefixInitial() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + Session session = driver.session(); Result res = session.run("CALL n10s.nsprefixes.add('abc','http://myvoc#')"); assertTrue(res.hasNext()); @@ -52,13 +65,11 @@ public void testAddNamespacePrefixInitial() throws Exception { next = res.next(); assertEquals("abc", next.get("prefix").asString()); assertEquals("http://myvoc2#", next.get("namespace").asString()); - } } @Test public void testAddNamespacePrefixInUse() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + Session session = driver.session(); Result res = session.run("CALL n10s.nsprefixes.add('abc','http://myvoc2#')"); assertTrue(res.hasNext()); @@ -78,13 +89,11 @@ public void testAddNamespacePrefixInUse() throws Exception { } res = session.run("CALL n10s.nsprefixes.add('abc','http://myvoc2#')"); assertTrue(res.hasNext()); - } } @Test public void testAddNamespaceWithPopulatedGraph() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + Session session = driver.session(); initialiseGraphDB(neo4j.defaultDatabaseService(), null); Result res1 = session.run("CALL n10s.rdf.import.fetch('" + @@ -104,15 +113,13 @@ public void testAddNamespaceWithPopulatedGraph() throws Exception { keys.removeAll(preAddition.keySet()); assertEquals(1, keys.size()); assertEquals(ns_prefix, keys.iterator().next()); - } } @Test public void testDeleteNamespaceWithPopulatedGraph() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + Session session = driver.session(); - initialiseGraphDB(neo4j.defaultDatabaseService(), null); + initialiseGraphDB(neo4j.defaultDatabaseService(), null); Result res1 = session.run("CALL n10s.rdf.import.fetch('" + NsPrefixDefProceduresTest.class.getClassLoader().getResource("mini-ld.json").toURI() + "','JSON-LD')"); @@ -137,15 +144,13 @@ public void testDeleteNamespaceWithPopulatedGraph() throws Exception { + "NsPrefixOperationNotAllowed: Namespace prefix definitions cannot be removed " + "when the graph is non-empty.")); } - } } @Test public void testAddNamespacePrefixFromText() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + Session session = driver.session(); - String turtle = "@prefix tr-common: . \n" + String turtle = "@prefix tr-common: . \n" + "@prefix fibo-be-le-cb: . \n" + "@prefix xsd: . \n" + "@prefix vcard: . \n" @@ -220,8 +225,6 @@ public void testAddNamespacePrefixFromText() throws Exception { validPairs.put("prop", "http://dbpedia.org/property/"); checkValidPrefixesCreated(session, validPairs, sparql); - - } } private void checkValidPrefixesCreated(Session session, Map validPairs, @@ -246,10 +249,9 @@ private boolean isExpectedPair(Map validPairs, String prefix, St @Test public void testRemoveAllNamespaces() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + Session session = driver.session(); - session.run("CALL n10s.nsprefixes.add('a1','http://myvoc1#')"); + session.run("CALL n10s.nsprefixes.add('a1','http://myvoc1#')"); session.run("CALL n10s.nsprefixes.add('a2','http://myvoc2#')"); session.run("CALL n10s.nsprefixes.add('a3','http://myvoc3#')"); Result res = session.run("CALL n10s.nsprefixes.add('a4','http://myvoc4#') yield prefix " @@ -264,8 +266,6 @@ public void testRemoveAllNamespaces() throws Exception { res = session.run("MATCH (nspd:_NsPrefDef) return nspd"); assertFalse(res.hasNext()); - - } } private void initialiseGraphDB(GraphDatabaseService db, String graphConfigParams) { diff --git a/src/test/java/n10s/onto/OntoProceduresTest.java b/src/test/java/n10s/onto/OntoProceduresTest.java index cf258fac..b7fb7730 100644 --- a/src/test/java/n10s/onto/OntoProceduresTest.java +++ b/src/test/java/n10s/onto/OntoProceduresTest.java @@ -1,11 +1,12 @@ package n10s.onto; import n10s.graphconfig.GraphConfigProcedures; +import n10s.nsprefixes.NsPrefixDefProcedures; import n10s.onto.load.OntoLoadProcedures; import n10s.onto.preview.OntoPreviewProcedures; import n10s.rdf.RDFProcedures; -import org.junit.Rule; -import org.junit.Test; +import n10s.rdf.load.RDFLoadProcedures; +import org.junit.*; import org.neo4j.driver.Record; import org.neo4j.driver.*; import org.neo4j.graphdb.GraphDatabaseService; @@ -27,13 +28,26 @@ * Created by jbarrasa on 21/03/2016. */ public class OntoProceduresTest { + public static Driver driver; + + @ClassRule + public static Neo4jRule neo4j = new Neo4jRule() + .withProcedure(OntoLoadProcedures.class) + .withProcedure(OntoPreviewProcedures.class) + .withProcedure(GraphConfigProcedures.class) + .withFunction(RDFProcedures.class); + + @BeforeClass + public static void init() { + driver = GraphDatabase.driver(neo4j.boltURI(), + Config.builder().withoutEncryption().build()); + } - @Rule - public Neo4jRule neo4j = new Neo4jRule() - .withProcedure(OntoLoadProcedures.class) - .withProcedure(OntoPreviewProcedures.class) - .withProcedure(GraphConfigProcedures.class) - .withFunction(RDFProcedures.class); + @Before + public void cleanDatabase() { + driver.session().run("match (n) detach delete n").consume(); + driver.session().run("drop constraint n10s_unique_uri if exists").consume(); + } private String turtleOntology = "@prefix owl: .\n" @@ -320,8 +334,7 @@ private static URI file(String path) { @Test public void testOntoPreviewFromSnippet() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + Session session = driver.session(); initialiseGraphDB(neo4j.defaultDatabaseService(), "{}"); @@ -338,13 +351,11 @@ public void testOntoPreviewFromSnippet() throws Exception { assertEquals(14, nodes.size()); final List rels = (List) next.get("relationships"); assertEquals(17, rels.size()); - } } @Test public void testOntoPreviewFromSnippetLimit() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + Session session = driver.session(); initialiseGraphDB(neo4j.defaultDatabaseService(), "{}"); @@ -372,13 +383,11 @@ public void testOntoPreviewFromSnippetLimit() throws Exception { assertEquals(5, nodes.size()); rels = (List) next.get("relationships"); assertEquals(1, rels.size()); - } } @Test public void testOntoPreviewFromSnippetWithRestrictions() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + Session session = driver.session(); initialiseGraphDB(neo4j.defaultDatabaseService(), "{}"); @@ -395,13 +404,11 @@ public void testOntoPreviewFromSnippetWithRestrictions() throws Exception { assertEquals(5, nodes.size()); final List rels = (List) next.get("relationships"); assertEquals(2, rels.size()); - } } @Test public void testOntoPreviewFromSnippetWithRestrictionsAndOtherElements() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + Session session = driver.session(); initialiseGraphDB(neo4j.defaultDatabaseService(), "{ handleVocabUris: 'IGNORE'}"); @@ -451,13 +458,11 @@ public void testOntoPreviewFromSnippetWithRestrictionsAndOtherElements() throws } } - } } @Test public void testOntoPreviewFromSnippetWithCardinalityRestrictions() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + Session session = driver.session(); initialiseGraphDB(neo4j.defaultDatabaseService(), "{ handleVocabUris: 'IGNORE'}"); @@ -498,13 +503,11 @@ public void testOntoPreviewFromSnippetWithCardinalityRestrictions() throws Excep assertEquals("hasUnit", nodeAsMap.get("name")); } } - } } @Test public void testOntoPreviewFromFileLimit() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + Session session = driver.session(); initialiseGraphDB(neo4j.defaultDatabaseService(), "{}"); @@ -533,15 +536,11 @@ public void testOntoPreviewFromFileLimit() throws Exception { assertEquals(2, nodes.size()); rels = (List) next.get("relationships"); assertEquals(0, rels.size()); - } } @Test public void ontoImportTest() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - initialiseGraphDB(neo4j.defaultDatabaseService(), "{ baseSchemaNamespace : 'http://basenamespace#' }"); Session session = driver.session(); @@ -561,14 +560,10 @@ public void ontoImportTest() throws Exception { assertEquals(6L, session.run("MATCH (n:n4sch__Relationship) RETURN count(n) AS count").next().get("count") .asLong()); - } - } @Test public void ontoImportTestWithRelCharacteristicsMultival() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { initialiseGraphDB(neo4j.defaultDatabaseService(), "{ baseSchemaNamespace : 'http://basenamespace#' , handleMultival: 'ARRAY'}"); @@ -601,15 +596,11 @@ public void ontoImportTestWithRelCharacteristicsMultival() throws Exception { assertTrue(propCharsForReviewed.contains("InverseFunctional")); assertTrue(propCharsForReviewed.contains("Functional")); assertTrue(propCharsForReviewed.size() == 2); - } } @Test public void ontoImportTestWithRelCharacteristicsOverwrite() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - initialiseGraphDB(neo4j.defaultDatabaseService(), "{}"); Session session = driver.session(); @@ -623,16 +614,10 @@ public void ontoImportTestWithRelCharacteristicsOverwrite() throws Exception { assertEquals("Functional",session.run("MATCH (n:n4sch__Relationship { n4sch__name: 'REVIEWED'} ) " + "RETURN n.n4sch__propCharacteristics AS pc").next().get("pc").asString()); - - } - } @Test public void ontoSnippetImportTest() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - initialiseGraphDB(neo4j.defaultDatabaseService(), null); Session session = driver.session(); @@ -655,15 +640,10 @@ public void ontoSnippetImportTest() throws Exception { assertEquals(6L, session.run("MATCH (n:n4sch__Relationship) RETURN count(n) AS count").next().get("count") .asLong()); - } - } @Test public void ontoImportWithCustomNames() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - initialiseGraphDB(neo4j.defaultDatabaseService(), " { classLabel : 'Category', objectPropertyLabel: 'Rel', " + "dataTypePropertyLabel: 'Prop', baseSchemaNamespace: 'http://base.org/voc#'}"); @@ -702,16 +682,10 @@ public void ontoImportWithCustomNames() throws Exception { assertEquals(13L, session.run("MATCH (n:Resource) RETURN count(distinct n.n4sch__comment) AS count") .next().get("count").asLong()); - - } - } @Test public void ontoImportWithCustomNamesIgnoreMode() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - initialiseGraphDB(neo4j.defaultDatabaseService(), " { classLabel : 'Category', objectPropertyLabel: 'Rel', dataTypePropertyLabel: 'Prop', handleVocabUris: 'IGNORE'}"); Session session = driver.session(); @@ -749,17 +723,11 @@ public void ontoImportWithCustomNamesIgnoreMode() throws Exception { assertEquals(13L, session.run("MATCH (n:Resource) RETURN count(distinct n.comment) AS count") .next().get("count").asLong()); - - } - } @Test public void ontoSnippetImportWithCustomNames() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - initialiseGraphDB(neo4j.defaultDatabaseService(), "{ classLabel : 'Category', objectPropertyLabel: 'Rel', dataTypePropertyLabel: 'Prop', handleVocabUris: 'IGNORE'}"); Session session = driver.session(); @@ -799,16 +767,10 @@ public void ontoSnippetImportWithCustomNames() throws Exception { assertEquals(13L, session.run("MATCH (n:Resource) RETURN count(distinct n.comment) AS count") .next().get("count").asLong()); - - } - } @Test public void ontoImportWithCustomNamesFilterLabels() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - initialiseGraphDB(neo4j.defaultDatabaseService(), "{ classLabel : 'Category', " + "objectPropertyLabel: 'Rel', dataTypePropertyLabel: 'Prop' , handleVocabUris: 'IGNORE' }"); Session session = driver.session(); @@ -850,16 +812,10 @@ public void ontoImportWithCustomNamesFilterLabels() throws Exception { assertEquals(0L, session.run("MATCH (n:Resource) RETURN count(distinct n.comment) AS count") .next().get("count").asLong()); - - } - } @Test public void ontoSnippetImportWithCustomNamesFilterLabels() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - initialiseGraphDB(neo4j.defaultDatabaseService(), "{ classLabel : 'Category', " + " objectPropertyLabel: 'Rel', dataTypePropertyLabel: 'Prop' , handleVocabUris: 'IGNORE' }"); Session session = driver.session(); @@ -903,16 +859,10 @@ public void ontoSnippetImportWithCustomNamesFilterLabels() throws Exception { assertEquals(0L, session.run("MATCH (n:Resource) RETURN count(distinct n.comment) AS count") .next().get("count").asLong()); - - } - } @Test public void ontoImportSchemaOrg() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - initialiseGraphDB(neo4j.defaultDatabaseService(), null); Session session = driver.session(); @@ -939,15 +889,10 @@ public void ontoImportSchemaOrg() throws Exception { session.run("MATCH (n:n4sch__Relationship) RETURN count(n) AS count").next().get("count") .asLong()); session.close(); - } - } @Test public void ontoImportClassHierarchy() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - initialiseGraphDB(neo4j.defaultDatabaseService(), null); Session session = driver.session(); @@ -962,14 +907,10 @@ public void ontoImportClassHierarchy() throws Exception { session.run("MATCH p=(:n4sch__Class{ n4sch__name:'Code'})-[:n4sch__SCO]->(:n4sch__Class{ n4sch__name:'Intangible'})" + " RETURN count(p) AS count").next().get("count").asLong()); session.close(); - } } @Test public void ontoImportPropHierarchy() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - initialiseGraphDB(neo4j.defaultDatabaseService(), " { baseSchemaPrefix : 'basevoc' }"); Session session = driver.session(); @@ -981,15 +922,11 @@ public void ontoImportPropHierarchy() throws Exception { session.run("MATCH p=(:basevoc__Property { basevoc__name:'prop1'})-[:basevoc__SPO]->(:basevoc__Property{ basevoc__name:'superprop'})" + " RETURN count(p) AS count").next().get("count").asLong()); session.close(); - } } @Test public void ontoImportMultilabel() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - - initialiseGraphDB(neo4j.defaultDatabaseService(), + initialiseGraphDB(neo4j.defaultDatabaseService(), "{ keepLangTag: true, handleMultival: 'ARRAY' , handleVocabUris: 'MAP' } "); //, handleVocabUris: 'IGNORE' Session session = driver.session(); @@ -1057,17 +994,11 @@ public void ontoImportMultilabel() throws Exception { assertEquals("titulo", singleRecord.get("label_es").asString()); assertEquals("The title of a film", singleRecord.get("comment_en").asString()); assertEquals("El titulo de una pelicula", singleRecord.get("comment_es").asString()); - - } - } @Test public void ontoSnippetImportMultilabel() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - initialiseGraphDB(neo4j.defaultDatabaseService(), "{ keepLangTag: true, handleMultival: 'ARRAY', handleVocabUris: 'IGNORE' }"); Session session = driver.session(); @@ -1137,17 +1068,11 @@ public void ontoSnippetImportMultilabel() throws Exception { assertEquals("titulo", singleRecord.get("label_es").asString()); assertEquals("The title of a film", singleRecord.get("comment_en").asString()); assertEquals("El titulo de una pelicula", singleRecord.get("comment_es").asString()); - - } - } @Test public void ontoSnippetImportRestrictions() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - initialiseGraphDB(neo4j.defaultDatabaseService(), "{ handleVocabUris: 'IGNORE' }"); Session session = driver.session(); @@ -1228,17 +1153,10 @@ public void ontoSnippetImportRestrictions() throws Exception { assertEquals(1L, session.run("MATCH ()-[r:SCO_RESTRICTION { restrictionType:'ALL'}]->() RETURN count(r) AS count").next().get("count") .asLong()); - - - } - } @Test public void ontoSnippetImportRestrictionsImplicitClass() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - initialiseGraphDB(neo4j.defaultDatabaseService(), "{ handleVocabUris: 'IGNORE' }"); Session session = driver.session(); @@ -1254,7 +1172,6 @@ public void ontoSnippetImportRestrictionsImplicitClass() throws Exception { assertEquals(8L, next.get("triplesLoaded").asLong()); assertEquals(8L, next.get("triplesParsed").asLong()); - } } // @Test @@ -1293,6 +1210,4 @@ private void initialiseGraphDB(GraphDatabaseService db, String graphConfigParams db.executeTransactionally("CALL n10s.graphconfig.init(" + (graphConfigParams != null ? graphConfigParams : "{}") + ")"); } - - } diff --git a/src/test/java/n10s/validation/SHACLValidationProceduresTest.java b/src/test/java/n10s/validation/SHACLValidationProceduresTest.java index f0bbc725..e125e05b 100644 --- a/src/test/java/n10s/validation/SHACLValidationProceduresTest.java +++ b/src/test/java/n10s/validation/SHACLValidationProceduresTest.java @@ -15,12 +15,13 @@ import n10s.aux.AuxProcedures; import n10s.graphconfig.GraphConfigProcedures; import n10s.nsprefixes.NsPrefixDefProcedures; +import n10s.onto.load.OntoLoadProcedures; +import n10s.onto.preview.OntoPreviewProcedures; import n10s.rdf.RDFProcedures; import n10s.rdf.load.RDFLoadProcedures; import org.eclipse.rdf4j.model.impl.SimpleValueFactory; import org.eclipse.rdf4j.model.vocabulary.SHACL; -import org.junit.Rule; -import org.junit.Test; +import org.junit.*; import org.neo4j.driver.*; import org.neo4j.driver.Record; import org.neo4j.driver.types.Node; @@ -64,18 +65,33 @@ public class SHACLValidationProceduresTest { + " toString(([(vr)-[:`http://www.w3.org/ns/shacl#value`]->(x)| x.uri] + ([] + coalesce(vr.`http://www.w3.org/ns/shacl#value`,[])))[0]) as offendingValue, " + " vr.`http://www.w3.org/ns/shacl#resultMessage` as message"; - @Rule - public Neo4jRule neo4j = new Neo4jRule() - .withProcedure(ValidationProcedures.class).withProcedure(GraphConfigProcedures.class) - .withProcedure(RDFLoadProcedures.class).withFunction(RDFProcedures.class).withProcedure( - NsPrefixDefProcedures.class).withFunction(AuxProcedures.class); + public static Driver driver; + @ClassRule + public static Neo4jRule neo4j = new Neo4jRule() + .withProcedure(ValidationProcedures.class) + .withProcedure(GraphConfigProcedures.class) + .withProcedure(RDFLoadProcedures.class) + .withFunction(RDFProcedures.class) + .withProcedure(NsPrefixDefProcedures.class) + .withFunction(AuxProcedures.class); + + @BeforeClass + public static void init() { + driver = GraphDatabase.driver(neo4j.boltURI(), + Config.builder().withoutEncryption().build()); + } + + @Before + public void cleanDatabase() { + driver.session().run("match (n) detach delete n").consume(); + driver.session().run("drop constraint n10s_unique_uri if exists").consume(); + } + + final String CREATE_N10S_CONSTRAINT = "CREATE CONSTRAINT n10s_unique_uri FOR ( resource:Resource ) REQUIRE (resource.uri) IS UNIQUE"; @Test public void testCompiledValidatorIsPersisted() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - Session session = driver.session(); assertFalse(session.run("MATCH (n) RETURN n").hasNext()); @@ -151,15 +167,11 @@ public void testCompiledValidatorIsPersisted() throws Exception { Result loadCompiled = session.run("call n10s.validation.shacl.validate()"); assertTrue(loadCompiled.hasNext()); - } } @Test public void testUriWithWhitespaces() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - Session session = driver.session(); String SHACL_URI_WHITESPACES = "@prefix neo4j: .\n" + @@ -190,14 +202,10 @@ public void testUriWithWhitespaces() throws Exception { List targetClasses = results.next().get("t").asList(); assertTrue(targetClasses.size()==1); assertEquals("Soccer Player", targetClasses.get(0)); - } } @Test public void testLargeShapesFile() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - Session session = driver.session(); assertFalse(session.run("MATCH (n) RETURN n").hasNext()); @@ -238,7 +246,6 @@ public void testLargeShapesFile() throws Exception { } assertEquals(3, minCountCount); assertEquals(3, datatypeConstCount); - } } String SHAPES_CLOSED_NO_EXCLUSION = "@prefix rdf: .\n" + @@ -297,17 +304,15 @@ public void testLargeShapesFile() throws Exception { @Test public void testClosedShapeIgnore() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { assertFalse(session.run("MATCH (n) RETURN n").hasNext()); - session.run("CREATE CONSTRAINT n10s_unique_uri FOR ( resource:Resource ) REQUIRE resource.uri IS UNIQUE "); + session.run(CREATE_N10S_CONSTRAINT); session.run("call n10s.graphconfig.init({handleRDFTypes:\"LABELS_AND_NODES\",handleMultival:\"ARRAY\"});\n"); session.run("call n10s.nsprefixes.add(\"ex\", \"http://www.example.com/device#\");"); session.run("CALL n10s.rdf.import.inline('" + SHAPES_CLOSED_DATA + "',\"RDF/XML\")"); } - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { Result results = session .run("CALL n10s.validation.shacl.import.inline(\"" + SHAPES_CLOSED_NO_EXCLUSION + "\",\"Turtle\")"); @@ -321,17 +326,15 @@ public void testClosedShapeIgnore() throws Exception { @Test public void testClosedShapeNoExclusion() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { assertFalse(session.run("MATCH (n) RETURN n").hasNext()); - session.run("CREATE CONSTRAINT n10s_unique_uri FOR ( resource:Resource ) REQUIRE resource.uri IS UNIQUE "); + session.run(CREATE_N10S_CONSTRAINT); session.run("call n10s.graphconfig.init({handleRDFTypes:\"LABELS_AND_NODES\",handleMultival:\"ARRAY\"});\n"); session.run("call n10s.nsprefixes.add(\"ex\", \"http://www.example.com/device#\");"); session.run("CALL n10s.rdf.import.inline('" + SHAPES_CLOSED_DATA + "',\"RDF/XML\")"); } - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { Result results = session .run("CALL n10s.validation.shacl.import.inline(\"" + SHAPES_CLOSED_NO_EXCLUSION + "\",\"Turtle\")"); @@ -374,18 +377,16 @@ public void testClosedShapeNoExclusion() throws Exception { @Test public void testDataTypeShape() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { assertFalse(session.run("MATCH (n) RETURN n").hasNext()); - session.run("CREATE CONSTRAINT n10s_unique_uri FOR ( resource:Resource ) REQUIRE resource.uri IS UNIQUE "); + session.run(CREATE_N10S_CONSTRAINT); session.run("CALL n10s.graphconfig.init()"); session.run("call n10s.nsprefixes.add(\"o1\",\"http://adaptive.accenture.com/ontologies/o1#\")"); session.run("call n10s.nsprefixes.add(\"ind\",\"http://adaptive.accenture.com/ind#\")"); session.run("CALL n10s.rdf.import.inline('" + DATE_DATA_1 + "',\"N-Triples\")"); } - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { Result results = session .run("CALL n10s.validation.shacl.import.inline(\"" + DATE_TYPE_CONSTRAINT + "\",\"Turtle\", {})"); @@ -431,18 +432,16 @@ public void testDataTypeShape() throws Exception { @Test public void testDataTypeShapeDataTypeRestrictedPropUsedAsRel() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { assertFalse(session.run("MATCH (n) RETURN n").hasNext()); - session.run("CREATE CONSTRAINT n10s_unique_uri FOR ( resource:Resource ) REQUIRE resource.uri IS UNIQUE "); + session.run(CREATE_N10S_CONSTRAINT); session.run("CALL n10s.graphconfig.init()"); session.run("call n10s.nsprefixes.add(\"o1\",\"http://adaptive.accenture.com/ontologies/o1#\")"); session.run("call n10s.nsprefixes.add(\"ind\",\"http://adaptive.accenture.com/ind#\")"); session.run("CALL n10s.rdf.import.inline('" + DATE_DATA_WHERE_PROP_IS_USED_AS_REL + "',\"N-Triples\")"); } - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { Result results = session .run("CALL n10s.validation.shacl.import.inline(\"" + DATE_TYPE_CONSTRAINT + "\",\"Turtle\", {})"); @@ -507,18 +506,16 @@ public void testDataTypeShapeDataTypeRestrictedPropUsedAsRel() throws Exception @Test public void testDataTypeShapeDataPointAndDate() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { assertFalse(session.run("MATCH (n) RETURN n").hasNext()); - session.run("CREATE CONSTRAINT n10s_unique_uri FOR ( resource:Resource ) REQUIRE resource.uri IS UNIQUE "); + session.run(CREATE_N10S_CONSTRAINT); session.run("CALL n10s.graphconfig.init()"); session.run("call n10s.nsprefixes.add(\"o1\",\"http://adaptive.accenture.com/ontologies/o1#\")"); session.run("call n10s.nsprefixes.add(\"ind\",\"http://adaptive.accenture.com/ind#\")"); session.run("CALL n10s.rdf.import.inline('" + DATE_DATA_POINT_AND_TYPE + "',\"N-Triples\")"); } - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { Result results = session @@ -588,18 +585,16 @@ public void testDataTypeShapeDataPointAndDate() throws Exception { @Test public void testDataTypeShapeAnyUri() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { assertFalse(session.run("MATCH (n) RETURN n").hasNext()); - session.run("CREATE CONSTRAINT n10s_unique_uri FOR ( resource:Resource ) REQUIRE resource.uri IS UNIQUE "); + session.run(CREATE_N10S_CONSTRAINT); session.run("CALL n10s.graphconfig.init()"); session.run("call n10s.nsprefixes.add(\"o1\",\"http://adaptive.accenture.com/ontologies/o1#\")"); session.run("call n10s.nsprefixes.add(\"ind\",\"http://adaptive.accenture.com/ind#\")"); session.run("CALL n10s.rdf.import.inline('" + DATE_DATA_ANYURI + "',\"N-Triples\")"); } - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { Result results = session @@ -637,18 +632,16 @@ public void testDataTypeShapeAnyUri() throws Exception { @Test public void testMusicExample() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { assertFalse(session.run("MATCH (n) RETURN n").hasNext()); - session.run("CREATE CONSTRAINT n10s_unique_uri FOR ( resource:Resource ) REQUIRE resource.uri IS UNIQUE "); + session.run(CREATE_N10S_CONSTRAINT); session.run("CALL n10s.graphconfig.init( { handleMultival: 'ARRAY', " + "multivalPropList: [ 'http://stardog.com/tutorial/date'] })"); session.run("CALL n10s.nsprefixes.add('tut','http://stardog.com/tutorial/')"); session.close(); } - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { Result loadShapes = session.run( "CALL n10s.validation.shacl.import.fetch(\"" + SHACLValidationProceduresTest.class @@ -701,9 +694,6 @@ public void testMusicExample() throws Exception { @Test public void testRegexValidationOnMovieDB() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - Session session = driver.session(); assertFalse(session.run("MATCH (n) RETURN n").hasNext()); @@ -723,7 +713,7 @@ public void testRegexValidationOnMovieDB() throws Exception { " (RosieO)-[:ACTED_IN {roles:['Becky']}]->(SleeplessInSeattle),\n" + " (NoraE)-[:DIRECTED]->(SleeplessInSeattle) "); - session.run("CREATE CONSTRAINT n10s_unique_uri FOR ( resource:Resource ) REQUIRE resource.uri IS UNIQUE "); + session.run(CREATE_N10S_CONSTRAINT); session.run("CALL n10s.validation.shacl.import.fetch(\"" + SHACLValidationProceduresTest.class .getClassLoader() @@ -746,15 +736,10 @@ public void testRegexValidationOnMovieDB() throws Exception { next.get("propertyShape").asString()); } } - - } } @Test public void testBug213() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - Session session = driver.session(); assertFalse(session.run("MATCH (n) RETURN n").hasNext()); @@ -811,21 +796,14 @@ public void testBug213() throws Exception { next.get("resultMessage").asString()); assertEquals(false, validationResults.hasNext()); - - } - - } @Test public void testValidationBeforeNsDefined() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - Session session = driver.session(); assertFalse(session.run("MATCH (n) RETURN n").hasNext()); - session.run("CREATE CONSTRAINT n10s_unique_uri FOR ( resource:Resource ) REQUIRE resource.uri IS UNIQUE "); + session.run(CREATE_N10S_CONSTRAINT); session.run("CALL n10s.graphconfig.init()"); Result result = session.run( "CALL n10s.validation.shacl.import.fetch(\"" + SHACLValidationProceduresTest.class @@ -847,14 +825,10 @@ public void testValidationBeforeNsDefined() throws Exception { .getResource("shacl/person2-shacl.ttl") .toURI() + "\",\"Turtle\", {})"); assertTrue(result.hasNext()); - } } @Test public void testLoadShapesOutput() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - Session session = driver.session(); assertFalse(session.run("MATCH (n) RETURN n").hasNext()); @@ -898,7 +872,7 @@ public void testLoadShapesOutput() throws Exception { session.run("MATCH (n) DETACH DELETE n"); assertFalse(session.run("MATCH (n) RETURN n").hasNext()); //RDF SHORTEN GRAPH - session.run("CREATE CONSTRAINT n10s_unique_uri FOR ( resource:Resource ) REQUIRE resource.uri IS UNIQUE "); + session.run(CREATE_N10S_CONSTRAINT); session.run("CALL n10s.graphconfig.init()"); session.run("CALL n10s.nsprefixes.add('neo','neo4j://graph.schema#')"); session.run("CALL n10s.nsprefixes.add('ex','http://example/')"); @@ -1017,19 +991,14 @@ public void testLoadShapesOutput() throws Exception { } } assertEquals(4, matches); - } } @Test public void testListAndDropShapesInRDFIgnoreGraph() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - Session session = driver.session(); session.run("CALL n10s.graphconfig.init({ handleVocabUris: 'IGNORE' })"); - - session.run("CREATE CONSTRAINT n10s_unique_uri FOR ( resource:Resource ) REQUIRE resource.uri IS UNIQUE "); + session.run(CREATE_N10S_CONSTRAINT); session.run("CALL n10s.validation.shacl.import.fetch(\"" + SHACLValidationProceduresTest.class .getClassLoader() @@ -1076,21 +1045,15 @@ public void testListAndDropShapesInRDFIgnoreGraph() throws Exception { //Expected assertTrue(e.getMessage().contains("n10s.validation.SHACLValidationException: No shapes compiled")); } - - - } } @Test public void testListShapesInRDFShortenGraph() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - Session session = driver.session(); session.run("CALL n10s.graphconfig.init()"); - - session.run("CREATE CONSTRAINT n10s_unique_uri FOR ( resource:Resource ) REQUIRE resource.uri IS UNIQUE "); + + session.run(CREATE_N10S_CONSTRAINT); String turtleNsDefinition = "@prefix ex: .\n" + "@prefix neo4j: .\n" @@ -1145,16 +1108,10 @@ public void testListShapesInRDFShortenGraph() throws Exception { //Expected assertTrue(e.getMessage().contains("n10s.validation.SHACLValidationException: No shapes compiled")); } - - - } } @Test public void testTxTriggerValidation() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - Session session = driver.session(); assertFalse(session.run("MATCH (n) RETURN n").hasNext()); @@ -1198,8 +1155,6 @@ public void testTxTriggerValidation() throws Exception { //This is expected assertTrue(e.getMessage().contains("SHACLValidationException")); } - - } } @@ -1474,8 +1429,6 @@ public void testRunTestSuite14() throws Exception { public void runIndividualTest(String testGroupName, String testName, String cypherScript, String handleVocabUris, String ... overrideShapesFileName) throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { Session session = driver.session(); Result getschemastatementsResults = session @@ -1634,12 +1587,6 @@ public void runIndividualTest(String testGroupName, String testName, } session.run("MATCH (n) DETACH DELETE n ").hasNext(); - - } catch (Exception e) { - assertTrue("Failure due to exception raised: " + e.getMessage(), false); - } - - } private String selectQuery(String handleVocabUris) { @@ -1656,9 +1603,6 @@ private String selectQuery(String handleVocabUris) { @Test public void testHasTypeValidationOnMovieDB() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build())) { - Session session = driver.session(); assertFalse(session.run("MATCH (n) RETURN n").hasNext()); @@ -1746,7 +1690,6 @@ public void testHasTypeValidationOnMovieDB() throws Exception { } } assertEquals(2,count); - } } String SHAPES_REQUIRED_EXCLUDED_TYPES = "@prefix ex: .\n" + @@ -1796,14 +1739,12 @@ public void testHasTypeValidationOnMovieDB() throws Exception { @Test public void testRequiredAndExcludedTypes() throws Exception { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { assertFalse(session.run("MATCH (n) RETURN n").hasNext()); session.run("create (:Man { name: 'JB'}) "); session.run("create (:Person:Woman:Man { name: 'Carol'}) "); } - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { Result results = session .run("CALL n10s.validation.shacl.import.inline('" + SHAPES_REQUIRED_EXCLUDED_TYPES + "',\"Turtle\")"); @@ -1886,8 +1827,7 @@ public void testBadQueriesInConstraint() throws Exception { } private void verifyBadCypher(String query) { - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), - Config.builder().withoutEncryption().build()); Session session = driver.session()) { + try (Session session = driver.session()) { Result results = session .run("CALL n10s.validation.shacl.import.inline('" + query + "',\"Turtle\")");