Search in sources :

Example 61 with Filter

use of com.artezio.arttime.filter.Filter in project ART-TIME by Artezio.

the class WorkTimeServiceTest method testGetApprovedWorkTimeProblems_NoProblems.

@Test
public void testGetApprovedWorkTimeProblems_NoProblems() throws NoSuchFieldException {
    Date start = new Date();
    Date finish = getOffsetDate(1);
    Period period = new Period(start, finish);
    WorkdaysCalendar calendar = new WorkdaysCalendar("calendar");
    Day day1 = new Day(start, calendar, true);
    Day day2 = new Day(getOffsetDate(1), calendar, true);
    Employee employee = new Employee("employee");
    employee.setCalendar(calendar);
    List<Employee> employees = Arrays.asList(employee);
    Project project = new Project();
    project.addTeamMember(employee);
    HourType actualType = new HourType("actual type");
    actualType.setActualTime(true);
    Hours hours1 = createHours(project, employee, start, actualType, new BigDecimal(8));
    Hours hours2 = createHours(project, employee, getOffsetDate(1), actualType, new BigDecimal(8));
    hours1.setApproved(true);
    hours2.setApproved(true);
    Filter filter = new Filter();
    filter.setCustomPeriod(period);
    filter.setEmployees(employees);
    entityManager.persist(employee);
    entityManager.persist(calendar);
    entityManager.persist(actualType);
    entityManager.persist(project);
    entityManager.persist(hours1);
    entityManager.persist(hours2);
    entityManager.persist(day1);
    entityManager.persist(day2);
    entityManager.flush();
    entityManager.clear();
    setField(workTimeService, "employeeRepository", employeeRepository);
    expect(employeeRepository.getEmployeesByDepartments(filter)).andReturn(employees);
    replay(employeeRepository);
    List<WorkTimeService.Efforts> actual = workTimeService.getEmployeesTimeProblems(filter);
    assertTrue(actual.isEmpty());
}
Also used : Efforts(com.artezio.arttime.services.WorkTimeService.Efforts) BigDecimal(java.math.BigDecimal) Filter(com.artezio.arttime.filter.Filter) Test(org.junit.Test)

Example 62 with Filter

use of com.artezio.arttime.filter.Filter in project ART-TIME by Artezio.

the class WorkTimeServiceTest method testGetApprovedWorkTimeProblems_existUnapprovedTime.

@Test
public void testGetApprovedWorkTimeProblems_existUnapprovedTime() throws NoSuchFieldException {
    Date start = new Date();
    Date finish = getOffsetDate(1);
    Period period = new Period(start, finish);
    WorkdaysCalendar calendar = new WorkdaysCalendar("calendar");
    Day day1 = new Day(new Date(), calendar, true);
    Day day2 = new Day(getOffsetDate(1), calendar, true);
    Employee employee = new Employee("employee");
    employee.setCalendar(calendar);
    Employee manager = new Employee("manager");
    List<Employee> employees = Arrays.asList(employee);
    Project project = new Project();
    project.addTeamMember(employee);
    project.addManager(manager);
    HourType actualType = new HourType("actual type");
    actualType.setActualTime(true);
    BigDecimal quantity1 = new BigDecimal(3);
    BigDecimal quantity2 = new BigDecimal(10);
    Hours hours1 = createHours(project, employee, new Date(), actualType, quantity1);
    Hours hours2 = createHours(project, employee, getOffsetDate(1), actualType, quantity2);
    hours1.setApproved(true);
    hours2.setApproved(false);
    Filter filter = new Filter();
    filter.setCustomPeriod(period);
    filter.setEmployees(employees);
    entityManager.persist(employee);
    entityManager.persist(manager);
    entityManager.persist(calendar);
    entityManager.persist(actualType);
    entityManager.persist(project);
    entityManager.persist(hours1);
    entityManager.persist(hours2);
    entityManager.persist(day1);
    entityManager.persist(day2);
    entityManager.flush();
    entityManager.clear();
    setField(workTimeService, "employeeRepository", employeeRepository);
    expect(employeeRepository.getEmployeesByDepartments(filter)).andReturn(employees);
    replay(employeeRepository);
    List<WorkTimeService.Efforts> actuals = workTimeService.getEmployeesTimeProblems(filter);
    WorkTimeService.Efforts actual = actuals.get(0);
    assertEquals(1, actuals.size());
    assertEquals(employee, actual.getEmployee());
    assertEquals(new BigDecimal("16.00"), actual.getRequiredTime());
    assertEquals(new BigDecimal("3.00"), actual.getApprovedTime());
    assertEquals(new BigDecimal("10.00"), actual.getUnapprovedTime());
    assertEquals(new BigDecimal("-13.00"), actual.getTimeDeviation());
    assertEquals(Arrays.asList(manager), actual.getWaitingApprovalBy());
    assertEquals(Arrays.asList(manager), actual.getAllManagers());
}
Also used : Efforts(com.artezio.arttime.services.WorkTimeService.Efforts) BigDecimal(java.math.BigDecimal) Filter(com.artezio.arttime.filter.Filter) Efforts(com.artezio.arttime.services.WorkTimeService.Efforts) Test(org.junit.Test)

Example 63 with Filter

use of com.artezio.arttime.filter.Filter in project ART-TIME by Artezio.

the class EmployeeRepositoryTest method testGetEmployeesByDepartments.

@Test
public void testGetEmployeesByDepartments() {
    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);
    entityManager.persist(project1);
    entityManager.persist(project2);
    entityManager.persist(employee1);
    entityManager.persist(employee2);
    entityManager.persist(employee3);
    Filter filter = new Filter();
    filter.setProjects(Arrays.asList(project1, project2));
    filter.setEmployees(Arrays.asList(employee1, employee2, employee3));
    filter.setDepartments(Arrays.asList("department1", "department2", "department3"));
    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 64 with Filter

use of com.artezio.arttime.filter.Filter in project ART-TIME by Artezio.

the class EmployeeRepositoryTest method testGetEmployeesByDepartments_ifEmployeesAreEmpty.

@Test
public void testGetEmployeesByDepartments_ifEmployeesAreEmpty() {
    Employee employee1 = new Employee("employee1", "test1", "test1", "department1");
    Employee employee2 = new Employee("employee2", "test2", "test2", "department2");
    Filter filter = new Filter();
    filter.setEmployees(Collections.emptyList());
    filter.setDepartments(Arrays.asList("department1", "department2"));
    entityManager.persist(employee1);
    entityManager.persist(employee2);
    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 65 with Filter

use of com.artezio.arttime.filter.Filter in project ART-TIME by Artezio.

the class EmployeeRepositoryTest method testGetEmployeesByDepartments_ifDepartmentsAreEmpty_FilterHasNotAllEmployees.

@Test
public void testGetEmployeesByDepartments_ifDepartmentsAreEmpty_FilterHasNotAllEmployees() {
    Employee employee1 = new Employee("employee1");
    Employee employee2 = new Employee("employee2");
    Employee employee3 = new Employee("employee3");
    Filter filter = new Filter();
    filter.setEmployees(Arrays.asList(employee1, employee2));
    filter.setDepartments(Collections.emptyList());
    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)

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