use of com.artezio.arttime.repositories.EmployeeRepository 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.EmployeeRepository 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.EmployeeRepository 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.EmployeeRepository in project ART-TIME by Artezio.
the class DepartmentServiceTest method testSetCalendar_departmentHadNoCalendar.
@Test
public void testSetCalendar_departmentHadNoCalendar() throws NoSuchFieldException {
String department = "ExpectedDepartment";
WorkdaysCalendar otherStoredCalendar = new WorkdaysCalendar("OtherStoredCalendar");
setField(otherStoredCalendar, "id", 2L);
WorkdaysCalendar newCalendar = new WorkdaysCalendar("NewCalendar");
setField(newCalendar, "id", 3L);
Set<String> newDepts = new HashSet<>();
newDepts.add("SomeDepartment");
newCalendar.setDepartments(newDepts);
Employee employee1 = new Employee();
Employee employee2 = new Employee();
Employee employee3 = new Employee();
employee3.setCalendar(otherStoredCalendar);
List<Employee> employees = asList(employee1, employee2, employee3);
EmployeeRepository.EmployeeQuery query = Mockito.mock(EmployeeRepository.EmployeeQuery.class, RETURNS_DEEP_STUBS);
Mockito.when(query.department(department).list()).thenReturn(employees);
EasyMock.expect(employeeRepository.query()).andReturn(query);
EasyMock.expect(workdaysCalendarRepository.findByDepartment(department)).andReturn(null);
EasyMock.expect(workdaysCalendarRepository.attachAndRefresh(newCalendar)).andReturn(newCalendar);
EasyMock.replay(employeeRepository, workdaysCalendarRepository);
departmentService.setCalendarToDepartment(department, newCalendar);
EasyMock.verify(employeeRepository, workdaysCalendarRepository);
assertTrue(newCalendar.getDepartments().contains(department));
assertEquals(newCalendar, employee1.getCalendar());
assertEquals(newCalendar, employee2.getCalendar());
assertEquals(otherStoredCalendar, employee3.getCalendar());
}
use of com.artezio.arttime.repositories.EmployeeRepository in project ART-TIME by Artezio.
the class DepartmentServiceTest method testSetCalendar_departmentHadCalendar.
@Test
public void testSetCalendar_departmentHadCalendar() throws NoSuchFieldException {
String department = "ExpectedDepartment";
WorkdaysCalendar storedCalendar = new WorkdaysCalendar("StoredCalendar");
setField(storedCalendar, "id", 1L);
WorkdaysCalendar otherStoredCalendar = new WorkdaysCalendar("OtherStoredCalendar");
setField(otherStoredCalendar, "id", 2L);
WorkdaysCalendar newCalendar = new WorkdaysCalendar("NewCalendar");
setField(newCalendar, "id", 3L);
Set<String> newDepts = new HashSet<>();
newDepts.add("SomeDepartment");
newCalendar.setDepartments(newDepts);
Set<String> storedDepts = new HashSet<>();
storedDepts.add(department);
storedCalendar.setDepartments(storedDepts);
Employee employee1 = new Employee();
employee1.setCalendar(storedCalendar);
Employee employee2 = new Employee();
Employee employee3 = new Employee();
employee3.setCalendar(otherStoredCalendar);
List<Employee> employees = asList(employee1, employee2, employee3);
EmployeeRepository.EmployeeQuery query = Mockito.mock(EmployeeRepository.EmployeeQuery.class, RETURNS_DEEP_STUBS);
Mockito.when(query.department(department).list()).thenReturn(employees);
EasyMock.expect(employeeRepository.query()).andReturn(query);
EasyMock.expect(workdaysCalendarRepository.findByDepartment(department)).andReturn(storedCalendar);
EasyMock.expect(workdaysCalendarRepository.attachAndRefresh(newCalendar)).andReturn(newCalendar);
EasyMock.replay(employeeRepository, workdaysCalendarRepository);
departmentService.setCalendarToDepartment(department, newCalendar);
EasyMock.verify(employeeRepository, workdaysCalendarRepository);
assertTrue(newCalendar.getDepartments().contains(department));
assertEquals(newCalendar, employee1.getCalendar());
assertEquals(newCalendar, employee2.getCalendar());
assertEquals(otherStoredCalendar, employee3.getCalendar());
}
Aggregations