Search in sources :

Example 41 with HourType

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

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

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

the class NotificationManagerTest method testNotifyAboutIncorrectTimesheet_oneEmployee.

@Test
public void testNotifyAboutIncorrectTimesheet_oneEmployee() throws Exception {
    setMockServices(notificationManager);
    Employee employee = new Employee("user_name");
    String employeeEmail = "user_name@mail.com";
    employee.setEmail(employeeEmail);
    Period period = mock(Period.class);
    HourType actualTime = new HourType("actual");
    String senderEmail = "sender@mail.com";
    String body = "mail_body";
    String subject = "mail_subject";
    Mail mail = new Mail(subject, body, senderEmail, employeeEmail);
    String applicationBaseUrl = "url";
    Map<String, Object> mailParameters = new HashMap<>();
    mailParameters.put("hourType", actualTime);
    mailParameters.put("period", period);
    mailParameters.put("appHost", applicationBaseUrl);
    expect(hourTypeService.findActualTime()).andReturn(actualTime);
    expect(settings.getSmtpSender()).andReturn(senderEmail);
    expect(settings.getApplicationBaseUrl()).andReturn(applicationBaseUrl);
    expect(mailTemplateManager.getTemplateText(MailTemplate.INCORRECT_TIMESHEET_BODY.getFileName(), mailParameters)).andReturn(body);
    expect(mailTemplateManager.getTemplateText(MailTemplate.INCORRECT_TIMESHEET_SUBJECT.getFileName(), mailParameters)).andReturn(subject);
    mailingEngine.send(mail);
    replay(hourTypeService, settings, mailTemplateManager, mailingEngine);
    notificationManager.notifyAboutIncorrectTimesheet(employee, period);
    verify(hourTypeService, settings, 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) Test(org.junit.Test)

Example 44 with HourType

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

the class HoursRepositoryTest method testGetManagersForApproveByEmployee_ifNotActualTime.

@Test
public void testGetManagersForApproveByEmployee_ifNotActualTime() {
    Date start = new Date();
    Date finish = getOffsetDate(3);
    Period period = new Period(start, finish);
    Employee manager1 = new Employee("manager1");
    Employee manager2 = new Employee("manager2");
    Project project1 = new Project();
    project1.setManagers(Arrays.asList(manager1));
    Project project2 = new Project();
    project2.setManagers(Arrays.asList(manager2));
    Employee employee = new Employee("employee");
    HourType actualType = new HourType("actual type");
    actualType.setActualTime(true);
    HourType notActualType = new HourType("not actual type");
    Hours hours1 = createHours(project1, employee, getOffsetDate(2), notActualType, new BigDecimal(8));
    Hours hours2 = createHours(project2, employee, getOffsetDate(2), actualType, new BigDecimal(8));
    entityManager.persist(manager1);
    entityManager.persist(manager2);
    entityManager.persist(actualType);
    entityManager.persist(notActualType);
    entityManager.persist(employee);
    entityManager.persist(project1);
    entityManager.persist(project2);
    entityManager.persist(hours1);
    entityManager.persist(hours2);
    Map<Employee, List<Employee>> actual = hoursRepository.getManagersForApproveByEmployee(Arrays.asList(employee), period);
    ListAssert.assertEquals(Arrays.asList(manager2), actual.get(employee));
}
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) Period(com.artezio.arttime.datamodel.Period) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Date(java.util.Date) CalendarUtils.getOffsetDate(com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 45 with HourType

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

the class HoursRepositoryTest method testGetActualTimeByEmployeeAndApproval_ifQuantityIsNull.

@Test
public void testGetActualTimeByEmployeeAndApproval_ifQuantityIsNull() {
    Date start = new Date();
    Date finish = getOffsetDate(3);
    Period period = new Period(start, finish);
    Project project = new Project();
    Employee employee1 = new Employee("employee1");
    Employee employee2 = new Employee("employee2");
    HourType actualType = new HourType("actual type");
    actualType.setActualTime(true);
    Hours hours1 = createHours(project, employee1, getOffsetDate(1), actualType, new BigDecimal(7));
    Hours hours2 = createHours(project, employee1, getOffsetDate(2), actualType, null);
    Hours hours3 = createHours(project, employee2, getOffsetDate(2), actualType, null);
    entityManager.persist(employee1);
    entityManager.persist(employee2);
    entityManager.persist(project);
    entityManager.persist(actualType);
    entityManager.persist(hours1);
    entityManager.persist(hours2);
    entityManager.persist(hours3);
    Map<Employee, Map<Boolean, BigDecimal>> actual = hoursRepository.getActualTimeByEmployeeAndApproval(Arrays.asList(employee1, employee2), period);
    assertEquals(1, actual.size());
    assertEquals(7.0, actual.get(employee1).get(false).doubleValue(), 0.0);
}
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) Period(com.artezio.arttime.datamodel.Period) HashMap(java.util.HashMap) Map(java.util.Map) Date(java.util.Date) CalendarUtils.getOffsetDate(com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate) BigDecimal(java.math.BigDecimal) 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