commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject [20/45] commons-rdf git commit: COMMONSRDF-51 Added langtag case tests for dataset
Date Fri, 10 Feb 2017 16:55:22 GMT
COMMONSRDF-51 Added langtag case tests for dataset

Project: http://git-wip-us.apache.org/repos/asf/commons-rdf/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rdf/commit/0470e7c0
Tree: http://git-wip-us.apache.org/repos/asf/commons-rdf/tree/0470e7c0
Diff: http://git-wip-us.apache.org/repos/asf/commons-rdf/diff/0470e7c0

Branch: refs/heads/COMMONSRDF-47
Commit: 0470e7c06ab9b8de927c185caf7d56f3f11fc51b
Parents: 6b07abf
Author: Stian Soiland-Reyes <stain@apache.org>
Authored: Thu Jan 26 14:32:55 2017 +0000
Committer: Stian Soiland-Reyes <stain@apache.org>
Committed: Thu Jan 26 14:32:55 2017 +0000

----------------------------------------------------------------------
 .../commons/rdf/api/AbstractDatasetTest.java    | 139 +++++++++++++++++++
 1 file changed, 139 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/0470e7c0/api/src/test/java/org/apache/commons/rdf/api/AbstractDatasetTest.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/commons/rdf/api/AbstractDatasetTest.java b/api/src/test/java/org/apache/commons/rdf/api/AbstractDatasetTest.java
index 505994f..9e2e192 100644
--- a/api/src/test/java/org/apache/commons/rdf/api/AbstractDatasetTest.java
+++ b/api/src/test/java/org/apache/commons/rdf/api/AbstractDatasetTest.java
@@ -23,6 +23,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.Set;
@@ -542,7 +543,145 @@ public abstract class AbstractDatasetTest {
     }
     
 
+    @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");
+
+        
+        dataset.add(null, example1, greeting, upper);
+        
+        // any kind of Triple should match
+        assertTrue(dataset.contains(factory.createQuad(null, example1, greeting, upper)));
+        assertTrue(dataset.contains(factory.createQuad(null, example1, greeting, lower)));
+        assertTrue(dataset.contains(factory.createQuad(null, example1, greeting, mixed)));
+
+        // or as patterns
+        assertTrue(dataset.contains(null, null, null, upper));
+        assertTrue(dataset.contains(null, null, null, lower));
+        assertTrue(dataset.contains(null, null, null, mixed));
+    }
+
+    @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 IRI exampleROOT = factory.createIRI("http://example.com/s1");
+            final IRI greeting = factory.createIRI("http://example.com/greeting");
+            dataset.add(null, 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");
+            dataset.add(null, exampleTR, greeting, upper);
+            assertTrue(dataset.contains(factory.createQuad(null, exampleTR, greeting, upper)));
+            assertTrue(dataset.contains(factory.createQuad(null, exampleTR, greeting, upperROOT)));
+            assertTrue(dataset.contains(factory.createQuad(null, exampleTR, greeting, lower)));
+            assertTrue(dataset.contains(factory.createQuad(null, exampleTR, greeting, lowerROOT)));
+            assertTrue(dataset.contains(factory.createQuad(null, exampleTR, greeting, mixed)));
+            assertTrue(dataset.contains(factory.createQuad(null, exampleTR, greeting, mixedROOT)));
+            assertTrue(dataset.contains(null, exampleTR, null, upper));
+            assertTrue(dataset.contains(null, exampleTR, null, upperROOT));
+            assertTrue(dataset.contains(null, exampleTR, null, lower));
+            assertTrue(dataset.contains(null, exampleTR, null, lowerROOT));
+            assertTrue(dataset.contains(null, exampleTR, null, mixed));
+            assertTrue(dataset.contains(null, exampleTR, null, mixedROOT));
+
+            // What about the triple we added while in ROOT locale?
+            assertTrue(dataset.contains(factory.createQuad(null, exampleROOT, greeting, upper)));
+            assertTrue(dataset.contains(factory.createQuad(null, exampleROOT, greeting, lower)));
+            assertTrue(dataset.contains(factory.createQuad(null, exampleROOT, greeting, mixed)));
+            assertTrue(dataset.contains(null, exampleROOT, null, upper));
+            assertTrue(dataset.contains(null, exampleROOT, null, lower));
+            assertTrue(dataset.contains(null, exampleROOT, null, mixed));
+        } finally {
+            Locale.setDefault(defaultLocale);
+        }
+    }
+    
+
+    @Test
+    public void removeLanguageTagsCaseInsensitive() {
+        // COMMONSRDF-51: Ensure we can 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");
+
+        dataset.add(null, example1, greeting, upper);
+
+        // Remove should also honour any case
+        dataset.remove(null, example1, null, mixed);
+        assertFalse(dataset.contains(null, null, greeting, null));
+        
+        dataset.add(null, example1, greeting, lower);
+        dataset.remove(null, example1, null, upper);
+
+        // Check with Triple
+        dataset.add(factory.createQuad(null, example1, greeting, mixed));
+        dataset.remove(factory.createQuad(null, example1, greeting, upper));
+        assertFalse(dataset.contains(null, null, greeting, null));
+    }
+
+    private static Optional<? extends Quad> closableFindAny(Stream<? extends Quad>
stream) {
+        try (Stream<? extends Quad> s = stream) {
+            return s.findAny();
+        }
+    }
     
+    @Test
+    public void streamLanguageTagsCaseInsensitive() {
+        // 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");
+
+        dataset.add(null, example1, greeting, upper);
+
+        // or as patterns
+        assertTrue(closableFindAny(dataset.stream(null, null, null, upper)).isPresent());
+        assertTrue(closableFindAny(dataset.stream(null, null, null, lower)).isPresent());
+        assertTrue(closableFindAny(dataset.stream(null, null, null, mixed)).isPresent());
+        
+        // Check the quad returned equal a new quad
+        Quad q = closableFindAny(dataset.stream(null, null, null, lower)).get();
+        assertEquals(q, factory.createQuad(null, example1, greeting, mixed));
+    }
+
     /**
      * An attempt to use the Java 8 streams to look up a more complicated query.
      * <p>


Mime
View raw message