use of nl.knaw.huygens.timbuctoo.core.dto.ReadEntity in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method getEntityReturnsTheLatestEntityIfTheRefIsNull.
@Test
public void getEntityReturnsTheLatestEntityIfTheRefIsNull() 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("testthing_prop1", "old").withProperty("rev", 1).withProperty("isLatest", false).withOutgoingRelation("VERSION_OF", "replacement")).withVertex("replacement", v -> v.withTimId(id.toString()).withType("thing").withVre("test").withProperty("testthing_prop1", "new").withProperty("rev", 2).withProperty("isLatest", false).withOutgoingRelation("VERSION_OF", "dangling")).withVertex("dangling", v -> v.withTimId(id.toString()).withType("thing").withVre("test").withProperty("testthing_prop1", "new").withProperty("rev", 2).withProperty("isLatest", true)).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
ReadEntity entity = instance.getEntity(id, null, collection, (readEntity, vertex) -> {
}, (graphTraversalSource, vre, vertex, relationRef) -> {
});
assertThat(entity.getRev(), is(2));
assertThat(entity.getProperties(), contains(allOf(hasProperty("name", equalTo("prop1")), hasProperty("value", equalTo("new")))));
}
use of nl.knaw.huygens.timbuctoo.core.dto.ReadEntity in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method getEntityByRdfUriReturnsTheLatestEntity.
@Test
public void getEntityByRdfUriReturnsTheLatestEntity() {
UUID id1 = UUID.randomUUID();
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withTimId(id1).withType("thing").withVre("test").withProperty("rdfUri", "http://example.com/entity").withProperty("rev", 2).isLatest(true).withLabel("testthing")).withVertex(v -> v.withTimId(id1).withType("thing").withVre("test").withProperty("rdfUri", "http://example.com/entity").isLatest(false).withProperty("rev", 1).withLabel("testthing")).wrap();
Vres vres = createConfiguration();
IndexHandler indexHandler = mock(IndexHandler.class);
Vertex vertex = graphManager.getGraph().traversal().V().has("tim_id", id1.toString()).next();
when(indexHandler.findVertexInRdfIndex(any(Vre.class), anyString())).thenReturn(Optional.of(vertex));
TinkerPopOperations instance = forGraphMappingsAndIndex(graphManager, vres, indexHandler);
Collection collection = vres.getCollection("testthings").get();
Optional<ReadEntity> readEntity = instance.getEntityByRdfUri(collection, "http://example.com/entity", false);
assertThat(readEntity, is(present()));
assertThat(readEntity.get(), hasProperty("rev", equalTo(2)));
}
use of nl.knaw.huygens.timbuctoo.core.dto.ReadEntity in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method getEntityOmitsDeletedRelations.
@Test
public void getEntityOmitsDeletedRelations() throws Exception {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testthings").get();
UUID id = UUID.randomUUID();
UUID relatedId = UUID.randomUUID();
TinkerPopGraphManager graphManager = newGraph().withVertex("source", v -> v.withOutgoingRelation("isRelatedTo", "relatedThing", rel -> rel.withDeleted(true)).withOutgoingRelation("hasOtherRelationWith", "relatedThing").withVre("test").withVre("").withType("thing").isLatest(true).withTimId(id.toString())).withVertex("relatedThing", v -> v.withVre("test").withVre("").withType("thing").withTimId(relatedId.toString()).withProperty("testthing_displayName", "displayName")).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
ReadEntity entity = instance.getEntity(id, null, collection, (readEntity, vertex) -> {
}, (graphTraversalSource, vre, vertex, relationRef) -> {
});
assertThat(entity.getRelations(), hasSize(1));
assertThat(entity.getRelations(), contains(hasProperty("relationType", equalTo("hasOtherRelationWith"))));
}
use of nl.knaw.huygens.timbuctoo.core.dto.ReadEntity in project timbuctoo by HuygensING.
the class TinkerPopToEntityMapperTest method mapEntitySetsABogusTimIdWhenTheVertexHasNoTimId.
@Test
public void mapEntitySetsABogusTimIdWhenTheVertexHasNoTimId() {
UUID bogusId = UUID.fromString("0000000-0000-0000-0000-000000000000");
GraphTraversalSource traversalSource = newGraph().withVertex(v -> v.withType("thing").withVre("test").withProperty("isLatest", true).withProperty("deleted", true).withProperty("rev", 1)).build().traversal();
GraphTraversal<Vertex, Vertex> traversal = traversalSource.V();
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testthings").get();
TinkerPopToEntityMapper instance = new TinkerPopToEntityMapper(collection, traversalSource, vres, (entity, entityVertex) -> {
}, (traversalSource1, vre, target, relationRef) -> {
});
ReadEntity readEntity = instance.mapEntity(traversal, false);
assertThat(readEntity.getId(), is(bogusId));
}
use of nl.knaw.huygens.timbuctoo.core.dto.ReadEntity in project timbuctoo by HuygensING.
the class TimbuctooActionsGetTest method getEntityReturnsTheReadEntity.
@Test
public void getEntityReturnsTheReadEntity() throws Exception {
ReadEntity readEntity = mock(ReadEntity.class);
when(dataStoreOperations.getEntity(ID, rev, collection, entityProps, relationProps)).thenReturn(readEntity);
ReadEntity actualEntity = instance.getEntity(collection, ID, rev, entityProps, relationProps);
assertThat(actualEntity, is(sameInstance(readEntity)));
}
Aggregations