PluralDataPropertyStrategy extends DataPropertyFieldStrategy<AbstractPluralAttribute<? super X, ?, ?>, X> { @Override void buildAxiomValuesFromInstance(X instance, AxiomValueGatherer valueBuilder) { final Object value = extractFieldValueFromInstance(instance); assert value instanceof Collection || value == null; final Collection<?> valueCollection = (Collection<?>) value; if (valueCollection == null || valueCollection.isEmpty()) { valueBuilder.addValue(createAssertion(), Value.nullValue(), getAttributeContext()); } else { final Set<Value<?>> assertionValues = valueCollection.stream() .filter(Objects::nonNull) .map(v -> new Value<>(toAxiomValue(v))) .collect(Collectors.toSet()); valueBuilder.addValues(createAssertion(), assertionValues, getAttributeContext()); } } PluralDataPropertyStrategy(EntityType<X> et, AbstractPluralAttribute<? super X, ?, ?> att,
                               Descriptor attributeDescriptor, EntityMappingHelper mapper);   }
@Test void buildAxiomValuesFromInstanceAddsAllValuesIntoAxiomValueGatherer() throws Exception { final PluralDataPropertyStrategy<OWLClassM> strategy = createStrategyForM(); final OWLClassM m = new OWLClassM(); m.initializeTestValues(false); strategy.buildAxiomValuesFromInstance(m, gatherer); final AxiomValueDescriptor valueDescriptor = OOMTestUtils.getAxiomValueDescriptor(gatherer); assertEquals(1, valueDescriptor.getAssertions().size()); assertTrue(valueDescriptor.getAssertions().contains(assertionForMIntegerSet())); final List<Value<?>> values = valueDescriptor.getAssertionValues(assertionForMIntegerSet()); assertEquals(m.getIntegerSet().size(), values.size()); values.forEach(v -> assertTrue(m.getIntegerSet().contains((Integer) v.getValue()))); }
@Test void buildAxiomValuesFromInstancesAddsNullValueWhenAttributeValueIsNull() throws Exception { final PluralDataPropertyStrategy<OWLClassM> strategy = createStrategyForM(); final OWLClassM m = new OWLClassM(); strategy.buildAxiomValuesFromInstance(m, gatherer); final AxiomValueDescriptor valueDescriptor = OOMTestUtils.getAxiomValueDescriptor(gatherer); assertEquals(1, valueDescriptor.getAssertions().size()); assertTrue(valueDescriptor.getAssertions().contains(assertionForMIntegerSet())); final List<Value<?>> values = valueDescriptor.getAssertionValues(assertionForMIntegerSet()); assertEquals(1, values.size()); assertTrue(values.contains(Value.nullValue())); }
@Test void buildAxiomValuesFromInstanceAddsNullValueWhenAttributeValueIsEmptyCollection() throws Exception { final PluralDataPropertyStrategy<OWLClassM> strategy = createStrategyForM(); final OWLClassM m = new OWLClassM(); m.setIntegerSet(Collections.emptySet()); strategy.buildAxiomValuesFromInstance(m, gatherer); final AxiomValueDescriptor valueDescriptor = OOMTestUtils.getAxiomValueDescriptor(gatherer); assertEquals(1, valueDescriptor.getAssertions().size()); assertTrue(valueDescriptor.getAssertions().contains(assertionForMIntegerSet())); final List<Value<?>> values = valueDescriptor.getAssertionValues(assertionForMIntegerSet()); assertEquals(1, values.size()); assertTrue(values.contains(Value.nullValue())); }