Merge pull request #925 from lingalamadhukar/MIFOSX-1166
MIFOSX-1216 and loan integration tests with accounting
This commit is contained in:
+20
-5
@@ -3,11 +3,13 @@ package org.mifosplatform.integrationtests;
|
|||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import org.joda.time.LocalDate;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -564,7 +566,9 @@ public class AccountingScenarioIntegrationTest {
|
|||||||
System.out.println("Repayment 1 ......");
|
System.out.println("Repayment 1 ......");
|
||||||
final float FIRST_INTEREST = 200.0f;
|
final float FIRST_INTEREST = 200.0f;
|
||||||
final float FIRST_PRINCIPAL = 2000.0f;
|
final float FIRST_PRINCIPAL = 2000.0f;
|
||||||
this.loanTransactionHelper.checkAccrualTransactionForRepayment(this.REPAYMENT_DATE[1], FIRST_INTEREST, loanID);
|
final float FEE_PORTION = 0.0f;
|
||||||
|
final float PENALTY_PORTION = 0.0f;
|
||||||
|
this.loanTransactionHelper.checkAccrualTransactionForRepayment(getDateAsLocalDate(this.REPAYMENT_DATE[1]), FIRST_INTEREST, FEE_PORTION, PENALTY_PORTION, loanID);
|
||||||
this.loanTransactionHelper.makeRepayment(this.REPAYMENT_DATE[1], this.REPAYMENT_AMOUNT[1], loanID);
|
this.loanTransactionHelper.makeRepayment(this.REPAYMENT_DATE[1], this.REPAYMENT_AMOUNT[1], loanID);
|
||||||
float expected_value = this.LP_PRINCIPAL - PRINCIPAL_VALUE_FOR_EACH_PERIOD;
|
float expected_value = this.LP_PRINCIPAL - PRINCIPAL_VALUE_FOR_EACH_PERIOD;
|
||||||
this.loanTransactionHelper.verifyRepaymentScheduleEntryFor(1, expected_value, loanID);
|
this.loanTransactionHelper.verifyRepaymentScheduleEntryFor(1, expected_value, loanID);
|
||||||
@@ -580,8 +584,8 @@ public class AccountingScenarioIntegrationTest {
|
|||||||
final float SECOND_AND_THIRD_INTEREST = 400.0f;
|
final float SECOND_AND_THIRD_INTEREST = 400.0f;
|
||||||
final float SECOND_PRINCIPAL = this.REPAYMENT_AMOUNT[2] - SECOND_AND_THIRD_INTEREST;
|
final float SECOND_PRINCIPAL = this.REPAYMENT_AMOUNT[2] - SECOND_AND_THIRD_INTEREST;
|
||||||
expected_value = expected_value - PRINCIPAL_VALUE_FOR_EACH_PERIOD;
|
expected_value = expected_value - PRINCIPAL_VALUE_FOR_EACH_PERIOD;
|
||||||
this.loanTransactionHelper.checkAccrualTransactionForRepayment(this.REPAYMENT_DATE[2], FIRST_INTEREST, loanID);
|
this.loanTransactionHelper.checkAccrualTransactionForRepayment(getDateAsLocalDate(this.REPAYMENT_DATE[2]), FIRST_INTEREST, FEE_PORTION, PENALTY_PORTION, loanID);
|
||||||
this.loanTransactionHelper.checkAccrualTransactionForRepayment(this.REPAYMENT_DATE[3], FIRST_INTEREST, loanID);
|
this.loanTransactionHelper.checkAccrualTransactionForRepayment(getDateAsLocalDate(this.REPAYMENT_DATE[3]), FIRST_INTEREST, FEE_PORTION, PENALTY_PORTION, loanID);
|
||||||
this.loanTransactionHelper.verifyRepaymentScheduleEntryFor(2, expected_value, loanID);
|
this.loanTransactionHelper.verifyRepaymentScheduleEntryFor(2, expected_value, loanID);
|
||||||
final JournalEntry[] assetAccountSecondEntry = { new JournalEntry(this.REPAYMENT_AMOUNT[2], JournalEntry.TransactionType.DEBIT),
|
final JournalEntry[] assetAccountSecondEntry = { new JournalEntry(this.REPAYMENT_AMOUNT[2], JournalEntry.TransactionType.DEBIT),
|
||||||
new JournalEntry(SECOND_AND_THIRD_INTEREST, JournalEntry.TransactionType.CREDIT),
|
new JournalEntry(SECOND_AND_THIRD_INTEREST, JournalEntry.TransactionType.CREDIT),
|
||||||
@@ -591,8 +595,8 @@ public class AccountingScenarioIntegrationTest {
|
|||||||
|
|
||||||
// WAIVE INTEREST
|
// WAIVE INTEREST
|
||||||
System.out.println("Waive Interest ......");
|
System.out.println("Waive Interest ......");
|
||||||
this.loanTransactionHelper.checkAccrualTransactionForRepayment(this.REPAYMENT_DATE[4], FIRST_INTEREST, loanID);
|
this.loanTransactionHelper.checkAccrualTransactionForRepayment(getDateAsLocalDate(this.REPAYMENT_DATE[4]), FIRST_INTEREST, FEE_PORTION, PENALTY_PORTION, loanID);
|
||||||
this.loanTransactionHelper.checkAccrualTransactionForRepayment(this.REPAYMENT_DATE[5], FIRST_INTEREST, loanID);
|
this.loanTransactionHelper.checkAccrualTransactionForRepayment(getDateAsLocalDate(this.REPAYMENT_DATE[5]), FIRST_INTEREST, FEE_PORTION, PENALTY_PORTION, loanID);
|
||||||
this.loanTransactionHelper.waiveInterest(this.REPAYMENT_DATE[4], this.AMOUNT_TO_BE_WAIVE.toString(), loanID);
|
this.loanTransactionHelper.waiveInterest(this.REPAYMENT_DATE[4], this.AMOUNT_TO_BE_WAIVE.toString(), loanID);
|
||||||
|
|
||||||
final JournalEntry waivedEntry = new JournalEntry(this.AMOUNT_TO_BE_WAIVE, JournalEntry.TransactionType.CREDIT);
|
final JournalEntry waivedEntry = new JournalEntry(this.AMOUNT_TO_BE_WAIVE, JournalEntry.TransactionType.CREDIT);
|
||||||
@@ -752,4 +756,15 @@ public class AccountingScenarioIntegrationTest {
|
|||||||
.build(null);
|
.build(null);
|
||||||
return this.loanTransactionHelper.getLoanProductId(loanProductJSON);
|
return this.loanTransactionHelper.getLoanProductId(loanProductJSON);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private LocalDate getDateAsLocalDate(String dateAsString) {
|
||||||
|
LocalDate date = null;
|
||||||
|
try {
|
||||||
|
DateFormat df = new SimpleDateFormat("dd MMMM yyyy");
|
||||||
|
date = new LocalDate(df.parse(dateAsString));
|
||||||
|
} catch (ParseException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return date;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1805
-11
File diff suppressed because it is too large
Load Diff
+6
@@ -290,4 +290,10 @@ public class LoanProductTestBuilder {
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LoanProductTestBuilder withAccounting(final String accountingRule, final Account[] account_list) {
|
||||||
|
this.accountingRule = accountingRule;
|
||||||
|
this.accountList = account_list;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+4
@@ -37,6 +37,10 @@ public class LoanStatusChecker {
|
|||||||
assertFalse(getStatus(loanStatusHashMap, "active"));
|
assertFalse(getStatus(loanStatusHashMap, "active"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void verifyLoanAccountIsOverPaid(final HashMap loanStatusHashMap) {
|
||||||
|
assertTrue(getStatus(loanStatusHashMap, "overpaid"));
|
||||||
|
}
|
||||||
|
|
||||||
public static HashMap getStatusOfLoan(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
public static HashMap getStatusOfLoan(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||||
final Integer loanID) {
|
final Integer loanID) {
|
||||||
final String url = "/mifosng-provider/api/v1/loans/" + loanID + "?tenantIdentifier=default";
|
final String url = "/mifosng-provider/api/v1/loans/" + loanID + "?tenantIdentifier=default";
|
||||||
|
|||||||
+15
-17
@@ -3,9 +3,6 @@ package org.mifosplatform.integrationtests.common.loans;
|
|||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.text.DateFormat;
|
|
||||||
import java.text.ParseException;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
@@ -16,7 +13,7 @@ import com.google.gson.Gson;
|
|||||||
import com.jayway.restassured.specification.RequestSpecification;
|
import com.jayway.restassured.specification.RequestSpecification;
|
||||||
import com.jayway.restassured.specification.ResponseSpecification;
|
import com.jayway.restassured.specification.ResponseSpecification;
|
||||||
|
|
||||||
@SuppressWarnings({ "rawtypes", "unchecked", "cast" })
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
public class LoanTransactionHelper {
|
public class LoanTransactionHelper {
|
||||||
|
|
||||||
private final RequestSpecification requestSpec;
|
private final RequestSpecification requestSpec;
|
||||||
@@ -338,7 +335,8 @@ public class LoanTransactionHelper {
|
|||||||
.get("principalLoanBalanceOutstanding"));
|
.get("principalLoanBalanceOutstanding"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkAccrualTransactionForRepayment(final String transactionDate, final Float interestAmount, final Integer loanID) {
|
public void checkAccrualTransactionForRepayment(final LocalDate transactionDate, final Float interestPortion, final Float feePortion,
|
||||||
|
final Float penaltyPortion, final Integer loanID) {
|
||||||
|
|
||||||
ArrayList<HashMap> transactions = (ArrayList<HashMap>) getLoanDetail(this.requestSpec, this.responseSpec, loanID, "transactions");
|
ArrayList<HashMap> transactions = (ArrayList<HashMap>) getLoanDetail(this.requestSpec, this.responseSpec, loanID, "transactions");
|
||||||
boolean isTransactionFound = false;
|
boolean isTransactionFound = false;
|
||||||
@@ -347,19 +345,19 @@ public class LoanTransactionHelper {
|
|||||||
boolean isAccrualTransaction = (Boolean) transactionType.get("accrual");
|
boolean isAccrualTransaction = (Boolean) transactionType.get("accrual");
|
||||||
|
|
||||||
if (isAccrualTransaction) {
|
if (isAccrualTransaction) {
|
||||||
ArrayList<Integer> accrualEntryDateAsArray = (ArrayList<Integer>)transactions.get(i).get("date");
|
ArrayList<Integer> accrualEntryDateAsArray = (ArrayList<Integer>) transactions.get(i).get("date");
|
||||||
LocalDate accrualEntryDate = new LocalDate(accrualEntryDateAsArray.get(0),accrualEntryDateAsArray.get(1),accrualEntryDateAsArray.get(2));
|
LocalDate accrualEntryDate = new LocalDate(accrualEntryDateAsArray.get(0), accrualEntryDateAsArray.get(1),
|
||||||
|
accrualEntryDateAsArray.get(2));
|
||||||
|
|
||||||
try {
|
if (transactionDate.equals(accrualEntryDate)) {
|
||||||
DateFormat df = new SimpleDateFormat("dd MMMM yyyy");
|
isTransactionFound = true;
|
||||||
LocalDate expectedTransactionDate = new LocalDate(df.parse(transactionDate));
|
assertEquals("Mismatch in transaction amounts", interestPortion,
|
||||||
if (expectedTransactionDate.equals(accrualEntryDate)) {
|
Float.valueOf(String.valueOf(transactions.get(i).get("interestPortion"))));
|
||||||
isTransactionFound = true;
|
assertEquals("Mismatch in transaction amounts", feePortion,
|
||||||
assertEquals("Mismatch in transaction amounts", interestAmount, (Float) transactions.get(i).get("amount"));
|
Float.valueOf(String.valueOf(transactions.get(i).get("feeChargesPortion"))));
|
||||||
break;
|
assertEquals("Mismatch in transaction amounts", penaltyPortion,
|
||||||
}
|
Float.valueOf(String.valueOf(transactions.get(i).get("penaltyChargesPortion"))));
|
||||||
} catch (ParseException e) {
|
break;
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-5
@@ -22,7 +22,6 @@ import org.mifosplatform.infrastructure.security.service.SpringSecurityPlatformS
|
|||||||
import org.mifosplatform.useradministration.data.RoleData;
|
import org.mifosplatform.useradministration.data.RoleData;
|
||||||
import org.mifosplatform.useradministration.domain.AppUser;
|
import org.mifosplatform.useradministration.domain.AppUser;
|
||||||
import org.mifosplatform.useradministration.domain.Role;
|
import org.mifosplatform.useradministration.domain.Role;
|
||||||
import org.mifosplatform.useradministration.exception.UserNotFoundException;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
@@ -59,10 +58,6 @@ public class AuthenticationApiResource {
|
|||||||
|
|
||||||
final Authentication authentication = new UsernamePasswordAuthenticationToken(username, password);
|
final Authentication authentication = new UsernamePasswordAuthenticationToken(username, password);
|
||||||
final Authentication authenticationCheck = this.customAuthenticationProvider.authenticate(authentication);
|
final Authentication authenticationCheck = this.customAuthenticationProvider.authenticate(authentication);
|
||||||
final AppUser principal = (AppUser) authenticationCheck.getPrincipal();
|
|
||||||
if (principal.isDeleted() || principal.isNotEnabled() ) {
|
|
||||||
throw new UserNotFoundException(principal.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
final Collection<String> permissions = new ArrayList<String>();
|
final Collection<String> permissions = new ArrayList<String>();
|
||||||
AuthenticatedUserData authenticatedUserData = new AuthenticatedUserData(username, permissions);
|
AuthenticatedUserData authenticatedUserData = new AuthenticatedUserData(username, permissions);
|
||||||
@@ -75,6 +70,7 @@ public class AuthenticationApiResource {
|
|||||||
|
|
||||||
final byte[] base64EncodedAuthenticationKey = Base64.encode(username + ":" + password);
|
final byte[] base64EncodedAuthenticationKey = Base64.encode(username + ":" + password);
|
||||||
|
|
||||||
|
final AppUser principal = (AppUser) authenticationCheck.getPrincipal();
|
||||||
final Collection<RoleData> roles = new ArrayList<RoleData>();
|
final Collection<RoleData> roles = new ArrayList<RoleData>();
|
||||||
final Set<Role> userRoles = principal.getRoles();
|
final Set<Role> userRoles = principal.getRoles();
|
||||||
for (final Role role : userRoles) {
|
for (final Role role : userRoles) {
|
||||||
|
|||||||
+1
-1
@@ -7,6 +7,6 @@ package org.mifosplatform.infrastructure.security.domain;
|
|||||||
|
|
||||||
public interface PlatformUserRepository {
|
public interface PlatformUserRepository {
|
||||||
|
|
||||||
PlatformUser findByUsername(String username);
|
PlatformUser findByUsernameAndDeletedAndEnabled(String username, boolean deleted, boolean enabled);
|
||||||
|
|
||||||
}
|
}
|
||||||
+5
-1
@@ -29,7 +29,11 @@ public class TenantAwareJpaPlatformUserDetailsService implements PlatformUserDet
|
|||||||
@Cacheable(value = "usersByUsername", key = "T(org.mifosplatform.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getTenantIdentifier().concat(#username+'ubu')")
|
@Cacheable(value = "usersByUsername", key = "T(org.mifosplatform.infrastructure.core.service.ThreadLocalContextUtil).getTenant().getTenantIdentifier().concat(#username+'ubu')")
|
||||||
public UserDetails loadUserByUsername(final String username) throws UsernameNotFoundException, DataAccessException {
|
public UserDetails loadUserByUsername(final String username) throws UsernameNotFoundException, DataAccessException {
|
||||||
|
|
||||||
final PlatformUser appUser = this.platformUserRepository.findByUsername(username);
|
// Retrieve active users only
|
||||||
|
final boolean deleted = false;
|
||||||
|
final boolean enabled = true;
|
||||||
|
|
||||||
|
final PlatformUser appUser = this.platformUserRepository.findByUsernameAndDeletedAndEnabled(username, deleted, enabled);
|
||||||
|
|
||||||
if (appUser == null) { throw new UsernameNotFoundException(username + ": not found"); }
|
if (appUser == null) { throw new UsernameNotFoundException(username + ": not found"); }
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -608,7 +608,7 @@ public final class LoanProductDataValidator {
|
|||||||
final Long incomeFromRecoveryAccountId = this.fromApiJsonHelper.extractLongNamed(
|
final Long incomeFromRecoveryAccountId = this.fromApiJsonHelper.extractLongNamed(
|
||||||
LOAN_PRODUCT_ACCOUNTING_PARAMS.INCOME_FROM_RECOVERY.getValue(), element);
|
LOAN_PRODUCT_ACCOUNTING_PARAMS.INCOME_FROM_RECOVERY.getValue(), element);
|
||||||
baseDataValidator.reset().parameter(LOAN_PRODUCT_ACCOUNTING_PARAMS.INCOME_FROM_RECOVERY.getValue()).value(incomeFromRecoveryAccountId)
|
baseDataValidator.reset().parameter(LOAN_PRODUCT_ACCOUNTING_PARAMS.INCOME_FROM_RECOVERY.getValue()).value(incomeFromRecoveryAccountId)
|
||||||
.notNull().integerGreaterThanZero();
|
.ignoreIfNull().integerGreaterThanZero();
|
||||||
|
|
||||||
final Long writeOffAccountId = this.fromApiJsonHelper.extractLongNamed(
|
final Long writeOffAccountId = this.fromApiJsonHelper.extractLongNamed(
|
||||||
LOAN_PRODUCT_ACCOUNTING_PARAMS.LOSSES_WRITTEN_OFF.getValue(), element);
|
LOAN_PRODUCT_ACCOUNTING_PARAMS.LOSSES_WRITTEN_OFF.getValue(), element);
|
||||||
|
|||||||
Reference in New Issue
Block a user