Search in sources :

Example 11 with Period

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

the class HoursRepositoryTest method testGetApprovedActualHoursSum_ifHoursForStartPeriod.

@Test
public void testGetApprovedActualHoursSum_ifHoursForStartPeriod() 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, start, actualType, quantity);
    hours.setApproved(true);
    entityManager.persist(employee);
    entityManager.persist(project);
    entityManager.persist(actualType);
    entityManager.persist(hours);
    BigDecimal actual = hoursRepository.getApprovedActualHoursSum(employee, period);
    assertEquals(new BigDecimal("8.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)

Example 12 with Period

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

the class WorkdaysCalendarRepositoryTest method testGetPersistedDays_ShouldFilterByCalendar.

@Test
public void testGetPersistedDays_ShouldFilterByCalendar() {
    WorkdaysCalendar expectedCalendar = new WorkdaysCalendar();
    WorkdaysCalendar unexpectedCalendar = new WorkdaysCalendar();
    String expectedName = "expected calendar name";
    String unexpectedName = "unexpected calendar name";
    expectedCalendar.setName(expectedName);
    unexpectedCalendar.setName(unexpectedName);
    Date start = new Date();
    Date finish = getOffsetDate(1);
    Day expectedDay = new Day(start, expectedCalendar);
    Day unexpectedDay = new Day(start, unexpectedCalendar);
    entityManager.persist(expectedCalendar);
    entityManager.persist(unexpectedCalendar);
    entityManager.persist(expectedDay);
    entityManager.persist(unexpectedDay);
    Period period = new Period(start, finish);
    List<Day> actuals = workdaysCalendarRepository.getPersistedDays(expectedCalendar, period);
    assertEquals(1, actuals.size());
    assertTrue(actuals.contains(expectedDay));
}
Also used : WorkdaysCalendar(com.artezio.arttime.datamodel.WorkdaysCalendar) Period(com.artezio.arttime.datamodel.Period) Day(com.artezio.arttime.datamodel.Day) Date(java.util.Date) CalendarUtils.getOffsetDate(com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate) Test(org.junit.Test)

Example 13 with Period

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

the class WorkdaysCalendarRepositoryTest 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);
    entityManager.persist(calendar);
    entityManager.persist(day);
    entityManager.flush();
    entityManager.clear();
    List<Day> actual = workdaysCalendarRepository.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) Date(java.util.Date) CalendarUtils.getOffsetDate(com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate) Test(org.junit.Test)

Example 14 with Period

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

the class WorkdaysCalendarRepositoryTest method testGetPersistedDays_ShouldFilterByPeriod.

@Test
public void testGetPersistedDays_ShouldFilterByPeriod() {
    WorkdaysCalendar workdaysCalendar = new WorkdaysCalendar();
    workdaysCalendar.setName("calendarName");
    Date start = new GregorianCalendar(2011, 0, 2).getTime();
    Date finish = new GregorianCalendar(2011, 0, 29).getTime();
    Date expectedDate = new GregorianCalendar(2011, 0, 15).getTime();
    Date unexpectedDate1 = new GregorianCalendar(2011, 0, 1).getTime();
    Date unexpectedDate2 = new GregorianCalendar(2011, 0, 30).getTime();
    Period period = new Period(start, finish);
    Day expected1 = new Day(start, workdaysCalendar);
    Day expected2 = new Day(expectedDate, workdaysCalendar);
    Day expected3 = new Day(finish, workdaysCalendar);
    Day unexpected1 = new Day(unexpectedDate1, workdaysCalendar);
    Day unexpected2 = new Day(unexpectedDate2, workdaysCalendar);
    entityManager.persist(workdaysCalendar);
    entityManager.persist(expected1);
    entityManager.persist(expected3);
    entityManager.persist(expected2);
    entityManager.persist(unexpected1);
    entityManager.persist(unexpected2);
    List<Day> actuals = workdaysCalendarRepository.getPersistedDays(workdaysCalendar, period);
    assertEquals(3, actuals.size());
    assertFalse(actuals.contains(unexpected1));
    assertFalse(actuals.contains(unexpected2));
}
Also used : WorkdaysCalendar(com.artezio.arttime.datamodel.WorkdaysCalendar) GregorianCalendar(java.util.GregorianCalendar) Period(com.artezio.arttime.datamodel.Period) Day(com.artezio.arttime.datamodel.Day) Date(java.util.Date) CalendarUtils.getOffsetDate(com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate) Test(org.junit.Test)

Example 15 with Period

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

the class PeriodValidator method validate.

@Override
public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
    UIInput startComponent = getStartComponent(component);
    Period period = new Period((Date) startComponent.getValue(), (Date) value);
    Set<ConstraintViolation<Object>> violations = createBeanValidator(context).validate(period);
    if (!violations.isEmpty()) {
        List<FacesMessage> messages = violations.stream().map(ConstraintViolation::getMessage).map(Messages::createError).collect(Collectors.toList());
        startComponent.setValid(false);
        showErrorsForStart(startComponent, component, messages);
        throw new ValidatorException(messages);
    }
}
Also used : ValidatorException(javax.faces.validator.ValidatorException) ConstraintViolation(javax.validation.ConstraintViolation) Period(com.artezio.arttime.datamodel.Period) UIInput(javax.faces.component.UIInput) FacesMessage(javax.faces.application.FacesMessage)

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