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());
}
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());
}
}
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());
}
}
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());
}
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);
}
Aggregations