Search in sources :

Example 6 with OriginalScheduleInfoDto

use of org.mifos.accounts.loan.business.service.OriginalScheduleInfoDto in project head by mifos.

the class LoanServiceFacadeWebTierTest method retrieveOriginalLoanSchedule.

@Test
public void retrieveOriginalLoanSchedule() throws PersistenceException {
    Integer accountId = new Integer(1);
    List<OriginalLoanScheduleEntity> loanScheduleEntities = new ArrayList<OriginalLoanScheduleEntity>();
    OriginalLoanScheduleEntity originalLoanScheduleEntity1 = mock(OriginalLoanScheduleEntity.class);
    OriginalLoanScheduleEntity originalLoanScheduleEntity2 = mock(OriginalLoanScheduleEntity.class);
    loanScheduleEntities.add(originalLoanScheduleEntity1);
    loanScheduleEntities.add(originalLoanScheduleEntity2);
    RepaymentScheduleInstallment installment1 = new RepaymentScheduleInstallment();
    RepaymentScheduleInstallment installment2 = new RepaymentScheduleInstallment();
    when(originalLoanScheduleEntity1.toDto()).thenReturn(installment1);
    when(originalLoanScheduleEntity2.toDto()).thenReturn(installment2);
    List<RepaymentScheduleInstallment> expected = new ArrayList<RepaymentScheduleInstallment>();
    expected.add(installment1);
    expected.add(installment2);
    Date date = new Date();
    when(loanBO.getDisbursementDate()).thenReturn(date);
    Money money = new Money(rupee, "4.9");
    when(loanBO.getLoanAmount()).thenReturn(money);
    when(loanBusinessService.retrieveOriginalLoanSchedule(accountId)).thenReturn(loanScheduleEntities);
    when(loanDao.findById(accountId)).thenReturn(loanBO);
    OriginalScheduleInfoDto expectedOriginalScheduleInfoDto = new OriginalScheduleInfoDto(money.toString(), date, expected);
    OriginalScheduleInfoDto originalScheduleInfoDto = loanServiceFacade.retrieveOriginalLoanSchedule(accountId);
    assertThat(originalScheduleInfoDto, is(new OriginalScheduleInfoDtoMatcher(expectedOriginalScheduleInfoDto)));
}
Also used : Money(org.mifos.framework.util.helpers.Money) RepaymentScheduleInstallment(org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment) OriginalScheduleInfoDtoMatcher(org.mifos.accounts.loan.business.matchers.OriginalScheduleInfoDtoMatcher) OriginalScheduleInfoDto(org.mifos.accounts.loan.business.service.OriginalScheduleInfoDto) OriginalLoanScheduleEntity(org.mifos.accounts.loan.business.OriginalLoanScheduleEntity) ArrayList(java.util.ArrayList) Date(java.util.Date) Test(org.junit.Test)

Example 7 with OriginalScheduleInfoDto

use of org.mifos.accounts.loan.business.service.OriginalScheduleInfoDto in project head by mifos.

the class LoanAccountActionTest method shouldViewOriginalSchedule.

@SuppressWarnings("unchecked")
@Test
public void shouldViewOriginalSchedule() throws Exception {
    ActionForward viewOriginalScheduleForward = new ActionForward("viewOriginalSchedule");
    int loanId = 1;
    String loanAmount = "123";
    List<RepaymentScheduleInstallment> installments = Collections.EMPTY_LIST;
    java.sql.Date disbursementDate = new java.sql.Date(new DateTime().toDate().getTime());
    OriginalScheduleInfoDto dto = mock(OriginalScheduleInfoDto.class);
    when(dto.getOriginalLoanScheduleInstallment()).thenReturn(installments);
    when(dto.getLoanAmount()).thenReturn(loanAmount);
    when(dto.getDisbursementDate()).thenReturn(disbursementDate);
    when(request.getParameter(LoanAccountAction.ACCOUNT_ID)).thenReturn(String.valueOf(loanId));
    when(loanServiceFacade.retrieveOriginalLoanSchedule(loanId)).thenReturn(dto);
    when(mapping.findForward("viewOriginalSchedule")).thenReturn(viewOriginalScheduleForward);
    ActionForward forward = loanAccountAction.viewOriginalSchedule(mapping, form, request, response);
    assertThat(forward, is(viewOriginalScheduleForward));
    verify(request).getParameter(LoanAccountAction.ACCOUNT_ID);
    verify(loanServiceFacade).retrieveOriginalLoanSchedule(loanId);
    verify(dto).getOriginalLoanScheduleInstallment();
    verify(dto).getLoanAmount();
    verify(dto).getDisbursementDate();
    verify(mapping).findForward("viewOriginalSchedule");
}
Also used : RepaymentScheduleInstallment(org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment) OriginalScheduleInfoDto(org.mifos.accounts.loan.business.service.OriginalScheduleInfoDto) ActionForward(org.apache.struts.action.ActionForward) Date(java.util.Date) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 8 with OriginalScheduleInfoDto

use of org.mifos.accounts.loan.business.service.OriginalScheduleInfoDto in project head by mifos.

the class LoanAccountActionTest method getLoanRepaymentScheduleShouldCalculateExtraInterest.

@Test
public void getLoanRepaymentScheduleShouldCalculateExtraInterest() throws Exception {
    when(loanBusinessService.computeExtraInterest(eq(loanBO), Matchers.<Date>any())).thenReturn(new Errors());
    when(request.getParameter("accountId")).thenReturn("1");
    when(loanServiceFacade.retrieveOriginalLoanSchedule(Matchers.<Integer>any())).thenReturn(new OriginalScheduleInfoDto("100", new Date(), Collections.<RepaymentScheduleInstallment>emptyList()));
    loanAccountAction.getLoanRepaymentSchedule(mapping, form, request, response);
    verify(loanBusinessService, times(1)).computeExtraInterest(Matchers.<LoanBO>any(), Matchers.<Date>any());
}
Also used : Errors(org.mifos.platform.validations.Errors) ActionErrors(org.apache.struts.action.ActionErrors) RepaymentScheduleInstallment(org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment) OriginalScheduleInfoDto(org.mifos.accounts.loan.business.service.OriginalScheduleInfoDto) Date(java.util.Date) Test(org.junit.Test)

Example 9 with OriginalScheduleInfoDto

use of org.mifos.accounts.loan.business.service.OriginalScheduleInfoDto in project head by mifos.

the class LoanAccountAction method getGroupLoanRepaymentSchedule.

@TransactionDemarcate(joinToken = true)
public ActionForward getGroupLoanRepaymentSchedule(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, @SuppressWarnings("unused") final HttpServletResponse response) throws Exception {
    LoanAccountActionForm loanAccountActionForm = (LoanAccountActionForm) form;
    UserContext userContext = getUserContext(request);
    Integer grouploanId = Integer.valueOf(request.getParameter(ACCOUNT_ID));
    Locale locale = userContext.getPreferredLocale();
    Date viewDate = loanAccountActionForm.getScheduleViewDateValue(locale);
    LoanBO groupLoan = getLoan(grouploanId);
    LoanAccountAction.setSessionAtributeForGLIM(request, groupLoan);
    groupLoan.updateDetails(userContext);
    Errors errors = loanBusinessService.computeExtraInterest(groupLoan, viewDate);
    if (errors.hasErrors()) {
        loanAccountActionForm.resetScheduleViewDate();
    }
    List<LoanBO> membersAccount = this.loanDao.findIndividualLoans(grouploanId);
    List<Integer> membersAccountIds = getMembersAccountId(membersAccount);
    OriginalScheduleInfoDto generatedSchedule = OriginalScheduleInfoHelper.sumRepaymentSchedule(getMembersSchedule(membersAccountIds));
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, groupLoan, request);
    SessionUtils.setAttribute(Constants.VIEW_DATE, viewDate, request);
    SessionUtils.setAttribute(Constants.ORIGINAL_SCHEDULE_AVAILABLE, generatedSchedule.hasOriginalInstallments(), request);
    SessionUtils.setAttribute("isNewGropLoan", Boolean.TRUE, request);
    String forward = errors.hasErrors() ? ActionForwards.getLoanRepaymentScheduleFailure.toString() : ActionForwards.getLoanRepaymentSchedule.toString();
    addErrors(request, getActionErrors(errors));
    return mapping.findForward(forward);
}
Also used : Locale(java.util.Locale) LoanAccountActionForm(org.mifos.accounts.loan.struts.actionforms.LoanAccountActionForm) ActionErrors(org.apache.struts.action.ActionErrors) Errors(org.mifos.platform.validations.Errors) UserContext(org.mifos.security.util.UserContext) OriginalScheduleInfoDto(org.mifos.accounts.loan.business.service.OriginalScheduleInfoDto) LoanBO(org.mifos.accounts.loan.business.LoanBO) Date(java.util.Date) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Aggregations

OriginalScheduleInfoDto (org.mifos.accounts.loan.business.service.OriginalScheduleInfoDto)9 Date (java.util.Date)7 RepaymentScheduleInstallment (org.mifos.accounts.loan.util.helpers.RepaymentScheduleInstallment)6 ActionErrors (org.apache.struts.action.ActionErrors)4 Test (org.junit.Test)4 LoanBO (org.mifos.accounts.loan.business.LoanBO)4 Errors (org.mifos.platform.validations.Errors)4 ArrayList (java.util.ArrayList)3 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)3 UserContext (org.mifos.security.util.UserContext)3 Locale (java.util.Locale)2 ActionForward (org.apache.struts.action.ActionForward)2 OriginalLoanScheduleEntity (org.mifos.accounts.loan.business.OriginalLoanScheduleEntity)2 LoanAccountActionForm (org.mifos.accounts.loan.struts.actionforms.LoanAccountActionForm)2 Money (org.mifos.framework.util.helpers.Money)2 DateTime (org.joda.time.DateTime)1 OriginalScheduleInfoDtoMatcher (org.mifos.accounts.loan.business.matchers.OriginalScheduleInfoDtoMatcher)1 MifosRuntimeException (org.mifos.core.MifosRuntimeException)1 PersistenceException (org.mifos.framework.exceptions.PersistenceException)1