ObjectPropertyFieldResultMapper extends FieldResultMapper { @Override void map(ResultRow resultRow, Object target, UnitOfWork uow) { final Optional<Object> id = getVariableValue(resultRow); id.ifPresent(idValue -> { final Object value = resolveValue(uow, idValue); EntityPropertiesUtils.setFieldValue(getFieldSpecification().getJavaField(), target, value); }); } ObjectPropertyFieldResultMapper(FieldResult fieldResult, FieldSpecification<?, ?> fieldSpec);   ObjectPropertyFieldResultMapper(FieldSpecification<?, ?> fieldSpec);   }
@Test void mapLoadsInstanceByIdentifierFromUnitOfWork() throws Exception { final FieldResultMapper mapper = new ObjectPropertyFieldResultMapper( metamodelMocks.forOwlClassD().owlClassAAtt()); final String fieldName = metamodelMocks.forOwlClassD().owlClassAAtt().getName(); final URI identifier = Generators.createIndividualIdentifier(); when(resultRow.isBound(fieldName)).thenReturn(true); when(resultRow.getObject(fieldName)).thenReturn(identifier); final OWLClassA aInstance = Generators.generateOwlClassAInstance(); aInstance.setUri(identifier); when(uowMock.readObject(eq(OWLClassA.class), eq(identifier), any())).thenReturn(aInstance); final OWLClassD target = new OWLClassD(); mapper.map(resultRow, target, uowMock); assertEquals(aInstance, target.getOwlClassA()); verify(uowMock).readObject(OWLClassA.class, identifier, new EntityDescriptor()); }
@Test void mapUsesValueDirectlyWhenFieldIsPlainIdentifier() throws Exception { final FieldResultMapper mapper = new ObjectPropertyFieldResultMapper( metamodelMocks.forOwlClassP().pUriAttribute()); final String fieldName = metamodelMocks.forOwlClassP().pUriAttribute().getName(); final URI value = Generators.createIndividualIdentifier(); when(resultRow.isBound(fieldName)).thenReturn(true); when(resultRow.getObject(fieldName)).thenReturn(value); final OWLClassP target = new OWLClassP(); mapper.map(resultRow, target, uowMock); assertEquals(value, target.getIndividualUri()); verify(uowMock, never()).readObject(any(), eq(value), any()); }