use of nl.knaw.huygens.timbuctoo.model.Change in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method deleteEntityIncreasesTheRevision.
// TODO move increase of the rev to TimbuctooActions
@Test
public void deleteEntityIncreasesTheRevision() 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);
int rev = instance.deleteEntity(collection, id, new Change(Instant.now().toEpochMilli(), "userId", null));
assertThat(rev, is(2));
}
use of nl.knaw.huygens.timbuctoo.model.Change 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.model.Change 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.model.Change in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method deletesAllRelationsOfCurrentVre.
@Test
public void deletesAllRelationsOfCurrentVre() throws Exception {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testthings").get();
UUID id = UUID.randomUUID();
String idString = id.toString();
final String testOnlyId = "10000000-0000-0000-0000-000000000000";
final String otherOnlyId = "20000000-0000-0000-0000-000000000000";
final String inBothId = "30000000-0000-0000-0000-000000000000";
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withTimId(idString).withVre("test").withType("thing").withProperty("isLatest", true).withProperty("rev", 1).withOutgoingRelation("hasWritten", "stuff", rel -> rel.withTim_id(UUID.fromString(testOnlyId)).removeType("other").withAccepted("testrelation", true)).withIncomingRelation("isFriendOf", "friend", rel -> rel.withTim_id(UUID.fromString(inBothId)).withAccepted("testrelation", true).withAccepted("otherrelation", true)).withIncomingRelation("isFriendOf", "friend", rel -> rel.withTim_id(UUID.fromString(otherOnlyId)).removeType("test").withAccepted("otherrelation", true))).withVertex("stuff", v -> v.withVre("test").withType("stuff").withProperty("isLatest", true).withProperty("rev", 1)).withVertex("friend", v -> v.withVre("test").withVre("other").withType("thing").withProperty("isLatest", true).withProperty("rev", 1)).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
instance.deleteEntity(collection, id, new Change(Instant.now().toEpochMilli(), "userId", null));
assertThat(graphManager.getGraph().traversal().E().has("tim_id", testOnlyId).has("isLatest", true).has("testrelation_accepted", false).not(has("otherrelation_accepted")).hasNext(), is(true));
assertThat(graphManager.getGraph().traversal().E().has("tim_id", inBothId).has("isLatest", true).has("testrelation_accepted", false).has("otherrelation_accepted", true).hasNext(), is(true));
assertThat(graphManager.getGraph().traversal().E().has("tim_id", otherOnlyId).has("isLatest", true).not(has("testrelation_accepted")).has("otherrelation_accepted", true).hasNext(), is(true));
}
use of nl.knaw.huygens.timbuctoo.model.Change in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method acceptRelationCallTheChangeListener.
@Test
public void acceptRelationCallTheChangeListener() throws Exception {
ChangeListener changeListener = mock(ChangeListener.class);
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testrelations").get();
UUID typeId = UUID.randomUUID();
UUID sourceId = UUID.randomUUID();
UUID targetId = UUID.randomUUID();
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)).withVertex(v -> v.withTimId(targetId.toString()).withProperty("rev", 1).withVre("test").withType("thing").withProperty("isLatest", true)).wrap();
TinkerPopOperations instance = forGraphMappingsAndChangeListener(graphManager, vres, changeListener);
CreateRelation createRelation = new CreateRelation(sourceId, typeId, targetId);
createRelation.setCreated(new Change(Instant.now().toEpochMilli(), "userId", null));
instance.acceptRelation(collection, createRelation);
verify(changeListener).onCreateEdge(argThat(is(sameInstance(collection))), argThat(is(likeEdge().withSourceWithId(sourceId).withTargetWithId(targetId).withTypeId(typeId))));
}
Aggregations