Author: alexdma
Date: Mon Feb 20 11:45:53 2012
New Revision: 1291214

URL: http://svn.apache.org/viewvc?rev=1291214&view=rev
Log:
Added unit test to verify STANBOL-495.

Added:
    
incubator/stanbol/trunk/ontologymanager/registry/src/test/resources/ontologies/registry/onmtest_inversepair.owl
Modified:
    incubator/stanbol/trunk/ontologymanager/registry/pom.xml
    
incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/Locations.java
    
incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/TestOntologyRegistry.java
    
incubator/stanbol/trunk/ontologymanager/registry/src/test/resources/ontologies/registry/onmtest_additions.owl

Modified: incubator/stanbol/trunk/ontologymanager/registry/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/registry/pom.xml?rev=1291214&r1=1291213&r2=1291214&view=diff
==============================================================================
--- incubator/stanbol/trunk/ontologymanager/registry/pom.xml (original)
+++ incubator/stanbol/trunk/ontologymanager/registry/pom.xml Mon Feb 20 
11:45:53 2012
@@ -123,6 +123,11 @@
                        <groupId>junit</groupId>
                        <artifactId>junit</artifactId>
                </dependency>
+       <dependency>
+               <groupId>org.slf4j</groupId>
+               <artifactId>slf4j-simple</artifactId>
+               <scope>test</scope>
+       </dependency>
                <dependency>
                        <groupId>org.apache.clerezza</groupId>
                        <artifactId>rdf.jena.parser</artifactId>

Modified: 
incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/Locations.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/Locations.java?rev=1291214&r1=1291213&r2=1291214&view=diff
==============================================================================
--- 
incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/Locations.java
 (original)
+++ 
incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/Locations.java
 Mon Feb 20 11:45:53 2012
@@ -40,6 +40,12 @@ public class Locations {
                                                                   + 
"registries/onmtest_additions.owl");
 
     /**
+     * Default physical location of the ontology registry for testing.
+     */
+    public static final IRI _REGISTRY_TEST_LOOP = 
IRI.create(__STANBOL_ONT_NAMESPACE
+                                                             + 
"registries/onmtest_inversepair.owl");
+
+    /**
      * An ontology in test library 1 but not in test library 2.
      */
     public static final IRI CHAR_ACTIVE = IRI.create(__STANBOL_ONT_NAMESPACE + 
"pcomics/characters_all.owl");

Modified: 
incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/TestOntologyRegistry.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/TestOntologyRegistry.java?rev=1291214&r1=1291213&r2=1291214&view=diff
==============================================================================
--- 
incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/TestOntologyRegistry.java
 (original)
+++ 
incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/TestOntologyRegistry.java
 Mon Feb 20 11:45:53 2012
@@ -22,6 +22,7 @@ import static org.junit.Assert.assertTru
 
 import java.io.File;
 import java.net.URL;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.Dictionary;
 import java.util.HashSet;
@@ -29,14 +30,12 @@ import java.util.Hashtable;
 import java.util.Set;
 
 import org.apache.clerezza.rdf.core.serializedform.Parser;
-import org.apache.clerezza.rdf.core.serializedform.Serializer;
 import org.apache.clerezza.rdf.simple.storage.SimpleTcProvider;
-import org.apache.stanbol.ontologymanager.ontonet.api.ONManager;
 import org.apache.stanbol.ontologymanager.ontonet.api.OfflineConfiguration;
-import org.apache.stanbol.ontologymanager.ontonet.impl.ONManagerImpl;
 import 
org.apache.stanbol.ontologymanager.ontonet.impl.OfflineConfigurationImpl;
 import 
org.apache.stanbol.ontologymanager.ontonet.impl.clerezza.ClerezzaOntologyProvider;
 import org.apache.stanbol.ontologymanager.registry.api.RegistryManager;
+import org.apache.stanbol.ontologymanager.registry.api.model.Library;
 import org.apache.stanbol.ontologymanager.registry.api.model.Registry;
 import org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem;
 import org.apache.stanbol.ontologymanager.registry.api.model.RegistryOntology;
@@ -54,9 +53,11 @@ import org.semanticweb.owlapi.util.AutoI
  */
 public class TestOntologyRegistry {
 
-    private String scopeIri = "Scope";
-    private static ONManager onm;
     private static RegistryManager regman;
+
+    /*
+     * This ontology manager will be empty on every test, except that it will 
have mappings to test resources.
+     */
     private OWLOntologyManager virginOntologyManager;
 
     /**
@@ -71,8 +72,6 @@ public class TestOntologyRegistry {
         // The registry manager can be updated via calls to createModel()
         regman = new RegistryManagerImpl(offline, new 
ClerezzaOntologyProvider(new SimpleTcProvider(),
                 offline, new Parser()), config);
-        // An ONManager with no storage support and same offline settings as 
the registry manager.
-        onm = new ONManagerImpl(null, null, offline, config);
     }
 
     /**
@@ -83,6 +82,7 @@ public class TestOntologyRegistry {
     @Before
     public void setupSources() throws Exception {
         virginOntologyManager = OWLManager.createOWLOntologyManager();
+        // Add mappings for any ontologies found in ontologies/registry
         URL url = getClass().getResource("/ontologies/registry");
         assertNotNull(url);
         virginOntologyManager.addIRIMapper(new AutoIRIMapper(new 
File(url.toURI()), true));
@@ -109,11 +109,37 @@ public class TestOntologyRegistry {
         // The nonexistent library should also be included, if using the more 
powerful algorithm.
         int count = 3; // set to 2 if using the less powerful algorithm.
         assertEquals(count, r.getChildren().length);
-        // There are no libreries without ontologies in the test registry.
+        // There are no libraries without ontologies in the test registry.
         for (RegistryItem ri : r.getChildren())
             assertTrue(ri.hasChildren());
     }
 
+    @Test
+    public void testLoopInLibrary() throws Exception {
+        // Create the model from the looping registry.
+        OWLOntology oReg = 
virginOntologyManager.loadOntology(Locations._REGISTRY_TEST_LOOP);
+        Set<Registry> rs = regman.createModel(Collections.singleton(oReg));
+
+        // There has to be a single registry, with the expected number of 
children (one).
+        assertEquals(1, rs.size());
+        Registry r = rs.iterator().next();
+        assertTrue(r.hasChildren());
+        int count = 1;
+        assertEquals(count, r.getChildren().length);
+        // There are no libreries without ontologies in the test registry.
+        for (RegistryItem child : r.getChildren()) {
+            assertTrue(child instanceof Library);
+            // Check both parent-child relations.
+            assertTrue(child.hasChildren());
+            for (RegistryItem grandchild : child.getChildren()) {
+                assertTrue(grandchild instanceof RegistryOntology);
+                assertTrue(grandchild.hasParents());
+                
assertTrue(Arrays.asList(grandchild.getParents()).contains(child));
+            }
+        }
+
+    }
+
     /**
      * Verifies that, when loading multiple registries that add library 
information to each other, the overall
      * model reflects the union of these registries.
@@ -153,45 +179,4 @@ public class TestOntologyRegistry {
         }
     }
 
-    // /**
-    // * Verifies that the addition of a null or valid registry source to a 
session space works.
-    // */
-    // @Test
-    // public void testAddRegistryToSessionSpace() throws Exception {
-    // SessionOntologySpace space = null;
-    // space = 
onm.getOntologySpaceFactory().createSessionOntologySpace(scopeIri);
-    // space.setUp();
-    // // space.addOntology(new
-    // // 
OntologyRegistryIRISource(testRegistryIri,onm.getOwlCacheManager(),onm.getRegistryLoader()));
-    // space.addOntology(ontologySource);
-    // // FIXME : no longer use the top ontology?
-    // assertTrue(space.asOWLOntology() != null);
-    // assertTrue(space.getOntologies(true).contains(space.asOWLOntology()));
-    // }
-    //
-    // /**
-    // * Verifies that an ontology scope with a null or valid registry source 
is created correctly.
-    // */
-    // @Test
-    // public void testScopeCreationWithRegistry() throws Exception {
-    // OntologyScope scope = null;
-    // // The input source instantiation automatically loads the entire 
content of a registry, no need to
-    // // test loading methods individually.
-    // scope = onm.getOntologyScopeFactory().createOntologyScope(scopeIri, 
ontologySource);
-    // assertTrue(scope != null && scope.getCoreSpace().asOWLOntology() != 
null);
-    // }
-    //
-    // /**
-    // * Verifies that an ontology space with a null or valid registry source 
is created correctly.
-    // */
-    // @Test
-    // public void testSpaceCreationWithRegistry() throws Exception {
-    // // setupOfflineMapper();
-    // CoreOntologySpace space = null;
-    // // The input source instantiation automatically loads the entire 
content of a registry, no need to
-    // // test loading methods individually.
-    // space = onm.getOntologySpaceFactory().createCoreOntologySpace(scopeIri, 
ontologySource);
-    // assertTrue(space != null && space.asOWLOntology() != null);
-    // }
-
 }

Modified: 
incubator/stanbol/trunk/ontologymanager/registry/src/test/resources/ontologies/registry/onmtest_additions.owl
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/registry/src/test/resources/ontologies/registry/onmtest_additions.owl?rev=1291214&r1=1291213&r2=1291214&view=diff
==============================================================================
--- 
incubator/stanbol/trunk/ontologymanager/registry/src/test/resources/ontologies/registry/onmtest_additions.owl
 (original)
+++ 
incubator/stanbol/trunk/ontologymanager/registry/src/test/resources/ontologies/registry/onmtest_additions.owl
 Mon Feb 20 11:45:53 2012
@@ -1,30 +1,33 @@
 <?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.
--->
-<rdf:RDF
-    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";
-    xmlns:xsd="http://www.w3.org/2001/XMLSchema#";
-    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#";
-    xmlns:owl="http://www.w3.org/2002/07/owl#";
-    xmlns:meta="http://www.ontologydesignpatterns.org/schemas/meta.owl#";
-    
xmlns="http://stanbol.apache.org/ontologies/registries/onmtest_additions.owl#";
-    
xml:base="http://stanbol.apache.org/ontologies/registries/onmtest_additions.owl";>
-    <owl:Ontology rdf:about="">
-        <owl:versionInfo 
rdf:datatype="http://www.w3.org/2001/XMLSchema#string";>0.1.0</owl:versionInfo>
+<!DOCTYPE rdf:RDF [
+    <!ENTITY owl "http://www.w3.org/2002/07/owl#"; >
+    <!ENTITY xsd "http://www.w3.org/2001/XMLSchema#"; >
+    <!ENTITY ontologies "http://stanbol.apache.org/ontologies/"; >
+    <!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#"; >
+    <!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#"; >
+    <!ENTITY meta "http://www.ontologydesignpatterns.org/schemas/meta.owl#"; >
+    <!ENTITY onmtest 
"http://stanbol.apache.org/ontologies/registries/onmtest.owl#"; >
+    <!ENTITY coddata 
"http://www.ontologydesignpatterns.org/cpont/codo/coddata.owl#"; >
+    <!ENTITY codkernel 
"http://www.ontologydesignpatterns.org/cpont/codo/codkernel.owl#"; >
+]>
+
+
+<rdf:RDF xmlns="&ontologies;registries/onmtest_additions.owl#"
+     xml:base="&ontologies;registries/onmtest_additions.owl"
+     xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#";
+     
xmlns:codkernel="http://www.ontologydesignpatterns.org/cpont/codo/codkernel.owl#";
+     xmlns:ontologies="http://stanbol.apache.org/ontologies/";
+     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#";
+     xmlns:onmtest="&ontologies;registries/onmtest.owl#"
+     
xmlns:coddata="http://www.ontologydesignpatterns.org/cpont/codo/coddata.owl#";
+     xmlns:meta="http://www.ontologydesignpatterns.org/schemas/meta.owl#";>
+    <owl:Ontology rdf:about="&ontologies;registries/onmtest_additions.owl">
+        <owl:versionInfo rdf:datatype="&xsd;string">0.1.0</owl:versionInfo>
+        <rdfs:comment>A registry that adds ontologies to libraries already 
defined in http://stanbol.apache.org/ontologies/registries/onmtest.owl (which 
is NOT imported by this ontology). Used for unit testing.</rdfs:comment>
         <owl:versionInfo xml:lang="en">Created by Alessandro 
Adamou</owl:versionInfo>
         <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
 
@@ -32,15 +35,62 @@
 
 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>
-        <rdfs:comment>A registry that adds ontologies to libraries already 
defined in http://stanbol.apache.org/ontologies/registries/onmtest.owl (which 
is NOT imported by this ontology). Used for unit testing.</rdfs:comment>
         <owl:imports 
rdf:resource="http://www.ontologydesignpatterns.org/schemas/meta.owl"/>
     </owl:Ontology>
-  
-    <!-- For testing additions to other libraries -->
-    <rdf:Description 
rdf:about="http://stanbol.apache.org/ontologies/test1.owl";>
-        <rdfs:label 
rdf:datatype="http://www.w3.org/2001/XMLSchema#string";>Test Model 1</rdfs:label>
-        <meta:isOntologyOf 
rdf:resource="http://stanbol.apache.org/ontologies/registries/onmtest.owl#Library1"/>
-        <rdf:type 
rdf:resource="http://www.ontologydesignpatterns.org/cpont/codo/codkernel.owl#Ontology"/>
-    </rdf:Description>
     
-</rdf:RDF>
\ No newline at end of file
+
+
+    <!-- 
+    
///////////////////////////////////////////////////////////////////////////////////////
+    //
+    // Annotation properties
+    //
+    
///////////////////////////////////////////////////////////////////////////////////////
+     -->
+
+    
+
+
+    <!-- 
+    
///////////////////////////////////////////////////////////////////////////////////////
+    //
+    // Datatypes
+    //
+    
///////////////////////////////////////////////////////////////////////////////////////
+     -->
+
+    
+
+
+    <!-- 
+    
///////////////////////////////////////////////////////////////////////////////////////
+    //
+    // Individuals
+    //
+    
///////////////////////////////////////////////////////////////////////////////////////
+     -->
+
+    
+
+
+    <!-- http://stanbol.apache.org/ontologies/test1.owl -->
+
+    <owl:NamedIndividual rdf:about="&ontologies;test1.owl">
+        <rdf:type rdf:resource="&codkernel;Ontology"/>
+        <rdfs:label rdf:datatype="&xsd;string">Test Model 1</rdfs:label>
+        <meta:isOntologyOf 
rdf:resource="&ontologies;registries/onmtest.owl#Library1"/>
+    </owl:NamedIndividual>
+    
+
+
+    <!-- http://stanbol.apache.org/ontologies/registries/onmtest.owl#Library1 
-->
+
+    <owl:NamedIndividual 
rdf:about="&ontologies;registries/onmtest.owl#Library1">
+        <rdf:type rdf:resource="&coddata;OntologyLibrary"/>
+    </owl:NamedIndividual>
+</rdf:RDF>
+
+
+
+<!-- Generated by the OWL API (version 3.2.3.1824) 
http://owlapi.sourceforge.net -->
+

Added: 
incubator/stanbol/trunk/ontologymanager/registry/src/test/resources/ontologies/registry/onmtest_inversepair.owl
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/registry/src/test/resources/ontologies/registry/onmtest_inversepair.owl?rev=1291214&view=auto
==============================================================================
--- 
incubator/stanbol/trunk/ontologymanager/registry/src/test/resources/ontologies/registry/onmtest_inversepair.owl
 (added)
+++ 
incubator/stanbol/trunk/ontologymanager/registry/src/test/resources/ontologies/registry/onmtest_inversepair.owl
 Mon Feb 20 11:45:53 2012
@@ -0,0 +1,50 @@
+<?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.
+-->
+<rdf:RDF
+    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";
+    xmlns:xsd="http://www.w3.org/2001/XMLSchema#";
+    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#";
+    xmlns:owl="http://www.w3.org/2002/07/owl#";
+    xmlns:meta="http://www.ontologydesignpatterns.org/schemas/meta.owl#";
+    xmlns="http://stanbol.apache.org/ontologies/registries/onmtest.owl#";
+    
xml:base="http://stanbol.apache.org/ontologies/registries/onmtest_inversepair.owl";>
+    <owl:Ontology rdf:about="">
+        <owl:versionInfo 
rdf:datatype="http://www.w3.org/2001/XMLSchema#string";>0.1.0</owl:versionInfo>
+        <owl:versionInfo xml:lang="en">Created by Alessandro 
Adamou</owl:versionInfo>
+        <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>
+        <rdfs:comment>A registry that introduces a materialization of the pair 
(hasOntology,isOntologyof). It is used to test if this causes loops when 
building the model, and to verify its equivalence with having only one 
predicate.</rdfs:comment>
+        <owl:imports 
rdf:resource="http://www.ontologydesignpatterns.org/schemas/meta.owl"/>
+    </owl:Ontology>
+  
+    <!-- For testing additions to other libraries -->
+    <rdf:Description 
rdf:about="http://stanbol.apache.org/ontologies/testloop.owl";>
+        <meta:isOntologyOf 
rdf:resource="http://stanbol.apache.org/ontologies/registries/onmtest.owl#Library1"/>
+        <rdf:type 
rdf:resource="http://www.ontologydesignpatterns.org/cpont/codo/codkernel.owl#Ontology"/>
+    </rdf:Description>
+    
+    <rdf:Description 
rdf:about="http://stanbol.apache.org/ontologies/registries/onmtest.owl#Library1";>
+        <rdf:type 
rdf:resource="http://www.ontologydesignpatterns.org/cpont/codo/coddata.owl#OntologyLibrary"/>
+        <meta:hasOntology 
rdf:resource="http://stanbol.apache.org/ontologies/testloop.owl"/>
+    </rdf:Description>
+    
+</rdf:RDF>
\ No newline at end of file


Reply via email to