OntologyModels { public static Optional<IRI> findFirstOntologyIRI(Model model, ValueFactory vf) { Optional<Resource> optionalResource = Models.findFirstSubject(model, vf.createIRI(RDF.TYPE.stringValue()), vf.createIRI(OWL.ONTOLOGY.stringValue())); if (optionalResource.isPresent() && optionalResource.get() instanceof IRI) { return Optional.of((IRI) optionalResource.get()); } return Optional.empty(); }  static Optional<IRI> findFirstOntologyIRI(Model model, ValueFactory vf); static Optional<IRI> findFirstVersionIRI(Model model, IRI ontologyIRI, ValueFactory vf);  }
@Test public void findFirstOntologyIRIOneTest() { Model model = mf.createModel(); model.add(ontologyIRI, type, vf.createIRI(OWL.ONTOLOGY.stringValue())); Optional<IRI> ontologyIRIOpt = OntologyModels.findFirstOntologyIRI(model, vf); assertTrue(ontologyIRIOpt.isPresent()); assertEquals(ontologyIRI, ontologyIRIOpt.get()); }
@Test public void findFirstOntologyIRIMultipleTest() { Model model = mf.createModel(); model.add(ontologyIRI, type, ontologyObj); model.add(vf.createIRI("urn:ontologyIRI2"), type, ontologyObj); model.add(vf.createIRI("urn:ontologyIRI3"), type, ontologyObj); Optional<IRI> ontologyIRIOpt = OntologyModels.findFirstOntologyIRI(model, vf); assertTrue(ontologyIRIOpt.isPresent()); assertTrue(ontologyIRIOpt.get().equals(ontologyIRI) || ontologyIRIOpt.get().equals(vf.createIRI("urn:ontologyIRI2")) || ontologyIRIOpt.get().equals(vf.createIRI("urn:ontologyIRI3"))); }
@Test public void findFirstOntologyIRIEmptyModelTest() { Model model = mf.createModel(); Optional<IRI> ontologyIRIOpt = OntologyModels.findFirstOntologyIRI(model, vf); assertTrue(!ontologyIRIOpt.isPresent()); }