commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject [3/5] commons-rdf git commit: test cases for testing RDF4J#asRDF overloads
Date Fri, 27 Jan 2017 16:06:19 GMT
test cases for testing RDF4J#asRDF overloads


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

Branch: refs/heads/master
Commit: 1dd347ec1be18d0c5d1e5f3e21f23229e912e452
Parents: ed787cf
Author: Guohui Xiao <gh.xiao@gmail.com>
Authored: Fri Jan 27 15:27:50 2017 +0100
Committer: Guohui Xiao <gh.xiao@gmail.com>
Committed: Fri Jan 27 15:27:50 2017 +0100

----------------------------------------------------------------------
 .../org/apache/commons/rdf/rdf4j/RDF4J.java     | 20 ++++++++++++
 .../rdf/rdf4j/RDF4JMethodOverloadsTest.java     | 33 ++++++++++++++++++++
 2 files changed, 53 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/1dd347ec/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4J.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4J.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4J.java
index 31002cb..44afa0a 100644
--- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4J.java
+++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4J.java
@@ -37,6 +37,7 @@ import org.apache.commons.rdf.api.Triple;
 import org.apache.commons.rdf.api.TripleLike;
 import org.apache.commons.rdf.rdf4j.impl.InternalRDF4JFactory;
 import org.eclipse.rdf4j.model.BNode;
+import org.eclipse.rdf4j.model.IRI;
 import org.eclipse.rdf4j.model.Literal;
 import org.eclipse.rdf4j.model.Model;
 import org.eclipse.rdf4j.model.Resource;
@@ -286,6 +287,25 @@ public final class RDF4J implements RDF {
     }
 
     /**
+     *
+     * Adapt a RDF4J
+     * {@link org.eclipse.rdf4j.model.Resource} as a Commons RDF
+     * {@link org.apache.commons.rdf.api.BlankNodeOrIRI}
+     * <p>
+     * @param value
+     *            The RDF4J {@link Value} to convert.
+     * @return A {@link RDF4JBlankNodeOrIRI} that corresponds to the RDF4J Resource
+     */
+    public RDF4JBlankNodeOrIRI asRDFTerm(final org.eclipse.rdf4j.model.Resource value) {
+        if(value instanceof IRI){
+            return asRDFTerm((IRI)value);
+        } else if (value instanceof BNode){
+            return asRDFTerm((BNode)value);
+        }
+        throw new IllegalArgumentException("Value is not a BNode or IRI: " + value.getClass());
+    }
+
+    /**
      * Adapt a RDF4J {@link Value} as a Commons RDF {@link RDFTerm}.
      * <p>
      * The value will be of the same kind as the term, e.g. a

http://git-wip-us.apache.org/repos/asf/commons-rdf/blob/1dd347ec/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/RDF4JMethodOverloadsTest.java
----------------------------------------------------------------------
diff --git a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/RDF4JMethodOverloadsTest.java
b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/RDF4JMethodOverloadsTest.java
new file mode 100644
index 0000000..eb6b5e9
--- /dev/null
+++ b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/RDF4JMethodOverloadsTest.java
@@ -0,0 +1,33 @@
+package org.apache.commons.rdf.rdf4j;
+
+import org.eclipse.rdf4j.model.BNode;
+import org.eclipse.rdf4j.model.IRI;
+import org.eclipse.rdf4j.model.Literal;
+import org.eclipse.rdf4j.model.Resource;
+import org.eclipse.rdf4j.model.Value;
+import org.eclipse.rdf4j.model.ValueFactory;
+import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class RDF4JMethodOverloadsTest {
+
+    @Test
+    public void testAsRDFTermOverloads() {
+        RDF4J rdf4J = new RDF4J();
+
+        final ValueFactory valueFactory = SimpleValueFactory.getInstance();
+
+        final Value bNode = valueFactory.createBNode("b1");
+        final Value iri = valueFactory.createIRI("http://ex.org");
+        final Value literal = valueFactory.createLiteral("b1");
+
+        assertEquals(rdf4J.asRDFTerm(bNode), rdf4J.asRDFTerm((BNode) bNode));
+        assertEquals(rdf4J.asRDFTerm(iri), rdf4J.asRDFTerm((IRI) iri));
+        assertEquals(rdf4J.asRDFTerm(literal), rdf4J.asRDFTerm((Literal) literal));
+        assertEquals(rdf4J.asRDFTerm(bNode), rdf4J.asRDFTerm((Resource) bNode));
+        assertEquals(rdf4J.asRDFTerm(iri), rdf4J.asRDFTerm((Resource) iri));
+    }
+}


Mime
View raw message