EntityDeconstructor { <T> AxiomValueGatherer mapEntityToAxioms(URI identifier, T entity, EntityType<T> et, Descriptor descriptor) { assert identifier != null; final AxiomValueGatherer valueBuilder = createAxiomValueBuilder(identifier, descriptor); try { for (FieldSpecification<? super T, ?> att : et.getFieldSpecifications()) { addAssertions(entity, et, att, descriptor, valueBuilder); } } catch (IllegalArgumentException | IllegalAccessException e) { throw new EntityDeconstructionException(e); } return valueBuilder; } EntityDeconstructor(ObjectOntologyMapperImpl mapper);   }
@Test void testMapEntityWithDataProperty() throws Exception { final Descriptor aDescriptor = new EntityDescriptor(); final AxiomValueGatherer builder = sut .mapEntityToAxioms(entityA.getUri(), entityA, mocks.forOwlClassA().entityType(), aDescriptor); final AxiomValueDescriptor res = getAxiomValueDescriptor(builder); assertNotNull(res); assertEquals(entityA.getUri(), res.getSubject().getIdentifier()); assertEquals(2, res.getAssertions().size()); assertTrue(containsInstanceClassAssertion(res, OWLClassA.getClassIri())); assertTrue(containsDPAssertion(res, OWLClassA.getStrAttField(), entityA.getStringAttribute())); }
@Test void testMapEntityWithDataPropertyNullValue() throws Exception { final OWLClassA entity = new OWLClassA(); entity.setUri(entityA.getUri()); final Descriptor aDescriptor = new EntityDescriptor(); final AxiomValueGatherer builder = sut.mapEntityToAxioms(entity.getUri(), entity, mocks.forOwlClassA().entityType(), aDescriptor); final AxiomValueDescriptor res = getAxiomValueDescriptor(builder); assertNotNull(res); assertEquals(entity.getUri(), res.getSubject().getIdentifier()); assertEquals(2, res.getAssertions().size()); assertTrue(containsInstanceClassAssertion(res, OWLClassA.getClassIri())); final List<Value<?>> v = res.getAssertionValues(Assertion.createDataPropertyAssertion( strAttAIdentifier, Generators.LANG, false)); assertEquals(1, v.size()); assertEquals(Value.nullValue(), v.get(0)); }
@Test void testMapEntityWithDataPropertyAndTypes() throws Exception { final Descriptor aDescriptor = new EntityDescriptor(); final Set<String> types = createTypes(); entityA.setTypes(types); final AxiomValueGatherer builder = sut.mapEntityToAxioms(entityA.getUri(), entityA, mocks.forOwlClassA().entityType(), aDescriptor); final AxiomValueDescriptor res = getAxiomValueDescriptor(builder); assertNotNull(res); assertEquals(entityA.getUri(), res.getSubject().getIdentifier()); assertEquals(2, res.getAssertions().size()); assertTrue(res.getAssertions().contains(Assertion.createClassAssertion(false))); assertTrue(res.getAssertions().contains( Assertion.createDataPropertyAssertion(strAttAIdentifier, Generators.LANG, false))); res.getAssertions().stream().filter(a -> a.getType() == AssertionType.CLASS).forEach(a -> { final List<Value<?>> cls = res.getAssertionValues(a); assertEquals(1, cls.size()); assertEquals(OWLClassA.getClassIri(), cls.get(0).stringValue()); }); final Set<URI> typesRes = OOMTestUtils.getTypesToAdd(builder); assertEquals(types.size(), typesRes.size()); for (URI u : typesRes) { assertTrue(types.contains(u.toString())); } }
@Test void testMapEntityWithDataPropertyAndTypesPropertyInDifferentContext() throws Exception { final Descriptor aDescriptor = new EntityDescriptor(); aDescriptor.addAttributeContext(OWLClassA.getStrAttField(), CONTEXT); final Set<String> types = createTypes(); entityA.setTypes(types); final AxiomValueGatherer builder = sut.mapEntityToAxioms(entityA.getUri(), entityA, mocks.forOwlClassA().entityType(), aDescriptor); final AxiomValueDescriptor res = getAxiomValueDescriptor(builder); assertNotNull(res); assertEquals(entityA.getUri(), res.getSubject().getIdentifier()); assertNull(res.getSubjectContext()); assertEquals(CONTEXT, res.getAssertionContext(Assertion.createDataPropertyAssertion( strAttAIdentifier, Generators.LANG, false))); assertNull(res.getAssertionContext(Assertion.createClassAssertion(false))); }
@Test void testMapEntityWithObjectProperty() throws Exception { final Descriptor dDescriptor = new EntityDescriptor(); when(oomMock.isManaged(entityD.getOwlClassA())).thenReturn(true); final AxiomValueGatherer builder = sut .mapEntityToAxioms(entityD.getUri(), entityD, mocks.forOwlClassD().entityType(), dDescriptor); final AxiomValueDescriptor res = getAxiomValueDescriptor(builder); assertNotNull(res); assertEquals(entityD.getUri(), res.getSubject().getIdentifier()); assertEquals(2, res.getAssertions().size()); assertTrue(containsInstanceClassAssertion(res, OWLClassD.getClassIri())); assertTrue( containsOPAssertion(res, OWLClassD.getOwlClassAField(), NamedResource.create(entityA.getUri()))); }
@Test void testMapEntityWithObjectPropertyNullValue() throws Exception { final OWLClassD entity = new OWLClassD(); entity.setUri(entityD.getUri()); final Descriptor dDescriptor = new EntityDescriptor(); final AxiomValueGatherer builder = sut.mapEntityToAxioms(entity.getUri(), entity, mocks.forOwlClassD().entityType(), dDescriptor); final AxiomValueDescriptor res = getAxiomValueDescriptor(builder); assertNotNull(res); assertEquals(entity.getUri(), res.getSubject().getIdentifier()); assertEquals(2, res.getAssertions().size()); assertTrue(res.getAssertions().contains(Assertion.createClassAssertion(false))); final List<Value<?>> v = res.getAssertionValues(Assertion.createObjectPropertyAssertion( owlClassAAttIdentifier, false)); assertEquals(1, v.size()); assertEquals(Value.nullValue(), v.get(0)); }
@Test void testMapEntityWithObjectPropertyAndContext() throws Exception { final Descriptor dDescriptor = new EntityDescriptor(CONTEXT); final AxiomValueGatherer builder = sut.mapEntityToAxioms(entityD.getUri(), entityD, mocks.forOwlClassD().entityType(), dDescriptor); final AxiomValueDescriptor res = getAxiomValueDescriptor(builder); assertNotNull(res); assertEquals(entityD.getUri(), res.getSubject().getIdentifier()); assertEquals(CONTEXT, res.getSubjectContext()); for (Assertion ass : res.getAssertions()) { assertEquals(CONTEXT, res.getAssertionContext(ass)); } }
@Test void testMapEntityWithProperties() throws Exception { final Descriptor bDescriptor = new EntityDescriptor(); final Map<String, Set<String>> props = Generators.generateStringProperties(); entityB.setProperties(props); final AxiomValueGatherer builder = sut.mapEntityToAxioms(entityB.getUri(), entityB, mocks.forOwlClassB().entityType(), bDescriptor); final AxiomValueDescriptor res = getAxiomValueDescriptor(builder); assertEquals(entityB.getUri(), res.getSubject().getIdentifier()); assertEquals(2, res.getAssertions().size()); verifyPropertiesForSave(props, builder); }
@Test void testMapEntityWithNullProperties() throws Exception { final Descriptor bDescriptor = new EntityDescriptor(); final AxiomValueGatherer builder = sut.mapEntityToAxioms(entityB.getUri(), entityB, mocks.forOwlClassB().entityType(), bDescriptor); final AxiomValueDescriptor res = getAxiomValueDescriptor(builder); assertEquals(entityB.getUri(), res.getSubject().getIdentifier()); assertEquals(2, res.getAssertions().size()); }
@Test void testMapEntityWithPropertiesMultipleValuesPerProperty() throws Exception { final Map<String, Set<String>> props = createProperties(); entityB.setProperties(props); final Descriptor bDescriptor = new EntityDescriptor(); final AxiomValueGatherer builder = sut.mapEntityToAxioms(entityB.getUri(), entityB, mocks.forOwlClassB().entityType(), bDescriptor); final AxiomValueDescriptor res = getAxiomValueDescriptor(builder); assertEquals(entityB.getUri(), res.getSubject().getIdentifier()); assertEquals(2, res.getAssertions().size()); verifyPropertiesForSave(props, builder); }
@Test void mapsEntityWithStringKeyAndBasicDataAttributes() throws Exception { final Descriptor desc = new EntityDescriptor(); final AxiomValueGatherer builder = sut .mapEntityToAxioms(URI.create(entityM.getKey()), entityM, mocks.forOwlClassM().entityType(), desc); final AxiomValueDescriptor res = getAxiomValueDescriptor(builder); assertTrue(containsInstanceClassAssertion(res, OWLClassM.getClassIri())); assertTrue(containsDPAssertion(res, OWLClassM.getBooleanAttributeField(), entityM.getBooleanAttribute())); assertTrue(containsDPAssertion(res, OWLClassM.getIntAttributeField(), entityM.getIntAttribute())); assertTrue(containsDPAssertion(res, OWLClassM.getDoubleAttributeField(), entityM.getDoubleAttribute())); assertTrue(containsDPAssertion(res, OWLClassM.getLongAttributeField(), entityM.getLongAttribute())); assertTrue(containsDPAssertion(res, OWLClassM.getDateAttributeField(), entityM.getDateAttribute())); }
@Test void mapEntityToAxiomsIncludesAttributesInheritedFromMappedSuperclass() throws Exception { final Descriptor desc = new EntityDescriptor(); final OWLClassQ q = initQ(); final AxiomValueGatherer builder = sut .mapEntityToAxioms(q.getUri(), q, mocks.forOwlClassQ().entityType(), desc); final AxiomValueDescriptor valueDescriptor = getAxiomValueDescriptor(builder); assertTrue(containsInstanceClassAssertion(valueDescriptor, OWLClassQ.getClassIri())); assertTrue(containsDPAssertion(valueDescriptor, OWLClassQ.getStringAttributeField(), q.getStringAttribute() )); assertTrue(containsDPAssertion(valueDescriptor, OWLClassQ.getParentStringField(), q.getParentString())); assertTrue(containsAPAssertion(valueDescriptor, OWLClassQ.getLabelField(), q.getLabel())); assertTrue(containsOPAssertion(valueDescriptor, OWLClassQ.getOwlClassAField(), NamedResource.create(entityA.getUri()))); }
@Test void mapEntityToAxiomsSupportsPluralAnnotationProperty() throws Exception { final Descriptor descriptor = new EntityDescriptor(); final OWLClassN n = new OWLClassN(); n.setId(Generators.createIndividualIdentifier().toString()); n.setPluralAnnotation( IntStream.range(0, 5).mapToObj(i -> Generators.createIndividualIdentifier().toString()).collect( Collectors.toSet())); final AxiomValueGatherer builder = sut .mapEntityToAxioms(URI.create(n.getId()), n, mocks.forOwlClassN().entityType(), descriptor); final AxiomValueDescriptor valueDescriptor = getAxiomValueDescriptor(builder); final Assertion assertion = Assertion.createAnnotationPropertyAssertion(URI.create(Vocabulary.DC_SOURCE), Generators.LANG, false); assertTrue(valueDescriptor.getAssertions().contains(assertion)); assertAll(() -> assertEquals(n.getPluralAnnotation().size(), valueDescriptor.getAssertionValues(assertion).size()), () -> { final List<Value<String>> values = n.getPluralAnnotation().stream().map(Value::new).collect(Collectors.toList()); assertTrue(valueDescriptor.getAssertionValues(assertion).containsAll(values)); }); }