use of nl.knaw.huygens.timbuctoo.rdf.Entity in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method getEntityReturnsTheTypesOfTheEntity.
@Test
public void getEntityReturnsTheTypesOfTheEntity() throws Exception {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testthings").get();
UUID id = UUID.randomUUID();
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withTimId(id.toString()).withProperty("isLatest", true).withProperty("rev", 1).withProperty("types", "[\"testthing\", \"otherthing\"]")).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
ReadEntity entity = instance.getEntity(id, null, collection, (readEntity, vertex) -> {
}, (graphTraversalSource, vre, vertex, relationRef) -> {
});
assertThat(entity.getTypes(), containsInAnyOrder("testthing", "otherthing"));
}
use of nl.knaw.huygens.timbuctoo.rdf.Entity in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method getCollectionReturnsRelationsIfRequested.
@Test
public void getCollectionReturnsRelationsIfRequested() {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testthings").get();
UUID thingId = UUID.randomUUID();
UUID stuffId = UUID.randomUUID();
TinkerPopGraphManager graphManager = newGraph().withVertex("v1", v -> v.withLabel("testthing").withVre("test").withType("thing").isLatest(true).withTimId(thingId.toString()).withOutgoingRelation("isCreatorOf", "stuff")).withVertex("stuff", v -> v.withVre("test").withType("stuff").withTimId(stuffId.toString())).withVertex(v -> v.withProperty("relationtype_regularName", "isCreatedBy").withProperty("relationtype_inverseName", "isCreatorOf")).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
DataStream<ReadEntity> entities = instance.getCollection(collection, 0, 1, true, (readEntity, vertex) -> {
}, (graphTraversalSource, vre, vertex, relationRef) -> {
});
ReadEntity readEntity = entities.map(entity -> entity).get(0);
assertThat(readEntity.getRelations(), contains(allOf(hasProperty("entityId", equalTo(stuffId.toString())), hasProperty("collectionName", equalTo("teststuffs")), hasProperty("entityType", equalTo("teststuff")), hasProperty("relationType", equalTo("isCreatorOf")))));
}
use of nl.knaw.huygens.timbuctoo.rdf.Entity in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method getEntityUsesTheInverseRelationName.
@Test
public void getEntityUsesTheInverseRelationName() throws Exception {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testthings").get();
UUID id = UUID.randomUUID();
UUID stuffId = UUID.randomUUID();
TinkerPopGraphManager graphManager = newGraph().withVertex("source", v -> v.withIncomingRelation("isCreatedBy", "stuff").withVre("test").withVre("").withType("thing").isLatest(true).withTimId(id.toString())).withVertex("stuff", v -> v.withVre("test").withVre("").withType("stuff").withTimId(stuffId.toString())).withVertex(v -> v.withProperty("relationtype_regularName", "isCreatedBy").withProperty("relationtype_inverseName", "isCreatorOf")).withVertex(v -> v.withProperty("relationtype_regularName", "otherRelationType").withProperty("relationtype_inverseName", "otherInverseType")).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
ReadEntity entity = instance.getEntity(id, null, collection, (readEntity, vertex) -> {
}, (graphTraversalSource, vre, vertex, relationRef) -> {
});
assertThat(entity.getRelations(), contains(allOf(hasProperty("entityId", equalTo(stuffId.toString())), hasProperty("relationType", equalTo("isCreatorOf")))));
}
use of nl.knaw.huygens.timbuctoo.rdf.Entity 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.rdf.Entity 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)));
}
Aggregations