Search in sources :

Example 11 with ProjectRepository

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

the class TeamSynchronizerTest method testGetEmployeesFromProjectTree_startingFromSubproject.

@Test
public void testGetEmployeesFromProjectTree_startingFromSubproject() {
    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> teamFromSubproject = teamSynchronizer.getEmployeesFromProjectTree(subProjectBasedOnMaster1);
    verify(projectRepository, query);
    assertTrue(teamFromSubproject.contains(employee1));
    assertTrue(teamFromSubproject.contains(employee2));
    assertTrue(teamFromSubproject.contains(employee3));
    assertTrue(teamFromSubproject.contains(employee4));
    assertFalse(teamFromSubproject.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 12 with ProjectRepository

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

the class TeamSynchronizerTest method testImportTeam_subprojectWithProjectCodeFilterType_MasterWithDisabledFilterType.

@Test
public void testImportTeam_subprojectWithProjectCodeFilterType_MasterWithDisabledFilterType() throws NoSuchFieldException {
    Project master = new Project();
    master.setTeamFilter(new TeamFilter(DISABLED));
    Project subproject = new Project(master);
    subproject.setTeamFilter(new TeamFilter(PROJECT_CODES));
    Employee employee1 = new Employee("employee1");
    employee1.setFormer(true);
    Employee employee2 = new Employee("employee2");
    List<Employee> teamMembers = asList(employee1, employee2);
    master.setTeam(teamMembers);
    subproject.setTeam(teamMembers);
    ProjectRepository.ProjectQuery projectQuery = Mockito.mock(ProjectRepository.ProjectQuery.class, Mockito.RETURNS_DEEP_STUBS);
    teamSynchronizer = createMockBuilder(TeamSynchronizer.class).addMockedMethod("getTeam", Project.class).createMock();
    setField(teamSynchronizer, "teamTrackingSystem", teamTrackingSystem);
    setField(teamSynchronizer, "projectRepository", projectRepository);
    setField(teamSynchronizer, "notificationManager", notificationManager);
    setField(teamSynchronizer, "employeeService", employeeService);
    EasyMock.expect(teamSynchronizer.getTeam(subproject)).andReturn(asList(employee2));
    EasyMock.expect(projectRepository.query()).andReturn(projectQuery);
    Mockito.when(projectQuery.masters(asList(subproject)).status(ACTIVE).list()).thenReturn(emptyList());
    EasyMock.expect(projectRepository.update(subproject)).andReturn(subproject);
    notificationManager.notifyAboutTeamChanges(subproject, asList(employee1), emptyList());
    EasyMock.expectLastCall();
    employeeService.setCalendar(emptyList());
    EasyMock.expectLastCall();
    replay(employeeService, projectRepository, teamTrackingSystem, notificationManager, teamSynchronizer);
    teamSynchronizer.importTeam(subproject);
    EasyMock.verify(employeeService, projectRepository, teamTrackingSystem, notificationManager);
    Mockito.verify(projectQuery.masters(asList(subproject)).status(ACTIVE)).list();
    ListAssert.assertEquals(asList(employee2), new ArrayList<>(subproject.getTeam()));
}
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 13 with ProjectRepository

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

the class TeamSynchronizerTest method testGetCurrentTeamMembers.

@Test
public void testGetCurrentTeamMembers() {
    Project project = new Project();
    project.setTeamFilter(new TeamFilter(Type.PROJECT_CODES, "abc"));
    Project subproject = new Project(project);
    subproject.setTeamFilter(new TeamFilter(DISABLED));
    Employee employee1 = new Employee("emp1");
    Employee employee2 = new Employee("emp2");
    Employee employee3 = new Employee("emp3");
    project.addTeamMember(employee1);
    project.addTeamMember(employee2);
    subproject.addTeamMember(employee2);
    subproject.addTeamMember(employee3);
    ProjectRepository.ProjectQuery query = mock(ProjectRepository.ProjectQuery.class);
    expect(projectRepository.query()).andReturn(query);
    expect(query.masters(asList(project))).andReturn(query);
    expect(query.status(ACTIVE)).andReturn(query);
    expect(query.list()).andReturn(asList(subproject));
    replay(projectRepository, query);
    List<Employee> currentTeamMembers = teamSynchronizer.getCurrentTeamMembers(project);
    verify(projectRepository, query);
    assertTrue(currentTeamMembers.containsAll(project.getTeam()));
    assertFalse(currentTeamMembers.contains(employee3));
}
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 14 with ProjectRepository

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

the class HoursServiceTest method testApply_HoursNotExists.

@Test
public void testApply_HoursNotExists() {
    Employee employee = new Employee("empl1");
    Project project = new Project();
    project.setCode("BBBCode");
    HourType hourType = new HourType("off");
    Date date1 = new GregorianCalendar(2016, 5, 5).getTime();
    Hours hours = new Hours(project, date1, employee, hourType);
    HoursChange hoursChange = new HoursChange(project.getCode(), date1, employee.getUserName(), 1L);
    hoursChange.setQuantityDelta(BigDecimal.valueOf(5.0));
    ProjectRepository.ProjectQuery projectQuery = Mockito.mock(ProjectRepository.ProjectQuery.class, Mockito.RETURNS_DEEP_STUBS);
    HoursRepository.HoursQuery hoursQuery = Mockito.mock(HoursRepository.HoursQuery.class, Mockito.RETURNS_DEEP_STUBS);
    EasyMock.expect(projectRepository.query()).andReturn(projectQuery);
    EasyMock.expect(hoursRepository.query()).andReturn(hoursQuery);
    Mockito.when(hoursQuery.employee(hoursChange.getEmployeeUsername()).project(hoursChange.getProjectCode()).hourType(hoursChange.getTypeId()).date(hoursChange.getDate()).uncached().getSingleResultOrNull()).thenReturn(null);
    Mockito.when(projectQuery.code(project.getCode()).getSingleResult()).thenReturn(project);
    hoursRepository.lock(employee);
    EasyMock.expect(hoursRepository.create(hours)).andReturn(hours);
    EasyMock.expect(employeeRepository.get(employee.getUserName())).andReturn(employee).times(2);
    EasyMock.expect(hourTypeService.find(anyLong())).andReturn(hourType);
    EasyMock.replay(hoursRepository, employeeRepository, hourTypeService, projectRepository);
    hoursService.apply(hoursChange);
    EasyMock.verify(hoursRepository, employeeRepository, hourTypeService, projectRepository);
    Mockito.verify(hoursQuery.employee(hoursChange.getEmployeeUsername()).project(hoursChange.getProjectCode()).hourType(hoursChange.getTypeId()).date(hoursChange.getDate()).uncached()).getSingleResultOrNull();
    Mockito.verify(projectQuery.code(project.getCode())).getSingleResult();
}
Also used : Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) HourType(com.artezio.arttime.datamodel.HourType) ProjectRepository(com.artezio.arttime.repositories.ProjectRepository) Hours(com.artezio.arttime.datamodel.Hours) GregorianCalendar(java.util.GregorianCalendar) HoursRepository(com.artezio.arttime.repositories.HoursRepository) Date(java.util.Date) CalendarUtils.getOffsetDate(com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate) Test(org.junit.Test)

Example 15 with ProjectRepository

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

the class ProjectServiceTest method testGetManagedProjectHierarchy_ProjectHasSubprojects_SubprojectsAreClosed.

@Test
public void testGetManagedProjectHierarchy_ProjectHasSubprojects_SubprojectsAreClosed() {
    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)).distinct().list()).thenReturn(asList(subproject01, subproject02));
    Mockito.when(projectQuery.masters(asList(subproject01, subproject02)).distinct().list()).thenReturn(asList(subproject11));
    Mockito.when(projectQuery.masters(asList(subproject11)).distinct().list()).thenReturn(emptyList());
    replay(projectRepository);
    List<Project> actual = projectService.getManagedProjectHierarchy(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)

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