You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by st...@apache.org on 2017/02/08 14:42:14 UTC

[5/9] commons-rdf git commit: Test generalized quad creation

Test generalized quad creation

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

Branch: refs/heads/master
Commit: d0ae2d8fa6d0ae902319cbe35f93fbefdc0a536e
Parents: 7bbff25
Author: Stian Soiland-Reyes <st...@apache.org>
Authored: Wed Feb 8 14:26:07 2017 +0000
Committer: Stian Soiland-Reyes <st...@apache.org>
Committed: Wed Feb 8 14:27:47 2017 +0000

----------------------------------------------------------------------
 .../rdf/jena/GeneralizedRDFQuadTest.java        | 90 ++++++++++++++++++++
 .../rdf/jena/GeneralizedRDFTripleTest.java      | 72 ++++++++++++++++
 2 files changed, 162 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/d0ae2d8f/jena/src/test/java/org/apache/commons/rdf/jena/GeneralizedRDFQuadTest.java
----------------------------------------------------------------------
diff --git a/jena/src/test/java/org/apache/commons/rdf/jena/GeneralizedRDFQuadTest.java b/jena/src/test/java/org/apache/commons/rdf/jena/GeneralizedRDFQuadTest.java
new file mode 100644
index 0000000..e5b26a4
--- /dev/null
+++ b/jena/src/test/java/org/apache/commons/rdf/jena/GeneralizedRDFQuadTest.java
@@ -0,0 +1,90 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.rdf.jena;
+
+import static org.junit.Assert.*;
+
+import org.apache.commons.rdf.api.BlankNode;
+import org.junit.Test;
+
+public class GeneralizedRDFQuadTest {
+
+    private JenaRDF jena = new JenaRDF();
+    
+    @Test
+    public void bnodeProperty() throws Exception {
+        BlankNode b1 = jena.createBlankNode("b1");
+        JenaIRI ex1 = jena.createIRI("http://example.com/ex1");
+        JenaIRI ex2 = jena.createIRI("http://example.com/ex2");
+        JenaIRI ex3 = jena.createIRI("http://example.com/ex3");
+        
+        JenaGeneralizedQuadLike t = jena.createGeneralizedQuad(ex1, b1, ex2, ex3);
+        assertEquals(ex1, t.getSubject());
+        assertEquals(ex2, t.getObject());
+        assertEquals(b1, t.getPredicate()); // it's a bnode!
+        assertTrue(t.asJenaQuad().getPredicate().isBlank());
+    }
+
+    @Test
+    public void literalPredicate() throws Exception {
+        JenaIRI ex1 = jena.createIRI("http://example.com/ex1");
+        JenaIRI ex2 = jena.createIRI("http://example.com/ex2");
+        JenaIRI ex3 = jena.createIRI("http://example.com/ex3");
+        JenaLiteral lit = jena.createLiteral("Hello");
+        
+        JenaGeneralizedQuadLike t = jena.createGeneralizedQuad(ex1, lit, ex2, ex3);
+        assertEquals(ex1, t.getSubject());
+        assertEquals(ex2, t.getObject());
+        assertEquals(lit, t.getPredicate()); // it's a literal!
+        assertTrue(t.asJenaQuad().getPredicate().isLiteral());
+    }
+
+
+    @Test
+    public void literalSubject() throws Exception {
+        JenaIRI ex1 = jena.createIRI("http://example.com/ex1");
+        JenaIRI ex2 = jena.createIRI("http://example.com/ex2");
+        JenaIRI ex3 = jena.createIRI("http://example.com/ex3");
+        JenaLiteral lit = jena.createLiteral("Hello");
+        
+        JenaGeneralizedQuadLike t = jena.createGeneralizedQuad(lit, ex1, ex2, ex3);
+        assertEquals(lit, t.getSubject()); // it's a literal!
+        assertEquals(ex1, t.getPredicate());
+        assertEquals(ex2, t.getObject());
+        assertTrue(t.asJenaQuad().getSubject().isLiteral());
+    }
+    
+
+    @Test
+    public void literalGraph() throws Exception {
+        JenaIRI ex1 = jena.createIRI("http://example.com/ex1");
+        JenaIRI ex2 = jena.createIRI("http://example.com/ex2");
+        JenaIRI ex3 = jena.createIRI("http://example.com/ex3");
+        JenaLiteral lit = jena.createLiteral("Hello");
+        
+        JenaGeneralizedQuadLike t = jena.createGeneralizedQuad(ex1, ex2, ex3, lit);
+        assertEquals(ex1, t.getSubject()); 
+        assertEquals(ex2, t.getPredicate());
+        assertEquals(ex3, t.getObject());
+        assertTrue(t.getGraphName().isPresent());
+        assertEquals(lit, t.getGraphName().get());
+        assertTrue(t.asJenaQuad().getGraph().isLiteral());
+    }
+    
+    
+}

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/d0ae2d8f/jena/src/test/java/org/apache/commons/rdf/jena/GeneralizedRDFTripleTest.java
----------------------------------------------------------------------
diff --git a/jena/src/test/java/org/apache/commons/rdf/jena/GeneralizedRDFTripleTest.java b/jena/src/test/java/org/apache/commons/rdf/jena/GeneralizedRDFTripleTest.java
new file mode 100644
index 0000000..82ccb81
--- /dev/null
+++ b/jena/src/test/java/org/apache/commons/rdf/jena/GeneralizedRDFTripleTest.java
@@ -0,0 +1,72 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.rdf.jena;
+
+import static org.junit.Assert.*;
+
+import org.apache.commons.rdf.api.BlankNode;
+import org.junit.Test;
+
+public class GeneralizedRDFTripleTest {
+
+    private JenaRDF jena = new JenaRDF();
+    
+    @Test
+    public void bnodeProperty() throws Exception {
+        BlankNode b1 = jena.createBlankNode("b1");
+        JenaIRI ex1 = jena.createIRI("http://example.com/ex1");
+        JenaIRI ex2 = jena.createIRI("http://example.com/ex2");
+        
+        JenaGeneralizedTripleLike t = jena.createGeneralizedTriple(ex1, b1, ex2);
+        assertEquals(ex1, t.getSubject());
+        assertEquals(ex2, t.getObject());
+        assertEquals(b1, t.getPredicate()); // it's a bnode!
+        assertTrue(t.asJenaTriple().getPredicate().isBlank());
+    }
+
+    @Test
+    public void literalPredicate() throws Exception {
+        JenaIRI ex1 = jena.createIRI("http://example.com/ex1");
+        JenaIRI ex2 = jena.createIRI("http://example.com/ex2");
+        JenaLiteral lit = jena.createLiteral("Hello");
+        
+        JenaGeneralizedTripleLike t = jena.createGeneralizedTriple(ex1, lit, ex2);
+        assertEquals(ex1, t.getSubject());
+        assertEquals(ex2, t.getObject());
+        assertEquals(lit, t.getPredicate()); // it's a literal!
+        assertTrue(t.asJenaTriple().getPredicate().isLiteral());
+    }
+
+
+    @Test
+    public void literalSubject() throws Exception {
+        JenaIRI ex1 = jena.createIRI("http://example.com/ex1");
+        JenaIRI ex2 = jena.createIRI("http://example.com/ex2");
+        JenaLiteral lit = jena.createLiteral("Hello");
+        
+        JenaGeneralizedTripleLike t = jena.createGeneralizedTriple(lit, ex1, ex2);
+        assertEquals(lit, t.getSubject()); // it's a literal!
+        assertEquals(ex1, t.getPredicate());
+        assertEquals(ex2, t.getObject());
+        assertTrue(t.asJenaTriple().getSubject().isLiteral());
+    }
+    
+    
+
+    
+}