use of com.artezio.arttime.filter.Filter in project ART-TIME by Artezio.
the class WorkTimeServiceTest method testCheckListAllManagers_ifEmployeeRemoveFromProject.
@Test
public void testCheckListAllManagers_ifEmployeeRemoveFromProject() throws NoSuchFieldException {
Date start = new Date();
Date finish = getOffsetDate(1);
Period period = new Period(start, finish);
Employee employee = new Employee("employee");
WorkdaysCalendar calendar = new WorkdaysCalendar("calendar");
employee.setCalendar(calendar);
Employee managerActiveProject = new Employee("manager1");
Employee managerRemoveEmployee = new Employee("manager2");
List<Employee> employees = Arrays.asList(employee);
Project project1 = new Project();
project1.addTeamMember(employee);
project1.addManager(managerActiveProject);
Project project2 = new Project();
project2.addTeamMember(employee);
project2.addManager(managerRemoveEmployee);
project2.removeTeamMember(employee);
HourType actualType = new HourType("actual type");
actualType.setActualTime(true);
BigDecimal quantity1 = new BigDecimal(3);
BigDecimal quantity2 = new BigDecimal(10);
Hours hours1 = createHours(project1, employee, new Date(), actualType, quantity1);
Hours hours2 = createHours(project2, employee, getOffsetDate(1), actualType, quantity2);
Hours hours3 = createHours(project2, employee, new Date(), actualType, quantity2);
hours1.setApproved(true);
hours2.setApproved(false);
hours3.setApproved(true);
Filter filter = new Filter();
filter.setEmployees(employees);
filter.setCustomPeriod(period);
entityManager.persist(employee);
entityManager.persist(managerActiveProject);
entityManager.persist(managerRemoveEmployee);
entityManager.persist(calendar);
entityManager.persist(actualType);
entityManager.persist(project1);
entityManager.persist(project2);
entityManager.persist(hours1);
entityManager.persist(hours2);
entityManager.persist(hours3);
entityManager.flush();
entityManager.clear();
setField(workTimeService, "employeeRepository", employeeRepository);
expect(employeeRepository.getEmployeesByDepartments(filter)).andReturn(employees);
replay(employeeRepository);
List<Efforts> actual = workTimeService.getEmployeesTimeProblems(filter);
assertEquals(actual.get(0).getAllManagers().size(), 2);
}
use of com.artezio.arttime.filter.Filter in project ART-TIME by Artezio.
the class WorkTimeServiceTest method testGetEmployees_FilterHasEmployeesAndHasNoDepartments.
@Test
public void testGetEmployees_FilterHasEmployeesAndHasNoDepartments() throws NoSuchFieldException {
Employee emp1 = new Employee();
emp1.setDepartment("dep1");
Employee emp2 = new Employee();
emp2.setDepartment("dep2");
Filter filter = new Filter();
filter.setEmployees(Collections.singletonList(emp1));
filter.setDepartments(Collections.emptyList());
setField(workTimeService, "employeeRepository", employeeRepository);
expect(employeeRepository.getEmployeesByDepartments(filter)).andReturn(filter.getEmployees());
replay(employeeRepository);
List<Employee> actual = workTimeService.getEmployees(filter);
ListAssert.assertEquals(filter.getEmployees(), actual);
}
use of com.artezio.arttime.filter.Filter in project ART-TIME by Artezio.
the class EmployeeRepositoryTest method testGetEmployeesByDepartments_ifEmployeesDepartmentsAreEmpty.
@Test
public void testGetEmployeesByDepartments_ifEmployeesDepartmentsAreEmpty() {
Employee employee1 = new Employee("employee1");
employee1.setDepartment("department1");
Employee employee2 = new Employee("employee2");
employee2.setDepartment("department2");
Employee employee3 = new Employee("employee3");
employee3.setDepartment("department3");
Project project1 = new Project();
project1.addTeamMember(employee1);
project1.addTeamMember(employee2);
Project project2 = new Project();
project2.addTeamMember(employee1);
project2.addTeamMember(employee3);
Filter filter = new Filter();
filter.setEmployees(Collections.emptyList());
filter.setDepartments(Collections.emptyList());
entityManager.persist(project1);
entityManager.persist(project2);
entityManager.persist(employee1);
entityManager.persist(employee2);
entityManager.persist(employee3);
entityManager.flush();
List<Employee> expected = Arrays.asList(employee1, employee2, employee3);
List<Employee> actual = employeeRepository.getEmployeesByDepartments(filter);
ListAssert.assertEquals(expected, actual);
}
use of com.artezio.arttime.filter.Filter in project ART-TIME by Artezio.
the class EmployeeRepositoryTest method testGetEmployeesByDepartments_ifEmployeesAreEmpty_FilterHasNotAllDepartments.
@Test
public void testGetEmployeesByDepartments_ifEmployeesAreEmpty_FilterHasNotAllDepartments() {
Employee employee1 = new Employee("employee1");
employee1.setDepartment("dep1");
Employee employee2 = new Employee("employee2");
employee2.setDepartment("dep2");
Employee employee3 = new Employee("employee3");
employee3.setDepartment("dep3");
Filter filter = new Filter();
filter.setEmployees(Arrays.asList(employee1, employee2));
filter.setDepartments(Arrays.asList("dep1", "dep2"));
entityManager.persist(employee1);
entityManager.persist(employee2);
entityManager.persist(employee3);
List<Employee> expected = filter.getEmployees();
List<Employee> actual = employeeRepository.getEmployeesByDepartments(filter);
ListAssert.assertEquals(expected, actual);
}
use of com.artezio.arttime.filter.Filter in project ART-TIME by Artezio.
the class FilterRepositoryTest method testFetchDetails.
@Test
public void testFetchDetails() throws NoSuchMethodException, SecurityException, NoSuchFieldException {
Filter filter = new Filter();
Project project = new Project();
List<Project> projects = Arrays.asList(project);
filter.setProjects(projects);
Project projectLoaded = new Project();
List<Project> projectsLoaded = Arrays.asList(projectLoaded);
entityManager.persist(project);
entityManager.persist(projectLoaded);
entityManager.persist(filter);
Method fetchCompleteMethod = ProjectRepository.class.getMethod("fetchComplete", List.class);
projectRepository = EasyMock.createMockBuilder(ProjectRepository.class).addMockedMethod(fetchCompleteMethod).createMock();
setField(filterRepository, "projectRepository", projectRepository);
PowerMock.mockStatic(Hibernate.class);
Hibernate.initialize(filter.getDepartments());
Hibernate.initialize(filter.getEmployees());
Hibernate.initialize(filter.getProjects());
Hibernate.initialize(filter.getHourTypes());
EasyMock.expect(projectRepository.fetchComplete(projects)).andReturn(projectsLoaded);
PowerMock.replayAll(Hibernate.class, projectRepository);
filterRepository.fetchDetails(filter);
PowerMock.verifyAll();
assertSame(projectLoaded, filter.getProjects().get(0));
}
Aggregations