|
1 | 1 | package n10s.endpoint;
|
2 | 2 |
|
3 | 3 | import static n10s.graphconfig.Params.PREFIX_SEPARATOR;
|
4 |
| -import static org.junit.Assert.assertEquals; |
5 |
| -import static org.junit.Assert.assertNull; |
6 |
| -import static org.junit.Assert.assertTrue; |
| 4 | +import static org.junit.Assert.*; |
7 | 5 | import static org.neo4j.internal.helpers.collection.Iterators.count;
|
8 | 6 |
|
9 | 7 | import com.fasterxml.jackson.databind.ObjectMapper;
|
|
14 | 12 | import java.nio.charset.StandardCharsets;
|
15 | 13 | import java.nio.file.Files;
|
16 | 14 | import java.nio.file.Paths;
|
17 |
| -import java.util.HashMap; |
18 |
| -import java.util.Map; |
19 |
| -import java.util.Set; |
| 15 | +import java.util.*; |
| 16 | + |
20 | 17 | import n10s.ModelTestUtils;
|
21 | 18 | import n10s.graphconfig.GraphConfigProcedures;
|
22 | 19 | import n10s.mapping.MappingUtils;
|
|
26 | 23 | import n10s.quadrdf.load.QuadRDFLoadProcedures;
|
27 | 24 | import n10s.rdf.RDFProcedures;
|
28 | 25 | import n10s.rdf.delete.RDFDeleteProcedures;
|
| 26 | +import n10s.rdf.export.ExportProcessor; |
| 27 | +import n10s.rdf.export.RDFExportProcedures; |
29 | 28 | import n10s.rdf.load.RDFLoadProcedures;
|
30 | 29 | import n10s.validation.ValidationProcedures;
|
| 30 | +import org.eclipse.rdf4j.model.vocabulary.RDF; |
31 | 31 | import org.eclipse.rdf4j.rio.RDFFormat;
|
32 | 32 | import org.junit.Rule;
|
33 | 33 | import org.junit.Test;
|
@@ -60,7 +60,8 @@ public class RDFEndpointTest {
|
60 | 60 | .withProcedure(RDFDeleteProcedures.class)
|
61 | 61 | .withProcedure(OntoLoadProcedures.class)
|
62 | 62 | .withProcedure(NsPrefixDefProcedures.class)
|
63 |
| - .withProcedure(ValidationProcedures.class); |
| 63 | + .withProcedure(ValidationProcedures.class) |
| 64 | + .withProcedure(RDFExportProcedures.class); |
64 | 65 |
|
65 | 66 | @Rule
|
66 | 67 | public Neo4jRule temp = new Neo4jRule().withProcedure(RDFLoadProcedures.class)
|
@@ -2441,4 +2442,74 @@ public void testCypherOnQuadRDFAfterDeleteRDFBNodes() throws Exception {
|
2441 | 2442 |
|
2442 | 2443 | }
|
2443 | 2444 |
|
| 2445 | + |
| 2446 | + @Test |
| 2447 | + public void testTicket13061() throws Exception { |
| 2448 | + // Given |
| 2449 | + final GraphDatabaseService graphDatabaseService = neo4j.defaultDatabaseService(); |
| 2450 | + //create constraint |
| 2451 | + try (Transaction tx = graphDatabaseService.beginTx()) { |
| 2452 | + tx.execute("CREATE CONSTRAINT n10s_unique_uri " |
| 2453 | + + "ON (r:Resource) ASSERT r.uri IS UNIQUE"); |
| 2454 | + tx.commit(); |
| 2455 | + } |
| 2456 | + //create graph config and import RDF |
| 2457 | + try (Transaction tx = graphDatabaseService.beginTx()) { |
| 2458 | + tx.execute("CALL n10s.graphconfig.init(" + |
| 2459 | + "{ handleVocabUris: 'MAP', handleMultival: 'ARRAY', keepCustomDataTypes: true, keepLangTag: true})"); |
| 2460 | + Result importResult = tx.execute("CALL n10s.rdf.import.fetch('" + |
| 2461 | + RDFEndpointTest.class.getClassLoader().getResource("data13061.trig") |
| 2462 | + .toURI() + "','TriG',{})"); |
| 2463 | + |
| 2464 | + tx.commit(); |
| 2465 | + } catch (Exception e){ |
| 2466 | + fail("exception raised on rdf.import"); |
| 2467 | + } |
| 2468 | + // check data is correctly loaded |
| 2469 | + Long id; |
| 2470 | + try (Transaction tx = graphDatabaseService.beginTx()) { |
| 2471 | + Result result = tx.execute("match (n:ConceptScheme) return properties(n) as n, size((n)--()) as deg"); |
| 2472 | + Map<String, Object> next = result.next(); |
| 2473 | + Map<String,Object> n = (Map<String,Object>)next.get("n"); |
| 2474 | + long[] tcVals = (long[])n.get("topConcepts"); |
| 2475 | + assertEquals(3L, tcVals.length); |
| 2476 | + long[] expected = new long[]{0, 3, 5}; |
| 2477 | + assertTrue(Arrays.equals(tcVals, expected)); |
| 2478 | + assertEquals(1L, next.get("deg")); |
| 2479 | + |
| 2480 | + |
| 2481 | + Result res |
| 2482 | + = tx |
| 2483 | + .execute(" CALL n10s.rdf.export.cypher(' match(n:ConceptScheme) return n ', {}) "); |
| 2484 | + assertTrue(res.hasNext()); |
| 2485 | + while(res.hasNext()){ |
| 2486 | + Map<String, Object> triple = res.next(); |
| 2487 | + assertTrue(triple.get("subject").equals("http://data.elsevier.com/vocabulary/OmniScience")); |
| 2488 | + List<String> expectedList = new ArrayList<String>(); |
| 2489 | + expectedList.add("0"); |
| 2490 | + expectedList.add("3"); |
| 2491 | + expectedList.add("5"); |
| 2492 | + assertTrue((triple.get("predicate").equals(RDF.TYPE.stringValue()) && |
| 2493 | + triple.get("object").equals("neo4j://graph.schema#ConceptScheme")) |
| 2494 | + || (triple.get("predicate").equals("neo4j://graph.schema#topConcepts") && |
| 2495 | + expectedList.contains(triple.get("object"))) && |
| 2496 | + triple.get("isLiteral").equals(true) && triple.get("literalType").equals("http://www.w3.org/2001/XMLSchema#long")); |
| 2497 | + } |
| 2498 | + } |
| 2499 | + |
| 2500 | + Map<String, Object> map = new HashMap<>(); |
| 2501 | + map.put("cypher", "match(n:ConceptScheme) return n"); |
| 2502 | + |
| 2503 | + Response response = HTTP.withHeaders("Accept", "text/plain").POST( |
| 2504 | + HTTP.GET(neo4j.httpURI().resolve("rdf").toString()).location() + "neo4j/cypher", map); |
| 2505 | + |
| 2506 | + assertEquals(200, response.status()); |
| 2507 | + String expected = "<http://data.elsevier.com/vocabulary/OmniScience> <neo4j://graph.schema#topConcepts> \"5\"^^<http://www.w3.org/2001/XMLSchema#long> .\n" + |
| 2508 | + "<http://data.elsevier.com/vocabulary/OmniScience> <neo4j://graph.schema#topConcepts> \"3\"^^<http://www.w3.org/2001/XMLSchema#long> .\n" + |
| 2509 | + "<http://data.elsevier.com/vocabulary/OmniScience> <neo4j://graph.schema#topConcepts> \"0\"^^<http://www.w3.org/2001/XMLSchema#long> .\n" + |
| 2510 | + "<http://data.elsevier.com/vocabulary/OmniScience> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <neo4j://graph.schema#ConceptScheme> .\n"; |
| 2511 | + assertTrue(ModelTestUtils |
| 2512 | + .compareModels(expected, RDFFormat.NTRIPLES, response.rawContent(), RDFFormat.TURTLE)); |
| 2513 | + } |
| 2514 | + |
2444 | 2515 | }
|
0 commit comments