Search in sources :

Example 66 with Period

use of com.artezio.arttime.datamodel.Period 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 67 with Period

use of com.artezio.arttime.datamodel.Period 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 68 with Period

use of com.artezio.arttime.datamodel.Period 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 69 with Period

use of com.artezio.arttime.datamodel.Period 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)

Example 70 with Period

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

the class WorkdaysCalendarBeanTest method testGetDaysOff.

@Test
public void testGetDaysOff() throws NoSuchFieldException, ParseException {
    DateFormat df = new SimpleDateFormat("dd-MM-yyyy");
    Period extendedPeriod = new Period(df.parse("01-12-2014"), df.parse("28-02-2015"));
    WorkdaysCalendar workdaysCalendar = new WorkdaysCalendar();
    setField(calendarBean, "workdaysCalendar", workdaysCalendar);
    setField(calendarBean, "extendedPeriod", extendedPeriod);
    Day day1 = new Day(df.parse("01-01-2015"), workdaysCalendar);
    day1.setWorking(false);
    Day day2 = new Day(df.parse("02-01-2015"), workdaysCalendar);
    day2.setWorking(true);
    Map<Date, Day> days = new HashMap<Date, Day>();
    days.put(day1.getDate(), day1);
    days.put(day2.getDate(), day2);
    setField(calendarBean, "days", days);
    assertEquals("1-1-2015", calendarBean.getDaysOff());
}
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

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