Search in sources :

Example 11 with Filter

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);
}
Also used : Filter(com.artezio.arttime.filter.Filter) Efforts(com.artezio.arttime.services.WorkTimeService.Efforts) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 12 with Filter

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);
}
Also used : Filter(com.artezio.arttime.filter.Filter) Test(org.junit.Test)

Example 13 with Filter

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);
}
Also used : Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) Filter(com.artezio.arttime.filter.Filter) Test(org.junit.Test)

Example 14 with Filter

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);
}
Also used : Employee(com.artezio.arttime.datamodel.Employee) Filter(com.artezio.arttime.filter.Filter) Test(org.junit.Test)

Example 15 with Filter

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));
}
Also used : Project(com.artezio.arttime.datamodel.Project) ProjectRepository(com.artezio.arttime.services.repositories.ProjectRepository) Filter(com.artezio.arttime.filter.Filter) Method(java.lang.reflect.Method) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Filter (com.artezio.arttime.filter.Filter)126 Test (org.junit.Test)110 Project (com.artezio.arttime.datamodel.Project)32 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)25 Employee (com.artezio.arttime.datamodel.Employee)24 RangePeriodSelector (com.artezio.arttime.web.criteria.RangePeriodSelector)16 Date (java.util.Date)9 BigDecimal (java.math.BigDecimal)8 Hours (com.artezio.arttime.datamodel.Hours)7 Arrays.asList (java.util.Arrays.asList)7 List (java.util.List)7 HourType (com.artezio.arttime.datamodel.HourType)5 Efforts (com.artezio.arttime.services.WorkTimeService.Efforts)5 CalendarUtils.getOffsetDate (com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate)5 ArrayList (java.util.ArrayList)4 Collections.emptyList (java.util.Collections.emptyList)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Period (com.artezio.arttime.datamodel.Period)3 EmployeeRepository (com.artezio.arttime.repositories.EmployeeRepository)3