Search in sources :

Example 6 with QuerySpec

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

the class TaskResourceRepositoryTest method checkGTDueDate.

@Test
public void checkGTDueDate() {
    QuerySpec querySpec = new QuerySpec(ApproveTask.class);
    querySpec.addFilter(new FilterSpec(Arrays.asList("dueDate"), FilterOperator.GT, OffsetDateTime.now().minusHours(1)));
    Assert.assertEquals(1, taskRepository.findAll(querySpec).size());
    querySpec = new QuerySpec(TaskResource.class);
    querySpec.addFilter(new FilterSpec(Arrays.asList("dueDate"), FilterOperator.GT, OffsetDateTime.now().plusHours(1)));
    Assert.assertEquals(0, taskRepository.findAll(querySpec).size());
}
Also used : TaskResource(io.crnk.activiti.resource.TaskResource) QuerySpec(io.crnk.core.queryspec.QuerySpec) FilterSpec(io.crnk.core.queryspec.FilterSpec) Test(org.junit.Test)

Example 7 with QuerySpec

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

the class TaskResourceRepositoryTest method updateTask.

@Test
public void updateTask() {
    QuerySpec querySpec = new QuerySpec(TaskResource.class);
    OffsetDateTime updatedDueDate = OffsetDateTime.now().plusHours(12);
    ApproveTask resource = taskRepository.findOne(task.getId(), querySpec);
    resource.setName("updatedName");
    resource.setPriority(101);
    resource.setDueDate(updatedDueDate);
    ApproveTask updatedResource = taskRepository.save(resource);
    Assert.assertEquals("updatedName", updatedResource.getName());
    Assert.assertEquals(101, updatedResource.getPriority());
    Assert.assertEquals(updatedDueDate.toInstant(), updatedResource.getDueDate().toInstant());
    updatedResource = taskRepository.findOne(task.getId(), querySpec);
    Assert.assertEquals("updatedName", updatedResource.getName());
    Assert.assertEquals(101, updatedResource.getPriority());
    Assert.assertEquals(updatedDueDate.toInstant(), updatedResource.getDueDate().toInstant());
}
Also used : OffsetDateTime(java.time.OffsetDateTime) QuerySpec(io.crnk.core.queryspec.QuerySpec) ApproveTask(io.crnk.activiti.example.model.ApproveTask) Test(org.junit.Test)

Example 8 with QuerySpec

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

the class TaskResourceRepositoryTest method checkLEDueDate.

@Test
public void checkLEDueDate() {
    QuerySpec querySpec = new QuerySpec(ApproveTask.class);
    querySpec.addFilter(new FilterSpec(Arrays.asList("dueDate"), FilterOperator.LT, OffsetDateTime.now().plusHours(1)));
    Assert.assertEquals(1, taskRepository.findAll(querySpec).size());
    querySpec = new QuerySpec(TaskResource.class);
    querySpec.addFilter(new FilterSpec(Arrays.asList("dueDate"), FilterOperator.LT, OffsetDateTime.now().minusHours(1)));
    Assert.assertEquals(0, taskRepository.findAll(querySpec).size());
}
Also used : TaskResource(io.crnk.activiti.resource.TaskResource) QuerySpec(io.crnk.core.queryspec.QuerySpec) FilterSpec(io.crnk.core.queryspec.FilterSpec) Test(org.junit.Test)

Example 9 with QuerySpec

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

the class TaskResourceRepositoryTest method checkOrderByPriorityDesc.

@Test
public void checkOrderByPriorityDesc() {
    addTask("otherTask", 14);
    QuerySpec querySpec = new QuerySpec(ApproveTask.class);
    querySpec.addSort(new SortSpec(Arrays.asList("priority"), Direction.DESC));
    ResourceList<ApproveTask> resources = taskRepository.findAll(querySpec);
    Assert.assertEquals(2, resources.size());
    Assert.assertEquals("otherTask", resources.get(0).getName());
    Assert.assertEquals("testTask", 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 10 with QuerySpec

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

the class TaskResourceRepositoryTest method checkGTPriority.

@Test
public void checkGTPriority() {
    QuerySpec querySpec = new QuerySpec(ApproveTask.class);
    querySpec.addFilter(new FilterSpec(Arrays.asList("priority"), FilterOperator.GE, task.getPriority() - 1));
    Assert.assertEquals(1, taskRepository.findAll(querySpec).size());
    querySpec = new QuerySpec(TaskResource.class);
    querySpec.addFilter(new FilterSpec(Arrays.asList("priority"), FilterOperator.GE, task.getPriority() + 1));
    Assert.assertEquals(0, taskRepository.findAll(querySpec).size());
}
Also used : TaskResource(io.crnk.activiti.resource.TaskResource) QuerySpec(io.crnk.core.queryspec.QuerySpec) FilterSpec(io.crnk.core.queryspec.FilterSpec) Test(org.junit.Test)

Aggregations

QuerySpec (io.crnk.core.queryspec.QuerySpec)306 Test (org.junit.Test)233 FilterSpec (io.crnk.core.queryspec.FilterSpec)51 Document (io.crnk.core.engine.document.Document)45 Resource (io.crnk.core.engine.document.Resource)43 Set (java.util.Set)39 HashMap (java.util.HashMap)37 HashSet (java.util.HashSet)36 AbstractQuerySpecTest (io.crnk.core.queryspec.AbstractQuerySpecTest)34 QuerySpecAdapter (io.crnk.core.queryspec.internal.QuerySpecAdapter)32 AbstractJpaJerseyTest (io.crnk.jpa.AbstractJpaJerseyTest)32 Task (io.crnk.test.mock.models.Task)32 Project (io.crnk.core.mock.models.Project)28 Relationship (io.crnk.core.engine.document.Relationship)26 Task (io.crnk.core.mock.models.Task)26 TestEntity (io.crnk.jpa.model.TestEntity)26 ResourceIdentifier (io.crnk.core.engine.document.ResourceIdentifier)25 Serializable (java.io.Serializable)24 RelatedEntity (io.crnk.jpa.model.RelatedEntity)21 ResourceRegistryTest (io.crnk.core.resource.registry.ResourceRegistryTest)20