BasicStorageConnector extends AbstractConnector { @Override public OntologySnapshot getOntologySnapshot() { ensureOpen(); READ.lock(); try { final OWLOntology snapshot = ontologyManager.createOntology(); cloneOntologyContent(snapshot); return new OntologySnapshot(snapshot, ontologyManager, ontologyManager.getOWLDataFactory(), getReasoner(snapshot)); } catch (OWLOntologyCreationException e) { throw new OntologySnapshotException("Unable to create ontology snapshot.", e); } finally { READ.unlock(); } } BasicStorageConnector(DriverConfiguration configuration); @Override URI getOntologyUri(); @Override OntologySnapshot getOntologySnapshot(); @Override R executeRead(Function<OntologySnapshot, R> function); @Override void executeWrite(Consumer<OntologySnapshot> function); @Override void applyChanges(List<OWLOntologyChange> changes); @Override void closeSnapshot(OntologySnapshot snapshot); @Override void close();  }
@Test public void loadsExistingOntology() throws Exception { final URI physicalUri = initOntology(Collections.emptySet(), false); this.connector = new BasicStorageConnector( new DriverConfiguration(initStorageProperties(physicalUri, ONTOLOGY_URI))); assertNotNull(connector); assertTrue(connector.isOpen()); final OntologySnapshot snapshot = connector.getOntologySnapshot(); assertNotNull(snapshot.getOntology()); assertNotNull(snapshot.getOntologyManager()); assertNotNull(snapshot.getDataFactory()); }
@Test public void getSnapshotReturnsDistinctSnapshots() throws Exception { final URI physicalUri = initOntology(Collections.emptySet(), false); this.connector = new BasicStorageConnector( new DriverConfiguration(initStorageProperties(physicalUri, ONTOLOGY_URI))); final OntologySnapshot snapshotOne = connector.getOntologySnapshot(); final OntologySnapshot snapshotTwo = connector.getOntologySnapshot(); assertNotSame(snapshotOne.getOntology(), snapshotTwo.getOntology()); }
@Test public void applyChangesModifiesTheCentralOntology() throws Exception { final URI physicalUri = initOntology(Collections.emptySet(), false); this.connector = new BasicStorageConnector( new DriverConfiguration(initStorageProperties(physicalUri, ONTOLOGY_URI))); final OntologySnapshot snapshot = connector.getOntologySnapshot(); final OWLClass cls = addClassToOntology(snapshot); final OntologySnapshot result = connector.getOntologySnapshot(); assertTrue(result.getOntology().containsClassInSignature(cls.getIRI())); }
@Test public void getSnapshotCreatesNewAnonymousTransactionalOntology() throws Exception { final URI physicalUri = initOntology(Collections.emptySet(), false); final OntologyStorageProperties storageProperties = initStorageProperties(physicalUri, ONTOLOGY_URI); this.connector = new BasicStorageConnector(new DriverConfiguration(storageProperties)); final OntologySnapshot snapshot = connector.getOntologySnapshot(); assertTrue(snapshot.getOntology().getOntologyID().isAnonymous()); }
@Test public void getSnapshotCopiesAxiomsIntoTheTransactionOntology() throws Exception { final Set<OWLAxiom> axioms = Generator.generateAxioms(); final URI physicalUri = initOntology(axioms, false); final OntologyStorageProperties storageProperties = initStorageProperties(physicalUri, ONTOLOGY_URI); this.connector = new BasicStorageConnector(new DriverConfiguration(storageProperties)); final OntologySnapshot snapshot = connector.getOntologySnapshot(); final Set<OWLAxiom> transactionalAxioms = snapshot.getOntology().axioms().collect(Collectors.toSet()); assertTrue(transactionalAxioms.containsAll(axioms)); }
@Test public void getSnapshotResolvesImportsOfTheTransactionalSnapshot() throws Exception { final URI physicalUri = initOntology(Collections.emptySet(), false); final String importedOntoLocation = "https: final IRI importedOntoIri = IRI.create("http: final OWLImportsDeclaration importDecl = manager.getOWLDataFactory() .getOWLImportsDeclaration(IRI.create(importedOntoLocation)); manager.applyChange(new AddImport(ontology, importDecl)); manager.saveOntology(ontology, IRI.create(physicalUri)); final OntologyStorageProperties storageProperties = initStorageProperties(physicalUri, ONTOLOGY_URI); this.connector = new BasicStorageConnector(new DriverConfiguration(storageProperties)); final OntologySnapshot snapshot = connector.getOntologySnapshot(); final Stream<OWLOntology> imports = snapshot.getOntology().imports(); final Optional<OWLOntology> imported = imports.filter(imp -> imp.getOntologyID().getOntologyIRI().orElse(IRI.create("")) .equals(importedOntoIri)).findAny(); assertTrue(imported.isPresent()); }
@Test public void loadsExistingAnonymousOntology() throws Exception { final URI physicalUri = initOntology(Collections.emptySet(), true); this.connector = new BasicStorageConnector(new DriverConfiguration(initStorageProperties(physicalUri, null))); assertNotNull(connector); assertTrue(connector.isOpen()); final OntologySnapshot snapshot = connector.getOntologySnapshot(); assertNotNull(snapshot.getOntology()); assertTrue(snapshot.getOntology().getOntologyID().isAnonymous()); assertNotNull(snapshot.getOntologyManager()); assertNotNull(snapshot.getDataFactory()); }