Search in sources :

Example 1 with WorkTime

use of com.artezio.arttime.services.WorkTimeService.WorkTime in project ART-TIME by Artezio.

the class WorkTimeServiceTest method testGetProblemWorkTime_PeriodHasWorkingDays.

@Test
public void testGetProblemWorkTime_PeriodHasWorkingDays() throws NoSuchFieldException {
    Date date1 = new Date();
    Date date2 = new Date();
    Period period = new Period();
    Employee employee = new Employee("employee");
    Map<Employee, Map<Boolean, BigDecimal>> actualWorkTimeByEmployee = new HashMap<>();
    actualWorkTimeByEmployee.put(employee, new HashMap<Boolean, BigDecimal>() {

        {
            put(false, new BigDecimal(8).setScale(2));
            put(true, new BigDecimal(8).setScale(2));
        }
    });
    WorkdaysCalendar calendar = new WorkdaysCalendar("calendar");
    employee.setCalendar(calendar);
    Employee manager1 = new Employee("manager1");
    Employee manager2 = new Employee("manager2");
    Map<Employee, List<Employee>> managersForApproveByEmployee = new HashMap<Employee, List<Employee>>() {

        {
            put(employee, asList(manager1));
        }
    };
    Map<Employee, List<Employee>> managersByEmployee = new HashMap<Employee, List<Employee>>() {

        {
            put(employee, asList(manager1, manager2));
        }
    };
    List<Employee> employees = asList(employee);
    Filter filter = new Filter();
    filter.setEmployees(employees);
    filter.setCustomPeriod(period);
    ProjectRepository.ProjectQuery projectQuery = Mockito.mock(ProjectRepository.ProjectQuery.class, Mockito.RETURNS_DEEP_STUBS);
    EmployeeRepository.EmployeeQuery employeeQuery = Mockito.mock(EmployeeRepository.EmployeeQuery.class, Mockito.RETURNS_DEEP_STUBS);
    Tuple tuple1 = Mockito.mock(Tuple.class);
    Tuple tuple2 = Mockito.mock(Tuple.class);
    expect(workdaysCalendarService.getDays(calendar, period)).andReturn(asList(new Day(date1, calendar, true), new Day(date2, calendar, true)));
    expect(hoursRepository.getActualTimeByEmployeeAndApproval(employees, period)).andReturn(actualWorkTimeByEmployee);
    expect(hoursRepository.getManagersForApproveByEmployee(employees, period)).andReturn(managersForApproveByEmployee);
    expect(projectRepository.query(true)).andReturn(projectQuery);
    expect(employeeRepository.query()).andReturn(employeeQuery);
    Mockito.when(employeeQuery.filter(filter).notFormer().list()).thenReturn(employees);
    Mockito.when(tuple1.get(0, Employee.class)).thenReturn(employee);
    Mockito.when(tuple1.get(1, Employee.class)).thenReturn(manager1);
    Mockito.when(tuple2.get(0, Employee.class)).thenReturn(employee);
    Mockito.when(tuple2.get(1, Employee.class)).thenReturn(manager2);
    Mockito.when(projectQuery.teamMembers(employees).getManagers()).thenReturn(asList(tuple1, tuple2));
    EasyMock.replay(workdaysCalendarService, hoursRepository, projectRepository, employeeRepository);
    List<WorkTime> expected = asList(new WorkTime(employee, new BigDecimal("16.00"), actualWorkTimeByEmployee.get(employee), managersForApproveByEmployee.get(employee), managersByEmployee.get(employee)));
    List<WorkTime> actual = workTimeService.getProblemWorkTime(filter);
    EasyMock.verify(workdaysCalendarService, hoursRepository, projectRepository, employeeRepository);
    assertEqualsWorkTime(expected.get(0), actual.get(0));
}
Also used : ProjectRepository(com.artezio.arttime.repositories.ProjectRepository) HashMap(java.util.HashMap) Date(java.util.Date) BigDecimal(java.math.BigDecimal) WorkTime(com.artezio.arttime.services.WorkTimeService.WorkTime) EmployeeRepository(com.artezio.arttime.repositories.EmployeeRepository) Filter(com.artezio.arttime.filter.Filter) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Tuple(javax.persistence.Tuple) Test(org.junit.Test)

Example 2 with WorkTime

use of com.artezio.arttime.services.WorkTimeService.WorkTime in project ART-TIME by Artezio.

the class WorkTimeServiceTest method testGetProblemWorkTime_PeriodHasNonWorkingDays.

@Test
public void testGetProblemWorkTime_PeriodHasNonWorkingDays() throws NoSuchFieldException {
    Date date1 = new Date();
    Date date2 = new Date();
    Period period = new Period();
    Employee employee = new Employee("employee");
    Map<Employee, Map<Boolean, BigDecimal>> actualWorkTimeByEmployee = new HashMap<>();
    WorkdaysCalendar calendar = new WorkdaysCalendar("calendar");
    employee.setCalendar(calendar);
    Employee manager1 = new Employee("manager1");
    Employee manager2 = new Employee("manager2");
    Map<Employee, List<Employee>> managersForApproveByEmployee = new HashMap<Employee, List<Employee>>() {

        {
            put(employee, asList(manager1));
        }
    };
    List<Employee> employees = asList(employee);
    Filter filter = new Filter();
    filter.setEmployees(employees);
    filter.setCustomPeriod(period);
    ProjectRepository.ProjectQuery projectQuery = Mockito.mock(ProjectRepository.ProjectQuery.class, Mockito.RETURNS_DEEP_STUBS);
    EmployeeRepository.EmployeeQuery employeeQuery = Mockito.mock(EmployeeRepository.EmployeeQuery.class, Mockito.RETURNS_DEEP_STUBS);
    Tuple tuple1 = Mockito.mock(Tuple.class);
    Tuple tuple2 = Mockito.mock(Tuple.class);
    expect(workdaysCalendarService.getDays(calendar, period)).andReturn(asList(new Day(date1, calendar, false), new Day(date2, calendar, false)));
    expect(hoursRepository.getActualTimeByEmployeeAndApproval(employees, period)).andReturn(actualWorkTimeByEmployee);
    expect(hoursRepository.getManagersForApproveByEmployee(employees, period)).andReturn(managersForApproveByEmployee);
    expect(projectRepository.query(true)).andReturn(projectQuery);
    expect(employeeRepository.query()).andReturn(employeeQuery);
    Mockito.when(employeeQuery.filter(filter).notFormer().list()).thenReturn(employees);
    Mockito.when(tuple1.get(0, Employee.class)).thenReturn(employee);
    Mockito.when(tuple1.get(1, Employee.class)).thenReturn(manager1);
    Mockito.when(tuple2.get(0, Employee.class)).thenReturn(employee);
    Mockito.when(tuple2.get(1, Employee.class)).thenReturn(manager2);
    Mockito.when(projectQuery.teamMembers(employees).getManagers()).thenReturn(asList(tuple1, tuple2));
    EasyMock.replay(workdaysCalendarService, hoursRepository, projectRepository, employeeRepository);
    List<WorkTime> actual = workTimeService.getProblemWorkTime(filter);
    EasyMock.verify(workdaysCalendarService, hoursRepository, projectRepository, employeeRepository);
    assertTrue(actual.isEmpty());
}
Also used : ProjectRepository(com.artezio.arttime.repositories.ProjectRepository) HashMap(java.util.HashMap) Date(java.util.Date) WorkTime(com.artezio.arttime.services.WorkTimeService.WorkTime) EmployeeRepository(com.artezio.arttime.repositories.EmployeeRepository) Filter(com.artezio.arttime.filter.Filter) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Tuple(javax.persistence.Tuple) Test(org.junit.Test)

Example 3 with WorkTime

use of com.artezio.arttime.services.WorkTimeService.WorkTime in project ART-TIME by Artezio.

the class WorkTimeServiceTest method testGetProblemWorkTime_PeriodHasWorkingAndNonWorkingDays.

@Test
public void testGetProblemWorkTime_PeriodHasWorkingAndNonWorkingDays() throws NoSuchFieldException {
    Date date1 = new Date();
    Date date2 = new Date();
    Period period = new Period();
    Employee employee = new Employee("employee");
    Map<Employee, Map<Boolean, BigDecimal>> actualWorkTimeByEmployee = new HashMap<>();
    actualWorkTimeByEmployee.put(employee, new HashMap<Boolean, BigDecimal>() {

        {
            put(false, new BigDecimal(8).setScale(2));
        }
    });
    WorkdaysCalendar calendar = new WorkdaysCalendar("calendar");
    employee.setCalendar(calendar);
    Employee manager1 = new Employee("manager1");
    Employee manager2 = new Employee("manager2");
    Map<Employee, List<Employee>> managersForApproveByEmployee = new HashMap<Employee, List<Employee>>() {

        {
            put(employee, asList(manager1));
        }
    };
    Map<Employee, List<Employee>> managersByEmployee = new HashMap<Employee, List<Employee>>() {

        {
            put(employee, asList(manager1, manager2));
        }
    };
    List<Employee> employees = asList(employee);
    Filter filter = new Filter();
    filter.setEmployees(employees);
    filter.setCustomPeriod(period);
    ProjectRepository.ProjectQuery projectQuery = Mockito.mock(ProjectRepository.ProjectQuery.class, Mockito.RETURNS_DEEP_STUBS);
    EmployeeRepository.EmployeeQuery employeeQuery = Mockito.mock(EmployeeRepository.EmployeeQuery.class, Mockito.RETURNS_DEEP_STUBS);
    Tuple tuple1 = Mockito.mock(Tuple.class);
    Tuple tuple2 = Mockito.mock(Tuple.class);
    expect(workdaysCalendarService.getDays(anyObject(WorkdaysCalendar.class), anyObject(Period.class))).andReturn(asList(new Day(date1, calendar, true), new Day(date2, calendar, false)));
    expect(hoursRepository.getActualTimeByEmployeeAndApproval(employees, period)).andReturn(actualWorkTimeByEmployee);
    expect(hoursRepository.getManagersForApproveByEmployee(employees, period)).andReturn(managersForApproveByEmployee);
    expect(projectRepository.query(true)).andReturn(projectQuery);
    expect(employeeRepository.query()).andReturn(employeeQuery);
    Mockito.when(employeeQuery.filter(filter).notFormer().list()).thenReturn(employees);
    Mockito.when(tuple1.get(0, Employee.class)).thenReturn(employee);
    Mockito.when(tuple1.get(1, Employee.class)).thenReturn(manager1);
    Mockito.when(tuple2.get(0, Employee.class)).thenReturn(employee);
    Mockito.when(tuple2.get(1, Employee.class)).thenReturn(manager2);
    Mockito.when(projectQuery.teamMembers(employees).getManagers()).thenReturn(asList(tuple1, tuple2));
    EasyMock.replay(workdaysCalendarService, hoursRepository, projectRepository, employeeRepository);
    List<WorkTime> expected = asList(new WorkTime(employee, new BigDecimal("8.00"), actualWorkTimeByEmployee.get(employee), managersForApproveByEmployee.get(employee), managersByEmployee.get(employee)));
    List<WorkTime> actual = workTimeService.getProblemWorkTime(filter);
    EasyMock.verify(workdaysCalendarService, hoursRepository, projectRepository, employeeRepository);
    assertEqualsWorkTime(expected.get(0), actual.get(0));
}
Also used : ProjectRepository(com.artezio.arttime.repositories.ProjectRepository) HashMap(java.util.HashMap) Date(java.util.Date) BigDecimal(java.math.BigDecimal) WorkTime(com.artezio.arttime.services.WorkTimeService.WorkTime) EmployeeRepository(com.artezio.arttime.repositories.EmployeeRepository) Filter(com.artezio.arttime.filter.Filter) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Tuple(javax.persistence.Tuple) Test(org.junit.Test)

Aggregations

Filter (com.artezio.arttime.filter.Filter)3 EmployeeRepository (com.artezio.arttime.repositories.EmployeeRepository)3 ProjectRepository (com.artezio.arttime.repositories.ProjectRepository)3 WorkTime (com.artezio.arttime.services.WorkTimeService.WorkTime)3 Arrays.asList (java.util.Arrays.asList)3 Collections.emptyList (java.util.Collections.emptyList)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 Tuple (javax.persistence.Tuple)3 Test (org.junit.Test)3 BigDecimal (java.math.BigDecimal)2