use of io.crnk.test.mock.models.Schedule in project crnk-framework by crnk-project.
the class QuerySpecClientTest method testNullNonLazyRelationWithSave.
@Test
public void testNullNonLazyRelationWithSave() {
Schedule schedule = new Schedule();
schedule.setId(1L);
schedule.setName("schedule");
scheduleRepo.create(schedule);
Task task = new Task();
task.setId(2L);
task.setName("test");
task.setSchedule(schedule);
taskRepo.create(task);
Task savedTask = taskRepo.findOne(task.getId(), new QuerySpec(Task.class));
Assert.assertNotNull(savedTask.getSchedule());
// null
savedTask.setSchedule(null);
taskRepo.save(savedTask);
// relation must be null
Task updatedTask = taskRepo.findOne(task.getId(), new QuerySpec(Task.class));
Assert.assertNull(updatedTask.getSchedule());
}
use of io.crnk.test.mock.models.Schedule in project crnk-framework by crnk-project.
the class QuerySpecClientTest method testInterfaceAccess.
@Test
public void testInterfaceAccess() {
// tag::interfaceAccess[]
ScheduleRepository scheduleRepository = client.getResourceRepository(ScheduleRepository.class);
Schedule schedule = new Schedule();
schedule.setId(13L);
schedule.setName("mySchedule");
scheduleRepository.create(schedule);
QuerySpec querySpec = new QuerySpec(Schedule.class);
ScheduleList list = scheduleRepository.findAll(querySpec);
Assert.assertEquals(1, list.size());
ScheduleListMeta meta = list.getMeta();
ScheduleListLinks links = list.getLinks();
Assert.assertNotNull(meta);
Assert.assertNotNull(links);
// end::interfaceAccess[]
}
use of io.crnk.test.mock.models.Schedule in project crnk-framework by crnk-project.
the class QuerySpecClientTest method testSaveRelationWithSave.
@Test
public void testSaveRelationWithSave() {
Schedule schedule = new Schedule();
schedule.setId(1L);
schedule.setName("schedule");
scheduleRepo.create(schedule);
Task task = new Task();
task.setId(2L);
task.setName("test");
taskRepo.create(task);
Task createdTask = taskRepo.findOne(task.getId(), new QuerySpec(Task.class));
Assert.assertNull(createdTask.getSchedule());
createdTask.setSchedule(schedule);
taskRepo.save(createdTask);
Task updatedTask = taskRepo.findOne(task.getId(), new QuerySpec(Task.class));
Assert.assertNotNull(updatedTask.getSchedule());
}
use of io.crnk.test.mock.models.Schedule in project crnk-framework by crnk-project.
the class QuerySpecClientTest method testCannotNullLazyRelationWithSave.
@Test
public void testCannotNullLazyRelationWithSave() {
Task task = new Task();
task.setId(2L);
task.setName("test");
taskRepo.create(task);
Schedule schedule = new Schedule();
schedule.setId(1L);
schedule.setName("schedule");
schedule.setLazyTask(task);
scheduleRepo.create(schedule);
// since lazy, will not be sent to client if not requested
QuerySpec querySpec = new QuerySpec(Schedule.class);
Schedule savedSchedule = scheduleRepo.findOne(schedule.getId(), querySpec);
Assert.assertNull(savedSchedule.getLazyTask());
querySpec.includeRelation(Arrays.asList("lazyTask"));
savedSchedule = scheduleRepo.findOne(schedule.getId(), querySpec);
Assert.assertNotNull(savedSchedule.getLazyTask());
// null
savedSchedule.setLazyTask(task);
scheduleRepo.save(savedSchedule);
// still not null because cannot differantiate between not loaded and
// nulled
Schedule updatedSchedule = scheduleRepo.findOne(schedule.getId(), querySpec);
Assert.assertNotNull(updatedSchedule.getLazyTask());
}
use of io.crnk.test.mock.models.Schedule in project crnk-framework by crnk-project.
the class RelationIdClientTest method checkCrud.
@Test
public void checkCrud() {
Schedule schedule = checkPost();
checkFindWithoutInclusion(schedule);
checkFindWithInclusion(schedule);
schedule = checkPatch(schedule);
checkPatchRelationship(schedule);
}
Aggregations