use of io.crnk.core.mock.models.RelationIdTestResource in project crnk-framework by crnk-project.
the class NestedRelationIdLookupTest method check.
private void check(boolean setRelatedEntity, boolean setRelatedId) {
RelationIdTestResource entity = new RelationIdTestResource();
entity.setId(2L);
entity.setName("test");
if (setRelatedId) {
entity.setTestNestedId(child.getId());
}
if (setRelatedEntity) {
entity.setTestNested(child);
}
QuerySpec querySpec = new QuerySpec(RelationIdTestResource.class);
querySpec.includeRelation(Arrays.asList("testNested", "schedule"));
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("testNested").getSingleData();
Assert.assertTrue(data.isPresent());
if (setRelatedId) {
Assert.assertNotNull(data.get());
Assert.assertEquals(2, document.getIncluded().size());
} else {
Assert.assertNull(data.get());
}
}
use of io.crnk.core.mock.models.RelationIdTestResource in project crnk-framework by crnk-project.
the class SerializeEagerRelationIdLookupTest method check.
private void check(boolean setRelatedEntity, boolean setRelatedId) {
RelationIdTestResource entity = new RelationIdTestResource();
entity.setId(2L);
entity.setName("test");
if (setRelatedId) {
entity.setTestSerializeEagerId(3L);
}
if (setRelatedEntity) {
entity.setTestSerializeEager(schedule);
}
QuerySpec querySpec = new QuerySpec(RelationIdTestResource.class);
// since eager no inclusion necessary
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("testSerializeEager").getSingleData();
Assert.assertTrue(data.isPresent());
if (setRelatedId) {
Assert.assertNotNull(data.get());
Assert.assertEquals(1, document.getIncluded().size());
Assert.assertEquals("3", document.getIncluded().get(0).getId());
Assert.assertEquals(setRelatedEntity ? 0 : 1, scheduleRepository.getNumFindAll());
} else {
Assert.assertNull(data.get());
Assert.assertEquals(0, scheduleRepository.getNumFindAll());
}
}
use of io.crnk.core.mock.models.RelationIdTestResource in project crnk-framework by crnk-project.
the class LookupNoneRelationIdLookupTest method check.
private void check(boolean setRelatedEntity, boolean setRelatedId) {
RelationIdTestResource entity = new RelationIdTestResource();
entity.setId(2L);
entity.setName("test");
if (setRelatedId) {
entity.setTestLookupNoneId(3L);
}
if (setRelatedEntity) {
entity.setTestLookupNone(schedule);
}
QuerySpec querySpec = new QuerySpec(RelationIdTestResource.class);
querySpec.includeRelation(Arrays.asList("testLookupNone"));
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("testLookupNone").getSingleData();
Assert.assertTrue(data.isPresent());
Assert.assertEquals(0, scheduleRepository.getNumFindAll());
if (setRelatedEntity) {
Assert.assertNotNull(data.get());
Assert.assertEquals(1, document.getIncluded().size());
Assert.assertEquals("3", document.getIncluded().get(0).getId());
} else if (setRelatedId) {
Assert.fail("without lookup related entity should be set if related id is set");
} else {
Assert.assertNull(data.get());
}
}
use of io.crnk.core.mock.models.RelationIdTestResource in project crnk-framework by crnk-project.
the class MultiValuedRelationIdLookupTest method check.
private void check(boolean setRelatedEntity, boolean setRelatedId) {
RelationIdTestResource entity = new RelationIdTestResource();
entity.setId(2L);
entity.setName("test");
if (setRelatedId) {
entity.setTestMultipleValueIds(Arrays.asList(3L, 4L));
} else {
entity.setTestMultipleValueIds(null);
}
if (setRelatedEntity) {
entity.setTestMultipleValues(Arrays.asList(schedule3, schedule4));
}
QuerySpec querySpec = new QuerySpec(RelationIdTestResource.class);
querySpec.includeRelation(Arrays.asList("testMultipleValues"));
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("testMultipleValues").getSingleData();
Assert.assertTrue(data.isPresent());
if (setRelatedId) {
Assert.assertNotNull(data.get());
Assert.assertEquals(2, document.getIncluded().size());
Assert.assertEquals("3", document.getIncluded().get(0).getId());
Assert.assertEquals("4", document.getIncluded().get(1).getId());
if (setRelatedEntity) {
Assert.assertEquals(0, scheduleRepository.getNumFindAll());
} else {
Assert.assertEquals(1, scheduleRepository.getNumFindAll());
}
} else {
Assert.assertNull(data.get());
}
}
use of io.crnk.core.mock.models.RelationIdTestResource in project crnk-framework by crnk-project.
the class ResourceIdBasedRelationIdLookupTest method check.
private void check(boolean setRelatedEntity, boolean setRelatedId) {
RelationIdTestResource entity = new RelationIdTestResource();
entity.setId(2L);
entity.setName("test");
if (setRelatedId) {
entity.setTestResourceIdRefId(new ResourceIdentifier("3", "schedules"));
}
if (setRelatedEntity) {
entity.setTestResourceIdRef(schedule);
}
QuerySpec querySpec = new QuerySpec(RelationIdTestResource.class);
querySpec.includeRelation(Arrays.asList("testResourceIdRef"));
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("testResourceIdRef").getSingleData();
Assert.assertTrue(data.isPresent());
if (setRelatedId) {
Assert.assertNotNull(data.get());
Assert.assertEquals(1, document.getIncluded().size());
Assert.assertEquals("3", document.getIncluded().get(0).getId());
Assert.assertEquals(setRelatedEntity ? 0 : 1, scheduleRepository.getNumFindAll());
} else {
Assert.assertNull(data.get());
Assert.assertEquals(0, scheduleRepository.getNumFindAll());
}
}
Aggregations