Search in sources :

Example 1 with HierarchicalTask

use of io.crnk.core.mock.models.HierarchicalTask in project crnk-framework by crnk-project.

the class AbstractIncludeBehaviorTest method setup.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Before
public void setup() {
    super.setup();
    ResourceRepositoryAdapter hierarchicalTaskRepository = resourceRegistry.findEntry(HierarchicalTask.class).getResourceRepository(null);
    h = new HierarchicalTask();
    h.setId(1L);
    h.setName("");
    h0 = new HierarchicalTask();
    h0.setId(2L);
    h0.setName("0");
    h0.setParent(h);
    h1 = new HierarchicalTask();
    h1.setId(3L);
    h1.setName("1");
    h1.setParent(h);
    h11 = new HierarchicalTask();
    h11.setId(4L);
    h11.setName("11");
    h11.setParent(h1);
    h.setChildren(Arrays.asList(h0, h1));
    h0.setChildren(new ArrayList<HierarchicalTask>());
    h1.setChildren(Arrays.asList(h11));
    h11.setChildren(new ArrayList<HierarchicalTask>());
    QueryAdapter emptyQueryAdapter = new QuerySpecAdapter(new QuerySpec(HierarchicalTask.class), resourceRegistry);
    hierarchicalTaskRepository.create(h, emptyQueryAdapter);
    hierarchicalTaskRepository.create(h0, emptyQueryAdapter);
    hierarchicalTaskRepository.create(h1, emptyQueryAdapter);
    hierarchicalTaskRepository.create(h11, emptyQueryAdapter);
}
Also used : HierarchicalTask(io.crnk.core.mock.models.HierarchicalTask) ResourceRepositoryAdapter(io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter) QueryAdapter(io.crnk.core.engine.query.QueryAdapter) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) QuerySpec(io.crnk.core.queryspec.QuerySpec) Before(org.junit.Before)

Example 2 with HierarchicalTask

use of io.crnk.core.mock.models.HierarchicalTask in project crnk-framework by crnk-project.

the class IncludeLookupSetterBaseTest method paginationMustHappenRootAndInclusions.

@Test
public void paginationMustHappenRootAndInclusions() {
    Mockito.when(propertiesProvider.getProperty(Mockito.eq(CrnkProperties.INCLUDE_PAGING_ENABLED))).thenReturn("true");
    setup();
    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(1, childIds.size());
}
Also used : ResourceIdentifier(io.crnk.core.engine.document.ResourceIdentifier) HierarchicalTask(io.crnk.core.mock.models.HierarchicalTask) Relationship(io.crnk.core.engine.document.Relationship) 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 3 with HierarchicalTask

use of io.crnk.core.mock.models.HierarchicalTask in project crnk-framework by crnk-project.

the class IncludeLookupSetterBaseTest method setup.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Before
public void setup() {
    super.setup();
    // get repositories
    ResourceRepositoryAdapter taskRepository = resourceRegistry.findEntry(Task.class).getResourceRepository(null);
    RelationshipRepositoryAdapter relRepositoryTaskToProject = resourceRegistry.findEntry(Task.class).getRelationshipRepository("projects", null);
    RelationshipRepositoryAdapter relRepositoryProjectToTask = resourceRegistry.findEntry(Project.class).getRelationshipRepository("tasks", null);
    ResourceRepositoryAdapter projectRepository = resourceRegistry.findEntry(Project.class).getResourceRepository(null);
    ResourceRepositoryAdapter hierarchicalTaskRepository = resourceRegistry.findEntry(HierarchicalTask.class).getResourceRepository(null);
    // setup test data
    ResourceInformation taskInfo = resourceRegistry.findEntry(Task.class).getResourceInformation();
    ResourceInformation projectInfo = resourceRegistry.findEntry(Project.class).getResourceInformation();
    ResourceField includedTaskField = projectInfo.findRelationshipFieldByName("includedTask");
    ResourceField includedProjectField = taskInfo.findRelationshipFieldByName("includedProject");
    ResourceField includedProjectsField = taskInfo.findRelationshipFieldByName("includedProjects");
    ResourceField projectField = taskInfo.findRelationshipFieldByName("project");
    QueryAdapter projectQuey = emptyQueryAdapter(Project.class);
    QueryAdapter taskQuery = emptyQueryAdapter(Task.class);
    QueryAdapter hierarchicalTaskQuery = emptyQueryAdapter(HierarchicalTask.class);
    Project project = new Project();
    project.setId(2L);
    projectRepository.create(project, projectQuey);
    Task task = new Task();
    task.setId(1L);
    taskRepository.create(task, taskQuery);
    relRepositoryTaskToProject.setRelation(task, project.getId(), includedProjectField, projectQuey);
    relRepositoryTaskToProject.setRelation(task, project.getId(), projectField, projectQuey);
    relRepositoryTaskToProject.addRelations(task, Collections.singletonList(project.getId()), includedProjectsField, projectQuey);
    // setup deep nested relationship
    Task includedTask = new Task();
    includedTask.setId(3L);
    taskRepository.create(includedTask, taskQuery);
    relRepositoryProjectToTask.setRelation(project, includedTask.getId(), includedTaskField, taskQuery);
    Project deepIncludedProject = new Project();
    deepIncludedProject.setId(2L);
    projectRepository.create(project, projectQuey);
    relRepositoryTaskToProject.setRelation(includedTask, deepIncludedProject.getId(), includedProjectField, projectQuey);
    relRepositoryTaskToProject.addRelations(includedTask, Collections.singletonList(project.getId()), includedProjectsField, projectQuey);
    // setup hierarchy of resources
    h = new HierarchicalTask();
    h.setId(1L);
    h.setName("");
    h0 = new HierarchicalTask();
    h0.setId(2L);
    h0.setName("0");
    h0.setParent(h);
    h1 = new HierarchicalTask();
    h1.setId(3L);
    h1.setName("1");
    h1.setParent(h);
    h11 = new HierarchicalTask();
    h11.setId(4L);
    h11.setName("11");
    h11.setParent(h1);
    h.setChildren(Arrays.asList(h0, h1));
    h0.setChildren(new ArrayList<HierarchicalTask>());
    h1.setChildren(Arrays.asList(h11));
    h11.setChildren(new ArrayList<HierarchicalTask>());
    hierarchicalTaskRepository.create(h, hierarchicalTaskQuery);
    hierarchicalTaskRepository.create(h0, hierarchicalTaskQuery);
    hierarchicalTaskRepository.create(h1, hierarchicalTaskQuery);
    hierarchicalTaskRepository.create(h11, hierarchicalTaskQuery);
}
Also used : Project(io.crnk.core.mock.models.Project) ResourceField(io.crnk.core.engine.information.resource.ResourceField) HierarchicalTask(io.crnk.core.mock.models.HierarchicalTask) Task(io.crnk.core.mock.models.Task) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) HierarchicalTask(io.crnk.core.mock.models.HierarchicalTask) ResourceRepositoryAdapter(io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter) QueryAdapter(io.crnk.core.engine.query.QueryAdapter) RelationshipRepositoryAdapter(io.crnk.core.engine.internal.repository.RelationshipRepositoryAdapter) Before(org.junit.Before)

Example 4 with HierarchicalTask

use of io.crnk.core.mock.models.HierarchicalTask 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());
}
Also used : ResourceIdentifier(io.crnk.core.engine.document.ResourceIdentifier) HierarchicalTask(io.crnk.core.mock.models.HierarchicalTask) Relationship(io.crnk.core.engine.document.Relationship) 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

HierarchicalTask (io.crnk.core.mock.models.HierarchicalTask)4 QuerySpec (io.crnk.core.queryspec.QuerySpec)3 Document (io.crnk.core.engine.document.Document)2 Relationship (io.crnk.core.engine.document.Relationship)2 ResourceIdentifier (io.crnk.core.engine.document.ResourceIdentifier)2 AbstractDocumentMapperTest (io.crnk.core.engine.internal.document.mapper.AbstractDocumentMapperTest)2 ResourceRepositoryAdapter (io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter)2 QueryAdapter (io.crnk.core.engine.query.QueryAdapter)2 Before (org.junit.Before)2 Test (org.junit.Test)2 ResourceField (io.crnk.core.engine.information.resource.ResourceField)1 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)1 RelationshipRepositoryAdapter (io.crnk.core.engine.internal.repository.RelationshipRepositoryAdapter)1 Project (io.crnk.core.mock.models.Project)1 Task (io.crnk.core.mock.models.Task)1 QuerySpecAdapter (io.crnk.core.queryspec.internal.QuerySpecAdapter)1