use of io.crnk.core.engine.document.Document in project crnk-framework by crnk-project.
the class IncludeLookupSetterBaseTest method includeManyRelationLookup.
@Test
public void includeManyRelationLookup() throws Exception {
QuerySpec querySpec = new QuerySpec(Task.class);
querySpec.includeRelation(Arrays.asList("includedProjects"));
Task task = new Task();
task.setId(1L);
Document document = mapper.toDocument(toResponse(task), toAdapter(querySpec));
Resource taskResource = document.getSingleData().get();
Relationship relationship = taskResource.getRelationships().get("includedProjects");
assertNotNull(relationship);
assertEquals(1, relationship.getCollectionData().get().size());
}
use of io.crnk.core.engine.document.Document in project crnk-framework by crnk-project.
the class IncludeLookupSetterBaseTest method includePropertiesProviderNonOverwriteRelationshipLookup.
@Test
public void includePropertiesProviderNonOverwriteRelationshipLookup() throws Exception {
PropertiesProvider propertiesProvider = new PropertiesProvider() {
@Override
public String getProperty(String key) {
if (key.equalsIgnoreCase(CrnkProperties.INCLUDE_AUTOMATICALLY_OVERWRITE)) {
return "false";
}
return null;
}
};
mapper = new DocumentMapper(resourceRegistry, objectMapper, propertiesProvider, resourceFilterDirectory);
QuerySpec querySpec = new QuerySpec(Task.class);
querySpec.includeRelation(Arrays.asList("project"));
Project project = new Project();
project.setId(12L);
Task task = new Task();
task.setId(1L);
task.setProject(project);
Document document = mapper.toDocument(toResponse(task), toAdapter(querySpec));
Resource taskResource = document.getSingleData().get();
Relationship relationship = taskResource.getRelationships().get("project");
assertNotNull(relationship);
assertEquals(relationship.getSingleData().get().getId(), "12");
}
use of io.crnk.core.engine.document.Document in project crnk-framework by crnk-project.
the class IncludeLookupSetterBaseTest method includeOneRelationLookup.
@Test
public void includeOneRelationLookup() throws Exception {
QuerySpec querySpec = new QuerySpec(Task.class);
querySpec.includeRelation(Arrays.asList("includedProject"));
Task task = new Task();
task.setId(1L);
Document document = mapper.toDocument(toResponse(task), toAdapter(querySpec));
Resource taskResource = document.getSingleData().get();
Relationship relationship = taskResource.getRelationships().get("includedProject");
assertNotNull(relationship);
assertNotNull(relationship.getSingleData());
List<Resource> included = document.getIncluded();
assertEquals(1, included.size());
}
use of io.crnk.core.engine.document.Document 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.Document 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());
}
}
Aggregations