Search in sources :

Example 56 with Resource

use of io.crnk.core.engine.document.Resource in project crnk-framework by crnk-project.

the class IncludeLookupSetterBaseTest method includeOneDeepNestedRelationLookup.

@Test
public void includeOneDeepNestedRelationLookup() throws Exception {
    QuerySpec querySpec = new QuerySpec(Task.class);
    querySpec.includeRelation(Arrays.asList("includedProject", "includedTask", "includedProject"));
    Task task = new Task();
    task.setId(3L);
    Document document = mapper.toDocument(toResponse(task), toAdapter(querySpec));
    Resource taskResource = document.getSingleData().get();
    Relationship oneRelationship = taskResource.getRelationships().get("includedProject");
    assertNotNull(oneRelationship);
    assertNotNull(oneRelationship.getSingleData());
    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());
}
Also used : HierarchicalTask(io.crnk.core.mock.models.HierarchicalTask) Task(io.crnk.core.mock.models.Task) 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) AbstractDocumentMapperTest(io.crnk.core.engine.internal.document.mapper.AbstractDocumentMapperTest) Test(org.junit.Test)

Example 57 with Resource

use of io.crnk.core.engine.document.Resource 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)

Example 58 with Resource

use of io.crnk.core.engine.document.Resource 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());
}
Also used : HierarchicalTask(io.crnk.core.mock.models.HierarchicalTask) Task(io.crnk.core.mock.models.Task) 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) AbstractDocumentMapperTest(io.crnk.core.engine.internal.document.mapper.AbstractDocumentMapperTest) Test(org.junit.Test)

Example 59 with Resource

use of io.crnk.core.engine.document.Resource 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");
}
Also used : PropertiesProvider(io.crnk.core.engine.properties.PropertiesProvider) EmptyPropertiesProvider(io.crnk.core.engine.properties.EmptyPropertiesProvider) 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) AbstractDocumentMapperTest(io.crnk.core.engine.internal.document.mapper.AbstractDocumentMapperTest) Test(org.junit.Test)

Example 60 with Resource

use of io.crnk.core.engine.document.Resource 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());
}
Also used : HierarchicalTask(io.crnk.core.mock.models.HierarchicalTask) Task(io.crnk.core.mock.models.Task) 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) AbstractDocumentMapperTest(io.crnk.core.engine.internal.document.mapper.AbstractDocumentMapperTest) Test(org.junit.Test)

Aggregations

Resource (io.crnk.core.engine.document.Resource)130 Document (io.crnk.core.engine.document.Document)86 Test (org.junit.Test)85 Relationship (io.crnk.core.engine.document.Relationship)48 Response (io.crnk.core.engine.dispatcher.Response)43 QuerySpec (io.crnk.core.queryspec.QuerySpec)43 ResourceIdentifier (io.crnk.core.engine.document.ResourceIdentifier)42 JsonPath (io.crnk.core.engine.internal.dispatcher.path.JsonPath)41 BaseControllerTest (io.crnk.core.engine.internal.dispatcher.controller.BaseControllerTest)37 Task (io.crnk.core.mock.models.Task)32 ResourcePost (io.crnk.core.engine.internal.dispatcher.controller.ResourcePost)31 Project (io.crnk.core.mock.models.Project)24 JsonApiResponse (io.crnk.core.repository.response.JsonApiResponse)17 LazyTask (io.crnk.core.mock.models.LazyTask)15 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)14 ResourcePatch (io.crnk.core.engine.internal.dispatcher.controller.ResourcePatch)14 RelationIdTestResource (io.crnk.core.mock.models.RelationIdTestResource)13 ResourceField (io.crnk.core.engine.information.resource.ResourceField)12 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)11 ResourceRepositoryAdapter (io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter)10