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));
}
}
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);
}
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);
}
}
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");
}
}
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;
}
Aggregations