junit test case fixes

This commit is contained in:
pramod
2016-01-20 16:04:32 +05:30
parent 4caeecfeb9
commit 10fd3f8978
4 changed files with 91 additions and 68 deletions
@@ -546,18 +546,24 @@ public class ClientSavingsIntegrationTest {
cal.set(Calendar.YEAR, (Integer) dates.get(0));
cal.set(Calendar.MONTH, (Integer) dates.get(1) - 1);
cal.set(Calendar.DAY_OF_MONTH, (Integer) dates.get(2));
int n = 0;
Calendar current = Calendar.getInstance();
while (cal.compareTo(current) < 0) {
n++;
cal.set(Calendar.YEAR, (Integer) dates.get(0) + n);
}
cal.set(Calendar.YEAR, (Integer) dates.get(0));
cal.set(Calendar.MONTH, (Integer) dates.get(1) - 1);
cal.set(Calendar.DAY_OF_MONTH, (Integer) dates.get(2));
this.savingsAccountHelper.payCharge((Integer) savingsChargeForPay.get("id"), savingsId,
((Float) savingsChargeForPay.get("amount")).toString(), sdf.format(cal.getTime()));
HashMap paidCharge = this.savingsAccountHelper.getSavingsCharge(savingsId, (Integer) savingsChargeForPay.get("id"));
assertEquals(savingsChargeForPay.get("amount"), paidCharge.get("amountPaid"));
// temporary fix, this test case needs to be re-factored (will fail
// again on Jan 15 2016)
cal.set(Calendar.YEAR, (Integer) dates.get(0) + 1);
this.savingsAccountHelper.payCharge((Integer) savingsChargeForPay.get("id"), savingsId,
((Float) savingsChargeForPay.get("amount")).toString(), sdf.format(cal.getTime()));
paidCharge = this.savingsAccountHelper.getSavingsCharge(savingsId, (Integer) savingsChargeForPay.get("id"));
for (int i = 1; i <= n; i++) {
this.savingsAccountHelper.payCharge((Integer) savingsChargeForPay.get("id"), savingsId,
((Float) savingsChargeForPay.get("amount")).toString(), sdf.format(cal.getTime()));
HashMap paidCharge = this.savingsAccountHelper.getSavingsCharge(savingsId, (Integer) savingsChargeForPay.get("id"));
Float expectedValue = (Float) savingsChargeForPay.get("amount") * i;
assertEquals(expectedValue, paidCharge.get("amountPaid"));
cal.set(Calendar.YEAR, (Integer) dates.get(0) + i);
}
Integer inactivatedChargeId = (Integer) this.savingsAccountHelper.inactivateCharge(annualSavingsChargeId, savingsId,
CommonConstants.RESPONSE_RESOURCE_ID);
@@ -618,7 +624,7 @@ public class ClientSavingsIntegrationTest {
this.savingsAccountHelper.payCharge((Integer) savingsChargeForPay.get("id"), savingsId,
((Float) savingsChargeForPay.get("amount")).toString(), sdf.format(cal.getTime()));
paidCharge = this.savingsAccountHelper.getSavingsCharge(savingsId, (Integer) savingsChargeForPay.get("id"));
HashMap paidCharge = this.savingsAccountHelper.getSavingsCharge(savingsId, (Integer) savingsChargeForPay.get("id"));
assertEquals(savingsChargeForPay.get("amount"), paidCharge.get("amountPaid"));
List nextDueDates = (List) paidCharge.get("dueDate");
LocalDate nextDueDate = new LocalDate((Integer) nextDueDates.get(0), (Integer) nextDueDates.get(1), (Integer) nextDueDates.get(2));
@@ -516,6 +516,10 @@ public class GroupSavingsIntegrationTest {
LocalDate expectedNextDueDate = new LocalDate((Integer) dates.get(0), (Integer) dates.get(1), (Integer) dates.get(2))
.plusWeeks((Integer) paidCharge.get("feeInterval"));
assertEquals(expectedNextDueDate, nextDueDate);
cal = Calendar.getInstance();
this.savingsAccountHelper.closeSavingsAccountAndGetBackRequiredField(savingsId, "true", null, sdf.format(cal.getTime()));
}
public static Integer createSavingsProduct(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
@@ -302,6 +302,7 @@ public class Loan extends AbstractPersistable<Long> {
// see
// http://stackoverflow.com/questions/4334970/hibernate-cannot-simultaneously-fetch-multiple-bags
@LazyCollection(LazyCollectionOption.FALSE)
@OrderBy(value = "installmentNumber")
@OneToMany(cascade = CascadeType.ALL, mappedBy = "loan", orphanRemoval = true)
private final List<LoanRepaymentScheduleInstallment> repaymentScheduleInstallments = new ArrayList<>();
@@ -310,7 +310,7 @@ public class SavingsAccount extends AbstractPersistable<Long> {
final Integer lockinPeriodFrequency, final SavingsPeriodFrequencyType lockinPeriodFrequencyType,
final boolean withdrawalFeeApplicableForTransfer, final Set<SavingsAccountCharge> savingsAccountCharges,
final boolean allowOverdraft, final BigDecimal overdraftLimit, final boolean enforceMinRequiredBalance,
final BigDecimal minRequiredBalance, final BigDecimal nominalAnnualInterestRateOverdraft,
final BigDecimal minRequiredBalance, final BigDecimal nominalAnnualInterestRateOverdraft,
final BigDecimal minOverdraftForInterestCalculation) {
final SavingsAccountStatusType status = SavingsAccountStatusType.SUBMITTED_AND_PENDING_APPROVAL;
@@ -345,7 +345,7 @@ public class SavingsAccount extends AbstractPersistable<Long> {
final Integer lockinPeriodFrequency, final SavingsPeriodFrequencyType lockinPeriodFrequencyType,
final boolean withdrawalFeeApplicableForTransfer, final Set<SavingsAccountCharge> savingsAccountCharges,
final boolean allowOverdraft, final BigDecimal overdraftLimit, final boolean enforceMinRequiredBalance,
final BigDecimal minRequiredBalance, final BigDecimal nominalAnnualInterestRateOverdraft,
final BigDecimal minRequiredBalance, final BigDecimal nominalAnnualInterestRateOverdraft,
final BigDecimal minOverdraftForInterestCalculation) {
this.client = client;
this.group = group;
@@ -457,33 +457,33 @@ public class SavingsAccount extends AbstractPersistable<Long> {
final SavingsAccountTransaction postingTransaction = findInterestPostingTransactionFor(interestPostingTransactionDate);
if (postingTransaction == null) {
SavingsAccountTransaction newPostingTransaction;
if(interestEarnedToBePostedForPeriod.isGreaterThanOrEqualTo(Money.zero(currency))){
newPostingTransaction = SavingsAccountTransaction.interestPosting(this, office(),
interestPostingTransactionDate, interestEarnedToBePostedForPeriod);
}else{
newPostingTransaction = SavingsAccountTransaction.overdraftInterest(this, office(),
interestPostingTransactionDate, interestEarnedToBePostedForPeriod.negated());
}
SavingsAccountTransaction newPostingTransaction;
if (interestEarnedToBePostedForPeriod.isGreaterThanOrEqualTo(Money.zero(currency))) {
newPostingTransaction = SavingsAccountTransaction.interestPosting(this, office(), interestPostingTransactionDate,
interestEarnedToBePostedForPeriod);
} else {
newPostingTransaction = SavingsAccountTransaction.overdraftInterest(this, office(), interestPostingTransactionDate,
interestEarnedToBePostedForPeriod.negated());
}
this.transactions.add(newPostingTransaction);
recalucateDailyBalanceDetails = true;
} else {
boolean correctionRequired = false;
if(postingTransaction.isInterestPostingAndNotReversed()){
correctionRequired = postingTransaction.hasNotAmount(interestEarnedToBePostedForPeriod);
}else{
correctionRequired = postingTransaction.hasNotAmount(interestEarnedToBePostedForPeriod.negated());
if (postingTransaction.isInterestPostingAndNotReversed()) {
correctionRequired = postingTransaction.hasNotAmount(interestEarnedToBePostedForPeriod);
} else {
correctionRequired = postingTransaction.hasNotAmount(interestEarnedToBePostedForPeriod.negated());
}
if (correctionRequired) {
postingTransaction.reverse();
SavingsAccountTransaction newPostingTransaction;
if(interestEarnedToBePostedForPeriod.isGreaterThanOrEqualTo(Money.zero(currency))){
SavingsAccountTransaction newPostingTransaction;
if (interestEarnedToBePostedForPeriod.isGreaterThanOrEqualTo(Money.zero(currency))) {
newPostingTransaction = SavingsAccountTransaction.interestPosting(this, office(),
interestPostingTransactionDate, interestEarnedToBePostedForPeriod);
}else{
} else {
newPostingTransaction = SavingsAccountTransaction.overdraftInterest(this, office(),
interestPostingTransactionDate, interestEarnedToBePostedForPeriod.negated());
}
}
this.transactions.add(newPostingTransaction);
recalucateDailyBalanceDetails = true;
}
@@ -510,7 +510,8 @@ public class SavingsAccount extends AbstractPersistable<Long> {
SavingsAccountTransaction postingTransation = null;
for (final SavingsAccountTransaction transaction : this.transactions) {
if ((transaction.isInterestPostingAndNotReversed() || transaction.isOverdraftInterestAndNotReversed()) && transaction.occursOn(postingDate)) {
if ((transaction.isInterestPostingAndNotReversed() || transaction.isOverdraftInterestAndNotReversed())
&& transaction.occursOn(postingDate)) {
postingTransation = transaction;
break;
}
@@ -634,10 +635,10 @@ public class SavingsAccount extends AbstractPersistable<Long> {
}
private BigDecimal getEffectiveOverdraftInterestRateAsFraction(MathContext mc) {
return this.nominalAnnualInterestRateOverdraft.divide(BigDecimal.valueOf(100l), mc);
return this.nominalAnnualInterestRateOverdraft.divide(BigDecimal.valueOf(100l), mc);
}
@SuppressWarnings("unused")
@SuppressWarnings("unused")
protected BigDecimal getEffectiveInterestRateAsFraction(final MathContext mc, final LocalDate upToInterestCalculationDate) {
return this.nominalAnnualInterestRate.divide(BigDecimal.valueOf(100l), mc);
}
@@ -648,7 +649,8 @@ public class SavingsAccount extends AbstractPersistable<Long> {
final List<SavingsAccountTransaction> orderedNonInterestPostingTransactions = new ArrayList<>();
for (final SavingsAccountTransaction transaction : listOfTransactionsSorted) {
if (!(transaction.isInterestPostingAndNotReversed() || transaction.isOverdraftInterestAndNotReversed()) && transaction.isNotReversed()) {
if (!(transaction.isInterestPostingAndNotReversed() || transaction.isOverdraftInterestAndNotReversed())
&& transaction.isNotReversed()) {
orderedNonInterestPostingTransactions.add(transaction);
}
}
@@ -727,9 +729,8 @@ public class SavingsAccount extends AbstractPersistable<Long> {
LocalDate endOfBalanceDate = interestPostingUpToDate;
for (int i = accountTransactionsSorted.size() - 1; i >= 0; i--) {
final SavingsAccountTransaction transaction = accountTransactionsSorted.get(i);
if (transaction.isNotReversed()
&& !(transaction.isInterestPostingAndNotReversed()
|| transaction.isOverdraftInterestAndNotReversed())) {
if (transaction.isNotReversed()
&& !(transaction.isInterestPostingAndNotReversed() || transaction.isOverdraftInterestAndNotReversed())) {
transaction.updateCumulativeBalanceAndDates(this.currency, endOfBalanceDate);
// this transactions transaction date is end of balance date for
// previous transaction.
@@ -888,7 +889,8 @@ public class SavingsAccount extends AbstractPersistable<Long> {
boolean transactionBeforeLastInterestPosting = false;
for (final SavingsAccountTransaction transaction : retreiveListOfTransactions()) {
if ((transaction.isInterestPostingAndNotReversed() || transaction.isOverdraftInterestAndNotReversed()) && transaction.isAfter(transactionDate)) {
if ((transaction.isInterestPostingAndNotReversed() || transaction.isOverdraftInterestAndNotReversed())
&& transaction.isAfter(transactionDate)) {
transactionBeforeLastInterestPosting = true;
break;
}
@@ -897,7 +899,8 @@ public class SavingsAccount extends AbstractPersistable<Long> {
return transactionBeforeLastInterestPosting;
}
public void validateAccountBalanceDoesNotBecomeNegative(final BigDecimal transactionAmount, final boolean isException,final List<DepositAccountOnHoldTransaction> depositAccountOnHoldTransactions) {
public void validateAccountBalanceDoesNotBecomeNegative(final BigDecimal transactionAmount, final boolean isException,
final List<DepositAccountOnHoldTransaction> depositAccountOnHoldTransactions) {
final List<SavingsAccountTransaction> transactionsSortedByDate = retreiveListOfTransactions();
Money runningBalance = Money.zero(this.currency);
Money minRequiredBalance = minRequiredBalanceDerived(getCurrency());
@@ -911,27 +914,28 @@ public class SavingsAccount extends AbstractPersistable<Long> {
continue;
}
final BigDecimal withdrawalFee = null;
/* Loop through the onHold funds and see if we need to deduct or add to minimum required balance
and the point in time the transaction was made: */
if(depositAccountOnHoldTransactions !=null){
for(final DepositAccountOnHoldTransaction onHoldTransaction: depositAccountOnHoldTransactions) {
/*
* Loop through the onHold funds and see if we need to deduct or add
* to minimum required balance and the point in time the transaction
* was made:
*/
if (depositAccountOnHoldTransactions != null) {
for (final DepositAccountOnHoldTransaction onHoldTransaction : depositAccountOnHoldTransactions) {
// Compare the balance of the on hold:
if((onHoldTransaction.getTransactionDate().isBefore(transaction.transactionLocalDate()) || onHoldTransaction.getTransactionDate().isEqual(transaction.transactionLocalDate()))
if ((onHoldTransaction.getTransactionDate().isBefore(transaction.transactionLocalDate()) || onHoldTransaction
.getTransactionDate().isEqual(transaction.transactionLocalDate()))
&& (lastSavingsDate == null || onHoldTransaction.getTransactionDate().isAfter(lastSavingsDate))) {
if(onHoldTransaction.getTransactionType().isHold()) {
if (onHoldTransaction.getTransactionType().isHold()) {
minRequiredBalance = minRequiredBalance.plus(onHoldTransaction.getAmountMoney(this.currency));
}else{
} else {
minRequiredBalance = minRequiredBalance.minus(onHoldTransaction.getAmountMoney(this.currency));
}
}
}
}
// deal with potential minRequiredBalance and
// enforceMinRequiredBalance
if (!isException && transaction.canProcessBalanceCheck()) {
@@ -943,7 +947,8 @@ public class SavingsAccount extends AbstractPersistable<Long> {
}
}
public void validateAccountBalanceDoesNotBecomeNegative(final String transactionAction,final List<DepositAccountOnHoldTransaction> depositAccountOnHoldTransactions) {
public void validateAccountBalanceDoesNotBecomeNegative(final String transactionAction,
final List<DepositAccountOnHoldTransaction> depositAccountOnHoldTransactions) {
final List<SavingsAccountTransaction> transactionsSortedByDate = retreiveListOfTransactions();
Money runningBalance = Money.zero(this.currency);
@@ -956,16 +961,20 @@ public class SavingsAccount extends AbstractPersistable<Long> {
runningBalance = runningBalance.minus(transaction.getAmount(this.currency));
}
/* Loop through the onHold funds and see if we need to deduct or add to minimum required balance
and the point in time the transaction was made: */
if(depositAccountOnHoldTransactions !=null){
for(final DepositAccountOnHoldTransaction onHoldTransaction: depositAccountOnHoldTransactions) {
/*
* Loop through the onHold funds and see if we need to deduct or add
* to minimum required balance and the point in time the transaction
* was made:
*/
if (depositAccountOnHoldTransactions != null) {
for (final DepositAccountOnHoldTransaction onHoldTransaction : depositAccountOnHoldTransactions) {
// Compare the balance of the on hold:
if((onHoldTransaction.getTransactionDate().isBefore(transaction.transactionLocalDate()) || onHoldTransaction.getTransactionDate().isEqual(transaction.transactionLocalDate()))
if ((onHoldTransaction.getTransactionDate().isBefore(transaction.transactionLocalDate()) || onHoldTransaction
.getTransactionDate().isEqual(transaction.transactionLocalDate()))
&& (lastSavingsDate == null || onHoldTransaction.getTransactionDate().isAfter(lastSavingsDate))) {
if(onHoldTransaction.getTransactionType().isHold()) {
if (onHoldTransaction.getTransactionType().isHold()) {
minRequiredBalance = minRequiredBalance.plus(onHoldTransaction.getAmountMoney(this.currency));
}else{
} else {
minRequiredBalance = minRequiredBalance.minus(onHoldTransaction.getAmountMoney(this.currency));
}
}
@@ -1172,15 +1181,19 @@ public class SavingsAccount extends AbstractPersistable<Long> {
this.overdraftLimit = newValue;
}
if (command.isChangeInBigDecimalParameterNamedDefaultingZeroToNull(nominalAnnualInterestRateOverdraftParamName, this.nominalAnnualInterestRateOverdraft)) {
final BigDecimal newValue = command.bigDecimalValueOfParameterNamedDefaultToNullIfZero(nominalAnnualInterestRateOverdraftParamName);
if (command.isChangeInBigDecimalParameterNamedDefaultingZeroToNull(nominalAnnualInterestRateOverdraftParamName,
this.nominalAnnualInterestRateOverdraft)) {
final BigDecimal newValue = command
.bigDecimalValueOfParameterNamedDefaultToNullIfZero(nominalAnnualInterestRateOverdraftParamName);
actualChanges.put(nominalAnnualInterestRateOverdraftParamName, newValue);
actualChanges.put(localeParamName, localeAsInput);
this.nominalAnnualInterestRateOverdraft = newValue;
}
if (command.isChangeInBigDecimalParameterNamedDefaultingZeroToNull(minOverdraftForInterestCalculationParamName, this.minOverdraftForInterestCalculation)) {
final BigDecimal newValue = command.bigDecimalValueOfParameterNamedDefaultToNullIfZero(minOverdraftForInterestCalculationParamName);
if (command.isChangeInBigDecimalParameterNamedDefaultingZeroToNull(minOverdraftForInterestCalculationParamName,
this.minOverdraftForInterestCalculation)) {
final BigDecimal newValue = command
.bigDecimalValueOfParameterNamedDefaultToNullIfZero(minOverdraftForInterestCalculationParamName);
actualChanges.put(minOverdraftForInterestCalculationParamName, newValue);
actualChanges.put(localeParamName, localeAsInput);
this.minOverdraftForInterestCalculation = newValue;
@@ -1208,21 +1221,20 @@ public class SavingsAccount extends AbstractPersistable<Long> {
validateLockinDetails(baseDataValidator);
esnureOverdraftLimitsSetForOverdraftAccounts();
}
/**
* If overdrafts are allowed and the overdraft limit is not set, set the
* same to Zero
**/
private void esnureOverdraftLimitsSetForOverdraftAccounts() {
if (this.allowOverdraft) {
this.overdraftLimit = this.overdraftLimit == null? BigDecimal.ZERO : this.overdraftLimit;
this.nominalAnnualInterestRateOverdraft = this.nominalAnnualInterestRateOverdraft == null? BigDecimal.ZERO : this.nominalAnnualInterestRateOverdraft;
this.minOverdraftForInterestCalculation = this.minOverdraftForInterestCalculation == null? BigDecimal.ZERO : this.minOverdraftForInterestCalculation;
}
this.overdraftLimit = this.overdraftLimit == null ? BigDecimal.ZERO : this.overdraftLimit;
this.nominalAnnualInterestRateOverdraft = this.nominalAnnualInterestRateOverdraft == null ? BigDecimal.ZERO
: this.nominalAnnualInterestRateOverdraft;
this.minOverdraftForInterestCalculation = this.minOverdraftForInterestCalculation == null ? BigDecimal.ZERO
: this.minOverdraftForInterestCalculation;
}
private void validateLockinDetails(final DataValidatorBuilder baseDataValidator) {
/*