use of nl.knaw.huygens.timbuctoo.database.tinkerpop.VertexDuplicator.VERSION_OF 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.database.tinkerpop.VertexDuplicator.VERSION_OF 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()));
}
use of nl.knaw.huygens.timbuctoo.database.tinkerpop.VertexDuplicator.VERSION_OF 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.database.tinkerpop.VertexDuplicator.VERSION_OF 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")))));
}
Aggregations