Search in sources :

Example 41 with MifosConfigurationManager

use of org.mifos.config.business.MifosConfigurationManager in project head by mifos.

the class AccountingRulesTest method testGetFinalRoundingMode.

@Test
public void testGetFinalRoundingMode() {
    RoundingMode configuredMode = AccountingRules.getFinalRoundingMode();
    String roundingMode = "CEILING";
    RoundingMode configRoundingMode = RoundingMode.CEILING;
    MifosConfigurationManager configMgr = MifosConfigurationManager.getInstance();
    configMgr.setProperty(AccountingRulesConstants.FINAL_ROUNDING_MODE, roundingMode);
    // return value from accounting rules class has to be the value defined
    // in the config file
    assertEquals(configRoundingMode, AccountingRules.getFinalRoundingMode());
    // clear the RoundingRule property from the config file
    configMgr.clearProperty(AccountingRulesConstants.FINAL_ROUNDING_MODE);
    RoundingMode defaultValue = AccountingRules.getFinalRoundingMode();
    assertEquals(defaultValue, RoundingMode.CEILING);
    // now set a wrong rounding mode in config
    roundingMode = "DOWN";
    configMgr.addProperty(AccountingRulesConstants.FINAL_ROUNDING_MODE, roundingMode);
    try {
        AccountingRules.getFinalRoundingMode();
        fail();
    } catch (RuntimeException e) {
        assertEquals("FinalRoundingMode defined in the config file is not CEILING, FLOOR, HALF_UP. It is " + roundingMode, e.getMessage());
    }
    // save it back
    configMgr.setProperty(AccountingRulesConstants.FINAL_ROUNDING_MODE, configuredMode.toString());
}
Also used : RoundingMode(java.math.RoundingMode) MifosConfigurationManager(org.mifos.config.business.MifosConfigurationManager) Test(org.junit.Test)

Example 42 with MifosConfigurationManager

use of org.mifos.config.business.MifosConfigurationManager in project head by mifos.

the class CustomerPersistenceIntegrationTest method testGetTotalAmountForAllClientsOfGroupForMultipleCurrencies.

/*
     * When trying to sum amounts across loans with different currencies, we should get an exception
     */
@Test
public void testGetTotalAmountForAllClientsOfGroupForMultipleCurrencies() throws Exception {
    MifosConfigurationManager configMgr = MifosConfigurationManager.getInstance();
    configMgr.setProperty(AccountingRulesConstants.ADDITIONAL_CURRENCY_CODES, TestUtils.EURO.getCurrencyCode());
    AccountBO clientAccount1;
    AccountBO clientAccount2;
    try {
        MeetingBO meeting = TestObjectFactory.createMeeting(TestObjectFactory.getTypicalMeeting());
        center = createCenter("new_center");
        group = TestObjectFactory.createWeeklyFeeGroupUnderCenter("Group", CustomerStatus.GROUP_ACTIVE, center);
        client = TestObjectFactory.createClient("client1", CustomerStatus.CLIENT_ACTIVE, group);
        clientAccount1 = getLoanAccount(client, meeting, "fdbdhgsgh", "54hg", TestUtils.RUPEE);
        clientAccount2 = getLoanAccount(client, meeting, "fasdfdsfasdf", "1qwe", TestUtils.EURO);
        try {
            customerPersistence.getTotalAmountForAllClientsOfGroup(group.getOffice().getOfficeId(), AccountState.LOAN_ACTIVE_IN_GOOD_STANDING, group.getSearchId() + ".%");
            Assert.fail("didn't get the expected CurrencyMismatchException");
        } catch (CurrencyMismatchException e) {
            // if we got here then we got the exception we were expecting
            Assert.assertNotNull(e);
        } catch (Exception e) {
            Assert.fail("didn't get the expected CurrencyMismatchException");
        }
    } finally {
        configMgr.clearProperty(AccountingRulesConstants.ADDITIONAL_CURRENCY_CODES);
    }
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) CurrencyMismatchException(org.mifos.core.CurrencyMismatchException) MeetingBO(org.mifos.application.meeting.business.MeetingBO) SystemException(org.mifos.framework.exceptions.SystemException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) CurrencyMismatchException(org.mifos.core.CurrencyMismatchException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) MifosConfigurationManager(org.mifos.config.business.MifosConfigurationManager) Test(org.junit.Test)

Example 43 with MifosConfigurationManager

use of org.mifos.config.business.MifosConfigurationManager in project head by mifos.

the class CustomerPersistenceIntegrationTest method testGetTotalAmountForGroupForMultipleCurrencies.

/*
     * When trying to sum amounts across loans with different currencies, we should get an exception
     */
@Test
public void testGetTotalAmountForGroupForMultipleCurrencies() throws Exception {
    MifosConfigurationManager configMgr = MifosConfigurationManager.getInstance();
    configMgr.setProperty(AccountingRulesConstants.ADDITIONAL_CURRENCY_CODES, TestUtils.EURO.getCurrencyCode());
    GroupBO group1;
    AccountBO account1;
    AccountBO account2;
    try {
        CustomerPersistence customerPersistence = new CustomerPersistence();
        meeting = TestObjectFactory.createMeeting(TestObjectFactory.getNewMeetingForToday(WEEKLY, EVERY_WEEK, CUSTOMER_MEETING));
        center = TestObjectFactory.createWeeklyFeeCenter("Center", meeting);
        group1 = TestObjectFactory.createWeeklyFeeGroupUnderCenter("Group1", CustomerStatus.GROUP_ACTIVE, center);
        account1 = getLoanAccount(group1, meeting, "adsfdsfsd", "3saf", TestUtils.RUPEE);
        account2 = getLoanAccount(group1, meeting, "adspp", "kkaf", TestUtils.EURO);
        try {
            customerPersistence.getTotalAmountForGroup(group1.getCustomerId(), AccountState.LOAN_ACTIVE_IN_GOOD_STANDING);
            Assert.fail("didn't get the expected CurrencyMismatchException");
        } catch (CurrencyMismatchException e) {
            // if we got here then we got the exception we were expecting
            Assert.assertNotNull(e);
        } catch (Exception e) {
            Assert.fail("didn't get the expected CurrencyMismatchException");
        }
    } finally {
        configMgr.clearProperty(AccountingRulesConstants.ADDITIONAL_CURRENCY_CODES);
    }
}
Also used : AccountBO(org.mifos.accounts.business.AccountBO) CustomerAccountBO(org.mifos.customers.business.CustomerAccountBO) CurrencyMismatchException(org.mifos.core.CurrencyMismatchException) GroupBO(org.mifos.customers.group.business.GroupBO) SystemException(org.mifos.framework.exceptions.SystemException) PersistenceException(org.mifos.framework.exceptions.PersistenceException) CurrencyMismatchException(org.mifos.core.CurrencyMismatchException) ApplicationException(org.mifos.framework.exceptions.ApplicationException) MifosConfigurationManager(org.mifos.config.business.MifosConfigurationManager) Test(org.junit.Test)

Example 44 with MifosConfigurationManager

use of org.mifos.config.business.MifosConfigurationManager in project head by mifos.

the class MoneyTest method testIsRoundedAmount.

@Test
public void testIsRoundedAmount() {
    String currencyCodeSuffix = "." + TestUtils.EURO.getCurrencyCode();
    MifosConfigurationManager configMgr = MifosConfigurationManager.getInstance();
    configMgr.setProperty(AccountingRulesConstants.DIGITS_AFTER_DECIMAL + currencyCodeSuffix, "1");
    configMgr.setProperty(AccountingRulesConstants.INITIAL_ROUND_OFF_MULTIPLE + currencyCodeSuffix, "1");
    configMgr.setProperty(AccountingRulesConstants.FINAL_ROUND_OFF_MULTIPLE + currencyCodeSuffix, "1");
    configMgr.setProperty(AccountingRulesConstants.ADDITIONAL_CURRENCY_CODES, TestUtils.EURO.getCurrencyCode());
    try {
        Assert.assertTrue(MoneyUtils.isRoundedAmount(new Money(EURO, "1")));
        Assert.assertFalse(MoneyUtils.isRoundedAmount(new Money(EURO, "1.1")));
        Money.setDefaultCurrency(RUPEE);
        Assert.assertFalse(MoneyUtils.isRoundedAmount(1.1));
    } finally {
        configMgr.clearProperty(AccountingRulesConstants.DIGITS_AFTER_DECIMAL + currencyCodeSuffix);
        configMgr.clearProperty(AccountingRulesConstants.INITIAL_ROUND_OFF_MULTIPLE + currencyCodeSuffix);
        configMgr.clearProperty(AccountingRulesConstants.FINAL_ROUND_OFF_MULTIPLE + currencyCodeSuffix);
        configMgr.clearProperty(AccountingRulesConstants.ADDITIONAL_CURRENCY_CODES);
    }
}
Also used : MifosConfigurationManager(org.mifos.config.business.MifosConfigurationManager) Test(org.junit.Test)

Example 45 with MifosConfigurationManager

use of org.mifos.config.business.MifosConfigurationManager in project head by mifos.

the class StandardTestingService method setProcessFlow.

@Override
public void setProcessFlow(String processFlowParamName, String processFlowParamValue) throws MifosException {
    MifosConfigurationManager configMgr = MifosConfigurationManager.getInstance();
    if (processFlowParamValue == null || processFlowParamValue.equals("")) {
        configMgr.clearProperty(processFlowParamName);
        return;
    }
    configMgr.setProperty(processFlowParamName, processFlowParamValue);
}
Also used : MifosConfigurationManager(org.mifos.config.business.MifosConfigurationManager)

Aggregations

MifosConfigurationManager (org.mifos.config.business.MifosConfigurationManager)66 Test (org.junit.Test)18 ConfigurationException (org.mifos.config.exceptions.ConfigurationException)8 Properties (java.util.Properties)5 MifosRuntimeException (org.mifos.core.MifosRuntimeException)5 PersistenceException (org.mifos.framework.exceptions.PersistenceException)5 ApplicationException (org.mifos.framework.exceptions.ApplicationException)4 RoundingMode (java.math.RoundingMode)3 ConfigurationPersistence (org.mifos.config.persistence.ConfigurationPersistence)3 CustomerAccountBO (org.mifos.customers.business.CustomerAccountBO)3 SystemException (org.mifos.framework.exceptions.SystemException)3 BigDecimal (java.math.BigDecimal)2 Ignore (org.junit.Ignore)2 AccountBO (org.mifos.accounts.business.AccountBO)2 SavingsBO (org.mifos.accounts.savings.business.SavingsBO)2 ConfigurationKeyValue (org.mifos.config.business.ConfigurationKeyValue)2 CurrencyMismatchException (org.mifos.core.CurrencyMismatchException)2 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1