Search in sources :

Example 6 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) CalendarUtils.createPeriod(com.artezio.arttime.test.utils.CalendarUtils.createPeriod) Date(java.util.Date) CalendarUtils.getOffsetDate(com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 7 with Period

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

the class HoursRepositoryTest method testGetActualHoursLists.

@Test
public void testGetActualHoursLists() {
    Date start = new Date();
    Date finish = getOffsetDate(2);
    Period period = new Period(start, finish);
    Employee employee1 = new Employee("employee1");
    Employee employee2 = new Employee("employee2");
    Employee employee3 = new Employee("employee3");
    Project project = new Project();
    HourType actualType = new HourType("actual type");
    actualType.setActualTime(true);
    BigDecimal quantity = new BigDecimal(8);
    Hours hours1 = createHours(project, employee1, getOffsetDate(1), actualType, quantity);
    Hours hours2 = createHours(project, employee1, getOffsetDate(2), actualType, quantity);
    Hours hours3 = createHours(project, employee2, getOffsetDate(0), actualType, quantity);
    hours1.setApproved(true);
    hours2.setApproved(false);
    hours3.setApproved(true);
    entityManager.persist(employee1);
    entityManager.persist(employee2);
    entityManager.persist(employee3);
    entityManager.persist(project);
    entityManager.persist(actualType);
    entityManager.persist(hours1);
    entityManager.persist(hours2);
    entityManager.persist(hours3);
    List<Employee> employees = asList(employee1, employee2, employee3);
    Map<Employee, List<Hours>> actualHours = hoursRepository.getActualHoursLists(employees, period, false);
    Map<Employee, List<Hours>> approvedActualHours = hoursRepository.getActualHoursLists(employees, period, true);
    ListAssert.assertEquals(asList(hours1, hours2), actualHours.get(employee1));
    ListAssert.assertEquals(Collections.singletonList(hours3), actualHours.get(employee2));
    assertTrue(actualHours.get(employee3).isEmpty());
    ListAssert.assertEquals(Collections.singletonList(hours1), approvedActualHours.get(employee1));
    ListAssert.assertEquals(Collections.singletonList(hours3), approvedActualHours.get(employee2));
    assertTrue(approvedActualHours.get(employee3).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) Period(com.artezio.arttime.datamodel.Period) CalendarUtils.createPeriod(com.artezio.arttime.test.utils.CalendarUtils.createPeriod) ArrayList(java.util.ArrayList) 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 8 with Period

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

the class HoursRepositoryTest method testGetActualHours_unexpectedHourType.

@Test
public void testGetActualHours_unexpectedHourType() 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);
    HourType unexpectedType = new HourType("type");
    actualType.setActualTime(false);
    BigDecimal quantity = new BigDecimal(8);
    Hours hours = createHours(project, employee, getOffsetDate(1), unexpectedType, quantity);
    entityManager.persist(employee);
    entityManager.persist(project);
    entityManager.persist(actualType);
    entityManager.persist(unexpectedType);
    entityManager.persist(hours);
    List<Hours> actuals = hoursRepository.getActualHours(Collections.singletonList(employee), period, false);
    assertTrue(actuals.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) Period(com.artezio.arttime.datamodel.Period) CalendarUtils.createPeriod(com.artezio.arttime.test.utils.CalendarUtils.createPeriod) Date(java.util.Date) CalendarUtils.getOffsetDate(com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 9 with Period

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

the class HoursRepositoryTest method testGetActualHours.

@Test
public void testGetActualHours() throws NoSuchFieldException {
    Date start = new Date();
    Date finish = getOffsetDate(2);
    Period period = new Period(start, finish);
    Employee employee1 = new Employee("employee1");
    Employee employee2 = new Employee("employee2");
    Project project = new Project();
    HourType actualType = new HourType("actual type");
    actualType.setActualTime(true);
    BigDecimal quantity = new BigDecimal(8);
    Hours hours1 = createHours(project, employee1, getOffsetDate(1), actualType, quantity);
    Hours hours2 = createHours(project, employee1, getOffsetDate(2), actualType, quantity);
    Hours hours3 = createHours(project, employee2, getOffsetDate(0), actualType, quantity);
    hours1.setApproved(true);
    hours2.setApproved(false);
    hours3.setApproved(true);
    entityManager.persist(employee1);
    entityManager.persist(employee2);
    entityManager.persist(project);
    entityManager.persist(actualType);
    entityManager.persist(hours1);
    entityManager.persist(hours2);
    entityManager.persist(hours3);
    List<Employee> employees = asList(employee1, employee2);
    List<Hours> actualHours = hoursRepository.getActualHours(employees, period, false);
    List<Hours> approvedActualHours = hoursRepository.getActualHours(employees, period, true);
    ListAssert.assertEquals(asList(hours1, hours2, hours3), actualHours);
    ListAssert.assertEquals(asList(hours1, hours3), approvedActualHours);
}
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) CalendarUtils.createPeriod(com.artezio.arttime.test.utils.CalendarUtils.createPeriod) Date(java.util.Date) CalendarUtils.getOffsetDate(com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 10 with Period

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

the class HoursRepositoryTest method testGetApprovedActualHoursSum_unexpectedHourType.

@Test
public void testGetApprovedActualHoursSum_unexpectedHourType() throws NoSuchFieldException {
    Date start = new Date();
    Date finish = getOffsetDate(2);
    Period period = new Period(start, finish);
    Employee employee = new Employee("expected employee");
    Project project = new Project();
    HourType actualType = new HourType("actual type");
    actualType.setActualTime(true);
    HourType unexpectedType = new HourType("type");
    actualType.setActualTime(false);
    BigDecimal quantity = new BigDecimal(8);
    Hours hours = createHours(project, employee, getOffsetDate(1), unexpectedType, quantity);
    entityManager.persist(employee);
    entityManager.persist(project);
    entityManager.persist(actualType);
    entityManager.persist(unexpectedType);
    entityManager.persist(hours);
    BigDecimal actual = hoursRepository.getApprovedActualHoursSum(employee, period);
    assertEquals(BigDecimal.ZERO, 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) Period(com.artezio.arttime.datamodel.Period) CalendarUtils.createPeriod(com.artezio.arttime.test.utils.CalendarUtils.createPeriod) 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