Search in sources :

Example 36 with Project

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

the class ManageProjectPermissionFilterTest method testIsAccessAllowed_ifPM_andProjectNotManagedTheEmployee.

@Test
public void testIsAccessAllowed_ifPM_andProjectNotManagedTheEmployee() throws Exception {
    Project project = new Project();
    Employee employee = new Employee("employee");
    mockStatic(SecurityUtils.class);
    expect(SecurityUtils.getSubject()).andReturn(subject);
    expect(subject.hasRole(UserRoles.EXEC_ROLE)).andReturn(false);
    expect(subject.hasRole(UserRoles.PM_ROLE)).andReturn(true);
    expect(servletRequest.getParameter("project")).andReturn("1");
    expect(subject.getPrincipal()).andReturn("employee");
    expect(projectRepository.findProject(1L)).andReturn(project);
    expect(employeeRepository.find("employee")).andReturn(employee);
    replayAll(SecurityUtils.class);
    replay(subject, servletRequest, projectRepository, employeeRepository);
    boolean actual = filter.isAccessAllowed(servletRequest, servletResponse, null);
    verifyAll();
    assertFalse(actual);
}
Also used : Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 37 with Project

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

the class NotificationManagerTest method testNotificatePmAboutTimeProblems.

@Test
public void testNotificatePmAboutTimeProblems() throws MessagingException, NoSuchFieldException {
    notificationManager = createMockBuilder(NotificationManager.class).addMockedMethod("getProjects", List.class).addMockedMethod("getProjectManagers", Collection.class).createMock();
    setMockServices(notificationManager);
    Employee employee = new Employee("iivanov");
    Employee pm = new Employee("ppetrov");
    pm.setEmail("ppetrov@mail.com");
    Project project = createProject(1L, employee);
    List<Employee> employees = Arrays.asList(employee);
    List<Project> projects = Arrays.asList(project);
    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(notificationManager.getProjects(employees)).andReturn(projects);
    expect(notificationManager.getProjectManagers(projects)).andReturn(Sets.newHashSet(pm));
    expect(hourTypeRepository.findActual()).andReturn(new HourType());
    expect(workTimeService.getApprovedWorkTimeProblems(period, employees)).andReturn(timeProblems);
    expect(mailTemplateManager.getTemplateText(eq(MailTemplate.TIME_PROBLEM_BODY_FOR_PM.getFileName()), anyObject(Map.class))).andReturn(body);
    expect(mailTemplateManager.getTemplateText(eq(MailTemplate.TIME_PROBLEM_SUBJECT.getFileName()), anyObject(Map.class))).andReturn(subject);
    mailingEngine.sendAsync("ppetrov@mail.com", new Mail(subject, body));
    replay(notificationManager, hourTypeRepository, workTimeService, mailTemplateManager, mailingEngine);
    notificationManager.notificatePmAboutTimeProblems(employees, period, comment);
    verify(notificationManager, hourTypeRepository, workTimeService, mailTemplateManager, mailingEngine);
}
Also used : HourType(com.artezio.arttime.datamodel.HourType) HashMap(java.util.HashMap) Period(com.artezio.arttime.datamodel.Period) Date(java.util.Date) BigDecimal(java.math.BigDecimal) Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) Mail(com.artezio.arttime.services.mailing.Mail) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) AbstractMap(java.util.AbstractMap) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 38 with Project

use of com.artezio.arttime.datamodel.Project 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 39 with Project

use of com.artezio.arttime.datamodel.Project 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 40 with Project

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

the class ProjectServiceTest method testGetRootProjects.

@Test
public void testGetRootProjects() throws NoSuchFieldException {
    Project project1 = createProject(1L, null);
    Project project11 = createProject(2L, project1);
    Project project12 = createProject(3L, project1);
    Project project111 = createProject(4L, project11);
    Project project2 = createProject(5L, null);
    Project project21 = createProject(6L, project2);
    Project project3 = createProject(7L, null);
    List<Project> projects = Arrays.asList(project21, project11, project12, project111, project3);
    List<Project> expected = Arrays.asList(project1, project2, project3);
    List<Project> actual = projectService.getRootProjects(projects);
    ListAssert.assertEquals(expected, actual);
}
Also used : Project(com.artezio.arttime.datamodel.Project) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) 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