SingularMultilingualStringFieldStrategy extends DataPropertyFieldStrategy<AbstractAttribute<? super X, MultilingualString>, X> { @Override void addValueFromAxiom(Axiom<?> ax) { if (value == null) { this.value = new MultilingualString(); } final Value<?> axiomValue = ax.getValue(); if (axiomValue.getValue() instanceof LangString) { final LangString lsAxiomValue = (LangString) axiomValue.getValue(); verifyCardinality(lsAxiomValue.getLanguage().orElse(null), ax.getSubject()); value.set(lsAxiomValue.getLanguage().orElse(null), lsAxiomValue.getValue()); } else { value.set(axiomValue.stringValue()); } } SingularMultilingualStringFieldStrategy(EntityType<X> et, AbstractAttribute<? super X, MultilingualString> att,
                                            Descriptor entityDescriptor, EntityMappingHelper mapper);   }
@Test void addValueFromAxiomThrowsCardinalityConstraintViolatedExceptionWhenMultipleValuesOfSameLanguageAreAdded() { final SingularMultilingualStringFieldStrategy<OWLClassU> sut = createStrategy(); final String value = "test"; final Axiom<LangString> axiomOne = new AxiomImpl<>(INDIVIDUAL, Assertion.createDataPropertyAssertion(URI.create( Vocabulary.P_U_SINGULAR_MULTILINGUAL_ATTRIBUTE), false), new Value<>(new LangString(value, LANG))); final Axiom<LangString> axiomTwo = new AxiomImpl<>(INDIVIDUAL, Assertion.createDataPropertyAssertion(URI.create( Vocabulary.P_U_SINGULAR_MULTILINGUAL_ATTRIBUTE), false), new Value<>(new LangString("test two", LANG))); sut.addValueFromAxiom(axiomOne); assertThrows(CardinalityConstraintViolatedException.class, () -> sut.addValueFromAxiom(axiomTwo)); }
@Test void addValueFromAxiomThrowsCardinalityConstraintViolatedExceptionWhenMultipleSimpleLiteralValuesAreAdded() { final SingularMultilingualStringFieldStrategy<OWLClassU> sut = createStrategy(); final Axiom<String> axiomOne = new AxiomImpl<>(INDIVIDUAL, Assertion.createDataPropertyAssertion(URI.create( Vocabulary.P_U_SINGULAR_MULTILINGUAL_ATTRIBUTE), false), new Value<>("test one")); final Axiom<LangString> axiomTwo = new AxiomImpl<>(INDIVIDUAL, Assertion.createDataPropertyAssertion(URI.create( Vocabulary.P_U_SINGULAR_MULTILINGUAL_ATTRIBUTE), false), new Value<>(new LangString("test two"))); sut.addValueFromAxiom(axiomOne); assertThrows(CardinalityConstraintViolatedException.class, () -> sut.addValueFromAxiom(axiomTwo)); }