formatting test cases

This commit is contained in:
Vishwas Babu A J
2014-12-13 09:38:43 -08:00
parent 5d5d79d46c
commit c94a59c66f
@@ -1,27 +1,28 @@
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;
@@ -34,13 +35,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;
@@ -53,27 +54,25 @@ 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(ContentType.JSON).build(); this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
this.requestSpec.header("Authorization","Basic "+ Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
this.responseValidationError = new ResponseSpecBuilder().expectStatusCode(400).build(); this.responseValidationError = new ResponseSpecBuilder().expectStatusCode(400).build();
this.responseNotFoundError = new ResponseSpecBuilder().expectStatusCode(404).build(); this.responseNotFoundError = new ResponseSpecBuilder().expectStatusCode(404).build();
this.responseForbiddenError = new ResponseSpecBuilder().expectStatusCode(403).build(); this.responseForbiddenError = new ResponseSpecBuilder().expectStatusCode(403).build();
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec); this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
this.accountNumberPreferencesHelper = new AccountNumberPreferencesHelper( this.accountNumberPreferencesHelper = new AccountNumberPreferencesHelper(this.requestSpec, this.responseSpec);
this.requestSpec, this.responseSpec);
} }
@Test @Test
public void testAccountNumberPreferences() { public void testAccountNumberPreferences() {
@@ -83,19 +82,28 @@ public class AccountNumberPreferencesTest {
/* Ensure no account number preferences are present in the system */ /* Ensure no account number preferences are present in the system */
this.deleteAllAccountNumberPreferences(); this.deleteAllAccountNumberPreferences();
/* Validate the default account number generation rules for clients, loans and savings accounts.*/ /*
* Validate the default account number generation rules for clients,
* loans and savings accounts.
*/
this.validateDefaultAccountNumberGeneration(); this.validateDefaultAccountNumberGeneration();
/* Create and Validate account number preferences */ /* Create and Validate account number preferences */
this.createAccountNumberPreference(); this.createAccountNumberPreference();
/* Validate account number preference rules apply to Clients,Loans and Saving Accounts */ /*
* Validate account number preference rules apply to Clients,Loans and
* Saving Accounts
*/
this.validateAccountNumberGenerationWithPreferences(); this.validateAccountNumberGenerationWithPreferences();
/* Validate account number preferences Updation */ /* Validate account number preferences Updation */
this.updateAccountNumberPreference(); this.updateAccountNumberPreference();
/* Validate account number preference rules apply to Clients,Loans and Saving Accounts after Updation */ /*
* Validate account number preference rules apply to Clients,Loans and
* Saving Accounts after Updation
*/
this.validateAccountNumberGenerationWithPreferences(); this.validateAccountNumberGenerationWithPreferences();
/* Delete all account number preferences */ /* Delete all account number preferences */
@@ -103,128 +111,121 @@ public class AccountNumberPreferencesTest {
} }
private void createLoanAndSavingsProduct(){ private void createLoanAndSavingsProduct() {
this.createLoanProduct(); this.createLoanProduct();
this.createSavingsProduct(); this.createSavingsProduct();
} }
private void deleteAllAccountNumberPreferences() { private void deleteAllAccountNumberPreferences() {
ArrayList<HashMap<String,Object>> preferenceIds = this.accountNumberPreferencesHelper.getAllAccountNumberPreferences(); ArrayList<HashMap<String, Object>> preferenceIds = this.accountNumberPreferencesHelper.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= (HashMap<String,Object>) this.accountNumberPreferencesHelper.deleteAccountNumberPreference(id, this.responseSpec,""); HashMap<String, Object> delResponse = this.accountNumberPreferencesHelper.deleteAccountNumberPreference(id, this.responseSpec,
System.out.println("Successfully deleted account number preference (ID: "+ delResponse.get("resourceId") + ")"); "");
System.out.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.println("---------------------------------DELETING ACCOUNT NUMBER PREFERENCE WITH INVALID ID------------------------------------------"); System.out
.println("---------------------------------DELETING ACCOUNT NUMBER PREFERENCE WITH INVALID ID------------------------------------------");
HashMap<String,Object> deletionError = (HashMap<String,Object>) 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() {
this.createAndValidateClientEntity(this.isAccountPreferenceSetUp); this.createAndValidateClientEntity(this.isAccountPreferenceSetUp);
this.createAndValidateLoanEntity(this.isAccountPreferenceSetUp); this.createAndValidateLoanEntity(this.isAccountPreferenceSetUp);
this.createAndValidateSavingsEntity(this.isAccountPreferenceSetUp); this.createAndValidateSavingsEntity(this.isAccountPreferenceSetUp);
} }
private void validateAccountNumberGenerationWithPreferences(){ private void validateAccountNumberGenerationWithPreferences() {
this.isAccountPreferenceSetUp = true; this.isAccountPreferenceSetUp = true;
this.createAndValidateClientEntity(this.isAccountPreferenceSetUp); this.createAndValidateClientEntity(this.isAccountPreferenceSetUp);
this.createAndValidateLoanEntity(this.isAccountPreferenceSetUp); this.createAndValidateLoanEntity(this.isAccountPreferenceSetUp);
this.createAndValidateSavingsEntity(this.isAccountPreferenceSetUp); this.createAndValidateSavingsEntity(this.isAccountPreferenceSetUp);
} }
private void createAccountNumberPreference() { private void createAccountNumberPreference() {
this.clientAccountNumberPreferenceId = (Integer) this.accountNumberPreferencesHelper this.clientAccountNumberPreferenceId = (Integer) this.accountNumberPreferencesHelper.createClientAccountNumberPreference(
.createClientAccountNumberPreference(this.responseSpec,"resourceId"); this.responseSpec, "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,"resourceId"); this.responseSpec, "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,"resourceId"); this.responseSpec, "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.verifyCreationOfAccountNumberPreferences( this.accountNumberPreferencesHelper.verifyCreationOfAccountNumberPreferences(this.clientAccountNumberPreferenceId,
this.clientAccountNumberPreferenceId, this.loanAccountNumberPreferenceId, this.savingsAccountNumberPreferenceId, this.responseSpec, this.requestSpec);
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(final String accountType,final String prefixType){ private void createAccountNumberPreferenceDuplicateData(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 = (HashMap<String, Object>) this.accountNumberPreferencesHelper HashMap<String, Object> creationError = this.accountNumberPreferencesHelper.createAccountNumberPreferenceWithInvalidData(
.createAccountNumberPreferenceWithInvalidData(this.responseForbiddenError, accountType, prefixType,""); this.responseForbiddenError, accountType, prefixType, "");
Assert.assertEquals("error.msg.account.number.format.duplicate.account.type",creationError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); Assert.assertEquals("error.msg.account.number.format.duplicate.account.type",
creationError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
} }
private void createAccountNumberPreferenceInvalidData(final String accountType,final String prefixType){ private void createAccountNumberPreferenceInvalidData(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 = (HashMap<String, Object>) 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("validation.msg.accountNumberFormat.accountType.is.not.within.expected.range",creationError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); creationError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
} } else if (creationError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE).equals(
else if (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",
.equals("validation.msg.accountNumberFormat.prefixType.is.not.one.of.expected.enumerations")) { creationError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
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 = (HashMap<String,Object>) 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 "+ (Integer)accountNumberPreferences.get("resourceId")); + accountNumberPreferences.get("resourceId"));
this.accountNumberPreferencesHelper.verifyUpdationOfAccountNumberPreferences((Integer)accountNumberPreferences.get("resourceId"), this.accountNumberPreferencesHelper.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 */
System.out System.out
.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 = (HashMap<String,Object>) this.accountNumberPreferencesHelper HashMap<String, Object> updationError = this.accountNumberPreferencesHelper.updateAccountNumberPreference(5, "101",
.updateAccountNumberPreference(5, "101", this.responseNotFoundError,""); this.responseNotFoundError, "");
if(updationError if (updationError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE).equals("error.msg.resource.not.found")) {
.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE) Assert.assertEquals("error.msg.resource.not.found", 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));
} }
/* Invalid Prefix Type */ /* Invalid Prefix Type */
HashMap<String,Object> updationError1 = (HashMap<String,Object>) this.accountNumberPreferencesHelper HashMap<String, Object> updationError1 = this.accountNumberPreferencesHelper.updateAccountNumberPreference(
.updateAccountNumberPreference(this.clientAccountNumberPreferenceId, "103",this.responseValidationError, ""); this.clientAccountNumberPreferenceId, "103", this.responseValidationError, "");
Assert.assertEquals( Assert.assertEquals("validation.msg.validation.errors.exist", updationError1.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
"validation.msg.validation.errors.exist",
updationError1.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
} }
@@ -232,137 +233,113 @@ public class AccountNumberPreferencesTest {
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
if (isAccountPreferenceSetUp) { if (isAccountPreferenceSetUp) {
this.createAndValidateClientBasedOnAccountPreference(); this.createAndValidateClientBasedOnAccountPreference();
} } else {
else {
this.createAndValidateClientWithoutAccountPreference(); this.createAndValidateClientWithoutAccountPreference();
} }
} }
private void createAndValidateClientWithoutAccountPreference(){ private void createAndValidateClientWithoutAccountPreference() {
this.clientId = ClientHelper.createClient(this.requestSpec,this.responseSpec); this.clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec);
Assert.assertNotNull(this.clientId); Assert.assertNotNull(this.clientId);
String clientAccountNo = (String) ClientHelper.getClient(requestSpec,responseSpec, this.clientId.toString(), "accountNo"); String clientAccountNo = (String) ClientHelper.getClient(requestSpec, 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.getAccountNumberPreference( String clientPrefixName = (String) this.accountNumberPreferencesHelper.getAccountNumberPreference(
this.clientAccountNumberPreferenceId, this.clientAccountNumberPreferenceId, "prefixType.value");
"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 = (HashMap<String,Object>)CodeHelper.getCodeByName(this.requestSpec, this.responseSpec, codeName, ""); HashMap<String, Object> code = CodeHelper.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 = (HashMap<String,Object>) CodeHelper.retrieveOrCreateCodeValue(this.clientTypeCodeId,this.requestSpec,this.responseSpec,""); HashMap<String, Object> codeValue = CodeHelper.retrieveOrCreateCodeValue(this.clientTypeCodeId, this.requestSpec,
this.clientCodeValueName = (String)codeValue.get("name"); this.responseSpec, "");
this.clientCodeValueId = (Integer)codeValue.get("id"); this.clientCodeValueName = (String) codeValue.get("name");
this.clientCodeValueId = (Integer) codeValue.get("id");
/* Create Client with Client Type*/ /* Create Client with Client Type */
this.clientId = ClientHelper this.clientId = ClientHelper.createClientForAccountPreference(this.requestSpec, this.responseSpec, this.clientCodeValueId,
.createClientForAccountPreference(this.requestSpec,this.responseSpec, this.clientCodeValueId,"clientId"); "clientId");
Assert.assertNotNull(clientId); Assert.assertNotNull(clientId);
clientAccountNo = (String) ClientHelper.getClient(this.requestSpec,this.responseSpec, this.clientId.toString(), "accountNo"); clientAccountNo = (String) ClientHelper.getClient(this.requestSpec, 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.responseSpec); this.clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec);
Assert.assertNotNull(clientId); Assert.assertNotNull(clientId);
clientAccountNo = (String) ClientHelper.getClient(requestSpec,responseSpec, this.clientId.toString(), "accountNo"); clientAccountNo = (String) ClientHelper.getClient(requestSpec, responseSpec, this.clientId.toString(), "accountNo");
String officeName = (String) ClientHelper.getClient(requestSpec,responseSpec, this.clientId.toString(), "officeName"); String officeName = (String) ClientHelper.getClient(requestSpec, responseSpec, this.clientId.toString(), "officeName");
this.validateAccountNumberLengthAndStartsWithPrefix(clientAccountNo,officeName); this.validateAccountNumberLengthAndStartsWithPrefix(clientAccountNo, officeName);
} }
} }
private void validateAccountNumberLengthAndStartsWithPrefix(final String accountNumber,final String prefix){ private void validateAccountNumberLengthAndStartsWithPrefix(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));
} } else {
else {
Assert.assertEquals(accountNumber.length(), 9); Assert.assertEquals(accountNumber.length(), 9);
} }
} }
private void createLoanProduct() { private void createLoanProduct() {
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
System.out.println("---------------------------------CREATING LOAN PRODUCT------------------------------------------"); System.out.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()
.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.getLoanDetail(this.requestSpec, this.responseSpec, this.loanId, "accountNo"); String loanAccountNo = (String) this.loanTransactionHelper.getLoanDetail(this.requestSpec, this.responseSpec, this.loanId,
"accountNo");
if (isAccountPreferenceSetUp) { if (isAccountPreferenceSetUp) {
String loanPrefixName = (String) this.accountNumberPreferencesHelper.getAccountNumberPreference(this.loanAccountNumberPreferenceId,"prefixType.value"); String loanPrefixName = (String) this.accountNumberPreferencesHelper.getAccountNumberPreference(
this.loanAccountNumberPreferenceId, "prefixType.value");
if (loanPrefixName.equals(this.officeName)) { if (loanPrefixName.equals(this.officeName)) {
String loanOfficeName = (String) ClientHelper.getClient(requestSpec, responseSpec, this.clientId.toString(),"officeName"); String loanOfficeName = (String) ClientHelper.getClient(requestSpec, responseSpec, this.clientId.toString(), "officeName");
this.validateAccountNumberLengthAndStartsWithPrefix(loanAccountNo, loanOfficeName); this.validateAccountNumberLengthAndStartsWithPrefix(loanAccountNo, loanOfficeName);
} } else if (loanPrefixName.equals(this.loanShortName)) {
else if (loanPrefixName.equals(this.loanShortName)) { String loanShortName = (String) this.loanTransactionHelper.getLoanProductDetail(this.requestSpec, this.responseSpec,
String loanShortName = (String) this.loanTransactionHelper this.loanProductId, "shortName");
.getLoanProductDetail(this.requestSpec,this.responseSpec, this.loanProductId,"shortName");
this.validateAccountNumberLengthAndStartsWithPrefix(loanAccountNo, loanShortName); 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: " } else {
+ this.loanId + ")");
}
else {
this.validateAccountNumberLengthAndStartsWithPrefix(loanAccountNo, null); this.validateAccountNumberLengthAndStartsWithPrefix(loanAccountNo, 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();
@@ -374,50 +351,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.responseSpec); this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
this.savingsId = this.savingsAccountHelper.applyForSavingsApplication(this.clientId, this.savingsProductId, ACCOUNT_TYPE_INDIVIDUAL); this.savingsId = this.savingsAccountHelper
.applyForSavingsApplication(this.clientId, this.savingsProductId, ACCOUNT_TYPE_INDIVIDUAL);
String savingsAccountNo = (String) this.savingsAccountHelper.getSavingsAccountDetail(this.savingsId, "accountNo"); String savingsAccountNo = (String) this.savingsAccountHelper.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(requestSpec, responseSpec, this.clientId.toString(),"officeName"); String savingsOfficeName = (String) ClientHelper.getClient(requestSpec, responseSpec, this.clientId.toString(),
"officeName");
this.validateAccountNumberLengthAndStartsWithPrefix(savingsAccountNo, savingsOfficeName); this.validateAccountNumberLengthAndStartsWithPrefix(savingsAccountNo, savingsOfficeName);
} } else if (savingsPrefixName.equals(this.savingsShortName)) {
else if (savingsPrefixName.equals(this.savingsShortName)) {
String loanShortName = (String) this.savingsAccountHelper.getSavingsAccountDetail(this.savingsId, "shortName"); String loanShortName = (String) this.savingsAccountHelper.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: " } else {
+ this.loanId + ")");
}
else {
this.validateAccountNumberLengthAndStartsWithPrefix(savingsAccountNo, null); this.validateAccountNumberLengthAndStartsWithPrefix(savingsAccountNo, null);
System.out.println("SUCCESSFULLY CREATED SAVINGS APPLICATION (ID: " System.out.println("SUCCESSFULLY CREATED SAVINGS APPLICATION (ID: " + this.savingsId + ")");
+ this.savingsId + ")");
} }
} }
} }