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));
}
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());
}
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));
}
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);
}
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);
}
Aggregations