use of nl.knaw.huygens.timbuctoo.core.dto.ReadEntityImpl 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());
}
use of nl.knaw.huygens.timbuctoo.core.dto.ReadEntityImpl 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")));
}
Aggregations