Search in sources :

Example 86 with Period

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

the class NotificationManagerTest method testNotifyAboutIncorrectTimesheet.

@Test
public void testNotifyAboutIncorrectTimesheet() throws Exception {
    notificationManager = createMockBuilder(NotificationManager.class).addMockedMethod("notifyAboutIncorrectTimesheet", Employee.class, Period.class).createMock();
    setMockServices(notificationManager);
    Employee goodEmployee = new Employee("good_employee");
    Employee badEmployee1 = new Employee("bad_employee1");
    Employee badEmployee2 = new Employee("bad_employee2");
    List<Employee> employees = Arrays.asList(goodEmployee, badEmployee1, badEmployee2);
    Date start = new GregorianCalendar(2020, 1, 1).getTime();
    Date finish = new GregorianCalendar(2020, 1, 29).getTime();
    Period period = new Period(start, finish);
    expect(workTimeService.getRequiredWorkHours(goodEmployee, period)).andReturn(BigDecimal.valueOf(160));
    expect(workTimeService.getRequiredWorkHours(badEmployee1, period)).andReturn(BigDecimal.valueOf(160));
    expect(workTimeService.getRequiredWorkHours(badEmployee2, period)).andReturn(BigDecimal.valueOf(160));
    expect(workTimeService.getActualWorkHours(goodEmployee, period)).andReturn(BigDecimal.valueOf(160));
    expect(workTimeService.getActualWorkHours(badEmployee1, period)).andReturn(BigDecimal.valueOf(8));
    expect(workTimeService.getActualWorkHours(badEmployee2, period)).andReturn(BigDecimal.valueOf(168));
    notificationManager.notifyAboutIncorrectTimesheet(badEmployee1, period);
    notificationManager.notifyAboutIncorrectTimesheet(badEmployee2, period);
    replay(notificationManager, workTimeService);
    notificationManager.notifyAboutIncorrectTimesheet(employees, period);
    verify(notificationManager, workTimeService);
}
Also used : Employee(com.artezio.arttime.datamodel.Employee) GregorianCalendar(java.util.GregorianCalendar) Period(com.artezio.arttime.datamodel.Period) Date(java.util.Date) Test(org.junit.Test)

Example 87 with Period

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

the class NotificationManagerTest method testNotifyAboutUnapprovedHours.

@Test
public void testNotifyAboutUnapprovedHours() throws Exception {
    notificationManager = createMockBuilder(NotificationManager.class).addMockedMethod("notifyAboutUnapprovedHours", Employee.class, Period.class).createMock();
    setMockServices(notificationManager);
    Date start = new GregorianCalendar(2020, 1, 1).getTime();
    Date finish = new GregorianCalendar(2020, 1, 29).getTime();
    Period period = new Period(start, finish);
    Employee manager1 = new Employee("user1");
    Employee manager2 = new Employee("user2");
    ;
    List<Employee> managers = Arrays.asList(manager1, manager2);
    notificationManager.notifyAboutUnapprovedHours(manager1, period);
    notificationManager.notifyAboutUnapprovedHours(manager2, period);
    replay(notificationManager);
    notificationManager.notifyAboutUnapprovedHours(managers, period);
    verify(notificationManager);
}
Also used : Employee(com.artezio.arttime.datamodel.Employee) GregorianCalendar(java.util.GregorianCalendar) Period(com.artezio.arttime.datamodel.Period) Date(java.util.Date) Test(org.junit.Test)

Example 88 with Period

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

the class NotificationManagerTest method testNotifyAboutOwnTimeProblems.

@Test
public void testNotifyAboutOwnTimeProblems() throws 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<>();
    timeProblems.put(employee, new HashMap<>());
    Period period = new Period();
    String comment = "comment";
    String subject = "subject";
    String body = "body";
    EasyMock.expect(hourTypeService.findActualTime()).andReturn(new HourType());
    EasyMock.expect(workTimeService.getWorkTimeDeviations(period, employees)).andReturn(timeProblems);
    EasyMock.expect(mailTemplateManager.getTemplateText(eq(MailTemplate.TIME_PROBLEM_BODY.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("username");
    EasyMock.expect(settings.getSmtpSender()).andReturn("sender");
    EasyMock.expect(settings.getApplicationBaseUrl()).andReturn("appHost");
    mailingEngine.send(new Mail(subject, body, "sender", "iivanov@mail.com"));
    String principalName = "someuser";
    Principal principal = Mockito.mock(Principal.class);
    Mockito.when(principal.getName()).thenReturn(principalName);
    EasyMock.expect(employeeRepository.get(principalName)).andReturn(employee);
    EasyMock.replay(hourTypeService, workTimeService, mailTemplateManager, mailingEngine, settings, employeeRepository, sessionContext);
    notificationManager.notifyEmployees(employees, period, comment);
    EasyMock.verify(hourTypeService, 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) Principal(java.security.Principal) Test(org.junit.Test)

Example 89 with Period

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

the class WorkdaysCalendarServiceTest method testGetDays.

@Test
public void testGetDays() {
    Date start = new Date();
    Date finish = getOffsetDate(2);
    Period period = new Period(start, finish);
    WorkdaysCalendar calendar = new WorkdaysCalendar("calendar");
    Day day = new Day(new Date(), calendar);
    expect(workdaysCalendarRepository.getSpecialDays(anyObject(), anyObject())).andReturn(new ArrayList<>());
    replay(workdaysCalendarRepository);
    List<Day> actual = workdaysCalendarService.getDays(calendar, period);
    assertNotNull(actual);
    assertEquals(3, actual.size());
}
Also used : WorkdaysCalendar(com.artezio.arttime.datamodel.WorkdaysCalendar) Period(com.artezio.arttime.datamodel.Period) Day(com.artezio.arttime.datamodel.Day) CalendarUtils.getOffsetDate(com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate) Test(org.junit.Test)

Example 90 with Period

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

the class HoursRepositoryTest method testGetActualHours_ifHoursForFinishPeriod.

@Test
public void testGetActualHours_ifHoursForFinishPeriod() throws NoSuchFieldException {
    Date start = new Date();
    Date finish = getOffsetDate(2);
    Period period = new Period(start, finish);
    Employee employee = new Employee("employee");
    Project project = new Project();
    HourType actualType = new HourType("actual type");
    actualType.setActualTime(true);
    BigDecimal quantity = new BigDecimal(8);
    Hours hours = createHours(project, employee, finish, actualType, quantity);
    entityManager.persist(employee);
    entityManager.persist(project);
    entityManager.persist(actualType);
    entityManager.persist(hours);
    List<Hours> actuals = hoursRepository.getActualHours(Collections.singletonList(employee), period, false);
    assertEquals(Collections.singletonList(hours), actuals);
}
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) Date(java.util.Date) CalendarUtils.getOffsetDate(com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

Period (com.artezio.arttime.datamodel.Period)93 Test (org.junit.Test)87 Employee (com.artezio.arttime.datamodel.Employee)59 Date (java.util.Date)56 CalendarUtils.getOffsetDate (com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate)44 HourType (com.artezio.arttime.datamodel.HourType)43 Project (com.artezio.arttime.datamodel.Project)42 Hours (com.artezio.arttime.datamodel.Hours)40 BigDecimal (java.math.BigDecimal)34 CalendarUtils.createPeriod (com.artezio.arttime.test.utils.CalendarUtils.createPeriod)22 Day (com.artezio.arttime.datamodel.Day)17 HashMap (java.util.HashMap)15 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)15 WorkdaysCalendar (com.artezio.arttime.datamodel.WorkdaysCalendar)13 List (java.util.List)13 Map (java.util.Map)11 ArrayList (java.util.ArrayList)8 GregorianCalendar (java.util.GregorianCalendar)8 HoursRepository (com.artezio.arttime.repositories.HoursRepository)7 Mail (com.artezio.arttime.services.mailing.Mail)7