SingularObjectPropertyStrategy extends FieldStrategy<Attribute<? super X, ?>, X> { @Override void buildAxiomValuesFromInstance(X instance, AxiomValueGatherer valueBuilder) { final Object extractedValue = extractFieldValueFromInstance(instance); if (referenceSavingResolver.shouldSaveReference(extractedValue, getAttributeValueContext())) { final Value<NamedResource> val = extractReferenceIdentifier(extractedValue); valueBuilder.addValue(createAssertion(), val, getAttributeContext()); } else { referenceSavingResolver .registerPendingReference(valueBuilder.getSubjectIdentifier(), createAssertion(), extractedValue, getAttributeContext()); valueBuilder.addValue(createAssertion(), Value.nullValue(), getAttributeContext()); } } SingularObjectPropertyStrategy(EntityType<X> et, Attribute<? super X, ?> att,
                                   Descriptor descriptor, EntityMappingHelper mapper);   }
@Test void buildsAxiomFromPlainIdentifierValue() throws Exception { final OWLClassP p = new OWLClassP(); p.setUri(IDENTIFIER); p.setIndividualUri(VALUE); final FieldStrategy<? extends FieldSpecification<? super OWLClassP, ?>, OWLClassP> strategy = strategy(metamodelMocks.forOwlClassP().entityType(), metamodelMocks.forOwlClassP().pUriAttribute()); strategy.setReferenceSavingResolver(referenceResolverMock); when(referenceResolverMock.shouldSaveReference(p.getIndividualUri(), null)).thenReturn(true); strategy.buildAxiomValuesFromInstance(p, gatherer); final AxiomValueDescriptor valueDescriptor = OOMTestUtils.getAxiomValueDescriptor(gatherer); assertEquals(1, valueDescriptor.getAssertions().size()); final List<Value<?>> axioms = valueDescriptor .getAssertionValues(propertyP()); assertEquals(1, axioms.size()); assertEquals(NamedResource.create(VALUE), axioms.get(0).getValue()); }
@Test void buildAxiomValuesChecksWhetherReferenceCanBeSaved() throws Exception { final OWLClassD d = new OWLClassD(); d.setUri(IDENTIFIER); d.setOwlClassA(Generators.generateOwlClassAInstance()); final FieldStrategy<? extends FieldSpecification<? super OWLClassD, ?>, OWLClassD> strategy = strategy(metamodelMocks.forOwlClassD().entityType(), metamodelMocks.forOwlClassD().owlClassAAtt()); when(mapperMock.getEntityType(OWLClassA.class)).thenReturn(metamodelMocks.forOwlClassA().entityType()); strategy.setReferenceSavingResolver(referenceResolverMock); strategy.buildAxiomValuesFromInstance(d, gatherer); verify(referenceResolverMock).shouldSaveReference(d.getOwlClassA(), descriptor.getContext()); }
@Test void buildAxiomValuesFromInstanceChecksForReferenceExistenceUsingTargetReferenceContext() throws Exception { final EntityDescriptor aDescriptor = new EntityDescriptor(Generators.createIndividualIdentifier()); descriptor.addAttributeDescriptor(OWLClassD.getOwlClassAField(), aDescriptor); final FieldStrategy<? extends FieldSpecification<? super OWLClassD, ?>, OWLClassD> sut = strategy(metamodelMocks.forOwlClassD().entityType(), metamodelMocks.forOwlClassD().owlClassAAtt()); sut.setReferenceSavingResolver(referenceResolverMock); final OWLClassD instance = new OWLClassD(Generators.createIndividualIdentifier()); instance.setOwlClassA(Generators.generateOwlClassAInstance()); sut.buildAxiomValuesFromInstance(instance, gatherer); verify(referenceResolverMock).shouldSaveReference(instance.getOwlClassA(), aDescriptor.getContext()); }