Search in sources :

Example 21 with DateTimeService

use of org.mifos.framework.util.DateTimeService in project head by mifos.

the class LoanAdjustmentsIntegrationTest method testWhenARepaymentIsAdjustedItGoesBackToBadStandingIfNecessary.

@Test
public void testWhenARepaymentIsAdjustedItGoesBackToBadStandingIfNecessary() throws Exception {
    // relates to mifos-3479
    new DateTimeService().setCurrentDateTimeFixed(date(2010, 10, 13));
    loan = createLoan();
    loan.updateDetails(TestUtils.makeUserWithLocales());
    // pay 2 installments
    makePayment(loan, "222.0");
    loan.updateDetails(TestUtils.makeUserWithLocales());
    // pay 1 more installment
    makePayment(loan, "111.0");
    loan.updateDetails(TestUtils.makeUserWithLocales());
    // Ensure that after the adjustment the loan is calculated to be in bad standing.
    new DateTimeService().setCurrentDateTimeFixed(date(2010, 11, 13));
    adjustLastLoanPayment(loan);
    loan.updateDetails(TestUtils.makeUserWithLocales());
    assertNotNull("Account Status Change History Should Not Be Null", loan.getAccountStatusChangeHistory());
    Integer listSize = loan.getAccountStatusChangeHistory().size();
    assertFalse(listSize == 0);
    // check if the last entry has an oldstatus LOAN_ACTIVE_IN_GOOD_STANDING and a new status of
    // LOAN_ACTIVE_IN_BAD_STANDING
    AccountStateEntity oldStatus = loan.getAccountStatusChangeHistory().get(listSize - 1).getOldStatus();
    AccountStateEntity newStatus = loan.getAccountStatusChangeHistory().get(listSize - 1).getNewStatus();
    assertTrue("Old Status Should Have Been LOAN_ACTIVE_IN_GOOD_STANDING", oldStatus.isInState(AccountState.LOAN_ACTIVE_IN_GOOD_STANDING));
    assertTrue("New Status Should Have Been LOAN_ACTIVE_IN_BAD_STANDING", newStatus.isInState(AccountState.LOAN_ACTIVE_IN_BAD_STANDING));
}
Also used : AccountStateEntity(org.mifos.accounts.business.AccountStateEntity) DateTimeService(org.mifos.framework.util.DateTimeService) Test(org.junit.Test)

Example 22 with DateTimeService

use of org.mifos.framework.util.DateTimeService in project head by mifos.

the class LoanAdjustmentsIntegrationTest method makeEarlyPayment.

private void makeEarlyPayment(LoanBO loan) throws AccountException {
    loan.makeEarlyRepayment(new AccountPaymentDto(loan.getEarlyRepayAmount().getAmount().doubleValue(), new DateTimeService().getCurrentJavaDateTime(), "", null, (short) 1), testUser().getPersonnelId(), false, new Money(loan.getCurrency(), "0"));
    StaticHibernateUtil.flushSession();
}
Also used : Money(org.mifos.framework.util.helpers.Money) AccountPaymentDto(org.mifos.dto.domain.AccountPaymentDto) DateTimeService(org.mifos.framework.util.DateTimeService)

Example 23 with DateTimeService

use of org.mifos.framework.util.DateTimeService in project head by mifos.

the class LoanAdjustmentsIntegrationTest method testWhenALoanIsRepaidEarlyAndThenAdjustedThatTheLoanSummaryAndSchedulesDetailsAreTheSameBeforeAndAfter.

/**
     * not sure why this is failing now.
     */
@Ignore
@Test
public void testWhenALoanIsRepaidEarlyAndThenAdjustedThatTheLoanSummaryAndSchedulesDetailsAreTheSameBeforeAndAfter() throws Exception {
    // relates to mifos-1986
    new DateTimeService().setCurrentDateTimeFixed(date(2010, 10, 13));
    loan = createLoan();
    Money initialOriginalPrincipal = loan.getLoanSummary().getOriginalPrincipal();
    Money initialOriginalInterest = loan.getLoanSummary().getOriginalInterest();
    Money initialOriginalFees = loan.getLoanSummary().getOriginalFees();
    Money initialPrincipalPaid = loan.getLoanSummary().getPrincipalPaid();
    Money initialInterestPaid = loan.getLoanSummary().getInterestPaid();
    Money initialFeesPaid = loan.getLoanSummary().getFeesPaid();
    // pay 3 installments
    makePayment(loan, "333.0");
    StaticHibernateUtil.flushAndClearSession();
    loan = (LoanBO) legacyAccountDao.getAccount(loan.getAccountId());
    loan.updateDetails(TestUtils.makeUserWithLocales());
    assertThat(loan.getLoanSummary().getOriginalPrincipal(), is(initialOriginalPrincipal));
    assertThat(loan.getLoanSummary().getOriginalInterest(), is(initialOriginalInterest));
    assertThat(loan.getLoanSummary().getOriginalFees(), is(initialOriginalFees));
    assertFalse(loan.getLoanSummary().getPrincipalPaid().equals(initialPrincipalPaid));
    assertFalse(loan.getLoanSummary().getInterestPaid().equals(initialInterestPaid));
    assertFalse(loan.getLoanSummary().getFeesPaid().equals(initialFeesPaid));
    List<LoanInstallment> copySchedule = copyLoanSchedule(loan);
    makeEarlyPayment(loan);
    StaticHibernateUtil.flushAndClearSession();
    loan = (LoanBO) legacyAccountDao.getAccount(loan.getAccountId());
    loan.updateDetails(TestUtils.makeUserWithLocales());
    // The early repayment should have caused the original interest and fees to be changed to equal the amounts
    // paid.
    assertThat(loan.getLoanSummary().getOriginalPrincipal(), is(initialOriginalPrincipal));
    assertFalse(loan.getLoanSummary().getOriginalInterest().equals(initialOriginalInterest));
    assertFalse(loan.getLoanSummary().getOriginalFees().equals(initialOriginalFees));
    assertThat(loan.getLoanSummary().getPrincipalPaid(), is(loan.getLoanSummary().getOriginalPrincipal()));
    assertThat(loan.getLoanSummary().getInterestPaid(), is(loan.getLoanSummary().getOriginalInterest()));
    assertThat(loan.getLoanSummary().getFeesPaid(), is(loan.getLoanSummary().getOriginalFees()));
    assertFalse(sameSchedule(copySchedule, loan.getAccountActionDates()));
    adjustLastLoanPayment(loan);
    StaticHibernateUtil.flushAndClearSession();
    loan = (LoanBO) legacyAccountDao.getAccount(loan.getAccountId());
    loan.updateDetails(TestUtils.makeUserWithLocales());
    // The adjustment of a completed loan should have caused the original amounts to be reset
    assertThat(loan.getLoanSummary().getOriginalPrincipal(), is(initialOriginalPrincipal));
    assertThat(loan.getLoanSummary().getOriginalInterest(), is(initialOriginalInterest));
    assertThat(loan.getLoanSummary().getOriginalFees(), is(initialOriginalFees));
    assertTrue(sameSchedule(copySchedule, loan.getAccountActionDates()));
}
Also used : Money(org.mifos.framework.util.helpers.Money) DateTimeService(org.mifos.framework.util.DateTimeService) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 24 with DateTimeService

use of org.mifos.framework.util.DateTimeService in project head by mifos.

the class ClientLoanDisbursalTest method logOut.

@AfterMethod(alwaysRun = true)
public void logOut() {
    new DateTimeService().resetToCurrentSystemDateTime();
    (new MifosPage(selenium)).logout();
}
Also used : DateTimeService(org.mifos.framework.util.DateTimeService) MifosPage(org.mifos.test.acceptance.framework.MifosPage) AfterMethod(org.testng.annotations.AfterMethod)

Example 25 with DateTimeService

use of org.mifos.framework.util.DateTimeService in project head by mifos.

the class CollectionSheetServiceImplIntegrationTest method initializeToFixedDateTime.

private DateTime initializeToFixedDateTime(Date date) {
    LocalDate localDate = DateUtils.getLocalDateFromDate(date).plusDays(3);
    DateTime dateTime = new DateTime(localDate.getYear(), localDate.getMonthOfYear(), localDate.getDayOfMonth(), 0, 0, 0, 0);
    DateTimeService dateTimeService = new DateTimeService();
    dateTimeService.setCurrentDateTimeFixed(dateTime);
    return dateTime;
}
Also used : LocalDate(org.joda.time.LocalDate) DateTimeService(org.mifos.framework.util.DateTimeService) DateTime(org.joda.time.DateTime)

Aggregations

DateTimeService (org.mifos.framework.util.DateTimeService)99 Test (org.junit.Test)24 Date (java.util.Date)21 Money (org.mifos.framework.util.helpers.Money)20 DateTime (org.joda.time.DateTime)19 PersistenceException (org.mifos.framework.exceptions.PersistenceException)19 MeetingBO (org.mifos.application.meeting.business.MeetingBO)16 MifosRuntimeException (org.mifos.core.MifosRuntimeException)16 LocalDate (org.joda.time.LocalDate)15 AccountException (org.mifos.accounts.exceptions.AccountException)14 LoanBO (org.mifos.accounts.loan.business.LoanBO)14 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)14 ArrayList (java.util.ArrayList)13 CustomerBO (org.mifos.customers.business.CustomerBO)10 CustomerException (org.mifos.customers.exceptions.CustomerException)10 UserContext (org.mifos.security.util.UserContext)10 BusinessRuleException (org.mifos.service.BusinessRuleException)9 AccountPaymentEntity (org.mifos.accounts.business.AccountPaymentEntity)8 MeetingException (org.mifos.application.meeting.exceptions.MeetingException)8 ApplicationException (org.mifos.framework.exceptions.ApplicationException)8