Search in sources :

Example 11 with SortSpec

use of io.crnk.core.queryspec.SortSpec in project crnk-framework by crnk-project.

the class TaskResourceRepositoryTest method checkPaging.

@Test
public void checkPaging() {
    addTask("otherTask1", 14);
    addTask("otherTask2", 15);
    addTask("otherTask3", 16);
    QuerySpec querySpec = new QuerySpec(ApproveTask.class);
    querySpec.addSort(new SortSpec(Arrays.asList("priority"), Direction.ASC));
    querySpec.setOffset(1);
    querySpec.setLimit(2L);
    ResourceList<ApproveTask> resources = taskRepository.findAll(querySpec);
    Assert.assertEquals(2, resources.size());
    Assert.assertEquals("otherTask1", resources.get(0).getName());
    Assert.assertEquals("otherTask2", resources.get(1).getName());
}
Also used : QuerySpec(io.crnk.core.queryspec.QuerySpec) ApproveTask(io.crnk.activiti.example.model.ApproveTask) SortSpec(io.crnk.core.queryspec.SortSpec) Test(org.junit.Test)

Example 12 with SortSpec

use of io.crnk.core.queryspec.SortSpec in project crnk-framework by crnk-project.

the class QuerySpecClientTest method testSortDesc.

@Test
public void testSortDesc() {
    for (int i = 0; i < 5; i++) {
        Task task = new Task();
        task.setId(Long.valueOf(i));
        task.setName("task" + i);
        taskRepo.create(task);
    }
    QuerySpec querySpec = new QuerySpec(Task.class);
    querySpec.addSort(new SortSpec(Arrays.asList("name"), Direction.DESC));
    List<Task> tasks = taskRepo.findAll(querySpec);
    Assert.assertEquals(5, tasks.size());
    for (int i = 0; i < 5; i++) {
        Assert.assertEquals("task" + i, tasks.get(4 - i).getName());
    }
}
Also used : Task(io.crnk.test.mock.models.Task) QuerySpec(io.crnk.core.queryspec.QuerySpec) SortSpec(io.crnk.core.queryspec.SortSpec) Test(org.junit.Test)

Example 13 with SortSpec

use of io.crnk.core.queryspec.SortSpec in project crnk-framework by crnk-project.

the class QuerySpecClientTest method testSortAsc.

@Test
public void testSortAsc() {
    for (int i = 0; i < 5; i++) {
        Task task = new Task();
        task.setId(Long.valueOf(i));
        task.setName("task" + i);
        taskRepo.create(task);
    }
    QuerySpec querySpec = new QuerySpec(Task.class);
    querySpec.addSort(new SortSpec(Arrays.asList("name"), Direction.ASC));
    List<Task> tasks = taskRepo.findAll(querySpec);
    Assert.assertEquals(5, tasks.size());
    for (int i = 0; i < 5; i++) {
        Assert.assertEquals("task" + i, tasks.get(i).getName());
    }
}
Also used : Task(io.crnk.test.mock.models.Task) QuerySpec(io.crnk.core.queryspec.QuerySpec) SortSpec(io.crnk.core.queryspec.SortSpec) Test(org.junit.Test)

Example 14 with SortSpec

use of io.crnk.core.queryspec.SortSpec in project crnk-framework by crnk-project.

the class InheritanceClientTest method testFindAll.

@Test
public void testFindAll() {
    QuerySpec querySpec = new QuerySpec(Task.class);
    querySpec.addSort(new SortSpec(Arrays.asList("name"), Direction.ASC));
    List<Task> tasks = taskRepo.findAll(querySpec);
    Assert.assertEquals(2, tasks.size());
    Assert.assertEquals("baseTask", tasks.get(0).getName());
    Assert.assertEquals("taskSubType", tasks.get(1).getName());
}
Also used : Task(io.crnk.test.mock.models.Task) QuerySpec(io.crnk.core.queryspec.QuerySpec) SortSpec(io.crnk.core.queryspec.SortSpec) Test(org.junit.Test)

Example 15 with SortSpec

use of io.crnk.core.queryspec.SortSpec in project crnk-framework by crnk-project.

the class MetaDefaultLimitIntTest method limitShouldNotAffectRelationshipsWithSpecOnRelationship.

@Test
public void limitShouldNotAffectRelationshipsWithSpecOnRelationship() {
    QuerySpec querySpec = new QuerySpec(MetaResource.class);
    querySpec.includeRelation(Arrays.asList("attributes"));
    querySpec.addFilter(new FilterSpec(Arrays.asList("resourceType"), FilterOperator.EQ, "tasks"));
    querySpec.getOrCreateQuerySpec(MetaAttribute.class).addSort(new SortSpec(Arrays.asList("id"), Direction.ASC));
    querySpec.getOrCreateQuerySpec(MetaElement.class).addSort(new SortSpec(Arrays.asList("id"), Direction.ASC));
    querySpec.getOrCreateQuerySpec(MetaResourceField.class).addSort(new SortSpec(Arrays.asList("id"), Direction.ASC));
    ResourceList<MetaResource> list = repository.findAll(querySpec);
    Assert.assertEquals(1, list.size());
    MetaResource taskMeta = list.get(0);
    List<? extends MetaAttribute> attributes = taskMeta.getAttributes();
    Assert.assertTrue(attributes.size() > 5);
}
Also used : MetaResourceField(io.crnk.meta.model.resource.MetaResourceField) MetaElement(io.crnk.meta.model.MetaElement) MetaResource(io.crnk.meta.model.resource.MetaResource) MetaAttribute(io.crnk.meta.model.MetaAttribute) QuerySpec(io.crnk.core.queryspec.QuerySpec) FilterSpec(io.crnk.core.queryspec.FilterSpec) SortSpec(io.crnk.core.queryspec.SortSpec) Test(org.junit.Test)

Aggregations

SortSpec (io.crnk.core.queryspec.SortSpec)15 QuerySpec (io.crnk.core.queryspec.QuerySpec)13 Test (org.junit.Test)13 HashMap (java.util.HashMap)6 AbstractQuerySpecTest (io.crnk.core.queryspec.AbstractQuerySpecTest)5 HashSet (java.util.HashSet)5 Set (java.util.Set)5 ApproveTask (io.crnk.activiti.example.model.ApproveTask)4 Task (io.crnk.test.mock.models.Task)3 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)1 TaskWithLookup (io.crnk.core.mock.models.TaskWithLookup)1 FilterSpec (io.crnk.core.queryspec.FilterSpec)1 SortingParams (io.crnk.legacy.queryParams.params.SortingParams)1 MetaAttribute (io.crnk.meta.model.MetaAttribute)1 MetaElement (io.crnk.meta.model.MetaElement)1 MetaResource (io.crnk.meta.model.resource.MetaResource)1 MetaResourceField (io.crnk.meta.model.resource.MetaResourceField)1 Method (java.lang.reflect.Method)1 LinkedHashMap (java.util.LinkedHashMap)1