Search in sources :

Example 36 with WorkdaysCalendar

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();
}
Also used : WorkdaysCalendar(com.artezio.arttime.datamodel.WorkdaysCalendar) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 37 with WorkdaysCalendar

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;
}
Also used : Stateless(javax.ejb.Stateless) Arrays(java.util.Arrays) Filter(com.artezio.arttime.filter.Filter) Scope(com.artezio.arttime.admin_tool.cache.WebCached.Scope) Period(com.artezio.arttime.datamodel.Period) Date(java.util.Date) ProjectRepository(com.artezio.arttime.services.repositories.ProjectRepository) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Employee(com.artezio.arttime.datamodel.Employee) Inject(javax.inject.Inject) BigDecimal(java.math.BigDecimal) Project(com.artezio.arttime.datamodel.Project) List(java.util.List) WorkdaysCalendarRepository(com.artezio.arttime.services.repositories.WorkdaysCalendarRepository) EmployeeRepository(com.artezio.arttime.services.repositories.EmployeeRepository) TreeMap(java.util.TreeMap) HoursRepository(com.artezio.arttime.services.repositories.HoursRepository) Map(java.util.Map) WorkdaysCalendar(com.artezio.arttime.datamodel.WorkdaysCalendar) Named(javax.inject.Named) Hours(com.artezio.arttime.datamodel.Hours) WebCached(com.artezio.arttime.admin_tool.cache.WebCached) WorkdaysCalendar(com.artezio.arttime.datamodel.WorkdaysCalendar) Date(java.util.Date)

Example 38 with WorkdaysCalendar

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");
}
Also used : WorkdaysCalendar(com.artezio.arttime.datamodel.WorkdaysCalendar) Test(org.junit.Test)

Example 39 with WorkdaysCalendar

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());
}
Also used : Project(com.artezio.arttime.datamodel.Project) WorkdaysCalendar(com.artezio.arttime.datamodel.WorkdaysCalendar) Employee(com.artezio.arttime.datamodel.Employee) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 40 with WorkdaysCalendar

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);
}
Also used : WorkdaysCalendar(com.artezio.arttime.datamodel.WorkdaysCalendar) Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) HourType(com.artezio.arttime.datamodel.HourType) Hours(com.artezio.arttime.datamodel.Hours) Period(com.artezio.arttime.datamodel.Period) CalendarUtils.createPeriod(com.artezio.arttime.test.utils.CalendarUtils.createPeriod) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) CalendarUtils.getOffsetDate(com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

WorkdaysCalendar (com.artezio.arttime.datamodel.WorkdaysCalendar)76 Test (org.junit.Test)65 Day (com.artezio.arttime.datamodel.Day)23 CalendarUtils.getOffsetDate (com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate)17 Employee (com.artezio.arttime.datamodel.Employee)16 Period (com.artezio.arttime.datamodel.Period)11 Date (java.util.Date)10 Project (com.artezio.arttime.datamodel.Project)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 SimpleDateFormat (java.text.SimpleDateFormat)5 DateFormat (java.text.DateFormat)3 Before (org.junit.Before)3 HourType (com.artezio.arttime.datamodel.HourType)2 Hours (com.artezio.arttime.datamodel.Hours)2 EmployeeRepository (com.artezio.arttime.repositories.EmployeeRepository)2 BigDecimal (java.math.BigDecimal)2 GregorianCalendar (java.util.GregorianCalendar)2 HashMap (java.util.HashMap)2 WebCached (com.artezio.arttime.admin_tool.cache.WebCached)1 Scope (com.artezio.arttime.admin_tool.cache.WebCached.Scope)1