Search in sources :

Example 76 with Project

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

the class HoursServiceTest method testExistApprovedHours.

@Test
public void testExistApprovedHours() throws NoSuchFieldException {
    Employee employee = new Employee("employee");
    Project project = new Project();
    setField(project, "id", 1L);
    HourType hourType = new HourType("regular");
    Hours hour1 = new Hours(project, getOffsetDate(-1), employee, hourType);
    Hours hour2 = new Hours(project, getOffsetDate(1), employee, hourType);
    hour2.setApproved(true);
    List<Hours> persisted = asList(hour1, hour2);
    Hours hour3 = new Hours(project, getOffsetDate(1), employee, hourType);
    hoursService = new HoursService();
    boolean actual = hoursService.existApprovedHours(asList(hour3), persisted);
    assertTrue(actual);
}
Also used : Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) HourType(com.artezio.arttime.datamodel.HourType) Hours(com.artezio.arttime.datamodel.Hours) Test(org.junit.Test)

Example 77 with Project

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

the class NotificationManagerTest method testNotifyPmAboutTimeProblems.

@Test
public void testNotifyPmAboutTimeProblems() throws NoSuchFieldException {
    notificationManager = createMockBuilder(NotificationManager.class).addMockedMethod("getProjects", List.class).addMockedMethod("getProjectManagers", Collection.class).createMock();
    setMockServices(notificationManager);
    Employee sender = new Employee("sender", "sender", "sender", "sender");
    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<>();
    timeProblems.put(employee, new HashMap<>());
    Period period = new Period();
    String comment = "comment";
    String subject = "subject";
    String body = "body";
    EasyMock.expect(notificationManager.getProjects(employees)).andReturn(projects);
    EasyMock.expect(notificationManager.getProjectManagers(projects)).andReturn(Lists.newArrayList(pm));
    EasyMock.expect(hourTypeService.findActualTime()).andReturn(new HourType());
    EasyMock.expect(workTimeService.getWorkTimeDeviations(period, employees)).andReturn(timeProblems);
    EasyMock.expect(mailTemplateManager.getTemplateText(eq(MailTemplate.TIME_PROBLEM_BODY_FOR_PM.getFileName()), anyObject(Map.class))).andReturn(body);
    EasyMock.expect(mailTemplateManager.getTemplateText(eq(MailTemplate.TIME_PROBLEM_SUBJECT.getFileName()), anyObject(Map.class))).andReturn(subject);
    EasyMock.expect(settings.getSmtpUsername()).andReturn("testSmtpUsername");
    EasyMock.expect(settings.getSmtpSender()).andReturn("sender");
    EasyMock.expect(settings.getApplicationBaseUrl()).andReturn("appHost");
    mailingEngine.send(new Mail(subject, body, sender.getEmail(), pm.getEmail()));
    EasyMock.replay(notificationManager, hourTypeService, workTimeService, mailTemplateManager, mailingEngine, settings);
    notificationManager.notifyProjectManagers(employees, period, comment);
    EasyMock.verify(notificationManager, hourTypeService, workTimeService, mailTemplateManager, mailingEngine);
}
Also used : HourType(com.artezio.arttime.datamodel.HourType) HashMap(java.util.HashMap) Period(com.artezio.arttime.datamodel.Period) 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 78 with Project

use of com.artezio.arttime.datamodel.Project 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<>();
    timeProblems.put(employee1, new HashMap<>());
    timeProblems.put(employee2, new HashMap<>());
    timeProblems.put(employee3, new HashMap<>());
    Set<WorkTimeProblems> actual = notificationManager.getEmployeeWorktimeProblems(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) WorkTimeProblems(com.artezio.arttime.services.NotificationManager.WorkTimeProblems) Test(org.junit.Test)

Example 79 with Project

use of com.artezio.arttime.datamodel.Project 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);
    List<Employee> employees = Arrays.asList(employee1, employee2, employee4);
    ProjectRepository.ProjectQuery projectQuery = Mockito.mock(ProjectRepository.ProjectQuery.class, Mockito.RETURNS_DEEP_STUBS);
    List<Project> expected = Arrays.asList(project1, project2);
    EasyMock.expect(projectRepository.query()).andReturn(projectQuery);
    Mockito.when(projectQuery.status(ACTIVE).teamMembers(employees).fetchManagers().fetchTeam().list()).thenReturn(expected);
    EasyMock.replay(projectRepository);
    List<Project> actual = notificationManager.getProjects(employees);
    assertEquals(expected, actual);
    EasyMock.verify(projectRepository);
}
Also used : Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) ProjectRepository(com.artezio.arttime.repositories.ProjectRepository) Test(org.junit.Test)

Example 80 with Project

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

the class ProjectServiceTest method testGetProjectHierarchy_ProjectHasNoSubprojects.

@Test
public void testGetProjectHierarchy_ProjectHasNoSubprojects() {
    Project master = createProject(1L, null);
    List<Project> expected = asList(master);
    ProjectRepository.ProjectQuery projectQuery = Mockito.mock(ProjectRepository.ProjectQuery.class, Mockito.RETURNS_DEEP_STUBS);
    EasyMock.expect(projectRepository.query()).andReturn(projectQuery).once();
    Mockito.when(projectQuery.masters(asList(master)).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)

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