Search in sources :

Example 51 with DateMidnight

use of org.joda.time.DateMidnight in project head by mifos.

the class HolidayServiceFacadeWebTierTest method validateDisbursementDateIsWorkingDayShouldThrowException.

@Test
public void validateDisbursementDateIsWorkingDayShouldThrowException() throws Exception {
    try {
        DateTime sundayDisbursementDate = new DateMidnight().toDateTime().withDayOfWeek(DayOfWeek.sunday());
        holidayServiceFacade.validateDisbursementDateForNewLoan(officeId, sundayDisbursementDate);
        fail("Should have thrown BusinessRuleException");
    } catch (BusinessRuleException e) {
        assertThat(e.getMessageKey(), is(LoanExceptionConstants.DISBURSEMENTDATE_MUST_BE_A_WORKING_DAY));
    }
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) DateMidnight(org.joda.time.DateMidnight) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 52 with DateMidnight

use of org.joda.time.DateMidnight 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 53 with DateMidnight

use of org.joda.time.DateMidnight in project head by mifos.

the class SavingsBOTest method depositScheduleIsGeneratedOnCreationNoHoliday.

@Ignore
@Test
public void depositScheduleIsGeneratedOnCreationNoHoliday() {
    //  setup
    when(savingsAccountCustomer.getCustomerMeeting()).thenReturn(customerMeetingEntity);
    when(customerMeetingEntity.getMeeting()).thenReturn(defaultWeeklyCustomerMeeting);
    when(savingsAccountCustomer.getCustomerLevel()).thenReturn(customerLevelEntity);
    when(customerLevelEntity.getId()).thenReturn(CustomerLevel.CLIENT.getValue());
    // exercise test
    savingsAccount = savingsAccountBuilder.buildForUnitTests();
    // verify
    List<SavingsScheduleEntity> sortedSavingsSchedules = getSortedSavingsScheduleEntities();
    assertThat(sortedSavingsSchedules.size(), is(10));
    DateTime installmentDate = new DateMidnight().toDateTime();
    for (SavingsScheduleEntity savingsScheduleEntity : sortedSavingsSchedules) {
        assertThat(new LocalDate(savingsScheduleEntity.getActionDate()), is(new LocalDate(installmentDate.toDate())));
        assertThat(savingsScheduleEntity.getDeposit(), is(new Money(TestUtils.RUPEE, "13.0")));
        assertThat(savingsScheduleEntity.getDepositPaid(), is(new Money(TestUtils.RUPEE, "0.0")));
        installmentDate = installmentDate.plusWeeks(1);
    }
}
Also used : Money(org.mifos.framework.util.helpers.Money) DateMidnight(org.joda.time.DateMidnight) SavingsScheduleEntity(org.mifos.accounts.savings.business.SavingsScheduleEntity) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 54 with DateMidnight

use of org.joda.time.DateMidnight in project head by mifos.

the class HolidayFormValidator method validate.

@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = { "REC_CATCH_EXCEPTION" }, justification = "Using catch all to detect invalid dates.")
@SuppressWarnings({ "PMD.CyclomaticComplexity", "PMD.NPathComplexity" })
@Override
public void validate(Object target, Errors errors) {
    if (target instanceof OfficeHoliday) {
        return;
    }
    HolidayFormBean formBean = (HolidayFormBean) target;
    rejectIfEmptyOrWhitespace(errors, formBean.getName(), "error.holiday.mandatory_field");
    Date dateFrom = null;
    Date dateTo = null;
    try {
        dateFrom = new DateTime().withDate(Integer.parseInt(formBean.getFromYear()), formBean.getFromMonth(), formBean.getFromDay()).toDate();
    } catch (Exception e) {
        errors.reject("holiday.fromDate.invalid");
    }
    if (formBean.anyToDateFieldFilled() && !formBean.allToDateFieldsFilled()) {
        errors.reject("holiday.thruDate.invalid");
    }
    try {
        if (formBean.getToDay() != null) {
            dateTo = new DateTime().withDate(Integer.parseInt(formBean.getToYear()), formBean.getToMonth(), formBean.getToDay()).toDate();
        }
    } catch (Exception e) {
        if (!errors.hasFieldErrors("holiday.thruDate.invalid")) {
            errors.reject("holiday.thruDate.invalid");
        }
    }
    // it should exist in one place within the domain layer
    if (dateFrom != null && dateTo != null && new DateTime(dateFrom).compareTo(new DateTime(dateTo)) > 0) {
        errors.reject("holiday.fromDate.invalid2");
    }
    if (dateFrom != null && new DateMidnight(dateFrom).compareTo(new DateMidnight()) < 0) {
        errors.reject("holiday.fromDate.invalid3");
    }
    if (dateFrom != null && new DateMidnight(dateFrom).compareTo(new DateMidnight()) == 0) {
        errors.reject("holiday.fromDate.invalid4");
    }
    if (formBean.getRepaymentRuleId() == null || Integer.parseInt(formBean.getRepaymentRuleId()) < 0) {
        errors.reject("holiday.repaymentrule.required");
    }
    if (formBean.getSelectedOfficeIds().trim().isEmpty()) {
        errors.reject("holiday.appliesto.required");
    }
}
Also used : DateMidnight(org.joda.time.DateMidnight) OfficeHoliday(org.mifos.dto.domain.OfficeHoliday) Date(java.util.Date) DateTime(org.joda.time.DateTime)

Example 55 with DateMidnight

use of org.joda.time.DateMidnight in project head by mifos.

the class ClientBoTest method getDateOffset.

private DateMidnight getDateOffset(final int numberOfDays) {
    DateMidnight currentDate = new DateTimeService().getCurrentDateMidnight();
    currentDate = currentDate.minusDays(numberOfDays);
    return currentDate;
}
Also used : DateMidnight(org.joda.time.DateMidnight) DateTimeService(org.mifos.framework.util.DateTimeService)

Aggregations

DateMidnight (org.joda.time.DateMidnight)70 DateTime (org.joda.time.DateTime)33 Test (org.junit.Test)27 ArrayList (java.util.ArrayList)10 Money (org.mifos.framework.util.helpers.Money)10 Ignore (org.junit.Ignore)8 MeetingBO (org.mifos.application.meeting.business.MeetingBO)8 LocalDate (org.joda.time.LocalDate)6 SavingsScheduleEntity (org.mifos.accounts.savings.business.SavingsScheduleEntity)6 Holiday (org.mifos.application.holiday.business.Holiday)6 Date (java.util.Date)5 AccountActionDateEntity (org.mifos.accounts.business.AccountActionDateEntity)5 OfficeBO (org.mifos.customers.office.business.OfficeBO)5 HolidayBuilder (org.mifos.domain.builders.HolidayBuilder)5 AggregationInterval (org.apereo.portal.events.aggr.AggregationInterval)4 AccountFeesEntity (org.mifos.accounts.business.AccountFeesEntity)4 UserContext (org.mifos.security.util.UserContext)4 DateTimeZone (org.joda.time.DateTimeZone)3 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)3 Before (org.junit.Before)3