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);
}
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));
}
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());
}
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));
}
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);
}
}
Aggregations