TypesFieldStrategy extends FieldStrategy<TypesSpecification<? super X, ?>, X> { @Override void buildInstanceFieldValue(Object instance) { assert attribute.getJavaField().getType().isAssignableFrom(Set.class); if (values.isEmpty()) { return; } setValueOnInstance(instance, values); } TypesFieldStrategy(EntityType<X> et, TypesSpecification<? super X, ?> att, Descriptor descriptor,
                       EntityMappingHelper mapper);   }
@Test public void buildsStringBasedTypesFieldValueFromAxioms() throws Exception { final TypesFieldStrategy<OWLClassA> strategy = strategy(mocks.forOwlClassA().entityType(), mocks.forOwlClassA().typesSpec()); final List<Axiom<URI>> axioms = generateClassAssertionAxioms(OWLClassA.getClassIri()); axioms.forEach(strategy::addValueFromAxiom); final OWLClassA a = new OWLClassA(); strategy.buildInstanceFieldValue(a); final URI classUri = URI.create(OWLClassA.getClassIri()); assertEquals(axioms.size() - 1, a.getTypes().size()); axioms.stream().filter(ax -> !ax.getValue().getValue().equals(classUri)) .forEach(ax -> assertTrue(a.getTypes().contains(ax.getValue().stringValue()))); }
@Test public void buildsUriBasedTypesFieldValueFromAxioms() throws Exception { final TypesFieldStrategy<OWLClassP> strategy = strategy(mocks.forOwlClassP().entityType(), mocks.forOwlClassP().types()); final List<Axiom<URI>> axioms = generateClassAssertionAxioms(OWLClassP.getClassIri()); axioms.forEach(strategy::addValueFromAxiom); final OWLClassP p = new OWLClassP(); strategy.buildInstanceFieldValue(p); final URI classUri = URI.create(OWLClassP.getClassIri()); assertEquals(axioms.size() - 1, p.getTypes().size()); axioms.stream().filter(ax -> !ax.getValue().getValue().equals(classUri)) .forEach(ax -> assertTrue(p.getTypes().contains(ax.getValue().getValue()))); }
@Test public void buildInstanceFieldLeavesFieldNullWhenNoAxiomsAreLoaded() throws Exception { final TypesFieldStrategy<OWLClassP> strategy = strategy(mocks.forOwlClassP().entityType(), mocks.forOwlClassP().types()); final List<Axiom<URI>> axioms = Collections.singletonList( new AxiomImpl<>(NamedResource.create(PK), Assertion.createClassAssertion(false), new Value<>(URI.create(OWLClassP.getClassIri())))); axioms.forEach(strategy::addValueFromAxiom); final OWLClassP p = new OWLClassP(); assertNull(p.getTypes()); strategy.buildInstanceFieldValue(p); assertNull(p.getTypes()); }