Search in sources :

Example 26 with Day

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

the class WorkdaysCalendarBeanTest method testPrevMonth.

@Test
public void testPrevMonth() throws Exception {
    Map<String, String> map = new HashMap<>();
    map.put("monthCount", "1");
    Period period = new Period(sdf.parse("1-01-2015"), sdf.parse("31-01-2015"));
    setField(calendarBean, "period", period);
    Period expected = new Period(sdf.parse("1-12-2014"), sdf.parse("31-12-2014"));
    expect(externalContext.getRequestParameterMap()).andReturn(map);
    expect(workdaysCalendarService.getDays(anyObject(WorkdaysCalendar.class), anyObject(Period.class))).andReturn(new ArrayList<Day>());
    replayAll(workdaysCalendarService, externalContext);
    calendarBean.prevMonth();
    verify(workdaysCalendarService);
    Period actual = (Period) getField(calendarBean, "period");
    assertEquals(expected, actual);
}
Also used : WorkdaysCalendar(com.artezio.arttime.datamodel.WorkdaysCalendar) Period(com.artezio.arttime.datamodel.Period) Day(com.artezio.arttime.datamodel.Day) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 27 with Day

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

the class WorkdaysCalendarBeanTest method testPopulateDays.

@Test
public void testPopulateDays() throws NoSuchFieldException, ParseException {
    Map<Date, Day> days = new HashMap<Date, Day>();
    setField(calendarBean, "days", days);
    DateFormat df = new SimpleDateFormat("dd-MM-yyyy");
    Period extendedPeriod = new Period(df.parse("01-12-2014"), df.parse("28-02-2015"));
    setField(calendarBean, "extendedPeriod", extendedPeriod);
    WorkdaysCalendar workdaysCalendar = new WorkdaysCalendar();
    setField(calendarBean, "workdaysCalendar", workdaysCalendar);
    List<Day> result = new ArrayList<Day>();
    for (Date date : extendedPeriod.getDays()) {
        result.add(new Day(date, workdaysCalendar));
    }
    expect(workdaysCalendarService.getDays(workdaysCalendar, extendedPeriod)).andReturn(result);
    replay(workdaysCalendarService);
    calendarBean.populateDays();
    verify(workdaysCalendarService);
    assertArrayEquals(result.toArray(), days.values().toArray());
}
Also used : WorkdaysCalendar(com.artezio.arttime.datamodel.WorkdaysCalendar) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) Period(com.artezio.arttime.datamodel.Period) Day(com.artezio.arttime.datamodel.Day) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 28 with Day

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

the class WorkdaysCalendarBeanTest method testNextMonth.

@Test
public void testNextMonth() throws Exception {
    Map<String, String> map = new HashMap<>();
    map.put("monthCount", "1");
    Period period = new Period(sdf.parse("1-01-2015"), sdf.parse("31-01-2015"));
    setField(calendarBean, "period", period);
    Period expected = new Period(sdf.parse("1-02-2015"), sdf.parse("28-02-2015"));
    expect(externalContext.getRequestParameterMap()).andReturn(map);
    expect(workdaysCalendarService.getDays(anyObject(WorkdaysCalendar.class), anyObject(Period.class))).andReturn(new ArrayList<Day>());
    replayAll(workdaysCalendarService, externalContext);
    calendarBean.nextMonth();
    verify(workdaysCalendarService);
    Period actual = (Period) getField(calendarBean, "period");
    assertEquals(expected, actual);
}
Also used : WorkdaysCalendar(com.artezio.arttime.datamodel.WorkdaysCalendar) Period(com.artezio.arttime.datamodel.Period) Day(com.artezio.arttime.datamodel.Day) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 29 with Day

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

the class WorkdaysCalendarBeanTest method testGetDaysOff_ifDayIsWorking.

@Test
public void testGetDaysOff_ifDayIsWorking() throws Exception {
    Period extendedPeriod = new Period(sdf.parse("01-12-2014"), sdf.parse("28-02-2015"));
    setField(calendarBean, "extendedPeriod", extendedPeriod);
    Date date = sdf.parse("1-01-2015");
    Map<Date, Day> days = new HashMap<Date, Day>();
    days.put(date, new Day(date, null, true));
    setField(calendarBean, "days", days);
    assertEquals(calendarBean.getDaysOff(), "");
}
Also used : Period(com.artezio.arttime.datamodel.Period) Day(com.artezio.arttime.datamodel.Day) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 30 with Day

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

the class WorkdaysCalendarBeanTest method testGetDaysShift_ifExist.

@Test
public void testGetDaysShift_ifExist() throws ParseException, Exception {
    DateFormat df = new SimpleDateFormat("dd-MM-yyyy");
    Period period = new Period(df.parse("01-12-2014"), df.parse("28-02-2015"));
    WorkdaysCalendar workdaysCalendar = new WorkdaysCalendar();
    setField(calendarBean, "workdaysCalendar", workdaysCalendar);
    Day day1 = createDay(1L, sdf.parse("1-01-2015"));
    day1.setShiftedFrom(sdf.parse("1-01-2015"));
    day1.setShiftedTo(sdf.parse("5-01-2015"));
    Map<Date, Day> days = new HashMap<Date, Day>();
    days.put(day1.getDate(), day1);
    setField(calendarBean, "days", days);
    setField(calendarBean, "period", period);
    List<Day> expected = Arrays.asList(day1);
    List<Day> actual = calendarBean.getDaysShift();
    assertEquals(expected, actual);
}
Also used : WorkdaysCalendar(com.artezio.arttime.datamodel.WorkdaysCalendar) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) Period(com.artezio.arttime.datamodel.Period) SimpleDateFormat(java.text.SimpleDateFormat) Day(com.artezio.arttime.datamodel.Day) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Day (com.artezio.arttime.datamodel.Day)37 Test (org.junit.Test)33 WorkdaysCalendar (com.artezio.arttime.datamodel.WorkdaysCalendar)25 Period (com.artezio.arttime.datamodel.Period)17 CalendarUtils.getOffsetDate (com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate)16 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)15 Date (java.util.Date)8 DateFormat (java.text.DateFormat)5 SimpleDateFormat (java.text.SimpleDateFormat)5 GregorianCalendar (java.util.GregorianCalendar)2 SelectEvent (org.primefaces.event.SelectEvent)1