Search in sources :

Example 51 with Period

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

the class HoursRepositoryTest method testGetActualHours_noHoursInPeriod.

@Test
public void testGetActualHours_noHoursInPeriod() 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 hours1 = createHours(project, employee, getOffsetDate(3), actualType, quantity);
    Hours hours2 = createHours(project, employee, getOffsetDate(-1), actualType, quantity);
    entityManager.persist(employee);
    entityManager.persist(project);
    entityManager.persist(actualType);
    entityManager.persist(hours1);
    entityManager.persist(hours2);
    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 52 with Period

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

the class HoursRepositoryTest method testGetActualHoursSum.

@Test
public void testGetActualHoursSum() throws Exception {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Employee employee = new Employee("username");
    Date start = sdf.parse("2014-11-01");
    WorkdaysCalendar calendar = new WorkdaysCalendar("calendar");
    Project project = createActiveProjectWithTeamMember(employee, calendar);
    HourType actualType = new HourType("actual");
    actualType.setActualTime(true);
    HourType notActualType = new HourType("not_actual");
    Hours approved = createHours(project, employee, sdf.parse("2014-11-02"), actualType, new BigDecimal("8"));
    approved.setApproved(true);
    Hours notApproved1 = createHours(project, employee, sdf.parse("2014-11-03"), actualType, new BigDecimal("8"));
    Hours notApproved2 = createHours(project, employee, sdf.parse("2014-11-04"), actualType, new BigDecimal("8"));
    Hours notActual = createHours(project, employee, sdf.parse("2014-11-05"), notActualType, new BigDecimal("8"));
    Hours beforePeriod = createHours(project, employee, sdf.parse("2014-10-31"), actualType, new BigDecimal("8"));
    entityManager.persist(actualType);
    entityManager.persist(notActualType);
    entityManager.persist(approved);
    entityManager.persist(notApproved1);
    entityManager.persist(notApproved2);
    entityManager.persist(notActual);
    entityManager.persist(beforePeriod);
    Period period = new Period(start, sdf.parse("2014-11-30"));
    BigDecimal actual = hoursRepository.getActualHoursSum(employee, period);
    assertEquals(new BigDecimal("24.00"), actual);
}
Also used : WorkdaysCalendar(com.artezio.arttime.datamodel.WorkdaysCalendar) 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) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) CalendarUtils.getOffsetDate(com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 53 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) 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 54 with Period

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

the class HoursRepositoryTest method testGetActualHours_unexpectedEmployee.

@Test
public void testGetActualHours_unexpectedEmployee() throws NoSuchFieldException {
    Date start = new Date();
    Date finish = getOffsetDate(2);
    Period period = new Period(start, finish);
    Employee expectedEmployee = new Employee("expected employee");
    Employee unexpectedEmployee = new Employee("unexpected employee");
    Project project = new Project();
    HourType actualType = new HourType("actual type");
    actualType.setActualTime(true);
    BigDecimal quantity = new BigDecimal(8);
    Hours hours = createHours(project, unexpectedEmployee, getOffsetDate(1), actualType, quantity);
    entityManager.persist(expectedEmployee);
    entityManager.persist(unexpectedEmployee);
    entityManager.persist(project);
    entityManager.persist(actualType);
    entityManager.persist(hours);
    List<Hours> actuals = hoursRepository.getActualHours(Collections.singletonList(expectedEmployee), 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 55 with Period

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

the class HoursRepositoryTest method testGetApprovedActualHoursSum.

@Test
public void testGetApprovedActualHoursSum() 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 quantity1 = new BigDecimal(8);
    BigDecimal quantity2 = new BigDecimal(8);
    Hours hours1 = createHours(project, employee, getOffsetDate(1), actualType, quantity1);
    Hours hours2 = createHours(project, employee, getOffsetDate(2), actualType, quantity2);
    hours1.setApproved(true);
    hours2.setApproved(true);
    entityManager.persist(employee);
    entityManager.persist(project);
    entityManager.persist(actualType);
    entityManager.persist(hours1);
    entityManager.persist(hours2);
    BigDecimal actual = hoursRepository.getApprovedActualHoursSum(employee, period);
    assertEquals(new BigDecimal("16.00"), 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