Author: alexdma
Date: Thu Jul 28 16:27:13 2011
New Revision: 1151910
URL: http://svn.apache.org/viewvc?rev=1151910&view=rev
Log:
STANBOL-285 : refined unit tests, javadoc, code cleanup.
Modified:
incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/api/RegistryManager.java
incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/model/LibraryImpl.java
incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/model/RegistryImpl.java
incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/io/LibrarySource.java
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/TestOntologyLibrary.java
incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/TestOntologyRegistry.java
incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/TestRegistryManager.java
Modified:
incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/api/RegistryManager.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/api/RegistryManager.java?rev=1151910&r1=1151909&r2=1151910&view=diff
==============================================================================
---
incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/api/RegistryManager.java
(original)
+++
incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/api/RegistryManager.java
Thu Jul 28 16:27:13 2011
@@ -85,6 +85,11 @@ public interface RegistryManager extends
*/
CachingPolicy getCachingPolicy();
+ /**
+ * Returns the offline configuration currently employed by this registry
manager.
+ *
+ * @return the offline configuration in use.
+ */
OfflineConfiguration getOfflineConfiguration();
/**
@@ -104,7 +109,7 @@ public interface RegistryManager extends
* the ontology registry to be removed.
*/
void removeRegistry(IRI registryId);
-
+
/**
* Sets the resource loading policy of this registry manager. There is no
guarantee that setting a policy
* after a model has already been created will affect the existing model
(i.e. unload all its ontologies
Modified:
incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/model/LibraryImpl.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/model/LibraryImpl.java?rev=1151910&r1=1151909&r2=1151910&view=diff
==============================================================================
---
incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/model/LibraryImpl.java
(original)
+++
incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/model/LibraryImpl.java
Thu Jul 28 16:27:13 2011
@@ -46,19 +46,51 @@ public class LibraryImpl extends Abstrac
private Logger log = LoggerFactory.getLogger(getClass());
+ /**
+ * Creates a new instance of {@link LibraryImpl}.
+ *
+ * @param iri
+ * the library identifier and possible physical location.
+ */
public LibraryImpl(IRI iri) {
this(iri, OWLManager.createOWLOntologyManager());
}
+ /**
+ * Creates a new instance of {@link LibraryImpl}.
+ *
+ * @param iri
+ * the library identifier and possible physical location.
+ * @param cache
+ * the {@link OWLOntologyManager} to be used for caching
ontologies in-memory.
+ */
public LibraryImpl(IRI iri, OWLOntologyManager cache) {
super(iri);
setCache(cache);
}
+ /**
+ * Creates a new instance of {@link LibraryImpl}.
+ *
+ * @param iri
+ * the library identifier and possible physical location.
+ * @param name
+ * the short name of this library.
+ */
public LibraryImpl(IRI iri, String name) {
this(iri, name, OWLManager.createOWLOntologyManager());
}
+ /**
+ * Creates a new instance of {@link LibraryImpl}.
+ *
+ * @param iri
+ * the library identifier and possible physical location.
+ * @param name
+ * the short name of this library.
+ * @param cache
+ * the {@link OWLOntologyManager} to be used for caching
ontologies in-memory.
+ */
public LibraryImpl(IRI iri, String name, OWLOntologyManager cache) {
super(iri, name);
setCache(cache);
@@ -104,13 +136,6 @@ public class LibraryImpl extends Abstrac
}
@Override
- public void removeChild(RegistryItem child) {
- super.removeChild(child);
- // Also unload the ontology version that comes from this library.
- if (child instanceof RegistryOntology) ((RegistryOntology)
child).setRawOntology(getIRI(), null);
- }
-
- @Override
public synchronized void loadOntologies(OWLOntologyManager mgr) {
if (mgr == null) throw new IllegalArgumentException("A null ontology
manager is not allowed.");
for (RegistryItem item : getChildren()) {
@@ -132,6 +157,13 @@ public class LibraryImpl extends Abstrac
}
@Override
+ public void removeChild(RegistryItem child) {
+ super.removeChild(child);
+ // Also unload the ontology version that comes from this library.
+ if (child instanceof RegistryOntology) ((RegistryOntology)
child).setRawOntology(getIRI(), null);
+ }
+
+ @Override
public void setCache(OWLOntologyManager cache) {
// TODO use the ontology manager factory.
if (cache == null) cache = OWLManager.createOWLOntologyManager();
Modified:
incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/model/RegistryImpl.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/model/RegistryImpl.java?rev=1151910&r1=1151909&r2=1151910&view=diff
==============================================================================
---
incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/model/RegistryImpl.java
(original)
+++
incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/impl/model/RegistryImpl.java
Thu Jul 28 16:27:13 2011
@@ -35,6 +35,7 @@ public class RegistryImpl extends Abstra
return this.message;
}
+ @Override
public String getName() {
return super.getName() + getError();
}
Modified:
incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/io/LibrarySource.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/io/LibrarySource.java?rev=1151910&r1=1151909&r2=1151910&view=diff
==============================================================================
---
incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/io/LibrarySource.java
(original)
+++
incubator/stanbol/trunk/ontologymanager/registry/src/main/java/org/apache/stanbol/ontologymanager/registry/io/LibrarySource.java
Thu Jul 28 16:27:13 2011
@@ -44,6 +44,13 @@ import org.slf4j.LoggerFactory;
*/
public class LibrarySource extends AbstractOntologyInputSource {
+ private static OWLOntologyManager checkOntologyManager(RegistryManager
registryManager) {
+ OfflineConfiguration offline =
registryManager.getOfflineConfiguration();
+ if (offline == null) return OWLManager.createOWLOntologyManager();
+ return
OWLOntologyManagerFactory.createOWLOntologyManager(offline.getOntologySourceLocations()
+ .toArray(new IRI[0]));
+ }
+
private IRI libraryID;
private Logger log = LoggerFactory.getLogger(getClass());
@@ -62,13 +69,6 @@ public class LibrarySource extends Abstr
this(libraryID, new RegistryManagerImpl(null, new
Hashtable<String,Object>()));
}
- private static OWLOntologyManager checkOntologyManager(RegistryManager
registryManager) {
- OfflineConfiguration offline =
registryManager.getOfflineConfiguration();
- if (offline == null) return OWLManager.createOWLOntologyManager();
- return
OWLOntologyManagerFactory.createOWLOntologyManager(offline.getOntologySourceLocations()
- .toArray(new IRI[0]));
- }
-
/**
* Creates a new ontology source from a library. The physical registry
location is assumed to be the
* parent URL of <code>libraryID</code>. <br/>
@@ -78,122 +78,13 @@ public class LibrarySource extends Abstr
*
* @param libraryID
* the identifier of the ontology library.
- * @param loader
+ * @param registryManager
+ * the registry manager that should contain the library data.
Must not be null.
*/
public LibrarySource(IRI libraryID, RegistryManager registryManager)
throws RegistryContentException {
this(libraryID, registryManager,
checkOntologyManager(registryManager));
}
- // /**
- // * Creates a new ontology source from a library.
- // *
- // * @param libraryID
- // * @param registryLocation
- // */
- // public LibrarySource(IRI libraryID, IRI registryLocation) {
- // this(libraryID, registryLocation, null);
- // }
-
- // /**
- // * Creates a new ontology source from a library.
- // *
- // * @param libraryID
- // * the identifier of the ontology library.
- // * @param registryLocation
- // * @param ontologyManager
- // * @param loader
- // */
- // public LibrarySource(IRI libraryID,
- // IRI registryLocation,
- // OWLOntologyManager ontologyManager,
- // RegistryLoader loader) {
- // this(libraryID, registryLocation, ontologyManager, loader, null);
- // }
-
- // /**
- // * Creates a new ontology source from a library.
- // *
- // * @param libraryID
- // * the identifier of the ontology library.
- // * @param registryLocation
- // * @param ontologyManager
- // * @param loader
- // * @param parentSrc
- // * the source of the ontology that will import all the ontologies in the
registry. If null, a
- // * new blank ontology will be used.
- // */
- // public LibrarySource(IRI libraryID,
- // IRI registryLocation,
- // OWLOntologyManager ontologyManager,
- // RegistryLoader loader,
- // OntologyInputSource parentSrc) {
- // this.libraryID = libraryID;
- //
- // // The ontology that imports the whole network is created in-memory,
therefore it has no physical IRI.
- // bindPhysicalIri(null);
- //
- // Set<OWLOntology> subtrees = new HashSet<OWLOntology>();
- // Registry reg = loader.loadLibrary(registryLocation, libraryID);
- // for (RegistryItem ri : reg.getChildren()) {
- // if (ri.isLibrary()) try {
- // Set<OWLOntology> adds = loader.gatherOntologies(ri, ontologyManager,
true);
- // subtrees.addAll(adds);
- // } catch (OWLOntologyAlreadyExistsException e) {
- // // Chettefreca
- // continue;
- // } catch (OWLOntologyCreationException e) {
- // log.warn("Failed to load ontology library " + ri.getName() + ".
Skipping.", e);
- // // If we can't load this library at all, scrap it.
- // // TODO : not entirely convinced of this step.
- // continue;
- // }
- // }
- //
- // // We always construct a new root now, even if there's just one subtree.
- //
- // // Set<OWLOntology> subtrees = mgr.getOntologies();
- // // if (subtrees.size() == 1)
- // // rootOntology = subtrees.iterator().next();
- // // else
- // try {
- // if (parentSrc != null)
bindRootOntology(OntologyUtils.buildImportTree(parentSrc, subtrees,
- // ontologyManager));
- // else bindRootOntology(OntologyUtils.buildImportTree(subtrees,
ontologyManager));
- // } catch (OWLOntologyCreationException e) {
- // log.error("Failed to build import tree for registry source " +
registryLocation, e);
- // }
- // }
-
- // /**
- // * Creates a new ontology source from a library.
- // *
- // * @param libraryID
- // * the identifier of the ontology library.
- // * @param registryLocation
- // * @param loader
- // */
- // public LibrarySource(IRI libraryID, IRI registryLocation,
RegistryLoader loader) {
- // this(libraryID, registryLocation,
OWLManager.createOWLOntologyManager(), loader);
- // }
-
- // /**
- // * Creates a new ontology source from a library.
- // *
- // * @param libraryID
- // * the identifier of the ontology library.
- // * @param registryLocation
- // * @param loader
- // * @param parentSrc
- // * the source of the ontology that will import all the ontologies in the
registry. If null, a
- // * new blank ontology will be used.
- // */
- // public LibrarySource(IRI libraryID,
- // IRI registryLocation,
- // RegistryLoader loader,
- // OntologyInputSource parentSrc) {
- // this(libraryID, registryLocation,
OWLManager.createOWLOntologyManager(), loader, parentSrc);
- // }
-
/**
* Creates a new ontology source from a library. The physical registry
location is assumed to be the
* parent URL of <code>libraryID</code>. <br/>
@@ -203,7 +94,8 @@ public class LibrarySource extends Abstr
*
* @param libraryID
* the identifier of the ontology library.
- * @param loader
+ * @param registryManager
+ * the registry manager that should contain the library data.
Must not be null.
* @param parentSrc
* the source of the ontology that will import all the
ontologies in the registry. If null, a
* new blank ontology will be used.
@@ -221,36 +113,34 @@ public class LibrarySource extends Abstr
*
* @param libraryID
* the identifier of the ontology library.
+ * @param registryManager
+ * the registry manager that should contain the library data.
Must not be null.
* @param ontologyManager
- * @param loader
+ * the ontology manager to be used for constructing the import
tree. if null, a new one will be
+ * used.
*/
public LibrarySource(IRI libraryID, RegistryManager registryManager,
OWLOntologyManager ontologyManager) throws RegistryContentException {
this(libraryID, registryManager, ontologyManager, null);
}
- //
- // /**
- // * Creates a new ontology source from a library. The physical registry
location is assumed to be the
- // * parent URL of <code>libraryID</code>. <br/>
- // * <br/>
- // * Example : if <code>libraryID</code> is
<tt>http://foo.bar.baz/registry#library</tt>, the registry
- // * location will be <tt>http://foo.bar.baz/registry</tt>. Same goes for
slash-URIs.
- // *
- // * @param libraryID
- // * the identifier of the ontology library.
- // * @param ontologyManager
- // * @param loader
- // * @param parentSrc
- // * the source of the ontology that will import all the ontologies in the
registry. If null, a
- // * new blank ontology will be used.
- // */
- // public LibrarySource(IRI libraryID,
- // OWLOntologyManager ontologyManager,
- // RegistryLoader loader,
- // OntologyInputSource parentSrc) {
- // this(libraryID, URIUtils.upOne(libraryID), ontologyManager, loader,
parentSrc);
- // }
-
+ /**
+ * Creates a new ontology source from a library. The physical registry
location is assumed to be the
+ * parent URL of <code>libraryID</code>. <br/>
+ * <br/>
+ * Example : if <code>libraryID</code> is
<tt>http://foo.bar.baz/registry#library</tt>, the registry
+ * location will be <tt>http://foo.bar.baz/registry</tt>. Same goes for
slash-URIs.
+ *
+ * @param libraryID
+ * the identifier of the ontology library.
+ * @param registryManager
+ * the registry manager that should contain the library data.
Must not be null.
+ * @param ontologyManager
+ * the ontology manager to be used for constructing the import
tree. if null, a new one will be
+ * used.
+ * @param parentSrc
+ * the source of the ontology that will import all the
ontologies in the registry. If null, a
+ * new blank ontology will be used.
+ */
public LibrarySource(IRI libraryID,
RegistryManager registryManager,
OWLOntologyManager ontologyManager,
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=1151910&r1=1151909&r2=1151910&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
Thu Jul 28 16:27:13 2011
@@ -66,8 +66,12 @@ public class Locations {
public static final IRI LIBRARY_TEST2 = IRI.create(_REGISTRY_TEST +
"#Library2");
/**
+ * Non existing and not referenced by any library. Used for negative tests.
+ */
+ public static final IRI ONT_BOGUS = IRI.create(__STANBOL_ONT_NAMESPACE +
"bogus.owl");
+
+ /**
* Identifier of test ontology library 1.
*/
public static final IRI ONT_TEST1 = IRI.create(__STANBOL_ONT_NAMESPACE +
"test1.owl");
-
}
Modified:
incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/TestOntologyLibrary.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/TestOntologyLibrary.java?rev=1151910&r1=1151909&r2=1151910&view=diff
==============================================================================
---
incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/TestOntologyLibrary.java
(original)
+++
incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/TestOntologyLibrary.java
Thu Jul 28 16:27:13 2011
@@ -22,6 +22,7 @@ import java.io.File;
import java.net.URL;
import java.util.Dictionary;
import java.util.Hashtable;
+import java.util.Set;
import org.apache.stanbol.ontologymanager.ontonet.api.OfflineConfiguration;
import org.apache.stanbol.ontologymanager.ontonet.api.io.OntologyInputSource;
@@ -53,7 +54,10 @@ public class TestOntologyLibrary {
private static OfflineConfiguration offline;
/**
- * Sets the ontology network manager and registry loader before running
the tests.
+ * Sets the offline configuration (identical across tests) before running
the tests.
+ *
+ * @throws Exception
+ * if any error occurs;
*/
@BeforeClass
public static void setupTest() throws Exception {
@@ -62,12 +66,15 @@ public class TestOntologyLibrary {
offline = new OfflineConfigurationImpl(config);
}
- private String registryResource = "/ontologies/registry/onmtest.owl";
+ private String registryResourcePath = "/ontologies/registry/onmtest.owl";
private RegistryManager regMgr;
private OWLOntologyManager virginOntologyManager;
+ /**
+ * Resets the registry manager, which each unit test needs to reconfigure
individually.
+ */
@After
public void reset() {
regMgr = null;
@@ -95,24 +102,28 @@ public class TestOntologyLibrary {
}
/**
- * Uses a plain {@link RegistryLoader} to load a single ontology library
and checks for its expected hits
+ * Uses a plain {@link RegistryManager} to load a single ontology library
and checks for its expected hits
* and misses.
*
* @throws Exception
+ * if any error occurs;
*/
@Test
public void testLibraryLoad() throws Exception {
- IRI localTestRegistry =
IRI.create(getClass().getResource(registryResource));
-
+ IRI localTestRegistry =
IRI.create(getClass().getResource(registryResourcePath));
Dictionary<String,Object> regmanConf = new Hashtable<String,Object>();
regmanConf.put(RegistryManager.REGISTRY_LOCATIONS, new String[]
{localTestRegistry.toString()});
+ // Instantiating the registry manager will also load the registry data.
regMgr = new RegistryManagerImpl(offline, regmanConf);
+
+ // The resulting manager must exist and have exactly one registry.
assertNotNull(regMgr);
+ Set<Registry> registries = regMgr.getRegistries();
+ assertFalse(registries.isEmpty());
+ assertEquals(1, registries.size());
- assertFalse(regMgr.getRegistries().isEmpty());
- assertEquals(1, regMgr.getRegistries().size());
- Registry reg = regMgr.getRegistries().iterator().next();
+ Registry reg = registries.iterator().next();
assertTrue(reg.hasChildren());
Library lib = null;
// Look for test #Library2
@@ -140,13 +151,14 @@ public class TestOntologyLibrary {
@Test
public void testLibrarySourceCreation() throws Exception {
- IRI localTestRegistry =
IRI.create(getClass().getResource(registryResource));
-
+ IRI localTestRegistry =
IRI.create(getClass().getResource(registryResourcePath));
Dictionary<String,Object> regmanConf = new Hashtable<String,Object>();
regmanConf.put(RegistryManager.REGISTRY_LOCATIONS, new String[]
{localTestRegistry.toString()});
+ // Instantiating the registry manager will also load the registry data.
regMgr = new RegistryManagerImpl(offline, regmanConf);
assertNotNull(regMgr);
+ // Now use this registry manager to instantiate an input source.
OntologyInputSource src = new LibrarySource(Locations.LIBRARY_TEST1,
regMgr, virginOntologyManager);
OWLOntology o = src.getRootOntology();
boolean hasImporting = false, hasImported = false;
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=1151910&r1=1151909&r2=1151910&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
Thu Jul 28 16:27:13 2011
@@ -26,13 +26,11 @@ import java.util.HashSet;
import java.util.Hashtable;
import java.util.Set;
-import org.apache.stanbol.ontologymanager.ontonet.api.DuplicateIDException;
import org.apache.stanbol.ontologymanager.ontonet.api.ONManager;
import org.apache.stanbol.ontologymanager.ontonet.api.OfflineConfiguration;
import
org.apache.stanbol.ontologymanager.ontonet.api.ontology.CoreOntologySpace;
import org.apache.stanbol.ontologymanager.ontonet.api.ontology.OntologyScope;
import
org.apache.stanbol.ontologymanager.ontonet.api.ontology.SessionOntologySpace;
-import
org.apache.stanbol.ontologymanager.ontonet.api.ontology.UnmodifiableOntologySpaceException;
import org.apache.stanbol.ontologymanager.ontonet.impl.ONManagerImpl;
import
org.apache.stanbol.ontologymanager.ontonet.impl.OfflineConfigurationImpl;
import org.apache.stanbol.ontologymanager.registry.api.RegistryManager;
@@ -41,6 +39,7 @@ import org.apache.stanbol.ontologymanage
import org.apache.stanbol.ontologymanager.registry.api.model.RegistryOntology;
import org.apache.stanbol.ontologymanager.registry.impl.RegistryManagerImpl;
import org.apache.stanbol.ontologymanager.registry.io.RegistryIRISource;
+import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.semanticweb.owlapi.apibinding.OWLManager;
@@ -49,66 +48,79 @@ import org.semanticweb.owlapi.model.OWLO
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.util.AutoIRIMapper;
+/**
+ * Verifies the correct setup of ontology registries.
+ */
public class TestOntologyRegistry {
- private static RegistryIRISource ontologySource;
+ private IRI scopeIri = IRI.create(Locations.__STANBOL_ONT_NAMESPACE +
"Scope");
+ private static RegistryIRISource ontologySource; // Null until the
RegistryIRISource stays in place.
private static ONManager onm;
private static RegistryManager regman;
+ private OWLOntologyManager virginOntologyManager;
+ /**
+ * Sets the registry and ontology network managers, which are immutable
across tests.
+ */
@BeforeClass
public static void setup() {
+ // We use a single Dictionary for storing all configurations.
final Dictionary<String,Object> config = new
Hashtable<String,Object>();
config.put(OfflineConfiguration.ONTOLOGY_PATHS, new String[]
{"/ontologies", "/ontologies/registry"});
OfflineConfiguration offline = new OfflineConfigurationImpl(config);
+ // The registry manager can be updated via calls to createModel()
regman = new RegistryManagerImpl(offline, config);
- // An ONManagerImpl with no store and same offline settings as the
registry manager.
+ // An ONManager with no storage support and same offline settings as
the registry manager.
onm = new ONManagerImpl(null, null, offline, config);
}
- // private static boolean mapperIsSet = false;
- //
- // public void setupOfflineMapper() {
- // if (mapperIsSet) {} else {
- // ontologySource = new OntologyRegistryIRISource(testRegistryIri,
ontologyManager, loader);
- // mapperIsSet = true;
- // }
- // }
-
- @Test
- public void testPopulateRegistry() throws Exception {
- OWLOntologyManager virginOntologyManager =
OWLManager.createOWLOntologyManager();
+ /**
+ * Resets the virgin ontology manager for each test.
+ *
+ * @throws Exception
+ */
+ @Before
+ public void setupSources() throws Exception {
+ virginOntologyManager = OWLManager.createOWLOntologyManager();
URL url = getClass().getResource("/ontologies/registry");
assertNotNull(url);
virginOntologyManager.addIRIMapper(new AutoIRIMapper(new
File(url.toURI()), true));
// Population is lazy; no need to add other mappers.
+ }
+
+ /**
+ * Verifies that a call to {@link RegistryManager#createModel(Set)} with a
registry location creates the
+ * object model accordingly.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testPopulateRegistry() throws Exception {
+ // Create the model from a single registry.
OWLOntology oReg =
virginOntologyManager.loadOntology(Locations._REGISTRY_TEST);
Set<Registry> rs = regman.createModel(Collections.singleton(oReg));
+ // There has to be a single registry, with the expected number of
children.
assertEquals(1, rs.size());
Registry r = rs.iterator().next();
assertTrue(r.hasChildren());
// 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.
for (RegistryItem ri : r.getChildren())
assertTrue(ri.hasChildren());
}
/**
- * Verify that, when loading multiple registries that add library
information to each other, the overall
+ * Verifies that, when loading multiple registries that add library
information to each other, the overall
* model reflects the union of these registries.
*
* @throws Exception
*/
@Test
public void testRegistryUnion() throws Exception {
- OWLOntologyManager virginOntologyManager =
OWLManager.createOWLOntologyManager();
- URL url = getClass().getResource("/ontologies/registry");
- assertNotNull(url);
- virginOntologyManager.addIRIMapper(new AutoIRIMapper(new
File(url.toURI()), true));
- // Population is lazy; no need to add other mappers.
// Create the model from two overlapping registries.
Set<OWLOntology> regs = new HashSet<OWLOntology>();
@@ -122,7 +134,7 @@ public class TestOntologyRegistry {
if (Locations._REGISTRY_TEST.equals(r.getIRI()))
assertEquals(count, r.getChildren().length);
else if (Locations._REGISTRY_TEST_ADDITIONS.equals(r.getIRI()))
assertEquals(1,
r.getChildren().length);
- // check
+ // Check that we find the expected ontology in the expected
library.
for (RegistryItem lib : r.getChildren()) {
if (Locations.LIBRARY_TEST1.equals(lib.getIRI())) {
boolean found = false;
@@ -140,49 +152,42 @@ 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 {
- // setupOfflineMapper();
- IRI scopeIri = IRI.create("http://fise.iks-project.eu/scopone");
SessionOntologySpace space = null;
space =
onm.getOntologySpaceFactory().createSessionOntologySpace(scopeIri);
space.setUp();
- try {
- // space.addOntology(new
- //
OntologyRegistryIRISource(testRegistryIri,onm.getOwlCacheManager(),onm.getRegistryLoader()));
- space.addOntology(ontologySource);
- } catch (UnmodifiableOntologySpaceException e) {
- fail("Adding libraries to session space failed. "
- + "This should not happen for active session spaces.");
- }
-
+ // space.addOntology(new
+ //
OntologyRegistryIRISource(testRegistryIri,onm.getOwlCacheManager(),onm.getRegistryLoader()));
+ space.addOntology(ontologySource);
assertTrue(space.getTopOntology() != null);
assertTrue(space.getOntologies().contains(space.getTopOntology()));
}
+ /**
+ * Verifies that an ontology scope with a null or valid registry source is
created correctly.
+ */
@Test
- public void testScopeCreationWithRegistry() {
- // setupOfflineMapper();
- IRI scopeIri = IRI.create("http://fise.iks-project.eu/scopone");
+ public void testScopeCreationWithRegistry() throws Exception {
OntologyScope scope = null;
- // The factory call also invokes loadRegistriesEager() and
- // gatherOntologies() so no need to test them individually.
- try {
- scope =
onm.getOntologyScopeFactory().createOntologyScope(scopeIri, ontologySource);
- } catch (DuplicateIDException e) {
- fail("DuplicateID exception caught when creating test scope.");
- }
-
+ // 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().getTopOntology() !=
null);
}
+ /**
+ * Verifies that an ontology space with a null or valid registry source is
created correctly.
+ */
@Test
- public void testSpaceCreationWithRegistry() {
+ public void testSpaceCreationWithRegistry() throws Exception {
// setupOfflineMapper();
- IRI scopeIri = IRI.create("http://fise.iks-project.eu/scopone");
CoreOntologySpace space = null;
- // The factory call also invokes loadRegistriesEager() and
- // gatherOntologies() so no need to test them individually.
+ // 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.getTopOntology() != null);
}
Modified:
incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/TestRegistryManager.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/TestRegistryManager.java?rev=1151910&r1=1151909&r2=1151910&view=diff
==============================================================================
---
incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/TestRegistryManager.java
(original)
+++
incubator/stanbol/trunk/ontologymanager/registry/src/test/java/org/apache/stanbol/ontologymanager/registry/TestRegistryManager.java
Thu Jul 28 16:27:13 2011
@@ -46,10 +46,15 @@ public class TestRegistryManager {
private static Dictionary<String,Object> configuration;
/*
- * This can very well stay the same across
+ * This can very well stay the same across tests.
*/
private static OfflineConfiguration offline;
+ /**
+ * Resets all configurations (the offline and registry manager ones).
+ *
+ * @throws Exception
+ */
@BeforeClass
public static void setup() throws Exception {
configuration = new Hashtable<String,Object>();
@@ -132,6 +137,12 @@ public class TestRegistryManager {
}
}
+ /**
+ * Verifies that by setting the loading policy to eager (LAZY_LOADING =
false), any random library will
+ * respond true to a call to {@link Library#isLoaded()} without ever
"touching" its content.
+ *
+ * @throws Exception
+ */
@Test
public void testLoadingEager() throws Exception {
// Change the caching policy and setup a new registry manager.
@@ -158,6 +169,13 @@ public class TestRegistryManager {
assertTrue(lib.isLoaded());
}
+ /**
+ * Verifies that by setting the loading policy to lazy (LAZY_LOADING =
true), any random library will
+ * respond false to a call to {@link Library#isLoaded()}, until its
content is "touched" via a call to
+ * {@link Library#getOntologies()}, only after which will it return true.
+ *
+ * @throws Exception
+ */
@Test
public void testLoadingLazy() throws Exception {
// Change the caching policy and setup a new registry manager.
@@ -169,23 +187,31 @@ public class TestRegistryManager {
// Now pick a library.
Registry reg;
+ Iterator<Registry> it =regman.getRegistries().iterator();
do
- reg = regman.getRegistries().iterator().next();
- while (!reg.hasChildren());
+ reg = it.next();
+ // We need a registry with at least 2 libraries to check that only one
will be loaded.
+ while (it.hasNext() && !reg.hasChildren() || reg.getChildren().length
< 2);
assertNotNull(reg);
- // There has to be at least one non-empty library from the test
registries...
- Library lib = null;
+ // There has to be at least one library with 2 children or more from
the test registries...
+ Library lib1 = null, lib2 = null;
RegistryItem[] children = reg.getChildren();
- for (int i = 0; i < children.length && lib == null; i++)
- if (children[i] instanceof Library) lib = (Library) (children[i]);
- assertNotNull(lib);
+ assertTrue(children.length >= 2);
+ for (int i = 0; i < children.length - 1 && lib1 == null && lib2 ==
null; i++) {
+ if (children[i] instanceof Library) lib1 = (Library) (children[i]);
+ if (children[i + 1] instanceof Library) lib2 = (Library)
(children[i + 1]);
+ }
+ assertFalse(lib1==lib2);
+ assertNotNull(lib1);
// ...but its ontologies must not be loaded yet.
- assertFalse(lib.isLoaded());
+ assertFalse(lib1.isLoaded());
+ assertFalse(lib2.isLoaded());
// Touch the library. Also test that the listener system works.
- assertFalse(lib.getOntologies().isEmpty());
- assertTrue(lib.isLoaded());
+ assertFalse(lib1.getOntologies().isEmpty());
+ assertTrue(lib1.isLoaded());
+ assertFalse(lib2.isLoaded());
}
}