Search in sources :

Example 36 with Holiday

use of org.mifos.application.holiday.business.Holiday in project head by mifos.

the class HolidayDaoHibernateIntegrationTest method shouldfindCurrentAndFutureOfficeHolidaysEarliestFirst.

@Test
public void shouldfindCurrentAndFutureOfficeHolidaysEarliestFirst() throws Exception {
    DateTime yesterday = new DateTime().minusDays(1);
    Set<HolidayBO> holidays;
    OfficeBO headOffice = IntegrationTestObjectMother.findOfficeById(Short.valueOf("1"));
    holidays = new HashSet<HolidayBO>();
    holidays.add((HolidayBO) new HolidayBuilder().withName("Fourth").from(yesterday.plusWeeks(4)).to(yesterday.plusWeeks(5)).build());
    holidays.add((HolidayBO) new HolidayBuilder().withName("Second").from(yesterday.plusDays(1)).to(yesterday.plusWeeks(7)).build());
    headOffice.setHolidays(holidays);
    IntegrationTestObjectMother.createOffice(headOffice);
    // builder not setting searchId correctly due to not going thru office.save (which uses HierarchyManager)
    String headOfficeSearchId = headOffice.getSearchId();
    OfficeBO areaOffice = new OfficeBuilder().withName("Area Office").withSearchId(headOfficeSearchId + "25.").withParentOffice(headOffice).withGlobalOfficeNum("area56").build();
    holidays = new HashSet<HolidayBO>();
    holidays.add((HolidayBO) new HolidayBuilder().withName("Fifth").from(yesterday.plusWeeks(8)).to(yesterday.plusWeeks(9)).build());
    areaOffice.setHolidays(holidays);
    IntegrationTestObjectMother.createOffice(areaOffice);
    OfficeBO myOffice = new OfficeBuilder().withName("My Office").withSearchId(headOfficeSearchId + "25.1.").withParentOffice(areaOffice).withGlobalOfficeNum("my001").build();
    holidays = new HashSet<HolidayBO>();
    holidays.add((HolidayBO) new HolidayBuilder().withName("Third").from(yesterday.plusWeeks(3)).to(yesterday.plusWeeks(4)).build());
    holidays.add((HolidayBO) new HolidayBuilder().withName("First").from(yesterday).to(yesterday.plusWeeks(2)).build());
    myOffice.setHolidays(holidays);
    IntegrationTestObjectMother.createOffice(myOffice);
    OfficeBO anotherOffice = new OfficeBuilder().withName("Another Unconnected Office").withSearchId(headOfficeSearchId + "26.").withParentOffice(headOffice).withGlobalOfficeNum("n/a001").build();
    holidays = new HashSet<HolidayBO>();
    holidays.add((HolidayBO) new HolidayBuilder().withName("N/A").from(yesterday.minusWeeks(3)).to(yesterday.plusWeeks(4)).build());
    anotherOffice.setHolidays(holidays);
    IntegrationTestObjectMother.createOffice(anotherOffice);
    List<Holiday> myHolidays = holidayDao.findCurrentAndFutureOfficeHolidaysEarliestFirst(myOffice.getOfficeId());
    assertThat(myHolidays.size(), is(5));
    assertThat(myHolidays.get(0).getName(), is("First"));
    assertThat(myHolidays.get(1).getName(), is("Second"));
    assertThat(myHolidays.get(2).getName(), is("Third"));
    assertThat(myHolidays.get(3).getName(), is("Fourth"));
    assertThat(myHolidays.get(4).getName(), is("Fifth"));
}
Also used : OfficeBuilder(org.mifos.domain.builders.OfficeBuilder) OfficeBO(org.mifos.customers.office.business.OfficeBO) Holiday(org.mifos.application.holiday.business.Holiday) HolidayBO(org.mifos.application.holiday.business.HolidayBO) HolidayBuilder(org.mifos.domain.builders.HolidayBuilder) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 37 with Holiday

use of org.mifos.application.holiday.business.Holiday in project head by mifos.

the class HolidayServiceFacadeWebTierTest method validateDisbursementDateIsNotInHolidayShouldThrowExceptionWhenDateIsInAHoliday.

@Test
public void validateDisbursementDateIsNotInHolidayShouldThrowExceptionWhenDateIsInAHoliday() throws Exception {
    DateTime disbursementDate = new DateMidnight().toDateTime().withDayOfWeek(DayOfWeek.monday());
    List<Holiday> holidays = new ArrayList<Holiday>();
    Holiday holiday = new HolidayBuilder().from(disbursementDate.minusDays(1)).to(disbursementDate.plusDays(6)).build();
    holidays.add(holiday);
    try {
        when(holidayDao.findAllHolidaysFromDateAndNext(officeId, new LocalDate(disbursementDate).toString())).thenReturn(holidays);
        holidayServiceFacade.validateDisbursementDateForNewLoan(officeId, disbursementDate);
        fail("Should have thrown BusinessRuleException");
    } catch (BusinessRuleException e) {
        assertThat(e.getMessageKey(), is(LoanExceptionConstants.DISBURSEMENTDATE_MUST_NOT_BE_IN_A_HOLIDAY));
    }
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) DateMidnight(org.joda.time.DateMidnight) Holiday(org.mifos.application.holiday.business.Holiday) ArrayList(java.util.ArrayList) HolidayBuilder(org.mifos.domain.builders.HolidayBuilder) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 38 with Holiday

use of org.mifos.application.holiday.business.Holiday in project head by mifos.

the class HolidayServiceFacadeWebTierTest method validateDisbursementDateIsWorkingDayAndNotAHolidayShouldReturnNormally.

@Test
public void validateDisbursementDateIsWorkingDayAndNotAHolidayShouldReturnNormally() throws Exception {
    DateTime disbursementDate = new DateMidnight().toDateTime().withDayOfWeek(DayOfWeek.monday());
    when(holidayDao.findAllHolidaysThisYearAndNext(officeId)).thenReturn(new ArrayList<Holiday>());
    holidayServiceFacade.validateDisbursementDateForNewLoan(officeId, disbursementDate);
}
Also used : DateMidnight(org.joda.time.DateMidnight) Holiday(org.mifos.application.holiday.business.Holiday) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 39 with Holiday

use of org.mifos.application.holiday.business.Holiday in project head by mifos.

the class HolidayAndWorkingDaysAndMoratoriaScheduledDateGenerationTest method weeklyScheduledEventSecondThirdFourthDateInThreeWeekNextMeetingHolidayShouldQuadrupleUpDatesAfterHoliday.

@Test
public void weeklyScheduledEventSecondThirdFourthDateInThreeWeekNextMeetingHolidayShouldQuadrupleUpDatesAfterHoliday() {
    Holiday threeWeekNextMeetngHolidayStartingJuly4th = new HolidayBuilder().from(mon_2011_07_04).to(mon_2011_07_04.plusWeeks(3)).withNextMeetingRule().build();
    validateDates(new ScheduleBuilder().withHolidays(threeWeekNextMeetngHolidayStartingJuly4th).withWeeklyEvent(1, wed_2011_06_29.getDayOfWeek()).withNumberOfDates(4).withStartDate(wed_2011_06_29.minusDays(1)).build(), wed_2011_06_29, wed_2011_06_29.plusWeeks(4), wed_2011_06_29.plusWeeks(4), wed_2011_06_29.plusWeeks(4));
}
Also used : Holiday(org.mifos.application.holiday.business.Holiday) HolidayBuilder(org.mifos.domain.builders.HolidayBuilder) Test(org.junit.Test)

Example 40 with Holiday

use of org.mifos.application.holiday.business.Holiday in project head by mifos.

the class HolidayAndWorkingDaysAndMoratoriaScheduledDateGenerationTest method biMonthlyByDayScheduleSecondDateInSameDayHolidayShouldNotShiftAnyDates.

@Test
public void biMonthlyByDayScheduleSecondDateInSameDayHolidayShouldNotShiftAnyDates() {
    Holiday twoWeekNextWorkingDayHoliday = new HolidayBuilder().from(date(2011, 7, 4)).to(date(2011, 7, 17)).withSameDayAsRule().build();
    validateDates(new ScheduleBuilder().withHolidays(twoWeekNextWorkingDayHoliday).withDayOfMonthEvent(2, 6).withStartDate(date(2011, 5, 6)).withNumberOfDates(3).build(), date(2011, 6, 6), date(2011, 8, 8), date(2011, 10, 6));
}
Also used : Holiday(org.mifos.application.holiday.business.Holiday) HolidayBuilder(org.mifos.domain.builders.HolidayBuilder) Test(org.junit.Test)

Aggregations

Holiday (org.mifos.application.holiday.business.Holiday)54 Test (org.junit.Test)32 HolidayBuilder (org.mifos.domain.builders.HolidayBuilder)28 DateTime (org.joda.time.DateTime)22 ArrayList (java.util.ArrayList)16 Days (org.joda.time.Days)13 FiscalCalendarRules (org.mifos.config.FiscalCalendarRules)13 LocalDate (org.joda.time.LocalDate)10 HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration (org.mifos.schedule.internal.HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration)9 ScheduledDateGeneration (org.mifos.schedule.ScheduledDateGeneration)8 Date (java.util.Date)7 DateMidnight (org.joda.time.DateMidnight)6 Ignore (org.junit.Ignore)6 HolidayDao (org.mifos.application.holiday.persistence.HolidayDao)6 InstallmentDate (org.mifos.accounts.util.helpers.InstallmentDate)4 DateTimeService (org.mifos.framework.util.DateTimeService)4 Before (org.junit.Before)3 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)3 SavingsScheduleEntity (org.mifos.accounts.savings.business.SavingsScheduleEntity)3 MeetingBO (org.mifos.application.meeting.business.MeetingBO)3