Search in sources :

Example 41 with Change

use of nl.knaw.huygens.timbuctoo.model.Change in project timbuctoo by HuygensING.

the class EntityToJsonMapperTest method mapEntityDoesNotAddADisplayPropertyWhenTheDisplayNameIsNull.

@Test
public void mapEntityDoesNotAddADisplayPropertyWhenTheDisplayNameIsNull() {
    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());
    readEntity.setRelations(Lists.newArrayList());
    Collection collection = mock(Collection.class);
    when(collection.getEntityTypeName()).thenReturn(type);
    ObjectNode resutlJson = instance.mapEntity(collection, readEntity, true, (readEntity1, resultJson) -> {
    }, (relationRef, resultJson) -> {
    });
    assertThat(resutlJson.has("@displayName"), is(false));
}
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) Test(org.junit.Test)

Example 42 with Change

use of nl.knaw.huygens.timbuctoo.model.Change in project timbuctoo by HuygensING.

the class EntityToJsonMapperTest method mapEntityMapsTheProperties.

@Test
public void mapEntityMapsTheProperties() throws Exception {
    ReadEntityImpl readEntity = new ReadEntityImpl();
    readEntity.setId(UUID.randomUUID());
    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");
    ArrayList<TimProperty<?>> properties = Lists.newArrayList();
    properties.add(new StringProperty("name", "Name"));
    readEntity.setProperties(properties);
    EntityToJsonMapper instance = new EntityToJsonMapper(userValidator, (collection, id1, rev) -> URI.create("www.example.com"));
    Collection collection = mock(Collection.class);
    when(collection.getEntityTypeName()).thenReturn(type);
    ObjectNode resutlJson = instance.mapEntity(collection, readEntity, false, (readEntity1, resultJson) -> {
    }, (relationRef, resultJson) -> {
    });
    assertThat(resutlJson.toString(), sameJSONAs(jsnO("name", jsn("Name")).toString()).allowingExtraUnexpectedFields());
}
Also used : ReadEntityImpl(nl.knaw.huygens.timbuctoo.core.dto.ReadEntityImpl) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) EntityToJsonMapper(nl.knaw.huygens.timbuctoo.crud.conversion.EntityToJsonMapper) TimProperty(nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty) StringProperty(nl.knaw.huygens.timbuctoo.core.dto.property.StringProperty) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Change(nl.knaw.huygens.timbuctoo.model.Change) Test(org.junit.Test)

Example 43 with Change

use of nl.knaw.huygens.timbuctoo.model.Change in project timbuctoo by HuygensING.

the class EntityToJsonMapperTest method doesNotAddNonConvertableProperties.

@Test
public void doesNotAddNonConvertableProperties() {
    ReadEntityImpl readEntity = new ReadEntityImpl();
    readEntity.setId(UUID.randomUUID());
    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");
    ArrayList<TimProperty<?>> properties = Lists.newArrayList();
    properties.add(new HyperLinksProperty("nonParsableProp", "Name"));
    readEntity.setProperties(properties);
    EntityToJsonMapper instance = new EntityToJsonMapper(userValidator, (collection, id1, rev) -> URI.create("www.example.com"));
    Collection collection = mock(Collection.class);
    when(collection.getEntityTypeName()).thenReturn(type);
    ObjectNode resutlJson = instance.mapEntity(collection, readEntity, false, (readEntity1, resultJson) -> {
    }, (relationRef, resultJson) -> {
    });
    assertThat(Lists.newArrayList(resutlJson.fieldNames()), not(hasItem("nonParsableProp")));
}
Also used : ReadEntityImpl(nl.knaw.huygens.timbuctoo.core.dto.ReadEntityImpl) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HyperLinksProperty(nl.knaw.huygens.timbuctoo.core.dto.property.HyperLinksProperty) EntityToJsonMapper(nl.knaw.huygens.timbuctoo.crud.conversion.EntityToJsonMapper) TimProperty(nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Change(nl.knaw.huygens.timbuctoo.model.Change) Test(org.junit.Test)

Example 44 with Change

use of nl.knaw.huygens.timbuctoo.model.Change in project timbuctoo by HuygensING.

the class TimbuctooActionsCreateTest method createEntityLetsDataAccessSaveTheEntity.

@Test
public void createEntityLetsDataAccessSaveTheEntity() throws Exception {
    TimbuctooActions instance = createInstance(true);
    UUID id = instance.createEntity(collection, baseCollection, newArrayList(), userWithId(userId));
    verify(dataStoreOperations).createEntity(collection, baseCollection, ImmutableCreateEntity.builder().properties(newArrayList()).id(id).created(new Change(instant.toEpochMilli(), userId, null)).build());
}
Also used : Change(nl.knaw.huygens.timbuctoo.model.Change) UUID(java.util.UUID) Test(org.junit.Test)

Example 45 with Change

use of nl.knaw.huygens.timbuctoo.model.Change in project timbuctoo by HuygensING.

the class TimbuctooActionsDeleteTest method setUp.

@Before
public void setUp() throws Exception {
    clock = mock(Clock.class);
    instant = Instant.now();
    when(clock.instant()).thenReturn(instant);
    persistentUrlCreator = mock(PersistentUrlCreator.class);
    collection = mock(Collection.class);
    when(collection.getCollectionName()).thenReturn(COLLECTION_NAME);
    change = new Change();
    change.setUserId(USER_ID);
    change.setTimeStamp(instant.toEpochMilli());
    dataStoreOperations = mock(DataStoreOperations.class);
    afterSuccessTaskExecutor = mock(AfterSuccessTaskExecutor.class);
}
Also used : Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Change(nl.knaw.huygens.timbuctoo.model.Change) Clock(java.time.Clock) Before(org.junit.Before)

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