Search in sources :

Example 6 with SortSpec

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

the class DefaultQuerySpecDeserializerTestBase method testFindAllOrderByDesc.

@Test
public void testFindAllOrderByDesc() {
    QuerySpec expectedSpec = new QuerySpec(Task.class);
    expectedSpec.addSort(new SortSpec(Arrays.asList("name"), Direction.DESC));
    Map<String, Set<String>> params = new HashMap<>();
    add(params, "sort[tasks]", "-name");
    QuerySpec actualSpec = deserializer.deserialize(taskInformation, params);
    Assert.assertEquals(expectedSpec, actualSpec);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) QuerySpec(io.crnk.core.queryspec.QuerySpec) SortSpec(io.crnk.core.queryspec.SortSpec) AbstractQuerySpecTest(io.crnk.core.queryspec.AbstractQuerySpecTest) Test(org.junit.Test)

Example 7 with SortSpec

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

the class DefaultQuerySpecDeserializerTestBase method testFindAllOrderByAsc.

@Test
public void testFindAllOrderByAsc() {
    QuerySpec expectedSpec = new QuerySpec(Task.class);
    expectedSpec.addSort(new SortSpec(Arrays.asList("name"), Direction.ASC));
    Map<String, Set<String>> params = new HashMap<>();
    add(params, "sort[tasks]", "name");
    QuerySpec actualSpec = deserializer.deserialize(taskInformation, params);
    Assert.assertEquals(expectedSpec, actualSpec);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) QuerySpec(io.crnk.core.queryspec.QuerySpec) SortSpec(io.crnk.core.queryspec.SortSpec) AbstractQuerySpecTest(io.crnk.core.queryspec.AbstractQuerySpecTest) Test(org.junit.Test)

Example 8 with SortSpec

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

the class DefaultQuerySpecDeserializerTestBase method testFollowNestedObjectWithinResource.

@Test
public void testFollowNestedObjectWithinResource() {
    // follow ProjectData.data
    QuerySpec expectedSpec = new QuerySpec(Project.class);
    expectedSpec.addSort(new SortSpec(Arrays.asList("data", "data"), Direction.ASC));
    Map<String, Set<String>> params = new HashMap<>();
    add(params, "sort", "data.data");
    QuerySpec actualSpec = deserializer.deserialize(taskInformation, params);
    Assert.assertEquals(expectedSpec, actualSpec);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) QuerySpec(io.crnk.core.queryspec.QuerySpec) SortSpec(io.crnk.core.queryspec.SortSpec) AbstractQuerySpecTest(io.crnk.core.queryspec.AbstractQuerySpecTest) Test(org.junit.Test)

Example 9 with SortSpec

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

the class DefaultQuerySpecDeserializerTestBase method testOrderByMultipleAttributes.

@Test
public void testOrderByMultipleAttributes() {
    QuerySpec expectedSpec = new QuerySpec(Task.class);
    expectedSpec.addSort(new SortSpec(Arrays.asList("name"), Direction.ASC));
    expectedSpec.addSort(new SortSpec(Arrays.asList("id"), Direction.ASC));
    Map<String, Set<String>> params = new HashMap<>();
    add(params, "sort[tasks]", "name,id");
    QuerySpec actualSpec = deserializer.deserialize(taskInformation, params);
    Assert.assertEquals(expectedSpec, actualSpec);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) QuerySpec(io.crnk.core.queryspec.QuerySpec) SortSpec(io.crnk.core.queryspec.SortSpec) AbstractQuerySpecTest(io.crnk.core.queryspec.AbstractQuerySpecTest) Test(org.junit.Test)

Example 10 with SortSpec

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

the class TaskResourceRepositoryTest method checkIsolation.

@Test
public void checkIsolation() {
    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)

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