PluralAnnotationPropertyStrategy extends PluralDataPropertyStrategy<X> { @Override void addValueFromAxiom(Axiom<?> ax) { final Object value = ax.getValue().getValue(); if (isValidRange(value)) { values.add(toAttributeValue(value)); } else if (value instanceof NamedResource && IdentifierTransformer.isValidIdentifierType(elementType)) { values.add(IdentifierTransformer .transformToIdentifier(ToLexicalFormConverter.INSTANCE.convertToAttribute(value), elementType)); } } PluralAnnotationPropertyStrategy(EntityType<X> et, AbstractPluralAttribute<? super X, ?, ?> att,
                                     Descriptor attributeDescriptor, EntityMappingHelper mapper);   }
@Test void addValueFromAxiomAddsStringValueToValues() { final PluralAnnotationPropertyStrategy<OWLClassN> sut = strategyForN(); final String value = "test"; final Axiom<String> axiom = new AxiomImpl<>(INDIVIDUAL, createAnnotationAssertionForN(), new Value<>(value)); sut.addValueFromAxiom(axiom); final OWLClassN instance = new OWLClassN(); sut.buildInstanceFieldValue(instance); assertEquals(Collections.singleton(value), instance.getPluralAnnotation()); }
@Test void addValueFromAxiomAddsNamedResourceToValues() { final PluralAnnotationPropertyStrategy<OWLClassN> sut = strategyForN(); final NamedResource value = NamedResource.create(Generators.createIndividualIdentifier()); final Axiom<NamedResource> axiom = new AxiomImpl<>(INDIVIDUAL, createAnnotationAssertionForN(), new Value<>(value)); sut.addValueFromAxiom(axiom); final OWLClassN instance = new OWLClassN(); sut.buildInstanceFieldValue(instance); assertEquals(Collections.singleton(value.getIdentifier().toString()), instance.getPluralAnnotation()); }
@Test void addValueFromAxiomAddsStringToUriValues() throws Exception { final PluralAnnotationPropertyStrategy<WithPluralUriAnnotations> sut = createStrategyWithPluralAnnotations( WithPluralUriAnnotations.class, URI.class, null); final NamedResource value = NamedResource.create(Generators.createIndividualIdentifier()); final Axiom<NamedResource> axiom = new AxiomImpl<>(INDIVIDUAL, createAnnotationAssertionForN(), new Value<>(value)); sut.addValueFromAxiom(axiom); final WithPluralUriAnnotations instance = new WithPluralUriAnnotations(); sut.buildInstanceFieldValue(instance); assertEquals(Collections.singleton(value.getIdentifier()), instance.sources); }
@Test void addValueFromAxiomTransformsValueToLexicalForm() throws Exception { final PluralAnnotationPropertyStrategy<WithPluralStringAnnotations> sut = createStrategyWithPluralAnnotations( WithPluralStringAnnotations.class, String.class, new ToLexicalFormConverter()); final Integer value = 117; final Axiom<Integer> axiom = new AxiomImpl<>(INDIVIDUAL, Assertion.createAnnotationPropertyAssertion(URI.create( DC.Terms.SOURCE), false), new Value<>(value)); sut.addValueFromAxiom(axiom); final WithPluralStringAnnotations instance = new WithPluralStringAnnotations(); sut.buildInstanceFieldValue(instance); assertEquals(Collections.singleton(value.toString()), instance.sources); }
@Test void addValueFromAxiomAcceptsIdentifiersForLexicalFormAttribute() throws Exception { final PluralAnnotationPropertyStrategy<WithPluralStringAnnotations> sut = createStrategyWithPluralAnnotations( WithPluralStringAnnotations.class, String.class, null); when(sut.attribute.getConverter()).thenReturn(new ToLexicalFormConverter()); final URI value = Generators.createIndividualIdentifier(); final Axiom<NamedResource> axiom = new AxiomImpl<>(INDIVIDUAL, Assertion.createAnnotationPropertyAssertion(URI.create( DC.Terms.SOURCE), false), new Value<>(NamedResource.create(value))); sut.addValueFromAxiom(axiom); final WithPluralStringAnnotations instance = new WithPluralStringAnnotations(); sut.buildInstanceFieldValue(instance); assertEquals(Collections.singleton(value.toString()), instance.sources); }
@Test void addAxiomValueConvertsNamedResourceToUriForAttributeOfTypeObject() throws Exception { final EntityType<ClassWithObjectAnnotation> et = mock(EntityType.class); final SetAttributeImpl<ClassWithObjectAnnotation, Object> att = objectAnnotationAttribute(et); final PluralAnnotationPropertyStrategy<ClassWithObjectAnnotation> sut = new PluralAnnotationPropertyStrategy<>( et, att, descriptor, mapperMock); final URI identifier = Generators.createIndividualIdentifier(); final Axiom<NamedResource> axiom = new AxiomImpl<>(NamedResource.create(PK), createAnnotationAssertionForN(), new Value<>(NamedResource.create(identifier))); sut.addValueFromAxiom(axiom); final ClassWithObjectAnnotation instance = new ClassWithObjectAnnotation(); sut.buildInstanceFieldValue(instance); assertEquals(Collections.singleton(identifier), instance.pluralAnnotation); }