SimpleSetPropertyStrategy extends PluralObjectPropertyStrategy<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; extractValues(valueCollection, valueBuilder); } SimpleSetPropertyStrategy(EntityType<X> et, AbstractPluralAttribute<? super X, ?, ?> att, Descriptor descriptor,
                              EntityMappingHelper mapper);   }
@Test void extractsValuesFromInstance() throws Exception { final SimpleSetPropertyStrategy<OWLClassJ> strategy = strategy(mocks.forOwlClassJ().entityType(), mocks.forOwlClassJ().setAttribute()); strategy.setReferenceSavingResolver(referenceResolverMock); final OWLClassJ j = new OWLClassJ(PK); j.setOwlClassA(generateSet(true)); when(referenceResolverMock.shouldSaveReferenceToItem(any(), eq(null))).thenReturn(true); strategy.buildAxiomValuesFromInstance(j, gatherer); final Set<URI> expected = j.getOwlClassA().stream().map(OWLClassA::getUri).collect(Collectors.toSet()); verifyExtractedValues(expected); }
@Test void extractValuesSkipsNullItem() throws Exception { final SimpleSetPropertyStrategy<OWLClassJ> strategy = strategy(mocks.forOwlClassJ().entityType(), mocks.forOwlClassJ().setAttribute()); strategy.setReferenceSavingResolver(referenceResolverMock); final OWLClassJ j = new OWLClassJ(PK); j.setOwlClassA(generateSet(true)); j.getOwlClassA().add(null); when(referenceResolverMock.shouldSaveReferenceToItem(any(), eq(null))).thenReturn(true); strategy.buildAxiomValuesFromInstance(j, gatherer); final Set<URI> expected = j.getOwlClassA().stream().filter(Objects::nonNull).map(OWLClassA::getUri) .collect(Collectors.toSet()); verifyExtractedValues(expected); }
@Test void extractValuesFromInstanceWhenSetIsNullCreatesNullValueAxiom() throws Exception { final SimpleSetPropertyStrategy<OWLClassJ> strategy = strategy(mocks.forOwlClassJ().entityType(), mocks.forOwlClassJ().setAttribute()); strategy.setReferenceSavingResolver(referenceResolverMock); final OWLClassJ j = new OWLClassJ(PK); j.setOwlClassA(null); final AxiomValueGatherer builder = new AxiomValueGatherer(NamedResource.create(PK), null); strategy.buildAxiomValuesFromInstance(j, builder); final AxiomValueDescriptor res = OOMTestUtils.getAxiomValueDescriptor(builder); assertEquals(NamedResource.create(PK), res.getSubject()); final OWLObjectProperty op = OWLClassJ.getOwlClassAField().getAnnotation( OWLObjectProperty.class); final Assertion ass = Assertion.createObjectPropertyAssertion(URI.create(op.iri()), OWLClassJ.getOwlClassAField().getAnnotation(Inferred.class) != null); assertEquals(1, res.getAssertionValues(ass).size()); assertSame(Value.nullValue(), res.getAssertionValues(ass).get(0)); }
@Test void extractsValuesFromFieldWithSetOfPlainIdentifiers() throws Exception { final SimpleSetPropertyStrategy<OWLClassP> strategy = strategy(mocks.forOwlClassP().entityType(), mocks.forOwlClassP().pUrlsAttribute()); final OWLClassP p = new OWLClassP(); strategy.setReferenceSavingResolver(referenceResolverMock); p.setUri(PK); setIndividualUrls(p); strategy.buildAxiomValuesFromInstance(p, gatherer); verifyExtractedValuesForP(p.getIndividualUrls()); }
@Test void extractValuesSkipsNullPlainIdentifiers() throws Exception { final SimpleSetPropertyStrategy<OWLClassP> strategy = strategy(mocks.forOwlClassP().entityType(), mocks.forOwlClassP().pUrlsAttribute()); final OWLClassP p = new OWLClassP(); strategy.setReferenceSavingResolver(referenceResolverMock); p.setUri(PK); setIndividualUrls(p); p.getIndividualUrls().add(null); strategy.buildAxiomValuesFromInstance(p, gatherer); final Set<URL> expected = p.getIndividualUrls().stream().filter(Objects::nonNull).collect(Collectors.toSet()); verifyExtractedValuesForP(expected); }
@Test void extractValuesRegistersPendingChangesForInstancesWithNullIdentifier() { final SimpleSetPropertyStrategy<OWLClassJ> strategy = strategy(mocks.forOwlClassJ().entityType(), mocks.forOwlClassJ().setAttribute()); strategy.setReferenceSavingResolver(referenceResolverMock); final OWLClassJ j = new OWLClassJ(PK); j.setOwlClassA(generateSet(false)); strategy.buildAxiomValuesFromInstance(j, gatherer); final NamedResource subject = NamedResource.create(PK); j.getOwlClassA().forEach(a -> verify( referenceResolverMock).registerPendingReference(subject, strategy.createAssertion(), a, null)); }