Search in sources :

Example 56 with Employee

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

the class NotificationManagerTest method testGetProjects.

@Test
public void testGetProjects() throws NoSuchFieldException {
    setMockServices(notificationManager);
    Employee employee1 = createEmployee("iivanov", "Ivan", "Ivanov");
    Employee employee2 = createEmployee("ppetrov", "Petr", "Petrov");
    Employee employee3 = createEmployee("asidorov", "Andrey", "Sidorov");
    Employee employee4 = createEmployee("afedorov", "Andrey", "Fedorov");
    Project project1 = createProject(1L, employee1);
    Project project2 = createProject(2L, employee1, employee2, employee3);
    Project project3 = createProject(3L);
    List<Employee> employees = Arrays.asList(employee1, employee2, employee3, employee4);
    List<Project> projects = Arrays.asList(project1, project2, project3);
    expect(projectRepository.getActiveProjects()).andReturn(projects);
    expect(projectRepository.fetchComplete(projects)).andReturn(projects);
    replay(projectRepository);
    List<Project> expected = Arrays.asList(project1, project2);
    List<Project> actual = notificationManager.getProjects(employees);
    verify(projectRepository);
    assertEquals(expected, actual);
}
Also used : Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) Test(org.junit.Test)

Example 57 with Employee

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

the class NotificationManagerTest method testGetSubordinateProblems.

@Test
public void testGetSubordinateProblems() throws Exception {
    Employee employee1 = createEmployee("iivanov", "Ivan", "Ivanov");
    Employee employee2 = createEmployee("ppetrov", "Petr", "Petrov");
    Employee employee3 = createEmployee("asidorov", "Andrey", "Sidorov");
    Project project1 = createProject(1L, employee2);
    Project project2 = createProject(2L, employee3, employee1);
    project1.addManager(employee1);
    project2.addManager(employee2);
    List<Project> projects = Arrays.asList(project1, project2);
    Map<Employee, Map<Date, BigDecimal>> timeProblems = new HashMap<Employee, Map<Date, BigDecimal>>();
    timeProblems.put(employee1, new HashMap<Date, BigDecimal>());
    timeProblems.put(employee2, new HashMap<Date, BigDecimal>());
    timeProblems.put(employee3, new HashMap<Date, BigDecimal>());
    Set<SubordinateProblem> actual = notificationManager.getSubordinateProblems(employee1, projects, timeProblems);
    assertEquals(1, actual.size());
    assertEquals(employee2, actual.iterator().next().getEmployee());
}
Also used : Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) AbstractMap(java.util.AbstractMap) TreeMap(java.util.TreeMap) SubordinateProblem(com.artezio.arttime.services.NotificationManager.SubordinateProblem) Date(java.util.Date) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 58 with Employee

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

the class NotificationManagerTest method testNotificateAboutOwnTimeProblems.

@Test
public void testNotificateAboutOwnTimeProblems() throws MessagingException, NoSuchFieldException {
    setMockServices(notificationManager);
    Employee employee = new Employee("iivanov");
    employee.setEmail("iivanov@mail.com");
    List<Employee> employees = Arrays.asList(employee);
    Map<Employee, Map<Date, BigDecimal>> timeProblems = new HashMap<Employee, Map<Date, BigDecimal>>();
    timeProblems.put(employee, new HashMap<Date, BigDecimal>());
    Period period = new Period();
    String comment = "comment";
    String subject = "subject";
    String body = "body";
    expect(hourTypeRepository.findActual()).andReturn(new HourType());
    expect(workTimeService.getApprovedWorkTimeProblems(period, employees)).andReturn(timeProblems);
    expect(mailTemplateManager.getTemplateText(eq(MailTemplate.TIME_PROBLEM_BODY.getFileName()), anyObject(Map.class))).andReturn(body);
    expect(mailTemplateManager.getTemplateText(eq(MailTemplate.TIME_PROBLEM_SUBJECT.getFileName()), anyObject(Map.class))).andReturn(subject);
    mailingEngine.sendAsync("iivanov@mail.com", new Mail(subject, body));
    replay(hourTypeRepository, workTimeService, mailTemplateManager, mailingEngine);
    notificationManager.notificateAboutOwnTimeProblems(employees, period, comment);
    verify(hourTypeRepository, workTimeService, mailTemplateManager, mailingEngine);
}
Also used : Employee(com.artezio.arttime.datamodel.Employee) HourType(com.artezio.arttime.datamodel.HourType) Mail(com.artezio.arttime.services.mailing.Mail) HashMap(java.util.HashMap) Period(com.artezio.arttime.datamodel.Period) HashMap(java.util.HashMap) Map(java.util.Map) AbstractMap(java.util.AbstractMap) TreeMap(java.util.TreeMap) Date(java.util.Date) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 59 with Employee

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

the class ProjectServiceTest method testGetAvailableProjects_userIsPM_expectManagedProjects.

@Test
public void testGetAvailableProjects_userIsPM_expectManagedProjects() 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, currentEmployee));
    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(false);
    expect(subject.hasRole(UserRoles.PM_ROLE)).andReturn(true);
    expect(projectRepository.getManagedProjects(currentEmployee)).andReturn(Arrays.asList(project1, project3));
    List<Project> expected = Arrays.asList(project1, 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 60 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)

Aggregations

Employee (com.artezio.arttime.datamodel.Employee)201 Test (org.junit.Test)173 Project (com.artezio.arttime.datamodel.Project)121 HourType (com.artezio.arttime.datamodel.HourType)74 Hours (com.artezio.arttime.datamodel.Hours)65 Date (java.util.Date)39 BigDecimal (java.math.BigDecimal)33 Period (com.artezio.arttime.datamodel.Period)28 Filter (com.artezio.arttime.filter.Filter)23 ArrayList (java.util.ArrayList)20 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)19 CalendarUtils.getOffsetDate (com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate)18 CalendarUtils.createPeriod (com.artezio.arttime.test.utils.CalendarUtils.createPeriod)15 TeamFilter (com.artezio.arttime.datamodel.TeamFilter)13 HashMap (java.util.HashMap)12 WorkdaysCalendar (com.artezio.arttime.datamodel.WorkdaysCalendar)7 Mail (com.artezio.arttime.services.mailing.Mail)7 ProjectRepository (com.artezio.arttime.services.repositories.ProjectRepository)7 List (java.util.List)7 Map (java.util.Map)7