Search in sources :

Example 36 with Schedule

use of io.crnk.test.mock.models.Schedule in project crnk-framework by crnk-project.

the class AbstractProxiedObjectsClientTest method proxyForCollection.

private void proxyForCollection(boolean set) {
    Schedule schedule = new Schedule();
    schedule.setId(1L);
    schedule.setName("project");
    scheduleRepo.create(schedule);
    Task task = new Task();
    task.setId(2L);
    task.setName("test");
    taskRepo.create(task);
    taskScheduleRepo.setRelation(task, schedule.getId(), "schedule");
    // collection must be available as proxy
    QuerySpec querySpec = new QuerySpec(Task.class);
    schedule = scheduleRepo.findOne(1L, querySpec);
    Collection<Task> proxiedTasks = set ? schedule.getTasks() : schedule.getTasksList();
    Assert.assertNotNull(proxiedTasks);
    // check status without loading
    ObjectProxy proxy = (ObjectProxy) proxiedTasks;
    Assert.assertFalse(proxy.isLoaded());
    Assert.assertNotNull(proxy.getUrl());
    Assert.assertFalse(proxy.isLoaded());
    // lazy load
    Assert.assertEquals(1, proxiedTasks.size());
    Assert.assertTrue(proxy.isLoaded());
    task = proxiedTasks.iterator().next();
    Assert.assertEquals(2L, task.getId().longValue());
}
Also used : Task(io.crnk.test.mock.models.Task) Schedule(io.crnk.test.mock.models.Schedule) ObjectProxy(io.crnk.client.internal.proxy.ObjectProxy) QuerySpec(io.crnk.core.queryspec.QuerySpec)

Example 37 with Schedule

use of io.crnk.test.mock.models.Schedule in project crnk-framework by crnk-project.

the class AbstractProxiedObjectsClientTest method saveLazyCollectionChange.

@Test
public void saveLazyCollectionChange() {
    Schedule schedule = new Schedule();
    schedule.setId(1L);
    schedule.setName("project");
    scheduleRepo.create(schedule);
    Task task = new Task();
    task.setId(2L);
    task.setName("test");
    taskRepo.create(task);
    QuerySpec querySpec = new QuerySpec(Task.class);
    schedule = scheduleRepo.findOne(1L, querySpec);
    Collection<Task> proxiedTasks = schedule.getTasks();
    ObjectProxy proxy = (ObjectProxy) proxiedTasks;
    Assert.assertFalse(proxy.isLoaded());
    // add task to collection
    proxiedTasks.add(task);
    Assert.assertTrue(proxy.isLoaded());
    Assert.assertEquals(1, proxiedTasks.size());
    scheduleRepo.save(schedule);
    schedule = scheduleRepo.findOne(1L, querySpec);
    proxiedTasks = schedule.getTasks();
    Assert.assertEquals(1, proxiedTasks.size());
    // remove task from collection
    proxiedTasks.remove(task);
    Assert.assertEquals(1, proxiedTasks.size());
    scheduleRepo.save(schedule);
    schedule = scheduleRepo.findOne(1L, querySpec);
    proxiedTasks = schedule.getTasks();
    Assert.assertEquals(1, proxiedTasks.size());
}
Also used : Task(io.crnk.test.mock.models.Task) Schedule(io.crnk.test.mock.models.Schedule) ObjectProxy(io.crnk.client.internal.proxy.ObjectProxy) QuerySpec(io.crnk.core.queryspec.QuerySpec) Test(org.junit.Test)

Aggregations

Schedule (io.crnk.test.mock.models.Schedule)37 Test (org.junit.Test)24 QuerySpec (io.crnk.core.queryspec.QuerySpec)21 Task (io.crnk.test.mock.models.Task)10 ScheduleRepository (io.crnk.test.mock.repository.ScheduleRepository)5 AbstractClientTest (io.crnk.client.AbstractClientTest)4 ObjectProxy (io.crnk.client.internal.proxy.ObjectProxy)4 Project (io.crnk.test.mock.models.Project)3 DocumentFilterChain (io.crnk.core.engine.filter.DocumentFilterChain)2 DocumentFilterContext (io.crnk.core.engine.filter.DocumentFilterContext)2 ActionPath (io.crnk.core.engine.internal.dispatcher.path.ActionPath)2 ScheduleList (io.crnk.test.mock.repository.ScheduleRepository.ScheduleList)2 ScheduleListLinks (io.crnk.test.mock.repository.ScheduleRepository.ScheduleListLinks)2 ScheduleListMeta (io.crnk.test.mock.repository.ScheduleRepository.ScheduleListMeta)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ApprovalManager (io.crnk.activiti.example.approval.ApprovalManager)1 ApprovalMapper (io.crnk.activiti.example.approval.ApprovalMapper)1 ApprovalRelationshipRepository (io.crnk.activiti.example.approval.ApprovalRelationshipRepository)1 ApproveTask (io.crnk.activiti.example.model.ApproveTask)1