use of nl.knaw.huygens.timbuctoo.model.Change in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method replaceEntityUpdatesTheKnownProperties.
@Test
public void replaceEntityUpdatesTheKnownProperties() throws Exception {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testthings").get();
UUID id = UUID.randomUUID();
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withTimId(id).withVre("test").withType("thing").withProperty("testthing_prop1", "oldValue").withProperty("isLatest", true).withProperty("rev", 1)).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
ArrayList<TimProperty<?>> properties = Lists.newArrayList(new StringProperty("prop1", "newValue"), new StringProperty("prop2", "prop2Value"));
UpdateEntity updateEntity = new UpdateEntity(id, properties, 1);
long timeStamp = Instant.now().toEpochMilli();
updateEntity.setModified(new Change(timeStamp, "userId", null));
instance.replaceEntity(collection, updateEntity);
Vertex vertex = graphManager.getGraph().traversal().V().has("tim_id", id.toString()).has("isLatest", true).next();
assertThat(vertex, is(likeVertex().withProperty("testthing_prop1", "newValue").withProperty("testthing_prop2", "prop2Value")));
}
use of nl.knaw.huygens.timbuctoo.model.Change in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method acceptRelationThrowsARelationNotPossibleExceptionIfTheSourceIsNotInTheRightVre.
@Test(expected = RelationNotPossibleException.class)
public void acceptRelationThrowsARelationNotPossibleExceptionIfTheSourceIsNotInTheRightVre() throws Exception {
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("other").withType("thing").withProperty("isLatest", true)).withVertex(v -> v.withTimId(targetId.toString()).withProperty("rev", 1).withVre("test").withType("thing").withProperty("isLatest", true)).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
CreateRelation createRelation = new CreateRelation(sourceId, typeId, targetId);
createRelation.setCreated(new Change(Instant.now().toEpochMilli(), "userId", null));
instance.acceptRelation(collection, createRelation);
}
use of nl.knaw.huygens.timbuctoo.model.Change in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method acceptRelationSetsTheCreatedInformation.
@Test
public void acceptRelationSetsTheCreatedInformation() throws Exception {
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 = forGraphWrapperAndMappings(graphManager, vres);
CreateRelation createRelation = new CreateRelation(sourceId, typeId, targetId);
long timeStamp = Instant.now().toEpochMilli();
String userId = "userId";
createRelation.setCreated(new Change(timeStamp, userId, null));
UUID relId = instance.acceptRelation(collection, createRelation);
Edge newEdge = graphManager.getGraph().traversal().E().has("tim_id", relId.toString()).next();
assertThat(getModificationInfo("modified", newEdge), is(jsnO("timeStamp", jsn(timeStamp), "userId", jsn(userId))));
assertThat(getModificationInfo("created", newEdge), is(jsnO("timeStamp", jsn(timeStamp), "userId", jsn(userId))));
}
use of nl.knaw.huygens.timbuctoo.model.Change in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method replaceEntityRemovesThePropertiesThatAreNotProvided.
@Test
public void replaceEntityRemovesThePropertiesThatAreNotProvided() throws Exception {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testthings").get();
UUID id = UUID.randomUUID();
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withTimId(id).withVre("test").withType("thing").withProperty("testthing_prop1", "oldValue1").withProperty("testthing_prop2", "oldValue2").withProperty("isLatest", true).withProperty("rev", 1)).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
ArrayList<TimProperty<?>> properties = Lists.newArrayList(new StringProperty("prop1", "newValue"));
UpdateEntity updateEntity = new UpdateEntity(id, properties, 1);
long timeStamp = Instant.now().toEpochMilli();
updateEntity.setModified(new Change(timeStamp, "userId", null));
instance.replaceEntity(collection, updateEntity);
Vertex vertex = graphManager.getGraph().traversal().V().has("tim_id", id.toString()).has("isLatest", true).next();
assertThat(vertex, is(likeVertex().withoutProperty("testthing_prop2")));
}
use of nl.knaw.huygens.timbuctoo.model.Change in project timbuctoo by HuygensING.
the class ChangeListenerTest method callsOnAddToCollectionOnReplaceEntityWithNewCollection.
@Test
public void callsOnAddToCollectionOnReplaceEntityWithNewCollection() throws Exception {
ChangeListener changeListener = new ChangeListenerImpl(vertex -> {
assertThat(vertex, likeVertex().withProperty("isLatest", true).withProperty("rev", 2));
Long prevVersions = stream(vertex.vertices(Direction.BOTH, VERSION_OF)).collect(Collectors.counting());
assertThat(prevVersions, is(1L));
});
UUID id = UUID.randomUUID();
ChangeListener spy = spy(changeListener);
DataStoreOperations instance = forReplaceCall(spy, id, 1);
UpdateEntity updateEntity = new UpdateEntity(id, newArrayList(), 1);
updateEntity.setModified(new Change());
Collection collectionMock = mock(Collection.class);
given(collectionMock.getEntityTypeName()).willReturn("something");
instance.replaceEntity(collectionMock, updateEntity);
verify(spy).onAddToCollection(same(collectionMock), any(), any());
}
Aggregations