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 CDEE5200C15 for ; Wed, 8 Feb 2017 15:43:59 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id CCABA160B4E; Wed, 8 Feb 2017 14:43:59 +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 F3C6D160B6A for ; Wed, 8 Feb 2017 15:43:58 +0100 (CET) Received: (qmail 14679 invoked by uid 500); 8 Feb 2017 14:43:57 -0000 Mailing-List: contact commits-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 commits@commons.apache.org Received: (qmail 13645 invoked by uid 99); 8 Feb 2017 14:43:56 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 08 Feb 2017 14:43:56 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 78F4ADFF2D; Wed, 8 Feb 2017 14:43:56 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: stain@apache.org To: commits@commons.apache.org Date: Wed, 08 Feb 2017 14:44:00 -0000 Message-Id: <4280f56681a648048081f13a02e31d99@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [05/16] commons-rdf git commit: COMMONSRDF-51: Check langtag equals also graph.add/contains/remove archived-at: Wed, 08 Feb 2017 14:44:00 -0000 COMMONSRDF-51: Check langtag equals also graph.add/contains/remove Project: http://git-wip-us.apache.org/repos/asf/commons-rdf/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-rdf/commit/50dc8861 Tree: http://git-wip-us.apache.org/repos/asf/commons-rdf/tree/50dc8861 Diff: http://git-wip-us.apache.org/repos/asf/commons-rdf/diff/50dc8861 Branch: refs/heads/master Commit: 50dc8861f3a0824168c8484d1c7a3535e49de57c Parents: 7046ea1 Author: Stian Soiland-Reyes Authored: Mon Jan 23 11:37:19 2017 +0000 Committer: Stian Soiland-Reyes Committed: Mon Jan 23 11:37:19 2017 +0000 ---------------------------------------------------------------------- .../commons/rdf/api/AbstractGraphTest.java | 105 ++++++++++++++++++- 1 file changed, 100 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/50dc8861/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java ---------------------------------------------------------------------- diff --git a/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java b/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java index 7e32676..eba8888 100644 --- a/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java +++ b/api/src/test/java/org/apache/commons/rdf/api/AbstractGraphTest.java @@ -27,6 +27,7 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; @@ -46,7 +47,7 @@ import org.junit.Test; *

* This test uses try-with-resources blocks for calls to {@link Graph#stream()} * and {@link Graph#iterate()}. - * + * * @see Graph * @see RDF */ @@ -68,10 +69,10 @@ public abstract class AbstractGraphTest { protected Triple bobNameTriple; /** - * + * * This method must be overridden by the implementing test to provide a * factory for the test to create {@link Graph}, {@link IRI} etc. - * + * * @return {@link RDF} instance to be tested. */ protected abstract RDF createFactory(); @@ -385,6 +386,100 @@ public abstract class AbstractGraphTest { } } + @Test + public void containsLanguageTagsCaseInsensitive() { + // COMMONSRDF-51: Ensure we can add/contains/remove with any casing + // of literal language tag + final Literal lower = factory.createLiteral("Hello", "en-gb"); + final Literal upper = factory.createLiteral("Hello", "EN-GB"); + final Literal mixed = factory.createLiteral("Hello", "en-GB"); + + final IRI example1 = factory.createIRI("http://example.com/s1"); + final IRI greeting = factory.createIRI("http://example.com/greeting"); + + final Graph graph = factory.createGraph(); + graph.add(example1, greeting, upper); + + assertTrue(graph.contains(factory.createTriple(example1, greeting, upper))); + assertTrue(graph.contains(factory.createTriple(example1, greeting, lower))); + assertTrue(graph.contains(factory.createTriple(example1, greeting, mixed))); + + // or as patterns + assertTrue(graph.contains(null, null, upper)); + assertTrue(graph.contains(null, null, lower)); + assertTrue(graph.contains(null, null, mixed)); + + // Remove should also honour any case + graph.remove(example1, greeting, mixed); + assertFalse(graph.contains(null, greeting, null)); + } + + @Test + public void containsLanguageTagsCaseInsensitiveTurkish() { + // COMMONSRDF-51: Special test for Turkish issue where + // "i".toLowerCase() != "i" + // See also: + // https://garygregory.wordpress.com/2015/11/03/java-lowercase-conversion-turkey/ + + // This is similar to the test in AbstractRDFTest, but on a graph + Locale defaultLocale = Locale.getDefault(); + try { + Locale.setDefault(Locale.ROOT); + final Literal lowerROOT = factory.createLiteral("moi", "fi"); + final Literal upperROOT = factory.createLiteral("moi", "FI"); + final Literal mixedROOT = factory.createLiteral("moi", "fI"); + final Graph g = factory.createGraph(); + final IRI exampleROOT = factory.createIRI("http://example.com/s1"); + final IRI greeting = factory.createIRI("http://example.com/greeting"); + g.add(exampleROOT, greeting, mixedROOT); + + Locale turkish = Locale.forLanguageTag("TR"); + Locale.setDefault(turkish); + // If the below assertion fails, then the Turkish + // locale no longer have this peculiarity that + // we want to test. + Assume.assumeFalse("FI".toLowerCase().equals("fi")); + + // Below is pretty much the same as in + // containsLanguageTagsCaseInsensitive() + final Literal lower = factory.createLiteral("moi", "fi"); + final Literal upper = factory.createLiteral("moi", "FI"); + final Literal mixed = factory.createLiteral("moi", "fI"); + + final IRI exampleTR = factory.createIRI("http://example.com/s2"); + g.add(exampleTR, greeting, upper); + assertTrue(g.contains(factory.createTriple(exampleTR, greeting, upper))); + assertTrue(g.contains(factory.createTriple(exampleTR, greeting, upperROOT))); + assertTrue(g.contains(factory.createTriple(exampleTR, greeting, lower))); + assertTrue(g.contains(factory.createTriple(exampleTR, greeting, lowerROOT))); + assertTrue(g.contains(factory.createTriple(exampleTR, greeting, mixed))); + assertTrue(g.contains(factory.createTriple(exampleTR, greeting, mixedROOT))); + assertTrue(g.contains(exampleTR, null, upper)); + assertTrue(g.contains(exampleTR, null, upperROOT)); + assertTrue(g.contains(exampleTR, null, lower)); + assertTrue(g.contains(exampleTR, null, lowerROOT)); + assertTrue(g.contains(exampleTR, null, mixed)); + assertTrue(g.contains(exampleTR, null, mixedROOT)); + g.remove(exampleTR, greeting, mixed); + assertFalse(g.contains(exampleTR, null, null)); + + // What about the triple we added while in ROOT locale? + assertTrue(g.contains(factory.createTriple(exampleROOT, greeting, upper))); + assertTrue(g.contains(factory.createTriple(exampleROOT, greeting, lower))); + assertTrue(g.contains(factory.createTriple(exampleROOT, greeting, mixed))); + assertTrue(g.contains(exampleROOT, null, upper)); + assertTrue(g.contains(exampleROOT, null, lower)); + assertTrue(g.contains(exampleROOT, null, mixed)); + g.remove(exampleROOT, greeting, mixed); + assertFalse(g.contains(exampleROOT, null, null)); + + + } finally { + Locale.setDefault(defaultLocale); + } + + } + private void notEquals(final BlankNodeOrIRI node1, final BlankNodeOrIRI node2) { assertFalse(node1.equals(node2)); // in which case we should be able to assume @@ -439,7 +534,7 @@ public abstract class AbstractGraphTest { * Create a different implementation of BlankNode to be tested with * graph.add(a,b,c); (the implementation may or may not then choose to * translate such to its own instances) - * + * * @param name * @return */ @@ -493,7 +588,7 @@ public abstract class AbstractGraphTest { * An attempt to use the Java 8 streams to look up a more complicated query. *

* FYI, the equivalent SPARQL version (untested): - * + * *

      *     SELECT ?orgName WHERE {
      *             ?org foaf:name ?orgName .