Search in sources :

Example 1 with ProjectRepository

use of com.artezio.arttime.repositories.ProjectRepository 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 ProjectRepository

use of com.artezio.arttime.repositories.ProjectRepository 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 ProjectRepository

use of com.artezio.arttime.repositories.ProjectRepository 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)

Example 4 with ProjectRepository

use of com.artezio.arttime.repositories.ProjectRepository in project ART-TIME by Artezio.

the class NotificationManagerTest method testGetProjects.

@Test
public void testGetProjects() throws NoSuchFieldException {
    setMockServices(notificationManager);
    Employee employee1 = createEmployee("iivanov", "Ivan", "Ivanov");
    Employee employee2 = createEmployee("ppetrov", "Petr", "Petrov");
    Employee employee3 = createEmployee("asidorov", "Andrey", "Sidorov");
    Employee employee4 = createEmployee("afedorov", "Andrey", "Fedorov");
    Project project1 = createProject(1L, employee1);
    Project project2 = createProject(2L, employee1, employee2, employee3);
    List<Employee> employees = Arrays.asList(employee1, employee2, employee4);
    ProjectRepository.ProjectQuery projectQuery = Mockito.mock(ProjectRepository.ProjectQuery.class, Mockito.RETURNS_DEEP_STUBS);
    List<Project> expected = Arrays.asList(project1, project2);
    EasyMock.expect(projectRepository.query()).andReturn(projectQuery);
    Mockito.when(projectQuery.status(ACTIVE).teamMembers(employees).fetchManagers().fetchTeam().list()).thenReturn(expected);
    EasyMock.replay(projectRepository);
    List<Project> actual = notificationManager.getProjects(employees);
    assertEquals(expected, actual);
    EasyMock.verify(projectRepository);
}
Also used : Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) ProjectRepository(com.artezio.arttime.repositories.ProjectRepository) Test(org.junit.Test)

Example 5 with ProjectRepository

use of com.artezio.arttime.repositories.ProjectRepository in project ART-TIME by Artezio.

the class ProjectServiceTest method testGetProjectHierarchy_ProjectHasNoSubprojects.

@Test
public void testGetProjectHierarchy_ProjectHasNoSubprojects() {
    Project master = createProject(1L, null);
    List<Project> expected = asList(master);
    ProjectRepository.ProjectQuery projectQuery = Mockito.mock(ProjectRepository.ProjectQuery.class, Mockito.RETURNS_DEEP_STUBS);
    EasyMock.expect(projectRepository.query()).andReturn(projectQuery).once();
    Mockito.when(projectQuery.masters(asList(master)).status(ACTIVE).distinct().list()).thenReturn(emptyList());
    replay(projectRepository);
    List<Project> actual = projectService.getProjectHierarchy(master);
    EasyMock.verify(projectRepository);
    ListAssert.assertEquals(expected, actual);
}
Also used : Project(com.artezio.arttime.datamodel.Project) ProjectRepository(com.artezio.arttime.repositories.ProjectRepository) Test(org.junit.Test)

Aggregations

ProjectRepository (com.artezio.arttime.repositories.ProjectRepository)19 Test (org.junit.Test)19 Project (com.artezio.arttime.datamodel.Project)15 Employee (com.artezio.arttime.datamodel.Employee)8 TeamFilter (com.artezio.arttime.datamodel.TeamFilter)6 Date (java.util.Date)4 Filter (com.artezio.arttime.filter.Filter)3 EmployeeRepository (com.artezio.arttime.repositories.EmployeeRepository)3 WorkTime (com.artezio.arttime.services.WorkTimeService.WorkTime)3 Arrays.asList (java.util.Arrays.asList)3 Collections.emptyList (java.util.Collections.emptyList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 Tuple (javax.persistence.Tuple)3 BigDecimal (java.math.BigDecimal)2 HourType (com.artezio.arttime.datamodel.HourType)1 Hours (com.artezio.arttime.datamodel.Hours)1 HoursRepository (com.artezio.arttime.repositories.HoursRepository)1 CalendarUtils.getOffsetDate (com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate)1