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