use of org.apache.stanbol.ontologymanager.registry.impl.RegistryManagerImpl in project stanbol by apache.
the class TestOntologyLibrary method testLibraryLoad.
/**
* 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(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, new ClerezzaOntologyProvider(tcManager, offline, parser), 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());
Registry reg = registries.iterator().next();
assertTrue(reg.hasChildren());
Library lib = null;
// Look for test #Library2
for (RegistryItem item : reg.getChildren()) {
if (Locations.LIBRARY_TEST2.equals(item.getIRI())) {
lib = (Library) item;
break;
}
}
assertNotNull(lib);
// Should be in the library.
boolean hasShould = RegistryUtils.containsOntologyRecursive(lib, Locations.CHAR_DROPPED);
// Should NOT be in the library (belongs to another library in the same registry).
boolean hasShouldNot = RegistryUtils.containsOntologyRecursive(lib, Locations.CHAR_ACTIVE);
assertTrue(hasShould);
assertFalse(hasShouldNot);
}
use of org.apache.stanbol.ontologymanager.registry.impl.RegistryManagerImpl in project stanbol by apache.
the class TestOntologyLibrary method testLibrarySourceCreation.
/**
* Tests the creation of an ontology input source from a single library. Because the test is run offline,
* import statements might be file URIs, so tests should not fail on this.
*
* @throws Exception
*/
@Test
public void testLibrarySourceCreation() throws Exception {
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, new ClerezzaOntologyProvider(tcManager, offline, parser), regmanConf);
assertNotNull(regMgr);
// Now use this registry manager to instantiate an input source.
OntologyInputSource<OWLOntology> src = new LibrarySource(Locations.LIBRARY_TEST1, regMgr, virginOntologyManager);
OWLOntology o = src.getRootOntology();
boolean hasImporting = false, hasImported = false;
for (OWLImportsDeclaration ax : o.getImportsDeclarations()) {
// Since we added a local IRI mapping, import statements might be using file: IRIs instead of
// HTTP, in which case IRI equality would fail. So it is enough here to just check the filename.
String tmpstr = ax.getIRI().toString();
if (!hasImporting && tmpstr.endsWith("characters_all.owl"))
hasImporting = true;
else if (!hasImported && tmpstr.endsWith("maincharacters.owl"))
hasImported = true;
if (hasImporting && hasImported)
break;
}
assertTrue(hasImporting);
assertTrue(hasImported);
}
Aggregations