use of nl.knaw.huygens.timbuctoo.database.tinkerpop.changelistener.ChangeListener 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))));
}
use of nl.knaw.huygens.timbuctoo.database.tinkerpop.changelistener.ChangeListener 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))));
}
use of nl.knaw.huygens.timbuctoo.database.tinkerpop.changelistener.ChangeListener in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method finishEntitiesCallsTheChangeListener.
@Test
public void finishEntitiesCallsTheChangeListener() {
ChangeListener changeListener = mock(ChangeListener.class);
TinkerPopOperations instance = TinkerPopOperationsStubs.forChangeListenerMock(changeListener);
Vre vre = instance.ensureVreExists("vre");
instance.addCollectionToVre(vre, CreateCollection.defaultCollection("vre"));
vre = instance.loadVres().getVre("vre");
Collection defaultCollection = vre.getCollectionForTypeName(defaultEntityTypeName(vre));
Vertex orig = instance.assertEntity(vre, "http://example.org/entity1");
instance.finishEntities(vre, new EntityFinisherHelper());
Vertex duplicate = orig.vertices(Direction.OUT, VERSION_OF).next();
verify(changeListener).onCreate(eq(defaultCollection), eq(duplicate));
verify(changeListener).onAddToCollection(eq(defaultCollection), eq(Optional.empty()), eq(duplicate));
}
Aggregations