PropertiesHandler { public Collection<Axiom<?>> getProperties(NamedResource subject, boolean includeInferred) { if (includeInferred) { return getPropertiesIncludingInferred(subject); } else { return getExplicitProperties(subject); } } PropertiesHandler(OwlapiAdapter adapter, OntologySnapshot snapshot); Collection<Axiom<?>> getProperties(NamedResource subject, boolean includeInferred); void addProperties(NamedResource subject, Map<Assertion, Set<Value<?>>> properties); void removeProperties(NamedResource subject, Map<Assertion, Set<Value<?>>> properties);  }
@Test public void getPropertiesLoadsExplicitPropertiesFromOntology() { initSampleProperties(); final Collection<Axiom<?>> axioms = propertiesHandler.getProperties(INDIVIDUAL, false); assertFalse(axioms.isEmpty()); verifyAxioms(axioms, Assertion.AssertionType.DATA_PROPERTY, dataValues); verifyAxioms(axioms, Assertion.AssertionType.OBJECT_PROPERTY, objectValues); }
@Test public void getPropertiesReturnsEmptyCollectionsForNonExistingIndividual() { final Collection<Axiom<?>> axioms = propertiesHandler.getProperties(INDIVIDUAL, false); assertNotNull(axioms); assertTrue(axioms.isEmpty()); }
@Test public void getPropertiesWithInferenceGetsInferredProperties() { final OWLNamedIndividual individual = dataFactory.getOWLNamedIndividual(IRI.create(PK)); manager.applyChange(new AddAxiom(ontology, dataFactory.getOWLDeclarationAxiom(dataFactory.getOWLDataProperty(IRI.create(DP_ONE))))); manager.applyChange(new AddAxiom(ontology, dataFactory.getOWLDeclarationAxiom(dataFactory.getOWLDataProperty(IRI.create(DP_TWO))))); manager.applyChange(new AddAxiom(ontology, dataFactory.getOWLDeclarationAxiom(dataFactory.getOWLObjectProperty(IRI.create(OP_ONE))))); when(reasonerMock.getDataPropertyValues(eq(individual), any(OWLDataProperty.class))) .thenReturn(Collections.emptySet()); when(reasonerMock.getObjectPropertyValues(eq(individual), any(OWLObjectProperty.class))).thenReturn(new OWLNamedIndividualNodeSet()); final Collection<Axiom<?>> axioms = propertiesHandler.getProperties(INDIVIDUAL, true); assertNotNull(axioms); verify(reasonerMock, atLeastOnce()).getDataPropertyValues(eq(individual), any(OWLDataProperty.class)); verify(reasonerMock, atLeastOnce()).getObjectPropertyValues(eq(individual), any(OWLObjectProperty.class)); }
@Test void loadAxiomsGetsObjectPropertyValuesFromImportedOntologiesAsWell() throws Exception { final IRI importedIri = IRI.create(Generator.generateUri()); final OWLOntology imported = manager.createOntology(importedIri); manager.applyChange(new AddImport(ontology, dataFactory.getOWLImportsDeclaration(importedIri))); final URI property = Generator.generateUri(); final OWLNamedIndividual object = dataFactory.getOWLNamedIndividual(Generator.generateUri().toString()); manager.applyChange(new AddAxiom(imported, dataFactory .getOWLObjectPropertyAssertionAxiom(dataFactory.getOWLObjectProperty(property.toString()), dataFactory.getOWLNamedIndividual(PK.toString()), object))); final Collection<Axiom<?>> result = propertiesHandler.getProperties(INDIVIDUAL, false); assertEquals(1, result.size()); assertEquals(NamedResource.create(object.getIRI().toURI()), result.iterator().next().getValue().getValue()); }