SingularMultilingualStringFieldStrategy extends DataPropertyFieldStrategy<AbstractAttribute<? super X, MultilingualString>, X> { @Override void buildAxiomValuesFromInstance(X instance, AxiomValueGatherer valueBuilder) { final MultilingualString attValue = (MultilingualString) extractFieldValueFromInstance(instance); if (attValue == null || attValue.isEmpty()) { valueBuilder.addValue(createAssertion(), Value.nullValue(), getAttributeContext()); } else { valueBuilder.addValues(createAssertion(), translationsToLangStrings(attValue), getAttributeContext()); } } SingularMultilingualStringFieldStrategy(EntityType<X> et, AbstractAttribute<? super X, MultilingualString> att,
                                            Descriptor entityDescriptor, EntityMappingHelper mapper);   }
@Test void buildAxiomValuesFromInstanceAddsAllTranslationsToValueDescriptor() throws Exception { final SingularMultilingualStringFieldStrategy<OWLClassU> sut = createStrategy(); final OWLClassU instance = new OWLClassU(ID); instance.setSingularStringAtt(MultilingualString.create("car", LANG)); instance.getSingularStringAtt().set("cs", "automobil"); final AxiomValueGatherer builder = new AxiomValueGatherer(INDIVIDUAL, null); sut.buildAxiomValuesFromInstance(instance, builder); final AxiomValueDescriptor valueDescriptor = OOMTestUtils.getAxiomValueDescriptor(builder); assertEquals(1, valueDescriptor.getAssertions().size()); final List<Value<?>> values = valueDescriptor.getAssertionValues(Assertion .createDataPropertyAssertion(URI.create(Vocabulary.P_U_SINGULAR_MULTILINGUAL_ATTRIBUTE), false)); assertEquals(instance.getSingularStringAtt().getLanguages().size(), values.size()); for (Map.Entry<String, String> entry : instance.getSingularStringAtt().getValue().entrySet()) { assertTrue(values.contains(new Value<>(new LangString(entry.getValue(), entry.getKey())))); } }
@Test void buildAxiomValuesFromInstanceAddsNullValueWhenAttributeValueIsNull() throws Exception { final SingularMultilingualStringFieldStrategy<OWLClassU> sut = createStrategy(); final OWLClassU instance = new OWLClassU(ID); final AxiomValueGatherer builder = new AxiomValueGatherer(INDIVIDUAL, null); sut.buildAxiomValuesFromInstance(instance, builder); final AxiomValueDescriptor valueDescriptor = OOMTestUtils.getAxiomValueDescriptor(builder); assertEquals(1, valueDescriptor.getAssertions().size()); final List<Value<?>> values = valueDescriptor.getAssertionValues(Assertion .createDataPropertyAssertion(URI.create(Vocabulary.P_U_SINGULAR_MULTILINGUAL_ATTRIBUTE), false)); assertEquals(1, values.size()); assertEquals(Value.nullValue(), values.get(0)); }
@Test void buildAxiomValuesFromInstanceAddsNulLValueWhenAttributeValueIsEmpty() throws Exception { final SingularMultilingualStringFieldStrategy<OWLClassU> sut = createStrategy(); final OWLClassU instance = new OWLClassU(ID); instance.setSingularStringAtt(new MultilingualString()); assertTrue(instance.getSingularStringAtt().isEmpty()); final AxiomValueGatherer builder = new AxiomValueGatherer(INDIVIDUAL, null); sut.buildAxiomValuesFromInstance(instance, builder); final AxiomValueDescriptor valueDescriptor = OOMTestUtils.getAxiomValueDescriptor(builder); assertEquals(1, valueDescriptor.getAssertions().size()); final List<Value<?>> values = valueDescriptor.getAssertionValues(Assertion .createDataPropertyAssertion(URI.create(Vocabulary.P_U_SINGULAR_MULTILINGUAL_ATTRIBUTE), false)); assertEquals(1, values.size()); assertEquals(Value.nullValue(), values.get(0)); }