@Test public void should_not_persist_comment_when_whole_week_is_locked() throws OverBudgetException { okStatus(); TimesheetCommentId commentId = new TimesheetCommentId(1, new Date()); TimesheetComment comment = new TimesheetComment(commentId, "comment"); Date s = baseDate.toDate(); DateTime end = baseDate.plusWeeks(1); Date e = end.toDate(); User user = UserObjectMother.createUser(); when(context.getBean(IPersistTimesheet.class)).thenReturn(persister); withLock(new Interval(baseDate, end)); persister.persistTimesheetWeek(newEntries, comment, new DateRange(s, e), user); verify(timesheetDAO, never()).persist((any(TimesheetEntry.class))); verify(commentDao, never()).persist(any(TimesheetComment.class)); }
@Test public void should_not_persist_when_whole_week_is_locked() throws OverBudgetException { okStatus(); TimesheetCommentId commentId = new TimesheetCommentId(1, new Date()); TimesheetComment comment = new TimesheetComment(commentId, "comment"); Date s = baseDate.toDate(); DateTime end = baseDate.plusWeeks(1); Date e = end.toDate(); User user = UserObjectMother.createUser(); when(context.getBean(IPersistTimesheet.class)).thenReturn(persister); withLock(new Interval(baseDate, end)); persister.persistTimesheetWeek(newEntries, comment, new DateRange(s, e), user); verify(timesheetDAO, never()).persist((any(TimesheetEntry.class))); }
@Test public void should_persist_individual_timesheet_entries_for_a_week() { TimesheetCommentId commentId = new TimesheetCommentId(1, new Date()); TimesheetComment comment = new TimesheetComment(commentId, "comment"); when(context.getBean(IPersistTimesheet.class)).thenReturn(persister); // through Spring for new TX per entr=y okStatus(); noLocks(); persister.persistTimesheetWeek(newEntries, comment, new DateRange(), UserObjectMother.createUser()); verify(commentDao).persist(comment); }
@Test public void should_get_timesheet_entries() { Date da = new Date(2006 - 1900, Calendar.DECEMBER, 31); Date db = new Date(2007 - 1900, Calendar.JANUARY, 6); DateRange range = new DateRange(da, db); DateRange rangeB = new DateRange(new Date(2006 - 1900, Calendar.DECEMBER, 31), new Date(2007 - 1900, Calendar.JANUARY, 6)); when(timesheetDAO.getTimesheetEntriesInRange(1, range)).thenReturn(new ArrayList<TimesheetEntry>()); when(timesheetCommentDAO.findById(new TimesheetCommentId(1, range.getDateStart()))).thenReturn(new TimesheetComment()); when(projectAssignmentService.getProjectAssignmentsForUser(1, rangeB)).thenReturn(new ArrayList<ProjectAssignment>()); when(config.getFirstDayOfWeek()).thenReturn(1); when(timesheetLockService.findLockedDatesInRange(any(Date.class), any(Date.class), any(User.class))).thenReturn(new Vector<Interval>(0, 0, 1)); timesheetService.getWeekOverview(new User(1), new GregorianCalendar(2007, Calendar.JANUARY, 1)); verify(timesheetDAO).getTimesheetEntriesInRange(1, range); verify(timesheetCommentDAO).findById(new TimesheetCommentId(1, range.getDateStart())); verify(projectAssignmentService).getProjectAssignmentsForUser(1, rangeB); verify(config).getFirstDayOfWeek(); verify(timesheetLockService).findLockedDatesInRange(any(Date.class), any(Date.class), any(User.class)); } }
@Test public void should_not_persist_for_locked_day() throws OverBudgetException { okStatus(); TimesheetCommentId commentId = new TimesheetCommentId(1, new Date()); TimesheetComment comment = new TimesheetComment(commentId, "comment"); Date s = baseDate.toDate(); DateTime end = baseDate.plusWeeks(1); Date e = end.toDate(); User user = UserObjectMother.createUser(); when(context.getBean(IPersistTimesheet.class)).thenReturn(persister); TimesheetEntry entry = new TimesheetEntry(); TimesheetEntryId id = new TimesheetEntryId(); id.setProjectAssignment(assignment); id.setEntryDate(baseDate.plusDays(2).toDate()); entry.setEntryId(id); entry.setHours(5f); newEntries.add(entry); withLock(new Interval(baseDate.plusDays(2), end));// cancelling out the just created entry persister.persistTimesheetWeek(newEntries, comment, new DateRange(s, e), user); verify(timesheetDAO, times(1)).persist((any(TimesheetEntry.class))); verify(timesheetDAO, never()).delete((any(TimesheetEntry.class))); verify(commentDao, times(1)).persist(any(TimesheetComment.class)); }