fixing test case failures due to work on tranche loans improvement
This commit is contained in:
+383
-500
@@ -5,512 +5,395 @@
|
|||||||
*/
|
*/
|
||||||
package org.mifosplatform.integrationtests;
|
package org.mifosplatform.integrationtests;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.mifosplatform.integrationtests.common.ClientHelper;
|
||||||
|
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.LoanProductTestBuilder;
|
||||||
|
import org.mifosplatform.integrationtests.common.loans.LoanTransactionHelper;
|
||||||
|
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.CodeHelper;
|
||||||
|
|
||||||
import com.jayway.restassured.builder.RequestSpecBuilder;
|
import com.jayway.restassured.builder.RequestSpecBuilder;
|
||||||
import com.jayway.restassured.builder.ResponseSpecBuilder;
|
import com.jayway.restassured.builder.ResponseSpecBuilder;
|
||||||
import com.jayway.restassured.http.ContentType;
|
import com.jayway.restassured.http.ContentType;
|
||||||
import com.jayway.restassured.specification.RequestSpecification;
|
import com.jayway.restassured.specification.RequestSpecification;
|
||||||
import com.jayway.restassured.specification.ResponseSpecification;
|
import com.jayway.restassured.specification.ResponseSpecification;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.mifosplatform.integrationtests.common.ClientHelper;
|
|
||||||
import org.mifosplatform.integrationtests.common.CommonConstants;
|
|
||||||
import org.mifosplatform.integrationtests.common.loans.LoanApplicationTestBuilder;
|
|
||||||
import org.mifosplatform.integrationtests.common.loans.LoanProductTestBuilder;
|
|
||||||
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.system.AccountNumberPreferencesHelper;
|
|
||||||
import org.mifosplatform.integrationtests.common.system.CodeHelper;
|
|
||||||
import org.mifosplatform.integrationtests.common.Utils;
|
|
||||||
|
|
||||||
public class AccountNumberPreferencesTest {
|
public class AccountNumberPreferencesTest {
|
||||||
|
|
||||||
private RequestSpecification requestSpec;
|
private RequestSpecification requestSpec;
|
||||||
private ResponseSpecification responseSpec;
|
private ResponseSpecification responseSpec;
|
||||||
private ResponseSpecification responseValidationError;
|
private ResponseSpecification responseValidationError;
|
||||||
private ResponseSpecification responseNotFoundError;
|
private ResponseSpecification responseNotFoundError;
|
||||||
private ResponseSpecification responseForbiddenError;
|
private ResponseSpecification responseForbiddenError;
|
||||||
private Integer clientId;
|
private Integer clientId;
|
||||||
private Integer loanProductId;
|
private Integer loanProductId;
|
||||||
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;
|
||||||
private Integer clientAccountNumberPreferenceId;
|
private Integer clientAccountNumberPreferenceId;
|
||||||
private Integer loanAccountNumberPreferenceId;
|
private Integer loanAccountNumberPreferenceId;
|
||||||
private Integer savingsAccountNumberPreferenceId;
|
private Integer savingsAccountNumberPreferenceId;
|
||||||
private final String MINIMUM_OPENING_BALANCE = "1000.0";
|
private final String MINIMUM_OPENING_BALANCE = "1000.0";
|
||||||
private final String ACCOUNT_TYPE_INDIVIDUAL = "INDIVIDUAL";
|
private final String ACCOUNT_TYPE_INDIVIDUAL = "INDIVIDUAL";
|
||||||
private Boolean isAccountPreferenceSetUp = false;
|
private Boolean isAccountPreferenceSetUp = false;
|
||||||
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();
|
@Test
|
||||||
this.responseForbiddenError = new ResponseSpecBuilder()
|
public void testAccountNumberPreferences() {
|
||||||
.expectStatusCode(403).build();
|
|
||||||
this.loanTransactionHelper = new LoanTransactionHelper(
|
/* Create Loan and Savings Product */
|
||||||
this.requestSpec, this.responseSpec);
|
this.createLoanAndSavingsProduct();
|
||||||
this.accountNumberPreferencesHelper = new AccountNumberPreferencesHelper(
|
|
||||||
this.requestSpec, this.responseSpec);
|
/* Ensure no account number preferences are present in the system */
|
||||||
|
this.deleteAllAccountNumberPreferences();
|
||||||
}
|
|
||||||
|
/*
|
||||||
@Test
|
* Validate the default account number generation rules for clients,
|
||||||
public void testAccountNumberPreferences() {
|
* loans and savings accounts.
|
||||||
|
*/
|
||||||
/* Create Loan and Savings Product */
|
this.validateDefaultAccountNumberGeneration();
|
||||||
this.createLoanAndSavingsProduct();
|
|
||||||
|
/* Create and Validate account number preferences */
|
||||||
/* Ensure no account number preferences are present in the system */
|
this.createAccountNumberPreference();
|
||||||
this.deleteAllAccountNumberPreferences();
|
|
||||||
|
/*
|
||||||
/*
|
* Validate account number preference rules apply to Clients,Loans and
|
||||||
* Validate the default account number generation rules for clients,
|
* Saving Accounts
|
||||||
* loans and savings accounts.
|
*/
|
||||||
*/
|
this.validateAccountNumberGenerationWithPreferences();
|
||||||
this.validateDefaultAccountNumberGeneration();
|
|
||||||
|
/* Validate account number preferences Updation */
|
||||||
/* Create and Validate account number preferences */
|
this.updateAccountNumberPreference();
|
||||||
this.createAccountNumberPreference();
|
|
||||||
|
/*
|
||||||
/*
|
* Validate account number preference rules apply to Clients,Loans and
|
||||||
* Validate account number preference rules apply to Clients,Loans and
|
* Saving Accounts after Updation
|
||||||
* Saving Accounts
|
*/
|
||||||
*/
|
this.validateAccountNumberGenerationWithPreferences();
|
||||||
this.validateAccountNumberGenerationWithPreferences();
|
|
||||||
|
/* Delete all account number preferences */
|
||||||
/* Validate account number preferences Updation */
|
this.deleteAllAccountNumberPreferences();
|
||||||
this.updateAccountNumberPreference();
|
|
||||||
|
}
|
||||||
/*
|
|
||||||
* Validate account number preference rules apply to Clients,Loans and
|
private void createLoanAndSavingsProduct() {
|
||||||
* Saving Accounts after Updation
|
this.createLoanProduct();
|
||||||
*/
|
this.createSavingsProduct();
|
||||||
this.validateAccountNumberGenerationWithPreferences();
|
}
|
||||||
|
|
||||||
/* Delete all account number preferences */
|
private void deleteAllAccountNumberPreferences() {
|
||||||
this.deleteAllAccountNumberPreferences();
|
ArrayList<HashMap<String, Object>> preferenceIds = this.accountNumberPreferencesHelper.getAllAccountNumberPreferences();
|
||||||
|
/* Deletion of valid account preference ID */
|
||||||
}
|
for (HashMap<String, Object> preferenceId : preferenceIds) {
|
||||||
|
Integer id = (Integer) preferenceId.get("id");
|
||||||
private void createLoanAndSavingsProduct() {
|
HashMap<String, Object> delResponse = this.accountNumberPreferencesHelper.deleteAccountNumberPreference(id, this.responseSpec,
|
||||||
this.createLoanProduct();
|
"");
|
||||||
this.createSavingsProduct();
|
System.out.println("Successfully deleted account number preference (ID: " + delResponse.get("resourceId") + ")");
|
||||||
}
|
}
|
||||||
|
/* Deletion of invalid account preference ID should fail */
|
||||||
private void deleteAllAccountNumberPreferences() {
|
System.out
|
||||||
ArrayList<HashMap<String, Object>> preferenceIds = this.accountNumberPreferencesHelper
|
.println("---------------------------------DELETING ACCOUNT NUMBER PREFERENCE WITH INVALID ID------------------------------------------");
|
||||||
.getAllAccountNumberPreferences();
|
|
||||||
/* Deletion of valid account preference ID */
|
HashMap<String, Object> deletionError = this.accountNumberPreferencesHelper.deleteAccountNumberPreference(10,
|
||||||
for (HashMap<String, Object> preferenceId : preferenceIds) {
|
this.responseNotFoundError, "");
|
||||||
Integer id = (Integer) preferenceId.get("id");
|
Assert.assertEquals("error.msg.resource.not.found", deletionError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||||
HashMap<String, Object> delResponse = this.accountNumberPreferencesHelper
|
}
|
||||||
.deleteAccountNumberPreference(id, this.responseSpec, "");
|
|
||||||
System.out
|
private void validateDefaultAccountNumberGeneration() {
|
||||||
.println("Successfully deleted account number preference (ID: "
|
this.createAndValidateClientEntity(this.isAccountPreferenceSetUp);
|
||||||
+ delResponse.get("resourceId") + ")");
|
this.createAndValidateLoanEntity(this.isAccountPreferenceSetUp);
|
||||||
}
|
this.createAndValidateSavingsEntity(this.isAccountPreferenceSetUp);
|
||||||
/* Deletion of invalid account preference ID should fail */
|
}
|
||||||
System.out
|
|
||||||
.println("---------------------------------DELETING ACCOUNT NUMBER PREFERENCE WITH INVALID ID------------------------------------------");
|
private void validateAccountNumberGenerationWithPreferences() {
|
||||||
|
this.isAccountPreferenceSetUp = true;
|
||||||
HashMap<String, Object> deletionError = this.accountNumberPreferencesHelper
|
this.createAndValidateClientEntity(this.isAccountPreferenceSetUp);
|
||||||
.deleteAccountNumberPreference(10, this.responseNotFoundError,
|
this.createAndValidateLoanEntity(this.isAccountPreferenceSetUp);
|
||||||
"");
|
this.createAndValidateSavingsEntity(this.isAccountPreferenceSetUp);
|
||||||
Assert.assertEquals("error.msg.resource.not.found",
|
}
|
||||||
deletionError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
|
||||||
}
|
private void createAccountNumberPreference() {
|
||||||
|
this.clientAccountNumberPreferenceId = (Integer) this.accountNumberPreferencesHelper.createClientAccountNumberPreference(
|
||||||
private void validateDefaultAccountNumberGeneration() {
|
this.responseSpec, "resourceId");
|
||||||
this.createAndValidateClientEntity(this.isAccountPreferenceSetUp);
|
System.out.println("Successfully created account number preferences for Client (ID: " + this.clientAccountNumberPreferenceId);
|
||||||
this.createAndValidateLoanEntity(this.isAccountPreferenceSetUp);
|
|
||||||
this.createAndValidateSavingsEntity(this.isAccountPreferenceSetUp);
|
this.loanAccountNumberPreferenceId = (Integer) this.accountNumberPreferencesHelper.createLoanAccountNumberPreference(
|
||||||
}
|
this.responseSpec, "resourceId");
|
||||||
|
System.out.println("Successfully created account number preferences for Loan (ID: " + this.loanAccountNumberPreferenceId);
|
||||||
private void validateAccountNumberGenerationWithPreferences() {
|
|
||||||
this.isAccountPreferenceSetUp = true;
|
this.savingsAccountNumberPreferenceId = (Integer) this.accountNumberPreferencesHelper.createSavingsAccountNumberPreference(
|
||||||
this.createAndValidateClientEntity(this.isAccountPreferenceSetUp);
|
this.responseSpec, "resourceId");
|
||||||
this.createAndValidateLoanEntity(this.isAccountPreferenceSetUp);
|
System.out.println("Successfully created account number preferences for Savings (ID: " + this.savingsAccountNumberPreferenceId);
|
||||||
this.createAndValidateSavingsEntity(this.isAccountPreferenceSetUp);
|
|
||||||
}
|
this.accountNumberPreferencesHelper.verifyCreationOfAccountNumberPreferences(this.clientAccountNumberPreferenceId,
|
||||||
|
this.loanAccountNumberPreferenceId, this.savingsAccountNumberPreferenceId, this.responseSpec, this.requestSpec);
|
||||||
private void createAccountNumberPreference() {
|
|
||||||
this.clientAccountNumberPreferenceId = (Integer) this.accountNumberPreferencesHelper
|
this.createAccountNumberPreferenceInvalidData("1000", "1001");
|
||||||
.createClientAccountNumberPreference(this.responseSpec,
|
this.createAccountNumberPreferenceDuplicateData("1", "101");
|
||||||
"resourceId");
|
|
||||||
System.out
|
}
|
||||||
.println("Successfully created account number preferences for Client (ID: "
|
|
||||||
+ this.clientAccountNumberPreferenceId);
|
private void createAccountNumberPreferenceDuplicateData(final String accountType, final String prefixType) {
|
||||||
|
/* Creating account Preference with duplicate data should fail */
|
||||||
this.loanAccountNumberPreferenceId = (Integer) this.accountNumberPreferencesHelper
|
System.out
|
||||||
.createLoanAccountNumberPreference(this.responseSpec,
|
.println("---------------------------------CREATING ACCOUNT NUMBER PREFERENCE WITH DUPLICATE DATA------------------------------------------");
|
||||||
"resourceId");
|
|
||||||
System.out
|
HashMap<String, Object> creationError = this.accountNumberPreferencesHelper.createAccountNumberPreferenceWithInvalidData(
|
||||||
.println("Successfully created account number preferences for Loan (ID: "
|
this.responseForbiddenError, accountType, prefixType, "");
|
||||||
+ this.loanAccountNumberPreferenceId);
|
|
||||||
|
Assert.assertEquals("error.msg.account.number.format.duplicate.account.type",
|
||||||
this.savingsAccountNumberPreferenceId = (Integer) this.accountNumberPreferencesHelper
|
creationError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||||
.createSavingsAccountNumberPreference(this.responseSpec,
|
|
||||||
"resourceId");
|
}
|
||||||
System.out
|
|
||||||
.println("Successfully created account number preferences for Savings (ID: "
|
private void createAccountNumberPreferenceInvalidData(final String accountType, final String prefixType) {
|
||||||
+ this.savingsAccountNumberPreferenceId);
|
|
||||||
|
/* Creating account Preference with invalid data should fail */
|
||||||
this.accountNumberPreferencesHelper
|
System.out
|
||||||
.verifyCreationOfAccountNumberPreferences(
|
.println("---------------------------------CREATING ACCOUNT NUMBER PREFERENCE WITH INVALID DATA------------------------------------------");
|
||||||
this.clientAccountNumberPreferenceId,
|
|
||||||
this.loanAccountNumberPreferenceId,
|
HashMap<String, Object> creationError = this.accountNumberPreferencesHelper.createAccountNumberPreferenceWithInvalidData(
|
||||||
this.savingsAccountNumberPreferenceId,
|
this.responseValidationError, accountType, prefixType, "");
|
||||||
this.responseSpec, this.requestSpec);
|
|
||||||
|
if (creationError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE).equals(
|
||||||
this.createAccountNumberPreferenceInvalidData("1000", "1001");
|
"validation.msg.accountNumberFormat.accountType.is.not.within.expected.range")) {
|
||||||
this.createAccountNumberPreferenceDuplicateData("1", "101");
|
Assert.assertEquals("validation.msg.accountNumberFormat.accountType.is.not.within.expected.range",
|
||||||
|
creationError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||||
}
|
} else if (creationError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE).equals(
|
||||||
|
"validation.msg.accountNumberFormat.prefixType.is.not.one.of.expected.enumerations")) {
|
||||||
private void createAccountNumberPreferenceDuplicateData(
|
Assert.assertEquals("validation.msg.accountNumberFormat.prefixType.is.not.one.of.expected.enumerations",
|
||||||
final String accountType, final String prefixType) {
|
creationError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||||
/* Creating account Preference with duplicate data should fail */
|
}
|
||||||
System.out
|
}
|
||||||
.println("---------------------------------CREATING ACCOUNT NUMBER PREFERENCE WITH DUPLICATE DATA------------------------------------------");
|
|
||||||
|
private void updateAccountNumberPreference() {
|
||||||
HashMap<String, Object> creationError = this.accountNumberPreferencesHelper
|
HashMap<String, Object> accountNumberPreferences = this.accountNumberPreferencesHelper.updateAccountNumberPreference(
|
||||||
.createAccountNumberPreferenceWithInvalidData(
|
this.clientAccountNumberPreferenceId, "101", this.responseSpec, "");
|
||||||
this.responseForbiddenError, accountType, prefixType,
|
|
||||||
"");
|
System.out.println("--------------------------UPDATION SUCCESSFUL FOR ACCOUNT NUMBER PREFERENCE ID "
|
||||||
|
+ accountNumberPreferences.get("resourceId"));
|
||||||
Assert.assertEquals(
|
|
||||||
"error.msg.account.number.format.duplicate.account.type",
|
this.accountNumberPreferencesHelper.verifyUpdationOfAccountNumberPreferences((Integer) accountNumberPreferences.get("resourceId"),
|
||||||
creationError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
this.responseSpec, this.requestSpec);
|
||||||
|
|
||||||
}
|
/* Update invalid account preference id should fail */
|
||||||
|
System.out
|
||||||
private void createAccountNumberPreferenceInvalidData(
|
.println("---------------------------------UPDATING ACCOUNT NUMBER PREFERENCE WITH INVALID DATA------------------------------------------");
|
||||||
final String accountType, final String prefixType) {
|
|
||||||
|
/* Invalid Account Type */
|
||||||
/* Creating account Preference with invalid data should fail */
|
HashMap<String, Object> updationError = this.accountNumberPreferencesHelper.updateAccountNumberPreference(9999, "101",
|
||||||
System.out
|
this.responseNotFoundError, "");
|
||||||
.println("---------------------------------CREATING ACCOUNT NUMBER PREFERENCE WITH INVALID DATA------------------------------------------");
|
if (updationError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE).equals("error.msg.resource.not.found")) {
|
||||||
|
Assert.assertEquals("error.msg.resource.not.found", updationError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||||
HashMap<String, Object> creationError = this.accountNumberPreferencesHelper
|
}
|
||||||
.createAccountNumberPreferenceWithInvalidData(
|
/* Invalid Prefix Type */
|
||||||
this.responseValidationError, accountType, prefixType,
|
HashMap<String, Object> updationError1 = this.accountNumberPreferencesHelper.updateAccountNumberPreference(
|
||||||
"");
|
this.clientAccountNumberPreferenceId, "103", this.responseValidationError, "");
|
||||||
|
|
||||||
if (creationError
|
Assert.assertEquals("validation.msg.validation.errors.exist", updationError1.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||||
.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)
|
|
||||||
.equals("validation.msg.accountNumberFormat.accountType.is.not.within.expected.range")) {
|
}
|
||||||
Assert.assertEquals(
|
|
||||||
"validation.msg.accountNumberFormat.accountType.is.not.within.expected.range",
|
private void createAndValidateClientEntity(Boolean isAccountPreferenceSetUp) {
|
||||||
creationError
|
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||||
.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
if (isAccountPreferenceSetUp) {
|
||||||
} else if (creationError
|
this.createAndValidateClientBasedOnAccountPreference();
|
||||||
.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)
|
} else {
|
||||||
.equals("validation.msg.accountNumberFormat.prefixType.is.not.one.of.expected.enumerations")) {
|
this.createAndValidateClientWithoutAccountPreference();
|
||||||
Assert.assertEquals(
|
}
|
||||||
"validation.msg.accountNumberFormat.prefixType.is.not.one.of.expected.enumerations",
|
}
|
||||||
creationError
|
|
||||||
.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
private void createAndValidateClientWithoutAccountPreference() {
|
||||||
}
|
this.clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||||
}
|
Assert.assertNotNull(this.clientId);
|
||||||
|
String clientAccountNo = (String) ClientHelper.getClient(requestSpec, responseSpec, this.clientId.toString(), "accountNo");
|
||||||
private void updateAccountNumberPreference() {
|
validateAccountNumberLengthAndStartsWithPrefix(clientAccountNo, null);
|
||||||
HashMap<String, Object> accountNumberPreferences = this.accountNumberPreferencesHelper
|
}
|
||||||
.updateAccountNumberPreference(
|
|
||||||
this.clientAccountNumberPreferenceId, "101",
|
private void createAndValidateClientBasedOnAccountPreference() {
|
||||||
this.responseSpec, "");
|
final String codeName = "ClientType";
|
||||||
|
String clientAccountNo = null;
|
||||||
System.out
|
String clientPrefixName = (String) this.accountNumberPreferencesHelper.getAccountNumberPreference(
|
||||||
.println("--------------------------UPDATION SUCCESSFUL FOR ACCOUNT NUMBER PREFERENCE ID "
|
this.clientAccountNumberPreferenceId, "prefixType.value");
|
||||||
+ accountNumberPreferences.get("resourceId"));
|
if (clientPrefixName.equals(this.clientTypeName)) {
|
||||||
|
|
||||||
this.accountNumberPreferencesHelper
|
/* Retrieve Code id for the Code "ClientType" */
|
||||||
.verifyUpdationOfAccountNumberPreferences(
|
HashMap<String, Object> code = CodeHelper.getCodeByName(this.requestSpec, this.responseSpec, codeName);
|
||||||
(Integer) accountNumberPreferences.get("resourceId"),
|
this.clientTypeCodeId = (Integer) code.get("id");
|
||||||
this.responseSpec, this.requestSpec);
|
|
||||||
|
/* Retrieve/Create Code Values for the Code "ClientType" */
|
||||||
/* Update invalid account preference id should fail */
|
HashMap<String, Object> codeValue = CodeHelper.retrieveOrCreateCodeValue(this.clientTypeCodeId, this.requestSpec,
|
||||||
System.out
|
this.responseSpec);
|
||||||
.println("---------------------------------UPDATING ACCOUNT NUMBER PREFERENCE WITH INVALID DATA------------------------------------------");
|
|
||||||
|
this.clientCodeValueName = (String) codeValue.get("name");
|
||||||
/* Invalid Account Type */
|
this.clientCodeValueId = (Integer) codeValue.get("id");
|
||||||
HashMap<String, Object> updationError = this.accountNumberPreferencesHelper
|
|
||||||
.updateAccountNumberPreference(9999, "101",
|
/* Create Client with Client Type */
|
||||||
this.responseNotFoundError, "");
|
this.clientId = ClientHelper.createClientForAccountPreference(this.requestSpec, this.responseSpec, this.clientCodeValueId,
|
||||||
if (updationError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)
|
"clientId");
|
||||||
.equals("error.msg.resource.not.found")) {
|
|
||||||
Assert.assertEquals("error.msg.resource.not.found", updationError
|
Assert.assertNotNull(clientId);
|
||||||
.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
|
||||||
}
|
clientAccountNo = (String) ClientHelper.getClient(this.requestSpec, this.responseSpec, this.clientId.toString(), "accountNo");
|
||||||
/* Invalid Prefix Type */
|
this.validateAccountNumberLengthAndStartsWithPrefix(clientAccountNo, this.clientCodeValueName);
|
||||||
HashMap<String, Object> updationError1 = this.accountNumberPreferencesHelper
|
|
||||||
.updateAccountNumberPreference(
|
} else if (clientPrefixName.equals(this.officeName)) {
|
||||||
this.clientAccountNumberPreferenceId, "103",
|
this.clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||||
this.responseValidationError, "");
|
Assert.assertNotNull(clientId);
|
||||||
|
clientAccountNo = (String) ClientHelper.getClient(requestSpec, responseSpec, this.clientId.toString(), "accountNo");
|
||||||
Assert.assertEquals("validation.msg.validation.errors.exist",
|
String officeName = (String) ClientHelper.getClient(requestSpec, responseSpec, this.clientId.toString(), "officeName");
|
||||||
updationError1.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
this.validateAccountNumberLengthAndStartsWithPrefix(clientAccountNo, officeName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createAndValidateClientEntity(Boolean isAccountPreferenceSetUp) {
|
private void validateAccountNumberLengthAndStartsWithPrefix(final String accountNumber, final String prefix) {
|
||||||
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200)
|
if (prefix != null) {
|
||||||
.build();
|
Assert.assertEquals(accountNumber.length(), prefix.length() + 9);
|
||||||
if (isAccountPreferenceSetUp) {
|
Assert.assertTrue(accountNumber.startsWith(prefix));
|
||||||
this.createAndValidateClientBasedOnAccountPreference();
|
} else {
|
||||||
} else {
|
Assert.assertEquals(accountNumber.length(), 9);
|
||||||
this.createAndValidateClientWithoutAccountPreference();
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
private void createLoanProduct() {
|
||||||
private void createAndValidateClientWithoutAccountPreference() {
|
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||||
this.clientId = ClientHelper.createClient(this.requestSpec,
|
|
||||||
this.responseSpec);
|
System.out.println("---------------------------------CREATING LOAN PRODUCT------------------------------------------");
|
||||||
Assert.assertNotNull(this.clientId);
|
|
||||||
String clientAccountNo = (String) ClientHelper.getClient(requestSpec,
|
final String loanProductJSON = new LoanProductTestBuilder().withPrincipal(loanPrincipalAmount)
|
||||||
responseSpec, this.clientId.toString(), "accountNo");
|
.withNumberOfRepayments(numberOfRepayments).withinterestRatePerPeriod(interestRatePerPeriod)
|
||||||
validateAccountNumberLengthAndStartsWithPrefix(clientAccountNo, null);
|
.withInterestRateFrequencyTypeAsYear().build(null);
|
||||||
}
|
|
||||||
|
this.loanProductId = this.loanTransactionHelper.getLoanProductId(loanProductJSON);
|
||||||
private void createAndValidateClientBasedOnAccountPreference() {
|
System.out.println("Successfully created loan product (ID: " + this.loanProductId + ")");
|
||||||
final String codeName = "ClientType";
|
}
|
||||||
String clientAccountNo = null;
|
|
||||||
String clientPrefixName = (String) this.accountNumberPreferencesHelper
|
private void createAndValidateLoanEntity(Boolean isAccountPreferenceSetUp) {
|
||||||
.getAccountNumberPreference(
|
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||||
this.clientAccountNumberPreferenceId,
|
|
||||||
"prefixType.value");
|
System.out.println("---------------------------------NEW LOAN APPLICATION------------------------------------------");
|
||||||
if (clientPrefixName.equals(this.clientTypeName)) {
|
|
||||||
|
final String loanApplicationJSON = new LoanApplicationTestBuilder().withPrincipal(loanPrincipalAmount)
|
||||||
/* Retrieve Code id for the Code "ClientType" */
|
.withLoanTermFrequency(numberOfRepayments).withLoanTermFrequencyAsMonths().withNumberOfRepayments(numberOfRepayments)
|
||||||
HashMap<String, Object> code = CodeHelper
|
.withRepaymentEveryAfter("1").withRepaymentFrequencyTypeAsMonths().withAmortizationTypeAsEqualInstallments()
|
||||||
.getCodeByName(this.requestSpec, this.responseSpec,
|
.withInterestCalculationPeriodTypeAsDays().withInterestRatePerPeriod(interestRatePerPeriod).withLoanTermFrequencyAsMonths()
|
||||||
codeName);
|
.withSubmittedOnDate(dateString).withExpectedDisbursementDate(dateString).withPrincipalGrace("2").withInterestGrace("2")
|
||||||
this.clientTypeCodeId = (Integer) code.get("id");
|
.build(this.clientId.toString(), this.loanProductId.toString(), null);
|
||||||
|
|
||||||
/* Retrieve/Create Code Values for the Code "ClientType" */
|
System.out.println("Loan Application :" + loanApplicationJSON);
|
||||||
HashMap<String, Object> codeValue = CodeHelper
|
|
||||||
.retrieveOrCreateCodeValue(this.clientTypeCodeId,
|
this.loanId = this.loanTransactionHelper.getLoanId(loanApplicationJSON);
|
||||||
this.requestSpec, this.responseSpec);
|
String loanAccountNo = (String) this.loanTransactionHelper.getLoanDetail(this.requestSpec, this.responseSpec, this.loanId,
|
||||||
|
"accountNo");
|
||||||
this.clientCodeValueName = (String) codeValue.get("name");
|
|
||||||
this.clientCodeValueId = (Integer) codeValue.get("id");
|
if (isAccountPreferenceSetUp) {
|
||||||
|
String loanPrefixName = (String) this.accountNumberPreferencesHelper.getAccountNumberPreference(
|
||||||
/* Create Client with Client Type */
|
this.loanAccountNumberPreferenceId, "prefixType.value");
|
||||||
this.clientId = ClientHelper.createClientForAccountPreference(
|
if (loanPrefixName.equals(this.officeName)) {
|
||||||
this.requestSpec, this.responseSpec,
|
String loanOfficeName = (String) ClientHelper.getClient(requestSpec, responseSpec, this.clientId.toString(), "officeName");
|
||||||
this.clientCodeValueId, "clientId");
|
this.validateAccountNumberLengthAndStartsWithPrefix(loanAccountNo, loanOfficeName);
|
||||||
|
} else if (loanPrefixName.equals(this.loanShortName)) {
|
||||||
Assert.assertNotNull(clientId);
|
String loanShortName = (String) this.loanTransactionHelper.getLoanProductDetail(this.requestSpec, this.responseSpec,
|
||||||
|
this.loanProductId, "shortName");
|
||||||
clientAccountNo = (String) ClientHelper.getClient(this.requestSpec,
|
this.validateAccountNumberLengthAndStartsWithPrefix(loanAccountNo, loanShortName);
|
||||||
this.responseSpec, this.clientId.toString(), "accountNo");
|
}
|
||||||
this.validateAccountNumberLengthAndStartsWithPrefix(
|
System.out.println("SUCCESSFULLY CREATED LOAN APPLICATION BASED ON ACCOUNT PREFERENCES (ID: " + this.loanId + ")");
|
||||||
clientAccountNo, this.clientCodeValueName);
|
} else {
|
||||||
|
this.validateAccountNumberLengthAndStartsWithPrefix(loanAccountNo, null);
|
||||||
} else if (clientPrefixName.equals(this.officeName)) {
|
System.out.println("SUCCESSFULLY CREATED LOAN APPLICATION (ID: " + loanId + ")");
|
||||||
this.clientId = ClientHelper.createClient(this.requestSpec,
|
}
|
||||||
this.responseSpec);
|
}
|
||||||
Assert.assertNotNull(clientId);
|
|
||||||
clientAccountNo = (String) ClientHelper.getClient(requestSpec,
|
private void createSavingsProduct() {
|
||||||
responseSpec, this.clientId.toString(), "accountNo");
|
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||||
String officeName = (String) ClientHelper.getClient(requestSpec,
|
|
||||||
responseSpec, this.clientId.toString(), "officeName");
|
System.out.println("------------------------------CREATING NEW SAVINGS PRODUCT ---------------------------------------");
|
||||||
this.validateAccountNumberLengthAndStartsWithPrefix(
|
|
||||||
clientAccountNo, officeName);
|
SavingsProductHelper savingsProductHelper = new SavingsProductHelper();
|
||||||
}
|
|
||||||
}
|
final String savingsProductJSON = savingsProductHelper
|
||||||
|
//
|
||||||
private void validateAccountNumberLengthAndStartsWithPrefix(
|
.withInterestCompoundingPeriodTypeAsDaily()
|
||||||
final String accountNumber, final String prefix) {
|
//
|
||||||
if (prefix != null) {
|
.withInterestPostingPeriodTypeAsMonthly()
|
||||||
Assert.assertEquals(accountNumber.length(), prefix.length() + 9);
|
//
|
||||||
Assert.assertTrue(accountNumber.startsWith(prefix));
|
.withInterestCalculationPeriodTypeAsDailyBalance()
|
||||||
} else {
|
//
|
||||||
Assert.assertEquals(accountNumber.length(), 9);
|
.withMinBalanceForInterestCalculation(minBalanceForInterestCalculation)
|
||||||
}
|
//
|
||||||
}
|
.withMinRequiredBalance(minRequiredBalance).withEnforceMinRequiredBalance(enforceMinRequiredBalance)
|
||||||
|
.withMinimumOpenningBalance(this.MINIMUM_OPENING_BALANCE).build();
|
||||||
private void createLoanProduct() {
|
this.savingsProductId = SavingsProductHelper.createSavingsProduct(savingsProductJSON, this.requestSpec, this.responseSpec);
|
||||||
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200)
|
System.out.println("Sucessfully created savings product (ID: " + this.savingsProductId + ")");
|
||||||
.build();
|
|
||||||
|
}
|
||||||
System.out
|
|
||||||
.println("---------------------------------CREATING LOAN PRODUCT------------------------------------------");
|
private void createAndValidateSavingsEntity(Boolean isAccountPreferenceSetUp) {
|
||||||
|
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||||
final String loanProductJSON = new LoanProductTestBuilder()
|
|
||||||
.withPrincipal(loanPrincipalAmount)
|
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
|
||||||
.withNumberOfRepayments(numberOfRepayments)
|
|
||||||
.withinterestRatePerPeriod(interestRatePerPeriod)
|
this.savingsId = this.savingsAccountHelper
|
||||||
.withInterestRateFrequencyTypeAsYear().build(null);
|
.applyForSavingsApplication(this.clientId, this.savingsProductId, ACCOUNT_TYPE_INDIVIDUAL);
|
||||||
|
|
||||||
this.loanProductId = this.loanTransactionHelper
|
String savingsAccountNo = (String) this.savingsAccountHelper.getSavingsAccountDetail(this.savingsId, "accountNo");
|
||||||
.getLoanProductId(loanProductJSON);
|
|
||||||
System.out.println("Successfully created loan product (ID: "
|
if (isAccountPreferenceSetUp) {
|
||||||
+ this.loanProductId + ")");
|
String savingsPrefixName = (String) this.accountNumberPreferencesHelper.getAccountNumberPreference(
|
||||||
}
|
this.savingsAccountNumberPreferenceId, "prefixType.value");
|
||||||
|
|
||||||
private void createAndValidateLoanEntity(Boolean isAccountPreferenceSetUp) {
|
if (savingsPrefixName.equals(this.officeName)) {
|
||||||
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200)
|
String savingsOfficeName = (String) ClientHelper.getClient(requestSpec, responseSpec, this.clientId.toString(),
|
||||||
.build();
|
"officeName");
|
||||||
|
this.validateAccountNumberLengthAndStartsWithPrefix(savingsAccountNo, savingsOfficeName);
|
||||||
System.out
|
} else if (savingsPrefixName.equals(this.savingsShortName)) {
|
||||||
.println("---------------------------------NEW LOAN APPLICATION------------------------------------------");
|
String loanShortName = (String) this.savingsAccountHelper.getSavingsAccountDetail(this.savingsId, "shortName");
|
||||||
|
this.validateAccountNumberLengthAndStartsWithPrefix(savingsAccountNo, loanShortName);
|
||||||
final String loanApplicationJSON = new LoanApplicationTestBuilder()
|
}
|
||||||
.withPrincipal(loanPrincipalAmount)
|
System.out.println("SUCCESSFULLY CREATED SAVINGS APPLICATION BASED ON ACCOUNT PREFERENCES (ID: " + this.loanId + ")");
|
||||||
.withLoanTermFrequency(numberOfRepayments)
|
} else {
|
||||||
.withLoanTermFrequencyAsMonths()
|
this.validateAccountNumberLengthAndStartsWithPrefix(savingsAccountNo, null);
|
||||||
.withNumberOfRepayments(numberOfRepayments)
|
System.out.println("SUCCESSFULLY CREATED SAVINGS APPLICATION (ID: " + this.savingsId + ")");
|
||||||
.withRepaymentEveryAfter("1")
|
}
|
||||||
.withRepaymentFrequencyTypeAsMonths()
|
}
|
||||||
.withAmortizationTypeAsEqualInstallments()
|
|
||||||
.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);
|
|
||||||
String loanAccountNo = (String) this.loanTransactionHelper
|
|
||||||
.getLoanDetail(this.requestSpec, this.responseSpec,
|
|
||||||
this.loanId, "accountNo");
|
|
||||||
|
|
||||||
if (isAccountPreferenceSetUp) {
|
|
||||||
String loanPrefixName = (String) this.accountNumberPreferencesHelper
|
|
||||||
.getAccountNumberPreference(
|
|
||||||
this.loanAccountNumberPreferenceId,
|
|
||||||
"prefixType.value");
|
|
||||||
if (loanPrefixName.equals(this.officeName)) {
|
|
||||||
String loanOfficeName = (String) ClientHelper.getClient(
|
|
||||||
requestSpec, responseSpec, this.clientId.toString(),
|
|
||||||
"officeName");
|
|
||||||
this.validateAccountNumberLengthAndStartsWithPrefix(
|
|
||||||
loanAccountNo, loanOfficeName);
|
|
||||||
} else if (loanPrefixName.equals(this.loanShortName)) {
|
|
||||||
String loanShortName = (String) this.loanTransactionHelper
|
|
||||||
.getLoanProductDetail(this.requestSpec,
|
|
||||||
this.responseSpec, this.loanProductId,
|
|
||||||
"shortName");
|
|
||||||
this.validateAccountNumberLengthAndStartsWithPrefix(
|
|
||||||
loanAccountNo, loanShortName);
|
|
||||||
}
|
|
||||||
System.out
|
|
||||||
.println("SUCCESSFULLY CREATED LOAN APPLICATION BASED ON ACCOUNT PREFERENCES (ID: "
|
|
||||||
+ this.loanId + ")");
|
|
||||||
} else {
|
|
||||||
this.validateAccountNumberLengthAndStartsWithPrefix(loanAccountNo,
|
|
||||||
null);
|
|
||||||
System.out.println("SUCCESSFULLY CREATED LOAN APPLICATION (ID: "
|
|
||||||
+ loanId + ")");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createSavingsProduct() {
|
|
||||||
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
System.out
|
|
||||||
.println("------------------------------CREATING NEW SAVINGS PRODUCT ---------------------------------------");
|
|
||||||
|
|
||||||
SavingsProductHelper savingsProductHelper = new SavingsProductHelper();
|
|
||||||
|
|
||||||
final String savingsProductJSON = savingsProductHelper
|
|
||||||
//
|
|
||||||
.withInterestCompoundingPeriodTypeAsDaily()
|
|
||||||
//
|
|
||||||
.withInterestPostingPeriodTypeAsMonthly()
|
|
||||||
//
|
|
||||||
.withInterestCalculationPeriodTypeAsDailyBalance()
|
|
||||||
//
|
|
||||||
.withMinBalanceForInterestCalculation(
|
|
||||||
minBalanceForInterestCalculation)
|
|
||||||
//
|
|
||||||
.withMinRequiredBalance(minRequiredBalance)
|
|
||||||
.withEnforceMinRequiredBalance(enforceMinRequiredBalance)
|
|
||||||
.withMinimumOpenningBalance(this.MINIMUM_OPENING_BALANCE)
|
|
||||||
.build();
|
|
||||||
this.savingsProductId = SavingsProductHelper.createSavingsProduct(
|
|
||||||
savingsProductJSON, this.requestSpec, this.responseSpec);
|
|
||||||
System.out.println("Sucessfully created savings product (ID: "
|
|
||||||
+ this.savingsProductId + ")");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createAndValidateSavingsEntity(Boolean isAccountPreferenceSetUp) {
|
|
||||||
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec,
|
|
||||||
this.responseSpec);
|
|
||||||
|
|
||||||
this.savingsId = this.savingsAccountHelper.applyForSavingsApplication(
|
|
||||||
this.clientId, this.savingsProductId, ACCOUNT_TYPE_INDIVIDUAL);
|
|
||||||
|
|
||||||
String savingsAccountNo = (String) this.savingsAccountHelper
|
|
||||||
.getSavingsAccountDetail(this.savingsId, "accountNo");
|
|
||||||
|
|
||||||
if (isAccountPreferenceSetUp) {
|
|
||||||
String savingsPrefixName = (String) this.accountNumberPreferencesHelper
|
|
||||||
.getAccountNumberPreference(
|
|
||||||
this.savingsAccountNumberPreferenceId,
|
|
||||||
"prefixType.value");
|
|
||||||
|
|
||||||
if (savingsPrefixName.equals(this.officeName)) {
|
|
||||||
String savingsOfficeName = (String) ClientHelper.getClient(
|
|
||||||
requestSpec, responseSpec, this.clientId.toString(),
|
|
||||||
"officeName");
|
|
||||||
this.validateAccountNumberLengthAndStartsWithPrefix(
|
|
||||||
savingsAccountNo, savingsOfficeName);
|
|
||||||
} else if (savingsPrefixName.equals(this.savingsShortName)) {
|
|
||||||
String loanShortName = (String) this.savingsAccountHelper
|
|
||||||
.getSavingsAccountDetail(this.savingsId, "shortName");
|
|
||||||
this.validateAccountNumberLengthAndStartsWithPrefix(
|
|
||||||
savingsAccountNo, loanShortName);
|
|
||||||
}
|
|
||||||
System.out
|
|
||||||
.println("SUCCESSFULLY CREATED SAVINGS APPLICATION BASED ON ACCOUNT PREFERENCES (ID: "
|
|
||||||
+ this.loanId + ")");
|
|
||||||
} else {
|
|
||||||
this.validateAccountNumberLengthAndStartsWithPrefix(
|
|
||||||
savingsAccountNo, null);
|
|
||||||
System.out.println("SUCCESSFULLY CREATED SAVINGS APPLICATION (ID: "
|
|
||||||
+ this.savingsId + ")");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+80
-138
@@ -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;
|
||||||
@@ -832,154 +831,97 @@ public final class LoanApplicationCommandFromApiJsonHelper {
|
|||||||
"Validation errors exist.", dataValidationErrors); }
|
"Validation errors exist.", dataValidationErrors); }
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
element);
|
||||||
final JsonArray variationArray = this.fromApiJsonHelper
|
if (variationArray != null) {
|
||||||
.extractJsonArrayNamed(
|
for (int i = 0; i < variationArray.size(); i++) {
|
||||||
LoanApiConstants.disbursementDataParameterName,
|
final JsonObject jsonObject1 = variationArray.get(i).getAsJsonObject();
|
||||||
element);
|
LocalDate date1 = this.fromApiJsonHelper.extractLocalDateNamed(LoanApiConstants.disbursementDateParameterName, jsonObject1,
|
||||||
for(int i=0 ; i< variationArray.size();i++){
|
dateFormat, locale);
|
||||||
final JsonObject jsonObject1 = variationArray.get(i)
|
|
||||||
.getAsJsonObject();
|
|
||||||
LocalDate date1 = this.fromApiJsonHelper
|
|
||||||
.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
|
jsonObject2, dateFormat, locale);
|
||||||
.extractLocalDateNamed(
|
if (date1.isAfter(date2)) {
|
||||||
LoanApiConstants.disbursementDateParameterName,
|
baseDataValidator.reset().parameter(LoanApiConstants.disbursementDataParameterName)
|
||||||
jsonObject2, dateFormat, locale);
|
.failWithCode(LoanApiConstants.DISBURSEMENT_DATES_NOT_IN_ORDER);
|
||||||
if(date1.isAfter(date2)){
|
}
|
||||||
baseDataValidator
|
}
|
||||||
.reset()
|
}
|
||||||
.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(
|
BigDecimal tatalDisbursement = BigDecimal.ZERO;
|
||||||
LoanApiConstants.disbursementDataParameterName, element)
|
boolean isFirstinstallmentOnExpectedDisbursementDate = false;
|
||||||
&& expectedDisbursement != null && totalPrincipal != null) {
|
final JsonArray variationArray = this.fromApiJsonHelper.extractJsonArrayNamed(LoanApiConstants.disbursementDataParameterName,
|
||||||
BigDecimal tatalDisbursement = BigDecimal.ZERO;
|
element);
|
||||||
boolean isFirstinstallmentOnExpectedDisbursementDate = false;
|
List<LocalDate> expectedDisbursementDates = new ArrayList<>();
|
||||||
final JsonArray variationArray = this.fromApiJsonHelper
|
if (variationArray != null && variationArray.size() > 0) {
|
||||||
.extractJsonArrayNamed(
|
int i = 0;
|
||||||
LoanApiConstants.disbursementDataParameterName,
|
do {
|
||||||
element);
|
final JsonObject jsonObject = variationArray.get(i).getAsJsonObject();
|
||||||
List<LocalDate> expectedDisbursementDates = new ArrayList<>();
|
LocalDate expectedDisbursementDate = this.fromApiJsonHelper.extractLocalDateNamed(
|
||||||
if (variationArray != null && variationArray.size() > 0) {
|
LoanApiConstants.disbursementDateParameterName, jsonObject, dateFormat, locale);
|
||||||
int i = 0;
|
if (expectedDisbursementDates.contains(expectedDisbursementDate)) {
|
||||||
do {
|
baseDataValidator.reset().parameter(LoanApiConstants.disbursementDateParameterName)
|
||||||
final JsonObject jsonObject = variationArray.get(i)
|
.failWithCode(LoanApiConstants.DISBURSEMENT_DATE_UNIQUE_ERROR);
|
||||||
.getAsJsonObject();
|
}
|
||||||
LocalDate expectedDisbursementDate = this.fromApiJsonHelper
|
if (expectedDisbursementDate.isBefore(expectedDisbursement)) {
|
||||||
.extractLocalDateNamed(
|
baseDataValidator.reset().parameter(LoanApiConstants.disbursementDataParameterName)
|
||||||
LoanApiConstants.disbursementDateParameterName,
|
.failWithCode(LoanApiConstants.DISBURSEMENT_DATE_BEFORE_ERROR);
|
||||||
jsonObject, dateFormat, locale);
|
}
|
||||||
if (expectedDisbursementDates
|
expectedDisbursementDates.add(expectedDisbursementDate);
|
||||||
.contains(expectedDisbursementDate)) {
|
BigDecimal principal = this.fromApiJsonHelper.extractBigDecimalNamed(
|
||||||
baseDataValidator
|
LoanApiConstants.disbursementPrincipalParameterName, jsonObject, locale);
|
||||||
.reset()
|
baseDataValidator.reset().parameter(LoanApiConstants.disbursementDataParameterName)
|
||||||
.parameter(
|
.parameterAtIndexArray(LoanApiConstants.disbursementPrincipalParameterName, i).value(principal).notBlank();
|
||||||
LoanApiConstants.disbursementDateParameterName)
|
if (principal != null) {
|
||||||
.failWithCode(
|
tatalDisbursement = tatalDisbursement.add(principal);
|
||||||
LoanApiConstants.DISBURSEMENT_DATE_UNIQUE_ERROR);
|
}
|
||||||
}
|
|
||||||
if(expectedDisbursementDate.isBefore(expectedDisbursement)){
|
|
||||||
baseDataValidator
|
|
||||||
.reset()
|
|
||||||
.parameter(
|
|
||||||
LoanApiConstants.disbursementDataParameterName)
|
|
||||||
.failWithCode(
|
|
||||||
LoanApiConstants.DISBURSEMENT_DATE_BEFORE_ERROR);
|
|
||||||
}
|
|
||||||
expectedDisbursementDates.add(expectedDisbursementDate);
|
|
||||||
BigDecimal principal = this.fromApiJsonHelper
|
|
||||||
.extractBigDecimalNamed(
|
|
||||||
LoanApiConstants.disbursementPrincipalParameterName,
|
|
||||||
jsonObject, locale);
|
|
||||||
baseDataValidator
|
|
||||||
.reset()
|
|
||||||
.parameter(
|
|
||||||
LoanApiConstants.disbursementDataParameterName)
|
|
||||||
.parameterAtIndexArray(
|
|
||||||
LoanApiConstants.disbursementPrincipalParameterName,
|
|
||||||
i).value(principal).notBlank();
|
|
||||||
if (principal != null) {
|
|
||||||
tatalDisbursement = tatalDisbursement.add(principal);
|
|
||||||
}
|
|
||||||
|
|
||||||
baseDataValidator
|
baseDataValidator.reset().parameter(LoanApiConstants.disbursementDataParameterName)
|
||||||
.reset()
|
.parameterAtIndexArray(LoanApiConstants.disbursementDateParameterName, i).value(expectedDisbursementDate)
|
||||||
.parameter(
|
.notNull();
|
||||||
LoanApiConstants.disbursementDataParameterName)
|
|
||||||
.parameterAtIndexArray(
|
|
||||||
LoanApiConstants.disbursementDateParameterName,
|
|
||||||
i).value(expectedDisbursementDate)
|
|
||||||
.notNull();
|
|
||||||
|
|
||||||
if (expectedDisbursement.equals(expectedDisbursementDate)) {
|
if (expectedDisbursement.equals(expectedDisbursementDate)) {
|
||||||
isFirstinstallmentOnExpectedDisbursementDate = true;
|
isFirstinstallmentOnExpectedDisbursementDate = true;
|
||||||
}
|
}
|
||||||
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)
|
final String interestTypeParameterName = "interestType";
|
||||||
.failWithCode(
|
final Integer interestType = this.fromApiJsonHelper.extractIntegerSansLocaleNamed(interestTypeParameterName, element);
|
||||||
LoanApiConstants.APPROVED_AMOUNT_IS_LESS_THAN_SUM_OF_TRANCHES);
|
baseDataValidator.reset().parameter(interestTypeParameterName).value(interestType).ignoreIfNull()
|
||||||
}
|
.integerSameAsNumber(InterestMethod.DECLINING_BALANCE.getValue());
|
||||||
final String interestTypeParameterName = "interestType";
|
|
||||||
final Integer interestType = this.fromApiJsonHelper
|
|
||||||
.extractIntegerSansLocaleNamed(
|
|
||||||
interestTypeParameterName, element);
|
|
||||||
baseDataValidator
|
|
||||||
.reset()
|
|
||||||
.parameter(interestTypeParameterName)
|
|
||||||
.value(interestType)
|
|
||||||
.ignoreIfNull()
|
|
||||||
.integerSameAsNumber(
|
|
||||||
InterestMethod.DECLINING_BALANCE.getValue());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void validateRecalcuationFrequency(final LocalDate recalculationFrequencyDate, final LocalDate expectedDisbursementDate,
|
public void validateRecalcuationFrequency(final LocalDate recalculationFrequencyDate, final LocalDate expectedDisbursementDate,
|
||||||
final List<ApiParameterError> dataValidationErrors) {
|
final List<ApiParameterError> dataValidationErrors) {
|
||||||
|
|||||||
Reference in New Issue
Block a user