use of nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method getCollectionReturnsAllTheLatestEntitiesOfACollection.
@Test
public void getCollectionReturnsAllTheLatestEntitiesOfACollection() {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testthings").get();
UUID id1 = UUID.randomUUID();
UUID id2 = UUID.randomUUID();
UUID id3 = UUID.randomUUID();
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withLabel("testthing").withType("thing").withVre("test").isLatest(true).withTimId(id1.toString())).withVertex(v -> v.withLabel("testthing").withType("thing").withVre("test").isLatest(true).withTimId(id2.toString())).withVertex(v -> v.withLabel("testthing").withType("thing").withVre("test").isLatest(false).withTimId(id2.toString())).withVertex(v -> v.withLabel("testthing").withType("thing").withVre("test").isLatest(true).withTimId(id3.toString())).withVertex(v -> v.withLabel("teststuff").withType("stuff").withVre("test").isLatest(true).withTimId(UUID.randomUUID().toString())).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
DataStream<ReadEntity> entities = instance.getCollection(collection, 0, 3, false, (readEntity, vertex) -> {
}, (graphTraversalSource, vre, vertex, relationRef) -> {
});
List<UUID> ids = entities.map(ReadEntity::getId);
assertThat(ids, hasSize(3));
assertThat(ids, containsInAnyOrder(id1, id2, id3));
}
use of nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method getEntityThrowsNotFoundIfTheEntityDoesNotContainTheRequestType.
@Test(expected = NotFoundException.class)
public void getEntityThrowsNotFoundIfTheEntityDoesNotContainTheRequestType() 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("other").withProperty("isLatest", true).withProperty("rev", 1)).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
instance.getEntity(id, null, collection, (readEntity, vertex) -> {
}, (graphTraversalSource, vre, vertex, relationRef) -> {
});
}
use of nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method replaceRelationUpdatesTheRevisionByOne.
@Test
public void replaceRelationUpdatesTheRevisionByOne() throws Exception {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testrelations").get();
UUID typeId = UUID.randomUUID();
UUID sourceId = UUID.randomUUID();
UUID targetId = UUID.randomUUID();
UUID relId = UUID.randomUUID();
int relationRev = 1;
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withTimId(typeId.toString()).withType("relationtype").withProperty("relationtype_regularName", "regularName").withProperty("rev", 1).withProperty("isLatest", true)).withVertex(v -> v.withTimId(sourceId.toString()).withProperty("rev", 1).withVre("test").withType("thing").withProperty("isLatest", true).withOutgoingRelation("regularName", "otherVertex", r -> r.withTim_id(relId).withAccepted("testrelation", true).withTypeId(typeId).withRev(relationRev).addType("testrelation"))).withVertex("otherVertex", v -> v.withTimId(targetId.toString()).withProperty("rev", 1).withVre("test").withType("thing").withProperty("isLatest", true)).wrap();
IndexHandler indexHandler = mock(IndexHandler.class);
when(indexHandler.findEdgeById(relId)).thenReturn(Optional.of(graphManager.getGraph().traversal().E().has("tim_id", relId.toString()).next()));
TinkerPopOperations instance = forGraphMappingsAndIndex(graphManager, vres, indexHandler);
UpdateRelation updateRelation = new UpdateRelation(relId, 1, false);
updateRelation.setModified(new Change(Instant.now().toEpochMilli(), "userId", null));
instance.replaceRelation(collection, updateRelation);
assertThat(graphManager.getGraph().traversal().E().has("tim_id", relId.toString()).has("isLatest", true).next(), is(likeEdge().withProperty("rev", relationRev + 1)));
}
use of nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method deleteVreRemovesAllTheVresCollectionsFromDatabase.
@Test
public void deleteVreRemovesAllTheVresCollectionsFromDatabase() {
TinkerPopGraphManager graphManager = newGraph().withVertex("vreName", v -> v.withLabel("VRE").withProperty(Vre.VRE_NAME_PROPERTY_NAME, "vreName").withOutgoingRelation(HAS_COLLECTION_RELATION_NAME, "collection1").withOutgoingRelation(HAS_COLLECTION_RELATION_NAME, "collection2")).withVertex("collection1", v -> v.withProperty(COLLECTION_NAME_PROPERTY_NAME, "collection1").withProperty(ENTITY_TYPE_NAME_PROPERTY_NAME, "entityType1").withProperty(IS_RELATION_COLLECTION_PROPERTY_NAME, true).withOutgoingRelation(HAS_DISPLAY_NAME_RELATION_NAME, "displayName").withOutgoingRelation(HAS_PROPERTY_RELATION_NAME, "property").withOutgoingRelation(HAS_ENTITY_NODE_RELATION_NAME, "entityNode")).withVertex("displayName", v -> v.withProperty("displayName", true).withProperty("propertyType", "string")).withVertex("property", v -> v.withProperty("property", true).withProperty("propertyType", "string")).withVertex("entityNode", v -> v.withOutgoingRelation(HAS_ENTITY_RELATION_NAME, "entity")).withVertex("entity", v -> v.withProperty("entity", true)).withVertex("collection2", v -> v.withProperty(COLLECTION_NAME_PROPERTY_NAME, "collection2").withProperty(ENTITY_TYPE_NAME_PROPERTY_NAME, "entityType2").withProperty(IS_RELATION_COLLECTION_PROPERTY_NAME, false)).withVertex("otherVreCollection", v -> v.withProperty(COLLECTION_NAME_PROPERTY_NAME, "otherVreCollection").withProperty(ENTITY_TYPE_NAME_PROPERTY_NAME, "entityType3").withProperty(IS_RELATION_COLLECTION_PROPERTY_NAME, false)).wrap();
TinkerPopOperations instance = forGraphWrapper(graphManager);
instance.deleteVre("vreName");
Graph graph = graphManager.getGraph();
assertThat(graph.traversal().V().has(Vre.VRE_NAME_PROPERTY_NAME, "vreName").hasNext(), equalTo(false));
assertThat(graph.traversal().V().has(COLLECTION_NAME_PROPERTY_NAME, "collection1").hasNext(), equalTo(false));
assertThat(graph.traversal().V().has(COLLECTION_NAME_PROPERTY_NAME, "collection2").hasNext(), equalTo(false));
assertThat(graph.traversal().V().has(COLLECTION_NAME_PROPERTY_NAME, "otherVreCollection").hasNext(), equalTo(true));
assertThat(graph.traversal().V().has("entity").hasNext(), equalTo(false));
assertThat(graph.traversal().V().has("displayName").hasNext(), equalTo(false));
}
use of nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method deleteEntitySetsDeletedToTrueWhenLastTypeIsRemoved.
@Test
public void deleteEntitySetsDeletedToTrueWhenLastTypeIsRemoved() 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).withProperty("isLatest", true).withVre("test").withType("thing").withProperty("rev", 1).withIncomingRelation("VERSION_OF", "orig")).withVertex("orig", v -> v.withTimId(idString).withVre("test").withType("thing").withProperty("isLatest", false).withProperty("rev", 1)).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
instance.deleteEntity(collection, id, new Change(Instant.now().toEpochMilli(), "userId", null));
assertThat(graphManager.getGraph().traversal().V().has("tim_id", idString).has("deleted", true).hasNext(), is(true));
}
Aggregations