AxiomDescriptorFactory { AxiomDescriptor createForEntityLoading(LoadingParameters<?> loadingParams, EntityType<?> et) { final AxiomDescriptor descriptor = new AxiomDescriptor(NamedResource.create(loadingParams.getIdentifier())); descriptor.setSubjectContext(loadingParams.getDescriptor().getContext()); descriptor.addAssertion(Assertion.createClassAssertion(false)); addForTypes(loadingParams, et, descriptor); addForProperties(loadingParams, et, descriptor); for (Attribute<?, ?> att : et.getAttributes()) { if (!shouldLoad(att.getFetchType(), loadingParams.isForceEager())) { continue; } final Assertion a = createAssertion(att, loadingParams.getDescriptor().getAttributeDescriptor(att)); addAssertionToDescriptor(loadingParams.getDescriptor(), att, descriptor, a); } return descriptor; }    }
@Test void testCreateForEntityLoadingWithTypes() { final AxiomDescriptor res = sut .createForEntityLoading(new LoadingParameters<>(OWLClassA.class, PK, descriptor), metamodelMocks.forOwlClassA().entityType()); assertEquals(2, res.getAssertions().size()); assertEquals(NamedResource.create(PK), res.getSubject()); assertNull(res.getSubjectContext()); assertTrue(res.getAssertions() .contains(Assertion.createDataPropertyAssertion(stringAttAUri, Generators.LANG, false))); assertTrue(res.getAssertions().contains(Assertion.createClassAssertion(false))); }
@Test void testCreateForEntityLoadingWithTypesInContext() throws Exception { descriptor.addAttributeContext(OWLClassA.getTypesField(), CONTEXT); final AxiomDescriptor res = sut .createForEntityLoading(new LoadingParameters<>(OWLClassA.class, PK, descriptor), metamodelMocks.forOwlClassA().entityType()); assertEquals(2, res.getAssertions().size()); assertEquals(NamedResource.create(PK), res.getSubject()); assertNull(res.getSubjectContext()); assertTrue(res.getAssertions().contains( Assertion.createDataPropertyAssertion(stringAttAUri, Generators.LANG, false))); assertTrue(res.getAssertions().contains(Assertion.createClassAssertion(false))); assertEquals(CONTEXT, res.getAssertionContext(Assertion.createClassAssertion(false))); }
@Test void testCreateForEntityLoadingWithPropertiesAndContext() { final AxiomDescriptor res = sut .createForEntityLoading(new LoadingParameters<>(OWLClassB.class, PK, descriptorInContext), metamodelMocks.forOwlClassB().entityType()); assertEquals(3, res.getAssertions().size()); assertEquals(NamedResource.create(PK), res.getSubject()); assertEquals(CONTEXT, res.getSubjectContext()); assertTrue(res.getAssertions() .contains(Assertion.createDataPropertyAssertion(stringAttBUri, Generators.LANG, false))); }
@Test void testCreateForEntityLoadingWithObjectPropertyInContext() throws Exception { descriptor.addAttributeContext(OWLClassD.getOwlClassAField(), CONTEXT); final AxiomDescriptor res = sut .createForEntityLoading(new LoadingParameters<>(OWLClassD.class, PK, descriptor), metamodelMocks.forOwlClassD().entityType()); assertEquals(2, res.getAssertions().size()); assertEquals(NamedResource.create(PK), res.getSubject()); assertNull(res.getSubjectContext()); final Optional<Assertion> ass = res.getAssertions().stream() .filter(a -> a.getIdentifier().equals(owlClassAAttUri)).findAny(); assertTrue(ass.isPresent()); assertEquals(CONTEXT, res.getAssertionContext(ass.get())); assertEquals(owlClassAAttUri, ass.get().getIdentifier()); }
@Test void testCreateForEntityLoadingWithAnnotationProperty() { when(metamodelMocks.forOwlClassD().owlClassAAtt().getPersistentAttributeType()).thenReturn( PersistentAttributeType.ANNOTATION); final AxiomDescriptor res = sut .createForEntityLoading(new LoadingParameters<>(OWLClassD.class, PK, descriptor), metamodelMocks.forOwlClassD().entityType()); assertEquals(2, res.getAssertions().size()); assertEquals(NamedResource.create(PK), res.getSubject()); assertNull(res.getSubjectContext()); assertTrue(res.getAssertions().contains( Assertion.createAnnotationPropertyAssertion(owlClassAAttUri, false))); }
@Test void createForEntityLoadingWithLazilyLoadedAttribute() { when(metamodelMocks.forOwlClassA().stringAttribute().getFetchType()).thenReturn(FetchType.LAZY); final AxiomDescriptor res = sut .createForEntityLoading(new LoadingParameters<>(OWLClassA.class, PK, descriptor), metamodelMocks.forOwlClassA().entityType()); assertEquals(1, res.getAssertions().size()); assertEquals(NamedResource.create(PK), res.getSubject()); assertNull(res.getSubjectContext()); assertFalse(res.getAssertions().contains( Assertion.createDataPropertyAssertion(stringAttAUri, false))); assertTrue(res.getAssertions().contains(Assertion.createClassAssertion(false))); }
@Test void createForEntityLoadingIncludesMappedSuperclassAttributes() throws Exception { final Descriptor desc = new EntityDescriptor(); final AxiomDescriptor res = sut.createForEntityLoading(loadingParameters(OWLClassQ.class, desc), metamodelMocks.forOwlClassQ().entityType()); final Set<String> propertyIris = OWLClassQ.getPersistentFields().stream().map(f -> { if (f.getAnnotation(OWLDataProperty.class) != null) { return f.getAnnotation(OWLDataProperty.class).iri(); } else if (f.getAnnotation(OWLObjectProperty.class) != null) { return f.getAnnotation(OWLObjectProperty.class).iri(); } else { return f.getAnnotation(OWLAnnotationProperty.class).iri(); } }).collect(Collectors.toSet()); final Set<Assertion> assertions = res.getAssertions(); assertEquals(OWLClassQ.getPersistentFields().size() + 1, assertions.size()); for (Assertion a : assertions) { if (a.getType() != Assertion.AssertionType.CLASS) { assertTrue(propertyIris.contains(a.getIdentifier().toString())); } } }
@Test void createForEntityLoadingSetsLanguageTagAccordingToDescriptor() { final Descriptor descriptor = new EntityDescriptor(); descriptor.setLanguage("en"); final AxiomDescriptor res = sut.createForEntityLoading(loadingParameters(OWLClassA.class, descriptor), metamodelMocks.forOwlClassA().entityType()); final Set<Assertion> assertions = res.getAssertions(); assertions.stream().filter(a -> a.getType() != Assertion.AssertionType.CLASS && a.getType() != Assertion.AssertionType.OBJECT_PROPERTY).forEach(a -> assertEquals("en", a.getLanguage())); }
@Test void createForEntityLoadingSetsLanguageTagOfSpecificAssertionAccordingToDescriptor() throws Exception { final Descriptor descriptor = new EntityDescriptor(); descriptor.setLanguage("en"); descriptor.setAttributeLanguage(OWLClassA.getStrAttField(), "cs"); final AxiomDescriptor res = sut.createForEntityLoading(loadingParameters(OWLClassA.class, descriptor), metamodelMocks.forOwlClassA().entityType()); final Set<Assertion> assertions = res.getAssertions(); final Optional<Assertion> strAssertion = assertions.stream().filter(a -> a.getIdentifier().equals(URI .create(Vocabulary.p_a_stringAttribute))).findAny(); assertTrue(strAssertion.isPresent()); assertEquals("cs", strAssertion.get().getLanguage()); }
@Test void createForEntityLoadingSetsLanguageTagAccordingToGlobalPUSpecification() { this.sut = new AxiomDescriptorFactory(); final AxiomDescriptor res = sut.createForEntityLoading(loadingParameters(OWLClassA.class, descriptor), metamodelMocks.forOwlClassA().entityType()); final Set<Assertion> assertions = res.getAssertions(); assertions.stream().filter(a -> a.getType() != Assertion.AssertionType.CLASS && a.getType() != Assertion.AssertionType.OBJECT_PROPERTY).forEach(a -> assertEquals(Generators.LANG, a.getLanguage())); }
@Test void createForEntityLoadingAllowsOverridingPULevelLanguageSetting() { descriptor.setLanguage(null); final AxiomDescriptor res = sut.createForEntityLoading(loadingParameters(OWLClassA.class, descriptor), metamodelMocks.forOwlClassA().entityType()); final Set<Assertion> assertions = res.getAssertions(); assertions.stream().filter(a -> a.getType() != Assertion.AssertionType.CLASS && a.getType() != Assertion.AssertionType.OBJECT_PROPERTY).forEach(a -> { assertFalse(a.hasLanguage()); assertNull(a.getLanguage()); }); }
@Test void createForEntityLoadingUsesSubjectContextForAssertionWhenAssertionsInSubjectContextIsConfiguredInDescriptor() throws Exception { descriptor.addAttributeDescriptor(OWLClassD.getOwlClassAField(), descriptorInContext); final LoadingParameters<OWLClassD> params = new LoadingParameters<>(OWLClassD.class, PK, descriptor); final AxiomDescriptor desc = sut.createForEntityLoading(params, metamodelMocks.forOwlClassD().entityType()); assertEquals(descriptor.getContext(), desc.getAssertionContext( Assertion.createObjectPropertyAssertion(URI.create(Vocabulary.P_HAS_A), false))); }
@Test void createForEntityLoadingAddsAssertionWithoutLanguageTagForSimpleLiteralAttribute() { final LoadingParameters<OWLClassM> params = new LoadingParameters<>(OWLClassM.class, PK, descriptor); final AxiomDescriptor desc = sut .createForEntityLoading(params, metamodelMocks.forOwlClassM().entityType()); final Optional<Assertion> result = desc.getAssertions().stream().filter(a -> a.getIdentifier().equals(URI .create(Vocabulary.p_m_simpleLiteral))).findAny(); assertTrue(result.isPresent()); assertFalse(result.get().hasLanguage()); }
@Test void createForLoadingSetsDefaultContextForAssertionInDefaultWhenSubjectContextIsDifferent() throws Exception { descriptorInContext.addAttributeContext(OWLClassA.getStrAttField(), null); final LoadingParameters<OWLClassA> params = new LoadingParameters<>(OWLClassA.class, PK, descriptorInContext); final AxiomDescriptor desc = sut .createForEntityLoading(params, metamodelMocks.forOwlClassA().entityType()); assertEquals(CONTEXT, desc.getSubjectContext()); final URI result = desc.getAssertionContext( Assertion.createDataPropertyAssertion(URI.create(Vocabulary.p_a_stringAttribute), Generators.LANG, false)); assertNull(result); }
@Test void createForEntityLoadingAddsAssertionsWithoutLanguageTagForMultilingualAttributes() { final LoadingParameters<OWLClassU> params = new LoadingParameters<>(OWLClassU.class, PK, descriptor); final AxiomDescriptor desc = sut.createForEntityLoading(params, metamodelMocks.forOwlClassU().entityType()); final Optional<Assertion> singularAssertion = desc.getAssertions().stream() .filter(a -> a.getIdentifier().toString() .equals(Vocabulary.P_U_SINGULAR_MULTILINGUAL_ATTRIBUTE)) .findAny(); assertTrue(singularAssertion.isPresent()); assertFalse(singularAssertion.get().hasLanguage()); final Optional<Assertion> pluralAssertion = desc.getAssertions().stream() .filter(a -> a.getIdentifier().toString() .equals(Vocabulary.P_U_PLURAL_MULTILINGUAL_ATTRIBUTE)) .findAny(); assertTrue(pluralAssertion.isPresent()); assertFalse(pluralAssertion.get().hasLanguage()); }