AxiomDescriptorFactory { AxiomDescriptor createForFieldLoading(URI identifier, Field field, Descriptor entityDescriptor, EntityType<?> et) { final AxiomDescriptor descriptor = new AxiomDescriptor(NamedResource.create(identifier)); descriptor.setSubjectContext(entityDescriptor.getContext()); FieldSpecification<?, ?> fieldSpec = MappingUtils.getFieldSpecification(field, et); final Assertion assertion; if (et.getTypes() != null && fieldSpec.equals(et.getTypes())) { assertion = Assertion.createClassAssertion(et.getTypes().isInferred()); } else if (et.getProperties() != null && fieldSpec.equals(et.getProperties())) { assertion = Assertion.createUnspecifiedPropertyAssertion(et.getProperties().isInferred()); } else { assertion = createAssertion((Attribute<?, ?>) fieldSpec, entityDescriptor.getAttributeDescriptor(fieldSpec)); } addAssertionToDescriptor(entityDescriptor, fieldSpec, descriptor, assertion); return descriptor; }    }
@Test void testCreateForFieldLoadingDataProperty() throws Exception { final Descriptor desc = new EntityDescriptor(); when(metamodelMocks.forOwlClassA().stringAttribute().getFetchType()).thenReturn(FetchType.LAZY); final AxiomDescriptor res = sut.createForFieldLoading(PK, OWLClassA.getStrAttField(), desc, metamodelMocks.forOwlClassA().entityType()); assertNotNull(res); assertEquals(1, res.getAssertions().size()); assertTrue(res.getAssertions().contains( Assertion.createDataPropertyAssertion(stringAttAUri, Generators.LANG, false))); }
@Test void testCreateForFieldLoadingObjectPropertyInEntityContext() throws Exception { final Descriptor desc = new EntityDescriptor(false); desc.addAttributeDescriptor(OWLClassD.getOwlClassAField(), new EntityDescriptor(CONTEXT)); final AxiomDescriptor res = sut.createForFieldLoading(PK, OWLClassD.getOwlClassAField(), desc, metamodelMocks.forOwlClassD().entityType()); assertEquals(1, res.getAssertions().size()); final Assertion as = res.getAssertions().iterator().next(); assertEquals(Assertion.createObjectPropertyAssertion(owlClassAAttUri, false), as); assertEquals(CONTEXT, res.getAssertionContext(as)); }
@Test void testCreateForFieldLoadingTypes() throws Exception { final Descriptor desc = new EntityDescriptor(CONTEXT); final AxiomDescriptor res = sut.createForFieldLoading(PK, OWLClassA.getTypesField(), desc, metamodelMocks.forOwlClassA().entityType()); assertEquals(1, res.getAssertions().size()); final Assertion as = res.getAssertions().iterator().next(); assertEquals(Assertion.createClassAssertion(metamodelMocks.forOwlClassA().typesSpec().isInferred()), as); assertEquals(CONTEXT, res.getAssertionContext(as)); }
@Test void testCreateForFieldLoadingProperties() throws Exception { final Descriptor desc = new EntityDescriptor(); final AxiomDescriptor res = sut.createForFieldLoading(PK, OWLClassB.getPropertiesField(), desc, metamodelMocks.forOwlClassB().entityType()); assertEquals(1, res.getAssertions().size()); final Assertion as = res.getAssertions().iterator().next(); assertEquals(Assertion .createUnspecifiedPropertyAssertion(metamodelMocks.forOwlClassB().propertiesSpec().isInferred()), as); }
@Test void createForFieldLoadingSetsLanguageTagBasedOnDescriptorLanguageTag() throws Exception { final Descriptor descriptor = new EntityDescriptor(); descriptor.setLanguage("en"); final AxiomDescriptor res = sut.createForFieldLoading(PK, OWLClassA.getStrAttField(), descriptor, metamodelMocks.forOwlClassA().entityType()); final Set<Assertion> assertions = res.getAssertions(); assertEquals(1, assertions.size()); assertEquals("en", assertions.iterator().next().getLanguage()); }
@Test void createForFieldLoadingSetsLanguageTagBasedOnAttributeLanguageTagInDescriptor() throws Exception { final Descriptor descriptor = new EntityDescriptor(); descriptor.setAttributeLanguage(OWLClassA.getStrAttField(), "cs"); final AxiomDescriptor res = sut.createForFieldLoading(PK, OWLClassA.getStrAttField(), descriptor, metamodelMocks.forOwlClassA().entityType()); final Set<Assertion> assertions = res.getAssertions(); assertEquals(1, assertions.size()); assertEquals("cs", assertions.iterator().next().getLanguage()); }
@Test void createForFieldLoadingSetsLanguageOfPUWhenDescriptorLanguageIsNotSpecified() throws Exception { this.sut = new AxiomDescriptorFactory(); final AxiomDescriptor res = sut.createForFieldLoading(PK, OWLClassA.getStrAttField(), descriptor, metamodelMocks.forOwlClassA().entityType()); final Set<Assertion> assertions = res.getAssertions(); assertEquals(1, assertions.size()); assertEquals(Generators.LANG, assertions.iterator().next().getLanguage()); }
@Test void createForFieldLoadingAllowsOverridingPULevelLanguageSetting() throws Exception { final Descriptor descriptor = new EntityDescriptor(); descriptor.setAttributeLanguage(OWLClassA.getStrAttField(), null); final AxiomDescriptor res = sut.createForFieldLoading(PK, OWLClassA.getStrAttField(), descriptor, metamodelMocks.forOwlClassA().entityType()); final Set<Assertion> assertions = res.getAssertions(); assertEquals(1, assertions.size()); assertFalse(assertions.iterator().next().hasLanguage()); assertNull(assertions.iterator().next().getLanguage()); }
@Test void createForLoadingCreatesDataPropertyAssertionWithoutLanguageWhenNoneIsSetForAttributeAndInDescriptor() throws Exception { final Descriptor descriptor = new EntityDescriptor(); when(metamodelMocks.forOwlClassA().stringAttribute().hasLanguage()).thenReturn(false); final AxiomDescriptor res = sut.createForFieldLoading(PK, OWLClassA.getStrAttField(), descriptor, metamodelMocks.forOwlClassA().entityType()); final Set<Assertion> assertions = res.getAssertions(); assertEquals(1, assertions.size()); assertFalse(assertions.iterator().next().hasLanguage()); }
@Test void createForLoadingCreatesAnnotationPropertyAssertionWithoutLanguageWhenNoneIsSetForAttributeAndInDescriptor() throws Exception { final Descriptor descriptor = new EntityDescriptor(); when(metamodelMocks.forOwlClassN().annotationAttribute().hasLanguage()).thenReturn(false); final AxiomDescriptor res = sut .createForFieldLoading(PK, OWLClassN.getAnnotationPropertyField(), descriptor, metamodelMocks.forOwlClassN().entityType()); final Set<Assertion> assertions = res.getAssertions(); assertEquals(1, assertions.size()); assertFalse(assertions.iterator().next().hasLanguage()); }
@Test void createForFieldLoadingUsesSubjectContextForAssertionWhenAssertionsInSubjectContextIsConfiguredInDescriptor() throws Exception { descriptor.addAttributeDescriptor(OWLClassD.getOwlClassAField(), descriptorInContext); final AxiomDescriptor desc = sut.createForFieldLoading(PK, OWLClassD.getOwlClassAField(), descriptor, metamodelMocks.forOwlClassD().entityType()); assertEquals(descriptor.getContext(), desc.getAssertionContext( Assertion.createObjectPropertyAssertion(URI.create(Vocabulary.P_HAS_A), false))); }
@Test void createForFieldLoadingAddsAssertionWithoutLanguageTagForSimpleLiteralAttribute() throws Exception { final AxiomDescriptor desc = sut.createForFieldLoading(PK, OWLClassM.getSimpleLiteralField(), descriptor, metamodelMocks.forOwlClassM().entityType()); assertEquals(1, desc.getAssertions().size()); final Assertion result = desc.getAssertions().iterator().next(); assertFalse(result.hasLanguage()); }