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

/**
 * TODO: Re-enable this test when rounding code correctly handles mid-stream
 * changes to the loan schedule./*from   w  ww  . j a va  2 s.c o m*/
 */
public void testRemoveFeeForPartiallyPaidFeesAccount() throws Exception {
    Date startDate = new Date(System.currentTimeMillis());
    MeetingBO meeting = TestObjectFactory.createMeeting(
            TestObjectFactory.getNewMeetingForToday(WEEKLY, EVERY_SECOND_WEEK, CUSTOMER_MEETING));
    center = TestObjectFactory.createWeeklyFeeCenter(this.getClass().getSimpleName() + " Center", meeting);
    group = TestObjectFactory.createWeeklyFeeGroupUnderCenter(this.getClass().getSimpleName() + " Group",
            CustomerStatus.GROUP_ACTIVE, center);
    LoanOfferingBO loanOffering = createOfferingNoPrincipalInLastInstallment(startDate,
            center.getCustomerMeeting().getMeeting());
    List<FeeView> feeViewList = new ArrayList<FeeView>();
    FeeBO periodicFee = TestObjectFactory.createPeriodicAmountFee("Periodic Fee", FeeCategory.LOAN, "100",
            RecurrenceType.WEEKLY, Short.valueOf("1"));
    feeViewList.add(new FeeView(TestObjectFactory.getContext(), periodicFee));

    accountBO = loanDao.createLoan(TestUtils.makeUser(), loanOffering, group,
            AccountState.LOAN_ACTIVE_IN_GOOD_STANDING, new Money(getCurrency(), "300.0"), Short.valueOf("6"),
            startDate, false, 1.2, (short) 0, null, feeViewList, null, DOUBLE_ZERO, DOUBLE_ZERO, SHORT_ZERO,
            SHORT_ZERO, false);
    new TestObjectPersistence().persist(accountBO);
    Assert.assertEquals(6, accountBO.getAccountActionDates().size());
    StaticHibernateUtil.closeSession();

    accountBO = (AccountBO) StaticHibernateUtil.getSessionTL().get(AccountBO.class, accountBO.getAccountId());

    accountBO.applyPaymentWithPersist(TestObjectFactory.getLoanAccountPaymentData(null,
            new Money(getCurrency(), "60"), accountBO.getCustomer(), accountBO.getPersonnel(), "432423",
            (short) 1, startDate, startDate));
    StaticHibernateUtil.commitTransaction();

    for (AccountFeesEntity accountFeesEntity : accountBO.getAccountFees()) {
        accountBO.removeFees(accountFeesEntity.getFees().getFeeId(), Short.valueOf("1"));
    }
    StaticHibernateUtil.commitTransaction();

    Map<String, String> fees0 = new HashMap<String, String>();

    Map<String, String> fees1 = new HashMap<String, String>();
    fees1.put("Periodic Fee", "60");

    Set<AccountActionDateEntity> actionDateEntities = ((LoanBO) accountBO).getAccountActionDates();
    Assert.assertEquals(6, actionDateEntities.size());
    LoanScheduleEntity[] paymentsArray = LoanBOTestUtils.getSortedAccountActionDateEntity(actionDateEntities);

    checkFees(fees1, paymentsArray[0], false);
    checkFees(fees0, paymentsArray[1], false);
    checkFees(fees0, paymentsArray[2], false);
    checkFees(fees0, paymentsArray[3], false);
    checkFees(fees0, paymentsArray[4], false);
    checkFees(fees0, paymentsArray[5], false);

    for (AccountFeesEntity accountFeesEntity : accountBO.getAccountFees()) {
        Assert.assertEquals(FeeStatus.INACTIVE, accountFeesEntity.getFeeStatusAsEnum());
        Assert.assertNull(accountFeesEntity.getLastAppliedDate());
    }
    LoanSummaryEntity loanSummaryEntity = ((LoanBO) accountBO).getLoanSummary();
    Assert.assertEquals(new Money(getCurrency(), "60"), loanSummaryEntity.getFeesPaid());
    Assert.assertEquals(new Money(getCurrency(), "60"), loanSummaryEntity.getOriginalFees());
    Assert.assertEquals(new Money(getCurrency()), loanSummaryEntity.getFeesDue());
    for (LoanActivityEntity loanActivityEntity : ((LoanBO) accountBO).getLoanActivityDetails()) {
        if (loanActivityEntity.getComments().equalsIgnoreCase("Periodic Fee removed")) {
            Assert.assertEquals(loanSummaryEntity.getFeesDue(), loanActivityEntity.getFeeOutstanding());
            Assert.assertEquals(new Money(getCurrency(), "1040"), loanActivityEntity.getFee());
            break;
        }
    }
}

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./*from  w  w w .  jav a  2  s.  c om*/
 */
public void testApplyChargeForPartiallyPaidFeesAccount() throws Exception {
    Date startDate = new Date(System.currentTimeMillis());
    MeetingBO meeting = TestObjectFactory.createMeeting(
            TestObjectFactory.getNewMeetingForToday(WEEKLY, EVERY_SECOND_WEEK, CUSTOMER_MEETING));
    center = TestObjectFactory.createWeeklyFeeCenter(this.getClass().getSimpleName() + " Center", meeting);
    group = TestObjectFactory.createWeeklyFeeGroupUnderCenter(this.getClass().getSimpleName() + " Group",
            CustomerStatus.GROUP_ACTIVE, center);
    LoanOfferingBO loanOffering = TestObjectFactory.createLoanOffering("Loan", ApplicableTo.GROUPS, startDate,
            PrdStatus.LOAN_ACTIVE, 300.0, 1.2, 3, InterestType.FLAT, center.getCustomerMeeting().getMeeting());
    List<FeeView> feeViewList = new ArrayList<FeeView>();
    FeeBO periodicFee = TestObjectFactory.createPeriodicAmountFee("Periodic Fee", FeeCategory.LOAN, "100",
            RecurrenceType.WEEKLY, Short.valueOf("1"));
    feeViewList.add(new FeeView(TestObjectFactory.getContext(), periodicFee));

    accountBO = loanDao.createLoan(TestUtils.makeUser(), loanOffering, group,
            AccountState.LOAN_ACTIVE_IN_GOOD_STANDING, new Money(getCurrency(), "300.0"), Short.valueOf("6"),
            startDate, false, 1.2, (short) 0, null, feeViewList, null, DOUBLE_ZERO, DOUBLE_ZERO, SHORT_ZERO,
            SHORT_ZERO, false);
    new TestObjectPersistence().persist(accountBO);
    Assert.assertEquals(6, accountBO.getAccountActionDates().size());
    StaticHibernateUtil.closeSession();

    accountBO = (AccountBO) StaticHibernateUtil.getSessionTL().get(AccountBO.class, accountBO.getAccountId());

    accountBO.applyPaymentWithPersist(TestObjectFactory.getLoanAccountPaymentData(null,
            new Money(getCurrency(), "60"), accountBO.getCustomer(), accountBO.getPersonnel(), "432423",
            (short) 1, startDate, startDate));
    StaticHibernateUtil.commitTransaction();

    for (AccountFeesEntity accountFeesEntity : accountBO.getAccountFees()) {
        accountBO.removeFees(accountFeesEntity.getFees().getFeeId(), Short.valueOf("1"));
    }
    StaticHibernateUtil.commitTransaction();
    Map<String, String> fees0 = new HashMap<String, String>(0);

    Map<String, String> fees1 = new HashMap<String, String>();
    fees1.put("Periodic Fee", "60");
    Map<String, String> feesPaid1 = new HashMap<String, String>();
    feesPaid1.put("Periodic Fee", "60");

    LoanScheduleEntity[] paymentsArray = LoanBOTestUtils
            .getSortedAccountActionDateEntity(((LoanBO) accountBO).getAccountActionDates());

    Assert.assertEquals(6, paymentsArray.length);
    checkLoanScheduleEntity(null, null, null, null, null, null, fees1, feesPaid1, null, null, paymentsArray[0]);
    checkLoanScheduleEntity(null, null, null, null, null, null, fees0, null, null, null, paymentsArray[1]);
    checkLoanScheduleEntity(null, null, null, null, null, null, fees0, null, null, null, paymentsArray[2]);
    checkLoanScheduleEntity(null, null, null, null, null, null, fees0, null, null, null, paymentsArray[3]);
    checkLoanScheduleEntity(null, null, null, null, null, null, fees0, null, null, null, paymentsArray[4]);
    checkLoanScheduleEntity(null, null, null, null, null, null, fees0, null, null, null, paymentsArray[5]);

    for (AccountFeesEntity accountFeesEntity : accountBO.getAccountFees()) {
        Assert.assertEquals(FeeStatus.INACTIVE, accountFeesEntity.getFeeStatusAsEnum());
        Assert.assertNull(accountFeesEntity.getLastAppliedDate());
    }
    LoanSummaryEntity loanSummaryEntity = ((LoanBO) accountBO).getLoanSummary();
    Assert.assertEquals(new Money(getCurrency(), "60"), loanSummaryEntity.getFeesPaid());
    Assert.assertEquals(new Money(getCurrency(), "60"), loanSummaryEntity.getOriginalFees());
    Assert.assertEquals(new Money(getCurrency()), loanSummaryEntity.getFeesDue());
    for (LoanActivityEntity loanActivityEntity : ((LoanBO) accountBO).getLoanActivityDetails()) {
        if (loanActivityEntity.getComments().equalsIgnoreCase("Periodic Fee removed")) {
            Assert.assertEquals(loanSummaryEntity.getFeesDue(), loanActivityEntity.getFeeOutstanding());
            Assert.assertEquals(new Money(getCurrency(), "1040"), loanActivityEntity.getFee());
            break;
        }
    }

    accountBO.setUserContext(TestUtils.makeUser());
    for (AccountFeesEntity accountFeesEntity : accountBO.getAccountFees()) {
        accountBO.applyCharge(accountFeesEntity.getFees().getFeeId(), Double.valueOf("200"));
    }
    StaticHibernateUtil.commitTransaction();

    Map<String, String> fee260 = new HashMap<String, String>();
    fee260.put("Periodic Fee", "260");

    Map<String, String> fee400 = new HashMap<String, String>();
    fee400.put("Periodic Fee", "400");

    Set<AccountActionDateEntity> actionDateEntities1 = ((LoanBO) accountBO).getAccountActionDates();
    Assert.assertEquals(6, actionDateEntities1.size());
    LoanScheduleEntity[] paymentsArray1 = LoanBOTestUtils.getSortedAccountActionDateEntity(actionDateEntities1);

    checkLoanScheduleEntity(null, null, null, null, null, null, fee260, null, null, null, paymentsArray1[0]);
    checkLoanScheduleEntity(null, null, null, null, null, null, fee400, null, null, null, paymentsArray1[1]);
    checkLoanScheduleEntity(null, null, null, null, null, null, fee400, null, null, null, paymentsArray1[2]);
    checkLoanScheduleEntity(null, null, null, null, null, null, fee400, null, null, null, paymentsArray1[3]);
    checkLoanScheduleEntity(null, null, null, null, null, null, fee400, null, null, null, paymentsArray1[4]);
    checkLoanScheduleEntity(null, null, null, null, null, null, fee400, null, null, null, paymentsArray1[5]);

    // not sure if the remaining is being handled by validatePayments
    for (AccountActionDateEntity accountActionDateEntity : accountBO.getAccountActionDates()) {
        LoanScheduleEntity loanScheduleEntity = (LoanScheduleEntity) accountActionDateEntity;
        if (!loanScheduleEntity.getInstallmentId().equals(Short.valueOf("1"))) {
            Assert.assertEquals(1, loanScheduleEntity.getAccountFeesActionDetails().size());
            for (AccountFeesActionDetailEntity accountFeesActionDetailEntity : loanScheduleEntity
                    .getAccountFeesActionDetails()) {
                LoanFeeScheduleEntity loanFeeScheduleEntity = (LoanFeeScheduleEntity) accountFeesActionDetailEntity;
                Assert.assertEquals(TestUtils.createMoney(), loanFeeScheduleEntity.getFeeAmountPaid());
            }
        }
    }

    for (AccountFeesEntity accountFeesEntity : accountBO.getAccountFees()) {
        Assert.assertEquals(FeeStatus.ACTIVE, accountFeesEntity.getFeeStatusAsEnum());
        Assert.assertNotNull(accountFeesEntity.getLastAppliedDate());
    }
    loanSummaryEntity = ((LoanBO) accountBO).getLoanSummary();
    Assert.assertEquals(new Money(getCurrency(), "60"), loanSummaryEntity.getFeesPaid());
    Assert.assertEquals(new Money(getCurrency(), "2260"), loanSummaryEntity.getOriginalFees());
    Assert.assertEquals(new Money(getCurrency(), "2200"), loanSummaryEntity.getFeesDue());
    for (LoanActivityEntity loanActivityEntity : ((LoanBO) accountBO).getLoanActivityDetails()) {
        if (loanActivityEntity.getComments().equalsIgnoreCase("Periodic Fee applied")) {
            Assert.assertEquals(loanSummaryEntity.getFeesDue(), loanActivityEntity.getFeeOutstanding());
            Assert.assertEquals(new Money(getCurrency(), "2200"), loanActivityEntity.getFee());
            break;
        }
    }
}

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

public void testGetDaysInArrears() {
    java.sql.Date lastWeekDate = setDate(new GregorianCalendar().DAY_OF_MONTH, -14);

    java.sql.Date twoWeeksBeforeDate = setDate(new GregorianCalendar().DAY_OF_MONTH, -21);
    accountBO = getLoanAccount();/*ww w  .  ja  v  a 2 s .c o m*/
    for (AccountActionDateEntity installment : accountBO.getAccountActionDates()) {
        if (installment.getInstallmentId().intValue() == 1) {
            ((LoanScheduleEntity) installment).setActionDate(twoWeeksBeforeDate);
        } else if (installment.getInstallmentId().intValue() == 2) {
            ((LoanScheduleEntity) installment).setActionDate(lastWeekDate);
        }
    }
    TestObjectFactory.updateObject(accountBO);
    TestObjectFactory.flushandCloseSession();
    accountBO = TestObjectFactory.getObject(AccountBO.class, accountBO.getAccountId());
    Assert.assertEquals(Short.valueOf("21"), ((LoanBO) accountBO).getDaysInArrears());
}

From source file:org.apache.ambari.server.controller.AmbariManagementControllerTest.java

@Test
public void testResourceFiltersWithCustomActions() throws AmbariException {
    setupClusterWithHosts("c1", "HDP-2.0.6", new ArrayList<String>() {
        {/*  ww  w  .  j a  va2 s. c  om*/
            add("h1");
            add("h2");
            add("h3");
        }
    }, "centos6");

    Cluster cluster = clusters.getCluster("c1");
    cluster.setDesiredStackVersion(new StackId("HDP-2.0.6"));
    cluster.setCurrentStackVersion(new StackId("HDP-2.0.6"));

    ConfigFactory cf = injector.getInstance(ConfigFactory.class);
    Config config1 = cf.createNew(cluster, "global", new HashMap<String, String>() {
        {
            put("key1", "value1");
        }
    }, new HashMap<String, Map<String, String>>());
    config1.setTag("version1");

    Config config2 = cf.createNew(cluster, "core-site", new HashMap<String, String>() {
        {
            put("key1", "value1");
        }
    }, new HashMap<String, Map<String, String>>());
    config2.setTag("version1");

    cluster.addConfig(config1);
    cluster.addConfig(config2);

    Service hdfs = cluster.addService("HDFS");
    hdfs.persist();

    Service mapred = cluster.addService("YARN");
    mapred.persist();

    hdfs.addServiceComponent(Role.HDFS_CLIENT.name()).persist();
    hdfs.addServiceComponent(Role.NAMENODE.name()).persist();
    hdfs.addServiceComponent(Role.DATANODE.name()).persist();

    mapred.addServiceComponent(Role.RESOURCEMANAGER.name()).persist();

    hdfs.getServiceComponent(Role.HDFS_CLIENT.name()).addServiceComponentHost("h1").persist();
    hdfs.getServiceComponent(Role.NAMENODE.name()).addServiceComponentHost("h1").persist();
    hdfs.getServiceComponent(Role.DATANODE.name()).addServiceComponentHost("h1").persist();
    hdfs.getServiceComponent(Role.DATANODE.name()).addServiceComponentHost("h2").persist();

    controller.getAmbariMetaInfo().addActionDefinition(new ActionDefinition("a1", ActionType.SYSTEM, "", "HDFS",
            "", "Some custom action.", TargetHostType.ALL, Short.valueOf("100")));

    Map<String, String> params = new HashMap<String, String>() {
        {
            put("test", "test");
        }
    };

    Map<String, String> requestProperties = new HashMap<String, String>();
    requestProperties.put(REQUEST_CONTEXT_PROPERTY, "Called from a test");

    List<RequestResourceFilter> resourceFilters = new ArrayList<RequestResourceFilter>();
    ArrayList<String> hosts = new ArrayList<String>() {
        {
            add("h2");
        }
    };
    RequestResourceFilter resourceFilter1 = new RequestResourceFilter("HDFS", "DATANODE", hosts);

    hosts = new ArrayList<String>() {
        {
            add("h1");
        }
    };
    RequestResourceFilter resourceFilter2 = new RequestResourceFilter("HDFS", "NAMENODE", hosts);

    resourceFilters.add(resourceFilter1);
    resourceFilters.add(resourceFilter2);

    ExecuteActionRequest actionRequest = new ExecuteActionRequest("c1", null, "a1", resourceFilters, null,
            params, false);
    RequestStatusResponse response = null;
    try {
        response = controller.createAction(actionRequest, requestProperties);
    } catch (AmbariException ae) {
        LOG.info("Expected exception.", ae);
        Assert.assertTrue(ae.getMessage()
                .contains("Custom action definition only " + "allows one resource filter to be specified"));
    }
    resourceFilters.remove(resourceFilter1);
    actionRequest = new ExecuteActionRequest("c1", null, "a1", resourceFilters, null, params, false);
    response = controller.createAction(actionRequest, requestProperties);

    assertEquals(1, response.getTasks().size());
    HostRoleCommand nnCommand = null;

    for (HostRoleCommand hrc : actionDB.getRequestTasks(response.getRequestId())) {
        if (hrc.getHostName().equals("h1")) {
            nnCommand = hrc;
        }
    }

    Assert.assertNotNull(nnCommand);
    ExecutionCommand cmd = nnCommand.getExecutionCommandWrapper().getExecutionCommand();
    Assert.assertEquals("a1", cmd.getRole());
    Type type = new TypeToken<Map<String, String>>() {
    }.getType();
    for (Stage stage : actionDB.getAllStages(response.getRequestId())) {
        Map<String, String> commandParamsStage = StageUtils.getGson().fromJson(stage.getCommandParamsStage(),
                type);
        Assert.assertTrue(commandParamsStage.containsKey("test"));
    }
}

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

public void testSaveLoanForInvalidConnection() throws Exception {
    createInitialCustomers();//  ww w  .  j  a v  a 2 s .  c  om
    LoanOfferingBO loanOffering = createLoanOffering(false);
    List<FeeView> feeViews = getFeeViews();

    LoanBO loan = loanDao.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, feeViews, null, DOUBLE_ZERO, DOUBLE_ZERO, SHORT_ZERO, SHORT_ZERO, false);
    TestObjectFactory.simulateInvalidConnection();
    try {
        loan.save();
        Assert.fail();
    } catch (AccountException e) {
        Assert.assertTrue(true);
    } finally {
        StaticHibernateUtil.closeSession();
    }
    deleteFee(feeViews);
    TestObjectFactory.removeObject(loanOffering);
}

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

public void testCreateLoanAccountWithDecliningInterestNoGracePeriod() throws Exception {
    Date startDate = new Date(System.currentTimeMillis());

    MeetingBO meeting = TestObjectFactory
            .createMeeting(TestObjectFactory.getNewMeetingForToday(WEEKLY, EVERY_WEEK, CUSTOMER_MEETING));
    center = TestObjectFactory.createWeeklyFeeCenter(this.getClass().getSimpleName() + " Center", meeting);
    group = TestObjectFactory.createWeeklyFeeGroupUnderCenter(this.getClass().getSimpleName() + " Group",
            CustomerStatus.GROUP_ACTIVE, center);
    LoanOfferingBO loanOffering = TestObjectFactory.createLoanOffering("Loan", "L", ApplicableTo.GROUPS,
            startDate, PrdStatus.LOAN_ACTIVE, 300.0, 12.0, (short) 3, InterestType.DECLINING, false, false,
            center.getCustomerMeeting().getMeeting(), GraceType.NONE, "1", "1");
    List<FeeView> feeViewList = new ArrayList<FeeView>();

    accountBO = loanDao.createLoan(TestUtils.makeUser(), loanOffering, group,
            AccountState.LOAN_ACTIVE_IN_GOOD_STANDING, new Money(getCurrency(), "300.0"), Short.valueOf("6"),
            startDate, false, // 6
            // installments
            12.0, (short) 0, null, feeViewList, null, DOUBLE_ZERO, DOUBLE_ZERO, SHORT_ZERO, SHORT_ZERO, false);
    new TestObjectPersistence().persist(accountBO);
    Assert.assertEquals(6, accountBO.getAccountActionDates().size());

    Map<String, String> fees0 = new HashMap<String, String>();

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

    checkLoanScheduleEntity(incrementCurrentDate(7 * 1), "50.3", "0.7", fees0, paymentsArray[0]);

    checkLoanScheduleEntity(incrementCurrentDate(7 * 2), "50.4", "0.6", fees0, paymentsArray[1]);

    checkLoanScheduleEntity(incrementCurrentDate(7 * 3), "50.5", "0.5", fees0, paymentsArray[2]);

    checkLoanScheduleEntity(incrementCurrentDate(7 * 4), "50.6", "0.4", fees0, paymentsArray[3]);

    checkLoanScheduleEntity(incrementCurrentDate(7 * 5), "50.7", "0.3", fees0, paymentsArray[4]);

    checkLoanScheduleEntity(incrementCurrentDate(7 * 6), "47.5", "0.5", fees0, paymentsArray[5]);

    LoanSummaryEntity loanSummaryEntity = ((LoanBO) accountBO).getLoanSummary();

    Assert.assertEquals(new Money(getCurrency(), "300.0"), loanSummaryEntity.getOriginalPrincipal());

}

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

/**
 * Check amount of the account fee in the installment. Note that this only
 * works correctly if the installment has just one account fee.
 *///from   www  . j a  v a2  s .c om
/*
 * private void assertOneInstallmentFee (Money expected, LoanScheduleEntity
 * installment) { Set<AccountFeesActionDetailEntity> actionDetails =
 * installment.getAccountFeesActionDetails(); for
 * (AccountFeesActionDetailEntity detail : actionDetails)
 * {Assert.assertEquals (expected, detail.getFeeAmount()); } }
 *
 * private void assertInstallmentDetails (LoanScheduleEntity installment,
 * Double principal, Double interest, Double accountFee, Double miscFee,
 * Double miscPenalty) {Assert.assertEquals(new Money(getCurrency(),
 * principal.toString()),
 * installment.getPrincipalDue());Assert.assertEquals(new
 * Money(interest.toString()), installment.getInterestDue());
 * Assert.assertEquals(new Money(getCurrency(), miscFee.toString()),
 * installment.getMiscFeeDue());Assert.assertEquals(new Money(getCurrency(),
 * miscPenalty.toString()), installment.getMiscPenaltyDue());
 * assertOneInstallmentFee(new Money(accountFee.toString()), installment); }
 */
public void testCreateLoanAccountWithDecliningInterestWithFeesNoGracePeriod() throws Exception {
    Date startDate = new Date(System.currentTimeMillis());

    MeetingBO meeting = TestObjectFactory
            .createMeeting(TestObjectFactory.getNewMeetingForToday(WEEKLY, EVERY_WEEK, CUSTOMER_MEETING));
    center = TestObjectFactory.createWeeklyFeeCenter(this.getClass().getSimpleName() + " Center", meeting);
    group = TestObjectFactory.createWeeklyFeeGroupUnderCenter(this.getClass().getSimpleName() + " Group",
            CustomerStatus.GROUP_ACTIVE, center);
    LoanOfferingBO loanOffering = TestObjectFactory.createLoanOffering("Loan", "L", ApplicableTo.GROUPS,
            startDate, PrdStatus.LOAN_ACTIVE, 300.0, 12.0, (short) 3, InterestType.DECLINING, false, false,
            center.getCustomerMeeting().getMeeting(), GraceType.NONE, "1", "1");

    FeeBO fee = TestObjectFactory.createPeriodicRateFee("Periodic Rate Fee", FeeCategory.LOAN,
            new Double("9.0"), FeeFormula.INTEREST, RecurrenceType.WEEKLY, new Short("1"), userContext,
            meeting);
    feeViews.add(new FeeView(userContext, fee));
    StaticHibernateUtil.commitTransaction();
    StaticHibernateUtil.closeSession();

    accountBO = loanDao.createLoan(TestUtils.makeUser(), loanOffering, group,
            AccountState.LOAN_ACTIVE_IN_GOOD_STANDING, new Money(getCurrency(), "300.0"), Short.valueOf("6"),
            startDate, false, // 6
            12.0, (short) 0, null, feeViews, null, DOUBLE_ZERO, DOUBLE_ZERO, SHORT_ZERO, SHORT_ZERO, false);
    new TestObjectPersistence().persist(accountBO);
    Assert.assertEquals(6, accountBO.getAccountActionDates().size());

    LoanBO loan = (LoanBO) accountBO;
    loan.applyCharge(Short.valueOf(AccountConstants.MISC_FEES), 2.0);
    loan.applyCharge(Short.valueOf(AccountConstants.MISC_PENALTY), 10.0);

    Set<AccountActionDateEntity> actionDateEntities = loan.getAccountActionDates();
    LoanScheduleEntity[] sortedInstallments = LoanBOTestUtils
            .getSortedAccountActionDateEntity(actionDateEntities);
    LoanTestUtils.assertInstallmentDetails(sortedInstallments[0], 50.0, 0.7, 0.3, 2.0, 10.0);
    LoanTestUtils.assertInstallmentDetails(sortedInstallments[1], 50.1, 0.6, 0.3, 0.0, 0.0);
    LoanTestUtils.assertInstallmentDetails(sortedInstallments[2], 50.2, 0.5, 0.3, 0.0, 0.0);
    LoanTestUtils.assertInstallmentDetails(sortedInstallments[3], 50.3, 0.4, 0.3, 0.0, 0.0);
    LoanTestUtils.assertInstallmentDetails(sortedInstallments[4], 50.4, 0.3, 0.3, 0.0, 0.0);
    LoanTestUtils.assertInstallmentDetails(sortedInstallments[5], 49.0, 0.1, -0.1, 0.0, 0.0);

    /*
     * HashMap fees0 = new HashMap();
     *
     * Set<AccountActionDateEntity> actionDateEntities = ((LoanBO)
     * accountBO) .getAccountActionDates(); LoanScheduleEntity[]
     * paymentsArray =
     * LoanBOTestUtils.getSortedAccountActionDateEntity(actionDateEntities);
     *
     * checkLoanScheduleEntity(incrementCurrentDate(7 * 1), "50.0", "0.7",
     * fees0, paymentsArray[0]); assertOneInstallmentFee(new
     * Money(getCurrency(), "0.3"), paymentsArray[0]);
     *
     * checkLoanScheduleEntity(incrementCurrentDate(7 * 2), "50.1", "0.6",
     * fees0, paymentsArray[1]); assertOneInstallmentFee(new
     * Money(getCurrency(), "0.3"), paymentsArray[1]);
     *
     * checkLoanScheduleEntity(incrementCurrentDate(7 * 3), "50.2", "0.5",
     * fees0, paymentsArray[2]); assertOneInstallmentFee(new
     * Money(getCurrency(), "0.3"), paymentsArray[2]);
     *
     * checkLoanScheduleEntity(incrementCurrentDate(7 * 4), "50.3", "0.4",
     * fees0, paymentsArray[3]); assertOneInstallmentFee(new
     * Money(getCurrency(), "0.3"), paymentsArray[3]);
     *
     * checkLoanScheduleEntity(incrementCurrentDate(7 * 5), "50.4", "0.3",
     * fees0, paymentsArray[4]); assertOneInstallmentFee(new
     * Money(getCurrency(), "0.3"), paymentsArray[4]);
     *
     * checkLoanScheduleEntity(incrementCurrentDate(7 * 6), "49.0", "0.1",
     * fees0, paymentsArray[5]); assertOneInstallmentFee(new
     * Money(getCurrency(), "-0.1"), paymentsArray[5]);
     *
     * LoanSummaryEntity loanSummaryEntity = ((LoanBO) accountBO)
     * .getLoanSummary();
     *
     * Assert.assertEquals(new Money(getCurrency(), "300.0"),
     * loanSummaryEntity .getOriginalPrincipal());
     */
}

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

public void testCreateLoanAccountWithZeroFlatInterest() throws Exception {
    Date startDate = new Date(System.currentTimeMillis());

    MeetingBO meeting = TestObjectFactory.createMeeting(
            TestObjectFactory.getNewMeetingForToday(WEEKLY, EVERY_SECOND_WEEK, CUSTOMER_MEETING));
    center = TestObjectFactory.createWeeklyFeeCenter(this.getClass().getSimpleName() + " Center", meeting);
    group = TestObjectFactory.createWeeklyFeeGroupUnderCenter(this.getClass().getSimpleName() + " Group",
            CustomerStatus.GROUP_ACTIVE, center);
    LoanOfferingBO loanOffering = TestObjectFactory.createLoanOffering("Loan", "L", ApplicableTo.GROUPS,
            startDate, PrdStatus.LOAN_ACTIVE, 300.0, 0.0, (short) 3, InterestType.FLAT, false, false,
            center.getCustomerMeeting().getMeeting(), GraceType.NONE, "1", "1");
    List<FeeView> feeViewList = new ArrayList<FeeView>();

    accountBO = loanDao.createLoan(TestUtils.makeUser(), loanOffering, group,
            AccountState.LOAN_ACTIVE_IN_GOOD_STANDING, new Money(getCurrency(), "300.0"), Short.valueOf("6"),
            startDate, false, 0.0, (short) 0, null, feeViewList, null, DOUBLE_ZERO, DOUBLE_ZERO, SHORT_ZERO,
            SHORT_ZERO, false);/* w  w w.j av  a  2  s  .co  m*/
    new TestObjectPersistence().persist(accountBO);
    Assert.assertEquals(6, accountBO.getAccountActionDates().size());

    Map<String, String> fees0 = new HashMap<String, String>();

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

    checkLoanScheduleEntity(incrementCurrentDate(14 * 1), "50.0", "0.0", fees0, paymentsArray[0]);

    checkLoanScheduleEntity(incrementCurrentDate(14 * 2), "50.0", "0.0", fees0, paymentsArray[1]);

    checkLoanScheduleEntity(incrementCurrentDate(14 * 3), "50.0", "0.0", fees0, paymentsArray[2]);

    checkLoanScheduleEntity(incrementCurrentDate(14 * 4), "50.0", "0.0", fees0, paymentsArray[3]);

    checkLoanScheduleEntity(incrementCurrentDate(14 * 5), "50.0", "0.0", fees0, paymentsArray[4]);

    checkLoanScheduleEntity(incrementCurrentDate(14 * 6), "50.0", "0.0", fees0, paymentsArray[5]);

    LoanSummaryEntity loanSummaryEntity = ((LoanBO) accountBO).getLoanSummary();

    Assert.assertEquals(new Money(getCurrency(), "300.0"), loanSummaryEntity.getOriginalPrincipal());

}

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

public void testCreateLoanAccountWithZeroDecliningInterest() throws Exception {
    Date startDate = new Date(System.currentTimeMillis());

    MeetingBO meeting = TestObjectFactory.createMeeting(
            TestObjectFactory.getNewMeetingForToday(WEEKLY, EVERY_SECOND_WEEK, CUSTOMER_MEETING));
    center = TestObjectFactory.createWeeklyFeeCenter(this.getClass().getSimpleName() + " Center", meeting);
    group = TestObjectFactory.createWeeklyFeeGroupUnderCenter(this.getClass().getSimpleName() + " Group",
            CustomerStatus.GROUP_ACTIVE, center);
    LoanOfferingBO loanOffering = TestObjectFactory.createLoanOffering("Loan", "L", ApplicableTo.GROUPS,
            startDate, PrdStatus.LOAN_ACTIVE, 300.0, 0.0, (short) 3, InterestType.DECLINING, false, false,
            center.getCustomerMeeting().getMeeting(), GraceType.NONE, "1", "1");
    List<FeeView> feeViewList = new ArrayList<FeeView>();

    accountBO = loanDao.createLoan(TestUtils.makeUser(), loanOffering, group,
            AccountState.LOAN_ACTIVE_IN_GOOD_STANDING, new Money(getCurrency(), "300.0"), Short.valueOf("6"),
            startDate, false, 0.0, (short) 0, null, feeViewList, null, DOUBLE_ZERO, DOUBLE_ZERO, SHORT_ZERO,
            SHORT_ZERO, false);/*w  w w.  j  a  v a  2 s  .  c  o  m*/
    new TestObjectPersistence().persist(accountBO);
    Assert.assertEquals(6, accountBO.getAccountActionDates().size());

    Map<String, String> fees0 = new HashMap<String, String>();

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

    checkLoanScheduleEntity(incrementCurrentDate(14 * 1), "50.0", "0.0", fees0, paymentsArray[0]);

    checkLoanScheduleEntity(incrementCurrentDate(14 * 2), "50.0", "0.0", fees0, paymentsArray[1]);

    checkLoanScheduleEntity(incrementCurrentDate(14 * 3), "50.0", "0.0", fees0, paymentsArray[2]);

    checkLoanScheduleEntity(incrementCurrentDate(14 * 4), "50.0", "0.0", fees0, paymentsArray[3]);

    checkLoanScheduleEntity(incrementCurrentDate(14 * 5), "50.0", "0.0", fees0, paymentsArray[4]);

    checkLoanScheduleEntity(incrementCurrentDate(14 * 6), "50.0", "0.0", fees0, paymentsArray[5]);

    LoanSummaryEntity loanSummaryEntity = ((LoanBO) accountBO).getLoanSummary();

    Assert.assertEquals(new Money(getCurrency(), "300.0"), loanSummaryEntity.getOriginalPrincipal());

}

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

public void testCreateLoanAccountWithDecliningInterestGraceAllRepayments() throws Exception {

    short graceDuration = (short) 2;
    MeetingBO meeting = TestObjectFactory.createMeeting(
            TestObjectFactory.getNewMeetingForToday(WEEKLY, EVERY_SECOND_WEEK, CUSTOMER_MEETING));
    center = TestObjectFactory.createWeeklyFeeCenter(this.getClass().getSimpleName() + " Center", meeting);
    group = TestObjectFactory.createWeeklyFeeGroupUnderCenter(this.getClass().getSimpleName() + " Group",
            CustomerStatus.GROUP_ACTIVE, center);
    LoanOfferingBO loanOffering = TestObjectFactory.createLoanOffering("Loan", ApplicableTo.GROUPS,
            new Date(System.currentTimeMillis()), PrdStatus.LOAN_ACTIVE, 300.0, 12.0, (short) 3,
            InterestType.DECLINING, center.getCustomerMeeting().getMeeting());
    List<FeeView> feeViewList = new ArrayList<FeeView>();

    accountBO = loanDao.createLoan(TestUtils.makeUser(), loanOffering, group,
            AccountState.LOAN_ACTIVE_IN_GOOD_STANDING, new Money(getCurrency(), "300.0"), Short.valueOf("6"),
            new Date(System.currentTimeMillis()), false, // 6 installments
            12.0, graceDuration, null, feeViewList, null, DOUBLE_ZERO, DOUBLE_ZERO, SHORT_ZERO, SHORT_ZERO,
            false);//  w w w  .j ava  2 s . c  o m
    new TestObjectPersistence().persist(accountBO);
    Assert.assertEquals(6, accountBO.getAccountActionDates().size());
    Map<String, String> fees0 = new HashMap<String, String>();

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

    checkLoanScheduleEntity(incrementCurrentDate(14 * (1 + graceDuration)), "49.6", "1.4", fees0,
            paymentsArray[0]);

    checkLoanScheduleEntity(incrementCurrentDate(14 * (2 + graceDuration)), "49.8", "1.2", fees0,
            paymentsArray[1]);

    checkLoanScheduleEntity(incrementCurrentDate(14 * (3 + graceDuration)), "50.0", "1.0", fees0,
            paymentsArray[2]);

    checkLoanScheduleEntity(incrementCurrentDate(14 * (4 + graceDuration)), "50.3", "0.7", fees0,
            paymentsArray[3]);

    checkLoanScheduleEntity(incrementCurrentDate(14 * (5 + graceDuration)), "50.5", "0.5", fees0,
            paymentsArray[4]);

    checkLoanScheduleEntity(incrementCurrentDate(14 * (6 + graceDuration)), "49.8", "0.2", fees0,
            paymentsArray[5]);

    LoanSummaryEntity loanSummaryEntity = ((LoanBO) accountBO).getLoanSummary();
    Assert.assertEquals(new Money(getCurrency(), "300.0"), loanSummaryEntity.getOriginalPrincipal());

}