Search in sources :

Example 11 with HourType

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

the class SpreadSheetTest method testGetSortedTeamMembers_FilterHasEmployeesAndDepartments.

@Test
public void testGetSortedTeamMembers_FilterHasEmployeesAndDepartments() throws NoSuchFieldException {
    List<Employee> employees = buildEmployeeList(2);
    List<String> departments = employees.stream().map(Employee::getDepartment).collect(Collectors.toList());
    HourType hourType = new HourType("1");
    List<HourType> hourTypes = Collections.singletonList(hourType);
    Project project = createProject("1", hourTypes, employees);
    List<Hours> hours = buildHourList(project, employees, hourType, new Date(2017, 1, 1));
    setField(filter, "employees", employees);
    setField(filter, "departments", departments);
    setField(spreadSheet, "filter", filter);
    setField(spreadSheet, "workTimeService", workTimeService);
    expect(workTimeService.getEmployees(filter)).andReturn(employees);
    replay(workTimeService);
    SortedSet<Employee> expected = new TreeSet<>(Employee.NAME_COMPARATOR);
    expected.addAll(employees);
    SortedSet<Employee> actual = spreadSheet.getSortedTeamMembers(project, hours);
    assertEquals(expected, 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 12 with HourType

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

the class SpreadSheetTest method testGetSortedTeamMembers_FilterHasEmployeesNotCorrespondingToDepartments.

@Test
public void testGetSortedTeamMembers_FilterHasEmployeesNotCorrespondingToDepartments() throws NoSuchFieldException {
    List<Employee> employees = buildEmployeeList(2);
    List<String> departments = asList("dep1", "dep2");
    HourType hourType = new HourType("1");
    List<HourType> hourTypes = Collections.singletonList(hourType);
    Project project = createProject("1", hourTypes, employees);
    List<Hours> hours = buildHourList(project, employees, hourType, new Date(2017, 1, 1));
    setField(filter, "employees", employees);
    setField(filter, "departments", departments);
    setField(spreadSheet, "filter", filter);
    setField(spreadSheet, "employeeRepository", employeeRepository);
    setField(spreadSheet, "workTimeService", workTimeService);
    expect(workTimeService.getEmployees(filter)).andReturn(Collections.emptyList());
    replay(workTimeService);
    SortedSet<Employee> actual = spreadSheet.getSortedTeamMembers(project, hours);
    assertTrue(actual.isEmpty());
}
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 13 with HourType

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

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

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

the class HourTypeRepositoryTest method testRemoveHourType_RemoveForbidden.

@Test(expected = PersistenceException.class)
public void testRemoveHourType_RemoveForbidden() throws ActualTimeRemovalException {
    HourType hourType = new HourType();
    Project project = new Project();
    project.addAccountableHours(hourType);
    entityManager.persist(hourType);
    entityManager.persist(project);
    hourTypeRepository.remove(hourType);
}
Also used : Project(com.artezio.arttime.datamodel.Project) HourType(com.artezio.arttime.datamodel.HourType) Test(org.junit.Test)

Aggregations

HourType (com.artezio.arttime.datamodel.HourType)172 Test (org.junit.Test)158 Project (com.artezio.arttime.datamodel.Project)120 Employee (com.artezio.arttime.datamodel.Employee)115 Hours (com.artezio.arttime.datamodel.Hours)103 Date (java.util.Date)60 CalendarUtils.getOffsetDate (com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate)54 Period (com.artezio.arttime.datamodel.Period)45 BigDecimal (java.math.BigDecimal)41 CalendarUtils.createPeriod (com.artezio.arttime.test.utils.CalendarUtils.createPeriod)21 HashMap (java.util.HashMap)16 HoursRepository (com.artezio.arttime.repositories.HoursRepository)13 Map (java.util.Map)11 Arrays.asList (java.util.Arrays.asList)10 List (java.util.List)10 Filter (com.artezio.arttime.filter.Filter)7 Mail (com.artezio.arttime.services.mailing.Mail)7 ArrayList (java.util.ArrayList)7 HourTypeRepository (com.artezio.arttime.repositories.HourTypeRepository)6 RangePeriodSelector (com.artezio.arttime.web.criteria.RangePeriodSelector)6