Search in sources :

Example 81 with Project

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

the class ProjectServiceTest method testGetProjectHierarchy_ProjectHasSubprojects_SubprojectsAreActive.

@Test
public void testGetProjectHierarchy_ProjectHasSubprojects_SubprojectsAreActive() {
    Project master = createProject(1L, null);
    Project subproject01 = createProject(2L, master);
    Project subproject02 = createProject(3L, master);
    Project subproject11 = createProject(4L, subproject01);
    List<Project> expected = asList(master, subproject01, subproject11, subproject02);
    ProjectRepository.ProjectQuery projectQuery = Mockito.mock(ProjectRepository.ProjectQuery.class, Mockito.RETURNS_DEEP_STUBS);
    EasyMock.expect(projectRepository.query()).andReturn(projectQuery).times(3);
    Mockito.when(projectQuery.masters(asList(master)).status(ACTIVE).distinct().list()).thenReturn(asList(subproject01, subproject02));
    Mockito.when(projectQuery.masters(asList(subproject01, subproject02)).status(ACTIVE).distinct().list()).thenReturn(asList(subproject11));
    Mockito.when(projectQuery.masters(asList(subproject11)).status(ACTIVE).distinct().list()).thenReturn(emptyList());
    replay(projectRepository);
    List<Project> actual = projectService.getProjectHierarchy(master);
    EasyMock.verify(projectRepository);
    ListAssert.assertEquals(expected, actual);
}
Also used : Project(com.artezio.arttime.datamodel.Project) ProjectRepository(com.artezio.arttime.repositories.ProjectRepository) Test(org.junit.Test)

Example 82 with Project

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

the class ProjectServiceTest method testGetProjectHierarchy_ProjectHasSubprojects_SubprojectsAreClosed.

@Test
public void testGetProjectHierarchy_ProjectHasSubprojects_SubprojectsAreClosed() {
    Project master = createProject(1L, null);
    Project subproject01 = createProject(2L, master);
    subproject01.setStatus(CLOSED);
    Project subproject02 = createProject(3L, master);
    subproject02.setStatus(CLOSED);
    Project subproject11 = createProject(4L, subproject01);
    subproject11.setStatus(CLOSED);
    List<Project> expected = asList(master);
    ProjectRepository.ProjectQuery projectQuery = Mockito.mock(ProjectRepository.ProjectQuery.class, Mockito.RETURNS_DEEP_STUBS);
    EasyMock.expect(projectRepository.query()).andReturn(projectQuery);
    Mockito.when(projectQuery.masters(expected).status(ACTIVE).distinct().list()).thenReturn(emptyList());
    replay(projectRepository);
    List<Project> actual = projectService.getProjectHierarchy(master);
    EasyMock.verify(projectRepository);
    ListAssert.assertEquals(expected, actual);
}
Also used : Project(com.artezio.arttime.datamodel.Project) ProjectRepository(com.artezio.arttime.repositories.ProjectRepository) Test(org.junit.Test)

Example 83 with Project

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

the class ProjectServiceTest method createProject.

private Project createProject(Long id, Project master) {
    try {
        Project project = new Project(master);
        setField(project, "id", id);
        return project;
    } catch (NoSuchFieldException e) {
        throw new RuntimeException("Error during creating test project", e);
    }
}
Also used : Project(com.artezio.arttime.datamodel.Project)

Example 84 with Project

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

the class HoursRepositoryTest method testGetManagersForApproveByEmployee_ifNotActualTime.

@Test
public void testGetManagersForApproveByEmployee_ifNotActualTime() {
    Date start = new Date();
    Date finish = getOffsetDate(3);
    Period period = new Period(start, finish);
    Employee manager1 = new Employee("manager1");
    Employee manager2 = new Employee("manager2");
    Project project1 = new Project();
    project1.setManagers(Arrays.asList(manager1));
    Project project2 = new Project();
    project2.setManagers(Arrays.asList(manager2));
    Employee employee = new Employee("employee");
    HourType actualType = new HourType("actual type");
    actualType.setActualTime(true);
    HourType notActualType = new HourType("not actual type");
    Hours hours1 = createHours(project1, employee, getOffsetDate(2), notActualType, new BigDecimal(8));
    Hours hours2 = createHours(project2, employee, getOffsetDate(2), actualType, new BigDecimal(8));
    entityManager.persist(manager1);
    entityManager.persist(manager2);
    entityManager.persist(actualType);
    entityManager.persist(notActualType);
    entityManager.persist(employee);
    entityManager.persist(project1);
    entityManager.persist(project2);
    entityManager.persist(hours1);
    entityManager.persist(hours2);
    Map<Employee, List<Employee>> actual = hoursRepository.getManagersForApproveByEmployee(Arrays.asList(employee), period);
    ListAssert.assertEquals(Arrays.asList(manager2), actual.get(employee));
}
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) Period(com.artezio.arttime.datamodel.Period) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Date(java.util.Date) CalendarUtils.getOffsetDate(com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 85 with Project

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

the class HoursRepositoryTest method testGetActualTimeByEmployeeAndApproval_ifQuantityIsNull.

@Test
public void testGetActualTimeByEmployeeAndApproval_ifQuantityIsNull() {
    Date start = new Date();
    Date finish = getOffsetDate(3);
    Period period = new Period(start, finish);
    Project project = new Project();
    Employee employee1 = new Employee("employee1");
    Employee employee2 = new Employee("employee2");
    HourType actualType = new HourType("actual type");
    actualType.setActualTime(true);
    Hours hours1 = createHours(project, employee1, getOffsetDate(1), actualType, new BigDecimal(7));
    Hours hours2 = createHours(project, employee1, getOffsetDate(2), actualType, null);
    Hours hours3 = createHours(project, employee2, getOffsetDate(2), actualType, null);
    entityManager.persist(employee1);
    entityManager.persist(employee2);
    entityManager.persist(project);
    entityManager.persist(actualType);
    entityManager.persist(hours1);
    entityManager.persist(hours2);
    entityManager.persist(hours3);
    Map<Employee, Map<Boolean, BigDecimal>> actual = hoursRepository.getActualTimeByEmployeeAndApproval(Arrays.asList(employee1, employee2), period);
    assertEquals(1, actual.size());
    assertEquals(7.0, actual.get(employee1).get(false).doubleValue(), 0.0);
}
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) Period(com.artezio.arttime.datamodel.Period) HashMap(java.util.HashMap) Map(java.util.Map) Date(java.util.Date) CalendarUtils.getOffsetDate(com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate) BigDecimal(java.math.BigDecimal) 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