private FlatReportElement createFlatReportElement() { ProjectAssignment assignment = ProjectAssignmentObjectMother.createProjectAssignment(1); return FlatReportElementBuilder.buildFlatReportElement(assignment); }
@Test public void should_find_project_assignment() throws ObjectNotFoundException { ProjectAssignment pa = ProjectAssignmentObjectMother.createProjectAssignment(1); when(projectAssignmentDAO.findById(1)).thenReturn(pa); List<Integer> ids = Lists.newArrayList(); ids.add(1); when(reportAggregatedDAO.getCumulatedHoursPerAssignmentForAssignments(ids)).thenReturn(new ArrayList<AssignmentAggregateReportElement>()); ProjectAssignment assignment = projectAssignmentService.getProjectAssignment(1); assertEquals(pa, assignment); }
@Test public void testCompareName() { int x = new ProjectAssignmentComparator(ProjectAssignmentComparator.ASSIGNMENT_COMPARE_NAME) .compare(ProjectAssignmentObjectMother.createProjectAssignment(2), ProjectAssignmentObjectMother.createProjectAssignment(1)); assertTrue(x > 0); }
@Test public void testCompareCustDatePrj() { int x = new ProjectAssignmentComparator(ProjectAssignmentComparator.ASSIGNMENT_COMPARE_CUSTDATEPRJ) .compare(ProjectAssignmentObjectMother.createProjectAssignment(2), ProjectAssignmentObjectMother.createProjectAssignment(1)); assertTrue(x > 0); }
@Test public void testCompareStart() { int x = new ProjectAssignmentComparator(ProjectAssignmentComparator.ASSIGNMENT_COMPARE_START) .compare(ProjectAssignmentObjectMother.createProjectAssignment(1), ProjectAssignmentObjectMother.createProjectAssignment(1)); assertTrue(x == 0); }
@Test public void should_assign_user_to_project() throws ProjectAlreadyAssignedException { ProjectAssignment projectAssignment = ProjectAssignmentObjectMother.createProjectAssignment(1); service.persistNewProjectAssignment(projectAssignment); verify(projectAssignmentDao).persist(projectAssignment); }
@Before public void setUp() { a1 = new AssignmentAggregateReportElement(); a2 = new AssignmentAggregateReportElement(); a1.setProjectAssignment(ProjectAssignmentObjectMother.createProjectAssignment(1)); a2.setProjectAssignment(ProjectAssignmentObjectMother.createProjectAssignment(2)); }
@Test public void should_find_project_assignments_for_project_and_check_deletability() throws ObjectNotFoundException { Project project = ProjectObjectMother.createProject(1); ProjectAssignment deleteableAssignment = ProjectAssignmentObjectMother.createProjectAssignment(1); ProjectAssignment nondeleteableAssignment = ProjectAssignmentObjectMother.createProjectAssignment(2); when(projectAssignmentDAO.findAllProjectAssignmentsForProject(project)).thenReturn(Arrays.asList(deleteableAssignment, nondeleteableAssignment)); when(reportAggregatedDAO.getCumulatedHoursPerAssignmentForAssignments(Lists.newArrayList(deleteableAssignment.getPK(), nondeleteableAssignment.getPK()))) .thenReturn(Lists.newArrayList(new AssignmentAggregateReportElement(nondeleteableAssignment, 5))); List<ProjectAssignment> assignments = projectAssignmentService.getProjectAssignmentsAndCheckDeletability(project); assertTrue(assignments.get(0).isDeletable()); assertFalse(assignments.get(1).isDeletable()); } }
@Test public void should_not_update_assignment_when_there_is_data_before_the_start() { ProjectAssignment assignment = ProjectAssignmentObjectMother.createProjectAssignment(1); Date dateStart = new Date(); assignment.setDateStart(dateStart); when(timesheetDao.getTimesheetEntriesBefore(assignment, dateStart)).thenReturn(Lists.newArrayList(TimesheetEntryObjectMother.createTimesheetEntry(1, new Date(), 5f))); try { service.persistUpdatedProjectAssignment(assignment); fail(); } catch (ProjectAssignmentValidationException e) { List<ProjectAssignmentValidationException.Issue> issues = e.getIssues(); assertThat(issues, contains(ProjectAssignmentValidationException.Issue.EXISTING_DATA_BEFORE_START)); } }
public static AssignmentAggregateReportElement createProjectAssignmentAggregate(int baseId, int customerId, int userId) { AssignmentAggregateReportElement pag = new AssignmentAggregateReportElement(); pag.setHours(baseId); pag.setProjectAssignment(ProjectAssignmentObjectMother.createProjectAssignment(baseId, customerId, userId)); return pag; } }
@Test public void when_finding_should_set_proper_id_for_embeddable_id() { TimesheetEntryId timesheetEntryId = new TimesheetEntryId(new Date(), ProjectAssignmentObjectMother.createProjectAssignment(1)); TimesheetEntry entry = subject.find(timesheetEntryId, TimesheetEntry.class); assertEquals(timesheetEntryId, entry.getEntryId()); }
@Test public void should_not_update_assignment_when_there_is_data_after_the_end() { ProjectAssignment assignment = ProjectAssignmentObjectMother.createProjectAssignment(1); Date date = new Date(); assignment.setDateEnd(date); when(timesheetDao.getTimesheetEntriesAfter(assignment, date)).thenReturn(Lists.newArrayList(TimesheetEntryObjectMother.createTimesheetEntry(1, new Date(), 5f))); try { service.persistUpdatedProjectAssignment(assignment); fail(); } catch (ProjectAssignmentValidationException e) { List<ProjectAssignmentValidationException.Issue> issues = e.getIssues(); assertThat(issues, contains(ProjectAssignmentValidationException.Issue.EXISTING_DATA_AFTER_END)); } }
@Test public void should_create_pm_detailed_report() { Project project = new Project(1); project.setProjectCode("PRJ"); DateRange dr = new DateRange(new Date(), new Date()); when(reportAggregatedDao.getMinMaxDateTimesheetEntry(project)).thenReturn(dr); List<AssignmentAggregateReportElement> elms = new ArrayList<>(); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { elms.add(AssignmentAggregateReportElementMother.createProjectAssignmentAggregate(j, i, i)); } } when(reportAggregatedDao.getCumulatedHoursPerAssignmentForProjects(any(List.class), any(DateRange.class))) .thenReturn(elms); List<ProjectAssignment> assignments = new ArrayList<>(); assignments.add(ProjectAssignmentObjectMother.createProjectAssignment(2)); when(assignmentService.getProjectAssignments(project, dr)).thenReturn(assignments); ProjectManagerReport report = aggregateReportService.getProjectManagerDetailedReport(project); assertEquals(new Integer(1), report.getProject().getPK()); assertEquals(16, report.getAggregates().size()); }
@Test public final void testGetAssignmentStatusDateOut() { ProjectAssignment assignment = ProjectAssignmentObjectMother.createProjectAssignment(1); ProjectAssignmentType type = new ProjectAssignmentType(); type.setAssignmentTypeId(EhourConstants.ASSIGNMENT_DATE); assignment.setAssignmentType(type); Calendar startCal = new GregorianCalendar(); startCal.add(Calendar.DAY_OF_YEAR, -5); assignment.setDateStart(startCal.getTime()); Date start = startCal.getTime(); Calendar endCal = new GregorianCalendar(); endCal.add(Calendar.DAY_OF_YEAR, -2); assignment.setDateEnd(endCal.getTime()); Date end = endCal.getTime(); when(timesheetDAO.getTimesheetEntriesBefore(assignment, start)) .thenReturn(new ArrayList<TimesheetEntry>()); List<TimesheetEntry> entry = new ArrayList<>(); entry.add(new TimesheetEntry()); when(timesheetDAO.getTimesheetEntriesAfter(assignment, end)) .thenReturn(entry); ProjectAssignmentStatus status = util.getAssignmentStatus(assignment); assertTrue(status.getStatusses().contains(ProjectAssignmentStatus.Status.AFTER_DEADLINE)); assertEquals(1, status.getStatusses().size()); }
@Test public final void testGetAssignmentStatusDateIn() { ProjectAssignment assignment = ProjectAssignmentObjectMother.createProjectAssignment(1); ProjectAssignmentType type = new ProjectAssignmentType(); type.setAssignmentTypeId(EhourConstants.ASSIGNMENT_DATE); assignment.setAssignmentType(type); Calendar startCal = new GregorianCalendar(); startCal.add(Calendar.DAY_OF_YEAR, -5); Date startDate = startCal.getTime(); assignment.setDateStart(startDate); Calendar endCal = new GregorianCalendar(); endCal.add(Calendar.DAY_OF_YEAR, 2); Date endDate = endCal.getTime(); assignment.setDateEnd(endDate); when(timesheetDAO.getTimesheetEntriesBefore(assignment, startDate)) .thenReturn(new ArrayList<TimesheetEntry>()); when(timesheetDAO.getTimesheetEntriesAfter(assignment, endDate)) .thenReturn(new ArrayList<TimesheetEntry>()); ProjectAssignmentStatus status = util.getAssignmentStatus(assignment); assertTrue(status.getStatusses().contains(ProjectAssignmentStatus.Status.RUNNING)); assertEquals(1, status.getStatusses().size()); }
@Test public void should_process_column_with_embeddable() throws InstantiationException, IllegalAccessException { FieldMap fieldDefinitionMap = FieldMapFactory.buildFieldMapForEntity(TimesheetEntry.class); FieldDefinition fieldDef = fieldDefinitionMap.get("assignment_id"); TimesheetEntry timesheetEntry = TimesheetEntryObjectMother.createTimesheetEntry(1, new Date(), 5f); timesheetEntry.setEntryId(null); Map<Class<?>, Object> embeddables = Maps.newHashMap(); ProjectAssignment projectAssignment = ProjectAssignmentObjectMother.createProjectAssignment(1); fieldDef.process(timesheetEntry, embeddables, projectAssignment); assertEquals(projectAssignment, ((TimesheetEntryId) embeddables.get(TimesheetEntryId.class)).getProjectAssignment()); } }
@Test public void shouldPersist() { Calendar cal = new GregorianCalendar(); cal.add(Calendar.MONTH, 1); ProjectAssignment assignment = ProjectAssignmentObjectMother.createProjectAssignment(new User(5), new Project(1)); assignment.setDateStart(new Date()); assignment.setDateEnd(cal.getTime()); assignment.setAssignmentType(new ProjectAssignmentType(EhourConstants.ASSIGNMENT_DATE)); assignment.setAssignmentId(25); projectAssignmentDAO.persist(assignment); assertNotNull(assignment.getAssignmentId()); }
@Test public void should_assign_users_to_project_using_template_assignment() { ProjectAssignment templateAssignment = ProjectAssignmentObjectMother.createProjectAssignment(1); templateAssignment.setAllottedHours(5f); User userA = UserObjectMother.createUser(); userA.setLastName("A"); User userB = UserObjectMother.createUser(); userB.setLastName("B"); userB.setUserId(2); List<User> users = Arrays.asList(userA, userB); service.assignUsersToProjects(users, templateAssignment); ArgumentCaptor<ProjectAssignment> captor = ArgumentCaptor.forClass(ProjectAssignment.class); verify(projectAssignmentDao, times(2)).persist(captor.capture()); List<ProjectAssignment> assignments = captor.getAllValues(); ProjectAssignment assignment = assignments.get(0); assertEquals(userA, assignment.getUser()); assertEquals(5f, assignment.getAllottedHours(), 0); }
@Test public void should_get_timesheet_overview() throws Exception { List<TimesheetEntry> daoResults = new ArrayList<>(); List<AssignmentAggregateReportElement> reportResults = new ArrayList<>(); Calendar cal = new GregorianCalendar(); TimesheetEntry entryA, entryB; TimesheetEntryId idA, idB; idA = new TimesheetEntryId(new Date(2006 - 1900, Calendar.OCTOBER, 2), null); entryA = new TimesheetEntry(); entryA.setEntryId(idA); entryA.setHours((float) 5); daoResults.add(entryA); idB = new TimesheetEntryId(new Date(2006 - 1900, Calendar.OCTOBER, 6), null); entryB = new TimesheetEntry(); entryB.setEntryId(idB); entryB.setHours((float) 3); daoResults.add(entryB); AssignmentAggregateReportElement agg = new AssignmentAggregateReportElement(); ProjectAssignment pa = ProjectAssignmentObjectMother.createProjectAssignment(0); agg.setProjectAssignment(pa); reportResults.add(agg); when(timesheetDAO.getTimesheetEntriesInRange(1, DateUtil.calendarToMonthRange(cal))).thenReturn(daoResults); when(aggregateReportService.getHoursPerAssignmentInRange(1, DateUtil.calendarToMonthRange(cal))).thenReturn(reportResults); timesheetService.getTimesheetOverview(new User(1), cal); verify(timesheetDAO).getTimesheetEntriesInRange(1, DateUtil.calendarToMonthRange(cal)); verify(aggregateReportService).getHoursPerAssignmentInRange(1, DateUtil.calendarToMonthRange(cal)); }
@Test public void should_provide_assignments_without_bookings() { provideNoLocks(); noFilteringOnUserOrProject(); when(reportAggregatedDao.getAssignmentsWithoutBookings(reportCriteria.getReportRange())).thenReturn(Arrays.asList(ProjectAssignmentObjectMother.createProjectAssignment(1))); userSelectedCriteria.setShowZeroBookings(true); Project billableProject = ProjectObjectMother.createProject(1); billableProject.setBillable(true); Project notBillableProject = ProjectObjectMother.createProject(2); notBillableProject.setBillable(false); when(projectDao.findAllActive()).thenReturn(Arrays.asList(billableProject)); when(detailedReportDao.getHoursPerDay(reportCriteria.getReportRange())).thenReturn(Arrays.asList(createFlatReportElement())); ReportData reportData = detailedReportService.getDetailedReportData(reportCriteria); FlatReportElement element = (FlatReportElement) reportData.getReportElements().get(0); assertTrue(element.isEmptyEntry()); verify(detailedReportDao).getHoursPerDay(reportCriteria.getReportRange()); verify(reportAggregatedDao).getAssignmentsWithoutBookings(reportCriteria.getReportRange()); } }