Example usage for java.lang Short valueOf

List of usage examples for java.lang Short valueOf

Introduction

In this page you can find the example usage for java.lang Short valueOf.

Prototype

@HotSpotIntrinsicCandidate
public static Short valueOf(short s) 

Source Link

Document

Returns a Short instance representing the specified short value.

Usage

From source file:org.mifos.accounts.loan.business.LoanBOIntegrationTest.java

public void testGetRemainingPrincipalAmount() throws AccountException, SystemException {
    accountBO = getLoanAccount();/*from w w  w .  jav a 2 s.c om*/
    Date currentDate = new Date(System.currentTimeMillis());
    LoanBO loan = (LoanBO) accountBO;
    List<AccountActionDateEntity> accntActionDates = new ArrayList<AccountActionDateEntity>();
    accntActionDates.addAll(loan.getAccountActionDates());
    PaymentData paymentData = TestObjectFactory.getLoanAccountPaymentData(accntActionDates,
            TestUtils.createMoney(700), null, accountBO.getPersonnel(), "receiptNum", Short.valueOf("1"),
            currentDate, currentDate);
    loan.applyPaymentWithPersist(paymentData);

    TestObjectFactory.updateObject(loan);
    TestObjectFactory.flushandCloseSession();
    Assert.assertEquals("The amount returned for the payment should have been 700", 700.0,
            loan.getLastPmntAmnt());
    accountBO = TestObjectFactory.getObject(AccountBO.class, loan.getAccountId());
    loan = (LoanBO) accountBO;
    loan.getLoanSummary().getOriginalPrincipal().subtract(loan.getLoanSummary().getPrincipalPaid());
    Assert.assertEquals(loan.getRemainingPrincipalAmount(),
            loan.getLoanSummary().getOriginalPrincipal().subtract(loan.getLoanSummary().getPrincipalPaid()));
}

From source file:org.mifos.accounts.loan.business.LoanBOIntegrationTest.java

public void testIsAccountActive() throws Exception {
    Date startDate = new Date(System.currentTimeMillis());
    accountBO = getLoanAccount(AccountState.LOAN_APPROVED, startDate, 3);
    Assert.assertFalse(((LoanBO) accountBO).isAccountActive());

    // disburse loan

    ((LoanBO) accountBO).disburseLoan("1234", startDate, Short.valueOf("1"), accountBO.getPersonnel(),
            startDate, Short.valueOf("1"));
    Session session = StaticHibernateUtil.getSessionTL();
    StaticHibernateUtil.startTransaction();
    session.save(accountBO);//from w  w w  .  j  a va 2  s .  c  om
    StaticHibernateUtil.getTransaction().commit();
    ((LoanBO) accountBO).setLoanMeeting(null);
    List<AccountPaymentEntity> accountpayments = accountBO.getAccountPayments();
    Assert.assertEquals(1, accountpayments.size());
    for (AccountPaymentEntity entity : accountpayments) {
        Assert.assertEquals("1234", entity.getReceiptNumber());
        // asssert loan trxns
        Set<AccountTrxnEntity> accountTrxns = entity.getAccountTrxns();
        Assert.assertEquals(1, accountTrxns.size());
        AccountTrxnEntity transaction = accountTrxns.iterator().next();
        Assert.assertEquals(AccountActionTypes.DISBURSAL, transaction.getAccountAction());
        Assert.assertEquals(TestUtils.createMoney(300.0), transaction.getAmount());
        Assert.assertEquals(accountBO.getAccountId(), transaction.getAccount().getAccountId());
    }
    Assert.assertTrue(((LoanBO) accountBO).isAccountActive());
}

From source file:org.mifos.accounts.loan.business.LoanBOIntegrationTest.java

public void testGetNoOfBackDatedPayments() throws AccountException, SystemException {
    accountBO = getLoanAccount();//from w w w  .  j ava  2  s  . com
    accountBO.setUserContext(TestObjectFactory.getContext());
    accountBO.changeStatus(AccountState.LOAN_ACTIVE_IN_BAD_STANDING, null, "");
    changeInstallmentDate(accountBO, 14, Short.valueOf("1"));
    changeInstallmentDate(accountBO, 14, Short.valueOf("2"));
    TestObjectFactory.updateObject(accountBO);
    TestObjectFactory.flushandCloseSession();

    accountBO = TestObjectFactory.getObject(AccountBO.class, accountBO.getAccountId());

    Date startDate = new Date(System.currentTimeMillis());
    PaymentData paymentData = PaymentData.createPaymentData(
            new Money(Configuration.getInstance().getSystemConfig().getCurrency(), "212.0"),
            accountBO.getPersonnel(), Short.valueOf("1"), startDate);
    paymentData.setReceiptDate(startDate);
    paymentData.setReceiptNum("5435345");

    accountBO.applyPaymentWithPersist(paymentData);
    TestObjectFactory.flushandCloseSession();

    accountBO = TestObjectFactory.getObject(AccountBO.class, accountBO.getAccountId());

    Assert.assertEquals(Integer.valueOf("2"),
            ((LoanBO) accountBO).getPerformanceHistory().getTotalNoOfMissedPayments());
}

From source file:org.mifos.accounts.loan.business.LoanBOIntegrationTest.java

public void testDisbursalLoanForCustomerPerfHistory() throws Exception {
    Date startDate = new Date(System.currentTimeMillis());
    accountBO = getLoanAccountWithPerformanceHistory(AccountState.LOAN_APPROVED, startDate, 3);

    ClientPerformanceHistoryEntity clientPerfHistory = (ClientPerformanceHistoryEntity) ((LoanBO) accountBO)
            .getCustomer().getPerformanceHistory();
    Integer noOfActiveLoans = clientPerfHistory.getNoOfActiveLoans();
    Integer loanCycleNumber = clientPerfHistory.getLoanCycleNumber();
    ((LoanBO) accountBO).disburseLoan("1234", startDate, Short.valueOf("1"), accountBO.getPersonnel(),
            startDate, Short.valueOf("1"));
    StaticHibernateUtil.commitTransaction();
    StaticHibernateUtil.closeSession();//  www . j av  a 2  s .c om
    client = TestObjectFactory.getCustomer(client.getCustomerId());
    accountBO = (AccountBO) StaticHibernateUtil.getSessionTL().get(AccountBO.class, accountBO.getAccountId());
    LoanBO loan = (LoanBO) accountBO;
    Assert.assertEquals(noOfActiveLoans + 1, clientPerfHistory.getNoOfActiveLoans().intValue());
    Assert.assertEquals(loanCycleNumber + 1, clientPerfHistory.getLoanCycleNumber().intValue());
    LoanPerformanceHistoryEntity loanPerfHistory = loan.getPerformanceHistory();
    Assert.assertEquals(getLastInstallmentAccountAction(loan).getActionDate(),
            loanPerfHistory.getLoanMaturityDate());
}

From source file:org.mifos.accounts.loan.business.LoanBOIntegrationTest.java

public void testDisbursalLoanForGroupPerfHistory() throws Exception {
    Date startDate = new Date(System.currentTimeMillis());
    accountBO = getLoanAccountWithGroupPerformanceHistory(AccountState.LOAN_APPROVED, startDate, 3);

    GroupPerformanceHistoryEntity groupPerformanceHistoryEntity = (GroupPerformanceHistoryEntity) ((LoanBO) accountBO)
            .getCustomer().getPerformanceHistory();
    ((LoanBO) accountBO).disburseLoan("1234", startDate, Short.valueOf("1"), accountBO.getPersonnel(),
            startDate, Short.valueOf("1"));
    StaticHibernateUtil.commitTransaction();
    StaticHibernateUtil.closeSession();/*w ww. j a  v  a 2 s  .c om*/
    group = TestObjectFactory.getCustomer(group.getCustomerId());
    accountBO = (AccountBO) StaticHibernateUtil.getSessionTL().get(AccountBO.class, accountBO.getAccountId());
    LoanBO loan = (LoanBO) accountBO;
    Assert.assertEquals(new Money(getCurrency(), "300.0"),
            groupPerformanceHistoryEntity.getLastGroupLoanAmount());
    LoanPerformanceHistoryEntity loanPerfHistory = loan.getPerformanceHistory();
    Assert.assertEquals(getLastInstallmentAccountAction(loan).getActionDate(),
            loanPerfHistory.getLoanMaturityDate());
}

From source file:org.mifos.accounts.loan.business.LoanBOIntegrationTest.java

/**
 * TODO: Re-enable this test when rounding code correctly handles mid-stream
 * changes to the loan schedule. Note the use of method getLoanAccount(),
 * which radically alters the terms of the loan, unbeknownst to the reader
 * of this code. Here's a trace of this bizarre code:
 * <ul>// w  w w.ja va 2s .com
 * <li>getLoanAccount() calls
 * <li>TestObjectFactory.createLoanAccount(), which calls
 * <li>LoanBOIntegrationTest.createLoanAccount(). This method initiall
 * creates the loan with terms:
 * <ul>
 * <li>Loan amount 0
 * <li>Interest rate 0.0
 * <li>6 weekly installments
 * <li>no fees
 * </ul>
 * <li>The method then goes on to alter the loan by directly manipulating
 * instance variables:
 * <ul>
 * <li>Add a periodic amount fee of 100 to each installment
 * <li>Change each installment's principal to 100 and interest to 12.0 (but
 * the loan amount is still 300, although the principal due is now 600!)
 * </ul>
 * </ul>
 * This leaves the loan in a badly inconsistent state, causing the (second)
 * call to applyRounding() to break. This test code needs to be refactored!
 * <p>
 * This test now breaks. However, rounding with miscellaneous fees is fully
 * covered by tests in TestLoanRedoDisbursal.java, so it is disabled.
 */
public void xtestRoundInstallments() throws AccountException, SystemException {
    accountBO = getLoanAccount();
    TestObjectFactory.flushandCloseSession();
    accountBO = TestObjectFactory.getObject(AccountBO.class, accountBO.getAccountId());
    ((LoanBO) accountBO).getLoanOffering().setPrinDueLastInst(false);
    List<Short> installmentIdList = new ArrayList<Short>();
    for (AccountActionDateEntity accountAction : accountBO.getAccountActionDates()) {
        LoanScheduleEntity accountActionDateEntity = (LoanScheduleEntity) accountAction;
        installmentIdList.add(accountActionDateEntity.getInstallmentId());
        if (accountActionDateEntity.getInstallmentId().equals(Short.valueOf("1"))) {
            accountActionDateEntity.setMiscFee(new Money(getCurrency(), "20.3"));
        }
    }
    ((LoanBO) accountBO).applyRounding();
    TestObjectFactory.updateObject(accountBO);
    TestObjectFactory.flushandCloseSession();

    accountBO = TestObjectFactory.getObject(AccountBO.class, accountBO.getAccountId());

    Set<AccountActionDateEntity> actionDateEntities = accountBO.getAccountActionDates();
    LoanScheduleEntity[] paymentsArray = LoanBOTestUtils.getSortedAccountActionDateEntity(actionDateEntities);

    checkTotalDueWithFees("233.0", paymentsArray[0]);
    checkTotalDueWithFees("212.0", paymentsArray[1]);
    checkTotalDueWithFees("212.0", paymentsArray[2]);
    checkTotalDueWithFees("212.0", paymentsArray[3]);
    checkTotalDueWithFees("212.0", paymentsArray[4]);
    checkTotalDueWithFees("212.0", paymentsArray[5]);
}

From source file:org.mifos.accounts.loan.business.LoanBOIntegrationTest.java

public void testBuildLoanWithoutLoanOffering() throws Exception {
    createInitialCustomers();//from  w w  w  .  j av a  2 s. c om
    try {
        loanDao.createLoan(TestUtils.makeUser(), null, group, AccountState.LOAN_APPROVED,
                new Money(getCurrency(), "300.0"), Short.valueOf("6"), new Date(System.currentTimeMillis()),
                false, 10.0, (short) 0, null, new ArrayList<FeeView>(), new ArrayList<CustomFieldView>(),
                DOUBLE_ZERO, DOUBLE_ZERO, SHORT_ZERO, SHORT_ZERO, false);
        Assert.assertFalse("The Loan object is created for null loan offering", true);
    } catch (AccountException ae) {
        Assert.assertTrue("The Loan object is not created for null loan offering", true);
    }
}

From source file:org.mifos.accounts.loan.business.LoanBOIntegrationTest.java

public void testBuildForInactiveLoanOffering() throws Exception {
    createInitialCustomers();/* w ww . j  av a2  s . c  om*/
    LoanOfferingBO loanOffering = createLoanOffering(false, false, PrdStatus.LOAN_INACTIVE);
    try {
        LoanOfferingInstallmentRange eligibleInstallmentRange = loanOffering
                .getEligibleInstallmentSameForAllLoan();

        LoanBO.createLoan(TestUtils.makeUser(), loanOffering, group, AccountState.LOAN_APPROVED,
                new Money(getCurrency(), "300.0"), Short.valueOf("6"), new Date(System.currentTimeMillis()),
                false, 10.0, (short) 0, null, new ArrayList<FeeView>(), new ArrayList<CustomFieldView>(),
                DEFAULT_LOAN_AMOUNT, DEFAULT_LOAN_AMOUNT, eligibleInstallmentRange.getMaxNoOfInstall(),
                eligibleInstallmentRange.getMinNoOfInstall(), false, null);
        Assert.fail("The Loan object is created for inactive loan offering");
    } catch (AccountException ae) {
        Assert.assertTrue("The Loan object is not created for inactive loan offering", true);
    }
    TestObjectFactory.removeObject(loanOffering);
}

From source file:org.mifos.accounts.loan.business.LoanBOIntegrationTest.java

public void testBuildLoanWithoutCustomer() throws Exception {
    createInitialCustomers();/*  w  w  w .j  ava  2s  .  c o m*/
    LoanOfferingBO loanOffering = createLoanOffering(false);
    LoanOfferingInstallmentRange eligibleInstallmentRange = loanOffering.getEligibleInstallmentSameForAllLoan();

    try {
        LoanBO.createLoan(TestUtils.makeUser(), loanOffering, null, AccountState.LOAN_APPROVED,
                new Money(getCurrency(), "300.0"), Short.valueOf("6"), new Date(System.currentTimeMillis()),
                false, 10.0, (short) 0, null, new ArrayList<FeeView>(), new ArrayList<CustomFieldView>(),
                DEFAULT_LOAN_AMOUNT, DEFAULT_LOAN_AMOUNT, eligibleInstallmentRange.getMaxNoOfInstall(),
                eligibleInstallmentRange.getMinNoOfInstall(), false, null);
        Assert.assertFalse("The Loan object is created for null customer", true);
    } catch (AccountException ae) {
        Assert.assertTrue("The Loan object is not created for null customer", true);
    }
    TestObjectFactory.removeObject(loanOffering);
}

From source file:org.mifos.accounts.loan.business.LoanBOIntegrationTest.java

public void testBuildForInactiveCustomer() throws Exception {
    createInitialCustomers();//from   www .j a v a2s .c o  m
    CustomerBOTestUtils.setCustomerStatus(group, new CustomerStatusEntity(CustomerStatus.GROUP_CLOSED));
    TestObjectFactory.updateObject(group);
    group = TestObjectFactory.getGroup(group.getCustomerId());

    LoanOfferingBO loanOffering = createLoanOffering(false);
    try {
        loanDao.createLoan(TestUtils.makeUser(), loanOffering, null, AccountState.LOAN_APPROVED,
                new Money(getCurrency(), "300.0"), Short.valueOf("6"), new Date(System.currentTimeMillis()),
                false, 10.0, (short) 0, null, new ArrayList<FeeView>(), new ArrayList<CustomFieldView>(),
                DOUBLE_ZERO, DOUBLE_ZERO, SHORT_ZERO, SHORT_ZERO, false);
        Assert.assertFalse("The Loan object is created for inactive customer", true);
    } catch (AccountException ae) {
        Assert.assertTrue("The Loan object is not created for inactive customer", true);
    }
    TestObjectFactory.removeObject(loanOffering);

}