Search in sources :

Example 6 with HourType

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

the class ProjectEffortsSpreadSheetTest method createSubprojects.

private Map<Project, List<Project>> createSubprojects() throws NoSuchFieldException {
    HourType hourType = filter.getHourTypes().get(0);
    Employee employee = filter.getEmployees().get(0);
    Project master = filter.getProjects().get(0);
    Project subproject = createProject("subproject", asList(hourType), asList(employee));
    setField(subproject, "id", 3L);
    setField(subproject, "master", master);
    Map<Project, List<Project>> result = filter.getProjects().stream().collect(Collectors.toMap(p -> p, p -> new ArrayList<Project>()));
    result.get(master).add(subproject);
    return result;
}
Also used : java.util(java.util) Filter(com.artezio.arttime.filter.Filter) Period(com.artezio.arttime.datamodel.Period) Mock(org.easymock.Mock) RunWith(org.junit.runner.RunWith) PrivateAccessor.setField(junitx.util.PrivateAccessor.setField) SimpleDateFormat(java.text.SimpleDateFormat) Employee(com.artezio.arttime.datamodel.Employee) BigDecimal(java.math.BigDecimal) Arrays.asList(java.util.Arrays.asList) EasyMockRunner(org.easymock.EasyMockRunner) ParseException(java.text.ParseException) ProjectService(com.artezio.arttime.services.ProjectService) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) Collections.emptyList(java.util.Collections.emptyList) HourTypeRepository(com.artezio.arttime.services.repositories.HourTypeRepository) ProjectRepository(com.artezio.arttime.services.repositories.ProjectRepository) TestSubject(org.easymock.TestSubject) Test(org.junit.Test) EasyMock(org.easymock.EasyMock) Collectors(java.util.stream.Collectors) ListAssert(junitx.framework.ListAssert) HourType(com.artezio.arttime.datamodel.HourType) Project(com.artezio.arttime.datamodel.Project) EmployeeRepository(com.artezio.arttime.services.repositories.EmployeeRepository) WorkTimeService(com.artezio.arttime.services.WorkTimeService) HoursRepository(com.artezio.arttime.services.repositories.HoursRepository) RangePeriodSelector(com.artezio.arttime.web.criteria.RangePeriodSelector) Assert(org.junit.Assert) Hours(com.artezio.arttime.datamodel.Hours) Project(com.artezio.arttime.datamodel.Project) HourType(com.artezio.arttime.datamodel.HourType) Employee(com.artezio.arttime.datamodel.Employee) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList)

Example 7 with HourType

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

the class ProjectEffortsSpreadSheetTest method testBuildSpreadSheetRows.

@Test
public void testBuildSpreadSheetRows() throws ParseException, NoSuchFieldException {
    Employee employee1 = filter.getEmployees().get(0);
    Employee employee2 = filter.getEmployees().get(1);
    Project project1 = filter.getProjects().get(0);
    Project project2 = filter.getProjects().get(1);
    HourType hourType1 = filter.getHourTypes().get(0);
    HourType hourType2 = filter.getHourTypes().get(1);
    List<Hours> hours = getHours();
    expect(hoursRepository.getHours(filter)).andReturn(hours);
    Map<Project, List<Project>> subprojects = createSubprojects();
    expect(projectService.getHighlevelOnly(filter.getProjects())).andReturn(filter.getProjects());
    expect(projectRepository.getSubprojectsMap(filter.getProjects())).andReturn(subprojects);
    expect(workTimeService.getEmployees(filter)).andReturn(Arrays.asList(employee1, employee2)).anyTimes();
    replay(hoursRepository, projectRepository, workTimeService, projectService);
    List<SpreadSheetRow<?>> actual = spreadSheet.buildSpreadSheetRows(new Employee());
    verify(hoursRepository, projectRepository);
    assertEquals(15, actual.size());
    // master project head
    assertRowMatch(actual.get(0), project1, null, null, emptyList());
    assertRowMatch(actual.get(1), project1, employee1, hourType1, findHours(hours, project1, employee1, hourType1));
    assertRowMatch(actual.get(2), project1, employee1, hourType2, findHours(hours, project1, employee1, hourType2));
    // master project total1
    assertRowMatch(actual.get(3), project1, null, hourType1, emptyList());
    // master project total2
    assertRowMatch(actual.get(4), project1, null, hourType2, emptyList());
    Project subproject = subprojects.get(project1).get(0);
    // subproject head
    assertRowMatch(actual.get(5), subproject, null, null, emptyList());
    assertRowMatch(actual.get(6), subproject, employee1, hourType1, findHours(hours, subproject, employee1, hourType1));
    // subproject total
    assertRowMatch(actual.get(7), subproject, null, hourType1, emptyList());
    // space row
    assertRowMatch(actual.get(8), null, null, null, emptyList());
    // master project total1
    assertRowMatch(actual.get(9), project1, null, hourType1, emptyList());
    // master project total2
    assertRowMatch(actual.get(10), project1, null, hourType2, emptyList());
    // project 2
    assertRowMatch(actual.get(11), project2, null, null, emptyList());
    assertRowMatch(actual.get(12), project2, employee1, hourType1, findHours(hours, project2, employee1, hourType1));
    assertRowMatch(actual.get(13), project2, employee2, hourType1, findHours(hours, project2, employee2, hourType1));
    assertRowMatch(actual.get(14), project2, null, hourType1, emptyList());
}
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) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) Test(org.junit.Test)

Example 8 with HourType

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

the class SpreadSheetTest method testGetSortedHourTypes_FilterHasNoHourTypes.

@Test
public void testGetSortedHourTypes_FilterHasNoHourTypes() throws NoSuchFieldException {
    List<Employee> employees = new ArrayList<>();
    List<HourType> hourTypes = buildHourTypeList(2);
    HourType hourType = new HourType("1");
    Project project = createProject("1", hourTypes, employees);
    List<Hours> hours = buildHourList(project, employees, hourType, null);
    setField(filter, "hourTypes", new ArrayList<>());
    setField(spreadSheet, "filter", filter);
    setField(spreadSheet, "hourTypeRepository", hourTypeRepository);
    expect(hourTypeRepository.getAll()).andReturn(hourTypes);
    replay(hourTypeRepository);
    SortedSet<HourType> expected = new TreeSet<>(HourType.ACTUALTIME_TYPE_COMPARATOR);
    expected.addAll(hourTypes);
    SortedSet<HourType> actual = spreadSheet.getSortedHourTypes(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 9 with HourType

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

the class SpreadSheetTest method testGetSortedTeamMembers_FilterHasEmployeesAndHasNoDepartments.

@Test
public void testGetSortedTeamMembers_FilterHasEmployeesAndHasNoDepartments() throws NoSuchFieldException {
    List<Employee> employees = buildEmployeeList(2);
    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", new ArrayList<>());
    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 10 with HourType

use of com.artezio.arttime.datamodel.HourType 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)

Aggregations

HourType (com.artezio.arttime.datamodel.HourType)172 Test (org.junit.Test)158 Project (com.artezio.arttime.datamodel.Project)120 Employee (com.artezio.arttime.datamodel.Employee)115 Hours (com.artezio.arttime.datamodel.Hours)103 Date (java.util.Date)60 CalendarUtils.getOffsetDate (com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate)54 Period (com.artezio.arttime.datamodel.Period)45 BigDecimal (java.math.BigDecimal)41 CalendarUtils.createPeriod (com.artezio.arttime.test.utils.CalendarUtils.createPeriod)21 HashMap (java.util.HashMap)16 HoursRepository (com.artezio.arttime.repositories.HoursRepository)13 Map (java.util.Map)11 Arrays.asList (java.util.Arrays.asList)10 List (java.util.List)10 Filter (com.artezio.arttime.filter.Filter)7 Mail (com.artezio.arttime.services.mailing.Mail)7 ArrayList (java.util.ArrayList)7 HourTypeRepository (com.artezio.arttime.repositories.HourTypeRepository)6 RangePeriodSelector (com.artezio.arttime.web.criteria.RangePeriodSelector)6