use of io.crnk.core.engine.document.ResourceIdentifier in project crnk-framework by crnk-project.
the class IncludeLookupSetterBaseTest method paginationMustHappenRootAndInclusions.
@Test
public void paginationMustHappenRootAndInclusions() {
Mockito.when(propertiesProvider.getProperty(Mockito.eq(CrnkProperties.INCLUDE_PAGING_ENABLED))).thenReturn("true");
setup();
HierarchicalTask hDetached = new HierarchicalTask();
hDetached.setId(1L);
hDetached.setName("");
QuerySpec querySpec = new QuerySpec(HierarchicalTask.class);
querySpec.setOffset(0L);
querySpec.setLimit(1L);
querySpec.includeRelation(Arrays.asList("children"));
Document document = mapper.toDocument(toResponse(hDetached), toAdapter(querySpec));
Relationship childrenRelationship = document.getSingleData().get().getRelationships().get("children");
List<ResourceIdentifier> childIds = childrenRelationship.getCollectionData().get();
Assert.assertEquals(1, childIds.size());
}
use of io.crnk.core.engine.document.ResourceIdentifier in project crnk-framework by crnk-project.
the class LookupAlwaysRelationIdLookupTest method check.
private void check(boolean setRelatedEntity, boolean setRelatedId) {
RelationIdTestResource entity = new RelationIdTestResource();
entity.setId(2L);
entity.setName("test");
if (setRelatedId) {
entity.setTestLookupAlwaysId(3L);
}
if (setRelatedEntity) {
entity.setTestLookupAlways(schedule);
}
QuerySpec querySpec = new QuerySpec(RelationIdTestResource.class);
querySpec.includeRelation(Arrays.asList("testLookupAlways"));
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("testLookupAlways").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(1, scheduleRepository.getNumFindAll());
} else {
Assert.assertNull(data.get());
Assert.assertEquals(0, scheduleRepository.getNumFindAll());
}
}
use of io.crnk.core.engine.document.ResourceIdentifier in project crnk-framework by crnk-project.
the class LookupNotNullRelationIdLookupTest method check.
private void check(boolean setRelatedEntity, boolean setRelatedId) {
RelationIdTestResource entity = new RelationIdTestResource();
entity.setId(2L);
entity.setName("test");
if (setRelatedId) {
entity.setTestLookupWhenNullId(3L);
}
if (setRelatedEntity) {
entity.setTestLookupWhenNull(schedule);
}
QuerySpec querySpec = new QuerySpec(RelationIdTestResource.class);
querySpec.includeRelation(Arrays.asList("testLookupWhenNull"));
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("testLookupWhenNull").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());
if (setRelatedEntity) {
Assert.assertEquals(0, scheduleRepository.getNumFindAll());
} else {
Assert.assertEquals(1, scheduleRepository.getNumFindAll());
}
} else {
Assert.assertNull(data.get());
}
}
use of io.crnk.core.engine.document.ResourceIdentifier in project crnk-framework by crnk-project.
the class InconsistentRelationshipTest 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());
}
}
use of io.crnk.core.engine.document.ResourceIdentifier in project crnk-framework by crnk-project.
the class ResourceInformationTest method toResourceIdentifier.
@Test
public void toResourceIdentifier() {
Resource resource = new Resource();
resource.setId("13");
resource.setType("tasks");
Task task = new Task();
task.setId(13L);
ResourceIdentifier expected = new ResourceIdentifier("13", "tasks");
Assert.assertSame(expected, sut.toResourceIdentifier(expected));
Assert.assertNull(sut.toResourceIdentifier(null));
Assert.assertEquals(expected, sut.toResourceIdentifier("13"));
Assert.assertEquals(expected, sut.toResourceIdentifier(13L));
Assert.assertEquals(expected, sut.toResourceIdentifier(task));
Assert.assertEquals(expected, sut.toResourceIdentifier(resource));
Assert.assertNotSame(resource, sut.toResourceIdentifier(resource));
}
Aggregations