Search in sources :

Example 56 with Period

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

the class HoursRepositoryTest method testGetApprovedActualHoursSum_thereNotHoursInPeriod.

@Test
public void testGetApprovedActualHoursSum_thereNotHoursInPeriod() 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);
    BigDecimal quantity = new BigDecimal(8);
    Hours hours = createHours(project, employee, getOffsetDate(5), actualType, quantity);
    entityManager.persist(employee);
    entityManager.persist(project);
    entityManager.persist(actualType);
    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)

Example 57 with Period

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

the class CalendarPeriodSelectorTest method testSetMonthPeriod.

@Test
public void testSetMonthPeriod() throws ParseException, NoSuchFieldException {
    Period period = new Period(sdf.parse("1-05-2014"), sdf.parse("3-05-2014"));
    setField(rangePeriodSelector, "period", period);
    setField(rangePeriodSelector, "range", Range.CUSTOM);
    Period expectedPeriod = new Period(sdf.parse("1-05-2014"), sdf.parse("31-05-2014"));
    PowerMock.mockStatic(Locale.class);
    expect(Locale.getDefault()).andReturn(Locale.US);
    rangePeriodSelector.setMonthPeriod();
    Range actualRange = (Range) getField(rangePeriodSelector, "range");
    Period actualPeriod = (Period) getField(rangePeriodSelector, "period");
    assertEquals(Range.MONTH, actualRange);
    assertEquals(expectedPeriod, actualPeriod);
}
Also used : Period(com.artezio.arttime.datamodel.Period) Range(com.artezio.arttime.web.criteria.RangePeriodSelector.Range) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 58 with Period

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

the class CalendarPeriodSelectorTest method testSetCustomPeriod.

@Test
public void testSetCustomPeriod() throws ParseException, NoSuchFieldException {
    Period period = new Period(sdf.parse("1-05-2014"), sdf.parse("3-05-2014"));
    setField(rangePeriodSelector, "period", period);
    setField(rangePeriodSelector, "range", Range.WEEK);
    Period expectedPeriod = new Period(sdf.parse("1-05-2014"), sdf.parse("3-05-2014"));
    PowerMock.mockStatic(Locale.class);
    expect(Locale.getDefault()).andReturn(Locale.US);
    rangePeriodSelector.setCustomPeriod();
    Range actualRange = (Range) getField(rangePeriodSelector, "range");
    Period actualPeriod = (Period) getField(rangePeriodSelector, "period");
    assertEquals(Range.CUSTOM, actualRange);
    assertEquals(expectedPeriod, actualPeriod);
}
Also used : Period(com.artezio.arttime.datamodel.Period) Range(com.artezio.arttime.web.criteria.RangePeriodSelector.Range) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 59 with Period

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

the class HoursRepositoryTest method testGetActualTimeByEmployeeAndApproval.

@Test
public void testGetActualTimeByEmployeeAndApproval() {
    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");
    Employee employee3 = new Employee("employee3");
    HourType actualType = new HourType("actual type");
    actualType.setActualTime(true);
    Hours hours1 = createHours(project, employee1, start, actualType, new BigDecimal(8), true);
    Hours hours2 = createHours(project, employee1, getOffsetDate(1), actualType, new BigDecimal(7), true);
    Hours hours3 = createHours(project, employee1, getOffsetDate(2), actualType, new BigDecimal(6), false);
    Hours hours4 = createHours(project, employee1, getOffsetDate(3), actualType, new BigDecimal(5), false);
    Hours hours5 = createHours(project, employee2, getOffsetDate(1), actualType, new BigDecimal(4), true);
    Hours hours6 = createHours(project, employee2, getOffsetDate(2), actualType, new BigDecimal(3), false);
    Hours hours7 = createHours(project, employee3, getOffsetDate(1), actualType, new BigDecimal(2), false);
    entityManager.persist(employee1);
    entityManager.persist(employee2);
    entityManager.persist(employee3);
    entityManager.persist(project);
    entityManager.persist(actualType);
    entityManager.persist(hours1);
    entityManager.persist(hours2);
    entityManager.persist(hours3);
    entityManager.persist(hours4);
    entityManager.persist(hours5);
    entityManager.persist(hours6);
    entityManager.persist(hours7);
    Map<Employee, Map<Boolean, BigDecimal>> actual = hoursRepository.getActualTimeByEmployeeAndApproval(Arrays.asList(employee1, employee2, employee3), period);
    assertEquals(3, actual.size());
    assertEquals(11.0, actual.get(employee1).get(false).doubleValue(), 0.0);
    assertEquals(15.0, actual.get(employee1).get(true).doubleValue(), 0.0);
    assertEquals(3.0, actual.get(employee2).get(false).doubleValue(), 0.0);
    assertEquals(4.0, actual.get(employee2).get(true).doubleValue(), 0.0);
    assertEquals(2.0, actual.get(employee3).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)

Example 60 with Period

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

the class HoursRepositoryTest method testGetActualHours_ifNoHours.

@Test
public void testGetActualHours_ifNoHours() 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) 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