Search in sources :

Example 31 with LoanBO

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

the class RepayLoanActionStrutsTest method testMakeRepaymentForCurrentDateLiesBetweenInstallmentDates.

@Test
public void testMakeRepaymentForCurrentDateLiesBetweenInstallmentDates() throws Exception {
    setMifosUserFromContext();
    request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
    accountBO.changeFirstInstallmentDateBy(-1);
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, accountBO, request);
    Money amount = ((LoanBO) accountBO).getEarlyRepayAmount();
    SessionUtils.setAttribute(LoanConstants.WAIVED_REPAYMENT_AMOUNT, Money.zero(), request);
    SessionUtils.setAttribute(LoanConstants.TOTAL_REPAYMENT_AMOUNT, amount, request);
    setRequestPathInfo("/repayLoanAction");
    addRequestParameter("method", "makeRepayment");
    addRequestParameter("globalAccountNum", accountBO.getGlobalAccountNum());
    addRequestParameter("paymentTypeId", "1");
    addRequestParameter(Constants.CURRENTFLOWKEY, (String) request.getAttribute(Constants.CURRENTFLOWKEY));
    RepayLoanActionForm repayLoanActionForm = new RepayLoanActionForm();
    repayLoanActionForm.setAmount(amount.toString());
    repayLoanActionForm.setWaiverInterest(false);
    repayLoanActionForm.setDateOfPayment("23/12/2010");
    setActionForm(repayLoanActionForm);
    actionPerform();
    verifyForward(Constants.UPDATE_SUCCESS);
    Assert.assertEquals(accountBO.getAccountState().getId(), Short.valueOf(AccountStates.LOANACC_OBLIGATIONSMET));
    LoanSummaryEntity loanSummaryEntity = ((LoanBO) accountBO).getLoanSummary();
    Assert.assertEquals(amount, loanSummaryEntity.getPrincipalPaid().add(loanSummaryEntity.getFeesPaid()).add(loanSummaryEntity.getInterestPaid()).add(loanSummaryEntity.getPenaltyPaid()));
}
Also used : Money(org.mifos.framework.util.helpers.Money) LoanBO(org.mifos.accounts.loan.business.LoanBO) RepayLoanActionForm(org.mifos.accounts.loan.struts.actionforms.RepayLoanActionForm) LoanSummaryEntity(org.mifos.accounts.loan.business.LoanSummaryEntity) Test(org.junit.Test)

Example 32 with LoanBO

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

the class LoanAccountActionStrutsTest method testGet.

@Test
public void testGet() throws Exception {
    setMifosUserFromContext();
    Date startDate = new Date(System.currentTimeMillis());
    accountBO = getLoanAccount(AccountState.LOAN_APPROVED, startDate, 1);
    LoanBO loan = (LoanBO) accountBO;
    setRequestPathInfo("/loanAccountAction.do");
    addRequestParameter("method", "get");
    addRequestParameter("globalAccountNum", loan.getGlobalAccountNum());
    actionPerform();
    verifyForward("get_success");
    Assert.assertEquals(0, loan.getPerformanceHistory().getNoOfPayments().intValue());
    //        Assert.assertEquals((accountBO).getTotalAmountDue().getAmountDoubleValue(), 212.0);
    modifyActionDateForFirstInstallment();
    Assert.assertEquals("Total no. of notes should be 5", 5, accountBO.getAccountNotes().size());
//        LoanInformationDto loanInformationDto = retrieveLoanInformationDtoFromSession();
//        Assert.assertEquals("Total no. of recent notes should be 3", 3,  loanInformationDto.getRecentAccountNotes().size());
}
Also used : LoanBO(org.mifos.accounts.loan.business.LoanBO) Date(java.util.Date) Test(org.junit.Test)

Example 33 with LoanBO

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

the class AccountActionStrutsTest method testGetTrxnHistorySucess.

@Test
public void testGetTrxnHistorySucess() throws Exception {
    request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
    Date currentDate = new Date(System.currentTimeMillis());
    setRequestPathInfo("/accountAppAction");
    addRequestParameter("method", "getTrxnHistory");
    addRequestParameter("accountId", accountBO.getAccountId().toString());
    addRequestParameter("feeId", "123");
    addRequestParameter(Constants.CURRENTFLOWKEY, (String) request.getAttribute(Constants.CURRENTFLOWKEY));
    addRequestParameter("globalAccountNum", accountBO.getGlobalAccountNum());
    LoanBO loan = (LoanBO) accountBO;
    loan.setUserContext(TestUtils.makeUser());
    List<AccountActionDateEntity> accntActionDates = new ArrayList<AccountActionDateEntity>();
    accntActionDates.addAll(loan.getAccountActionDates());
    PaymentData accountPaymentDataView = TestObjectFactory.getLoanAccountPaymentData(accntActionDates, TestUtils.createMoney(0), null, loan.getPersonnel(), "receiptNum", Short.valueOf("1"), currentDate, currentDate);
    IntegrationTestObjectMother.applyAccountPayment(loan, accountPaymentDataView);
    actionPerform();
    verifyForward("getTransactionHistory_success");
    StaticHibernateUtil.flushSession();
    accountBO = TestObjectFactory.getObject(AccountBO.class, loan.getAccountId());
    List<TransactionHistoryDto> trxnHistoryList = (List<TransactionHistoryDto>) SessionUtils.getAttribute(SavingsConstants.TRXN_HISTORY_LIST, request);
    for (TransactionHistoryDto transactionHistoryDto : trxnHistoryList) {
        Assert.assertEquals(accountBO.getUserContext().getName(), transactionHistoryDto.getPostedBy());
    }
}
Also used : AccountActionDateEntity(org.mifos.accounts.business.AccountActionDateEntity) PaymentData(org.mifos.accounts.util.helpers.PaymentData) AccountBO(org.mifos.accounts.business.AccountBO) LoanBO(org.mifos.accounts.loan.business.LoanBO) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TransactionHistoryDto(org.mifos.dto.screen.TransactionHistoryDto) Date(java.util.Date) Test(org.junit.Test)

Example 34 with LoanBO

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

the class ApplyAdjustmentActionStrutsTest method getLoanAccount.

private AccountBO getLoanAccount() {
    Date startDate = new Date(System.currentTimeMillis());
    MeetingBO meeting = TestObjectFactory.createMeeting(TestObjectFactory.getTypicalMeeting());
    center = TestObjectFactory.createWeeklyFeeCenter(this.getClass().getSimpleName() + " Center", meeting);
    group = TestObjectFactory.createWeeklyFeeGroupUnderCenter(this.getClass().getSimpleName() + " Group", CustomerStatus.GROUP_ACTIVE, center);
    LoanOfferingBO loanOffering = TestObjectFactory.createLoanOffering(startDate, meeting);
    LoanBO loan = TestObjectFactory.createLoanAccount("42423142341", group, AccountState.LOAN_ACTIVE_IN_GOOD_STANDING, startDate, loanOffering);
    StaticHibernateUtil.flushSession();
    return TestObjectFactory.getObject(LoanBO.class, loan.getAccountId());
}
Also used : MeetingBO(org.mifos.application.meeting.business.MeetingBO) LoanBO(org.mifos.accounts.loan.business.LoanBO) LoanOfferingBO(org.mifos.accounts.productdefinition.business.LoanOfferingBO) Date(java.util.Date)

Example 35 with LoanBO

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

the class ApplyAdjustmentActionStrutsTest method testApplyAdjustment.

@Ignore
@Test
public void testApplyAdjustment() throws Exception {
    PersonnelBO personnel = legacyPersonnelDao.getPersonnel(PersonnelConstants.SYSTEM_USER);
    request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
    loan = (LoanBO) getLoanAccount();
    applyPayment(loan, 212);
    loan = TestObjectFactory.getObject(LoanBO.class, loan.getAccountId());
    applyPayment(loan, 700);
    loan = TestObjectFactory.getObject(LoanBO.class, loan.getAccountId());
    AccountStatusChangeHistoryEntity historyEntity = new AccountStatusChangeHistoryEntity(new AccountStateEntity(AccountState.LOAN_ACTIVE_IN_GOOD_STANDING), new AccountStateEntity(AccountState.LOAN_ACTIVE_IN_GOOD_STANDING), personnel, loan);
    AccountTestUtils.addToAccountStatusChangeHistory(loan, historyEntity);
    TestObjectFactory.updateObject(loan);
    StaticHibernateUtil.flushAndClearSession();
    loan = TestObjectFactory.getObject(LoanBO.class, loan.getAccountId());
    loan.setUserContext(userContext);
    for (AccountStatusChangeHistoryEntity accountStatus : loan.getAccountStatusChangeHistory()) {
        Assert.assertEquals(loan.getAccountId(), accountStatus.getAccount().getAccountId());
        Assert.assertNotNull(accountStatus.getAccountStatusChangeId());
        Assert.assertEquals(AccountState.LOAN_ACTIVE_IN_GOOD_STANDING.getValue(), accountStatus.getNewStatus().getId());
        Assert.assertEquals(personnel.getPersonnelId(), accountStatus.getPersonnel().getPersonnelId());
        Assert.assertEquals(personnel.getDisplayName(), accountStatus.getPersonnel().getDisplayName());
        Assert.assertEquals("-", accountStatus.getOldStatusName());
        Assert.assertNotNull(accountStatus.getNewStatusName());
        Assert.assertNull(accountStatus.getLocale());
        Assert.assertNotNull(accountStatus.getUserPrefferedTransactionDate());
    }
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, loan, request);
    setRequestPathInfo("/applyAdjustment");
    addRequestParameter("method", "applyAdjustment");
    addRequestParameter("adjustmentNote", "Loan adjustment testing");
    addRequestParameter("globalAccountNum", loan.getGlobalAccountNum());
    addRequestParameter(Constants.CURRENTFLOWKEY, (String) request.getAttribute(Constants.CURRENTFLOWKEY));
    setUpSecurityContext();
    getRequest().getSession().setAttribute(Constants.USERCONTEXT, TestUtils.makeUser());
    actionPerform();
    loan = (LoanBO) TestObjectFactory.getObject(AccountBO.class, loan.getAccountId());
    verifyForward("applyadj_success");
}
Also used : PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) LoanBO(org.mifos.accounts.loan.business.LoanBO) AccountStatusChangeHistoryEntity(org.mifos.accounts.business.AccountStatusChangeHistoryEntity) AccountStateEntity(org.mifos.accounts.business.AccountStateEntity) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

LoanBO (org.mifos.accounts.loan.business.LoanBO)215 ArrayList (java.util.ArrayList)76 Test (org.junit.Test)62 Money (org.mifos.framework.util.helpers.Money)60 UserContext (org.mifos.security.util.UserContext)45 MifosRuntimeException (org.mifos.core.MifosRuntimeException)42 Date (java.util.Date)37 AccountException (org.mifos.accounts.exceptions.AccountException)35 AccountBO (org.mifos.accounts.business.AccountBO)34 MifosUser (org.mifos.security.MifosUser)33 BigDecimal (java.math.BigDecimal)30 HashMap (java.util.HashMap)28 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)26 LocalDate (org.joda.time.LocalDate)23 PaymentData (org.mifos.accounts.util.helpers.PaymentData)22 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)22 PersistenceException (org.mifos.framework.exceptions.PersistenceException)21 ServiceException (org.mifos.framework.exceptions.ServiceException)19 BusinessRuleException (org.mifos.service.BusinessRuleException)19 LoanOfferingBO (org.mifos.accounts.productdefinition.business.LoanOfferingBO)18