OntologyModels { public static Optional<IRI> findFirstVersionIRI(Model model, IRI ontologyIRI, ValueFactory vf) { Optional<Value> optionalValue = Models.findFirstObject(model, ontologyIRI, vf.createIRI(OWL.VERSIONIRI.stringValue())); if (optionalValue.isPresent() && optionalValue.get() instanceof IRI) { return Optional.of((IRI) optionalValue.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 findFirstVersionIRIOneTest() { Model model = mf.createModel(); model.add(ontologyIRI, type, ontologyObj); model.add(ontologyIRI, versionType, versionIRI); Optional<IRI> versionIRIOpt = OntologyModels.findFirstVersionIRI(model, ontologyIRI, vf); assertTrue(versionIRIOpt.isPresent()); assertEquals(versionIRI, versionIRIOpt.get()); }
@Test public void findFirstVersionIRIMultipleTest() { Model model = mf.createModel(); model.add(ontologyIRI, type, ontologyObj); model.add(ontologyIRI, versionType, versionIRI); model.add(ontologyIRI, versionType, vf.createIRI("urn:versionIRI2")); model.add(ontologyIRI, versionType, vf.createIRI("urn:versionIRI3")); Optional<IRI> versionIRIOpt = OntologyModels.findFirstVersionIRI(model, ontologyIRI, vf); assertTrue(versionIRIOpt.isPresent()); assertTrue(versionIRIOpt.get().equals(versionIRI) || versionIRIOpt.get().equals(vf.createIRI("urn:versionIRI2")) || versionIRIOpt.get().equals(vf.createIRI("urn:versionIRI3"))); }
@Test public void findFirstVersionIRIEmptyModelTest() { Model model = mf.createModel(); Optional<IRI> versionIRIOpt = OntologyModels.findFirstVersionIRI(model, ontologyIRI, vf); assertTrue(!versionIRIOpt.isPresent()); }
@Test public void findFirstVersionIRIOntologyIRINotInModelTest() { Model model = mf.createModel(); model.add(ontologyIRI, type, ontologyObj); model.add(ontologyIRI, versionType, versionIRI); Optional<IRI> versionIRIOpt = OntologyModels.findFirstVersionIRI(model, vf.createIRI("urn:ontologyIRI2"), vf); assertTrue(!versionIRIOpt.isPresent()); }