Search in sources :

Example 6 with HolidayBuilder

use of org.mifos.domain.builders.HolidayBuilder in project head by mifos.

the class HolidayDaoHibernateIntegrationTest method shouldThrowExceptionWhenFutureHolidaysApplicableToNewParentOfficeDifferFromPreviousParentOffice.

@Test
public void shouldThrowExceptionWhenFutureHolidaysApplicableToNewParentOfficeDifferFromPreviousParentOffice() throws Exception {
    OfficeBO headOffice = IntegrationTestObjectMother.findOfficeById(Short.valueOf("1"));
    // setup
    createOfficeHierarchyUnderHeadOffice(headOffice);
    DateTime tomorrow = new DateTime().plusDays(1);
    HolidayDetails holidayDetails = new HolidayBuilder().withName("areaOffice2Holiday").from(tomorrow).to(tomorrow).buildDto();
    IntegrationTestObjectMother.createHoliday(holidayDetails, Arrays.asList(areaOffice2.getOfficeId()));
    HolidayDetails branchOnlyHolidayDetails = new HolidayBuilder().withName("branchOnlyHoliday").from(tomorrow).to(tomorrow).buildDto();
    IntegrationTestObjectMother.createHoliday(branchOnlyHolidayDetails, Arrays.asList(branch1.getOfficeId()));
    // refetch
    branch1 = IntegrationTestObjectMother.findOfficeById(branch1.getOfficeId());
    // exercise test
    try {
        holidayDao.validateNoExtraFutureHolidaysApplicableOnParentOffice(branch1.getParentOffice().getOfficeId(), areaOffice2.getOfficeId());
        fail("shouldThrowExceptionWhenFutureHolidaysApplicableToNewParentOfficeDifferFromPreviousParentOffice");
    } catch (ApplicationException e) {
        assertThat(e.getKey(), is(OfficeConstants.ERROR_REPARENT_NOT_ALLOWED_AS_FUTURE_APPLICABLE_HOLIDAYS_ARE_DIFFERENT_ON_PREVIOUS_AND_NEW_PARENT));
    }
}
Also used : ApplicationException(org.mifos.framework.exceptions.ApplicationException) OfficeBO(org.mifos.customers.office.business.OfficeBO) HolidayDetails(org.mifos.dto.domain.HolidayDetails) HolidayBuilder(org.mifos.domain.builders.HolidayBuilder) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 7 with HolidayBuilder

use of org.mifos.domain.builders.HolidayBuilder in project head by mifos.

the class HolidayDaoHibernateIntegrationTest method shouldSaveFutureHoliday.

@Test
public void shouldSaveFutureHoliday() throws Exception {
    List<Holiday> holidays = holidayDao.findAllHolidaysThisYearAndNext((short) 1);
    int initialCount = holidays.size();
    OfficeBO headOffice = IntegrationTestObjectMother.findOfficeById(Short.valueOf("1"));
    Holiday futureHoliday = new HolidayBuilder().from(new DateTime()).to(new DateTime().plusDays(1)).appliesTo(headOffice).build();
    StaticHibernateUtil.startTransaction();
    holidayDao.save(futureHoliday);
    StaticHibernateUtil.flushSession();
    holidays = holidayDao.findAllHolidaysThisYearAndNext(headOffice.getOfficeId());
    assertFalse(holidays.isEmpty());
    assertThat(holidays.size() - initialCount, is(1));
}
Also used : Holiday(org.mifos.application.holiday.business.Holiday) OfficeBO(org.mifos.customers.office.business.OfficeBO) HolidayBuilder(org.mifos.domain.builders.HolidayBuilder) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 8 with HolidayBuilder

use of org.mifos.domain.builders.HolidayBuilder in project head by mifos.

the class HolidayDaoHibernateIntegrationTest method shouldFindWhetherGivenDateIsAHoliday.

@Ignore
@Test
public void shouldFindWhetherGivenDateIsAHoliday() {
    Short officeId = Short.valueOf("1");
    DateTime secondlastDayOfYear = new DateTime().withMonthOfYear(12).withDayOfMonth(30).toDateMidnight().toDateTime();
    insertHoliday(new HolidayBuilder().from(secondlastDayOfYear).to(secondlastDayOfYear).build());
    assertThat(holidayDao.isHoliday(officeId, secondlastDayOfYear.toLocalDate().toString()), is(true));
    DateTime thirdOfJanNextYear = new DateTime().plusYears(1).withMonthOfYear(1).withDayOfMonth(3).toDateMidnight().toDateTime();
    DateTime sixthOfJanNextYear = new DateTime().plusYears(1).withMonthOfYear(1).withDayOfMonth(6).toDateMidnight().toDateTime();
    DateTime tenthOfJanNextYear = new DateTime().plusYears(1).withMonthOfYear(1).withDayOfMonth(10).toDateMidnight().toDateTime();
    DateTime eleventhOfJanNextYear = new DateTime().plusYears(1).withMonthOfYear(1).withDayOfMonth(11).toDateMidnight().toDateTime();
    insertHoliday(new HolidayBuilder().from(thirdOfJanNextYear).to(tenthOfJanNextYear).build());
    assertThat(holidayDao.isHoliday(officeId, thirdOfJanNextYear.toLocalDate().toString()), is(true));
    assertThat(holidayDao.isHoliday(officeId, sixthOfJanNextYear.toLocalDate().toString()), is(true));
    assertThat(holidayDao.isHoliday(officeId, tenthOfJanNextYear.toLocalDate().toString()), is(true));
    assertThat(holidayDao.isHoliday(officeId, eleventhOfJanNextYear.toLocalDate().toString()), is(false));
}
Also used : HolidayBuilder(org.mifos.domain.builders.HolidayBuilder) DateTime(org.joda.time.DateTime) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 9 with HolidayBuilder

use of org.mifos.domain.builders.HolidayBuilder in project head by mifos.

the class HolidayDaoHibernateIntegrationTest method shouldFindAllHolidaysOrderedByFromDateAscending.

@Ignore
@Test
public void shouldFindAllHolidaysOrderedByFromDateAscending() throws Exception {
    DateTime secondlastDayOfYear = new DateTime().withMonthOfYear(12).withDayOfMonth(30).toDateMidnight().toDateTime();
    DateTime lastDayOfYear = secondlastDayOfYear.plusDays(1);
    DateTime secondOfJanNextYear = new DateTime().plusYears(1).withMonthOfYear(1).withDayOfMonth(2).toDateMidnight().toDateTime();
    DateTime thirdOfJanNextYear = new DateTime().plusYears(1).withMonthOfYear(1).withDayOfMonth(3).toDateMidnight().toDateTime();
    List<Holiday> holidays = holidayDao.findAllHolidaysThisYearAndNext(new Short("1"));
    int initialCountOfHolidays = holidays.size();
    List<Holiday> futureHolidays = holidayDao.findAllHolidaysFromDateAndNext(new Short("1"), secondOfJanNextYear.toLocalDate().toString());
    int initialCountOfFutureHolidays = futureHolidays.size();
    Holiday holiday1 = new HolidayBuilder().from(secondlastDayOfYear).to(secondlastDayOfYear).build();
    Holiday holiday2 = new HolidayBuilder().from(secondOfJanNextYear).to(secondOfJanNextYear).build();
    Holiday holiday3 = new HolidayBuilder().from(thirdOfJanNextYear).to(thirdOfJanNextYear).build();
    Holiday holiday4 = new HolidayBuilder().from(lastDayOfYear).to(lastDayOfYear).build();
    insertHoliday(holiday2);
    insertHoliday(holiday3);
    insertHoliday(holiday1);
    insertHoliday(holiday4);
    holidays = holidayDao.findAllHolidaysThisYearAndNext(new Short("1"));
    assertThat(holidays.size() - initialCountOfHolidays, is(4));
    assertTrue(holidays.get(0).encloses(secondlastDayOfYear.toDate()));
    assertTrue(holidays.get(1).encloses(lastDayOfYear.toDate()));
    assertTrue(holidays.get(2).encloses(secondOfJanNextYear.toDate()));
    assertTrue(holidays.get(3).encloses(thirdOfJanNextYear.toDate()));
    futureHolidays = holidayDao.findAllHolidaysFromDateAndNext(new Short("1"), secondOfJanNextYear.toLocalDate().toString());
    assertThat(futureHolidays.size() - initialCountOfFutureHolidays, is(2));
    assertTrue(futureHolidays.get(0).encloses(secondOfJanNextYear.toDate()));
    assertTrue(futureHolidays.get(1).encloses(thirdOfJanNextYear.toDate()));
}
Also used : Holiday(org.mifos.application.holiday.business.Holiday) HolidayBuilder(org.mifos.domain.builders.HolidayBuilder) DateTime(org.joda.time.DateTime) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 10 with HolidayBuilder

use of org.mifos.domain.builders.HolidayBuilder in project head by mifos.

the class ApplyHolidayChangesHelperIntegrationTest method createOfficeHolidayTestData.

private void createOfficeHolidayTestData(DateTime startDate) throws Exception {
    /*
         * When startDate is 'yesterday' Head Office Holiday: from 2010-02-22 thru 2010-03-01 ... repayment rule is next
         * meeting date Branch Holiday:
         *
         * from 2010-03-08 thru 2010-03-22 ... moratorium
         *
         * One more holiday that should not affect any schedules
         */
    // Creating Office Holidays
    Set<HolidayBO> holidays;
    OfficeBO headOffice = IntegrationTestObjectMother.findOfficeById(Short.valueOf("1"));
    holidays = new HashSet<HolidayBO>();
    holidays.add((HolidayBO) new HolidayBuilder().withName("HO Holiday").from(startDate).to(startDate.plusWeeks(1)).withRepaymentRule(RepaymentRuleTypes.NEXT_MEETING_OR_REPAYMENT).build());
    headOffice.setHolidays(holidays);
    IntegrationTestObjectMother.createOffice(headOffice);
    OfficeBO centerOffice = testSaveCollectionSheetUtils.getCenter().getOffice();
    holidays = new HashSet<HolidayBO>();
    holidays.add((HolidayBO) new HolidayBuilder().withName("Center Hierarchy Holiday").from(startDate.plusWeeks(2)).to(startDate.plusWeeks(4)).withRepaymentMoratoriumRule().build());
    centerOffice.setHolidays(holidays);
    IntegrationTestObjectMother.createOffice(centerOffice);
    // builder not setting searchId correctly due to not going thru office.save (which uses HierarchyManager)
    String headOfficeSearchId = headOffice.getSearchId();
    OfficeBO anotherOffice = new OfficeBuilder().withParentOffice(headOffice).withName("Another Office").withSearchId(headOfficeSearchId + "26.").withGlobalOfficeNum("n/a001").build();
    holidays = new HashSet<HolidayBO>();
    holidays.add((HolidayBO) new HolidayBuilder().withName("N/A").from(startDate.minusWeeks(3)).to(startDate.plusWeeks(8)).withRepaymentMoratoriumRule().build());
    anotherOffice.setHolidays(holidays);
    IntegrationTestObjectMother.createOffice(anotherOffice);
}
Also used : OfficeBuilder(org.mifos.domain.builders.OfficeBuilder) OfficeBO(org.mifos.customers.office.business.OfficeBO) HolidayBO(org.mifos.application.holiday.business.HolidayBO) HolidayBuilder(org.mifos.domain.builders.HolidayBuilder)

Aggregations

HolidayBuilder (org.mifos.domain.builders.HolidayBuilder)35 Test (org.junit.Test)34 Holiday (org.mifos.application.holiday.business.Holiday)28 DateTime (org.joda.time.DateTime)16 Ignore (org.junit.Ignore)7 OfficeBO (org.mifos.customers.office.business.OfficeBO)7 DateMidnight (org.joda.time.DateMidnight)6 HolidayBO (org.mifos.application.holiday.business.HolidayBO)4 ArrayList (java.util.ArrayList)3 SavingsScheduleEntity (org.mifos.accounts.savings.business.SavingsScheduleEntity)3 Money (org.mifos.framework.util.helpers.Money)3 LocalDate (org.joda.time.LocalDate)2 GenericDao (org.mifos.accounts.savings.persistence.GenericDao)2 GenericDaoHibernate (org.mifos.accounts.savings.persistence.GenericDaoHibernate)2 HolidayDao (org.mifos.application.holiday.persistence.HolidayDao)2 HolidayDaoHibernate (org.mifos.application.holiday.persistence.HolidayDaoHibernate)2 OfficeDao (org.mifos.customers.office.persistence.OfficeDao)2 OfficeDaoHibernate (org.mifos.customers.office.persistence.OfficeDaoHibernate)2 OfficePersistence (org.mifos.customers.office.persistence.OfficePersistence)2 OfficeBuilder (org.mifos.domain.builders.OfficeBuilder)2