Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 6A9AF200D5E for ; Sat, 23 Dec 2017 21:15:43 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 68F8F160BFD; Sat, 23 Dec 2017 20:15:43 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 76A44160C3D for ; Sat, 23 Dec 2017 21:15:40 +0100 (CET) Received: (qmail 89733 invoked by uid 500); 23 Dec 2017 20:15:39 -0000 Mailing-List: contact notifications-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list notifications@commons.apache.org Received: (qmail 89705 invoked by uid 99); 23 Dec 2017 20:15:39 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 23 Dec 2017 20:15:39 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 381D73A0C3F for ; Sat, 23 Dec 2017 20:15:36 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1022644 [19/31] - in /websites/production/commons/content/proper/commons-rdf: ./ apidocs/ apidocs/org/apache/commons/rdf/api/ apidocs/org/apache/commons/rdf/api/class-use/ apidocs/org/apache/commons/rdf/experimental/ apidocs/org/apache/com... Date: Sat, 23 Dec 2017 20:15:33 -0000 To: notifications@commons.apache.org From: wikier@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20171223201536.381D73A0C3F@svn01-us-west.apache.org> archived-at: Sat, 23 Dec 2017 20:15:43 -0000 Modified: websites/production/commons/content/proper/commons-rdf/xref-test/org/apache/commons/rdf/api/AbstractDatasetTest.html ============================================================================== --- websites/production/commons/content/proper/commons-rdf/xref-test/org/apache/commons/rdf/api/AbstractDatasetTest.html (original) +++ websites/production/commons/content/proper/commons-rdf/xref-test/org/apache/commons/rdf/api/AbstractDatasetTest.html Sat Dec 23 20:15:28 2017 @@ -53,7 +53,7 @@ 45 * <p> 46 * This test uses try-with-resources blocks for calls to {@link Dataset#stream()} 47 * and {@link Dataset#iterate()}. -48 * +48 * 49 * @see Dataset 50 * @see RDF 51 */ @@ -78,10 +78,10 @@ 70 private BlankNode graph2; 71 72 /** -73 * +73 * 74 * This method must be overridden by the implementing test to provide a 75 * factory for the test to create {@link Dataset}, {@link IRI} etc. -76 * +76 * 77 * @return {@link RDF} instance to be tested. 78 */ 79 protected abstract RDF createFactory(); @@ -94,7 +94,7 @@ 86 87 graph1 = factory.createIRI("http://example.com/graph1"); 88 graph2 = factory.createBlankNode(); -89 +89 90 alice = factory.createIRI("http://example.com/alice"); 91 bob = factory.createIRI("http://example.com/bob"); 92 name = factory.createIRI("http://xmlns.com/foaf/0.1/name"); @@ -121,13 +121,13 @@ 113 // NOTE: bnode1 used in both graph1 and graph2 114 dataset.add(graph1, bnode1, name, secretClubName); 115 dataset.add(graph2, bnode2, name, companyName); -116 -117 // default graph describes graph1 and graph2 +116 +117 // default graph describes graph1 and graph2 118 isPrimaryTopicOf = factory.createIRI("http://xmlns.com/foaf/0.1/isPrimaryTopicOf"); 119 dataset.add(null, alice, isPrimaryTopicOf, graph1); 120 dataset.add(null, bob, isPrimaryTopicOf, graph2); -121 -122 +121 +122 123 } 124 125 @Test @@ -143,10 +143,10 @@ 135 quads.add(t); 136 } 137 assertEquals(dataset.size(), quads.size()); -138 +138 139 //assertTrue(quads.contains(bobNameQuad)); -140 // java.util.List won't do any BlankNode mapping, so -141 // instead bobNameQuad of let's check for an IRI-centric quad +140 // java.util.List won't do any BlankNode mapping, so +141 // instead bobNameQuad of let's check for an IRI-centric quad 142 final Quad q = factory.createQuad(graph1, alice, name, aliceName); 143 quads.contains(q); 144 @@ -167,24 +167,24 @@ 159 count++; 160 } 161 assertEquals(dataset.size(), count); -162 +162 163 // Pattern iteration which should cover multiple graphs. -164 -165 Set<Quad> aliceQuads = new HashSet<>(); -166 for (Quad aliceQ : dataset.iterate(null, alice, null, null)) { +164 +165 final Set<Quad> aliceQuads = new HashSet<>(); +166 for (final Quad aliceQ : dataset.iterate(null, alice, null, null)) { 167 aliceQuads.add(aliceQ); 168 } 169 assertTrue(aliceQuads.contains(factory.createQuad(graph1, alice, name, aliceName))); 170 assertTrue(aliceQuads.contains(factory.createQuad(graph1, alice, knows, bob))); -171 // We can't test this by Quad equality, as bnode1 might become mapped by the +171 // We can't test this by Quad equality, as bnode1 might become mapped by the 172 // dataset 173 //assertTrue(aliceQuads.contains(factory.createQuad(graph1, alice, member, bnode1))); 174 assertTrue(aliceQuads.contains(factory.createQuad(null, alice, isPrimaryTopicOf, graph1))); 175 assertEquals(4, aliceQuads.size()); -176 +176 177 // Check the isPrimaryTopicOf statements in the default graph 178 int topics = 0; -179 for (Quad topic : dataset.iterate(null, null, isPrimaryTopicOf, null)) { +179 for (final Quad topic : dataset.iterate(null, null, isPrimaryTopicOf, null)) { 180 topics++; 181 // COMMONSRDF-55: should not be <urn:x-arq:defaultgraph> or similar 182 assertFalse(topic.getGraphName().isPresent()); @@ -195,7 +195,7 @@ 187 @Test 188 public void streamDefaultGraphNameAlice() throws Exception { 189 // null below would match in ANY graph (including default graph) -190 Optional<? extends Quad> aliceTopic = dataset.stream(null, alice, isPrimaryTopicOf, null).findAny(); +190 final Optional<? extends Quad> aliceTopic = dataset.stream(null, alice, isPrimaryTopicOf, null).findAny(); 191 assertTrue(aliceTopic.isPresent()); 192 // COMMONSRDF-55: should not be <urn:x-arq:defaultgraph> or similar 193 assertNull(aliceTopic.get().getGraphName().orElse(null)); @@ -206,14 +206,14 @@ 198 @Test 199 public void streamDefaultGraphNameByPattern() throws Exception { 200 // Explicitly select in only the default graph Optional.empty() -201 Optional<? extends Quad> aliceTopic = dataset.stream(Optional.empty(), null, null, null).findAny(); +201 final Optional<? extends Quad> aliceTopic = dataset.stream(Optional.empty(), null, null, null).findAny(); 202 assertTrue(aliceTopic.isPresent()); 203 // COMMONSRDF-55: should not be <urn:x-arq:defaultgraph> or similar 204 assertNull(aliceTopic.get().getGraphName().orElse(null)); 205 assertFalse(aliceTopic.get().getGraphName().isPresent()); 206 } -207 -208 +207 +208 209 /** 210 * Special quad closing for RDF4J. 211 */ @@ -352,70 +352,70 @@ 344 } 345 346 @Test -347 public void addBlankNodesFromMultipleDatasets() { -348 // Create two separate Dataset instances -349 final Dataset g1 = createDataset1(); -350 final Dataset g2 = createDataset2(); -351 -352 // and add them to a new Dataset g3 -353 final Dataset g3 = factory.createDataset(); -354 addAllQuads(g1, g3); -355 addAllQuads(g2, g3); -356 -357 // Let's make a map to find all those blank nodes after insertion -358 // (The Dataset implementation is not currently required to -359 // keep supporting those BlankNodes with contains() - see -360 // COMMONSRDF-15) -361 -362 final Map<String, BlankNodeOrIRI> whoIsWho = new ConcurrentHashMap<>(); -363 // ConcurrentHashMap as we will try parallel forEach below, -364 // which should not give inconsistent results (it does with a -365 // HashMap!) -366 -367 // look up BlankNodes by name -368 final IRI name = factory.createIRI("http://xmlns.com/foaf/0.1/name"); -369 try (Stream<? extends Quad> stream = g3.stream(null, null, name, null)) { -370 stream.parallel().forEach(t -> whoIsWho.put(t.getObject().ntriplesString(), t.getSubject())); -371 } -372 -373 assertEquals(4, whoIsWho.size()); -374 // and contains 4 unique values -375 assertEquals(4, new HashSet<>(whoIsWho.values()).size()); -376 -377 final BlankNodeOrIRI b1Alice = whoIsWho.get("\"Alice\""); -378 assertNotNull(b1Alice); -379 final BlankNodeOrIRI b2Bob = whoIsWho.get("\"Bob\""); -380 assertNotNull(b2Bob); -381 final BlankNodeOrIRI b1Charlie = whoIsWho.get("\"Charlie\""); -382 assertNotNull(b1Charlie); -383 final BlankNodeOrIRI b2Dave = whoIsWho.get("\"Dave\""); -384 assertNotNull(b2Dave); -385 -386 // All blank nodes should differ -387 notEquals(b1Alice, b2Bob); -388 notEquals(b1Alice, b1Charlie); -389 notEquals(b1Alice, b2Dave); -390 notEquals(b2Bob, b1Charlie); -391 notEquals(b2Bob, b2Dave); -392 notEquals(b1Charlie, b2Dave); -393 -394 // And we should be able to query with them again -395 // as we got them back from g3 -396 final IRI hasChild = factory.createIRI("http://example.com/hasChild"); -397 // FIXME: Check graph2 BlankNode in these ..? -398 assertTrue(g3.contains(null, b1Alice, hasChild, b2Bob)); -399 assertTrue(g3.contains(null, b2Dave, hasChild, b1Charlie)); -400 // But not -401 assertFalse(g3.contains(null, b1Alice, hasChild, b1Alice)); -402 assertFalse(g3.contains(null, b1Alice, hasChild, b1Charlie)); -403 assertFalse(g3.contains(null, b1Alice, hasChild, b2Dave)); -404 // nor +347 public void addBlankNodesFromMultipleDatasets() throws Exception { +348 // Create two separate Dataset instances +349 try (final Dataset g1 = createDataset1(); +350 final Dataset g2 = createDataset2(); +351 final Dataset g3 = factory.createDataset()) { +352 +353 addAllQuads(g1, g3); +354 addAllQuads(g2, g3); +355 +356 // Let's make a map to find all those blank nodes after insertion +357 // (The Dataset implementation is not currently required to +358 // keep supporting those BlankNodes with contains() - see +359 // COMMONSRDF-15) +360 +361 final Map<String, BlankNodeOrIRI> whoIsWho = new ConcurrentHashMap<>(); +362 // ConcurrentHashMap as we will try parallel forEach below, +363 // which should not give inconsistent results (it does with a +364 // HashMap!) +365 +366 // look up BlankNodes by name +367 final IRI name = factory.createIRI("http://xmlns.com/foaf/0.1/name"); +368 try (Stream<? extends Quad> stream = g3.stream(null, null, name, null)) { +369 stream.parallel().forEach(t -> whoIsWho.put(t.getObject().ntriplesString(), t.getSubject())); +370 } +371 +372 assertEquals(4, whoIsWho.size()); +373 // and contains 4 unique values +374 assertEquals(4, new HashSet<>(whoIsWho.values()).size()); +375 +376 final BlankNodeOrIRI b1Alice = whoIsWho.get("\"Alice\""); +377 assertNotNull(b1Alice); +378 final BlankNodeOrIRI b2Bob = whoIsWho.get("\"Bob\""); +379 assertNotNull(b2Bob); +380 final BlankNodeOrIRI b1Charlie = whoIsWho.get("\"Charlie\""); +381 assertNotNull(b1Charlie); +382 final BlankNodeOrIRI b2Dave = whoIsWho.get("\"Dave\""); +383 assertNotNull(b2Dave); +384 +385 // All blank nodes should differ +386 notEquals(b1Alice, b2Bob); +387 notEquals(b1Alice, b1Charlie); +388 notEquals(b1Alice, b2Dave); +389 notEquals(b2Bob, b1Charlie); +390 notEquals(b2Bob, b2Dave); +391 notEquals(b1Charlie, b2Dave); +392 +393 // And we should be able to query with them again +394 // as we got them back from g3 +395 final IRI hasChild = factory.createIRI("http://example.com/hasChild"); +396 // FIXME: Check graph2 BlankNode in these ..? +397 assertTrue(g3.contains(null, b1Alice, hasChild, b2Bob)); +398 assertTrue(g3.contains(null, b2Dave, hasChild, b1Charlie)); +399 // But not +400 assertFalse(g3.contains(null, b1Alice, hasChild, b1Alice)); +401 assertFalse(g3.contains(null, b1Alice, hasChild, b1Charlie)); +402 assertFalse(g3.contains(null, b1Alice, hasChild, b2Dave)); +403 // nor +404 assertFalse(g3.contains(null, b2Dave, hasChild, b1Alice)); 405 assertFalse(g3.contains(null, b2Dave, hasChild, b1Alice)); -406 assertFalse(g3.contains(null, b2Dave, hasChild, b1Alice)); -407 -408 // and these don't have any children (as far as we know) -409 assertFalse(g3.contains(null, b2Bob, hasChild, null)); -410 assertFalse(g3.contains(null, b1Charlie, hasChild, null)); +406 +407 // and these don't have any children (as far as we know) +408 assertFalse(g3.contains(null, b2Bob, hasChild, null)); +409 assertFalse(g3.contains(null, b1Charlie, hasChild, null)); +410 } 411 } 412 413 private void notEquals(final BlankNodeOrIRI node1, final BlankNodeOrIRI node2) { @@ -472,14 +472,14 @@ 464 * Create a different implementation of BlankNode to be tested with 465 * dataset.add(a,b,c); (the implementation may or may not then choose to 466 * translate such to its own instances) -467 * +467 * 468 * @param name 469 * @return 470 */ 471 private BlankNode createOwnBlankNode(final String name, final String uuid) { 472 return new BlankNode() { 473 @Override -474 public String ntriplesString() { +474 public String ntriplesString() { 475 return "_: " + name; 476 } 477 @@ -521,269 +521,272 @@ 513 g2.add(b2, b2, hasChild, b1); 514 return g2; 515 } -516 +516 517 /** 518 * Ensure {@link Dataset#getGraphNames()} contains our two graphs. -519 * +519 * 520 * @throws Exception 521 * If test fails 522 */ 523 @Test 524 public void getGraphNames() throws Exception { -525 final Set<BlankNodeOrIRI> names = dataset.getGraphNames().collect(Collectors.toSet()); +525 final Set<BlankNodeOrIRI> names = dataset.getGraphNames().collect(Collectors.toSet()); 526 assertTrue("Can't find graph name " + graph1, names.contains(graph1)); 527 assertTrue("Found no quads in graph1", dataset.contains(Optional.of(graph1), null, null, null)); -528 +528 529 final Optional<BlankNodeOrIRI> graphName2 = dataset.getGraphNames().filter(BlankNode.class::isInstance).findAny(); -530 assertTrue("Could not find graph2-like BlankNode", graphName2.isPresent()); +530 assertTrue("Could not find graph2-like BlankNode", graphName2.isPresent()); 531 assertTrue("Found no quads in graph2", dataset.contains(graphName2, null, null, null)); 532 533 // Some implementations like Virtuoso might have additional internal graphs, 534 // so we can't assume this: 535 //assertEquals(2, names.size()); 536 } -537 +537 538 @Test 539 public void getGraph() throws Exception { -540 final Graph defaultGraph = dataset.getGraph(); -541 // TODO: Can we assume the default graph was empty before our new triples? -542 assertEquals(2, defaultGraph.size()); -543 assertTrue(defaultGraph.contains(alice, isPrimaryTopicOf, graph1)); -544 // NOTE: graph2 is a BlankNode -545 assertTrue(defaultGraph.contains(bob, isPrimaryTopicOf, null)); -546 } -547 +540 try (final Graph defaultGraph = dataset.getGraph()) { +541 // TODO: Can we assume the default graph was empty before our new triples? +542 assertEquals(2, defaultGraph.size()); +543 assertTrue(defaultGraph.contains(alice, isPrimaryTopicOf, graph1)); +544 // NOTE: graph2 is a BlankNode +545 assertTrue(defaultGraph.contains(bob, isPrimaryTopicOf, null)); +546 } +547 } 548 -549 @Test -550 public void getGraphNull() throws Exception { -551 // Default graph should be present -552 final Graph defaultGraph = dataset.getGraph(null).get(); -553 // TODO: Can we assume the default graph was empty before our new triples? -554 assertEquals(2, defaultGraph.size()); -555 assertTrue(defaultGraph.contains(alice, isPrimaryTopicOf, graph1)); -556 // NOTE: wildcard as graph2 is a (potentially mapped) BlankNode -557 assertTrue(defaultGraph.contains(bob, isPrimaryTopicOf, null)); -558 } -559 -560 -561 @Test -562 public void getGraph1() throws Exception { -563 // graph1 should be present -564 final Graph g1 = dataset.getGraph(graph1).get(); -565 assertEquals(4, g1.size()); -566 -567 assertTrue(g1.contains(alice, name, aliceName)); -568 assertTrue(g1.contains(alice, knows, bob)); -569 assertTrue(g1.contains(alice, member, null)); -570 assertTrue(g1.contains(null, name, secretClubName)); -571 } -572 -573 @Test -574 public void getGraph2() throws Exception { -575 // graph2 should be present, even if is named by a BlankNode -576 // We'll look up the potentially mapped graph2 blanknode -577 final BlankNodeOrIRI graph2Name = (BlankNodeOrIRI) dataset.stream(Optional.empty(), bob, isPrimaryTopicOf, null) -578 .map(Quad::getObject).findAny().get(); -579 -580 final Graph g2 = dataset.getGraph(graph2Name).get(); -581 assertEquals(4, g2.size()); -582 final Triple bobNameTriple = bobNameQuad.asTriple(); -583 assertTrue(g2.contains(bobNameTriple)); -584 assertTrue(g2.contains(bob, member, bnode1)); -585 assertTrue(g2.contains(bob, member, bnode2)); -586 assertFalse(g2.contains(bnode1, name, secretClubName)); -587 assertTrue(g2.contains(bnode2, name, companyName)); -588 } -589 -590 -591 @Test -592 public void containsLanguageTagsCaseInsensitive() { -593 // COMMONSRDF-51: Ensure we can add/contains/remove with any casing -594 // of literal language tag -595 final Literal lower = factory.createLiteral("Hello there", "en-gb"); -596 final Literal upper = factory.createLiteral("Hello there", "EN-GB"); -597 final Literal mixed = factory.createLiteral("Hello there", "en-GB"); -598 -599 final IRI example1 = factory.createIRI("http://example.com/s1"); -600 final IRI greeting = factory.createIRI("http://example.com/greeting"); +549 +550 @Test +551 public void getGraphNull() throws Exception { +552 // Default graph should be present +553 try (final Graph defaultGraph = dataset.getGraph(null).get()) { +554 // TODO: Can we assume the default graph was empty before our new triples? +555 assertEquals(2, defaultGraph.size()); +556 assertTrue(defaultGraph.contains(alice, isPrimaryTopicOf, graph1)); +557 // NOTE: wildcard as graph2 is a (potentially mapped) BlankNode +558 assertTrue(defaultGraph.contains(bob, isPrimaryTopicOf, null)); +559 } +560 } +561 +562 +563 @Test +564 public void getGraph1() throws Exception { +565 // graph1 should be present +566 try (final Graph g1 = dataset.getGraph(graph1).get()) { +567 assertEquals(4, g1.size()); +568 +569 assertTrue(g1.contains(alice, name, aliceName)); +570 assertTrue(g1.contains(alice, knows, bob)); +571 assertTrue(g1.contains(alice, member, null)); +572 assertTrue(g1.contains(null, name, secretClubName)); +573 } +574 } +575 +576 @Test +577 public void getGraph2() throws Exception { +578 // graph2 should be present, even if is named by a BlankNode +579 // We'll look up the potentially mapped graph2 blanknode +580 final BlankNodeOrIRI graph2Name = (BlankNodeOrIRI) dataset.stream(Optional.empty(), bob, isPrimaryTopicOf, null) +581 .map(Quad::getObject).findAny().get(); +582 +583 try (final Graph g2 = dataset.getGraph(graph2Name).get()) { +584 assertEquals(4, g2.size()); +585 final Triple bobNameTriple = bobNameQuad.asTriple(); +586 assertTrue(g2.contains(bobNameTriple)); +587 assertTrue(g2.contains(bob, member, bnode1)); +588 assertTrue(g2.contains(bob, member, bnode2)); +589 assertFalse(g2.contains(bnode1, name, secretClubName)); +590 assertTrue(g2.contains(bnode2, name, companyName)); +591 } +592 } +593 +594 @Test +595 public void containsLanguageTagsCaseInsensitive() { +596 // COMMONSRDF-51: Ensure we can add/contains/remove with any casing +597 // of literal language tag +598 final Literal lower = factory.createLiteral("Hello there", "en-gb"); +599 final Literal upper = factory.createLiteral("Hello there", "EN-GB"); +600 final Literal mixed = factory.createLiteral("Hello there", "en-GB"); 601 -602 -603 dataset.add(null, example1, greeting, upper); -604 -605 // any kind of Triple should match -606 assertTrue(dataset.contains(factory.createQuad(null, example1, greeting, upper))); -607 assertTrue(dataset.contains(factory.createQuad(null, example1, greeting, lower))); -608 assertTrue(dataset.contains(factory.createQuad(null, example1, greeting, mixed))); -609 -610 // or as patterns -611 assertTrue(dataset.contains(null, null, null, upper)); -612 assertTrue(dataset.contains(null, null, null, lower)); -613 assertTrue(dataset.contains(null, null, null, mixed)); -614 } -615 -616 @Test -617 public void containsLanguageTagsCaseInsensitiveTurkish() { -618 // COMMONSRDF-51: Special test for Turkish issue where -619 // "i".toLowerCase() != "i" -620 // See also: -621 // https://garygregory.wordpress.com/2015/11/03/java-lowercase-conversion-turkey/ -622 -623 // This is similar to the test in AbstractRDFTest, but on a graph -624 Locale defaultLocale = Locale.getDefault(); -625 try { -626 Locale.setDefault(Locale.ROOT); -627 final Literal lowerROOT = factory.createLiteral("moi", "fi"); -628 final Literal upperROOT = factory.createLiteral("moi", "FI"); -629 final Literal mixedROOT = factory.createLiteral("moi", "fI"); -630 final IRI exampleROOT = factory.createIRI("http://example.com/s1"); -631 final IRI greeting = factory.createIRI("http://example.com/greeting"); -632 dataset.add(null, exampleROOT, greeting, mixedROOT); -633 -634 Locale turkish = Locale.forLanguageTag("TR"); -635 Locale.setDefault(turkish); -636 // If the below assertion fails, then the Turkish -637 // locale no longer have this peculiarity that -638 // we want to test. -639 Assume.assumeFalse("FI".toLowerCase().equals("fi")); -640 -641 // Below is pretty much the same as in -642 // containsLanguageTagsCaseInsensitive() -643 final Literal lower = factory.createLiteral("moi", "fi"); -644 final Literal upper = factory.createLiteral("moi", "FI"); -645 final Literal mixed = factory.createLiteral("moi", "fI"); -646 -647 final IRI exampleTR = factory.createIRI("http://example.com/s2"); -648 dataset.add(null, exampleTR, greeting, upper); -649 assertTrue(dataset.contains(factory.createQuad(null, exampleTR, greeting, upper))); -650 assertTrue(dataset.contains(factory.createQuad(null, exampleTR, greeting, upperROOT))); -651 assertTrue(dataset.contains(factory.createQuad(null, exampleTR, greeting, lower))); -652 assertTrue(dataset.contains(factory.createQuad(null, exampleTR, greeting, lowerROOT))); -653 assertTrue(dataset.contains(factory.createQuad(null, exampleTR, greeting, mixed))); -654 assertTrue(dataset.contains(factory.createQuad(null, exampleTR, greeting, mixedROOT))); -655 assertTrue(dataset.contains(null, exampleTR, null, upper)); -656 assertTrue(dataset.contains(null, exampleTR, null, upperROOT)); -657 assertTrue(dataset.contains(null, exampleTR, null, lower)); -658 assertTrue(dataset.contains(null, exampleTR, null, lowerROOT)); -659 assertTrue(dataset.contains(null, exampleTR, null, mixed)); -660 assertTrue(dataset.contains(null, exampleTR, null, mixedROOT)); -661 -662 // What about the triple we added while in ROOT locale? -663 assertTrue(dataset.contains(factory.createQuad(null, exampleROOT, greeting, upper))); -664 assertTrue(dataset.contains(factory.createQuad(null, exampleROOT, greeting, lower))); -665 assertTrue(dataset.contains(factory.createQuad(null, exampleROOT, greeting, mixed))); -666 assertTrue(dataset.contains(null, exampleROOT, null, upper)); -667 assertTrue(dataset.contains(null, exampleROOT, null, lower)); -668 assertTrue(dataset.contains(null, exampleROOT, null, mixed)); -669 } finally { -670 Locale.setDefault(defaultLocale); -671 } -672 } -673 -674 -675 @Test -676 public void removeLanguageTagsCaseInsensitive() { -677 // COMMONSRDF-51: Ensure we can remove with any casing -678 // of literal language tag -679 final Literal lower = factory.createLiteral("Howdy", "en-us"); -680 final Literal upper = factory.createLiteral("Howdy", "EN-US"); -681 final Literal mixed = factory.createLiteral("Howdy", "en-US"); -682 -683 final IRI example1 = factory.createIRI("http://example.com/s1"); -684 final IRI greeting = factory.createIRI("http://example.com/greeting"); +602 final IRI example1 = factory.createIRI("http://example.com/s1"); +603 final IRI greeting = factory.createIRI("http://example.com/greeting"); +604 +605 +606 dataset.add(null, example1, greeting, upper); +607 +608 // any kind of Triple should match +609 assertTrue(dataset.contains(factory.createQuad(null, example1, greeting, upper))); +610 assertTrue(dataset.contains(factory.createQuad(null, example1, greeting, lower))); +611 assertTrue(dataset.contains(factory.createQuad(null, example1, greeting, mixed))); +612 +613 // or as patterns +614 assertTrue(dataset.contains(null, null, null, upper)); +615 assertTrue(dataset.contains(null, null, null, lower)); +616 assertTrue(dataset.contains(null, null, null, mixed)); +617 } +618 +619 @Test +620 public void containsLanguageTagsCaseInsensitiveTurkish() { +621 // COMMONSRDF-51: Special test for Turkish issue where +622 // "i".toLowerCase() != "i" +623 // See also: +624 // https://garygregory.wordpress.com/2015/11/03/java-lowercase-conversion-turkey/ +625 +626 // This is similar to the test in AbstractRDFTest, but on a graph +627 final Locale defaultLocale = Locale.getDefault(); +628 try { +629 Locale.setDefault(Locale.ROOT); +630 final Literal lowerROOT = factory.createLiteral("moi", "fi"); +631 final Literal upperROOT = factory.createLiteral("moi", "FI"); +632 final Literal mixedROOT = factory.createLiteral("moi", "fI"); +633 final IRI exampleROOT = factory.createIRI("http://example.com/s1"); +634 final IRI greeting = factory.createIRI("http://example.com/greeting"); +635 dataset.add(null, exampleROOT, greeting, mixedROOT); +636 +637 final Locale turkish = Locale.forLanguageTag("TR"); +638 Locale.setDefault(turkish); +639 // If the below assertion fails, then the Turkish +640 // locale no longer have this peculiarity that +641 // we want to test. +642 Assume.assumeFalse("FI".toLowerCase().equals("fi")); +643 +644 // Below is pretty much the same as in +645 // containsLanguageTagsCaseInsensitive() +646 final Literal lower = factory.createLiteral("moi", "fi"); +647 final Literal upper = factory.createLiteral("moi", "FI"); +648 final Literal mixed = factory.createLiteral("moi", "fI"); +649 +650 final IRI exampleTR = factory.createIRI("http://example.com/s2"); +651 dataset.add(null, exampleTR, greeting, upper); +652 assertTrue(dataset.contains(factory.createQuad(null, exampleTR, greeting, upper))); +653 assertTrue(dataset.contains(factory.createQuad(null, exampleTR, greeting, upperROOT))); +654 assertTrue(dataset.contains(factory.createQuad(null, exampleTR, greeting, lower))); +655 assertTrue(dataset.contains(factory.createQuad(null, exampleTR, greeting, lowerROOT))); +656 assertTrue(dataset.contains(factory.createQuad(null, exampleTR, greeting, mixed))); +657 assertTrue(dataset.contains(factory.createQuad(null, exampleTR, greeting, mixedROOT))); +658 assertTrue(dataset.contains(null, exampleTR, null, upper)); +659 assertTrue(dataset.contains(null, exampleTR, null, upperROOT)); +660 assertTrue(dataset.contains(null, exampleTR, null, lower)); +661 assertTrue(dataset.contains(null, exampleTR, null, lowerROOT)); +662 assertTrue(dataset.contains(null, exampleTR, null, mixed)); +663 assertTrue(dataset.contains(null, exampleTR, null, mixedROOT)); +664 +665 // What about the triple we added while in ROOT locale? +666 assertTrue(dataset.contains(factory.createQuad(null, exampleROOT, greeting, upper))); +667 assertTrue(dataset.contains(factory.createQuad(null, exampleROOT, greeting, lower))); +668 assertTrue(dataset.contains(factory.createQuad(null, exampleROOT, greeting, mixed))); +669 assertTrue(dataset.contains(null, exampleROOT, null, upper)); +670 assertTrue(dataset.contains(null, exampleROOT, null, lower)); +671 assertTrue(dataset.contains(null, exampleROOT, null, mixed)); +672 } finally { +673 Locale.setDefault(defaultLocale); +674 } +675 } +676 +677 +678 @Test +679 public void removeLanguageTagsCaseInsensitive() { +680 // COMMONSRDF-51: Ensure we can remove with any casing +681 // of literal language tag +682 final Literal lower = factory.createLiteral("Howdy", "en-us"); +683 final Literal upper = factory.createLiteral("Howdy", "EN-US"); +684 final Literal mixed = factory.createLiteral("Howdy", "en-US"); 685 -686 dataset.add(null, example1, greeting, upper); -687 -688 // Remove should also honour any case -689 dataset.remove(null, example1, null, mixed); -690 assertFalse(dataset.contains(null, null, greeting, null)); -691 -692 dataset.add(null, example1, greeting, lower); -693 dataset.remove(null, example1, null, upper); +686 final IRI example1 = factory.createIRI("http://example.com/s1"); +687 final IRI greeting = factory.createIRI("http://example.com/greeting"); +688 +689 dataset.add(null, example1, greeting, upper); +690 +691 // Remove should also honour any case +692 dataset.remove(null, example1, null, mixed); +693 assertFalse(dataset.contains(null, null, greeting, null)); 694 -695 // Check with Triple -696 dataset.add(factory.createQuad(null, example1, greeting, mixed)); -697 dataset.remove(factory.createQuad(null, example1, greeting, upper)); -698 assertFalse(dataset.contains(null, null, greeting, null)); -699 } -700 -701 private static Optional<? extends Quad> closableFindAny(Stream<? extends Quad> stream) { -702 try (Stream<? extends Quad> s = stream) { -703 return s.findAny(); -704 } -705 } -706 -707 @Test -708 public void streamLanguageTagsCaseInsensitive() { -709 // COMMONSRDF-51: Ensure we can add/contains/remove with any casing -710 // of literal language tag -711 final Literal lower = factory.createLiteral("Good afternoon", "en-gb"); -712 final Literal upper = factory.createLiteral("Good afternoon", "EN-GB"); -713 final Literal mixed = factory.createLiteral("Good afternoon", "en-GB"); -714 -715 final IRI example1 = factory.createIRI("http://example.com/s1"); -716 final IRI greeting = factory.createIRI("http://example.com/greeting"); +695 dataset.add(null, example1, greeting, lower); +696 dataset.remove(null, example1, null, upper); +697 +698 // Check with Triple +699 dataset.add(factory.createQuad(null, example1, greeting, mixed)); +700 dataset.remove(factory.createQuad(null, example1, greeting, upper)); +701 assertFalse(dataset.contains(null, null, greeting, null)); +702 } +703 +704 private static Optional<? extends Quad> closableFindAny(final Stream<? extends Quad> stream) { [... 142 lines stripped ...]