Search in sources :

Example 16 with Change

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());
}
Also used : ReadEntityImpl(nl.knaw.huygens.timbuctoo.core.dto.ReadEntityImpl) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Change(nl.knaw.huygens.timbuctoo.model.Change) UUID(java.util.UUID) RelationRef(nl.knaw.huygens.timbuctoo.core.dto.RelationRef) Test(org.junit.Test)

Example 17 with Change

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());
}
Also used : DataStoreOperations(nl.knaw.huygens.timbuctoo.core.DataStoreOperations) Vre(nl.knaw.huygens.timbuctoo.model.vre.Vre) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Change(nl.knaw.huygens.timbuctoo.model.Change) UUID(java.util.UUID) Test(org.junit.Test)

Example 18 with Change

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());
}
Also used : DataStoreOperations(nl.knaw.huygens.timbuctoo.core.DataStoreOperations) UpdateEntity(nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Change(nl.knaw.huygens.timbuctoo.model.Change) UUID(java.util.UUID) Test(org.junit.Test)

Example 19 with Change

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;
}
Also used : Change(nl.knaw.huygens.timbuctoo.model.Change)

Example 20 with 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));
}
Also used : Change(nl.knaw.huygens.timbuctoo.model.Change) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

Change (nl.knaw.huygens.timbuctoo.model.Change)52 Collection (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection)40 Test (org.junit.Test)40 UUID (java.util.UUID)39 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)34 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)33 IOException (java.io.IOException)33 TimProperty (nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty)31 UpdateEntity (nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity)30 Instant (java.time.Instant)29 List (java.util.List)29 ReadEntity (nl.knaw.huygens.timbuctoo.core.dto.ReadEntity)29 Vres (nl.knaw.huygens.timbuctoo.model.vre.Vres)29 Lists (com.google.common.collect.Lists)28 URI (java.net.URI)28 Optional (java.util.Optional)28 Collectors.toList (java.util.stream.Collectors.toList)28 CreateCollection (nl.knaw.huygens.timbuctoo.core.dto.CreateCollection)28 CreateEntity (nl.knaw.huygens.timbuctoo.core.dto.CreateEntity)28 ArrayList (java.util.ArrayList)27