DefaultInstanceLoader extends EntityInstanceLoader { @Override <T> T loadReference(LoadingParameters<T> loadingParameters) { final EntityType<T> et = metamodel.entity(loadingParameters.getEntityType()); return loadReferenceInstance(loadingParameters, et); } private  DefaultInstanceLoader(DefaultInstanceLoaderBuilder builder);   }
@Test void loadReferenceVerifiesClassAssertionExistenceAndBuildsEntityInstanceWithIdentifier() throws Exception { final Axiom<NamedResource> typeAxiom = new AxiomImpl<>(NamedResource.create(IDENTIFIER), Assertion.createClassAssertion(false), new Value<>(NamedResource.create( Vocabulary.c_OwlClassA))); when(connectionMock.contains(typeAxiom, null)).thenReturn(true); when(descriptorFactoryMock.createForReferenceLoading(IDENTIFIER, etAMock)).thenReturn(typeAxiom); when(entityConstructorMock.createEntityInstance(IDENTIFIER, etAMock)).thenReturn(entityA); final OWLClassA result = instanceLoader.loadReference(loadingParameters); assertNotNull(result); verify(descriptorFactoryMock).createForReferenceLoading(IDENTIFIER, etAMock); verify(connectionMock).contains(typeAxiom, null); verify(entityConstructorMock).createEntityInstance(IDENTIFIER, etAMock); }
@Test void loadReferenceChecksForClassAssertionInCorrectContext() throws Exception { final EntityDescriptor descriptor = new EntityDescriptor(Generators.createIndividualIdentifier()); final Axiom<NamedResource> typeAxiom = new AxiomImpl<>(NamedResource.create(IDENTIFIER), Assertion.createClassAssertion(false), new Value<>(NamedResource.create( Vocabulary.c_OwlClassA))); when(connectionMock.contains(eq(typeAxiom), any())).thenReturn(true); when(descriptorFactoryMock.createForReferenceLoading(IDENTIFIER, etAMock)).thenReturn(typeAxiom); when(entityConstructorMock.createEntityInstance(IDENTIFIER, etAMock)).thenReturn(entityA); final OWLClassA result = instanceLoader.loadReference(new LoadingParameters<>(OWLClassA.class, IDENTIFIER, descriptor)); assertNotNull(result); verify(connectionMock).contains(typeAxiom, descriptor.getContext()); }
@Test void loadReferenceReturnsNullWhenStorageDoesNotContainTypeAssertionAxiom() throws Exception { final Axiom<NamedResource> typeAxiom = new AxiomImpl<>(NamedResource.create(IDENTIFIER), Assertion.createClassAssertion(false), new Value<>(NamedResource.create( Vocabulary.c_OwlClassA))); when(connectionMock.contains(any(), any())).thenReturn(false); when(descriptorFactoryMock.createForReferenceLoading(IDENTIFIER, etAMock)).thenReturn(typeAxiom); when(entityConstructorMock.createEntityInstance(IDENTIFIER, etAMock)).thenReturn(entityA); final OWLClassA result = instanceLoader.loadReference(loadingParameters); assertNull(result); verify(entityConstructorMock, never()).createEntityInstance(IDENTIFIER, etAMock); }
@Test void loadReferenceThrowsStorageAccessExceptionOnDriverException() throws Exception { final Axiom<NamedResource> typeAxiom = new AxiomImpl<>(NamedResource.create(IDENTIFIER), Assertion.createClassAssertion(false), new Value<>(NamedResource.create( Vocabulary.c_OwlClassA))); when(descriptorFactoryMock.createForReferenceLoading(IDENTIFIER, etAMock)).thenReturn(typeAxiom); when(connectionMock.contains(any(), any())).thenThrow(new OntoDriverException()); assertThrows(StorageAccessException.class, () -> instanceLoader.loadReference(loadingParameters)); verify(entityConstructorMock, never()).createEntityInstance(IDENTIFIER, etAMock); }