You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by al...@apache.org on 2012/08/13 13:00:47 UTC

svn commit: r1372359 - in /incubator/stanbol/trunk/ontologymanager/ontonet/src: main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/ test/java/org/apache/stanbol/ontologymanager/ontonet/ontology/ test/resources/ontologies/id/ test/resour...

Author: alexdma
Date: Mon Aug 13 11:00:46 2012
New Revision: 1372359

URL: http://svn.apache.org/viewvc?rev=1372359&view=rev
Log:
Added last unit tests for verifying that: 
* loading an ontology with no ontology IRI but a version IRI is still possible;
* the loaded ontology will be anonymous but with a non-anonymous public key; 
* OWLOntologyID objects with only a version IRI cannot be created at all, so no further checks for bad public keys are required.

We can now close STANBOL-524.

Added:
    incubator/stanbol/trunk/ontologymanager/ontonet/src/test/resources/ontologies/naming/
      - copied from r1372293, incubator/stanbol/trunk/ontologymanager/ontonet/src/test/resources/ontologies/id/
    incubator/stanbol/trunk/ontologymanager/ontonet/src/test/resources/ontologies/naming/versionedonly.owl
Removed:
    incubator/stanbol/trunk/ontologymanager/ontonet/src/test/resources/ontologies/id/
Modified:
    incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/ClerezzaOntologyProvider.java
    incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/ontology/TestOntologyReconciliation.java

Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/ClerezzaOntologyProvider.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/ClerezzaOntologyProvider.java?rev=1372359&r1=1372358&r2=1372359&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/ClerezzaOntologyProvider.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/main/java/org/apache/stanbol/ontologymanager/ontonet/impl/clerezza/ClerezzaOntologyProvider.java Mon Aug 13 11:00:46 2012
@@ -598,7 +598,7 @@ public class ClerezzaOntologyProvider im
 
     @Override
     public Set<OWLOntologyID> listAliases(OWLOntologyID publicKey) {
-        if (publicKey == null || publicKey.getOntologyIRI() == null) throw new IllegalArgumentException(
+        if (publicKey == null || publicKey.isAnonymous()) throw new IllegalArgumentException(
                 "Cannot locate aliases for null or anonymous public keys.");
         Set<OWLOntologyID> aliases = new HashSet<OWLOntologyID>();
         TripleCollection meta = getMetaGraph(TripleCollection.class);

Modified: incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/ontology/TestOntologyReconciliation.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/ontology/TestOntologyReconciliation.java?rev=1372359&r1=1372358&r2=1372359&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/ontology/TestOntologyReconciliation.java (original)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/test/java/org/apache/stanbol/ontologymanager/ontonet/ontology/TestOntologyReconciliation.java Mon Aug 13 11:00:46 2012
@@ -22,8 +22,10 @@ import static org.apache.stanbol.ontolog
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.io.InputStream;
 import java.net.URL;
@@ -49,6 +51,11 @@ import org.slf4j.LoggerFactory;
  */
 public class TestOntologyReconciliation {
 
+    @AfterClass
+    public static void cleanup() {
+        reset();
+    }
+
     @BeforeClass
     public static void setup() {
         reset();
@@ -107,7 +114,7 @@ public class TestOntologyReconciliation 
      */
     @Test
     public void namedFromStream() throws Exception {
-        String location = "/ontologies/id/named-2.owl";
+        String location = "/ontologies/naming/named-2.owl";
         OWLOntologyID expectedId = new OWLOntologyID(
                 IRI.create("http://stanbol.apache.org/ontologies/test/naming/named-2"));
         InputStream in = getClass().getResourceAsStream(location);
@@ -145,7 +152,7 @@ public class TestOntologyReconciliation 
      */
     @Test
     public void namedFromURL() throws Exception {
-        String location = "/ontologies/id/named-1.owl";
+        String location = "/ontologies/naming/named-1.owl";
         OWLOntologyID expectedId = new OWLOntologyID(
                 IRI.create("http://stanbol.apache.org/ontologies/test/naming/named-1"));
         URL url = getClass().getResource(location);
@@ -276,9 +283,102 @@ public class TestOntologyReconciliation 
         assertSame(0, ontologyProvider.listAliases(id2).size());
     }
 
-    @AfterClass
-    public static void cleanup() {
-        reset();
+    /*
+     * If an ontology has no ontology IRI but does have a version IRI, it should still be possible to load it,
+     * but the version IRI must be erased.
+     */
+    @Test
+    public void versionedOnlyFromStream() throws Exception {
+        String location = "/ontologies/naming/versionedonly.owl";
+
+        InputStream in = getClass().getResourceAsStream(location);
+        in.mark(Integer.MAX_VALUE);
+        OWLOntologyManager onMgr = OWLManager.createOWLOntologyManager();
+        OWLOntology o1 = onMgr.loadOntologyFromOntologyDocument(in);
+        // Ensure that the OWL API erases the version IRI.
+        assertTrue(o1.isAnonymous());
+        assertNull(o1.getOntologyID().getVersionIRI());
+        in.reset();
+        // in = getClass().getResourceAsStream(location); // use if stream cannot be reset
+
+        // The public key must be non-anonymous nonetheless.
+        OWLOntologyID key = ontologyProvider.loadInStore(in, RDF_XML, false);
+        assertNotNull(key);
+        assertFalse(key.isAnonymous());
+        assertNull(key.getVersionIRI());
+        log.info("Wrongly versioned ontology loaded with public key {}", key);
+        assertFalse(o1.equals(key));
+
+        OWLOntology o1_1 = ontologyProvider.getStoredOntology(key, OWLOntology.class, false);
+        assertNotNull(o1_1);
+        assertTrue(o1_1.isAnonymous());
+        assertNull(o1_1.getOntologyID().getVersionIRI());
+
+        // Cannot equal two OWLOntology objects, especially if anonymous.
+        // Check that they match axiom-wise.
+        log.warn("Plain OWL API seems to be failing to preserve owl:versionInfo. Will test non-annotation axioms only.");
+        assertEquals(o1.getTBoxAxioms(false), o1_1.getTBoxAxioms(false));
+        log.info(" -- TBox axiom check successful.");
+        assertEquals(o1.getABoxAxioms(false), o1_1.getABoxAxioms(false));
+        log.info(" -- ABox axiom check successful.");
+
+        // No aliases should have been created.
+        assertSame(0, ontologyProvider.listAliases(key).size());
+    }
+
+    /*
+     * If an ontology has no ontology IRI but does have a version IRI, it should still be possible to load it,
+     * but the version IRI must be erased. Plus, the public key should be created after the resource URL.
+     */
+    @Test
+    public void versionedOnlyFromURL() throws Exception {
+        String location = "/ontologies/naming/versionedonly.owl";
+        IRI url = IRI.create(getClass().getResource(location));
+
+        OWLOntologyID expected = new OWLOntologyID(url);
+
+        OWLOntologyManager onMgr = OWLManager.createOWLOntologyManager();
+        OWLOntology o1 = onMgr.loadOntologyFromOntologyDocument(url);
+        // Ensure that the OWL API erases the version IRI.
+        assertTrue(o1.isAnonymous());
+        assertNull(o1.getOntologyID().getVersionIRI());
+
+        // The public key must be non-anonymous nonetheless.
+        OWLOntologyID key = ontologyProvider.loadInStore(url, RDF_XML, false);
+        assertNotNull(key);
+        assertFalse(key.isAnonymous());
+
+        log.info("Wrongly versioned ontology loaded with public key {}", key);
+        assertFalse(o1.equals(key));
+        assertEquals(expected, key);
+        log.info(" -- (matches resource URL).");
+
+        OWLOntology o1_1 = ontologyProvider.getStoredOntology(key, OWLOntology.class, false);
+        assertNotNull(o1_1);
+        assertTrue(o1_1.isAnonymous());
+        assertNull(o1_1.getOntologyID().getVersionIRI());
+
+        // Cannot equal two OWLOntology objects, especially if anonymous.
+        // Check that they match axiom-wise.
+        log.warn("Plain OWL API seems to be failing to preserve owl:versionInfo. Will test non-annotation axioms only.");
+        assertEquals(o1.getTBoxAxioms(false), o1_1.getTBoxAxioms(false));
+        log.info(" -- TBox axiom check successful.");
+        assertEquals(o1.getABoxAxioms(false), o1_1.getABoxAxioms(false));
+        log.info(" -- ABox axiom check successful.");
+
+        // No aliases should have been created.
+        assertSame(0, ontologyProvider.listAliases(key).size());
+    }
+
+    /*
+     * Ensures ontology IDs with only the version IRI are illegal.
+     */
+    @Test
+    public void versionIriOnlyIsIllegal() {
+        try {
+            new OWLOntologyID(null, IRI.create("http://stanbol.apache.org/ontologies/version/bad/1"));
+            fail("An anonymous ontology ID with a version IRI was unexpectedly accepted!");
+        } catch (Exception ex) {}
     }
 
 }

Added: incubator/stanbol/trunk/ontologymanager/ontonet/src/test/resources/ontologies/naming/versionedonly.owl
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/ontonet/src/test/resources/ontologies/naming/versionedonly.owl?rev=1372359&view=auto
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/ontonet/src/test/resources/ontologies/naming/versionedonly.owl (added)
+++ incubator/stanbol/trunk/ontologymanager/ontonet/src/test/resources/ontologies/naming/versionedonly.owl Mon Aug 13 11:00:46 2012
@@ -0,0 +1,101 @@
+<?xml version="1.0"?>
+<!--
+  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.
+-->
+
+<!DOCTYPE rdf:RDF [
+    <!ENTITY foaf "http://xmlns.com/foaf/0.1/" >
+    <!ENTITY owl "http://www.w3.org/2002/07/owl#" >
+    <!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
+    <!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
+    <!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
+]>
+
+
+<rdf:RDF 
+     xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
+     xmlns:foaf="http://xmlns.com/foaf/0.1/"
+     xmlns:owl="http://www.w3.org/2002/07/owl#"
+     xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
+     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+    <owl:Ontology>
+        <rdfs:comment xml:lang="en">An ontology whose ID contains a version IRI but no ontology IRI. This is not allowed in OWL 2, therefore this ontology shoudl be used for negative testing.
+        </rdfs:comment>
+        <owl:versionInfo xml:lang="en">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 &quot;License&quot;); 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 &quot;AS IS&quot; 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.
+        </owl:versionInfo>
+        <owl:versionIRI rdf:resource="http://stanbol.apache.org/ontologies/version/bad/1"/>
+    </owl:Ontology>
+    
+
+
+    <!-- 
+    ///////////////////////////////////////////////////////////////////////////////////////
+    //
+    // Annotation properties
+    //
+    ///////////////////////////////////////////////////////////////////////////////////////
+     -->
+
+    
+
+
+    <!-- 
+    ///////////////////////////////////////////////////////////////////////////////////////
+    //
+    // Datatypes
+    //
+    ///////////////////////////////////////////////////////////////////////////////////////
+     -->
+
+    
+
+
+    <!-- 
+    ///////////////////////////////////////////////////////////////////////////////////////
+    //
+    // Individuals
+    //
+    ///////////////////////////////////////////////////////////////////////////////////////
+     -->
+
+    
+
+
+    <!-- http://stanbol.apache.org/ontologies/test/naming/versioned-bad#SomeGuy -->
+
+    <foaf:Person rdf:about="http://stanbol.apache.org/ontologies/test/naming/versioned-bad#SomeGuy">
+        <rdf:type rdf:resource="&owl;NamedIndividual"/>
+        <rdfs:label xml:lang="en">Some Guy</rdfs:label>
+    </foaf:Person>
+    
+
+
+    <!-- http://stanbol.apache.org/ontologies/test/naming/versioned-bad#SomeGal -->
+
+    <foaf:Person rdf:about="http://stanbol.apache.org/ontologies/test/naming/versioned-bad#SomeGal">
+        <rdf:type rdf:resource="&owl;NamedIndividual"/>
+        <rdfs:label xml:lang="en">Some Gal</rdfs:label>
+    </foaf:Person>
+</rdf:RDF>
+
+
+
+<!-- Generated by the OWL API (version 3.2.2.1789) http://owlapi.sourceforge.net -->
+