use of nl.knaw.huygens.timbuctoo.crud.conversion.EntityToJsonMapper in project timbuctoo by HuygensING.
the class EntityToJsonMapperTest method mapEntityMapsTheTypeAndId.
@Test
public void mapEntityMapsTheTypeAndId() throws Exception {
ReadEntityImpl readEntity = new ReadEntityImpl();
UUID id = UUID.randomUUID();
readEntity.setId(id);
Change change = new Change(Instant.now().toEpochMilli(), USER_ID, 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());
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("_id", jsn(id.toString()), "@type", jsn(type)).toString()).allowingExtraUnexpectedFields());
}
use of nl.knaw.huygens.timbuctoo.crud.conversion.EntityToJsonMapper in project timbuctoo by HuygensING.
the class EntityToJsonMapperTest method setUp.
@Before
public void setUp() throws Exception {
userValidator = mock(UserValidator.class);
when(userValidator.getUserFromUserId(USER_ID)).thenReturn(Optional.of(User.create(USER_NAME, "")));
instance = new EntityToJsonMapper(userValidator, (collection, id1, rev) -> URI.create("www.example.com"));
}
use of nl.knaw.huygens.timbuctoo.crud.conversion.EntityToJsonMapper 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.crud.conversion.EntityToJsonMapper 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