|
16 | 16 | import org.eclipse.rdf4j.model.Statement;
|
17 | 17 | import org.eclipse.rdf4j.model.ValueFactory;
|
18 | 18 | import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
|
| 19 | +import org.eclipse.rdf4j.model.vocabulary.FOAF; |
19 | 20 | import org.eclipse.rdf4j.model.vocabulary.RDF;
|
20 | 21 | import org.eclipse.rdf4j.model.vocabulary.XSD;
|
21 | 22 | import org.eclipse.rdf4j.rio.RDFFormat;
|
@@ -46,7 +47,7 @@ public class RDFExportTest {
|
46 | 47 |
|
47 | 48 |
|
48 | 49 | @Test
|
49 |
| - public void testExportFromCypher() throws Exception { |
| 50 | + public void testExportFromCypherOnLPG() throws Exception { |
50 | 51 | try (Driver driver = GraphDatabase.driver(neo4j.boltURI(),
|
51 | 52 | Config.builder().withoutEncryption().build()); Session session = driver.session()) {
|
52 | 53 |
|
@@ -79,6 +80,97 @@ public void testExportFromCypher() throws Exception {
|
79 | 80 | }
|
80 | 81 | }
|
81 | 82 |
|
| 83 | + @Test |
| 84 | + public void testExportFromCypherOnLPGWithMappings() throws Exception { |
| 85 | + try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), |
| 86 | + Config.builder().withoutEncryption().build()); Session session = driver.session()) { |
| 87 | + |
| 88 | + session |
| 89 | + .run( |
| 90 | + "CREATE (n:Node { a: 1, b: 'hello' })-[:CONNECTED_TO]->(:Node { a:2, b2:'bye@en'})"); |
| 91 | + |
| 92 | + session.run("call n10s.nsprefixes.add('foaf','http://xmlns.com/foaf/0.1/')"); |
| 93 | + session.run("call n10s.nsprefixes.add('myv','http://myvoc.org/testing#')"); |
| 94 | + assertEquals(2L, session.run("call n10s.nsprefixes.list() yield prefix return count(*) as ct").next().get("ct").asLong()); |
| 95 | + session.run("call n10s.mapping.add('http://xmlns.com/foaf/0.1/linkedTo','CONNECTED_TO')"); |
| 96 | + session.run("call n10s.mapping.add('http://xmlns.com/foaf/0.1/Thang','Node')"); |
| 97 | + session.run("call n10s.mapping.add('http://myvoc.org/testing#propA','a')"); |
| 98 | + session.run("call n10s.mapping.add('http://myvoc.org/testing#propB','b')"); |
| 99 | + List<Object> mappings = session.run("call n10s.mapping.list() yield schemaNs, schemaElement, elemName\n" + |
| 100 | + "return collect ({uri: schemaNs + schemaElement, elem: elemName}) as m").next().get("m").asList(); |
| 101 | + assertEquals(4L, mappings.size()); |
| 102 | + |
| 103 | + |
| 104 | + Result res |
| 105 | + = session |
| 106 | + .run(" CALL n10s.rdf.export.cypher(' MATCH path = (n)-[r]->(m) RETURN path ', {}) "); |
| 107 | + assertTrue(res.hasNext()); |
| 108 | + |
| 109 | + final ValueFactory vf = SimpleValueFactory.getInstance(); |
| 110 | + Set<Statement> expectedStatememts = new HashSet<>(Arrays.asList( |
| 111 | + vf.createStatement(vf.createIRI(BASE_INDIV_NS + "0"), RDF.TYPE, vf.createIRI("http://xmlns.com/foaf/0.1/Thang")), |
| 112 | + vf.createStatement(vf.createIRI(BASE_INDIV_NS + "0"), vf.createIRI("http://myvoc.org/testing#propA"), vf.createLiteral(1L)), |
| 113 | + vf.createStatement(vf.createIRI(BASE_INDIV_NS + "0"), vf.createIRI("http://myvoc.org/testing#propB"), vf.createLiteral("hello")), |
| 114 | + vf.createStatement(vf.createIRI(BASE_INDIV_NS + "0"), vf.createIRI("http://xmlns.com/foaf/0.1/linkedTo"), vf.createIRI(BASE_INDIV_NS + "1")), |
| 115 | + vf.createStatement(vf.createIRI(BASE_INDIV_NS + "1"), RDF.TYPE, vf.createIRI("http://xmlns.com/foaf/0.1/Thang")), |
| 116 | + vf.createStatement(vf.createIRI(BASE_INDIV_NS + "1"), vf.createIRI(DEFAULT_BASE_SCH_NS + "b2"), vf.createLiteral("bye","en")), |
| 117 | + vf.createStatement(vf.createIRI(BASE_INDIV_NS + "1"), vf.createIRI("http://myvoc.org/testing#propA"), vf.createLiteral(2L)))); |
| 118 | + |
| 119 | + int resultCount = 0; |
| 120 | + while (res.hasNext()) { |
| 121 | + Statement returnedStatement = recordAsStatement(vf, res.next()); |
| 122 | + assertTrue(expectedStatememts.contains(returnedStatement)); |
| 123 | + resultCount++; |
| 124 | + } |
| 125 | + assertEquals(resultCount,expectedStatememts.size()); |
| 126 | + } |
| 127 | + } |
| 128 | + |
| 129 | + @Test |
| 130 | + public void testExportFromCypherOnRDF() throws Exception { |
| 131 | + try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), |
| 132 | + Config.builder().withoutEncryption().build())) { |
| 133 | + |
| 134 | + Session session = driver.session(); |
| 135 | + |
| 136 | + initialiseGraphDB(neo4j.defaultDatabaseService(), |
| 137 | + " { handleVocabUris: 'SHORTEN' } "); |
| 138 | + |
| 139 | + } |
| 140 | + try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), |
| 141 | + Config.builder().withoutEncryption().build()); Session session = driver.session()) { |
| 142 | + |
| 143 | + Result importResults1 = session.run("CALL n10s.rdf.import.inline('" + |
| 144 | + jsonLdFragment + "','JSON-LD')"); |
| 145 | + assertEquals(11L, importResults1.single().get("triplesLoaded").asLong()); |
| 146 | + |
| 147 | + Result res |
| 148 | + = session |
| 149 | + .run(" CALL n10s.rdf.export.cypher(' MATCH path = (n)-[r]->(m) RETURN path ', {}) "); |
| 150 | + assertTrue(res.hasNext()); |
| 151 | + |
| 152 | + final ValueFactory vf = SimpleValueFactory.getInstance(); |
| 153 | + Set<Statement> expectedStatememts = new HashSet<>(Arrays.asList( |
| 154 | + vf.createStatement(vf.createIRI("http://me.markus-lanthaler.com/"), RDF.TYPE, vf.createIRI("http://xmlns.com/foaf/0.1/Individual")), |
| 155 | + vf.createStatement(vf.createIRI("http://me.markus-lanthaler.com/"), FOAF.NAME, vf.createLiteral("Markus Lanthaler")), |
| 156 | + vf.createStatement(vf.createIRI("http://me.markus-lanthaler.com/"), FOAF.KNOWS, vf.createIRI("http://manu.sporny.org/about#manu")), |
| 157 | + vf.createStatement(vf.createIRI("http://manu.sporny.org/about#manu"), RDF.TYPE,vf.createIRI("http://xmlns.com/foaf/0.1/Subject")), |
| 158 | + vf.createStatement(vf.createIRI("http://manu.sporny.org/about#manu"), FOAF.NAME, vf.createLiteral("Manu Sporny")), |
| 159 | + vf.createStatement(vf.createIRI("http://manu.sporny.org/about#manu"), RDF.TYPE,vf.createIRI("http://xmlns.com/foaf/0.1/Citizen")) |
| 160 | + )); |
| 161 | + |
| 162 | + int resultCount = 0; |
| 163 | + while (res.hasNext()) { |
| 164 | + Statement returnedStatement = recordAsStatement(vf, res.next()); |
| 165 | + assertTrue(returnedStatement.getSubject().stringValue().startsWith("bnode://") || |
| 166 | + returnedStatement.getObject().stringValue().startsWith("bnode://") || |
| 167 | + expectedStatememts.contains(returnedStatement)); |
| 168 | + resultCount++; |
| 169 | + } |
| 170 | + assertEquals(9,resultCount); |
| 171 | + } |
| 172 | + } |
| 173 | + |
82 | 174 | private Statement recordAsStatement(ValueFactory vf, Record r) {
|
83 | 175 | IRI s = vf.createIRI(r.get("subject").asString());
|
84 | 176 | IRI p = vf.createIRI(r.get("predicate").asString());
|
|
0 commit comments