use of io.crnk.core.mock.models.RelationIdTestResource in project crnk-framework by crnk-project.
the class SerializeOnlyIdRelationIdLookupTest method check.
private void check(boolean setRelatedEntity, boolean setRelatedId) {
RelationIdTestResource entity = new RelationIdTestResource();
entity.setId(2L);
entity.setName("test");
if (setRelatedId) {
entity.setTestSerializeOnlyIdId(3L);
}
if (setRelatedEntity) {
entity.setTestSerializeOnlyId(schedule);
}
QuerySpec querySpec = new QuerySpec(RelationIdTestResource.class);
Document document = mapper.toDocument(toResponse(entity), toAdapter(querySpec));
Resource resource = document.getSingleData().get();
Assert.assertEquals("2", resource.getId());
Assert.assertEquals("relationIdTest", resource.getType());
Assert.assertEquals("test", resource.getAttributes().get("name").asText());
Nullable<ResourceIdentifier> data = resource.getRelationships().get("testSerializeOnlyId").getSingleData();
Assert.assertTrue(data.isPresent());
Assert.assertEquals(0, scheduleRepository.getNumFindAll());
Assert.assertEquals(0, document.getIncluded().size());
if (setRelatedEntity || setRelatedId) {
Assert.assertNotNull(data.get());
} else {
Assert.assertNull(data.get());
}
}
Aggregations