use of nl.knaw.huygens.timbuctoo.model.Change in project timbuctoo by HuygensING.
the class EntityToJsonMapperTest method mapEntityMapsTheRelations.
@Test
public void mapEntityMapsTheRelations() throws Exception {
ReadEntityImpl readEntity = new ReadEntityImpl();
UUID id = UUID.randomUUID();
readEntity.setId(id);
String userId = "userId";
Change change = new Change(Instant.now().toEpochMilli(), userId, null);
readEntity.setCreated(change);
readEntity.setModified(change);
String type = "otherType";
readEntity.setTypes(Lists.newArrayList("type", type));
readEntity.setDeleted(false);
readEntity.setRev(1);
readEntity.setPid("pid");
readEntity.setProperties(Lists.newArrayList());
String otherEntity = UUID.randomUUID().toString();
String relType = "relType";
readEntity.setRelations(Lists.newArrayList(new RelationRef(otherEntity, "rdfUri", new String[] { "origUri" }, "otherColl", "otherType", true, "relId", "rdfUri", 1, relType, "displayName")));
Collection collection = mock(Collection.class);
when(collection.getEntityTypeName()).thenReturn(type);
ObjectNode resutlJson = instance.mapEntity(collection, readEntity, true, (readEntity1, resultJson) -> {
}, (relationRef, resultJson) -> {
});
assertThat(resutlJson.toString(), sameJSONAs(jsnO("@relationCount", jsn(1), "@relations", jsnO(relType, jsnA(jsnO("id", jsn(otherEntity))))).toString()).allowingExtraUnexpectedFields());
}
use of nl.knaw.huygens.timbuctoo.model.Change in project timbuctoo by HuygensING.
the class ChangeListenerTest method callsOnRemoveFromCollectionOnDeleteEntity.
@Test
public void callsOnRemoveFromCollectionOnDeleteEntity() 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 = forDeleteCall(spy, id, 1, "someName");
Collection collection = mock(Collection.class);
when(collection.getEntityTypeName()).thenReturn("someName");
when(collection.getVre()).thenReturn(mock(Vre.class));
instance.deleteEntity(collection, id, new Change());
verify(spy).onRemoveFromCollection(same(collection), any(), any());
}
use of nl.knaw.huygens.timbuctoo.model.Change in project timbuctoo by HuygensING.
the class ChangeListenerTest method callsOnPropertyUpdateOnReplaceEntity.
@Test
public void callsOnPropertyUpdateOnReplaceEntity() 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);
instance.replaceEntity(collectionMock, updateEntity);
verify(spy).onPropertyUpdate(same(collectionMock), any(), any());
}
use of nl.knaw.huygens.timbuctoo.model.Change in project timbuctoo by HuygensING.
the class TimbuctooActions method createChange.
private Change createChange(User user) {
Change change = new Change();
change.setUserId(user.getId());
change.setTimeStamp(clock.instant().toEpochMilli());
return change;
}
use of nl.knaw.huygens.timbuctoo.model.Change in project timbuctoo by HuygensING.
the class ChangeDatePropertyParserTest method parseForSortReturnsTheTimestamp.
@Test
public void parseForSortReturnsTheTimestamp() throws JsonProcessingException {
long timeStampOnJan20th2016 = 1453290593000L;
Change change = new Change(timeStampOnJan20th2016, "user", "vre");
String changeString = new ObjectMapper().writeValueAsString(change);
Object result = instance.parseForSort(changeString);
assertThat(result, is(timeStampOnJan20th2016));
}
Aggregations