Search in sources :

Example 61 with Period

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

the class HoursRepositoryTest method testGetManagersForApproveByEmployee.

@Test
public void testGetManagersForApproveByEmployee() {
    Date start = new Date();
    Date finish = getOffsetDate(3);
    Period period = new Period(start, finish);
    Employee manager1 = new Employee("manager1");
    Employee manager2 = new Employee("manager2");
    Employee manager3 = new Employee("manager3");
    Employee manager4 = new Employee("manager4");
    Employee manager5 = new Employee("manager5");
    Project project1 = new Project();
    project1.setManagers(Arrays.asList(manager1));
    Project project2 = new Project();
    project2.setManagers(Arrays.asList(manager2, manager3));
    Project project3 = new Project();
    project3.setManagers(Arrays.asList(manager2, manager4, manager5));
    Employee employee1 = new Employee("employee1");
    Employee employee2 = new Employee("employee2");
    HourType actualType = new HourType("actual type");
    actualType.setActualTime(true);
    Hours hours1 = createHours(project1, employee1, getOffsetDate(2), actualType, new BigDecimal(8));
    Hours hours2 = createHours(project2, employee1, getOffsetDate(2), actualType, new BigDecimal(8));
    Hours hours3 = createHours(project3, employee1, getOffsetDate(2), actualType, new BigDecimal(8));
    Hours hours4 = createHours(project2, employee2, getOffsetDate(2), actualType, new BigDecimal(8));
    entityManager.persist(manager1);
    entityManager.persist(manager2);
    entityManager.persist(manager3);
    entityManager.persist(manager4);
    entityManager.persist(manager5);
    entityManager.persist(actualType);
    entityManager.persist(employee1);
    entityManager.persist(employee2);
    entityManager.persist(project1);
    entityManager.persist(project2);
    entityManager.persist(project3);
    entityManager.persist(hours1);
    entityManager.persist(hours2);
    entityManager.persist(hours3);
    entityManager.persist(hours4);
    Map<Employee, List<Employee>> actual = hoursRepository.getManagersForApproveByEmployee(Arrays.asList(employee1, employee2), period);
    assertEquals(2, actual.size());
    ListAssert.assertEquals(Arrays.asList(manager1, manager2, manager3, manager4, manager5), actual.get(employee1));
    ListAssert.assertEquals(Arrays.asList(manager2, manager3), actual.get(employee2));
}
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 62 with Period

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

the class HoursRepositoryTest method testGetActualHours_ifHoursForStartPeriod.

@Test
public void testGetActualHours_ifHoursForStartPeriod() 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, start, 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)

Example 63 with Period

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

the class NotificationSchedulerTest method testGetPeriodForPreviousMonth.

@Test
public void testGetPeriodForPreviousMonth() {
    notificationScheduler = partialMockBuilder(NotificationScheduler.class).addMockedMethod("getCurrentDate").createMock();
    Date start = new GregorianCalendar(2020, 1, 1).getTime();
    Date finish = new GregorianCalendar(2020, 1, 29).getTime();
    Period expected = new Period(start, finish);
    Date now = new GregorianCalendar(2020, 2, 1).getTime();
    expect(notificationScheduler.getCurrentDate()).andReturn(now);
    replayAll();
    Period actual = notificationScheduler.getPeriodForPreviousMonth();
    verifyAll();
    assertEquals(expected, actual);
}
Also used : GregorianCalendar(java.util.GregorianCalendar) Period(com.artezio.arttime.datamodel.Period) Date(java.util.Date) Test(org.junit.Test)

Example 64 with Period

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

the class NotificationSchedulerTest method testNotifyAboutIncorrectTimesheet.

@Test
public void testNotifyAboutIncorrectTimesheet() {
    List<Employee> employees = Arrays.asList(new Employee("test_user"));
    Date start = new GregorianCalendar(2020, 1, 1).getTime();
    Date finish = new GregorianCalendar(2020, 1, 29).getTime();
    Period period = new Period(start, finish);
    expect(settingsService.getSettings()).andReturn(settings);
    expect(settings.isIncorrectTimesheetNotificationEnabled()).andReturn(true);
    expect(employeeService.getCurrent()).andReturn(employees);
    expect(notificationScheduler.getPeriodForPreviousMonth()).andReturn(period);
    notificationManager.notifyAboutIncorrectTimesheet(employees, period);
    expectLastCall().once();
    replayAll();
    notificationScheduler.notifyAboutIncorrectTimesheet();
    verifyAll();
}
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 65 with Period

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

the class WorkdaysCalendarBeanTest method testPrevMonth.

@Test
public void testPrevMonth() throws Exception {
    Map<String, String> map = new HashMap<>();
    map.put("monthCount", "1");
    Period period = new Period(sdf.parse("1-01-2015"), sdf.parse("31-01-2015"));
    setField(calendarBean, "period", period);
    Period expected = new Period(sdf.parse("1-12-2014"), sdf.parse("31-12-2014"));
    expect(externalContext.getRequestParameterMap()).andReturn(map);
    expect(workdaysCalendarService.getDays(anyObject(WorkdaysCalendar.class), anyObject(Period.class))).andReturn(new ArrayList<Day>());
    replayAll(workdaysCalendarService, externalContext);
    calendarBean.prevMonth();
    verify(workdaysCalendarService);
    Period actual = (Period) getField(calendarBean, "period");
    assertEquals(expected, actual);
}
Also used : WorkdaysCalendar(com.artezio.arttime.datamodel.WorkdaysCalendar) Period(com.artezio.arttime.datamodel.Period) Day(com.artezio.arttime.datamodel.Day) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

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