Search in sources :

Example 36 with MifosConfigurationManager

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

the class AccountingRulesTest method testGetDigitsAfterDecimalMultiple.

@Test
public void testGetDigitsAfterDecimalMultiple() {
    MifosConfigurationManager configMgr = MifosConfigurationManager.getInstance();
    Short digitsAfterDecimalSaved = AccountingRules.getDigitsAfterDecimal();
    try {
        checkDigitsAfterDecimalMultiple(2, "0.01");
        checkDigitsAfterDecimalMultiple(1, "0.1");
        checkDigitsAfterDecimalMultiple(0, "1");
        checkDigitsAfterDecimalMultiple(-1, "10");
        checkDigitsAfterDecimalMultiple(-2, "100");
    } finally {
        configMgr.setProperty(AccountingRulesConstants.DIGITS_AFTER_DECIMAL, digitsAfterDecimalSaved);
    }
}
Also used : MifosConfigurationManager(org.mifos.config.business.MifosConfigurationManager) Test(org.junit.Test)

Example 37 with MifosConfigurationManager

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

the class AccountingRulesTest method testGetFinalRoundOffMultiple.

@Test
public void testGetFinalRoundOffMultiple() {
    BigDecimal configuredRoundOffMultiple = AccountingRules.getFinalRoundOffMultiple();
    String roundOffMultiple = "1";
    MifosConfigurationManager configMgr = MifosConfigurationManager.getInstance();
    configMgr.setProperty(AccountingRulesConstants.FINAL_ROUND_OFF_MULTIPLE, roundOffMultiple);
    // return value from accounting rules class has to be the value defined
    // in the config file
    assertEquals(new BigDecimal(roundOffMultiple), AccountingRules.getFinalRoundOffMultiple());
    // clear the RoundingRule property from the config file
    configMgr.clearProperty(AccountingRulesConstants.FINAL_ROUND_OFF_MULTIPLE);
    BigDecimal defaultValue = AccountingRules.getFinalRoundOffMultiple();
    assertEquals(defaultValue, new BigDecimal("1"));
    // save it back
    configMgr.addProperty(AccountingRulesConstants.FINAL_ROUND_OFF_MULTIPLE, configuredRoundOffMultiple.toString());
}
Also used : BigDecimal(java.math.BigDecimal) MifosConfigurationManager(org.mifos.config.business.MifosConfigurationManager) Test(org.junit.Test)

Example 38 with MifosConfigurationManager

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

the class ClientRulesIntegrationTest method testGetGroupCanApplyLoans.

@Test
public void testGetGroupCanApplyLoans() throws Exception {
    MifosConfigurationManager configMgr = MifosConfigurationManager.getInstance();
    ConfigurationPersistence configPersistence = new ConfigurationPersistence();
    ConfigurationKeyValue savedDBValue = null;
    savedDBValue = configPersistence.getConfigurationKeyValue(ClientRules.GroupCanApplyLoansKey);
    Boolean savedValue = ClientRules.getGroupCanApplyLoans();
    configMgr.setProperty(ClientRules.ClientRulesGroupCanApplyLoans, false);
    configPersistence.updateConfigurationKeyValueInteger(ClientRules.GroupCanApplyLoansKey, Constants.NO);
    ClientRules.refresh();
    // set db value to false, too
    Assert.assertFalse(ClientRules.getGroupCanApplyLoans());
    // now the return value from accounting rules class has to be what is in
    // the database (0)
    ClientRules.refresh();
    Assert.assertFalse(ClientRules.getGroupCanApplyLoans());
    // set the saved value back for following tests
    configPersistence.updateConfigurationKeyValueInteger(ClientRules.GroupCanApplyLoansKey, Integer.parseInt(savedDBValue.getValue()));
    configMgr.setProperty(ClientRules.ClientRulesGroupCanApplyLoans, savedValue);
    ClientRules.refresh();
}
Also used : ConfigurationPersistence(org.mifos.config.persistence.ConfigurationPersistence) ConfigurationKeyValue(org.mifos.config.business.ConfigurationKeyValue) MifosConfigurationManager(org.mifos.config.business.MifosConfigurationManager) Test(org.junit.Test)

Example 39 with MifosConfigurationManager

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

the class ClientRulesIntegrationTest method testClientCanExistOutsideGroup.

@Test
public void testClientCanExistOutsideGroup() throws Exception {
    MifosConfigurationManager configMgr = MifosConfigurationManager.getInstance();
    ConfigurationPersistence configPersistence = new ConfigurationPersistence();
    ConfigurationKeyValue savedDBValue = null;
    savedDBValue = configPersistence.getConfigurationKeyValue(ClientRules.ClientCanExistOutsideGroupKey);
    Boolean savedValue = ClientRules.getClientCanExistOutsideGroup();
    configMgr.setProperty(ClientRules.ClientRulesClientCanExistOutsideGroup, false);
    configPersistence.updateConfigurationKeyValueInteger(ClientRules.ClientCanExistOutsideGroupKey, Constants.NO);
    ClientRules.refresh();
    // set db value to false, too
    Assert.assertFalse(ClientRules.getClientCanExistOutsideGroup());
    // now the return value from accounting rules class has to be what is in
    // the database (0)
    ClientRules.refresh();
    Assert.assertFalse(ClientRules.getClientCanExistOutsideGroup());
    // set the saved value back for following tests
    configPersistence.updateConfigurationKeyValueInteger(ClientRules.ClientCanExistOutsideGroupKey, Integer.parseInt(savedDBValue.getValue()));
    configMgr.setProperty(ClientRules.ClientRulesClientCanExistOutsideGroup, savedValue);
    ClientRules.refresh();
}
Also used : ConfigurationPersistence(org.mifos.config.persistence.ConfigurationPersistence) ConfigurationKeyValue(org.mifos.config.business.ConfigurationKeyValue) MifosConfigurationManager(org.mifos.config.business.MifosConfigurationManager) Test(org.junit.Test)

Example 40 with MifosConfigurationManager

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

the class AccountingRulesTest method testGetCurrencyRoundingMode.

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

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