fixing test case failures due to work on tranche loans improvement

This commit is contained in:
Vishwas Babu A J
2015-03-03 17:36:08 +05:30
parent 445a98d225
commit e5ccac0ca2
2 changed files with 465 additions and 640 deletions
@@ -5,27 +5,28 @@
*/ */
package org.mifosplatform.integrationtests; package org.mifosplatform.integrationtests;
import com.jayway.restassured.builder.RequestSpecBuilder;
import com.jayway.restassured.builder.ResponseSpecBuilder;
import com.jayway.restassured.http.ContentType;
import com.jayway.restassured.specification.RequestSpecification;
import com.jayway.restassured.specification.ResponseSpecification;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.mifosplatform.integrationtests.common.ClientHelper; import org.mifosplatform.integrationtests.common.ClientHelper;
import org.mifosplatform.integrationtests.common.CommonConstants; import org.mifosplatform.integrationtests.common.CommonConstants;
import org.mifosplatform.integrationtests.common.Utils;
import org.mifosplatform.integrationtests.common.loans.LoanApplicationTestBuilder; import org.mifosplatform.integrationtests.common.loans.LoanApplicationTestBuilder;
import org.mifosplatform.integrationtests.common.loans.LoanProductTestBuilder; import org.mifosplatform.integrationtests.common.loans.LoanProductTestBuilder;
import org.mifosplatform.integrationtests.common.loans.LoanTransactionHelper; import org.mifosplatform.integrationtests.common.loans.LoanTransactionHelper;
import org.mifosplatform.integrationtests.common.savings.SavingsProductHelper;
import org.mifosplatform.integrationtests.common.savings.SavingsAccountHelper; import org.mifosplatform.integrationtests.common.savings.SavingsAccountHelper;
import org.mifosplatform.integrationtests.common.savings.SavingsProductHelper;
import org.mifosplatform.integrationtests.common.system.AccountNumberPreferencesHelper; import org.mifosplatform.integrationtests.common.system.AccountNumberPreferencesHelper;
import org.mifosplatform.integrationtests.common.system.CodeHelper; import org.mifosplatform.integrationtests.common.system.CodeHelper;
import org.mifosplatform.integrationtests.common.Utils;
import com.jayway.restassured.builder.RequestSpecBuilder;
import com.jayway.restassured.builder.ResponseSpecBuilder;
import com.jayway.restassured.http.ContentType;
import com.jayway.restassured.specification.RequestSpecification;
import com.jayway.restassured.specification.ResponseSpecification;
public class AccountNumberPreferencesTest { public class AccountNumberPreferencesTest {
@@ -39,13 +40,13 @@ public class AccountNumberPreferencesTest {
private Integer loanId; private Integer loanId;
private Integer savingsProductId; private Integer savingsProductId;
private Integer savingsId; private Integer savingsId;
private String loanPrincipalAmount = "100000.00"; private final String loanPrincipalAmount = "100000.00";
private String numberOfRepayments = "12"; private final String numberOfRepayments = "12";
private String interestRatePerPeriod = "18"; private final String interestRatePerPeriod = "18";
private String dateString = "4 September 2014"; private final String dateString = "4 September 2014";
private String minBalanceForInterestCalculation = null; private final String minBalanceForInterestCalculation = null;
private String minRequiredBalance = null; private final String minRequiredBalance = null;
private String enforceMinRequiredBalance = "false"; private final String enforceMinRequiredBalance = "false";
private LoanTransactionHelper loanTransactionHelper; private LoanTransactionHelper loanTransactionHelper;
private SavingsAccountHelper savingsAccountHelper; private SavingsAccountHelper savingsAccountHelper;
private AccountNumberPreferencesHelper accountNumberPreferencesHelper; private AccountNumberPreferencesHelper accountNumberPreferencesHelper;
@@ -58,32 +59,22 @@ public class AccountNumberPreferencesTest {
private Integer clientTypeCodeId; private Integer clientTypeCodeId;
private String clientCodeValueName; private String clientCodeValueName;
private Integer clientCodeValueId; private Integer clientCodeValueId;
private String clientTypeName = "CLIENT_TYPE"; private final String clientTypeName = "CLIENT_TYPE";
private String officeName = "OFFICE_NAME"; private final String officeName = "OFFICE_NAME";
private String loanShortName = "LOAN_PRODUCT_SHORT_NAME"; private final String loanShortName = "LOAN_PRODUCT_SHORT_NAME";
private String savingsShortName = "SAVINGS_PRODUCT_SHORT_NAME"; private final String savingsShortName = "SAVINGS_PRODUCT_SHORT_NAME";
@Before @Before
public void setup() { public void setup() {
Utils.initializeRESTAssured(); Utils.initializeRESTAssured();
this.requestSpec = new RequestSpecBuilder().setContentType( this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
ContentType.JSON).build(); this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
this.requestSpec this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
.header("Authorization", this.responseValidationError = new ResponseSpecBuilder().expectStatusCode(400).build();
"Basic " this.responseNotFoundError = new ResponseSpecBuilder().expectStatusCode(404).build();
+ Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); this.responseForbiddenError = new ResponseSpecBuilder().expectStatusCode(403).build();
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200) this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
.build(); this.accountNumberPreferencesHelper = new AccountNumberPreferencesHelper(this.requestSpec, this.responseSpec);
this.responseValidationError = new ResponseSpecBuilder()
.expectStatusCode(400).build();
this.responseNotFoundError = new ResponseSpecBuilder()
.expectStatusCode(404).build();
this.responseForbiddenError = new ResponseSpecBuilder()
.expectStatusCode(403).build();
this.loanTransactionHelper = new LoanTransactionHelper(
this.requestSpec, this.responseSpec);
this.accountNumberPreferencesHelper = new AccountNumberPreferencesHelper(
this.requestSpec, this.responseSpec);
} }
@@ -131,26 +122,21 @@ public class AccountNumberPreferencesTest {
} }
private void deleteAllAccountNumberPreferences() { private void deleteAllAccountNumberPreferences() {
ArrayList<HashMap<String, Object>> preferenceIds = this.accountNumberPreferencesHelper ArrayList<HashMap<String, Object>> preferenceIds = this.accountNumberPreferencesHelper.getAllAccountNumberPreferences();
.getAllAccountNumberPreferences();
/* Deletion of valid account preference ID */ /* Deletion of valid account preference ID */
for (HashMap<String, Object> preferenceId : preferenceIds) { for (HashMap<String, Object> preferenceId : preferenceIds) {
Integer id = (Integer) preferenceId.get("id"); Integer id = (Integer) preferenceId.get("id");
HashMap<String, Object> delResponse = this.accountNumberPreferencesHelper HashMap<String, Object> delResponse = this.accountNumberPreferencesHelper.deleteAccountNumberPreference(id, this.responseSpec,
.deleteAccountNumberPreference(id, this.responseSpec, ""); "");
System.out System.out.println("Successfully deleted account number preference (ID: " + delResponse.get("resourceId") + ")");
.println("Successfully deleted account number preference (ID: "
+ delResponse.get("resourceId") + ")");
} }
/* Deletion of invalid account preference ID should fail */ /* Deletion of invalid account preference ID should fail */
System.out System.out
.println("---------------------------------DELETING ACCOUNT NUMBER PREFERENCE WITH INVALID ID------------------------------------------"); .println("---------------------------------DELETING ACCOUNT NUMBER PREFERENCE WITH INVALID ID------------------------------------------");
HashMap<String, Object> deletionError = this.accountNumberPreferencesHelper HashMap<String, Object> deletionError = this.accountNumberPreferencesHelper.deleteAccountNumberPreference(10,
.deleteAccountNumberPreference(10, this.responseNotFoundError, this.responseNotFoundError, "");
""); Assert.assertEquals("error.msg.resource.not.found", deletionError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
Assert.assertEquals("error.msg.resource.not.found",
deletionError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
} }
private void validateDefaultAccountNumberGeneration() { private void validateDefaultAccountNumberGeneration() {
@@ -167,98 +153,67 @@ public class AccountNumberPreferencesTest {
} }
private void createAccountNumberPreference() { private void createAccountNumberPreference() {
this.clientAccountNumberPreferenceId = (Integer) this.accountNumberPreferencesHelper this.clientAccountNumberPreferenceId = (Integer) this.accountNumberPreferencesHelper.createClientAccountNumberPreference(
.createClientAccountNumberPreference(this.responseSpec, this.responseSpec, "resourceId");
"resourceId"); System.out.println("Successfully created account number preferences for Client (ID: " + this.clientAccountNumberPreferenceId);
System.out
.println("Successfully created account number preferences for Client (ID: "
+ this.clientAccountNumberPreferenceId);
this.loanAccountNumberPreferenceId = (Integer) this.accountNumberPreferencesHelper this.loanAccountNumberPreferenceId = (Integer) this.accountNumberPreferencesHelper.createLoanAccountNumberPreference(
.createLoanAccountNumberPreference(this.responseSpec, this.responseSpec, "resourceId");
"resourceId"); System.out.println("Successfully created account number preferences for Loan (ID: " + this.loanAccountNumberPreferenceId);
System.out
.println("Successfully created account number preferences for Loan (ID: "
+ this.loanAccountNumberPreferenceId);
this.savingsAccountNumberPreferenceId = (Integer) this.accountNumberPreferencesHelper this.savingsAccountNumberPreferenceId = (Integer) this.accountNumberPreferencesHelper.createSavingsAccountNumberPreference(
.createSavingsAccountNumberPreference(this.responseSpec, this.responseSpec, "resourceId");
"resourceId"); System.out.println("Successfully created account number preferences for Savings (ID: " + this.savingsAccountNumberPreferenceId);
System.out
.println("Successfully created account number preferences for Savings (ID: "
+ this.savingsAccountNumberPreferenceId);
this.accountNumberPreferencesHelper this.accountNumberPreferencesHelper.verifyCreationOfAccountNumberPreferences(this.clientAccountNumberPreferenceId,
.verifyCreationOfAccountNumberPreferences( this.loanAccountNumberPreferenceId, this.savingsAccountNumberPreferenceId, this.responseSpec, this.requestSpec);
this.clientAccountNumberPreferenceId,
this.loanAccountNumberPreferenceId,
this.savingsAccountNumberPreferenceId,
this.responseSpec, this.requestSpec);
this.createAccountNumberPreferenceInvalidData("1000", "1001"); this.createAccountNumberPreferenceInvalidData("1000", "1001");
this.createAccountNumberPreferenceDuplicateData("1", "101"); this.createAccountNumberPreferenceDuplicateData("1", "101");
} }
private void createAccountNumberPreferenceDuplicateData( private void createAccountNumberPreferenceDuplicateData(final String accountType, final String prefixType) {
final String accountType, final String prefixType) {
/* Creating account Preference with duplicate data should fail */ /* Creating account Preference with duplicate data should fail */
System.out System.out
.println("---------------------------------CREATING ACCOUNT NUMBER PREFERENCE WITH DUPLICATE DATA------------------------------------------"); .println("---------------------------------CREATING ACCOUNT NUMBER PREFERENCE WITH DUPLICATE DATA------------------------------------------");
HashMap<String, Object> creationError = this.accountNumberPreferencesHelper HashMap<String, Object> creationError = this.accountNumberPreferencesHelper.createAccountNumberPreferenceWithInvalidData(
.createAccountNumberPreferenceWithInvalidData( this.responseForbiddenError, accountType, prefixType, "");
this.responseForbiddenError, accountType, prefixType,
"");
Assert.assertEquals( Assert.assertEquals("error.msg.account.number.format.duplicate.account.type",
"error.msg.account.number.format.duplicate.account.type",
creationError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); creationError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
} }
private void createAccountNumberPreferenceInvalidData( private void createAccountNumberPreferenceInvalidData(final String accountType, final String prefixType) {
final String accountType, final String prefixType) {
/* Creating account Preference with invalid data should fail */ /* Creating account Preference with invalid data should fail */
System.out System.out
.println("---------------------------------CREATING ACCOUNT NUMBER PREFERENCE WITH INVALID DATA------------------------------------------"); .println("---------------------------------CREATING ACCOUNT NUMBER PREFERENCE WITH INVALID DATA------------------------------------------");
HashMap<String, Object> creationError = this.accountNumberPreferencesHelper HashMap<String, Object> creationError = this.accountNumberPreferencesHelper.createAccountNumberPreferenceWithInvalidData(
.createAccountNumberPreferenceWithInvalidData( this.responseValidationError, accountType, prefixType, "");
this.responseValidationError, accountType, prefixType,
"");
if (creationError if (creationError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE).equals(
.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE) "validation.msg.accountNumberFormat.accountType.is.not.within.expected.range")) {
.equals("validation.msg.accountNumberFormat.accountType.is.not.within.expected.range")) { Assert.assertEquals("validation.msg.accountNumberFormat.accountType.is.not.within.expected.range",
Assert.assertEquals( creationError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
"validation.msg.accountNumberFormat.accountType.is.not.within.expected.range", } else if (creationError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE).equals(
creationError "validation.msg.accountNumberFormat.prefixType.is.not.one.of.expected.enumerations")) {
.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); Assert.assertEquals("validation.msg.accountNumberFormat.prefixType.is.not.one.of.expected.enumerations",
} else if (creationError creationError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)
.equals("validation.msg.accountNumberFormat.prefixType.is.not.one.of.expected.enumerations")) {
Assert.assertEquals(
"validation.msg.accountNumberFormat.prefixType.is.not.one.of.expected.enumerations",
creationError
.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
} }
} }
private void updateAccountNumberPreference() { private void updateAccountNumberPreference() {
HashMap<String, Object> accountNumberPreferences = this.accountNumberPreferencesHelper HashMap<String, Object> accountNumberPreferences = this.accountNumberPreferencesHelper.updateAccountNumberPreference(
.updateAccountNumberPreference( this.clientAccountNumberPreferenceId, "101", this.responseSpec, "");
this.clientAccountNumberPreferenceId, "101",
this.responseSpec, "");
System.out System.out.println("--------------------------UPDATION SUCCESSFUL FOR ACCOUNT NUMBER PREFERENCE ID "
.println("--------------------------UPDATION SUCCESSFUL FOR ACCOUNT NUMBER PREFERENCE ID "
+ accountNumberPreferences.get("resourceId")); + accountNumberPreferences.get("resourceId"));
this.accountNumberPreferencesHelper this.accountNumberPreferencesHelper.verifyUpdationOfAccountNumberPreferences((Integer) accountNumberPreferences.get("resourceId"),
.verifyUpdationOfAccountNumberPreferences(
(Integer) accountNumberPreferences.get("resourceId"),
this.responseSpec, this.requestSpec); this.responseSpec, this.requestSpec);
/* Update invalid account preference id should fail */ /* Update invalid account preference id should fail */
@@ -266,28 +221,21 @@ public class AccountNumberPreferencesTest {
.println("---------------------------------UPDATING ACCOUNT NUMBER PREFERENCE WITH INVALID DATA------------------------------------------"); .println("---------------------------------UPDATING ACCOUNT NUMBER PREFERENCE WITH INVALID DATA------------------------------------------");
/* Invalid Account Type */ /* Invalid Account Type */
HashMap<String, Object> updationError = this.accountNumberPreferencesHelper HashMap<String, Object> updationError = this.accountNumberPreferencesHelper.updateAccountNumberPreference(9999, "101",
.updateAccountNumberPreference(9999, "101",
this.responseNotFoundError, ""); this.responseNotFoundError, "");
if (updationError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE) if (updationError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE).equals("error.msg.resource.not.found")) {
.equals("error.msg.resource.not.found")) { Assert.assertEquals("error.msg.resource.not.found", updationError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
Assert.assertEquals("error.msg.resource.not.found", updationError
.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
} }
/* Invalid Prefix Type */ /* Invalid Prefix Type */
HashMap<String, Object> updationError1 = this.accountNumberPreferencesHelper HashMap<String, Object> updationError1 = this.accountNumberPreferencesHelper.updateAccountNumberPreference(
.updateAccountNumberPreference( this.clientAccountNumberPreferenceId, "103", this.responseValidationError, "");
this.clientAccountNumberPreferenceId, "103",
this.responseValidationError, "");
Assert.assertEquals("validation.msg.validation.errors.exist", Assert.assertEquals("validation.msg.validation.errors.exist", updationError1.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
updationError1.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
} }
private void createAndValidateClientEntity(Boolean isAccountPreferenceSetUp) { private void createAndValidateClientEntity(Boolean isAccountPreferenceSetUp) {
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200) this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
.build();
if (isAccountPreferenceSetUp) { if (isAccountPreferenceSetUp) {
this.createAndValidateClientBasedOnAccountPreference(); this.createAndValidateClientBasedOnAccountPreference();
} else { } else {
@@ -296,64 +244,49 @@ public class AccountNumberPreferencesTest {
} }
private void createAndValidateClientWithoutAccountPreference() { private void createAndValidateClientWithoutAccountPreference() {
this.clientId = ClientHelper.createClient(this.requestSpec, this.clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec);
this.responseSpec);
Assert.assertNotNull(this.clientId); Assert.assertNotNull(this.clientId);
String clientAccountNo = (String) ClientHelper.getClient(requestSpec, String clientAccountNo = (String) ClientHelper.getClient(requestSpec, responseSpec, this.clientId.toString(), "accountNo");
responseSpec, this.clientId.toString(), "accountNo");
validateAccountNumberLengthAndStartsWithPrefix(clientAccountNo, null); validateAccountNumberLengthAndStartsWithPrefix(clientAccountNo, null);
} }
private void createAndValidateClientBasedOnAccountPreference() { private void createAndValidateClientBasedOnAccountPreference() {
final String codeName = "ClientType"; final String codeName = "ClientType";
String clientAccountNo = null; String clientAccountNo = null;
String clientPrefixName = (String) this.accountNumberPreferencesHelper String clientPrefixName = (String) this.accountNumberPreferencesHelper.getAccountNumberPreference(
.getAccountNumberPreference( this.clientAccountNumberPreferenceId, "prefixType.value");
this.clientAccountNumberPreferenceId,
"prefixType.value");
if (clientPrefixName.equals(this.clientTypeName)) { if (clientPrefixName.equals(this.clientTypeName)) {
/* Retrieve Code id for the Code "ClientType" */ /* Retrieve Code id for the Code "ClientType" */
HashMap<String, Object> code = CodeHelper HashMap<String, Object> code = CodeHelper.getCodeByName(this.requestSpec, this.responseSpec, codeName);
.getCodeByName(this.requestSpec, this.responseSpec,
codeName);
this.clientTypeCodeId = (Integer) code.get("id"); this.clientTypeCodeId = (Integer) code.get("id");
/* Retrieve/Create Code Values for the Code "ClientType" */ /* Retrieve/Create Code Values for the Code "ClientType" */
HashMap<String, Object> codeValue = CodeHelper HashMap<String, Object> codeValue = CodeHelper.retrieveOrCreateCodeValue(this.clientTypeCodeId, this.requestSpec,
.retrieveOrCreateCodeValue(this.clientTypeCodeId, this.responseSpec);
this.requestSpec, this.responseSpec);
this.clientCodeValueName = (String) codeValue.get("name"); this.clientCodeValueName = (String) codeValue.get("name");
this.clientCodeValueId = (Integer) codeValue.get("id"); this.clientCodeValueId = (Integer) codeValue.get("id");
/* Create Client with Client Type */ /* Create Client with Client Type */
this.clientId = ClientHelper.createClientForAccountPreference( this.clientId = ClientHelper.createClientForAccountPreference(this.requestSpec, this.responseSpec, this.clientCodeValueId,
this.requestSpec, this.responseSpec, "clientId");
this.clientCodeValueId, "clientId");
Assert.assertNotNull(clientId); Assert.assertNotNull(clientId);
clientAccountNo = (String) ClientHelper.getClient(this.requestSpec, clientAccountNo = (String) ClientHelper.getClient(this.requestSpec, this.responseSpec, this.clientId.toString(), "accountNo");
this.responseSpec, this.clientId.toString(), "accountNo"); this.validateAccountNumberLengthAndStartsWithPrefix(clientAccountNo, this.clientCodeValueName);
this.validateAccountNumberLengthAndStartsWithPrefix(
clientAccountNo, this.clientCodeValueName);
} else if (clientPrefixName.equals(this.officeName)) { } else if (clientPrefixName.equals(this.officeName)) {
this.clientId = ClientHelper.createClient(this.requestSpec, this.clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec);
this.responseSpec);
Assert.assertNotNull(clientId); Assert.assertNotNull(clientId);
clientAccountNo = (String) ClientHelper.getClient(requestSpec, clientAccountNo = (String) ClientHelper.getClient(requestSpec, responseSpec, this.clientId.toString(), "accountNo");
responseSpec, this.clientId.toString(), "accountNo"); String officeName = (String) ClientHelper.getClient(requestSpec, responseSpec, this.clientId.toString(), "officeName");
String officeName = (String) ClientHelper.getClient(requestSpec, this.validateAccountNumberLengthAndStartsWithPrefix(clientAccountNo, officeName);
responseSpec, this.clientId.toString(), "officeName");
this.validateAccountNumberLengthAndStartsWithPrefix(
clientAccountNo, officeName);
} }
} }
private void validateAccountNumberLengthAndStartsWithPrefix( private void validateAccountNumberLengthAndStartsWithPrefix(final String accountNumber, final String prefix) {
final String accountNumber, final String prefix) {
if (prefix != null) { if (prefix != null) {
Assert.assertEquals(accountNumber.length(), prefix.length() + 9); Assert.assertEquals(accountNumber.length(), prefix.length() + 9);
Assert.assertTrue(accountNumber.startsWith(prefix)); Assert.assertTrue(accountNumber.startsWith(prefix));
@@ -363,90 +296,58 @@ public class AccountNumberPreferencesTest {
} }
private void createLoanProduct() { private void createLoanProduct() {
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200) this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
.build();
System.out System.out.println("---------------------------------CREATING LOAN PRODUCT------------------------------------------");
.println("---------------------------------CREATING LOAN PRODUCT------------------------------------------");
final String loanProductJSON = new LoanProductTestBuilder() final String loanProductJSON = new LoanProductTestBuilder().withPrincipal(loanPrincipalAmount)
.withPrincipal(loanPrincipalAmount) .withNumberOfRepayments(numberOfRepayments).withinterestRatePerPeriod(interestRatePerPeriod)
.withNumberOfRepayments(numberOfRepayments)
.withinterestRatePerPeriod(interestRatePerPeriod)
.withInterestRateFrequencyTypeAsYear().build(null); .withInterestRateFrequencyTypeAsYear().build(null);
this.loanProductId = this.loanTransactionHelper this.loanProductId = this.loanTransactionHelper.getLoanProductId(loanProductJSON);
.getLoanProductId(loanProductJSON); System.out.println("Successfully created loan product (ID: " + this.loanProductId + ")");
System.out.println("Successfully created loan product (ID: "
+ this.loanProductId + ")");
} }
private void createAndValidateLoanEntity(Boolean isAccountPreferenceSetUp) { private void createAndValidateLoanEntity(Boolean isAccountPreferenceSetUp) {
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200) this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
.build();
System.out System.out.println("---------------------------------NEW LOAN APPLICATION------------------------------------------");
.println("---------------------------------NEW LOAN APPLICATION------------------------------------------");
final String loanApplicationJSON = new LoanApplicationTestBuilder() final String loanApplicationJSON = new LoanApplicationTestBuilder().withPrincipal(loanPrincipalAmount)
.withPrincipal(loanPrincipalAmount) .withLoanTermFrequency(numberOfRepayments).withLoanTermFrequencyAsMonths().withNumberOfRepayments(numberOfRepayments)
.withLoanTermFrequency(numberOfRepayments) .withRepaymentEveryAfter("1").withRepaymentFrequencyTypeAsMonths().withAmortizationTypeAsEqualInstallments()
.withLoanTermFrequencyAsMonths() .withInterestCalculationPeriodTypeAsDays().withInterestRatePerPeriod(interestRatePerPeriod).withLoanTermFrequencyAsMonths()
.withNumberOfRepayments(numberOfRepayments) .withSubmittedOnDate(dateString).withExpectedDisbursementDate(dateString).withPrincipalGrace("2").withInterestGrace("2")
.withRepaymentEveryAfter("1") .build(this.clientId.toString(), this.loanProductId.toString(), null);
.withRepaymentFrequencyTypeAsMonths()
.withAmortizationTypeAsEqualInstallments() System.out.println("Loan Application :" + loanApplicationJSON);
.withInterestCalculationPeriodTypeAsDays()
.withInterestRatePerPeriod(interestRatePerPeriod)
.withLoanTermFrequencyAsMonths()
.withSubmittedOnDate(dateString)
.withExpectedDisbursementDate(dateString)
.withPrincipalGrace("2")
.withInterestGrace("2")
.build(this.clientId.toString(), this.loanProductId.toString(),
null);
this.loanId = this.loanTransactionHelper.getLoanId(loanApplicationJSON); this.loanId = this.loanTransactionHelper.getLoanId(loanApplicationJSON);
String loanAccountNo = (String) this.loanTransactionHelper String loanAccountNo = (String) this.loanTransactionHelper.getLoanDetail(this.requestSpec, this.responseSpec, this.loanId,
.getLoanDetail(this.requestSpec, this.responseSpec, "accountNo");
this.loanId, "accountNo");
if (isAccountPreferenceSetUp) { if (isAccountPreferenceSetUp) {
String loanPrefixName = (String) this.accountNumberPreferencesHelper String loanPrefixName = (String) this.accountNumberPreferencesHelper.getAccountNumberPreference(
.getAccountNumberPreference( this.loanAccountNumberPreferenceId, "prefixType.value");
this.loanAccountNumberPreferenceId,
"prefixType.value");
if (loanPrefixName.equals(this.officeName)) { if (loanPrefixName.equals(this.officeName)) {
String loanOfficeName = (String) ClientHelper.getClient( String loanOfficeName = (String) ClientHelper.getClient(requestSpec, responseSpec, this.clientId.toString(), "officeName");
requestSpec, responseSpec, this.clientId.toString(), this.validateAccountNumberLengthAndStartsWithPrefix(loanAccountNo, loanOfficeName);
"officeName");
this.validateAccountNumberLengthAndStartsWithPrefix(
loanAccountNo, loanOfficeName);
} else if (loanPrefixName.equals(this.loanShortName)) { } else if (loanPrefixName.equals(this.loanShortName)) {
String loanShortName = (String) this.loanTransactionHelper String loanShortName = (String) this.loanTransactionHelper.getLoanProductDetail(this.requestSpec, this.responseSpec,
.getLoanProductDetail(this.requestSpec, this.loanProductId, "shortName");
this.responseSpec, this.loanProductId, this.validateAccountNumberLengthAndStartsWithPrefix(loanAccountNo, loanShortName);
"shortName");
this.validateAccountNumberLengthAndStartsWithPrefix(
loanAccountNo, loanShortName);
} }
System.out System.out.println("SUCCESSFULLY CREATED LOAN APPLICATION BASED ON ACCOUNT PREFERENCES (ID: " + this.loanId + ")");
.println("SUCCESSFULLY CREATED LOAN APPLICATION BASED ON ACCOUNT PREFERENCES (ID: "
+ this.loanId + ")");
} else { } else {
this.validateAccountNumberLengthAndStartsWithPrefix(loanAccountNo, this.validateAccountNumberLengthAndStartsWithPrefix(loanAccountNo, null);
null); System.out.println("SUCCESSFULLY CREATED LOAN APPLICATION (ID: " + loanId + ")");
System.out.println("SUCCESSFULLY CREATED LOAN APPLICATION (ID: "
+ loanId + ")");
} }
} }
private void createSavingsProduct() { private void createSavingsProduct() {
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200) this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
.build();
System.out System.out.println("------------------------------CREATING NEW SAVINGS PRODUCT ---------------------------------------");
.println("------------------------------CREATING NEW SAVINGS PRODUCT ---------------------------------------");
SavingsProductHelper savingsProductHelper = new SavingsProductHelper(); SavingsProductHelper savingsProductHelper = new SavingsProductHelper();
@@ -458,59 +359,41 @@ public class AccountNumberPreferencesTest {
// //
.withInterestCalculationPeriodTypeAsDailyBalance() .withInterestCalculationPeriodTypeAsDailyBalance()
// //
.withMinBalanceForInterestCalculation( .withMinBalanceForInterestCalculation(minBalanceForInterestCalculation)
minBalanceForInterestCalculation)
// //
.withMinRequiredBalance(minRequiredBalance) .withMinRequiredBalance(minRequiredBalance).withEnforceMinRequiredBalance(enforceMinRequiredBalance)
.withEnforceMinRequiredBalance(enforceMinRequiredBalance) .withMinimumOpenningBalance(this.MINIMUM_OPENING_BALANCE).build();
.withMinimumOpenningBalance(this.MINIMUM_OPENING_BALANCE) this.savingsProductId = SavingsProductHelper.createSavingsProduct(savingsProductJSON, this.requestSpec, this.responseSpec);
.build(); System.out.println("Sucessfully created savings product (ID: " + this.savingsProductId + ")");
this.savingsProductId = SavingsProductHelper.createSavingsProduct(
savingsProductJSON, this.requestSpec, this.responseSpec);
System.out.println("Sucessfully created savings product (ID: "
+ this.savingsProductId + ")");
} }
private void createAndValidateSavingsEntity(Boolean isAccountPreferenceSetUp) { private void createAndValidateSavingsEntity(Boolean isAccountPreferenceSetUp) {
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200) this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
.build();
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
this.responseSpec);
this.savingsId = this.savingsAccountHelper.applyForSavingsApplication( this.savingsId = this.savingsAccountHelper
this.clientId, this.savingsProductId, ACCOUNT_TYPE_INDIVIDUAL); .applyForSavingsApplication(this.clientId, this.savingsProductId, ACCOUNT_TYPE_INDIVIDUAL);
String savingsAccountNo = (String) this.savingsAccountHelper String savingsAccountNo = (String) this.savingsAccountHelper.getSavingsAccountDetail(this.savingsId, "accountNo");
.getSavingsAccountDetail(this.savingsId, "accountNo");
if (isAccountPreferenceSetUp) { if (isAccountPreferenceSetUp) {
String savingsPrefixName = (String) this.accountNumberPreferencesHelper String savingsPrefixName = (String) this.accountNumberPreferencesHelper.getAccountNumberPreference(
.getAccountNumberPreference( this.savingsAccountNumberPreferenceId, "prefixType.value");
this.savingsAccountNumberPreferenceId,
"prefixType.value");
if (savingsPrefixName.equals(this.officeName)) { if (savingsPrefixName.equals(this.officeName)) {
String savingsOfficeName = (String) ClientHelper.getClient( String savingsOfficeName = (String) ClientHelper.getClient(requestSpec, responseSpec, this.clientId.toString(),
requestSpec, responseSpec, this.clientId.toString(),
"officeName"); "officeName");
this.validateAccountNumberLengthAndStartsWithPrefix( this.validateAccountNumberLengthAndStartsWithPrefix(savingsAccountNo, savingsOfficeName);
savingsAccountNo, savingsOfficeName);
} else if (savingsPrefixName.equals(this.savingsShortName)) { } else if (savingsPrefixName.equals(this.savingsShortName)) {
String loanShortName = (String) this.savingsAccountHelper String loanShortName = (String) this.savingsAccountHelper.getSavingsAccountDetail(this.savingsId, "shortName");
.getSavingsAccountDetail(this.savingsId, "shortName"); this.validateAccountNumberLengthAndStartsWithPrefix(savingsAccountNo, loanShortName);
this.validateAccountNumberLengthAndStartsWithPrefix(
savingsAccountNo, loanShortName);
} }
System.out System.out.println("SUCCESSFULLY CREATED SAVINGS APPLICATION BASED ON ACCOUNT PREFERENCES (ID: " + this.loanId + ")");
.println("SUCCESSFULLY CREATED SAVINGS APPLICATION BASED ON ACCOUNT PREFERENCES (ID: "
+ this.loanId + ")");
} else { } else {
this.validateAccountNumberLengthAndStartsWithPrefix( this.validateAccountNumberLengthAndStartsWithPrefix(savingsAccountNo, null);
savingsAccountNo, null); System.out.println("SUCCESSFULLY CREATED SAVINGS APPLICATION (ID: " + this.savingsId + ")");
System.out.println("SUCCESSFULLY CREATED SAVINGS APPLICATION (ID: "
+ this.savingsId + ")");
} }
} }
} }
@@ -17,7 +17,6 @@ import java.util.Set;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.joda.time.LocalDate; import org.joda.time.LocalDate;
import org.mifosplatform.infrastructure.core.api.JsonCommand;
import org.mifosplatform.infrastructure.core.data.ApiParameterError; import org.mifosplatform.infrastructure.core.data.ApiParameterError;
import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder; import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder;
import org.mifosplatform.infrastructure.core.exception.InvalidJsonException; import org.mifosplatform.infrastructure.core.exception.InvalidJsonException;
@@ -834,111 +833,69 @@ public final class LoanApplicationCommandFromApiJsonHelper {
private void validateDisbursementsAreDatewiseOrdered(JsonElement element, final DataValidatorBuilder baseDataValidator) { private void validateDisbursementsAreDatewiseOrdered(JsonElement element, final DataValidatorBuilder baseDataValidator) {
final JsonObject topLevelJsonElement = element.getAsJsonObject(); final JsonObject topLevelJsonElement = element.getAsJsonObject();
final Locale locale = this.fromApiJsonHelper final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(topLevelJsonElement);
.extractLocaleParameter(topLevelJsonElement); final String dateFormat = this.fromApiJsonHelper.extractDateFormatParameter(topLevelJsonElement);
final String dateFormat = this.fromApiJsonHelper final JsonArray variationArray = this.fromApiJsonHelper.extractJsonArrayNamed(LoanApiConstants.disbursementDataParameterName,
.extractDateFormatParameter(topLevelJsonElement);
final JsonArray variationArray = this.fromApiJsonHelper
.extractJsonArrayNamed(
LoanApiConstants.disbursementDataParameterName,
element); element);
if (variationArray != null) {
for (int i = 0; i < variationArray.size(); i++) { for (int i = 0; i < variationArray.size(); i++) {
final JsonObject jsonObject1 = variationArray.get(i) final JsonObject jsonObject1 = variationArray.get(i).getAsJsonObject();
.getAsJsonObject(); LocalDate date1 = this.fromApiJsonHelper.extractLocalDateNamed(LoanApiConstants.disbursementDateParameterName, jsonObject1,
LocalDate date1 = this.fromApiJsonHelper dateFormat, locale);
.extractLocalDateNamed(
LoanApiConstants.disbursementDateParameterName,
jsonObject1, dateFormat, locale);
for (int j = i + 1; j < variationArray.size(); j++) { for (int j = i + 1; j < variationArray.size(); j++) {
final JsonObject jsonObject2 = variationArray.get(j) final JsonObject jsonObject2 = variationArray.get(j).getAsJsonObject();
.getAsJsonObject(); LocalDate date2 = this.fromApiJsonHelper.extractLocalDateNamed(LoanApiConstants.disbursementDateParameterName,
LocalDate date2 = this.fromApiJsonHelper
.extractLocalDateNamed(
LoanApiConstants.disbursementDateParameterName,
jsonObject2, dateFormat, locale); jsonObject2, dateFormat, locale);
if (date1.isAfter(date2)) { if (date1.isAfter(date2)) {
baseDataValidator baseDataValidator.reset().parameter(LoanApiConstants.disbursementDataParameterName)
.reset() .failWithCode(LoanApiConstants.DISBURSEMENT_DATES_NOT_IN_ORDER);
.parameter( }
LoanApiConstants.disbursementDataParameterName)
.failWithCode(
LoanApiConstants.DISBURSEMENT_DATES_NOT_IN_ORDER);
} }
} }
} }
} }
public void validateLoanMultiDisbursementdate(final JsonElement element, public void validateLoanMultiDisbursementdate(final JsonElement element, final DataValidatorBuilder baseDataValidator,
final DataValidatorBuilder baseDataValidator,
LocalDate expectedDisbursement, BigDecimal totalPrincipal) { LocalDate expectedDisbursement, BigDecimal totalPrincipal) {
this.validateDisbursementsAreDatewiseOrdered(element, baseDataValidator); this.validateDisbursementsAreDatewiseOrdered(element, baseDataValidator);
final JsonObject topLevelJsonElement = element.getAsJsonObject(); final JsonObject topLevelJsonElement = element.getAsJsonObject();
final Locale locale = this.fromApiJsonHelper final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(topLevelJsonElement);
.extractLocaleParameter(topLevelJsonElement); final String dateFormat = this.fromApiJsonHelper.extractDateFormatParameter(topLevelJsonElement);
final String dateFormat = this.fromApiJsonHelper if (this.fromApiJsonHelper.parameterExists(LoanApiConstants.disbursementDataParameterName, element) && expectedDisbursement != null
.extractDateFormatParameter(topLevelJsonElement); && totalPrincipal != null) {
if (this.fromApiJsonHelper.parameterExists(
LoanApiConstants.disbursementDataParameterName, element)
&& expectedDisbursement != null && totalPrincipal != null) {
BigDecimal tatalDisbursement = BigDecimal.ZERO; BigDecimal tatalDisbursement = BigDecimal.ZERO;
boolean isFirstinstallmentOnExpectedDisbursementDate = false; boolean isFirstinstallmentOnExpectedDisbursementDate = false;
final JsonArray variationArray = this.fromApiJsonHelper final JsonArray variationArray = this.fromApiJsonHelper.extractJsonArrayNamed(LoanApiConstants.disbursementDataParameterName,
.extractJsonArrayNamed(
LoanApiConstants.disbursementDataParameterName,
element); element);
List<LocalDate> expectedDisbursementDates = new ArrayList<>(); List<LocalDate> expectedDisbursementDates = new ArrayList<>();
if (variationArray != null && variationArray.size() > 0) { if (variationArray != null && variationArray.size() > 0) {
int i = 0; int i = 0;
do { do {
final JsonObject jsonObject = variationArray.get(i) final JsonObject jsonObject = variationArray.get(i).getAsJsonObject();
.getAsJsonObject(); LocalDate expectedDisbursementDate = this.fromApiJsonHelper.extractLocalDateNamed(
LocalDate expectedDisbursementDate = this.fromApiJsonHelper LoanApiConstants.disbursementDateParameterName, jsonObject, dateFormat, locale);
.extractLocalDateNamed( if (expectedDisbursementDates.contains(expectedDisbursementDate)) {
LoanApiConstants.disbursementDateParameterName, baseDataValidator.reset().parameter(LoanApiConstants.disbursementDateParameterName)
jsonObject, dateFormat, locale); .failWithCode(LoanApiConstants.DISBURSEMENT_DATE_UNIQUE_ERROR);
if (expectedDisbursementDates
.contains(expectedDisbursementDate)) {
baseDataValidator
.reset()
.parameter(
LoanApiConstants.disbursementDateParameterName)
.failWithCode(
LoanApiConstants.DISBURSEMENT_DATE_UNIQUE_ERROR);
} }
if (expectedDisbursementDate.isBefore(expectedDisbursement)) { if (expectedDisbursementDate.isBefore(expectedDisbursement)) {
baseDataValidator baseDataValidator.reset().parameter(LoanApiConstants.disbursementDataParameterName)
.reset() .failWithCode(LoanApiConstants.DISBURSEMENT_DATE_BEFORE_ERROR);
.parameter(
LoanApiConstants.disbursementDataParameterName)
.failWithCode(
LoanApiConstants.DISBURSEMENT_DATE_BEFORE_ERROR);
} }
expectedDisbursementDates.add(expectedDisbursementDate); expectedDisbursementDates.add(expectedDisbursementDate);
BigDecimal principal = this.fromApiJsonHelper BigDecimal principal = this.fromApiJsonHelper.extractBigDecimalNamed(
.extractBigDecimalNamed( LoanApiConstants.disbursementPrincipalParameterName, jsonObject, locale);
LoanApiConstants.disbursementPrincipalParameterName, baseDataValidator.reset().parameter(LoanApiConstants.disbursementDataParameterName)
jsonObject, locale); .parameterAtIndexArray(LoanApiConstants.disbursementPrincipalParameterName, i).value(principal).notBlank();
baseDataValidator
.reset()
.parameter(
LoanApiConstants.disbursementDataParameterName)
.parameterAtIndexArray(
LoanApiConstants.disbursementPrincipalParameterName,
i).value(principal).notBlank();
if (principal != null) { if (principal != null) {
tatalDisbursement = tatalDisbursement.add(principal); tatalDisbursement = tatalDisbursement.add(principal);
} }
baseDataValidator baseDataValidator.reset().parameter(LoanApiConstants.disbursementDataParameterName)
.reset() .parameterAtIndexArray(LoanApiConstants.disbursementDateParameterName, i).value(expectedDisbursementDate)
.parameter(
LoanApiConstants.disbursementDataParameterName)
.parameterAtIndexArray(
LoanApiConstants.disbursementDateParameterName,
i).value(expectedDisbursementDate)
.notNull(); .notNull();
if (expectedDisbursement.equals(expectedDisbursementDate)) { if (expectedDisbursement.equals(expectedDisbursementDate)) {
@@ -947,33 +904,18 @@ public final class LoanApplicationCommandFromApiJsonHelper {
i++; i++;
} while (i < variationArray.size()); } while (i < variationArray.size());
if (!isFirstinstallmentOnExpectedDisbursementDate) { if (!isFirstinstallmentOnExpectedDisbursementDate) {
baseDataValidator baseDataValidator.reset().parameter(LoanApiConstants.disbursementDateParameterName)
.reset() .failWithCode(LoanApiConstants.DISBURSEMENT_DATE_START_WITH_ERROR);
.parameter(
LoanApiConstants.disbursementDateParameterName)
.failWithCode(
LoanApiConstants.DISBURSEMENT_DATE_START_WITH_ERROR);
} }
if (tatalDisbursement.compareTo(totalPrincipal) == 1) { if (tatalDisbursement.compareTo(totalPrincipal) == 1) {
baseDataValidator baseDataValidator.reset().parameter(LoanApiConstants.disbursementPrincipalParameterName)
.reset() .failWithCode(LoanApiConstants.APPROVED_AMOUNT_IS_LESS_THAN_SUM_OF_TRANCHES);
.parameter(
LoanApiConstants.disbursementPrincipalParameterName)
.failWithCode(
LoanApiConstants.APPROVED_AMOUNT_IS_LESS_THAN_SUM_OF_TRANCHES);
} }
final String interestTypeParameterName = "interestType"; final String interestTypeParameterName = "interestType";
final Integer interestType = this.fromApiJsonHelper final Integer interestType = this.fromApiJsonHelper.extractIntegerSansLocaleNamed(interestTypeParameterName, element);
.extractIntegerSansLocaleNamed( baseDataValidator.reset().parameter(interestTypeParameterName).value(interestType).ignoreIfNull()
interestTypeParameterName, element); .integerSameAsNumber(InterestMethod.DECLINING_BALANCE.getValue());
baseDataValidator
.reset()
.parameter(interestTypeParameterName)
.value(interestType)
.ignoreIfNull()
.integerSameAsNumber(
InterestMethod.DECLINING_BALANCE.getValue());
} }