From 64e78540d9bca109a93f910eb906fca283a83d7f Mon Sep 17 00:00:00 2001 From: Chandrika Date: Fri, 12 Dec 2014 14:56:10 -0500 Subject: [PATCH] MIFOSX-1717 Integration test cases for Account Number Preferences. --- .../AccountNumberPreferencesTest.java | 423 ++++++++++++++++++ .../integrationtests/common/ClientHelper.java | 27 +- .../common/loans/LoanTransactionHelper.java | 6 + .../common/savings/SavingsAccountHelper.java | 5 + .../AccountNumberPreferencesHelper.java | 118 +++++ .../AccountNumberPreferencesTestBuilder.java | 52 +++ .../common/system/CodeHelper.java | 44 +- 7 files changed, 672 insertions(+), 3 deletions(-) create mode 100644 mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/AccountNumberPreferencesTest.java create mode 100644 mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/system/AccountNumberPreferencesHelper.java create mode 100644 mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/system/AccountNumberPreferencesTestBuilder.java diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/AccountNumberPreferencesTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/AccountNumberPreferencesTest.java new file mode 100644 index 000000000..9a098bed7 --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/AccountNumberPreferencesTest.java @@ -0,0 +1,423 @@ +package org.mifosplatform.integrationtests; + +import com.jayway.restassured.builder.RequestSpecBuilder; +import com.jayway.restassured.builder.ResponseSpecBuilder; +import com.jayway.restassured.http.ContentType; +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +import java.util.ArrayList; +import java.util.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 { + + private RequestSpecification requestSpec; + private ResponseSpecification responseSpec; + private ResponseSpecification responseValidationError; + private ResponseSpecification responseNotFoundError; + private ResponseSpecification responseForbiddenError; + private Integer clientId; + private Integer loanProductId; + private Integer loanId; + private Integer savingsProductId; + private Integer savingsId; + private String loanPrincipalAmount = "100000.00"; + private String numberOfRepayments = "12"; + private String interestRatePerPeriod = "18"; + private String dateString = "4 September 2014"; + private String minBalanceForInterestCalculation = null; + private String minRequiredBalance = null; + private String enforceMinRequiredBalance = "false"; + private LoanTransactionHelper loanTransactionHelper; + private SavingsAccountHelper savingsAccountHelper; + private AccountNumberPreferencesHelper accountNumberPreferencesHelper; + private Integer clientAccountNumberPreferenceId; + private Integer loanAccountNumberPreferenceId; + private Integer savingsAccountNumberPreferenceId; + private final String MINIMUM_OPENING_BALANCE = "1000.0"; + private final String ACCOUNT_TYPE_INDIVIDUAL = "INDIVIDUAL"; + private Boolean isAccountPreferenceSetUp = false; + private Integer clientTypeCodeId; + private String clientCodeValueName; + private Integer clientCodeValueId; + private String clientTypeName = "CLIENT_TYPE"; + private String officeName = "OFFICE_NAME"; + private String loanShortName = "LOAN_PRODUCT_SHORT_NAME"; + private String savingsShortName = "SAVINGS_PRODUCT_SHORT_NAME"; + + @Before + public void setup() { + Utils.initializeRESTAssured(); + this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build(); + this.requestSpec.header("Authorization","Basic "+ Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); + this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); + this.responseValidationError = new ResponseSpecBuilder().expectStatusCode(400).build(); + this.responseNotFoundError = new ResponseSpecBuilder().expectStatusCode(404).build(); + this.responseForbiddenError = new ResponseSpecBuilder().expectStatusCode(403).build(); + this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec); + this.accountNumberPreferencesHelper = new AccountNumberPreferencesHelper( + this.requestSpec, this.responseSpec); + + } + + + @Test + public void testAccountNumberPreferences() { + + /* Create Loan and Savings Product */ + this.createLoanAndSavingsProduct(); + + /* Ensure no account number preferences are present in the system */ + this.deleteAllAccountNumberPreferences(); + + /* Validate the default account number generation rules for clients, loans and savings accounts.*/ + this.validateDefaultAccountNumberGeneration(); + + /* Create and Validate account number preferences */ + this.createAccountNumberPreference(); + + /* Validate account number preference rules apply to Clients,Loans and Saving Accounts */ + this.validateAccountNumberGenerationWithPreferences(); + + /* Validate account number preferences Updation */ + this.updateAccountNumberPreference(); + + /* Validate account number preference rules apply to Clients,Loans and Saving Accounts after Updation */ + this.validateAccountNumberGenerationWithPreferences(); + + /* Delete all account number preferences */ + this.deleteAllAccountNumberPreferences(); + + } + + private void createLoanAndSavingsProduct(){ + this.createLoanProduct(); + this.createSavingsProduct(); + } + + private void deleteAllAccountNumberPreferences() { + ArrayList> preferenceIds = this.accountNumberPreferencesHelper.getAllAccountNumberPreferences(); + /* Deletion of valid account preference ID */ + for (HashMap preferenceId : preferenceIds) { + Integer id = (Integer) preferenceId.get("id"); + HashMap delResponse= (HashMap) this.accountNumberPreferencesHelper.deleteAccountNumberPreference(id, this.responseSpec,""); + System.out.println("Successfully deleted account number preference (ID: "+ delResponse.get("resourceId") + ")"); + } + /* Deletion of invalid account preference ID should fail */ + System.out.println("---------------------------------DELETING ACCOUNT NUMBER PREFERENCE WITH INVALID ID------------------------------------------"); + + HashMap deletionError = (HashMap) this.accountNumberPreferencesHelper + .deleteAccountNumberPreference(10, this.responseNotFoundError,""); + Assert.assertEquals("error.msg.resource.not.found",deletionError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); + } + + private void validateDefaultAccountNumberGeneration(){ + this.createAndValidateClientEntity(this.isAccountPreferenceSetUp); + this.createAndValidateLoanEntity(this.isAccountPreferenceSetUp); + this.createAndValidateSavingsEntity(this.isAccountPreferenceSetUp); + } + + private void validateAccountNumberGenerationWithPreferences(){ + this.isAccountPreferenceSetUp = true; + this.createAndValidateClientEntity(this.isAccountPreferenceSetUp); + this.createAndValidateLoanEntity(this.isAccountPreferenceSetUp); + this.createAndValidateSavingsEntity(this.isAccountPreferenceSetUp); + } + + + private void createAccountNumberPreference() { + this.clientAccountNumberPreferenceId = (Integer) this.accountNumberPreferencesHelper + .createClientAccountNumberPreference(this.responseSpec,"resourceId"); + System.out.println("Successfully created account number preferences for Client (ID: "+ this.clientAccountNumberPreferenceId); + + this.loanAccountNumberPreferenceId = (Integer) this.accountNumberPreferencesHelper + .createLoanAccountNumberPreference(this.responseSpec,"resourceId"); + System.out.println("Successfully created account number preferences for Loan (ID: "+ this.loanAccountNumberPreferenceId); + + this.savingsAccountNumberPreferenceId = (Integer) this.accountNumberPreferencesHelper + .createSavingsAccountNumberPreference(this.responseSpec,"resourceId"); + System.out.println("Successfully created account number preferences for Savings (ID: "+ this.savingsAccountNumberPreferenceId); + + this.accountNumberPreferencesHelper.verifyCreationOfAccountNumberPreferences( + this.clientAccountNumberPreferenceId, + this.loanAccountNumberPreferenceId, + this.savingsAccountNumberPreferenceId, + this.responseSpec, + this.requestSpec); + + this.createAccountNumberPreferenceInvalidData("1000","1001"); + this.createAccountNumberPreferenceDuplicateData("1","101"); + + } + + private void createAccountNumberPreferenceDuplicateData(final String accountType,final String prefixType){ + /* Creating account Preference with duplicate data should fail */ + System.out + .println("---------------------------------CREATING ACCOUNT NUMBER PREFERENCE WITH DUPLICATE DATA------------------------------------------"); + + HashMap creationError = (HashMap) this.accountNumberPreferencesHelper + .createAccountNumberPreferenceWithInvalidData(this.responseForbiddenError, accountType, prefixType,""); + + 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){ + + /* Creating account Preference with invalid data should fail */ + System.out + .println("---------------------------------CREATING ACCOUNT NUMBER PREFERENCE WITH INVALID DATA------------------------------------------"); + + HashMap creationError = (HashMap) this.accountNumberPreferencesHelper + .createAccountNumberPreferenceWithInvalidData(this.responseValidationError, accountType, prefixType,""); + + if (creationError + .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",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")) { + Assert.assertEquals("validation.msg.accountNumberFormat.prefixType.is.not.one.of.expected.enumerations",creationError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); + } + } + + private void updateAccountNumberPreference() { + HashMap accountNumberPreferences = (HashMap) this.accountNumberPreferencesHelper + .updateAccountNumberPreference(this.clientAccountNumberPreferenceId, "101",this.responseSpec, ""); + + System.out + .println("--------------------------UPDATION SUCCESSFUL FOR ACCOUNT NUMBER PREFERENCE ID "+ (Integer)accountNumberPreferences.get("resourceId")); + + this.accountNumberPreferencesHelper.verifyUpdationOfAccountNumberPreferences((Integer)accountNumberPreferences.get("resourceId"), + this.responseSpec,this.requestSpec); + + /* Update invalid account preference id should fail */ + System.out + .println("---------------------------------UPDATING ACCOUNT NUMBER PREFERENCE WITH INVALID DATA------------------------------------------"); + + /* Invalid Account Type */ + HashMap updationError = (HashMap) this.accountNumberPreferencesHelper + .updateAccountNumberPreference(5, "101", this.responseNotFoundError,""); + 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)); + } + /* Invalid Prefix Type */ + HashMap updationError1 = (HashMap) this.accountNumberPreferencesHelper + .updateAccountNumberPreference(this.clientAccountNumberPreferenceId, "103",this.responseValidationError, ""); + + Assert.assertEquals( + "validation.msg.validation.errors.exist", + updationError1.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); + + } + + private void createAndValidateClientEntity(Boolean isAccountPreferenceSetUp) { + this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); + if (isAccountPreferenceSetUp) { + this.createAndValidateClientBasedOnAccountPreference(); + } + else { + this.createAndValidateClientWithoutAccountPreference(); + } + } + + 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"); + validateAccountNumberLengthAndStartsWithPrefix(clientAccountNo,null); + } + + private void createAndValidateClientBasedOnAccountPreference() { + final String codeName = "ClientType"; + String clientAccountNo = null; + String clientPrefixName = (String) this.accountNumberPreferencesHelper.getAccountNumberPreference( + this.clientAccountNumberPreferenceId, + "prefixType.value"); + if (clientPrefixName.equals(this.clientTypeName)) { + + /* Retrieve Code id for the Code "ClientType" */ + HashMap code = (HashMap)CodeHelper.getCodeByName(this.requestSpec, this.responseSpec, codeName, ""); + this.clientTypeCodeId = (Integer)code.get("id"); + + /* Retrieve/Create Code Values for the Code "ClientType" */ + HashMap codeValue = (HashMap) CodeHelper.retrieveOrCreateCodeValue(this.clientTypeCodeId,this.requestSpec,this.responseSpec,""); + this.clientCodeValueName = (String)codeValue.get("name"); + this.clientCodeValueId = (Integer)codeValue.get("id"); + + /* Create Client with Client Type*/ + this.clientId = ClientHelper + .createClientForAccountPreference(this.requestSpec,this.responseSpec, this.clientCodeValueId,"clientId"); + + Assert.assertNotNull(clientId); + + clientAccountNo = (String) ClientHelper.getClient(this.requestSpec,this.responseSpec, this.clientId.toString(), "accountNo"); + this.validateAccountNumberLengthAndStartsWithPrefix(clientAccountNo,this.clientCodeValueName); + + } else if (clientPrefixName.equals(this.officeName)) { + this.clientId = ClientHelper.createClient(this.requestSpec,this.responseSpec); + Assert.assertNotNull(clientId); + clientAccountNo = (String) ClientHelper.getClient(requestSpec,responseSpec, this.clientId.toString(), "accountNo"); + String officeName = (String) ClientHelper.getClient(requestSpec,responseSpec, this.clientId.toString(), "officeName"); + this.validateAccountNumberLengthAndStartsWithPrefix(clientAccountNo,officeName); + } + } + + private void validateAccountNumberLengthAndStartsWithPrefix(final String accountNumber,final String prefix){ + if(prefix != null){ + Assert.assertEquals(accountNumber.length(),prefix.length() + 9); + Assert.assertTrue(accountNumber.startsWith(prefix)); + } + else { + Assert.assertEquals(accountNumber.length(), 9); + } + } + + + private void createLoanProduct() { + this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); + + System.out.println("---------------------------------CREATING LOAN PRODUCT------------------------------------------"); + + final String loanProductJSON = new LoanProductTestBuilder() + .withPrincipal(loanPrincipalAmount) + .withNumberOfRepayments(numberOfRepayments) + .withinterestRatePerPeriod(interestRatePerPeriod) + .withInterestRateFrequencyTypeAsYear().build(null); + + this.loanProductId = this.loanTransactionHelper + .getLoanProductId(loanProductJSON); + System.out.println("Successfully created loan product (ID: " + + this.loanProductId + ")"); + } + + private void createAndValidateLoanEntity(Boolean isAccountPreferenceSetUp) { + this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200) + .build(); + + System.out + .println("---------------------------------NEW LOAN APPLICATION------------------------------------------"); + + final String loanApplicationJSON = new LoanApplicationTestBuilder() + .withPrincipal(loanPrincipalAmount) + .withLoanTermFrequency(numberOfRepayments) + .withLoanTermFrequencyAsMonths() + .withNumberOfRepayments(numberOfRepayments) + .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 + ")"); + } + } +} diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/ClientHelper.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/ClientHelper.java index 255270198..e4bfe4d43 100755 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/ClientHelper.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/ClientHelper.java @@ -8,6 +8,7 @@ package org.mifosplatform.integrationtests.common; import static org.junit.Assert.assertEquals; import java.util.HashMap; +import java.util.List; import com.google.gson.Gson; import com.jayway.restassured.specification.RequestSpecification; @@ -53,6 +54,15 @@ public class ClientHelper { "clientId"); } + public static Integer createClientForAccountPreference(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final Integer clientType,String jsonAttributeToGetBack) { + final String activationDate = "04 March 2011"; + final String officeId = "1"; + System.out.println("---------------------------------CREATING A CLIENT BASED ON ACCOUNT PREFERENCE---------------------------------------------"); + return Utils.performServerPost(requestSpec, responseSpec, CREATE_CLIENT_URL, getTestClientWithClientTypeAsJSON(activationDate, officeId, clientType.toString()), + "clientId"); + } + public static Object assignStaffToClient(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, final String clientId, final String staffId) { final String CLIENT_ASSIGN_STAFF_URL = "/mifosng-provider/api/v1/clients/" + clientId + "?" + Utils.TENANT_IDENTIFIER @@ -80,6 +90,22 @@ public class ClientHelper { System.out.println("map : " + map); return new Gson().toJson(map); } + + public static String getTestClientWithClientTypeAsJSON(final String dateOfJoining, final String officeId, + final String clientType) { + final HashMap map = new HashMap<>(); + map.put("officeId", officeId); + map.put("firstname", Utils.randomNameGenerator("Client_FirstName_", 5)); + map.put("lastname", Utils.randomNameGenerator("Client_LastName_", 4)); + map.put("externalId", randomIDGenerator("ID_", 7)); + map.put("dateFormat", "dd MMMM yyyy"); + map.put("locale", "en"); + map.put("active", "true"); + map.put("activationDate", dateOfJoining); + map.put("clientTypeId", clientType); + System.out.println("map : " + map); + return new Gson().toJson(map); + } public static String assignStaffToClientAsJson(final String staffId) { final HashMap map = new HashMap<>(); @@ -99,7 +125,6 @@ public class ClientHelper { public static Object getClient(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, final String clientId, final String jsonReturn) { final String GET_CLIENT_URL = "/mifosng-provider/api/v1/clients/" + clientId + "?" + Utils.TENANT_IDENTIFIER; - System.out.println("---------------------------------GET A CLIENT---------------------------------------------"); return Utils.performServerGet(requestSpec, responseSpec, GET_CLIENT_URL, jsonReturn); diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/loans/LoanTransactionHelper.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/loans/LoanTransactionHelper.java index a5a57482d..8721b7e5e 100755 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/loans/LoanTransactionHelper.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/loans/LoanTransactionHelper.java @@ -90,6 +90,12 @@ public class LoanTransactionHelper { final String URL = "/mifosng-provider/api/v1/loans/" + loanID + "?associations=all&" + Utils.TENANT_IDENTIFIER; return Utils.performServerGet(requestSpec, responseSpec, URL, param); } + + public Object getLoanProductDetail(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, final Integer loanProductId, + final String param) { + final String URL = "/mifosng-provider/api/v1/loanproducts/" + loanProductId + "?associations=all&" + Utils.TENANT_IDENTIFIER; + return Utils.performServerGet(requestSpec, responseSpec, URL, param); + } public ArrayList getLoanCharges(final Integer loanId) { final String GET_LOAN_CHARGES_URL = "/mifosng-provider/api/v1/loans/" + loanId + "/charges?" + Utils.TENANT_IDENTIFIER; diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/savings/SavingsAccountHelper.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/savings/SavingsAccountHelper.java index 4af3c976e..56591cf35 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/savings/SavingsAccountHelper.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/savings/SavingsAccountHelper.java @@ -328,6 +328,11 @@ public class SavingsAccountHelper { final ArrayList response = Utils.performServerGet(requestSpec, responseSpec, URL, jSONAttribute); return response; } + + public Object getSavingsAccountDetail(final Integer savingsID, final String jsonAttribute){ + final String URL = SAVINGS_ACCOUNT_URL + "/" + savingsID + "?associations=all&" + Utils.TENANT_IDENTIFIER; + return Utils.performServerGet(requestSpec, responseSpec, URL, jsonAttribute); + } public ArrayList getSavingsCharges(final Integer savingsID) { final String URL = SAVINGS_ACCOUNT_URL + "/" + savingsID + "/charges?" + Utils.TENANT_IDENTIFIER; diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/system/AccountNumberPreferencesHelper.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/system/AccountNumberPreferencesHelper.java new file mode 100644 index 000000000..9fc35610a --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/system/AccountNumberPreferencesHelper.java @@ -0,0 +1,118 @@ +package org.mifosplatform.integrationtests.common.system; + + +import java.util.ArrayList; +import java.util.HashMap; + +import org.mifosplatform.integrationtests.common.Utils; + +import com.jayway.restassured.specification.RequestSpecification; +import com.jayway.restassured.specification.ResponseSpecification; + +public class AccountNumberPreferencesHelper { + + private final RequestSpecification requestSpec; + private final ResponseSpecification responseSpec; + + private static final String ACCOUNT_NUMBER_FORMATS_REQUEST_URL = "/mifosng-provider/api/v1/accountnumberformats"; + + public AccountNumberPreferencesHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + this.requestSpec = requestSpec; + this.responseSpec = responseSpec; + } + + public Object createClientAccountNumberPreference(ResponseSpecification responseSpec,String jsonAttributeToGetBack) { + System.out.println("---------------------------------CREATING CLIENT ACCOUNT NUMBER PREFERENCE------------------------------------------"); + + final String requestJSON = new AccountNumberPreferencesTestBuilder().clientBuild(); + + final String URL = ACCOUNT_NUMBER_FORMATS_REQUEST_URL + "?" + Utils.TENANT_IDENTIFIER; + + return Utils.performServerPost(this.requestSpec, responseSpec, URL, requestJSON, jsonAttributeToGetBack); + } + + public Object createLoanAccountNumberPreference(ResponseSpecification responseSpec,String jsonAttributeToGetBack) { + System.out.println("---------------------------------CREATING LOAN ACCOUNT NUMBER PREFERENCE------------------------------------------"); + + final String requestJSON = new AccountNumberPreferencesTestBuilder().loanBuild(); + + final String URL = ACCOUNT_NUMBER_FORMATS_REQUEST_URL + "?" + Utils.TENANT_IDENTIFIER; + return Utils.performServerPost(this.requestSpec, responseSpec, URL, requestJSON, jsonAttributeToGetBack); + } + + public Object createSavingsAccountNumberPreference(ResponseSpecification responseSpec,String jsonAttributeToGetBack) { + System.out.println("---------------------------------CREATING SAVINGS ACCOUNT NUMBER PREFERENCE------------------------------------------"); + + final String requestJSON = new AccountNumberPreferencesTestBuilder().savingsBuild(); + + final String URL = ACCOUNT_NUMBER_FORMATS_REQUEST_URL + "?" + Utils.TENANT_IDENTIFIER; + return Utils.performServerPost(this.requestSpec, responseSpec, URL, requestJSON, jsonAttributeToGetBack); + + } + + public HashMap createAccountNumberPreferenceWithInvalidData(ResponseSpecification responseSpec, + String accountType,String prefixType,String jsonAttributeToGetBack){ + + final String requestJSON = new AccountNumberPreferencesTestBuilder().invalidDataBuild(accountType,prefixType); + + final String URL = ACCOUNT_NUMBER_FORMATS_REQUEST_URL + "?" + Utils.TENANT_IDENTIFIER; + return Utils.performServerPost(this.requestSpec, responseSpec, URL, requestJSON, jsonAttributeToGetBack); + + } + + public HashMap updateAccountNumberPreference(final Integer accountNumberFormatId,final String prefixType,ResponseSpecification responseSpec,String jsonAttributeToGetBack) { + + final String requestJSON = new AccountNumberPreferencesTestBuilder().updatePrefixType(prefixType); + + final String URL = ACCOUNT_NUMBER_FORMATS_REQUEST_URL + "/" + accountNumberFormatId + "?" + Utils.TENANT_IDENTIFIER; + + return Utils.performServerPut(this.requestSpec, responseSpec, URL, requestJSON, jsonAttributeToGetBack); + + } + + public HashMap deleteAccountNumberPreference(final Integer accountNumberFormatId,ResponseSpecification responseSpec,String jsonAttributeToGetBack) { + + System.out.println("---------------------------------DELETING ACCOUNT NUMBER PREFERENCE------------------------------------------"); + + final String URL = ACCOUNT_NUMBER_FORMATS_REQUEST_URL + "/" + accountNumberFormatId + "?" + Utils.TENANT_IDENTIFIER; + + return Utils.performServerDelete(this.requestSpec, responseSpec, URL,jsonAttributeToGetBack); + } + + public Object getAccountNumberPreference(final Integer accountNumberFormatId, final String jsonAttributeToGetBack) { + final String URL = ACCOUNT_NUMBER_FORMATS_REQUEST_URL + "/" + accountNumberFormatId + "?" + Utils.TENANT_IDENTIFIER; + + return Utils.performServerGet(requestSpec, responseSpec, URL, jsonAttributeToGetBack); + } + + public ArrayList> getAllAccountNumberPreferences() { + final String URL = ACCOUNT_NUMBER_FORMATS_REQUEST_URL + "?" + Utils.TENANT_IDENTIFIER; + final ArrayList> response = Utils.performServerGet(requestSpec, responseSpec, URL, ""); + return response; + } + + public void verifyCreationOfAccountNumberPreferences(final Integer clientAccountNumberPreferenceId, + final Integer loanAccountNumberPreferenceId,final Integer savingsAccountNumberPreferenceId, + ResponseSpecification responseSpec,RequestSpecification requestSpec) { + + final String clientURL = ACCOUNT_NUMBER_FORMATS_REQUEST_URL + "/" + clientAccountNumberPreferenceId + "?" + Utils.TENANT_IDENTIFIER; + + Utils.performServerGet(requestSpec, responseSpec, clientURL, "id"); + + final String loanURL = ACCOUNT_NUMBER_FORMATS_REQUEST_URL + "/" + loanAccountNumberPreferenceId + "?" + Utils.TENANT_IDENTIFIER; + + Utils.performServerGet(requestSpec, responseSpec, loanURL, "id"); + + final String savingsURL = ACCOUNT_NUMBER_FORMATS_REQUEST_URL + "/" + savingsAccountNumberPreferenceId + "?" + Utils.TENANT_IDENTIFIER; + + Utils.performServerGet(requestSpec, responseSpec, savingsURL, "id"); + } + + public void verifyUpdationOfAccountNumberPreferences(final Integer accountNumberPreferenceId, + ResponseSpecification responseSpec,RequestSpecification requestSpec){ + + final String URL = ACCOUNT_NUMBER_FORMATS_REQUEST_URL + "/" + accountNumberPreferenceId + "?" + Utils.TENANT_IDENTIFIER; + Utils.performServerGet(requestSpec, responseSpec, URL, "id"); + + } +} diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/system/AccountNumberPreferencesTestBuilder.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/system/AccountNumberPreferencesTestBuilder.java new file mode 100644 index 000000000..98e63d201 --- /dev/null +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/system/AccountNumberPreferencesTestBuilder.java @@ -0,0 +1,52 @@ +package org.mifosplatform.integrationtests.common.system; + +import java.util.HashMap; + +import com.google.gson.Gson; + +public class AccountNumberPreferencesTestBuilder { + + private String clientAccountType = "1"; + private String clientPrefixType = "101"; + private String loanAccountType = "2"; + private String loanPrefixType = "1"; + private String savingsAccountType = "3"; + private String savingsPrefixType = "1"; + + public String clientBuild() { + final HashMap map = new HashMap<>(); + map.put("accountType", clientAccountType); + map.put("prefixType", clientPrefixType); + + return new Gson().toJson(map); + } + public String loanBuild(){ + final HashMap map = new HashMap<>(); + map.put("accountType", loanAccountType); + map.put("prefixType", loanPrefixType); + + return new Gson().toJson(map); + } + public String savingsBuild(){ + final HashMap map = new HashMap<>(); + map.put("accountType", savingsAccountType); + map.put("prefixType", savingsPrefixType); + + return new Gson().toJson(map); + } + public String invalidDataBuild(String accountType,String prefixType){ + final HashMap map = new HashMap<>(); + map.put("accountType", accountType); + map.put("prefixType", prefixType); + + return new Gson().toJson(map); + } + public String updatePrefixType(final String prefixType) { + + final HashMap map = new HashMap<>(); + map.put("prefixType", prefixType); + + return new Gson().toJson(map); + } +} + diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/system/CodeHelper.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/system/CodeHelper.java index 85a931e1a..4fdac3c42 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/system/CodeHelper.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/common/system/CodeHelper.java @@ -7,7 +7,9 @@ package org.mifosplatform.integrationtests.common.system; import static com.jayway.restassured.RestAssured.given; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import org.mifosplatform.integrationtests.common.Utils; @@ -52,8 +54,46 @@ public class CodeHelper { jsonAttributeToGetback); } + + public static HashMap getCodeByName(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final String codeName, final String jsonAttributeToGetback){ - public static Object getAllCodes(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { + final HashMap code = new HashMap<>(); + + ArrayList> getAllCodes = (ArrayList>) CodeHelper.getAllCodes(requestSpec, responseSpec); + for (HashMapmap : getAllCodes) { + String name = (String) map.get("name"); + if (name.equals(codeName)) { + code.put("id", map.get("id")); + code.put("name", map.get("name")); + code.put("position", map.get("position")); + code.put("description",map.get("description")); + break; + } + } + return code; + } + + public static HashMap retrieveOrCreateCodeValue(Integer codeId,final RequestSpecification requestSpec, + final ResponseSpecification responseSpec,final String jsonAttributeToGetBack) { + Integer codeValueId = null; + final List> codeValuesList = + (List>) CodeHelper.getCodeValuesForCode(requestSpec,responseSpec, codeId,""); + /* If Code Values doesn't exist,then create Code value */ + if (codeValuesList.size() == 0) { + final Integer codeValuePosition = 0; + final String codeValue = Utils.randomNameGenerator("", 3); + codeValueId = (Integer)CodeHelper.createCodeValue(requestSpec, responseSpec, codeId , codeValue,codeValuePosition, "resourceId"); + + } else { + codeValueId = (Integer) codeValuesList.get(0).get("id"); + } + return Utils.performServerGet(requestSpec, responseSpec, + CODE_VALUE_URL.replace("[codeId]", codeId.toString()) + "/" + codeValueId.toString() + "?" + Utils.TENANT_IDENTIFIER, + ""); + } + + public static ArrayList> getAllCodes(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { return Utils.performServerGet(requestSpec, responseSpec, CODE_URL + "?" + Utils.TENANT_IDENTIFIER, ""); @@ -109,7 +149,7 @@ public class CodeHelper { + Utils.TENANT_IDENTIFIER, getTestCodeValueAsJSON(codeValueName, description, position), jsonAttributeToGetback); } - public static Object getCodeValuesForCode(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + public static List> getCodeValuesForCode(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, final Integer codeId, final String jsonAttributeToGetback) { return Utils.performServerGet(requestSpec, responseSpec, CODE_VALUE_URL.replace("[codeId]", codeId.toString()) + "?"