use of io.crnk.core.engine.document.ResourceIdentifier in project crnk-framework by crnk-project.
the class IncludeLookupSetterBaseTest method paginationMustOnlyHappenRootButNotInclusions.
@Test
public void paginationMustOnlyHappenRootButNotInclusions() {
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(2, childIds.size());
}
use of io.crnk.core.engine.document.ResourceIdentifier 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.engine.document.ResourceIdentifier in project crnk-framework by crnk-project.
the class ResourceFieldContributorTest method checkInclusionUponRequest.
@Test
public void checkInclusionUponRequest() {
TaskRepository repo = new TaskRepository();
Task task = new Task();
task.setId(1L);
task.setName("someTask");
repo.save(task);
HttpRequestProcessorImpl requestDispatcher = boot.getRequestDispatcher();
HttpRequestContextProvider httpRequestContextProvider = boot.getModuleRegistry().getHttpRequestContextProvider();
HttpRequestContext request = Mockito.mock(HttpRequestContext.class);
httpRequestContextProvider.onRequestStarted(request);
Map<String, Set<String>> parameters = new HashMap<>();
parameters.put("include", Sets.newHashSet("contributedProject"));
Response response = requestDispatcher.dispatchRequest("tasks", "GET", parameters, null, null);
Document document = response.getDocument();
Resource resource = document.getCollectionData().get().get(0);
Assert.assertEquals("1", resource.getId());
Assert.assertEquals("tasks", resource.getType());
Assert.assertEquals("someTask", resource.getAttributes().get("name").asText());
Relationship relationship = resource.getRelationships().get("contributedProject");
Assert.assertNotNull(relationship);
ResourceIdentifier relationshipId = relationship.getSingleData().get();
Assert.assertEquals("projects", relationshipId.getType());
Assert.assertEquals("11", relationshipId.getId());
List<Resource> included = document.getIncluded();
Assert.assertEquals(1, included.size());
Resource includedResource = included.get(0);
Assert.assertEquals("projects", includedResource.getType());
Assert.assertEquals("11", includedResource.getId());
Assert.assertEquals("someProject", includedResource.getAttributes().get("name").asText());
}
use of io.crnk.core.engine.document.ResourceIdentifier in project crnk-framework by crnk-project.
the class DocumentMapperUtilTest method toResourceIds.
@Test
public void toResourceIds() {
Task task = new Task();
task.setId(12L);
List<ResourceIdentifier> ids = util.toResourceIds(Arrays.asList(task));
ResourceIdentifier id = ids.get(0);
Assert.assertEquals("tasks", id.getType());
Assert.assertEquals("12", id.getId());
}
use of io.crnk.core.engine.document.ResourceIdentifier in project crnk-framework by crnk-project.
the class PerTypeIncludeBehaviorTest method includeParent.
@Test
public void includeParent() throws Exception {
QuerySpec querySpec = new QuerySpec(HierarchicalTask.class);
querySpec.includeRelation(Arrays.asList("parent"));
Document document = mapper.toDocument(toResponse(h11), toAdapter(querySpec));
Resource taskResource = document.getSingleData().get();
Relationship parentRelationship = taskResource.getRelationships().get("parent");
assertNotNull(parentRelationship);
assertNotNull(parentRelationship.getSingleData());
ResourceIdentifier parentResource = parentRelationship.getSingleData().get();
assertNotNull(h1.getId().toString(), parentResource.getId());
List<Resource> included = document.getIncluded();
assertEquals(2, included.size());
assertNotNull(h1.getId().toString(), included.get(0).getId());
assertNotNull(h.getId().toString(), included.get(1).getId());
}
Aggregations