Search in sources :

Example 16 with DateMidnight

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

the class LegacyAccountDaoIntegrationTest method testGetListOfAccountIdsHavingLoanSchedulesWithinAHoliday.

@Test
public void testGetListOfAccountIdsHavingLoanSchedulesWithinAHoliday() throws Exception {
    Set<HolidayBO> holidays;
    DateTime fromDate = new DateMidnight().toDateTime().plusDays(1);
    DateTime thruDate = new DateMidnight().toDateTime().plusDays(30);
    GenericDao genericDao = new GenericDaoHibernate();
    OfficeDao officeDao = new OfficeDaoHibernate(genericDao);
    HolidayDao holidayDao = new HolidayDaoHibernate(genericDao);
    OfficeBO sampleBranch = officeDao.findOfficeById(this.getBranchOffice().getOfficeId());
    holidays = new HashSet<HolidayBO>();
    holiday = new HolidayBuilder().withName("Welcome Holiday").from(fromDate).to(thruDate).build();
    holidayDao.save(holiday);
    holidays.add((HolidayBO) holiday);
    sampleBranch.setHolidays(holidays);
    new OfficePersistence().createOrUpdate(sampleBranch);
    StaticHibernateUtil.flushSession();
    List<Object[]> AccountIds = legacyAccountDao.getListOfAccountIdsHavingLoanSchedulesWithinAHoliday(holiday);
    Assert.assertNotNull(AccountIds);
    assertThat(AccountIds.size(), is(2));
}
Also used : GenericDaoHibernate(org.mifos.accounts.savings.persistence.GenericDaoHibernate) GenericDao(org.mifos.accounts.savings.persistence.GenericDao) DateTime(org.joda.time.DateTime) HolidayDao(org.mifos.application.holiday.persistence.HolidayDao) HolidayDaoHibernate(org.mifos.application.holiday.persistence.HolidayDaoHibernate) DateMidnight(org.joda.time.DateMidnight) OfficeBO(org.mifos.customers.office.business.OfficeBO) OfficeDao(org.mifos.customers.office.persistence.OfficeDao) HolidayBO(org.mifos.application.holiday.business.HolidayBO) OfficeDaoHibernate(org.mifos.customers.office.persistence.OfficeDaoHibernate) HolidayBuilder(org.mifos.domain.builders.HolidayBuilder) OfficePersistence(org.mifos.customers.office.persistence.OfficePersistence) Test(org.junit.Test)

Example 17 with DateMidnight

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

the class LegacyAccountDaoIntegrationTest method testGetListOfAccountIdsHavingCustomerSchedulesWithinAHoliday.

@Test
public void testGetListOfAccountIdsHavingCustomerSchedulesWithinAHoliday() throws Exception {
    Set<HolidayBO> holidays;
    DateTime fromDate = new DateMidnight().toDateTime().plusDays(1);
    DateTime thruDate = new DateMidnight().toDateTime().plusDays(30);
    GenericDao genericDao = new GenericDaoHibernate();
    OfficeDao officeDao = new OfficeDaoHibernate(genericDao);
    HolidayDao holidayDao = new HolidayDaoHibernate(genericDao);
    OfficeBO sampleBranch = officeDao.findOfficeById(this.getBranchOffice().getOfficeId());
    holidays = new HashSet<HolidayBO>();
    holiday = new HolidayBuilder().withName("Welcome Holiday").from(fromDate).to(thruDate).build();
    holidayDao.save(holiday);
    holidays.add((HolidayBO) holiday);
    sampleBranch.setHolidays(holidays);
    new OfficePersistence().createOrUpdate(sampleBranch);
    StaticHibernateUtil.flushSession();
    List<Object[]> AccountIds = legacyAccountDao.getListOfAccountIdsHavingCustomerSchedulesWithinAHoliday(holiday);
    Assert.assertNotNull(AccountIds);
    assertThat(AccountIds.size(), is(3));
}
Also used : GenericDaoHibernate(org.mifos.accounts.savings.persistence.GenericDaoHibernate) GenericDao(org.mifos.accounts.savings.persistence.GenericDao) DateTime(org.joda.time.DateTime) HolidayDao(org.mifos.application.holiday.persistence.HolidayDao) HolidayDaoHibernate(org.mifos.application.holiday.persistence.HolidayDaoHibernate) DateMidnight(org.joda.time.DateMidnight) OfficeBO(org.mifos.customers.office.business.OfficeBO) OfficeDao(org.mifos.customers.office.persistence.OfficeDao) HolidayBO(org.mifos.application.holiday.business.HolidayBO) OfficeDaoHibernate(org.mifos.customers.office.persistence.OfficeDaoHibernate) HolidayBuilder(org.mifos.domain.builders.HolidayBuilder) OfficePersistence(org.mifos.customers.office.persistence.OfficePersistence) Test(org.junit.Test)

Example 18 with DateMidnight

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

the class GroupTransferServiceIntegrationTest method transferingGroupToCenterWithDifferentMeetingDayOfWeekCausesFutureSchedulesToBeRegeneratedForGroupsChildren.

@Ignore
@Test
public void transferingGroupToCenterWithDifferentMeetingDayOfWeekCausesFutureSchedulesToBeRegeneratedForGroupsChildren() throws Exception {
    // setup
    OfficeBO branchOffice = anExistingBranchOffice(new OfficeBuilder().withGlobalOfficeNum("xxxx-003").withName("builder-branch-office1").withShortName("bf1").withSearchId("1.1.1.1."));
    OfficeBO branchOffice2 = new OfficeBuilder().withParentOffice(branchOffice.getParentOffice()).branchOffice().withGlobalOfficeNum("xxxx-004").withName("builder-branch-office2").withShortName("bf1").withSearchId("1.1.1.2.").build();
    IntegrationTestObjectMother.createOffice(branchOffice2);
    DateTime todaySixWeeksAgo = new DateMidnight().toDateTime().minusWeeks(6);
    MeetingBO weeklyMeeting = aWeeklyMeeting().withLocation("weeklyMeeting-sixWeeksAgo").startingFrom(todaySixWeeksAgo.toDate()).build();
    IntegrationTestObjectMother.saveMeeting(weeklyMeeting);
    CenterBuilder centerWithWeeklyMeeting = anActiveCenter().withName("center-with-no-children").with(weeklyMeeting).with(branchOffice).withActivationDate(todaySixWeeksAgo).withLoanOfficer(anExistingLoanOfficer());
    CenterBO centerWithNoChildren = anExistingActiveCenter(centerWithWeeklyMeeting);
    DateTime tomorrowTwoWeeksAgo = new DateMidnight().toDateTime().minusWeeks(2).plusDays(1);
    MeetingBO differentWeeklyMeeting = aWeeklyMeeting().withLocation("weeklyMeeting-tomorrow-twoWeeksAgo").withStartDate(tomorrowTwoWeeksAgo.minusWeeks(1)).build();
    IntegrationTestObjectMother.saveMeeting(differentWeeklyMeeting);
    CenterBuilder centerInDifferentBranchWithDifferentMeeting = centerWithWeeklyMeeting.withName("center-with-group").with(branchOffice2).with(differentWeeklyMeeting).withActivationDate(tomorrowTwoWeeksAgo);
    GroupBO groupForTransfer = anExistingGroupUnderCenterInDifferentBranchAs(centerInDifferentBranchWithDifferentMeeting);
    ClientBO child1 = new ClientBuilder().active().withName("client1").withParentCustomer(groupForTransfer).buildForIntegrationTests();
    IntegrationTestObjectMother.createClient(child1, child1.getCustomerMeetingValue());
    // pre-verification
    ClientBO client = customerDao.findClientBySystemId(child1.getGlobalCustNum());
    TestUtils.assertThatAllCustomerSchedulesOccuringAfterCurrentInstallmentPeriodFallOnDayOfWeek(client, WeekDay.getJodaWeekDay(tomorrowTwoWeeksAgo.getDayOfWeek()));
    // exercise test
    groupForTransfer = customerDao.findGroupBySystemId(groupForTransfer.getGlobalCustNum());
    groupForTransfer.setUserContext(TestUtils.makeUser());
    customerService.transferGroupTo(groupForTransfer, centerWithNoChildren);
    // verification
    client = customerDao.findClientBySystemId(child1.getGlobalCustNum());
    TestUtils.assertThatAllCustomerSchedulesOccuringBeforeOrOnCurrentInstallmentPeriodRemainUnchanged(client, WeekDay.getJodaWeekDay(tomorrowTwoWeeksAgo.getDayOfWeek()));
// TO-FIX TestUtils.assertThatAllCustomerSchedulesOccuringAfterCurrentInstallmentPeriodFallOnDayOfWeek(client, WeekDay.getJodaWeekDay(todaySixWeeksAgo.getDayOfWeek()));
}
Also used : OfficeBuilder(org.mifos.domain.builders.OfficeBuilder) OfficeBO(org.mifos.customers.office.business.OfficeBO) DateMidnight(org.joda.time.DateMidnight) MeetingBO(org.mifos.application.meeting.business.MeetingBO) ClientBO(org.mifos.customers.client.business.ClientBO) CenterBuilder(org.mifos.domain.builders.CenterBuilder) CenterBO(org.mifos.customers.center.business.CenterBO) GroupBO(org.mifos.customers.group.business.GroupBO) DateTime(org.joda.time.DateTime) ClientBuilder(org.mifos.domain.builders.ClientBuilder) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 19 with DateMidnight

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

the class ClientBoTest method testHandleAttendanceForDifferentDates.

@Test
public void testHandleAttendanceForDifferentDates() throws Exception {
    DateTime meetingDate = new DateTimeService().getCurrentDateTime();
    client.handleAttendance(meetingDate.toDate(), AttendanceType.PRESENT.getValue(), false);
    Assert.assertEquals("The size of customer attendance is : ", client.getClientAttendances().size(), 1);
    Assert.assertEquals("The value of customer attendance for the meeting : ", AttendanceType.PRESENT, client.getClientAttendanceForMeeting(meetingDate.toDate()).getAttendanceAsEnum());
    DateMidnight offSetDate = getDateOffset(1);
    client.handleAttendance(new java.sql.Date(offSetDate.getMillis()), AttendanceType.ABSENT.getValue(), false);
    Assert.assertEquals("The size of customer attendance is : ", client.getClientAttendances().size(), 2);
    Assert.assertEquals("The value of customer attendance for the meeting : ", AttendanceType.PRESENT, client.getClientAttendanceForMeeting(meetingDate.toDate()).getAttendanceAsEnum());
    Assert.assertEquals("The value of customer attendance for the meeting : ", AttendanceType.ABSENT, client.getClientAttendanceForMeeting(offSetDate.toDate()).getAttendanceAsEnum());
}
Also used : DateMidnight(org.joda.time.DateMidnight) DateTimeService(org.mifos.framework.util.DateTimeService) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 20 with DateMidnight

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

the class TestUtils method assertThatAllCustomerSchedulesOccuringBeforeOrOnCurrentInstallmentPeriodRemainUnchanged.

public static void assertThatAllCustomerSchedulesOccuringBeforeOrOnCurrentInstallmentPeriodRemainUnchanged(CustomerBO customer, WeekDay expectedDayOfWeek) {
    Set<AccountActionDateEntity> customerSchedules = customer.getCustomerAccount().getAccountActionDates();
    for (AccountActionDateEntity accountActionDateEntity : customerSchedules) {
        CustomerScheduleEntity customerSchedule = (CustomerScheduleEntity) accountActionDateEntity;
        LocalDate scheduledDate = new LocalDate(customerSchedule.getActionDate());
        DateTime endOfCurrentInstallmentPeriod = TestUtils.nearestDateMatchingPeriodStartingOn(new DateMidnight().toDateTime(), customer.getCustomerMeetingValue());
        LocalDate endOfCurrentInstallmentPeriodLocalDate = new LocalDate(endOfCurrentInstallmentPeriod);
        if (scheduledDate.isBefore(endOfCurrentInstallmentPeriodLocalDate)) {
            assertThat(scheduledDate.dayOfWeek().get(), is(WeekDay.getJodaDayOfWeekThatMatchesMifosWeekDay(expectedDayOfWeek.getValue())));
        }
    }
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) CustomerScheduleEntity(org.mifos.customers.business.CustomerScheduleEntity) DateMidnight(org.joda.time.DateMidnight) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime)

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