Fix to accept Loan Charge amounts using locales (#2393)
Co-authored-by: Jose Alberto Hernandez <alberto@MacBook-Pro.local>
This commit is contained in:
co-authored by
Jose Alberto Hernandez
parent
13d587a951
commit
bd404e8c7b
+35
-1
@@ -865,6 +865,39 @@ public class ClientLoanIntegrationTest {
|
||||
validateChargeExcludePrecission(flatAccTransfer, loanCharges, "100.0", "300", "100.0", "0.0");
|
||||
validateChargeExcludePrecission(flat, loanCharges, "50.0", "150", "0.0", "50.0");
|
||||
|
||||
// Loan Charges with US Locale using the amount as a number in the JSON body
|
||||
this.loanTransactionHelper.addChargesForLoan(loanID,
|
||||
LoanTransactionHelper.getInstallmentChargesForLoanAsJSON(String.valueOf(flat), 50.05, Locale.US));
|
||||
loanCharges = this.loanTransactionHelper.getLoanCharges(loanID);
|
||||
|
||||
loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
|
||||
loanSchedule.remove(0);
|
||||
for (HashMap installment : loanSchedule) {
|
||||
validateNumberForEqualExcludePrecission("200.05", String.valueOf(installment.get("feeChargesDue")));
|
||||
}
|
||||
|
||||
// Loan Charges with other Locale using comma (,) as decimal delimiter
|
||||
this.loanTransactionHelper.addChargesForLoan(loanID,
|
||||
LoanTransactionHelper.getInstallmentChargesForLoanAsJSON(String.valueOf(flat), "50,05", Locale.GERMAN));
|
||||
loanCharges = this.loanTransactionHelper.getLoanCharges(loanID);
|
||||
|
||||
loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
|
||||
loanSchedule.remove(0);
|
||||
for (HashMap installment : loanSchedule) {
|
||||
validateNumberForEqualExcludePrecission("250.10", String.valueOf(installment.get("feeChargesDue")));
|
||||
}
|
||||
|
||||
// Loan Charges with German Locale (where the comma is the decimal delimiter) using the amount as a number in
|
||||
// the JSON body
|
||||
this.loanTransactionHelper.addChargesForLoan(loanID,
|
||||
LoanTransactionHelper.getInstallmentChargesForLoanAsJSON(String.valueOf(flat), 50.05, Locale.GERMAN));
|
||||
loanCharges = this.loanTransactionHelper.getLoanCharges(loanID);
|
||||
|
||||
loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
|
||||
loanSchedule.remove(0);
|
||||
for (HashMap installment : loanSchedule) {
|
||||
validateNumberForEqualExcludePrecission("300.15", String.valueOf(installment.get("feeChargesDue")));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1080,7 +1113,8 @@ public class ClientLoanIntegrationTest {
|
||||
private void validateNumberForEqualExcludePrecission(String val, String val2) {
|
||||
DecimalFormat twoDForm = new DecimalFormat("#");
|
||||
Assertions.assertTrue(
|
||||
Float.valueOf(twoDForm.format(Float.valueOf(val))).compareTo(Float.valueOf(twoDForm.format(Float.valueOf(val2)))) == 0);
|
||||
Float.valueOf(twoDForm.format(Float.valueOf(val))).compareTo(Float.valueOf(twoDForm.format(Float.valueOf(val2)))) == 0,
|
||||
String.format("%s is not equal to %s", val, val2));
|
||||
}
|
||||
|
||||
private Integer createLoanProduct(final boolean multiDisburseLoan, final String accountingRule, final Account... accounts) {
|
||||
|
||||
+1
-1
@@ -415,7 +415,7 @@ public final class ChargesHelper {
|
||||
public static String getModifyChargeJSON() {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("locale", CommonConstants.LOCALE);
|
||||
map.put("amount", "200.0");
|
||||
map.put("amount", 200.0);
|
||||
String json = new Gson().toJson(map);
|
||||
LOG.info("{}", json);
|
||||
return json;
|
||||
|
||||
+7
-2
@@ -33,6 +33,7 @@ import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
@@ -674,8 +675,12 @@ public class LoanTransactionHelper {
|
||||
}
|
||||
|
||||
public static String getInstallmentChargesForLoanAsJSON(final String chargeId, final String amount) {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("locale", "en_GB");
|
||||
return getInstallmentChargesForLoanAsJSON(chargeId, amount, Locale.UK);
|
||||
}
|
||||
|
||||
public static String getInstallmentChargesForLoanAsJSON(final String chargeId, final Object amount, final Locale locale) {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("locale", locale.getLanguage());
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("amount", amount);
|
||||
map.put("chargeId", chargeId);
|
||||
|
||||
Reference in New Issue
Block a user