use of nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method getEntityReturnsTheSpecifiedRevision.
@Test
public void getEntityReturnsTheSpecifiedRevision() 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, 1, collection, (readEntity, vertex) -> {
}, (graphTraversalSource, vre, vertex, relationRef) -> {
});
assertThat(entity.getRev(), is(1));
assertThat(entity.getProperties(), contains(allOf(hasProperty("name", equalTo("prop1")), hasProperty("value", equalTo("old")))));
}
use of nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method replaceEntityUpdatesTheRevisionByOne.
@Test
public void replaceEntityUpdatesTheRevisionByOne() 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).withIncomingRelation("VERSION_OF", "orig")).withVertex("orig", v -> v.withTimId(id.toString()).withProperty("isLatest", false).withProperty("rev", 1)).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);
int rev = (int) graphManager.getGraph().traversal().V().has("tim_id", id.toString()).has("isLatest", true).values("rev").next();
assertThat(rev, is(2));
}
use of nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method finishEntitiesSetsTheAdministrativeProperties.
@Test
public void finishEntitiesSetsTheAdministrativeProperties() {
TinkerPopGraphManager graphManager = newGraph().wrap();
TinkerPopOperations instance = forGraphWrapper(graphManager);
Vre vre = instance.ensureVreExists("vre");
instance.addCollectionToVre(vre, CreateCollection.defaultCollection("vre"));
vre = instance.loadVres().getVre("vre");
Vertex e1 = instance.assertEntity(vre, "http://example.org/entity1");
Vertex e2 = instance.assertEntity(vre, "http://example.org/entity2");
instance.finishEntities(vre, new EntityFinisherHelper());
assertThat(graphManager.getGraph().traversal().V(e1.id()).has("tim_id").has("rev").has("modified").has("created").has("types").hasNext(), is(true));
assertThat(graphManager.getGraph().traversal().V(e2.id()).has("tim_id").has("rev").has("modified").has("created").has("types").hasNext(), is(true));
}
use of nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method getEntityOnlyReturnsTheLatestRelations.
@Test
public void getEntityOnlyReturnsTheLatestRelations() 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.withIsLatest(true).withRev(2)).withOutgoingRelation("isRelatedTo", "relatedThing", rel -> rel.withIsLatest(false).withRev(1)).withVre("test").withVre("").withType("thing").isLatest(true).withTimId(id.toString())).withVertex("relatedThing", v -> v.withVre("test").withVre("").withType("thing").withTimId(relatedId.toString())).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(allOf(hasProperty("entityId", equalTo(relatedId.toString())), hasProperty("relationType", equalTo("isRelatedTo")), hasProperty("relationRev", equalTo(2)))));
}
use of nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method deleteEntityPreparesBackupCopyAfterMakingChanges.
@Test
public void deleteEntityPreparesBackupCopyAfterMakingChanges() 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("test").withType("thing").withProperty("isLatest", true).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);
Vertex beforeUpdate = graphManager.getGraph().traversal().V().has("tim_id", idString).has("isLatest", true).next();
instance.deleteEntity(collection, id, new Change(Instant.now().toEpochMilli(), "userId", null));
Vertex afterUpdate = graphManager.getGraph().traversal().V().has("tim_id", idString).has("isLatest", true).next();
assertThat(afterUpdate.id(), is(not(beforeUpdate.id())));
// single edge, containing the VERSION_OF pointer
assertThat(afterUpdate.edges(Direction.IN).next().outVertex().id(), is(beforeUpdate.id()));
}
Aggregations