Search in sources :

Example 21 with Project

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

the class ProjectEffortsSpreadSheetTest method testCalculateTotalKeysFor_subproject.

@Test
public void testCalculateTotalKeysFor_subproject() throws NoSuchFieldException {
    Project master = new Project();
    Project subproject = new Project(master);
    setField(master, "id", 1L);
    setField(subproject, "id", 2L);
    // master head row
    HeadSpreadSheetRow row1 = new HeadSpreadSheetRow(master);
    // master hours
    HoursSpreadSheetRow row2 = new HoursSpreadSheetRow(master, null, null, new ArrayList<>());
    // master totals
    TotalsSpreadSheetRow row3 = new TotalsSpreadSheetRow(master, null, Arrays.asList(row2));
    // subproject head row
    HeadSpreadSheetRow row4 = new HeadSpreadSheetRow(subproject);
    // subproject hours
    HoursSpreadSheetRow row5 = new HoursSpreadSheetRow(subproject, null, null, new ArrayList<>());
    // subproject totals
    TotalsSpreadSheetRow row6 = new TotalsSpreadSheetRow(subproject, null, Arrays.asList(row5));
    // master and subproject totals
    TotalsSpreadSheetRow row7 = new TotalsSpreadSheetRow(subproject, null, Arrays.asList(row2, row5));
    List<SpreadSheetRow<?>> rows = Arrays.asList(row1, row2, row3, row4, row5, row6, row7);
    setField(spreadSheet, "rows", rows);
    List<Integer> expected = Arrays.asList(rows.get(5).getKey(), rows.get(6).getKey());
    List<Integer> actual = spreadSheet.calculateKeysOfTotalsRows(row5);
    assertEquals(2, actual.size());
    ListAssert.assertEquals(expected, actual);
}
Also used : Project(com.artezio.arttime.datamodel.Project) Test(org.junit.Test)

Example 22 with Project

use of com.artezio.arttime.datamodel.Project 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 23 with Project

use of com.artezio.arttime.datamodel.Project 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 24 with Project

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

the class ProjectEffortsSpreadSheetTest method createProject.

private Project createProject(String code, List<HourType> hourTypes, List<Employee> employees) {
    Project project = new Project();
    project.setAccountableHours(hourTypes);
    project.setCode(code);
    project.getTeam().addAll(employees);
    return project;
}
Also used : Project(com.artezio.arttime.datamodel.Project)

Example 25 with Project

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

the class ProjectEffortsSpreadSheetTest method testHasTeam.

@Test
public void testHasTeam() throws NoSuchFieldException {
    Employee employee = new Employee("employee");
    spreadSheet.getFilter().setEmployees(asList(employee));
    Project master = createProject("master", emptyList(), asList(employee));
    Project subproject = createProject("subproject", emptyList(), asList(employee));
    setField(subproject, "master", master);
    assertTrue(spreadSheet.hasTeam(master, asList(subproject)));
    master.setTeam(emptyList());
    assertTrue(spreadSheet.hasTeam(master, asList(subproject)));
    subproject.setTeam(emptyList());
    assertFalse(spreadSheet.hasTeam(master, asList(subproject)));
}
Also used : Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) Test(org.junit.Test)

Aggregations

Project (com.artezio.arttime.datamodel.Project)310 Test (org.junit.Test)278 Employee (com.artezio.arttime.datamodel.Employee)195 HourType (com.artezio.arttime.datamodel.HourType)119 Hours (com.artezio.arttime.datamodel.Hours)108 Date (java.util.Date)61 CalendarUtils.getOffsetDate (com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate)56 Period (com.artezio.arttime.datamodel.Period)43 BigDecimal (java.math.BigDecimal)39 Filter (com.artezio.arttime.filter.Filter)33 TeamFilter (com.artezio.arttime.datamodel.TeamFilter)26 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)25 CalendarUtils.createPeriod (com.artezio.arttime.test.utils.CalendarUtils.createPeriod)21 ArrayList (java.util.ArrayList)18 Arrays.asList (java.util.Arrays.asList)18 ProjectRepository (com.artezio.arttime.repositories.ProjectRepository)17 List (java.util.List)17 HoursRepository (com.artezio.arttime.repositories.HoursRepository)13 HashMap (java.util.HashMap)13 Map (java.util.Map)11