Search in sources :

Example 26 with DateRange

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);
}
Also used : DateRange(com.qcadoo.commons.dateTime.DateRange) Date(java.util.Date) Test(org.junit.Test)

Example 27 with DateRange

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);
}
Also used : DateRange(com.qcadoo.commons.dateTime.DateRange) Date(java.util.Date) Test(org.junit.Test)

Example 28 with DateRange

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");
}
Also used : DateRange(com.qcadoo.commons.dateTime.DateRange) Date(java.util.Date) Test(org.junit.Test)

Example 29 with DateRange

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());
}
Also used : Entity(com.qcadoo.model.api.Entity) DateRange(com.qcadoo.commons.dateTime.DateRange) LocalTime(org.joda.time.LocalTime) EntityList(com.qcadoo.model.api.EntityList) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

DateRange (com.qcadoo.commons.dateTime.DateRange)29 Test (org.junit.Test)25 Date (java.util.Date)24 DateTime (org.joda.time.DateTime)20 Entity (com.qcadoo.model.api.Entity)2 Shift (com.qcadoo.mes.basic.shift.Shift)1 EntityList (com.qcadoo.model.api.EntityList)1 LocalTime (org.joda.time.LocalTime)1