@Test
public void testTimesheetProtection()
{
// Create test tasks:
getInitTestDB().addUser("tpt-user");
TaskDO task;
task = initTestDB.addTask("timesheetprotectiontest", "root");
task = initTestDB.addTask("tpt", "timesheetprotectiontest");
task = initTestDB.addTask("tpt.1", "tpt");
task = initTestDB.addTask("tpt.1.1", "tpt.1");
task = initTestDB.addTask("tpt.2", "tpt");
date.setDate(2008, Calendar.OCTOBER, 31, 0, 0, 0);
task.setProtectTimesheetsUntil(date.getDate());
taskDao.internalUpdate(task); // Without check access.
task = initTestDB.addTask("tpt.2.1", "tpt.2");
TimesheetDO sheet = new TimesheetDO();
sheet.setUser(getUser("tpt-user"));
System.out.println(sheet.getUserId());
sheet.setTask(getTask("tpt.2.1"));
setTimeperiod(sheet, 2008, Calendar.OCTOBER, 01, 7, 0, 21, 8, 15); // 10/01 from 07:00 to 08:15
try {
timesheetDao.save(sheet);
fail("AccessException caused by time sheet violation expected.");
} catch (final AccessException ex) {
// OK
}
setTimeperiod(sheet, 2008, Calendar.OCTOBER, 31, 23, 45, 31, 0, 15); // 10/30 from 23:45 to 00:15
try {
timesheetDao.save(sheet);
fail("AccessException caused by time sheet violation expected.");
} catch (final AccessException ex) {
// OK
}
setTimeperiod(sheet, 2008, Calendar.NOVEMBER, 1, 0, 0, 1, 2, 15); // 11/01 from 00:00 to 02:15
final Serializable id = timesheetDao.save(sheet);
sheet = timesheetDao.getById(id);
date.setDate(2008, Calendar.OCTOBER, 31, 23, 45, 0);
sheet.setStartTime(date.getTimestamp());
try {
timesheetDao.update(sheet);
fail("AccessException caused by time sheet violation expected.");
} catch (final AccessException ex) {
// OK
}
task = getTask("tpt.2");
date.setDate(2008, Calendar.NOVEMBER, 30, 0, 0, 0); // Change protection date, so time sheet is now protected.
task.setProtectTimesheetsUntil(date.getDate());
taskDao.internalUpdate(task); // Without check access.
sheet = timesheetDao.getById(id).setDescription("Hurzel"); // Should work, because start and stop time is not modified.
timesheetDao.update(sheet);
date.setDate(2008, Calendar.NOVEMBER, 1, 2, 0, 0);
sheet = timesheetDao.getById(id).setStopTime(date.getTimestamp());