@Test
@Transactional
public void testSaveAndRemoveResourceCalendar() {
Worker worker = ResourceDAOTest.givenValidWorker();
ResourceCalendar resourceCalendar = ResourceCalendar.create();
addChristmasAsExceptionDay(resourceCalendar);
resourceCalendar.setName("testResourceCalendar");
BaseCalendarTest.setHoursForAllDays(resourceCalendar, 8);
worker.setCalendar(resourceCalendar);
// Resource calendar was saved whe worker was saved
resourceDAO.save(worker);
resourceCalendar = worker.getCalendar();
assertTrue(resourceCalendar.getId() != null);
// Unset calendar from resource and save should remove calendar
try {
baseCalendarDAO.remove(resourceCalendar.getId());
worker.setCalendar(null);
resourceDAO.save(worker);
} catch (InstanceNotFoundException e) {
}
assertTrue(!baseCalendarDAO.exists(resourceCalendar.getId()));
}