Search in sources :

Example 1 with RegistryManagerImpl

use of org.apache.stanbol.ontologymanager.registry.impl.RegistryManagerImpl in project stanbol by apache.

the class TestOntologyRegistry method setup.

/**
     * 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, new ClerezzaOntologyProvider(new SimpleTcProvider(), offline, Parser.getInstance()), config);
}
Also used : Hashtable(java.util.Hashtable) SimpleTcProvider(org.apache.clerezza.rdf.simple.storage.SimpleTcProvider) RegistryManagerImpl(org.apache.stanbol.ontologymanager.registry.impl.RegistryManagerImpl) OfflineConfigurationImpl(org.apache.stanbol.ontologymanager.core.OfflineConfigurationImpl) OfflineConfiguration(org.apache.stanbol.ontologymanager.servicesapi.OfflineConfiguration) ClerezzaOntologyProvider(org.apache.stanbol.ontologymanager.multiplexer.clerezza.ontology.ClerezzaOntologyProvider) BeforeClass(org.junit.BeforeClass)

Example 2 with RegistryManagerImpl

use of org.apache.stanbol.ontologymanager.registry.impl.RegistryManagerImpl in project stanbol by apache.

the class TestRegistryManager method testCachingCentralised.

/**
     * Verifies that by instantiating a new {@link RegistryManager} with a centralised caching policy and
     * loading two registries, they share the same cache ontology manager.
     * 
     * @throws Exception
     */
@Test
public void testCachingCentralised() throws Exception {
    // Change the caching policy and setup a new registry manager.
    configuration.put(RegistryManager.CACHING_POLICY, CachingPolicy.CENTRALISED);
    regman = new RegistryManagerImpl(offline, provider, configuration);
    // Check that the configuration was set.
    assertNotNull(regman);
    assertSame(CachingPolicy.CENTRALISED, regman.getCachingPolicy());
    // All registries must have the same cache.
    Iterator<Library> it = regman.getLibraries().iterator();
    OntologyProvider<?> cache = it.next().getCache();
    while (it.hasNext()) assertSame(cache, it.next().getCache());
    // Now "touch" a library.
    Registry reg;
    do reg = regman.getRegistries().iterator().next(); while (!reg.hasChildren());
    assertNotNull(reg);
    // There has to be at least one non-empty lib from the test ontologies.
    Library lib = 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);
    // Touch the library. Also test that the listener system works.
    assertFalse(lib.getOntologies(OWLOntology.class).isEmpty());
}
Also used : RegistryManagerImpl(org.apache.stanbol.ontologymanager.registry.impl.RegistryManagerImpl) Library(org.apache.stanbol.ontologymanager.registry.api.model.Library) Registry(org.apache.stanbol.ontologymanager.registry.api.model.Registry) RegistryItem(org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem) Test(org.junit.Test)

Example 3 with RegistryManagerImpl

use of org.apache.stanbol.ontologymanager.registry.impl.RegistryManagerImpl in project stanbol by apache.

the class TestRegistryManager method testCachingDistributed.

/**
     * Verifies that by instantiating a new {@link RegistryManager} with a distributed caching policy and
     * loading two registries, they have different ontology managers.
     * 
     * @throws Exception
     */
@Test
public void testCachingDistributed() throws Exception {
    // Change the caching policy and setup a new registry manager.
    configuration.put(RegistryManager.CACHING_POLICY, CachingPolicy.DISTRIBUTED);
    regman = new RegistryManagerImpl(offline, provider, configuration);
    // Check that the configuration was set.
    assertNotNull(regman);
    assertSame(CachingPolicy.DISTRIBUTED, regman.getCachingPolicy());
    // Each registry must have its own distinct cache.
    Iterator<Library> it = regman.getLibraries().iterator();
    OntologyProvider<?> cache = it.next().getCache();
    // Just checking against the first in the list.
    while (it.hasNext()) {
        assertNotSame(cache, it.next().getCache());
    }
}
Also used : RegistryManagerImpl(org.apache.stanbol.ontologymanager.registry.impl.RegistryManagerImpl) Library(org.apache.stanbol.ontologymanager.registry.api.model.Library) Test(org.junit.Test)

Example 4 with RegistryManagerImpl

use of org.apache.stanbol.ontologymanager.registry.impl.RegistryManagerImpl in project stanbol by apache.

the class TestRegistryManager method testLoadingLazy.

/**
     * 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.
    configuration.put(RegistryManager.CACHING_POLICY, CachingPolicy.CENTRALISED);
    configuration.put(RegistryManager.LAZY_LOADING, true);
    regman = new RegistryManagerImpl(offline, provider, configuration);
    // Check that the configuration was set.
    assertNotNull(regman);
    // Now pick a library.
    Registry reg;
    Iterator<Registry> it = regman.getRegistries().iterator();
    do reg = it.next(); while (// We need a registry with at least 2 libraries to check that only one will be loaded.
    it.hasNext() && !reg.hasChildren() || reg.getChildren().length < 2);
    assertNotNull(reg);
    // 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();
    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(lib1.isLoaded());
    assertFalse(lib2.isLoaded());
    // Touch the library. Also test that the listener system works.
    assertFalse(lib1.getOntologies(OWLOntology.class).isEmpty());
    assertTrue(lib1.isLoaded());
    assertFalse(lib2.isLoaded());
}
Also used : RegistryManagerImpl(org.apache.stanbol.ontologymanager.registry.impl.RegistryManagerImpl) Registry(org.apache.stanbol.ontologymanager.registry.api.model.Registry) Library(org.apache.stanbol.ontologymanager.registry.api.model.Library) RegistryItem(org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem) Test(org.junit.Test)

Example 5 with RegistryManagerImpl

use of org.apache.stanbol.ontologymanager.registry.impl.RegistryManagerImpl in project stanbol by apache.

the class TestRegistryManager method testLoadingEager.

/**
     * 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.
    configuration.put(RegistryManager.CACHING_POLICY, CachingPolicy.DISTRIBUTED);
    configuration.put(RegistryManager.LAZY_LOADING, false);
    regman = new RegistryManagerImpl(offline, provider, configuration);
    // Check that the configuration was set.
    assertNotNull(regman);
    // Now pick a library.
    Registry reg;
    do reg = regman.getRegistries().iterator().next(); while (!reg.hasChildren());
    assertNotNull(reg);
    // There has to be at least one non-empty library from the test registries...
    Library lib = 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);
    // ...and its ontologies must already be loaded without having to request them.
    assertTrue(lib.isLoaded());
}
Also used : RegistryManagerImpl(org.apache.stanbol.ontologymanager.registry.impl.RegistryManagerImpl) Registry(org.apache.stanbol.ontologymanager.registry.api.model.Registry) Library(org.apache.stanbol.ontologymanager.registry.api.model.Library) RegistryItem(org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem) Test(org.junit.Test)

Aggregations

RegistryManagerImpl (org.apache.stanbol.ontologymanager.registry.impl.RegistryManagerImpl)7 Test (org.junit.Test)6 Library (org.apache.stanbol.ontologymanager.registry.api.model.Library)5 Registry (org.apache.stanbol.ontologymanager.registry.api.model.Registry)4 RegistryItem (org.apache.stanbol.ontologymanager.registry.api.model.RegistryItem)4 Hashtable (java.util.Hashtable)3 ClerezzaOntologyProvider (org.apache.stanbol.ontologymanager.multiplexer.clerezza.ontology.ClerezzaOntologyProvider)3 IRI (org.semanticweb.owlapi.model.IRI)2 SimpleTcProvider (org.apache.clerezza.rdf.simple.storage.SimpleTcProvider)1 OfflineConfigurationImpl (org.apache.stanbol.ontologymanager.core.OfflineConfigurationImpl)1 LibrarySource (org.apache.stanbol.ontologymanager.registry.io.LibrarySource)1 OfflineConfiguration (org.apache.stanbol.ontologymanager.servicesapi.OfflineConfiguration)1 BeforeClass (org.junit.BeforeClass)1 OWLImportsDeclaration (org.semanticweb.owlapi.model.OWLImportsDeclaration)1 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)1