Search in sources :

Example 6 with ProjectRepository

use of com.artezio.arttime.repositories.ProjectRepository 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 7 with ProjectRepository

use of com.artezio.arttime.repositories.ProjectRepository 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 8 with ProjectRepository

use of com.artezio.arttime.repositories.ProjectRepository in project ART-TIME by Artezio.

the class TeamSynchronizerTest method testGetEmployeesFromProjectTree_expectNoEmployeesFromClosedSubprojects.

@Test
public void testGetEmployeesFromProjectTree_expectNoEmployeesFromClosedSubprojects() {
    Employee employee1 = new Employee("emp1");
    Employee employee2 = new Employee("emp2");
    Employee employee3 = new Employee("emp3");
    Employee employee4 = new Employee("emp4");
    Project master = new Project();
    master.setCode("master");
    master.setTeamFilter(new TeamFilter(Type.PROJECT_CODES, "abc"));
    master.addTeamMember(employee1);
    Project activeSubproject = new Project(master);
    activeSubproject.setStatus(ACTIVE);
    activeSubproject.setCode("activeSubBased");
    activeSubproject.setTeamFilter(new TeamFilter(BASED_ON_MASTER));
    activeSubproject.addTeamMember(employee2);
    activeSubproject.addTeamMember(employee3);
    Project closedSubproject = new Project(master);
    closedSubproject.setStatus(Project.Status.CLOSED);
    closedSubproject.setCode("subBased2");
    closedSubproject.setTeamFilter(new TeamFilter(BASED_ON_MASTER));
    closedSubproject.addTeamMember(employee3);
    closedSubproject.addTeamMember(employee4);
    ProjectRepository.ProjectQuery query = mock(ProjectRepository.ProjectQuery.class);
    ProjectRepository.ProjectQuery query1 = mock(ProjectRepository.ProjectQuery.class);
    ProjectRepository.ProjectQuery query2 = mock(ProjectRepository.ProjectQuery.class);
    expect(projectRepository.query()).andReturn(query).times(2);
    expect(query.masters(asList(master))).andReturn(query1);
    expect(query.masters(asList(activeSubproject))).andReturn(query2);
    expect(query1.status(ACTIVE)).andReturn(query1);
    expect(query1.list()).andReturn(asList(activeSubproject));
    expect(query2.status(ACTIVE)).andReturn(query2);
    expect(query2.list()).andReturn(emptyList());
    replay(projectRepository, query, query1, query2);
    List<Employee> teamFromSubproject = teamSynchronizer.getEmployeesFromProjectTree(activeSubproject);
    verify(projectRepository, query);
    assertTrue(teamFromSubproject.contains(employee1));
    assertTrue(teamFromSubproject.contains(employee2));
    assertTrue(teamFromSubproject.contains(employee3));
    assertFalse(teamFromSubproject.contains(employee4));
}
Also used : Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) ProjectRepository(com.artezio.arttime.repositories.ProjectRepository) TeamFilter(com.artezio.arttime.datamodel.TeamFilter) Test(org.junit.Test)

Example 9 with ProjectRepository

use of com.artezio.arttime.repositories.ProjectRepository in project ART-TIME by Artezio.

the class TeamSynchronizerTest method testGetEmployeesFromProjectTree.

@Test
public void testGetEmployeesFromProjectTree() {
    Employee employee1 = new Employee("emp1");
    Employee employee2 = new Employee("emp2");
    Employee employee3 = new Employee("emp3");
    Employee employee4 = new Employee("emp4");
    Employee employee5 = new Employee("emp5");
    Project master = new Project();
    master.setCode("master");
    master.setTeamFilter(new TeamFilter(Type.PROJECT_CODES, "abc"));
    master.addTeamMember(employee1);
    Project subProjectBasedOnMaster1 = new Project(master);
    subProjectBasedOnMaster1.setCode("subBased1");
    subProjectBasedOnMaster1.setTeamFilter(new TeamFilter(BASED_ON_MASTER));
    subProjectBasedOnMaster1.addTeamMember(employee2);
    subProjectBasedOnMaster1.addTeamMember(employee3);
    Project subProjectBasedOnMaster2 = new Project(master);
    subProjectBasedOnMaster2.setCode("subBased2");
    subProjectBasedOnMaster2.setTeamFilter(new TeamFilter(BASED_ON_MASTER));
    subProjectBasedOnMaster2.addTeamMember(employee4);
    Project subProjectNotBasedOnMaster = new Project(master);
    subProjectNotBasedOnMaster.setCode("subNotBased");
    subProjectNotBasedOnMaster.setTeamFilter(new TeamFilter(Type.PROJECT_CODES));
    subProjectNotBasedOnMaster.addTeamMember(employee5);
    ProjectRepository.ProjectQuery query = mock(ProjectRepository.ProjectQuery.class);
    ProjectRepository.ProjectQuery query1 = mock(ProjectRepository.ProjectQuery.class);
    ProjectRepository.ProjectQuery query2 = mock(ProjectRepository.ProjectQuery.class);
    expect(projectRepository.query()).andReturn(query).times(2);
    expect(query.masters(asList(master))).andReturn(query1);
    expect(query.masters(asList(subProjectBasedOnMaster1, subProjectBasedOnMaster2))).andReturn(query2);
    expect(query1.status(ACTIVE)).andReturn(query1);
    expect(query1.list()).andReturn(asList(subProjectBasedOnMaster1, subProjectBasedOnMaster2, subProjectNotBasedOnMaster));
    expect(query2.status(ACTIVE)).andReturn(query2);
    expect(query2.list()).andReturn(emptyList());
    replay(projectRepository, query, query1, query2);
    List<Employee> teamFromMaster = teamSynchronizer.getEmployeesFromProjectTree(master);
    verify(projectRepository, query);
    assertTrue(teamFromMaster.contains(employee1));
    assertTrue(teamFromMaster.contains(employee2));
    assertTrue(teamFromMaster.contains(employee3));
    assertTrue(teamFromMaster.contains(employee4));
    assertFalse(teamFromMaster.contains(employee5));
}
Also used : Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) ProjectRepository(com.artezio.arttime.repositories.ProjectRepository) TeamFilter(com.artezio.arttime.datamodel.TeamFilter) Test(org.junit.Test)

Example 10 with ProjectRepository

use of com.artezio.arttime.repositories.ProjectRepository in project ART-TIME by Artezio.

the class TeamSynchronizerTest method testGetCurrentTeamMembers_existSubprojectsBasedOnMaster.

@Test
public void testGetCurrentTeamMembers_existSubprojectsBasedOnMaster() throws NoSuchFieldException {
    Project project = new Project();
    project.setTeamFilter(new TeamFilter(Type.PROJECT_CODES, "abc"));
    Project subproject = new Project(project);
    subproject.setTeamFilter(new TeamFilter(BASED_ON_MASTER));
    Project subprojectNotBasedOnMaster = new Project(project);
    subprojectNotBasedOnMaster.setTeamFilter(new TeamFilter(Type.PROJECT_CODES));
    Employee employee1 = new Employee("emp1");
    Employee employee2 = new Employee("emp2");
    Employee employee3 = new Employee("emp3");
    Employee employee4 = new Employee("emp4");
    project.addTeamMember(employee1);
    project.addTeamMember(employee2);
    subproject.addTeamMember(employee2);
    subproject.addTeamMember(employee3);
    subprojectNotBasedOnMaster.addTeamMember(employee4);
    teamSynchronizer = createMockBuilder(TeamSynchronizer.class).addMockedMethod("getEmployeesFromProjectTree", Project.class).createMock();
    setField(teamSynchronizer, "projectRepository", projectRepository);
    ProjectRepository.ProjectQuery query = mock(ProjectRepository.ProjectQuery.class);
    expect(teamSynchronizer.getEmployeesFromProjectTree(project)).andReturn(asList(employee1, employee2, employee3));
    expect(projectRepository.query()).andReturn(query);
    expect(query.masters(asList(project))).andReturn(query);
    expect(query.status(ACTIVE)).andReturn(query);
    expect(query.list()).andReturn(asList(subproject, subprojectNotBasedOnMaster));
    replay(projectRepository, teamSynchronizer, query);
    List<Employee> currentTeamMembers = teamSynchronizer.getCurrentTeamMembers(project);
    verify(projectRepository, teamSynchronizer, query);
    assertTrue(currentTeamMembers.containsAll(project.getTeam()));
    assertTrue(currentTeamMembers.containsAll(subproject.getTeam()));
    assertFalse(currentTeamMembers.contains(employee4));
}
Also used : Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) ProjectRepository(com.artezio.arttime.repositories.ProjectRepository) TeamFilter(com.artezio.arttime.datamodel.TeamFilter) Test(org.junit.Test)

Aggregations

ProjectRepository (com.artezio.arttime.repositories.ProjectRepository)19 Test (org.junit.Test)19 Project (com.artezio.arttime.datamodel.Project)15 Employee (com.artezio.arttime.datamodel.Employee)8 TeamFilter (com.artezio.arttime.datamodel.TeamFilter)6 Date (java.util.Date)4 Filter (com.artezio.arttime.filter.Filter)3 EmployeeRepository (com.artezio.arttime.repositories.EmployeeRepository)3 WorkTime (com.artezio.arttime.services.WorkTimeService.WorkTime)3 Arrays.asList (java.util.Arrays.asList)3 Collections.emptyList (java.util.Collections.emptyList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 Tuple (javax.persistence.Tuple)3 BigDecimal (java.math.BigDecimal)2 HourType (com.artezio.arttime.datamodel.HourType)1 Hours (com.artezio.arttime.datamodel.Hours)1 HoursRepository (com.artezio.arttime.repositories.HoursRepository)1 CalendarUtils.getOffsetDate (com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate)1