use of nl.knaw.huygens.timbuctoo.rdf.Entity in project timbuctoo by HuygensING.
the class SameAsTripleProcessorTest method shouldCopyAndRemoveObjectEntityWhenBothEntitiesExist.
@Test
public void shouldCopyAndRemoveObjectEntityWhenBothEntitiesExist() {
final Entity subjectEntity = mock(Entity.class);
final Entity objectEntity = mock(Entity.class);
final Optional<Entity> subjectEntityOptional = Optional.of(subjectEntity);
final Optional<Entity> objectEntityOptional = Optional.of(objectEntity);
final List<Map<String, String>> objectProperties = Lists.newArrayList();
final Map<String, String> objectProperty = Maps.newHashMap();
final String unprefixedPropertyName = "the-name";
final String propertyType = "the-type";
final String propertyValue = "a value";
objectProperty.put(LocalProperty.PROPERTY_TYPE_NAME, propertyType);
objectProperty.put(LocalProperty.CLIENT_PROPERTY_NAME, unprefixedPropertyName);
objectProperty.put("value", propertyValue);
objectProperties.add(objectProperty);
given(database.findEntity(VRE_NAME, SUBJECT_URI)).willReturn(subjectEntityOptional);
given(database.findEntity(VRE_NAME, OBJECT_URI)).willReturn(objectEntityOptional);
given(objectEntity.getProperties()).willReturn(objectProperties);
given(subjectEntity.getProperty(unprefixedPropertyName)).willReturn(Optional.empty());
instance.process(VRE_NAME, SUBJECT_URI, SAME_AS_URI, OBJECT_URI, true);
// Verify initial load *and* reload of subject entity
verify(database, atLeast(2)).findEntity(VRE_NAME, SUBJECT_URI);
verify(subjectEntity).addProperty(unprefixedPropertyName, propertyValue, propertyType);
verify(database).copyEdgesFromObjectIntoSubject(subjectEntity, objectEntity);
verify(database).purgeEntity(VRE_NAME, objectEntity);
verify(database).addRdfSynonym(VRE_NAME, subjectEntity, OBJECT_URI);
}
use of nl.knaw.huygens.timbuctoo.rdf.Entity in project timbuctoo by HuygensING.
the class CollectionMembershipTripleProcessorTest method processLogsAnExceptionWhenTheEntityAlreadyIsPartOfACollectionWhenAsserted.
@Test
public void processLogsAnExceptionWhenTheEntityAlreadyIsPartOfACollectionWhenAsserted() {
Database database = mock(Database.class);
Collection collectionFromTriple = mock(Collection.class);
Collection archetypeCollection = mock(Collection.class);
when(collectionFromTriple.getArchetype()).thenReturn(Optional.of(archetypeCollection));
when(database.findOrCreateCollection(anyString(), anyString(), anyString())).thenReturn(collectionFromTriple);
Collection defaultCollection = mock(Collection.class);
when(database.getDefaultCollection("vreName")).thenReturn(defaultCollection);
Entity entity = mock(Entity.class);
when(entity.isInKnownCollection()).thenReturn(true);
when(database.findOrCreateEntity("vreName", SUBJECT_URI)).thenReturn(entity);
RdfImportSession rdfImportSession = mock(RdfImportSession.class);
RdfImportErrorReporter errorReporter = mock(RdfImportErrorReporter.class);
when(rdfImportSession.getErrorReporter()).thenReturn(errorReporter);
CollectionMembershipTripleProcessor instance = new CollectionMembershipTripleProcessor(database, rdfImportSession);
instance.process("vreName", SUBJECT_URI, PREDICATE_URI, OBJECT_URI, true);
verify(errorReporter).multipleRdfTypes(SUBJECT_URI, OBJECT_URI);
}
use of nl.knaw.huygens.timbuctoo.rdf.Entity in project timbuctoo by HuygensING.
the class CollectionMembershipTripleProcessorTest method processRemovesTheEntityToTheRequestedCollectionIfItIsARetraction.
@Test
public void processRemovesTheEntityToTheRequestedCollectionIfItIsARetraction() {
Database database = mock(Database.class);
Collection collectionFromTriple = mock(Collection.class);
Collection archetypeCollection = mock(Collection.class);
when(collectionFromTriple.getArchetype()).thenReturn(Optional.of(archetypeCollection));
when(database.findOrCreateCollection(anyString(), anyString(), anyString())).thenReturn(collectionFromTriple);
Collection defaultCollection = mock(Collection.class);
when(database.getDefaultCollection("vreName")).thenReturn(defaultCollection);
Entity entity = mock(Entity.class);
when(database.findOrCreateEntity("vreName", SUBJECT_URI)).thenReturn(entity);
CollectionMembershipTripleProcessor instance = new CollectionMembershipTripleProcessor(database, mock(RdfImportSession.class));
instance.process("vreName", SUBJECT_URI, PREDICATE_URI, OBJECT_URI, false);
InOrder inOrder = inOrder(entity, database);
inOrder.verify(database).findOrCreateCollection("vreName", OBJECT_URI, OBJECT_NAME);
inOrder.verify(entity).removeFromCollection(collectionFromTriple);
}
use of nl.knaw.huygens.timbuctoo.rdf.Entity in project timbuctoo by HuygensING.
the class PersonNamesTripleProcessorTest method setUp.
@Before
public void setUp() throws Exception {
RdfImportSession rdfImportSession = mock(RdfImportSession.class);
database = mock(Database.class);
instance = new PersonNamesTripleProcessor(rdfImportSession, database);
entity = mock(Entity.class);
given(entity.getPropertyValue(PROPERTY_NAME)).willReturn(Optional.empty());
given(database.findOrCreateEntity(VRE_NAME, SUBJECT_URI)).willReturn(entity);
}
use of nl.knaw.huygens.timbuctoo.rdf.Entity in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method getEntityAlwaysReturnsTheDeletedProperty.
@Test
public void getEntityAlwaysReturnsTheDeletedProperty() throws Exception {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testthings").get();
UUID id = UUID.randomUUID();
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withTimId(id.toString()).withType("thing").withVre("test").withProperty("isLatest", true).withProperty("rev", 1)).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
ReadEntity entity = instance.getEntity(id, null, collection, (readEntity, vertex) -> {
}, (graphTraversalSource, vre, vertex, relationRef) -> {
});
assertThat(entity.getDeleted(), is(false));
}
Aggregations