use of com.qcadoo.commons.dateTime.DateRange in project mes by qcadoo.
the class OrderHooksTest method shouldReturnTrueForNullToDate.
@Test
public void shouldReturnTrueForNullToDate() throws Exception {
// given
DateRange dateRange = new DateRange(new Date(), null);
given(orderDatesService.getCalculatedDates(order)).willReturn(dateRange);
// when
boolean result = orderHooks.checkOrderDates(orderDD, order);
// then
assertTrue(result);
}
use of com.qcadoo.commons.dateTime.DateRange in project mes by qcadoo.
the class OrderHooksTest method shouldReturnTrueForValidOrderDates.
@Test
public void shouldReturnTrueForValidOrderDates() throws Exception {
// given
DateRange dateRange = new DateRange(new Date(System.currentTimeMillis() - 10000), new Date());
given(orderDatesService.getCalculatedDates(order)).willReturn(dateRange);
// when
boolean result = orderHooks.checkOrderDates(orderDD, order);
// then
assertTrue(result);
}
use of com.qcadoo.commons.dateTime.DateRange in project mes by qcadoo.
the class OrderHooksTest method shouldReturnFalseForEqualOrderDates.
@Test
public void shouldReturnFalseForEqualOrderDates() throws Exception {
// given
Date currDate = new Date();
DateRange dateRange = new DateRange(currDate, currDate);
given(orderDatesService.getCalculatedDates(order)).willReturn(dateRange);
given(orderDD.getField(OrderFields.FINISH_DATE)).willReturn(dateToField);
// when
boolean result = orderHooks.checkOrderDates(orderDD, order);
// then
assertFalse(result);
verify(order).addError(dateToField, "orders.validate.global.error.datesOrder");
}
use of com.qcadoo.commons.dateTime.DateRange in project mes by qcadoo.
the class ShiftTest method shouldParseTimeTableExceptions.
@Test
public final void shouldParseTimeTableExceptions() {
// given
String hours = "6:00-12:00, 21:30-2:30";
given(shiftEntity.getStringField(ShiftFields.MONDAY_HOURS)).willReturn(hours);
given(shiftEntity.getBooleanField(ShiftFields.MONDAY_WORKING)).willReturn(true);
DateTime mondayMidnight = new DateTime(2013, 9, 2, 0, 0);
DateTime freeTimeBegin = mondayMidnight.plusHours(8);
DateTime freeTimeEnd = freeTimeBegin.plusHours(4);
Entity freeTime = mockTimetableException(TimetableExceptionType.FREE_TIME, freeTimeBegin, freeTimeEnd);
DateTime workTimeBegin = mondayMidnight.plusHours(20);
DateTime workTimeEnd = workTimeBegin.plusHours(2);
Entity workTime = mockTimetableException(TimetableExceptionType.WORK_TIME, workTimeBegin, workTimeEnd);
EntityList timetableExceptionsList = mockEntityList(Lists.newArrayList(freeTime, workTime));
given(shiftEntity.getHasManyField(ShiftFields.TIMETABLE_EXCEPTIONS)).willReturn(timetableExceptionsList);
// when
Shift shift = new Shift(shiftEntity);
// then
assertTrue(shift.worksAt(DateTimeConstants.MONDAY, new LocalTime(10, 30)));
assertFalse(shift.worksAt(DateTimeConstants.SUNDAY, new LocalTime(12, 0)));
assertFalse(shift.worksAt(DateTimeConstants.MONDAY, new LocalTime(12, 01)));
assertEquals(Optional.of(new DateRange(mondayMidnight.plusHours(6).toDate(), mondayMidnight.plusHours(12).toDate())), shift.findWorkTimeAt(mondayMidnight.plusHours(7).toDate()));
assertFalse(shift.findWorkTimeAt(mondayMidnight.plusDays(2).toDate()).isPresent());
assertFalse(shift.findWorkTimeAt(mondayMidnight.plusHours(9).toDate()).isPresent());
}
Aggregations