use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection 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.core.dto.dataset.Collection 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.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method replaceEntityAddsAType.
@Test
public void replaceEntityAddsAType() throws Exception {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testthings").get();
UUID id = UUID.randomUUID();
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withTimId(id).withVre("other").withType("thing").withProperty("isLatest", true).withProperty("rev", 1).withProperty("otherthing_prop1", "the name").withIncomingRelation("VERSION_OF", "orig")).withVertex("orig", v -> v.withTimId(id).withVre("other").withType("thing").withProperty("isLatest", false).withProperty("rev", 1).withProperty("otherthing_prop1", "the name")).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
UpdateEntity updateEntity = new UpdateEntity(id, Lists.newArrayList(), 1);
updateEntity.setModified(new Change(Instant.now().toEpochMilli(), "userId", null));
instance.replaceEntity(collection, updateEntity);
String types = (String) graphManager.getGraph().traversal().V().has("tim_id", id.toString()).has("isLatest", true).values("types").next();
assertThat(types, containsString("\"testthing\""));
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method deleteEntityThrowsNotFoundWhenTheEntityIsNotOfThisVre.
@Test(expected = NotFoundException.class)
public void deleteEntityThrowsNotFoundWhenTheEntityIsNotOfThisVre() throws Exception {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testthings").get();
UUID id = UUID.randomUUID();
String idString = id.toString();
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withTimId(idString).withVre("other").withType("person").withProperty("isLatest", true).withProperty("rev", 1).withProperty("deleted", false)).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
instance.deleteEntity(collection, id, null);
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection 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")))));
}
Aggregations