use of nl.knaw.huygens.timbuctoo.core.dto.UpdateRelation in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method replaceRelationUpdatesTheModifiedInformation.
@Test
public void replaceRelationUpdatesTheModifiedInformation() 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();
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(1).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);
long timeStamp = Instant.now().toEpochMilli();
String userId = "userId";
updateRelation.setModified(new Change(timeStamp, userId, null));
instance.replaceRelation(collection, updateRelation);
Edge newEdge = graphManager.getGraph().traversal().E().has("tim_id", relId.toString()).has("isLatest", true).next();
assertThat(getModificationInfo("modified", newEdge), is(jsnO("timeStamp", jsn(timeStamp), "userId", jsn(userId))));
}
use of nl.knaw.huygens.timbuctoo.core.dto.UpdateRelation in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method replaceRelationUpdatesTheExistingRelation.
@Test
public void replaceRelationUpdatesTheExistingRelation() 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();
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(1).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().withSourceWithId(sourceId).withTargetWithId(targetId).withTypeId(typeId).withProperty("testrelation_accepted", false)));
}
use of nl.knaw.huygens.timbuctoo.core.dto.UpdateRelation in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method replaceRelationDuplicatesTheEdge.
@Test
public void replaceRelationDuplicatesTheEdge() 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();
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(1).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);
long timeStamp = Instant.now().toEpochMilli();
String userId = "userId";
updateRelation.setModified(new Change(timeStamp, userId, null));
instance.replaceRelation(collection, updateRelation);
assertThat(graphManager.getGraph().traversal().E().has("tim_id", relId.toString()).count().next(), is(2L));
}
use of nl.knaw.huygens.timbuctoo.core.dto.UpdateRelation 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.core.dto.UpdateRelation in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method replaceRelationCallsTheChangeListener.
@Test
public void replaceRelationCallsTheChangeListener() 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();
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(1).addType("testrelation"))).withVertex("otherVertex", v -> v.withTimId(targetId.toString()).withProperty("rev", 1).withVre("test").withType("thing").withProperty("isLatest", true)).wrap();
ChangeListener changeListener = mock(ChangeListener.class);
IndexHandler indexHandler = mock(IndexHandler.class);
when(indexHandler.findEdgeById(relId)).thenReturn(Optional.of(graphManager.getGraph().traversal().E().has("tim_id", relId.toString()).next()));
TinkerPopOperations instance = forGraphMappingsListenerAndIndex(graphManager, vres, changeListener, indexHandler);
UpdateRelation updateRelation = new UpdateRelation(relId, 1, false);
long timeStamp = Instant.now().toEpochMilli();
String userId = "userId";
updateRelation.setModified(new Change(timeStamp, userId, null));
instance.replaceRelation(collection, updateRelation);
String acceptedProp = createPropName(collection.getEntityTypeName(), "accepted");
verify(changeListener).onEdgeUpdate(argThat(is(sameInstance(collection))), argThat(is(likeEdge().withProperty(acceptedProp, true))), argThat(is(likeEdge().withProperty(acceptedProp, false))));
}
Aggregations