Search in sources :

Example 21 with LoanBO

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

the class LoanAccountActionStrutsTest method testShouldPopulateClientDetailsFromLoan.

@Test
public void testShouldPopulateClientDetailsFromLoan() throws Exception {
    ClientBO clientMock1 = createMock(ClientBO.class);
    expect(clientMock1.getCustomerId()).andReturn(1).anyTimes();
    expect(clientMock1.getDisplayName()).andReturn("client 1");
    ClientBO clientMock2 = createMock(ClientBO.class);
    expect(clientMock2.getCustomerId()).andReturn(2).anyTimes();
    expect(clientMock2.getDisplayName()).andReturn("client 2");
    LoanBO loanMock = createMock(LoanBO.class);
    expect(loanMock.getCustomer()).andReturn(clientMock1).anyTimes();
    expect(loanMock.getBusinessActivityId()).andReturn(3);
    expect(loanMock.getLoanAmount()).andReturn(new Money(getCurrency(), "100")).anyTimes();
    LoanAccountDetailsDto clientDetails1 = new LoanAccountDetailsDto();
    clientDetails1.setClientId("1");
    clientDetails1.setClientName("client 1");
    clientDetails1.setBusinessActivity("3");
    clientDetails1.setLoanAmount("100.0");
    LoanAccountDetailsDto clientDetails2 = new LoanAccountDetailsDto();
    clientDetails2.setClientId("2");
    clientDetails2.setClientName("client 2");
    replay(clientMock1, clientMock2, loanMock);
    List<LoanAccountDetailsDto> clientDetails = new LoanAccountAction().populateClientDetailsFromLoan(Arrays.asList(clientMock1, clientMock2), Arrays.asList(loanMock), new ArrayList<ValueListElement>());
    Assert.assertEquals(Arrays.asList(clientDetails1, clientDetails2), clientDetails);
    verify(clientMock1, clientMock2, loanMock);
}
Also used : Money(org.mifos.framework.util.helpers.Money) ClientBO(org.mifos.customers.client.business.ClientBO) LoanBO(org.mifos.accounts.loan.business.LoanBO) LoanAccountDetailsDto(org.mifos.dto.domain.LoanAccountDetailsDto) ValueListElement(org.mifos.dto.domain.ValueListElement) Test(org.junit.Test)

Example 22 with LoanBO

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

the class LoanAccountActionStrutsTest method testManage.

@Test
public void testManage() throws Exception {
    request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
    Date startDate = new Date(System.currentTimeMillis());
    accountBO = getLoanAccount(AccountState.LOAN_APPROVED, startDate, 1);
    LoanBO loan = (LoanBO) accountBO;
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, loan, request);
    setRequestPathInfo("/loanAccountAction.do");
    addRequestParameter(Constants.CURRENTFLOWKEY, (String) request.getAttribute(Constants.CURRENTFLOWKEY));
    addRequestParameter("method", "manage");
    addRequestParameter("customerId", accountBO.getCustomer().getCustomerId().toString());
    addRequestParameter("globalAccountNum", accountBO.getGlobalAccountNum());
    actionPerform();
    verifyForward(ActionForwards.manage_success.toString());
    Assert.assertNotNull(SessionUtils.getAttribute(LoanConstants.LOANOFFERING, request));
    Assert.assertNotNull(SessionUtils.getAttribute(MasterConstants.COLLATERAL_TYPES, request));
    Assert.assertNotNull(SessionUtils.getAttribute(MasterConstants.BUSINESS_ACTIVITIES, request));
    Assert.assertNotNull(SessionUtils.getAttribute(LoanConstants.CUSTOM_FIELDS, request));
}
Also used : LoanBO(org.mifos.accounts.loan.business.LoanBO) Date(java.util.Date) Test(org.junit.Test)

Example 23 with LoanBO

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

the class LoanAccountActionStrutsTest method testManageWithoutFlow.

/*
     * this test appears to be confirming that an unauthenticated user gets a
     * "page expired" exception, but the catch() block doesn't appear to be
     * reached.
     */
@Test
public void testManageWithoutFlow() throws Exception {
    try {
        request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
        Date startDate = new Date(System.currentTimeMillis());
        accountBO = getLoanAccount(AccountState.LOAN_APPROVED, startDate, 1);
        LoanBO loan = (LoanBO) accountBO;
        SessionUtils.setAttribute(Constants.BUSINESS_KEY, loan, request);
        setRequestPathInfo("/loanAccountAction.do");
        addRequestParameter("method", "manage");
        addRequestParameter("customerId", accountBO.getCustomer().getCustomerId().toString());
        addRequestParameter("globalAccountNum", accountBO.getGlobalAccountNum());
        actionPerform();
    // I'd normally expect to see a call to JUnit 3's fail() here
    } catch (PageExpiredException pe) {
        Assert.assertTrue(true);
        Assert.assertEquals(ExceptionConstants.PAGEEXPIREDEXCEPTION, pe.getKey());
    }
}
Also used : LoanBO(org.mifos.accounts.loan.business.LoanBO) PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) Date(java.util.Date) Test(org.junit.Test)

Example 24 with LoanBO

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

the class LoanAccountActionStrutsTest method testUpdateSuccessWithRegeneratingNewRepaymentSchedule.

@Test
public void testUpdateSuccessWithRegeneratingNewRepaymentSchedule() throws Exception {
    request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
    Date startDate = new Date(System.currentTimeMillis());
    String newDate = offSetCurrentDate(14, userContext.getPreferredLocale());
    // This is a loan with weekly meetings every week. No interest is paid
    // at disbursement, so the first payment will be one week after the
    // disbursement date of the loan (14 days + 7 days = 21 days)
    String firstInstallmentDateWithNoInterestPaidAtDisbursementDate = offSetCurrentDate(21, userContext.getPreferredLocale());
    accountBO = getLoanAccount(AccountState.LOAN_APPROVED, startDate, 1);
    ((LoanBO) accountBO).setBusinessActivityId(1);
    PersonnelBO loggedInUser = IntegrationTestObjectMother.testUser();
    accountBO.changeStatus(AccountState.LOAN_APPROVED, null, "status changed", loggedInUser);
    accountBO.update();
    StaticHibernateUtil.flushSession();
    LoanBO loan = (LoanBO) accountBO;
    LoanOfferingBO loanOffering = loan.getLoanOffering();
    // loanOffering.updateLoanOfferingSameForAllLoan(loanOffering);
    SessionUtils.setAttribute(Constants.BUSINESS_KEY, loan, request);
    setRequestPathInfo("/loanAccountAction.do");
    addRequestParameter(Constants.CURRENTFLOWKEY, (String) request.getAttribute(Constants.CURRENTFLOWKEY));
    addRequestParameter("method", "manage");
    addRequestParameter("customerId", accountBO.getCustomer().getCustomerId().toString());
    addRequestParameter("globalAccountNum", accountBO.getGlobalAccountNum());
    actionPerform();
    setRequestPathInfo("/loanAccountAction.do");
    addRequestParameter(Constants.CURRENTFLOWKEY, (String) request.getAttribute(Constants.CURRENTFLOWKEY));
    addRequestParameter("method", "managePreview");
    addRequestParameter("loanAmount", loanOffering.getEligibleLoanAmountSameForAllLoan().getDefaultLoanAmount().toString());
    addRequestParameter("interestRate", loan.getLoanOffering().getDefInterestRate().toString());
    addRequestParameter("noOfInstallments", loanOffering.getDefaultNumOfEligibleInstallmentsSameForAllLoan().toString());
    addRequestParameter("disbursementDate", newDate);
    addRequestParameter("gracePeriodDuration", "0");
    addRequestParameter("intDedDisbursement", "0");
    addRequestParameter("customerId", group.getCustomerId().toString());
    actionPerform();
    setRequestPathInfo("/loanAccountAction.do");
    addRequestParameter(Constants.CURRENTFLOWKEY, (String) request.getAttribute(Constants.CURRENTFLOWKEY));
    addRequestParameter("method", "update");
    addRequestParameter("collateralNote", "test");
    actionPerform();
    verifyForward(ActionForwards.update_success.toString());
    loan = TestObjectFactory.getObject(LoanBO.class, loan.getAccountId());
    Assert.assertEquals("test", loan.getCollateralNote());
    Assert.assertEquals(300.0, loan.getLoanAmount().getAmount().doubleValue(), DELTA);
    Assert.assertEquals(0, loan.getGracePeriodDuration().intValue());
    Assert.assertEquals(firstInstallmentDateWithNoInterestPaidAtDisbursementDate, DateUtils.getUserLocaleDate(TestObjectFactory.getContext().getPreferredLocale(), DateUtils.toDatabaseFormat(loan.getAccountActionDate(Short.valueOf("1")).getActionDate())));
}
Also used : PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) LoanBO(org.mifos.accounts.loan.business.LoanBO) LoanOfferingBO(org.mifos.accounts.productdefinition.business.LoanOfferingBO) Date(java.util.Date) Test(org.junit.Test)

Example 25 with LoanBO

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

the class LoanAccountActionStrutsTest method testGetWithPayment.

@Test
public void testGetWithPayment() throws Exception {
    setMifosUserFromContext();
    Date startDate = new Date(System.currentTimeMillis());
    accountBO = getLoanAccount(AccountState.LOAN_APPROVED, startDate, 1);
    disburseLoan(startDate);
    LoanBO loan = (LoanBO) accountBO;
    setRequestPathInfo("/loanAccountAction.do");
    addRequestParameter("method", "get");
    addRequestParameter("globalAccountNum", loan.getGlobalAccountNum());
    actionPerform();
    verifyForward("get_success");
    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());
    Assert.assertEquals("Last payment action should be 'PAYMENT'", AccountActionTypes.DISBURSAL.getValue(), SessionUtils.getAttribute(AccountConstants.LAST_PAYMENT_ACTION, request));
    client = (CustomerBO) StaticHibernateUtil.getSessionTL().get(CustomerBO.class, client.getCustomerId());
    group = (CustomerBO) StaticHibernateUtil.getSessionTL().get(CustomerBO.class, group.getCustomerId());
    center = (CustomerBO) StaticHibernateUtil.getSessionTL().get(CustomerBO.class, center.getCustomerId());
}
Also used : LoanBO(org.mifos.accounts.loan.business.LoanBO) Date(java.util.Date) 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