Search in sources :

Example 1 with EmptyPropertiesProvider

use of io.crnk.core.engine.properties.EmptyPropertiesProvider in project crnk-framework by crnk-project.

the class IncludeLookupSetterBaseTest method includeByDefaultSerializeNLevels.

@Test
public void includeByDefaultSerializeNLevels() throws Exception {
    Project project = new Project();
    project.setId(1L);
    Task task = new Task().setId(2L);
    project.setTask(task);
    Project projectDefault = new Project().setId(3L);
    task.setProject(projectDefault);
    mapper = new DocumentMapper(resourceRegistry, objectMapper, new EmptyPropertiesProvider(), resourceFilterDirectory);
    QuerySpec querySpec = new QuerySpec(Project.class);
    querySpec.includeRelation(Collections.singletonList("task"));
    Document document = mapper.toDocument(toResponse(project), toAdapter(querySpec));
    Resource projectResource = document.getSingleData().get();
    Relationship relationship = projectResource.getRelationships().get("task");
    assertNotNull(relationship);
    assertEquals("2", relationship.getSingleData().get().getId());
    assertNotNull(document.getIncluded());
    assertEquals(2, document.getIncluded().size());
    List<Resource> resources = document.getIncluded();
    assertEquals("projects", resources.get(0).getType());
    assertEquals("3", resources.get(0).getId());
    assertEquals("tasks", resources.get(1).getType());
    assertEquals("2", resources.get(1).getId());
}
Also used : Project(io.crnk.core.mock.models.Project) HierarchicalTask(io.crnk.core.mock.models.HierarchicalTask) Task(io.crnk.core.mock.models.Task) DocumentMapper(io.crnk.core.engine.internal.document.mapper.DocumentMapper) Relationship(io.crnk.core.engine.document.Relationship) Resource(io.crnk.core.engine.document.Resource) QuerySpec(io.crnk.core.queryspec.QuerySpec) Document(io.crnk.core.engine.document.Document) EmptyPropertiesProvider(io.crnk.core.engine.properties.EmptyPropertiesProvider) AbstractDocumentMapperTest(io.crnk.core.engine.internal.document.mapper.AbstractDocumentMapperTest) Test(org.junit.Test)

Aggregations

Document (io.crnk.core.engine.document.Document)1 Relationship (io.crnk.core.engine.document.Relationship)1 Resource (io.crnk.core.engine.document.Resource)1 AbstractDocumentMapperTest (io.crnk.core.engine.internal.document.mapper.AbstractDocumentMapperTest)1 DocumentMapper (io.crnk.core.engine.internal.document.mapper.DocumentMapper)1 EmptyPropertiesProvider (io.crnk.core.engine.properties.EmptyPropertiesProvider)1 HierarchicalTask (io.crnk.core.mock.models.HierarchicalTask)1 Project (io.crnk.core.mock.models.Project)1 Task (io.crnk.core.mock.models.Task)1 QuerySpec (io.crnk.core.queryspec.QuerySpec)1 Test (org.junit.Test)1