use of com.artezio.arttime.datamodel.WorkdaysCalendar in project ART-TIME by Artezio.
the class WorkdaysCalendarBeanTest method testInit_ifCalendarPassAsParam.
@Test
public void testInit_ifCalendarPassAsParam() throws Exception {
calendarBean = createMockBuilder(WorkdaysCalendarBean.class).addMockedMethod("updatePeriod", Date.class, Date.class).createMock();
setField(calendarBean, "externalContext", externalContext);
setField(calendarBean, "workdaysCalendarService", workdaysCalendarService);
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
Date date1 = sdf.parse("1-01-2015");
Date date2 = sdf.parse("31-01-2015");
WorkdaysCalendar calendar = new WorkdaysCalendar();
Map<String, String> requestParams = new HashMap<String, String>();
requestParams.put("calendar", "1");
PowerMock.mockStatic(CalendarUtils.class);
expect(externalContext.getRequestParameterMap()).andReturn(requestParams);
expect(workdaysCalendarService.findById(1L)).andReturn(calendar);
expect(CalendarUtils.firstDayOfMonth(anyObject(Date.class))).andReturn(date1);
expect(CalendarUtils.lastDayOfMonth(anyObject(Date.class))).andReturn(date2);
replayAll(CalendarUtils.class, externalContext, workdaysCalendarService);
calendarBean.init();
PowerMock.verifyAll();
}
use of com.artezio.arttime.datamodel.WorkdaysCalendar in project ART-TIME by Artezio.
the class WorkTimeService method getWorkSchedule.
protected Map<Date, Boolean> getWorkSchedule(List<Project> activeProjects, Employee employee, Period period) {
Map<Date, Boolean> workSchedule = generateWorkScheduleTemplate(period);
WorkdaysCalendar calendar = employee.getCalendar();
if (isTeamMember(activeProjects, employee)) {
workdaysCalendarRepository.getDays(calendar, period).stream().filter(day -> !workSchedule.get(day.getDate())).forEach(day -> workSchedule.put(day.getDate(), day.isWorking()));
}
return workSchedule;
}
use of com.artezio.arttime.datamodel.WorkdaysCalendar in project ART-TIME by Artezio.
the class DepartmentServiceTest method testGetDepartmentsWithCalendar.
@Test
public void testGetDepartmentsWithCalendar() throws NoSuchFieldException {
setField(departmentService, "workdaysCalendarRepository", workdaysCalendarRepository);
WorkdaysCalendar calendar1 = new WorkdaysCalendar();
calendar1.getDepartments().add("dep1");
calendar1.getDepartments().add("dep2");
WorkdaysCalendar calendar2 = new WorkdaysCalendar();
calendar2.getDepartments().add("dep1");
calendar2.getDepartments().add("dep3");
List<WorkdaysCalendar> calendars = Arrays.asList(calendar1, calendar2);
expect(workdaysCalendarRepository.getWorkdaysCalendars()).andReturn(calendars);
replay(workdaysCalendarRepository);
Set<String> actual = departmentService.getDepartmentsWithCalendars();
verify(workdaysCalendarRepository);
assertEquals(3, actual.size());
ListAssert.assertContains(new ArrayList<String>(actual), "dep1");
ListAssert.assertContains(new ArrayList<String>(actual), "dep2");
ListAssert.assertContains(new ArrayList<String>(actual), "dep3");
}
use of com.artezio.arttime.datamodel.WorkdaysCalendar in project ART-TIME by Artezio.
the class ProjectServiceTest method testAddTeamMembers.
@Test
public void testAddTeamMembers() throws ParseException, NoSuchFieldException {
Project project = new Project();
WorkdaysCalendar calendar1 = new WorkdaysCalendar("calendar1");
WorkdaysCalendar calendar2 = new WorkdaysCalendar("calendar2");
Map<String, WorkdaysCalendar> calendars = new HashMap<>();
calendars.put("Minsk", calendar1);
calendars.put("Moscow", calendar2);
Employee employee1 = new Employee("employee1");
employee1.setDepartment("Minsk");
Employee employee2 = new Employee("employee2");
employee2.setDepartment("Minsk");
Employee employee3 = new Employee("employee3");
employee3.setDepartment("Moscow");
project.addTeamMember(employee1);
List<Employee> employees = Arrays.asList(employee2, employee3);
expect(calendarRepository.getCalendarsByDepartments()).andReturn(calendars);
setField(projectService, "calendarRepository", calendarRepository);
replay(calendarRepository);
projectService.addTeamMembers(project, employees);
verify(calendarRepository);
assertEquals(3, project.getTeam().size());
assertEquals(employee1, project.getTeam().get(0));
assertEquals(employee2, project.getTeam().get(1));
assertEquals(employee3, project.getTeam().get(2));
assertSame(calendar1, project.getTeam().get(1).getCalendar());
assertSame(calendar2, project.getTeam().get(2).getCalendar());
}
use of com.artezio.arttime.datamodel.WorkdaysCalendar in project ART-TIME by Artezio.
the class HoursRepositoryTest method testGetActualHoursSum.
@Test
public void testGetActualHoursSum() throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Employee employee = new Employee("username");
Date start = sdf.parse("2014-11-01");
WorkdaysCalendar calendar = new WorkdaysCalendar("calendar");
Project project = createActiveProjectWithTeamMember(employee, calendar);
HourType actualType = new HourType("actual");
actualType.setActualTime(true);
HourType notActualType = new HourType("not_actual");
Hours approved = createHours(project, employee, sdf.parse("2014-11-02"), actualType, new BigDecimal("8"));
approved.setApproved(true);
Hours notApproved1 = createHours(project, employee, sdf.parse("2014-11-03"), actualType, new BigDecimal("8"));
Hours notApproved2 = createHours(project, employee, sdf.parse("2014-11-04"), actualType, new BigDecimal("8"));
Hours notActual = createHours(project, employee, sdf.parse("2014-11-05"), notActualType, new BigDecimal("8"));
Hours beforePeriod = createHours(project, employee, sdf.parse("2014-10-31"), actualType, new BigDecimal("8"));
entityManager.persist(actualType);
entityManager.persist(notActualType);
entityManager.persist(approved);
entityManager.persist(notApproved1);
entityManager.persist(notApproved2);
entityManager.persist(notActual);
entityManager.persist(beforePeriod);
Period period = new Period(start, sdf.parse("2014-11-30"));
BigDecimal actual = hoursRepository.getActualHoursSum(employee, period);
assertEquals(new BigDecimal("24.00"), actual);
}
Aggregations