use of io.crnk.client.internal.proxy.ObjectProxy in project crnk-framework by crnk-project.
the class InheritanceClientTest method doTestIncludePoloymorphCollection.
private void doTestIncludePoloymorphCollection(boolean include) {
QuerySpec querySpec = new QuerySpec(Project.class);
if (include) {
querySpec.includeRelation(Arrays.asList("tasks"));
}
List<Project> projects = projectRepo.findAll(querySpec);
Assert.assertEquals(1, projects.size());
Project project = projects.get(0);
List<Task> tasks = project.getTasks();
if (include) {
Assert.assertFalse(tasks instanceof ObjectProxy);
} else {
ObjectProxy proxy = (ObjectProxy) tasks;
Assert.assertFalse(proxy.isLoaded());
}
if (tasks.get(0).getName().equals("baseTask")) {
Assert.assertEquals("baseTask", tasks.get(0).getName());
Assert.assertEquals("taskSubType", tasks.get(1).getName());
} else {
Assert.assertEquals("baseTask", tasks.get(1).getName());
Assert.assertEquals("taskSubType", tasks.get(0).getName());
}
}
use of io.crnk.client.internal.proxy.ObjectProxy 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.client.internal.proxy.ObjectProxy 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