Search in sources :

Example 46 with Employee

use of com.artezio.arttime.datamodel.Employee in project ART-TIME by Artezio.

the class SpreadSheetTest method testGetSortedProjects_FilterHasNoProjects.

@Test
public void testGetSortedProjects_FilterHasNoProjects() throws NoSuchFieldException {
    List<Employee> employees = new ArrayList<>();
    List<HourType> hourTypes = new ArrayList<>();
    List<Project> expected = buildProjectList(2, hourTypes, employees);
    setField(filter, "projects", new ArrayList<>());
    setField(spreadSheet, "filter", filter);
    setField(spreadSheet, "projectRepository", projectRepository);
    setField(spreadSheet, "projectService", projectService);
    expect(projectRepository.fetchComplete(expected)).andReturn(expected);
    expect(projectService.getAvailableProjects(anyObject())).andReturn(expected);
    replay(projectRepository, projectService);
    List<Project> actual = spreadSheet.getSortedProjects(new Employee());
    assertEquals(expected, actual);
}
Also used : Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) HourType(com.artezio.arttime.datamodel.HourType) Test(org.junit.Test)

Example 47 with Employee

use of com.artezio.arttime.datamodel.Employee in project ART-TIME by Artezio.

the class SpreadSheetTest method testGetSortedTeamMembers_FilterHasEmployeesAndDepartments.

@Test
public void testGetSortedTeamMembers_FilterHasEmployeesAndDepartments() throws NoSuchFieldException {
    List<Employee> employees = buildEmployeeList(2);
    List<String> departments = employees.stream().map(Employee::getDepartment).collect(Collectors.toList());
    HourType hourType = new HourType("1");
    List<HourType> hourTypes = Collections.singletonList(hourType);
    Project project = createProject("1", hourTypes, employees);
    List<Hours> hours = buildHourList(project, employees, hourType, new Date(2017, 1, 1));
    setField(filter, "employees", employees);
    setField(filter, "departments", departments);
    setField(spreadSheet, "filter", filter);
    setField(spreadSheet, "workTimeService", workTimeService);
    expect(workTimeService.getEmployees(filter)).andReturn(employees);
    replay(workTimeService);
    SortedSet<Employee> expected = new TreeSet<>(Employee.NAME_COMPARATOR);
    expected.addAll(employees);
    SortedSet<Employee> actual = spreadSheet.getSortedTeamMembers(project, hours);
    assertEquals(expected, actual);
}
Also used : Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) HourType(com.artezio.arttime.datamodel.HourType) Hours(com.artezio.arttime.datamodel.Hours) Test(org.junit.Test)

Example 48 with Employee

use of com.artezio.arttime.datamodel.Employee in project ART-TIME by Artezio.

the class SpreadSheetTest method testGetSortedTeamMembers_FilterHasEmployeesNotCorrespondingToDepartments.

@Test
public void testGetSortedTeamMembers_FilterHasEmployeesNotCorrespondingToDepartments() throws NoSuchFieldException {
    List<Employee> employees = buildEmployeeList(2);
    List<String> departments = asList("dep1", "dep2");
    HourType hourType = new HourType("1");
    List<HourType> hourTypes = Collections.singletonList(hourType);
    Project project = createProject("1", hourTypes, employees);
    List<Hours> hours = buildHourList(project, employees, hourType, new Date(2017, 1, 1));
    setField(filter, "employees", employees);
    setField(filter, "departments", departments);
    setField(spreadSheet, "filter", filter);
    setField(spreadSheet, "employeeRepository", employeeRepository);
    setField(spreadSheet, "workTimeService", workTimeService);
    expect(workTimeService.getEmployees(filter)).andReturn(Collections.emptyList());
    replay(workTimeService);
    SortedSet<Employee> actual = spreadSheet.getSortedTeamMembers(project, hours);
    assertTrue(actual.isEmpty());
}
Also used : Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) HourType(com.artezio.arttime.datamodel.HourType) Hours(com.artezio.arttime.datamodel.Hours) Test(org.junit.Test)

Example 49 with Employee

use of com.artezio.arttime.datamodel.Employee in project ART-TIME by Artezio.

the class FilterServiceTest method testCreatePersonalTimesheetFilter.

@Test
public void testCreatePersonalTimesheetFilter() throws NoSuchFieldException {
    setField(filterService, "hourTypeRepository", hourTypeRepository);
    setField(filterService, "projectRepository", projectRepository);
    setField(filterService, "departmentRepository", departmentRepository);
    Filter currentFilter = new Filter();
    RangePeriodSelector currentPeriodSelector = new RangePeriodSelector(new Period(new Date(1), new Date(2)));
    currentFilter.setRangePeriodSelector(currentPeriodSelector);
    Employee employee = new Employee("user");
    expect(departmentRepository.getDepartments()).andReturn(Collections.emptyList());
    expect(hourTypeRepository.getAll()).andReturn(Collections.emptyList());
    expect(projectRepository.getActiveAndReportedProjects(employee, currentFilter.getPeriod())).andReturn(Collections.emptyList());
    replay(departmentRepository, hourTypeRepository, projectRepository);
    Filter actual = filterService.createPersonalTimesheetFilter(currentFilter, employee);
    verify(departmentRepository, hourTypeRepository, projectRepository);
    assertEquals(currentFilter.getPeriod(), actual.getPeriod());
    assertEquals(1, actual.getEmployees().size());
    assertEquals(employee, actual.getEmployees().get(0));
}
Also used : Employee(com.artezio.arttime.datamodel.Employee) RangePeriodSelector(com.artezio.arttime.web.criteria.RangePeriodSelector) Period(com.artezio.arttime.datamodel.Period) Test(org.junit.Test)

Example 50 with Employee

use of com.artezio.arttime.datamodel.Employee in project ART-TIME by Artezio.

the class ManageProjectPermissionFilterTest method testIsAccessAllowed_ifPM_andProjectNotManagedTheEmployee.

@Test
public void testIsAccessAllowed_ifPM_andProjectNotManagedTheEmployee() throws Exception {
    Project project = new Project();
    Employee employee = new Employee("employee");
    mockStatic(SecurityUtils.class);
    expect(SecurityUtils.getSubject()).andReturn(subject);
    expect(subject.hasRole(UserRoles.EXEC_ROLE)).andReturn(false);
    expect(subject.hasRole(UserRoles.PM_ROLE)).andReturn(true);
    expect(servletRequest.getParameter("project")).andReturn("1");
    expect(subject.getPrincipal()).andReturn("employee");
    expect(projectRepository.findProject(1L)).andReturn(project);
    expect(employeeRepository.find("employee")).andReturn(employee);
    replayAll(SecurityUtils.class);
    replay(subject, servletRequest, projectRepository, employeeRepository);
    boolean actual = filter.isAccessAllowed(servletRequest, servletResponse, null);
    verifyAll();
    assertFalse(actual);
}
Also used : Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Employee (com.artezio.arttime.datamodel.Employee)201 Test (org.junit.Test)173 Project (com.artezio.arttime.datamodel.Project)121 HourType (com.artezio.arttime.datamodel.HourType)74 Hours (com.artezio.arttime.datamodel.Hours)65 Date (java.util.Date)39 BigDecimal (java.math.BigDecimal)33 Period (com.artezio.arttime.datamodel.Period)28 Filter (com.artezio.arttime.filter.Filter)23 ArrayList (java.util.ArrayList)20 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)19 CalendarUtils.getOffsetDate (com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate)18 CalendarUtils.createPeriod (com.artezio.arttime.test.utils.CalendarUtils.createPeriod)15 TeamFilter (com.artezio.arttime.datamodel.TeamFilter)13 HashMap (java.util.HashMap)12 WorkdaysCalendar (com.artezio.arttime.datamodel.WorkdaysCalendar)7 Mail (com.artezio.arttime.services.mailing.Mail)7 ProjectRepository (com.artezio.arttime.services.repositories.ProjectRepository)7 List (java.util.List)7 Map (java.util.Map)7