use of io.crnk.core.engine.document.Relationship in project crnk-framework by crnk-project.
the class PerRootPathIncludeBehaviorTest method includeParentParent.
@Test
public void includeParentParent() throws Exception {
QuerySpec querySpec = new QuerySpec(HierarchicalTask.class);
querySpec.includeRelation(Arrays.asList("parent", "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());
}
use of io.crnk.core.engine.document.Relationship in project crnk-framework by crnk-project.
the class IncludeLookupSetterBaseTest method includeManyDeepNestedRelationLookup.
@Test
public void includeManyDeepNestedRelationLookup() throws Exception {
QuerySpec querySpec = new QuerySpec(Task.class);
querySpec.includeRelation(Arrays.asList("includedProjects", "includedTask", "includedProject"));
Task task = new Task();
task.setId(3L);
Document document = mapper.toDocument(toResponse(task), toAdapter(querySpec));
Resource taskResource = document.getSingleData().get();
Relationship manyRelationship = taskResource.getRelationships().get("includedProjects");
assertNotNull(manyRelationship);
List<ResourceIdentifier> relationshipData = manyRelationship.getCollectionData().get();
assertNotNull(relationshipData.get(0).getId());
List<Resource> includes = document.getIncluded();
assertEquals(1, includes.size());
Resource includedResource = includes.get(0);
assertEquals("projects", includedResource.getType());
assertNotNull(includedResource.getRelationships().get("includedTask"));
assertNotNull(includedResource.getRelationships().get("includedTask").getData());
}
use of io.crnk.core.engine.document.Relationship 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.Relationship 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.Relationship 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