|
24 | 24 | import org.eclipse.rdf4j.model.Statement; |
25 | 25 | import org.eclipse.rdf4j.model.util.Values; |
26 | 26 | import org.eclipse.rdf4j.model.vocabulary.DCTERMS; |
| 27 | +import org.eclipse.rdf4j.model.vocabulary.FOAF; |
| 28 | +import org.eclipse.rdf4j.model.vocabulary.RDF; |
27 | 29 | import org.eclipse.rdf4j.model.vocabulary.RDFS; |
28 | 30 | import org.eclipse.rdf4j.query.AbstractTupleQueryResultHandler; |
29 | 31 | import org.eclipse.rdf4j.query.BindingSet; |
|
35 | 37 | import org.eclipse.rdf4j.query.TupleQueryResult; |
36 | 38 | import org.eclipse.rdf4j.query.TupleQueryResultHandlerException; |
37 | 39 | import org.eclipse.rdf4j.query.impl.SimpleDataset; |
| 40 | +import org.eclipse.rdf4j.repository.Repository; |
38 | 41 | import org.eclipse.rdf4j.repository.RepositoryConnection; |
39 | 42 | import org.eclipse.rdf4j.repository.util.Repositories; |
40 | 43 | import org.junit.jupiter.api.Assertions; |
@@ -575,4 +578,83 @@ public void test_EscapingQuotedLiteral() throws Exception { |
575 | 578 | } |
576 | 579 |
|
577 | 580 | } |
| 581 | + |
| 582 | + @Test |
| 583 | + public void test_reduceFederation() throws Exception { |
| 584 | + |
| 585 | + List<Endpoint> endpoints = prepareTest( |
| 586 | + Arrays.asList("/tests/basic/data_emptyStore.ttl", "/tests/basic/data_emptyStore.ttl")); |
| 587 | + |
| 588 | + Repository repo1 = getRepository(1); |
| 589 | + Repository repo2 = getRepository(2); |
| 590 | + |
| 591 | + String repo1Id = endpoints.get(0).getId(); |
| 592 | + |
| 593 | + IRI graph1 = Values.iri("http://example.org/graph1"); |
| 594 | + IRI graph2 = Values.iri("http://example.org/graph2"); |
| 595 | + |
| 596 | + try (RepositoryConnection con = repo1.getConnection()) { |
| 597 | + con.add(Values.iri("http://example.org/repo1/p1"), RDF.TYPE, FOAF.PERSON, graph1); |
| 598 | + con.add(Values.iri("http://example.org/repo2/p2"), RDF.TYPE, FOAF.PERSON, graph2); |
| 599 | + } |
| 600 | + |
| 601 | + try (RepositoryConnection con = repo2.getConnection()) { |
| 602 | + con.add(Values.iri("http://example.org/repo2/p3"), RDF.TYPE, FOAF.PERSON, graph1); |
| 603 | + } |
| 604 | + |
| 605 | + Repository fedxRepo = fedxRule.getRepository(); |
| 606 | + |
| 607 | + // 1: regular federation |
| 608 | + try (RepositoryConnection con = fedxRepo.getConnection()) { |
| 609 | + TupleQuery tupleQuery = con.prepareTupleQuery( |
| 610 | + "PREFIX foaf: <http://xmlns.com/foaf/0.1/> " |
| 611 | + + "SELECT * WHERE { " |
| 612 | + + " ?subClass a foaf:Person. " |
| 613 | + + " } " |
| 614 | + ); |
| 615 | + |
| 616 | + // expect from both repos |
| 617 | + Assertions.assertEquals(3, QueryResults.asSet(tupleQuery.evaluate()).size()); |
| 618 | + |
| 619 | + // now we scope it additional to graph1 |
| 620 | + tupleQuery = con.prepareTupleQuery( |
| 621 | + "PREFIX foaf: <http://xmlns.com/foaf/0.1/> " |
| 622 | + + "SELECT * FROM <http://example.org/graph1> WHERE { " |
| 623 | + + " ?subClass a foaf:Person. " |
| 624 | + + " } "); |
| 625 | + |
| 626 | + // expect results defined in graph1 (1 in repo1, 2 from repo2) |
| 627 | + Assertions.assertEquals(2, QueryResults.asSet(tupleQuery.evaluate()).size()); |
| 628 | + } |
| 629 | + |
| 630 | + // 2: reduce to federation member 1 id |
| 631 | + // 2a: additionall restrict to named graph |
| 632 | + FedXDataset fedXDataset = new FedXDataset(new SimpleDataset()); |
| 633 | + fedXDataset.addEndpoint(repo1Id); |
| 634 | + |
| 635 | + try (RepositoryConnection con = fedxRepo.getConnection()) { |
| 636 | + TupleQuery tupleQuery = con.prepareTupleQuery( |
| 637 | + "PREFIX foaf: <http://xmlns.com/foaf/0.1/> " |
| 638 | + + "SELECT * WHERE { " |
| 639 | + + " ?subClass a foaf:Person. " |
| 640 | + + " } " |
| 641 | + ); |
| 642 | + tupleQuery.setDataset(fedXDataset); |
| 643 | + |
| 644 | + // expect result from repo 1 |
| 645 | + Assertions.assertEquals(2, QueryResults.asSet(tupleQuery.evaluate()).size()); |
| 646 | + |
| 647 | + // now we scope it additional to graph1 |
| 648 | + tupleQuery = con.prepareTupleQuery( |
| 649 | + "PREFIX foaf: <http://xmlns.com/foaf/0.1/> " |
| 650 | + + "SELECT * FROM <http://example.org/graph1> WHERE { " |
| 651 | + + " ?subClass a foaf:Person. " |
| 652 | + + " } "); |
| 653 | + tupleQuery.setDataset(fedXDataset); |
| 654 | + |
| 655 | + // expect result from graph1 from repo1 |
| 656 | + Assertions.assertEquals(1, QueryResults.asSet(tupleQuery.evaluate()).size()); |
| 657 | + } |
| 658 | + |
| 659 | + } |
578 | 660 | } |
0 commit comments