Search in sources :

Example 36 with Employee

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

the class ProjectServiceTest method testGetAvailableProjects_userIsExec_expectAllProjects.

@Test
public void testGetAvailableProjects_userIsExec_expectAllProjects() throws NoSuchFieldException {
    Employee currentEmployee = new Employee("curr", "fn", "ln", "mail");
    Employee manager1 = new Employee("man1", "fn1", "ln1", "mail1");
    Employee manager2 = new Employee("man2", "fn2", "ln2", "mail2");
    Project project1 = createProject(1L, null);
    Project project2 = createProject(2L, null);
    Project project3 = createProject(3L, null);
    project1.setManagers(Arrays.asList(manager1));
    project2.setManagers(Arrays.asList(manager2));
    project3.setManagers(Arrays.asList(currentEmployee));
    Subject subject = createMock(Subject.class);
    PowerMock.mockStatic(SecurityUtils.class);
    projectRepository = createMock(ProjectRepository.class);
    setField(projectService, "projectRepository", projectRepository);
    expect(SecurityUtils.getSubject()).andReturn(subject);
    expect(subject.hasRole(UserRoles.EXEC_ROLE)).andReturn(true);
    expect(projectRepository.getAll()).andReturn(Arrays.asList(project1, project2, project3));
    List<Project> expected = Arrays.asList(project1, project2, project3);
    PowerMock.replayAll(projectRepository, subject, SecurityUtils.class);
    List<Project> actual = projectService.getAvailableProjects(currentEmployee);
    PowerMock.verifyAll();
    ListAssert.assertEquals(expected, actual);
}
Also used : Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) ProjectRepository(com.artezio.arttime.services.repositories.ProjectRepository) Subject(org.apache.shiro.subject.Subject) TestSubject(org.easymock.TestSubject) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 37 with Employee

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

the class TeamSynchronizerTest method testImportTeam_ifTeamNotChanged.

@Test
public void testImportTeam_ifTeamNotChanged() throws Exception {
    Employee employee = new Employee("employee");
    Project project = new Project();
    setField(project, "id", 1L);
    project.addTeamMember(employee);
    project.setTeamFilter(new TeamFilter(FilterType.PROJECT_CODES, "foreign code"));
    List<Employee> projectTeam = Arrays.asList(employee);
    expect(projectRepository.fetchComplete(project)).andReturn(project);
    expect(projectService.getSubprojectsByProject(project)).andReturn(Arrays.asList(project));
    expect(teamTrackingSystem.getTeam(project)).andReturn(projectTeam);
    expect(projectService.addTeamMembers(project, new ArrayList<>())).andReturn(new ArrayList<>());
    replay(projectRepository, projectService, teamTrackingSystem);
    teamSynchronizer.importTeam(project);
    verify(projectRepository, projectService, teamTrackingSystem);
}
Also used : Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) TeamFilter(com.artezio.arttime.datamodel.TeamFilter) Test(org.junit.Test)

Example 38 with Employee

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

the class TeamSynchronizerTest method testGetTeamMembers.

@Test
public void testGetTeamMembers() {
    Employee employee1 = new Employee("employee1");
    Employee employee2 = new Employee("employee2");
    Employee employee3 = new Employee("employee3");
    Project project1 = new Project();
    project1.addTeamMember(employee1);
    Project project2 = new Project();
    project2.addTeamMember(employee2);
    project2.addTeamMember(employee3);
    List<Project> projects = Arrays.asList(project1, project2);
    List<Employee> expected = Arrays.asList(employee1, employee2, employee3);
    Set<Employee> actual = teamSynchronizer.getTeamMembers(projects);
    ListAssert.assertEquals(expected, new ArrayList<>(actual));
}
Also used : Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) Test(org.junit.Test)

Example 39 with Employee

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

the class TeamSynchronizerTest method testGetFullTeam.

@Test
public void testGetFullTeam() throws Exception {
    Employee employee1 = new Employee("employee1");
    Employee employee2 = new Employee("employee2");
    Employee employee3 = new Employee("employee3");
    Employee employee4 = new Employee("employee4");
    Employee employee5 = new Employee("employee5");
    Project master = createProject(1L, null, FilterType.PROJECT_CODES);
    Project project01 = createProject(2L, master, FilterType.BASED_ON_MASTER);
    Project project02 = createProject(3L, master, FilterType.DISABLED);
    Project project11 = createProject(4L, project01, FilterType.BASED_ON_MASTER);
    Project project21 = createProject(5L, project02, FilterType.BASED_ON_MASTER);
    List<Project> projects = Arrays.asList(master, project01, project02, project11, project21);
    expect(projectService.getSubprojectsByProject(master)).andReturn(projects);
    master.addTeamMember(employee1);
    project01.addTeamMember(employee2);
    project11.addTeamMember(employee3);
    project02.addTeamMember(employee4);
    project21.addTeamMember(employee5);
    List<Employee> expected = Arrays.asList(employee1, employee2, employee3);
    replay(projectService);
    Set<Employee> actual = teamSynchronizer.getFullTeam(master);
    verify(projectService);
    ListAssert.assertEquals(expected, new ArrayList<>(actual));
}
Also used : Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) Test(org.junit.Test)

Example 40 with Employee

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

the class TeamSynchronizerTest method testImportTeam_ifBasedOnMaster.

@Test
public void testImportTeam_ifBasedOnMaster() throws Exception {
    Employee employee = new Employee("employee");
    Project project = new Project();
    setField(project, "id", 1L);
    project.addTeamMember(employee);
    project.setTeamFilter(new TeamFilter(FilterType.BASED_ON_MASTER));
    List<Employee> projectTeam = Arrays.asList(new Employee("new employee"));
    expect(projectRepository.fetchComplete(project)).andReturn(project);
    expect(projectService.getSubprojectsByProject(project)).andReturn(Arrays.asList(project));
    expect(teamTrackingSystem.getTeam(project)).andReturn(projectTeam);
    expect(projectService.addTeamMembers(project, new ArrayList<>())).andReturn(new ArrayList<>());
    expect(projectRepository.update(project)).andReturn(project);
    expect(mailTemplateManager.getTemplateText(anyString(), anyObject(Map.class))).andReturn("").anyTimes();
    replay(projectRepository, projectService, teamTrackingSystem, mailTemplateManager);
    teamSynchronizer.importTeam(project);
    verify(projectRepository, projectService, teamTrackingSystem, mailTemplateManager);
}
Also used : Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) TeamFilter(com.artezio.arttime.datamodel.TeamFilter) Test(org.junit.Test)

Aggregations

Employee (com.artezio.arttime.datamodel.Employee)339 Test (org.junit.Test)300 Project (com.artezio.arttime.datamodel.Project)196 HourType (com.artezio.arttime.datamodel.HourType)115 Hours (com.artezio.arttime.datamodel.Hours)101 Date (java.util.Date)67 Period (com.artezio.arttime.datamodel.Period)61 CalendarUtils.getOffsetDate (com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate)52 BigDecimal (java.math.BigDecimal)45 TeamFilter (com.artezio.arttime.datamodel.TeamFilter)27 Filter (com.artezio.arttime.filter.Filter)26 ArrayList (java.util.ArrayList)24 CalendarUtils.createPeriod (com.artezio.arttime.test.utils.CalendarUtils.createPeriod)22 HashMap (java.util.HashMap)21 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)21 WorkdaysCalendar (com.artezio.arttime.datamodel.WorkdaysCalendar)16 Arrays.asList (java.util.Arrays.asList)15 List (java.util.List)15 Map (java.util.Map)15 HoursRepository (com.artezio.arttime.repositories.HoursRepository)13