Merge pull request #1191 from chandrikamohith/TestCase

MIFOSX-1717,MIFOSX-1662 Test case for account number preferences and Cod...
This commit is contained in:
Vishwas Babu A J
2014-12-15 18:31:29 -08:00
12 changed files with 880 additions and 653 deletions
+6 -6
View File
@@ -3567,7 +3567,7 @@ Request Body:
<td><div class="mifosXHeading2">Mandatory Fields</div></td> <td><div class="mifosXHeading2">Mandatory Fields</div></td>
</tr> </tr>
<tr class=alt> <tr class=alt>
<td>rejectDate, rejectReasonId<br> <td>rejectionDate, rejectionReasonId<br>
</td> </td>
</tr> </tr>
</table> </table>
@@ -3579,8 +3579,8 @@ Request Body:
Content-Type: application/json Content-Type: application/json
Request Body: Request Body:
{ {
"rejectDate":"28 November 2014", "rejectionDate":"28 November 2014",
"rejectReasonId":16, "rejectionReasonId":16,
"locale":"en", "locale":"en",
"dateFormat":"dd MMMM yyyy" "dateFormat":"dd MMMM yyyy"
} }
@@ -3605,7 +3605,7 @@ Request Body:
<td><div class="mifosXHeading2">Mandatory Fields</div></td> <td><div class="mifosXHeading2">Mandatory Fields</div></td>
</tr> </tr>
<tr class=alt> <tr class=alt>
<td>withdrawDate, withdrawReasonId<br> <td>withdrawalDate, withdrawalReasonId<br>
</td> </td>
</tr> </tr>
</table> </table>
@@ -3616,8 +3616,8 @@ Request Body:
Content-Type: application/json Content-Type: application/json
Request Body: Request Body:
{ {
"withdrawDate":"28 November 2014", "withdrawalDate":"28 November 2014",
"withdrawReasonId":17, "withdrawalReasonId":17,
"locale":"en", "locale":"en",
"dateFormat":"dd MMMM yyyy" "dateFormat":"dd MMMM yyyy"
} }
@@ -1,391 +1,511 @@
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 final String loanPrincipalAmount = "100000.00"; private String loanPrincipalAmount = "100000.00";
private final String numberOfRepayments = "12"; private String numberOfRepayments = "12";
private final String interestRatePerPeriod = "18"; private String interestRatePerPeriod = "18";
private final String dateString = "4 September 2014"; private String dateString = "4 September 2014";
private final String minBalanceForInterestCalculation = null; private String minBalanceForInterestCalculation = null;
private final String minRequiredBalance = null; private String minRequiredBalance = null;
private final String enforceMinRequiredBalance = "false"; private 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 final String clientTypeName = "CLIENT_TYPE"; private String clientTypeName = "CLIENT_TYPE";
private final String officeName = "OFFICE_NAME"; private String officeName = "OFFICE_NAME";
private final String loanShortName = "LOAN_PRODUCT_SHORT_NAME"; private String loanShortName = "LOAN_PRODUCT_SHORT_NAME";
private final String savingsShortName = "SAVINGS_PRODUCT_SHORT_NAME"; private 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(
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); ContentType.JSON).build();
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); this.requestSpec
this.responseValidationError = new ResponseSpecBuilder().expectStatusCode(400).build(); .header("Authorization",
this.responseNotFoundError = new ResponseSpecBuilder().expectStatusCode(404).build(); "Basic "
this.responseForbiddenError = new ResponseSpecBuilder().expectStatusCode(403).build(); + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec); this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200)
this.accountNumberPreferencesHelper = new AccountNumberPreferencesHelper(this.requestSpec, this.responseSpec); .build();
this.responseValidationError = new ResponseSpecBuilder()
} .expectStatusCode(400).build();
this.responseNotFoundError = new ResponseSpecBuilder()
@Test .expectStatusCode(404).build();
public void testAccountNumberPreferences() { this.responseForbiddenError = new ResponseSpecBuilder()
.expectStatusCode(403).build();
/* Create Loan and Savings Product */ this.loanTransactionHelper = new LoanTransactionHelper(
this.createLoanAndSavingsProduct(); this.requestSpec, this.responseSpec);
this.accountNumberPreferencesHelper = new AccountNumberPreferencesHelper(
/* Ensure no account number preferences are present in the system */ this.requestSpec, this.responseSpec);
this.deleteAllAccountNumberPreferences();
}
/*
* Validate the default account number generation rules for clients, @Test
* loans and savings accounts. public void testAccountNumberPreferences() {
*/
this.validateDefaultAccountNumberGeneration(); /* Create Loan and Savings Product */
this.createLoanAndSavingsProduct();
/* Create and Validate account number preferences */
this.createAccountNumberPreference(); /* Ensure no account number preferences are present in the system */
this.deleteAllAccountNumberPreferences();
/*
* Validate account number preference rules apply to Clients,Loans and /*
* Saving Accounts * Validate the default account number generation rules for clients,
*/ * loans and savings accounts.
this.validateAccountNumberGenerationWithPreferences(); */
this.validateDefaultAccountNumberGeneration();
/* Validate account number preferences Updation */
this.updateAccountNumberPreference(); /* Create and Validate account number preferences */
this.createAccountNumberPreference();
/*
* 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
this.validateAccountNumberGenerationWithPreferences(); */
this.validateAccountNumberGenerationWithPreferences();
/* Delete all account number preferences */
this.deleteAllAccountNumberPreferences(); /* Validate account number preferences Updation */
this.updateAccountNumberPreference();
}
/*
private void createLoanAndSavingsProduct() { * Validate account number preference rules apply to Clients,Loans and
this.createLoanProduct(); * Saving Accounts after Updation
this.createSavingsProduct(); */
} this.validateAccountNumberGenerationWithPreferences();
private void deleteAllAccountNumberPreferences() { /* Delete all account number preferences */
ArrayList<HashMap<String, Object>> preferenceIds = this.accountNumberPreferencesHelper.getAllAccountNumberPreferences(); this.deleteAllAccountNumberPreferences();
/* Deletion of valid account preference ID */
for (HashMap<String, Object> preferenceId : preferenceIds) { }
Integer id = (Integer) preferenceId.get("id");
HashMap<String, Object> delResponse = this.accountNumberPreferencesHelper.deleteAccountNumberPreference(id, this.responseSpec, private void createLoanAndSavingsProduct() {
""); this.createLoanProduct();
System.out.println("Successfully deleted account number preference (ID: " + delResponse.get("resourceId") + ")"); this.createSavingsProduct();
} }
/* Deletion of invalid account preference ID should fail */
System.out private void deleteAllAccountNumberPreferences() {
.println("---------------------------------DELETING ACCOUNT NUMBER PREFERENCE WITH INVALID ID------------------------------------------"); ArrayList<HashMap<String, Object>> preferenceIds = this.accountNumberPreferencesHelper
.getAllAccountNumberPreferences();
HashMap<String, Object> deletionError = this.accountNumberPreferencesHelper.deleteAccountNumberPreference(10, /* Deletion of valid account preference ID */
this.responseNotFoundError, ""); for (HashMap<String, Object> preferenceId : preferenceIds) {
Assert.assertEquals("error.msg.resource.not.found", deletionError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); Integer id = (Integer) preferenceId.get("id");
} HashMap<String, Object> delResponse = this.accountNumberPreferencesHelper
.deleteAccountNumberPreference(id, this.responseSpec, "");
private void validateDefaultAccountNumberGeneration() { System.out
this.createAndValidateClientEntity(this.isAccountPreferenceSetUp); .println("Successfully deleted account number preference (ID: "
this.createAndValidateLoanEntity(this.isAccountPreferenceSetUp); + delResponse.get("resourceId") + ")");
this.createAndValidateSavingsEntity(this.isAccountPreferenceSetUp); }
} /* Deletion of invalid account preference ID should fail */
System.out
private void validateAccountNumberGenerationWithPreferences() { .println("---------------------------------DELETING ACCOUNT NUMBER PREFERENCE WITH INVALID ID------------------------------------------");
this.isAccountPreferenceSetUp = true;
this.createAndValidateClientEntity(this.isAccountPreferenceSetUp); HashMap<String, Object> deletionError = this.accountNumberPreferencesHelper
this.createAndValidateLoanEntity(this.isAccountPreferenceSetUp); .deleteAccountNumberPreference(10, this.responseNotFoundError,
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(
this.responseSpec, "resourceId"); private void validateDefaultAccountNumberGeneration() {
System.out.println("Successfully created account number preferences for Client (ID: " + this.clientAccountNumberPreferenceId); this.createAndValidateClientEntity(this.isAccountPreferenceSetUp);
this.createAndValidateLoanEntity(this.isAccountPreferenceSetUp);
this.loanAccountNumberPreferenceId = (Integer) this.accountNumberPreferencesHelper.createLoanAccountNumberPreference( this.createAndValidateSavingsEntity(this.isAccountPreferenceSetUp);
this.responseSpec, "resourceId"); }
System.out.println("Successfully created account number preferences for Loan (ID: " + this.loanAccountNumberPreferenceId);
private void validateAccountNumberGenerationWithPreferences() {
this.savingsAccountNumberPreferenceId = (Integer) this.accountNumberPreferencesHelper.createSavingsAccountNumberPreference( this.isAccountPreferenceSetUp = true;
this.responseSpec, "resourceId"); this.createAndValidateClientEntity(this.isAccountPreferenceSetUp);
System.out.println("Successfully created account number preferences for Savings (ID: " + this.savingsAccountNumberPreferenceId); this.createAndValidateLoanEntity(this.isAccountPreferenceSetUp);
this.createAndValidateSavingsEntity(this.isAccountPreferenceSetUp);
this.accountNumberPreferencesHelper.verifyCreationOfAccountNumberPreferences(this.clientAccountNumberPreferenceId, }
this.loanAccountNumberPreferenceId, this.savingsAccountNumberPreferenceId, this.responseSpec, this.requestSpec);
private void createAccountNumberPreference() {
this.createAccountNumberPreferenceInvalidData("1000", "1001"); this.clientAccountNumberPreferenceId = (Integer) this.accountNumberPreferencesHelper
this.createAccountNumberPreferenceDuplicateData("1", "101"); .createClientAccountNumberPreference(this.responseSpec,
"resourceId");
} System.out
.println("Successfully created account number preferences for Client (ID: "
private void createAccountNumberPreferenceDuplicateData(final String accountType, final String prefixType) { + this.clientAccountNumberPreferenceId);
/* Creating account Preference with duplicate data should fail */
System.out this.loanAccountNumberPreferenceId = (Integer) this.accountNumberPreferencesHelper
.println("---------------------------------CREATING ACCOUNT NUMBER PREFERENCE WITH DUPLICATE DATA------------------------------------------"); .createLoanAccountNumberPreference(this.responseSpec,
"resourceId");
HashMap<String, Object> creationError = this.accountNumberPreferencesHelper.createAccountNumberPreferenceWithInvalidData( System.out
this.responseForbiddenError, accountType, prefixType, ""); .println("Successfully created account number preferences for Loan (ID: "
+ this.loanAccountNumberPreferenceId);
Assert.assertEquals("error.msg.account.number.format.duplicate.account.type",
creationError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); this.savingsAccountNumberPreferenceId = (Integer) this.accountNumberPreferencesHelper
.createSavingsAccountNumberPreference(this.responseSpec,
} "resourceId");
System.out
private void createAccountNumberPreferenceInvalidData(final String accountType, final String prefixType) { .println("Successfully created account number preferences for Savings (ID: "
+ this.savingsAccountNumberPreferenceId);
/* Creating account Preference with invalid data should fail */
System.out this.accountNumberPreferencesHelper
.println("---------------------------------CREATING ACCOUNT NUMBER PREFERENCE WITH INVALID DATA------------------------------------------"); .verifyCreationOfAccountNumberPreferences(
this.clientAccountNumberPreferenceId,
HashMap<String, Object> creationError = this.accountNumberPreferencesHelper.createAccountNumberPreferenceWithInvalidData( this.loanAccountNumberPreferenceId,
this.responseValidationError, accountType, prefixType, ""); this.savingsAccountNumberPreferenceId,
this.responseSpec, this.requestSpec);
if (creationError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE).equals(
"validation.msg.accountNumberFormat.accountType.is.not.within.expected.range")) { this.createAccountNumberPreferenceInvalidData("1000", "1001");
Assert.assertEquals("validation.msg.accountNumberFormat.accountType.is.not.within.expected.range", this.createAccountNumberPreferenceDuplicateData("1", "101");
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", private void createAccountNumberPreferenceDuplicateData(
creationError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); final String accountType, final String prefixType) {
} /* Creating account Preference with duplicate data should fail */
} System.out
.println("---------------------------------CREATING ACCOUNT NUMBER PREFERENCE WITH DUPLICATE DATA------------------------------------------");
private void updateAccountNumberPreference() {
HashMap<String, Object> accountNumberPreferences = this.accountNumberPreferencesHelper.updateAccountNumberPreference( HashMap<String, Object> creationError = this.accountNumberPreferencesHelper
this.clientAccountNumberPreferenceId, "101", this.responseSpec, ""); .createAccountNumberPreferenceWithInvalidData(
this.responseForbiddenError, accountType, prefixType,
System.out.println("--------------------------UPDATION SUCCESSFUL FOR ACCOUNT NUMBER PREFERENCE ID " "");
+ accountNumberPreferences.get("resourceId"));
Assert.assertEquals(
this.accountNumberPreferencesHelper.verifyUpdationOfAccountNumberPreferences((Integer) accountNumberPreferences.get("resourceId"), "error.msg.account.number.format.duplicate.account.type",
this.responseSpec, this.requestSpec); creationError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
/* Update invalid account preference id should fail */ }
System.out
.println("---------------------------------UPDATING ACCOUNT NUMBER PREFERENCE WITH INVALID DATA------------------------------------------"); private void createAccountNumberPreferenceInvalidData(
final String accountType, final String prefixType) {
/* Invalid Account Type */
HashMap<String, Object> updationError = this.accountNumberPreferencesHelper.updateAccountNumberPreference(5, "101", /* Creating account Preference with invalid data should fail */
this.responseNotFoundError, ""); System.out
if (updationError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE).equals("error.msg.resource.not.found")) { .println("---------------------------------CREATING ACCOUNT NUMBER PREFERENCE WITH INVALID DATA------------------------------------------");
Assert.assertEquals("error.msg.resource.not.found", updationError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
} HashMap<String, Object> creationError = this.accountNumberPreferencesHelper
/* Invalid Prefix Type */ .createAccountNumberPreferenceWithInvalidData(
HashMap<String, Object> updationError1 = this.accountNumberPreferencesHelper.updateAccountNumberPreference( this.responseValidationError, accountType, prefixType,
this.clientAccountNumberPreferenceId, "103", this.responseValidationError, ""); "");
Assert.assertEquals("validation.msg.validation.errors.exist", updationError1.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)); if (creationError
.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)
} .equals("validation.msg.accountNumberFormat.accountType.is.not.within.expected.range")) {
Assert.assertEquals(
private void createAndValidateClientEntity(Boolean isAccountPreferenceSetUp) { "validation.msg.accountNumberFormat.accountType.is.not.within.expected.range",
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); creationError
if (isAccountPreferenceSetUp) { .get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
this.createAndValidateClientBasedOnAccountPreference(); } else if (creationError
} else { .get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)
this.createAndValidateClientWithoutAccountPreference(); .equals("validation.msg.accountNumberFormat.prefixType.is.not.one.of.expected.enumerations")) {
} Assert.assertEquals(
} "validation.msg.accountNumberFormat.prefixType.is.not.one.of.expected.enumerations",
creationError
private void createAndValidateClientWithoutAccountPreference() { .get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
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 updateAccountNumberPreference() {
} HashMap<String, Object> accountNumberPreferences = this.accountNumberPreferencesHelper
.updateAccountNumberPreference(
private void createAndValidateClientBasedOnAccountPreference() { this.clientAccountNumberPreferenceId, "101",
final String codeName = "ClientType"; this.responseSpec, "");
String clientAccountNo = null;
String clientPrefixName = (String) this.accountNumberPreferencesHelper.getAccountNumberPreference( System.out
this.clientAccountNumberPreferenceId, "prefixType.value"); .println("--------------------------UPDATION SUCCESSFUL FOR ACCOUNT NUMBER PREFERENCE ID "
if (clientPrefixName.equals(this.clientTypeName)) { + accountNumberPreferences.get("resourceId"));
/* Retrieve Code id for the Code "ClientType" */ this.accountNumberPreferencesHelper
HashMap<String, Object> code = CodeHelper.getCodeByName(this.requestSpec, this.responseSpec, codeName, ""); .verifyUpdationOfAccountNumberPreferences(
this.clientTypeCodeId = (Integer) code.get("id"); (Integer) accountNumberPreferences.get("resourceId"),
this.responseSpec, this.requestSpec);
/* Retrieve/Create Code Values for the Code "ClientType" */
HashMap<String, Object> codeValue = CodeHelper.retrieveOrCreateCodeValue(this.clientTypeCodeId, this.requestSpec, /* Update invalid account preference id should fail */
this.responseSpec, ""); System.out
this.clientCodeValueName = (String) codeValue.get("name"); .println("---------------------------------UPDATING ACCOUNT NUMBER PREFERENCE WITH INVALID DATA------------------------------------------");
this.clientCodeValueId = (Integer) codeValue.get("id");
/* Invalid Account Type */
/* Create Client with Client Type */ HashMap<String, Object> updationError = this.accountNumberPreferencesHelper
this.clientId = ClientHelper.createClientForAccountPreference(this.requestSpec, this.responseSpec, this.clientCodeValueId, .updateAccountNumberPreference(9999, "101",
"clientId"); this.responseNotFoundError, "");
if (updationError.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE)
Assert.assertNotNull(clientId); .equals("error.msg.resource.not.found")) {
Assert.assertEquals("error.msg.resource.not.found", updationError
clientAccountNo = (String) ClientHelper.getClient(this.requestSpec, this.responseSpec, this.clientId.toString(), "accountNo"); .get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
this.validateAccountNumberLengthAndStartsWithPrefix(clientAccountNo, this.clientCodeValueName); }
/* Invalid Prefix Type */
} else if (clientPrefixName.equals(this.officeName)) { HashMap<String, Object> updationError1 = this.accountNumberPreferencesHelper
this.clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec); .updateAccountNumberPreference(
Assert.assertNotNull(clientId); this.clientAccountNumberPreferenceId, "103",
clientAccountNo = (String) ClientHelper.getClient(requestSpec, responseSpec, this.clientId.toString(), "accountNo"); this.responseValidationError, "");
String officeName = (String) ClientHelper.getClient(requestSpec, responseSpec, this.clientId.toString(), "officeName");
this.validateAccountNumberLengthAndStartsWithPrefix(clientAccountNo, officeName); Assert.assertEquals("validation.msg.validation.errors.exist",
} updationError1.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
}
}
private void validateAccountNumberLengthAndStartsWithPrefix(final String accountNumber, final String prefix) {
if (prefix != null) { private void createAndValidateClientEntity(Boolean isAccountPreferenceSetUp) {
Assert.assertEquals(accountNumber.length(), prefix.length() + 9); this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200)
Assert.assertTrue(accountNumber.startsWith(prefix)); .build();
} else { if (isAccountPreferenceSetUp) {
Assert.assertEquals(accountNumber.length(), 9); this.createAndValidateClientBasedOnAccountPreference();
} } else {
} this.createAndValidateClientWithoutAccountPreference();
}
private void createLoanProduct() { }
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
private void createAndValidateClientWithoutAccountPreference() {
System.out.println("---------------------------------CREATING LOAN PRODUCT------------------------------------------"); this.clientId = ClientHelper.createClient(this.requestSpec,
this.responseSpec);
final String loanProductJSON = new LoanProductTestBuilder().withPrincipal(loanPrincipalAmount) Assert.assertNotNull(this.clientId);
.withNumberOfRepayments(numberOfRepayments).withinterestRatePerPeriod(interestRatePerPeriod) String clientAccountNo = (String) ClientHelper.getClient(requestSpec,
.withInterestRateFrequencyTypeAsYear().build(null); responseSpec, this.clientId.toString(), "accountNo");
validateAccountNumberLengthAndStartsWithPrefix(clientAccountNo, null);
this.loanProductId = this.loanTransactionHelper.getLoanProductId(loanProductJSON); }
System.out.println("Successfully created loan product (ID: " + this.loanProductId + ")");
} private void createAndValidateClientBasedOnAccountPreference() {
final String codeName = "ClientType";
private void createAndValidateLoanEntity(Boolean isAccountPreferenceSetUp) { String clientAccountNo = null;
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); String clientPrefixName = (String) this.accountNumberPreferencesHelper
.getAccountNumberPreference(
System.out.println("---------------------------------NEW LOAN APPLICATION------------------------------------------"); this.clientAccountNumberPreferenceId,
"prefixType.value");
final String loanApplicationJSON = new LoanApplicationTestBuilder().withPrincipal(loanPrincipalAmount) if (clientPrefixName.equals(this.clientTypeName)) {
.withLoanTermFrequency(numberOfRepayments).withLoanTermFrequencyAsMonths().withNumberOfRepayments(numberOfRepayments)
.withRepaymentEveryAfter("1").withRepaymentFrequencyTypeAsMonths().withAmortizationTypeAsEqualInstallments() /* Retrieve Code id for the Code "ClientType" */
.withInterestCalculationPeriodTypeAsDays().withInterestRatePerPeriod(interestRatePerPeriod).withLoanTermFrequencyAsMonths() HashMap<String, Object> code = CodeHelper
.withSubmittedOnDate(dateString).withExpectedDisbursementDate(dateString).withPrincipalGrace("2").withInterestGrace("2") .getCodeByName(this.requestSpec, this.responseSpec,
.build(this.clientId.toString(), this.loanProductId.toString(), null); codeName);
this.clientTypeCodeId = (Integer) code.get("id");
this.loanId = this.loanTransactionHelper.getLoanId(loanApplicationJSON);
String loanAccountNo = (String) this.loanTransactionHelper.getLoanDetail(this.requestSpec, this.responseSpec, this.loanId, /* Retrieve/Create Code Values for the Code "ClientType" */
"accountNo"); HashMap<String, Object> codeValue = CodeHelper
.retrieveOrCreateCodeValue(this.clientTypeCodeId,
if (isAccountPreferenceSetUp) { this.requestSpec, this.responseSpec);
String loanPrefixName = (String) this.accountNumberPreferencesHelper.getAccountNumberPreference(
this.loanAccountNumberPreferenceId, "prefixType.value"); this.clientCodeValueName = (String) codeValue.get("name");
if (loanPrefixName.equals(this.officeName)) { this.clientCodeValueId = (Integer) codeValue.get("id");
String loanOfficeName = (String) ClientHelper.getClient(requestSpec, responseSpec, this.clientId.toString(), "officeName");
this.validateAccountNumberLengthAndStartsWithPrefix(loanAccountNo, loanOfficeName); /* Create Client with Client Type */
} else if (loanPrefixName.equals(this.loanShortName)) { this.clientId = ClientHelper.createClientForAccountPreference(
String loanShortName = (String) this.loanTransactionHelper.getLoanProductDetail(this.requestSpec, this.responseSpec, this.requestSpec, this.responseSpec,
this.loanProductId, "shortName"); this.clientCodeValueId, "clientId");
this.validateAccountNumberLengthAndStartsWithPrefix(loanAccountNo, loanShortName);
} Assert.assertNotNull(clientId);
System.out.println("SUCCESSFULLY CREATED LOAN APPLICATION BASED ON ACCOUNT PREFERENCES (ID: " + this.loanId + ")");
} else { clientAccountNo = (String) ClientHelper.getClient(this.requestSpec,
this.validateAccountNumberLengthAndStartsWithPrefix(loanAccountNo, null); this.responseSpec, this.clientId.toString(), "accountNo");
System.out.println("SUCCESSFULLY CREATED LOAN APPLICATION (ID: " + loanId + ")"); this.validateAccountNumberLengthAndStartsWithPrefix(
} clientAccountNo, this.clientCodeValueName);
}
} else if (clientPrefixName.equals(this.officeName)) {
private void createSavingsProduct() { this.clientId = ClientHelper.createClient(this.requestSpec,
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); this.responseSpec);
Assert.assertNotNull(clientId);
System.out.println("------------------------------CREATING NEW SAVINGS PRODUCT ---------------------------------------"); clientAccountNo = (String) ClientHelper.getClient(requestSpec,
responseSpec, this.clientId.toString(), "accountNo");
SavingsProductHelper savingsProductHelper = new SavingsProductHelper(); String officeName = (String) ClientHelper.getClient(requestSpec,
responseSpec, this.clientId.toString(), "officeName");
final String savingsProductJSON = savingsProductHelper this.validateAccountNumberLengthAndStartsWithPrefix(
// clientAccountNo, officeName);
.withInterestCompoundingPeriodTypeAsDaily() }
// }
.withInterestPostingPeriodTypeAsMonthly()
// private void validateAccountNumberLengthAndStartsWithPrefix(
.withInterestCalculationPeriodTypeAsDailyBalance() final String accountNumber, final String prefix) {
// if (prefix != null) {
.withMinBalanceForInterestCalculation(minBalanceForInterestCalculation) Assert.assertEquals(accountNumber.length(), prefix.length() + 9);
// Assert.assertTrue(accountNumber.startsWith(prefix));
.withMinRequiredBalance(minRequiredBalance).withEnforceMinRequiredBalance(enforceMinRequiredBalance) } else {
.withMinimumOpenningBalance(this.MINIMUM_OPENING_BALANCE).build(); Assert.assertEquals(accountNumber.length(), 9);
this.savingsProductId = SavingsProductHelper.createSavingsProduct(savingsProductJSON, this.requestSpec, this.responseSpec); }
System.out.println("Sucessfully created savings product (ID: " + this.savingsProductId + ")"); }
} private void createLoanProduct() {
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200)
private void createAndValidateSavingsEntity(Boolean isAccountPreferenceSetUp) { .build();
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
System.out
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec); .println("---------------------------------CREATING LOAN PRODUCT------------------------------------------");
this.savingsId = this.savingsAccountHelper final String loanProductJSON = new LoanProductTestBuilder()
.applyForSavingsApplication(this.clientId, this.savingsProductId, ACCOUNT_TYPE_INDIVIDUAL); .withPrincipal(loanPrincipalAmount)
.withNumberOfRepayments(numberOfRepayments)
String savingsAccountNo = (String) this.savingsAccountHelper.getSavingsAccountDetail(this.savingsId, "accountNo"); .withinterestRatePerPeriod(interestRatePerPeriod)
.withInterestRateFrequencyTypeAsYear().build(null);
if (isAccountPreferenceSetUp) {
String savingsPrefixName = (String) this.accountNumberPreferencesHelper.getAccountNumberPreference( this.loanProductId = this.loanTransactionHelper
this.savingsAccountNumberPreferenceId, "prefixType.value"); .getLoanProductId(loanProductJSON);
System.out.println("Successfully created loan product (ID: "
if (savingsPrefixName.equals(this.officeName)) { + this.loanProductId + ")");
String savingsOfficeName = (String) ClientHelper.getClient(requestSpec, responseSpec, this.clientId.toString(), }
"officeName");
this.validateAccountNumberLengthAndStartsWithPrefix(savingsAccountNo, savingsOfficeName); private void createAndValidateLoanEntity(Boolean isAccountPreferenceSetUp) {
} else if (savingsPrefixName.equals(this.savingsShortName)) { this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200)
String loanShortName = (String) this.savingsAccountHelper.getSavingsAccountDetail(this.savingsId, "shortName"); .build();
this.validateAccountNumberLengthAndStartsWithPrefix(savingsAccountNo, loanShortName);
} System.out
System.out.println("SUCCESSFULLY CREATED SAVINGS APPLICATION BASED ON ACCOUNT PREFERENCES (ID: " + this.loanId + ")"); .println("---------------------------------NEW LOAN APPLICATION------------------------------------------");
} else {
this.validateAccountNumberLengthAndStartsWithPrefix(savingsAccountNo, null); final String loanApplicationJSON = new LoanApplicationTestBuilder()
System.out.println("SUCCESSFULLY CREATED SAVINGS APPLICATION (ID: " + this.savingsId + ")"); .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 + ")");
}
}
} }
@@ -9,6 +9,7 @@ import java.util.HashMap;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test;
import org.mifosplatform.integrationtests.common.ClientHelper; import org.mifosplatform.integrationtests.common.ClientHelper;
import org.mifosplatform.integrationtests.common.Utils; import org.mifosplatform.integrationtests.common.Utils;
@@ -33,7 +34,7 @@ public class ClientTest {
} }
// @Test @Test
public void testClientStatus() { public void testClientStatus() {
this.clientHelper = new ClientHelper(this.requestSpec, this.responseSpec); this.clientHelper = new ClientHelper(this.requestSpec, this.responseSpec);
final Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec); final Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec);
@@ -8,7 +8,7 @@ package org.mifosplatform.integrationtests.common;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import org.mifosplatform.integrationtests.common.system.CodeHelper;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.jayway.restassured.specification.RequestSpecification; import com.jayway.restassured.specification.RequestSpecification;
@@ -60,7 +60,7 @@ public class ClientHelper {
final String officeId = "1"; final String officeId = "1";
System.out.println("---------------------------------CREATING A CLIENT BASED ON ACCOUNT PREFERENCE---------------------------------------------"); System.out.println("---------------------------------CREATING A CLIENT BASED ON ACCOUNT PREFERENCE---------------------------------------------");
return Utils.performServerPost(requestSpec, responseSpec, CREATE_CLIENT_URL, getTestClientWithClientTypeAsJSON(activationDate, officeId, clientType.toString()), return Utils.performServerPost(requestSpec, responseSpec, CREATE_CLIENT_URL, getTestClientWithClientTypeAsJSON(activationDate, officeId, clientType.toString()),
"clientId"); jsonAttributeToGetBack);
} }
public static Object assignStaffToClient(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, public static Object assignStaffToClient(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
@@ -141,10 +141,21 @@ public class ClientHelper {
private String getCloseClientAsJSON() { private String getCloseClientAsJSON() {
final HashMap<String, String> map = new HashMap<>(); final HashMap<String, String> map = new HashMap<>();
/* Retrieve Code id for the Code "ClientClosureReason" */
String codeName = "ClientClosureReason";
HashMap<String,Object> code = CodeHelper.getCodeByName(this.requestSpec, this.responseSpec, codeName);
Integer clientClosureCodeId = (Integer)code.get("id");
/* Retrieve/Create Code Values for the Code "ClientClosureReason" */
HashMap<String,Object> codeValue = CodeHelper.retrieveOrCreateCodeValue(clientClosureCodeId,this.requestSpec,this.responseSpec);
String closureReasonId = (String)codeValue.get("id");
map.put("closureReasonId", closureReasonId);
map.put("locale", CommonConstants.locale); map.put("locale", CommonConstants.locale);
map.put("dateFormat", CommonConstants.dateFormat); map.put("dateFormat", CommonConstants.dateFormat);
map.put("closureDate", CREATED_DATE_PLUS_ONE); map.put("closureDate", CREATED_DATE_PLUS_ONE);
map.put("closureReasonId", "12");
String clientJson = new Gson().toJson(map); String clientJson = new Gson().toJson(map);
System.out.println(clientJson); System.out.println(clientJson);
return clientJson; return clientJson;
@@ -166,8 +177,8 @@ public class ClientHelper {
final HashMap<String, String> map = new HashMap<>(); final HashMap<String, String> map = new HashMap<>();
map.put("locale", CommonConstants.locale); map.put("locale", CommonConstants.locale);
map.put("dateFormat", CommonConstants.dateFormat); map.put("dateFormat", CommonConstants.dateFormat);
map.put("rejectDate", CREATED_DATE_PLUS_ONE); map.put("rejectionDate", CREATED_DATE_PLUS_ONE);
map.put("rejectReasonId", "15"); map.put("rejectionReasonId", "15");
String clientJson = new Gson().toJson(map); String clientJson = new Gson().toJson(map);
System.out.println(clientJson); System.out.println(clientJson);
return clientJson; return clientJson;
@@ -189,8 +200,8 @@ public class ClientHelper {
final HashMap<String, String> map = new HashMap<>(); final HashMap<String, String> map = new HashMap<>();
map.put("locale", CommonConstants.locale); map.put("locale", CommonConstants.locale);
map.put("dateFormat", CommonConstants.dateFormat); map.put("dateFormat", CommonConstants.dateFormat);
map.put("withdrawDate", CREATED_DATE_PLUS_ONE); map.put("withdrawalDate", CREATED_DATE_PLUS_ONE);
map.put("withdrawReasonId", "17"); map.put("withdrawalReasonId", "17");
String clientJson = new Gson().toJson(map); String clientJson = new Gson().toJson(map);
System.out.println(clientJson); System.out.println(clientJson);
return clientJson; return clientJson;
@@ -92,9 +92,9 @@ public class LoanTransactionHelper {
} }
public Object getLoanProductDetail(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, final Integer loanProductId, public Object getLoanProductDetail(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, final Integer loanProductId,
final String param) { final String jsonAttributeToGetBack) {
final String URL = "/mifosng-provider/api/v1/loanproducts/" + loanProductId + "?associations=all&" + Utils.TENANT_IDENTIFIER; final String URL = "/mifosng-provider/api/v1/loanproducts/" + loanProductId + "?associations=all&" + Utils.TENANT_IDENTIFIER;
return Utils.performServerGet(requestSpec, responseSpec, URL, param); return Utils.performServerGet(requestSpec, responseSpec, URL, jsonAttributeToGetBack);
} }
public ArrayList getLoanCharges(final Integer loanId) { public ArrayList getLoanCharges(final Integer loanId) {
@@ -1,6 +1,5 @@
package org.mifosplatform.integrationtests.common.system; package org.mifosplatform.integrationtests.common.system;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@@ -12,107 +11,154 @@ import com.jayway.restassured.specification.ResponseSpecification;
public class AccountNumberPreferencesHelper { public class AccountNumberPreferencesHelper {
private final RequestSpecification requestSpec; private final RequestSpecification requestSpec;
private final ResponseSpecification responseSpec;
private static final String ACCOUNT_NUMBER_FORMATS_REQUEST_URL = "/mifosng-provider/api/v1/accountnumberformats"; private final ResponseSpecification responseSpec;
public AccountNumberPreferencesHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { private static final String ACCOUNT_NUMBER_FORMATS_REQUEST_URL = "/mifosng-provider/api/v1/accountnumberformats";
this.requestSpec = requestSpec;
this.responseSpec = responseSpec;
}
public Object createClientAccountNumberPreference(ResponseSpecification responseSpec,String jsonAttributeToGetBack) { public AccountNumberPreferencesHelper(
System.out.println("---------------------------------CREATING CLIENT ACCOUNT NUMBER PREFERENCE------------------------------------------"); final RequestSpecification requestSpec,
final ResponseSpecification responseSpec) {
this.requestSpec = requestSpec;
this.responseSpec = responseSpec;
}
final String requestJSON = new AccountNumberPreferencesTestBuilder().clientBuild(); public Object createClientAccountNumberPreference(
ResponseSpecification responseSpec, String jsonAttributeToGetBack) {
System.out
.println("---------------------------------CREATING CLIENT ACCOUNT NUMBER PREFERENCE------------------------------------------");
final String URL = ACCOUNT_NUMBER_FORMATS_REQUEST_URL + "?" + Utils.TENANT_IDENTIFIER; final String requestJSON = new AccountNumberPreferencesTestBuilder()
.clientBuild();
return Utils.performServerPost(this.requestSpec, responseSpec, URL, requestJSON, jsonAttributeToGetBack); final String URL = ACCOUNT_NUMBER_FORMATS_REQUEST_URL + "?"
} + Utils.TENANT_IDENTIFIER;
public Object createLoanAccountNumberPreference(ResponseSpecification responseSpec,String jsonAttributeToGetBack) { return Utils.performServerPost(this.requestSpec, responseSpec, URL,
System.out.println("---------------------------------CREATING LOAN ACCOUNT NUMBER PREFERENCE------------------------------------------"); requestJSON, jsonAttributeToGetBack);
}
final String requestJSON = new AccountNumberPreferencesTestBuilder().loanBuild(); public Object createLoanAccountNumberPreference(
ResponseSpecification responseSpec, String jsonAttributeToGetBack) {
System.out
.println("---------------------------------CREATING LOAN ACCOUNT NUMBER PREFERENCE------------------------------------------");
final String URL = ACCOUNT_NUMBER_FORMATS_REQUEST_URL + "?" + Utils.TENANT_IDENTIFIER; final String requestJSON = new AccountNumberPreferencesTestBuilder()
return Utils.performServerPost(this.requestSpec, responseSpec, URL, requestJSON, jsonAttributeToGetBack); .loanBuild();
}
public Object createSavingsAccountNumberPreference(ResponseSpecification responseSpec,String jsonAttributeToGetBack) { final String URL = ACCOUNT_NUMBER_FORMATS_REQUEST_URL + "?"
System.out.println("---------------------------------CREATING SAVINGS ACCOUNT NUMBER PREFERENCE------------------------------------------"); + Utils.TENANT_IDENTIFIER;
return Utils.performServerPost(this.requestSpec, responseSpec, URL,
requestJSON, jsonAttributeToGetBack);
}
final String requestJSON = new AccountNumberPreferencesTestBuilder().savingsBuild(); public Object createSavingsAccountNumberPreference(
ResponseSpecification responseSpec, String jsonAttributeToGetBack) {
System.out
.println("---------------------------------CREATING SAVINGS ACCOUNT NUMBER PREFERENCE------------------------------------------");
final String URL = ACCOUNT_NUMBER_FORMATS_REQUEST_URL + "?" + Utils.TENANT_IDENTIFIER; final String requestJSON = new AccountNumberPreferencesTestBuilder()
return Utils.performServerPost(this.requestSpec, responseSpec, URL, requestJSON, jsonAttributeToGetBack); .savingsBuild();
} final String URL = ACCOUNT_NUMBER_FORMATS_REQUEST_URL + "?"
+ Utils.TENANT_IDENTIFIER;
return Utils.performServerPost(this.requestSpec, responseSpec, URL,
requestJSON, jsonAttributeToGetBack);
public HashMap<String, Object> createAccountNumberPreferenceWithInvalidData(ResponseSpecification responseSpec, }
String accountType,String prefixType,String jsonAttributeToGetBack){
final String requestJSON = new AccountNumberPreferencesTestBuilder().invalidDataBuild(accountType,prefixType); public HashMap<String, Object> createAccountNumberPreferenceWithInvalidData(
ResponseSpecification responseSpec, String accountType,
String prefixType, String jsonAttributeToGetBack) {
final String URL = ACCOUNT_NUMBER_FORMATS_REQUEST_URL + "?" + Utils.TENANT_IDENTIFIER; final String requestJSON = new AccountNumberPreferencesTestBuilder()
return Utils.performServerPost(this.requestSpec, responseSpec, URL, requestJSON, jsonAttributeToGetBack); .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<String,Object> updateAccountNumberPreference(final Integer accountNumberFormatId,final String prefixType,ResponseSpecification responseSpec,String jsonAttributeToGetBack) { }
final String requestJSON = new AccountNumberPreferencesTestBuilder().updatePrefixType(prefixType); public HashMap<String, Object> updateAccountNumberPreference(
final Integer accountNumberFormatId, final String prefixType,
ResponseSpecification responseSpec, String jsonAttributeToGetBack) {
final String URL = ACCOUNT_NUMBER_FORMATS_REQUEST_URL + "/" + accountNumberFormatId + "?" + Utils.TENANT_IDENTIFIER; final String requestJSON = new AccountNumberPreferencesTestBuilder()
.updatePrefixType(prefixType);
return Utils.performServerPut(this.requestSpec, responseSpec, URL, requestJSON, jsonAttributeToGetBack); final String URL = ACCOUNT_NUMBER_FORMATS_REQUEST_URL + "/"
+ accountNumberFormatId + "?" + Utils.TENANT_IDENTIFIER;
} return Utils.performServerPut(this.requestSpec, responseSpec, URL,
requestJSON, jsonAttributeToGetBack);
public HashMap<String,Object> deleteAccountNumberPreference(final Integer accountNumberFormatId,ResponseSpecification responseSpec,String jsonAttributeToGetBack) { }
System.out.println("---------------------------------DELETING ACCOUNT NUMBER PREFERENCE------------------------------------------"); public HashMap<String, Object> deleteAccountNumberPreference(
final Integer accountNumberFormatId,
ResponseSpecification responseSpec, String jsonAttributeToGetBack) {
final String URL = ACCOUNT_NUMBER_FORMATS_REQUEST_URL + "/" + accountNumberFormatId + "?" + Utils.TENANT_IDENTIFIER; System.out
.println("---------------------------------DELETING ACCOUNT NUMBER PREFERENCE------------------------------------------");
return Utils.performServerDelete(this.requestSpec, responseSpec, URL,jsonAttributeToGetBack); final String URL = ACCOUNT_NUMBER_FORMATS_REQUEST_URL + "/"
} + accountNumberFormatId + "?" + Utils.TENANT_IDENTIFIER;
public Object getAccountNumberPreference(final Integer accountNumberFormatId, final String jsonAttributeToGetBack) { return Utils.performServerDelete(this.requestSpec, responseSpec, URL,
final String URL = ACCOUNT_NUMBER_FORMATS_REQUEST_URL + "/" + accountNumberFormatId + "?" + Utils.TENANT_IDENTIFIER; jsonAttributeToGetBack);
}
return Utils.performServerGet(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;
public ArrayList<HashMap<String, Object>> getAllAccountNumberPreferences() { return Utils.performServerGet(requestSpec, responseSpec, URL,
final String URL = ACCOUNT_NUMBER_FORMATS_REQUEST_URL + "?" + Utils.TENANT_IDENTIFIER; jsonAttributeToGetBack);
final ArrayList<HashMap<String,Object>> response = Utils.performServerGet(requestSpec, responseSpec, URL, ""); }
return response;
}
public void verifyCreationOfAccountNumberPreferences(final Integer clientAccountNumberPreferenceId, public ArrayList<HashMap<String, Object>> getAllAccountNumberPreferences() {
final Integer loanAccountNumberPreferenceId,final Integer savingsAccountNumberPreferenceId, final String URL = ACCOUNT_NUMBER_FORMATS_REQUEST_URL + "?"
ResponseSpecification responseSpec,RequestSpecification requestSpec) { + Utils.TENANT_IDENTIFIER;
final ArrayList<HashMap<String, Object>> response = Utils
.performServerGet(requestSpec, responseSpec, URL, "");
return response;
}
final String clientURL = ACCOUNT_NUMBER_FORMATS_REQUEST_URL + "/" + clientAccountNumberPreferenceId + "?" + Utils.TENANT_IDENTIFIER; public void verifyCreationOfAccountNumberPreferences(
final Integer clientAccountNumberPreferenceId,
final Integer loanAccountNumberPreferenceId,
final Integer savingsAccountNumberPreferenceId,
ResponseSpecification responseSpec, RequestSpecification requestSpec) {
Utils.performServerGet(requestSpec, responseSpec, clientURL, "id"); final String clientURL = ACCOUNT_NUMBER_FORMATS_REQUEST_URL + "/"
+ clientAccountNumberPreferenceId + "?"
+ Utils.TENANT_IDENTIFIER;
final String loanURL = ACCOUNT_NUMBER_FORMATS_REQUEST_URL + "/" + loanAccountNumberPreferenceId + "?" + Utils.TENANT_IDENTIFIER; Utils.performServerGet(requestSpec, responseSpec, clientURL, "id");
Utils.performServerGet(requestSpec, responseSpec, loanURL, "id"); final String loanURL = ACCOUNT_NUMBER_FORMATS_REQUEST_URL + "/"
+ loanAccountNumberPreferenceId + "?" + Utils.TENANT_IDENTIFIER;
final String savingsURL = ACCOUNT_NUMBER_FORMATS_REQUEST_URL + "/" + savingsAccountNumberPreferenceId + "?" + Utils.TENANT_IDENTIFIER; Utils.performServerGet(requestSpec, responseSpec, loanURL, "id");
Utils.performServerGet(requestSpec, responseSpec, savingsURL, "id"); final String savingsURL = ACCOUNT_NUMBER_FORMATS_REQUEST_URL + "/"
} + savingsAccountNumberPreferenceId + "?"
+ Utils.TENANT_IDENTIFIER;
public void verifyUpdationOfAccountNumberPreferences(final Integer accountNumberPreferenceId, Utils.performServerGet(requestSpec, responseSpec, savingsURL, "id");
ResponseSpecification responseSpec,RequestSpecification requestSpec){ }
final String URL = ACCOUNT_NUMBER_FORMATS_REQUEST_URL + "/" + accountNumberPreferenceId + "?" + Utils.TENANT_IDENTIFIER; public void verifyUpdationOfAccountNumberPreferences(
Utils.performServerGet(requestSpec, responseSpec, URL, "id"); 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");
}
} }
@@ -5,7 +5,6 @@ import java.util.HashMap;
import com.google.gson.Gson; import com.google.gson.Gson;
public class AccountNumberPreferencesTestBuilder { public class AccountNumberPreferencesTestBuilder {
private String clientAccountType = "1"; private String clientAccountType = "1";
private String clientPrefixType = "101"; private String clientPrefixType = "101";
private String loanAccountType = "2"; private String loanAccountType = "2";
@@ -20,33 +19,35 @@ public class AccountNumberPreferencesTestBuilder {
return new Gson().toJson(map); return new Gson().toJson(map);
} }
public String loanBuild(){
public String loanBuild() {
final HashMap<String, Object> map = new HashMap<>(); final HashMap<String, Object> map = new HashMap<>();
map.put("accountType", loanAccountType); map.put("accountType", loanAccountType);
map.put("prefixType", loanPrefixType); map.put("prefixType", loanPrefixType);
return new Gson().toJson(map); return new Gson().toJson(map);
} }
public String savingsBuild(){
public String savingsBuild() {
final HashMap<String, Object> map = new HashMap<>(); final HashMap<String, Object> map = new HashMap<>();
map.put("accountType", savingsAccountType); map.put("accountType", savingsAccountType);
map.put("prefixType", savingsPrefixType); map.put("prefixType", savingsPrefixType);
return new Gson().toJson(map); return new Gson().toJson(map);
} }
public String invalidDataBuild(String accountType,String prefixType){
public String invalidDataBuild(String accountType, String prefixType) {
final HashMap<String, Object> map = new HashMap<>(); final HashMap<String, Object> map = new HashMap<>();
map.put("accountType", accountType); map.put("accountType", accountType);
map.put("prefixType", prefixType); map.put("prefixType", prefixType);
return new Gson().toJson(map); return new Gson().toJson(map);
} }
public String updatePrefixType(final String prefixType) { public String updatePrefixType(final String prefixType) {
final HashMap<String, Object> map = new HashMap<>(); final HashMap<String, Object> map = new HashMap<>();
map.put("prefixType", prefixType); map.put("prefixType", prefixType);
return new Gson().toJson(map); return new Gson().toJson(map);
} }
} }
@@ -20,170 +20,218 @@ import com.jayway.restassured.specification.ResponseSpecification;
public class CodeHelper { public class CodeHelper {
public static final String CODE_ID_ATTRIBUTE_NAME = "id"; public static final String CODE_ID_ATTRIBUTE_NAME = "id";
public static final String RESPONSE_ID_ATTRIBUTE_NAME = "resourceId"; public static final String RESPONSE_ID_ATTRIBUTE_NAME = "resourceId";
public static final String SUBRESPONSE_ID_ATTRIBUTE_NAME = "subResourceId"; public static final String SUBRESPONSE_ID_ATTRIBUTE_NAME = "subResourceId";
public static final String CODE_NAME_ATTRIBUTE_NAME = "name"; public static final String CODE_NAME_ATTRIBUTE_NAME = "name";
public static final String CODE_SYSTEM_DEFINED_ATTRIBUTE_NAME = "systemDefined"; public static final String CODE_SYSTEM_DEFINED_ATTRIBUTE_NAME = "systemDefined";
public static final String CODE_URL = "/mifosng-provider/api/v1/codes"; public static final String CODE_URL = "/mifosng-provider/api/v1/codes";
public static final String CODE_VALUE_ID_ATTRIBUTE_NAME = "id"; public static final String CODE_VALUE_ID_ATTRIBUTE_NAME = "id";
public static final String CODE_VALUE_NAME_ATTRIBUTE_NAME = "name"; public static final String CODE_VALUE_NAME_ATTRIBUTE_NAME = "name";
public static final String CODE_VALUE_DESCRIPTION_ATTRIBUTE_NAME = "description"; public static final String CODE_VALUE_DESCRIPTION_ATTRIBUTE_NAME = "description";
public static final String CODE_VALUE_POSITION_ATTRIBUTE_NAME = "position"; public static final String CODE_VALUE_POSITION_ATTRIBUTE_NAME = "position";
public static final String CODE_VALUE_URL = "/mifosng-provider/api/v1/codes/[codeId]/codevalues"; public static final String CODE_VALUE_URL = "/mifosng-provider/api/v1/codes/[codeId]/codevalues";
public static Object createCode(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, public static Object createCode(final RequestSpecification requestSpec,
final String codeName, final String jsonAttributeToGetback) { final ResponseSpecification responseSpec, final String codeName,
final String jsonAttributeToGetback) {
return Utils.performServerPost(requestSpec, responseSpec, CODE_URL + "?" + Utils.TENANT_IDENTIFIER, getTestCodeAsJSON(codeName), return Utils.performServerPost(requestSpec, responseSpec, CODE_URL
jsonAttributeToGetback); + "?" + Utils.TENANT_IDENTIFIER, getTestCodeAsJSON(codeName),
} jsonAttributeToGetback);
}
public static Object updateCode(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, final Integer codeId, public static Object updateCode(final RequestSpecification requestSpec,
final String codeName, final String jsonAttributeToGetback) { final ResponseSpecification responseSpec, final Integer codeId,
final String codeName, final String jsonAttributeToGetback) {
return Utils.performServerPut(requestSpec, responseSpec, CODE_URL + "/" + codeId + "?" + Utils.TENANT_IDENTIFIER, return Utils.performServerPut(requestSpec, responseSpec, CODE_URL + "/"
getTestCodeAsJSON(codeName), jsonAttributeToGetback); + codeId + "?" + Utils.TENANT_IDENTIFIER,
} getTestCodeAsJSON(codeName), jsonAttributeToGetback);
}
public static Object getCodeById(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, public static Object getCodeById(final RequestSpecification requestSpec,
final Integer codeId, final String jsonAttributeToGetback) { final ResponseSpecification responseSpec, final Integer codeId,
final String jsonAttributeToGetback) {
return Utils.performServerGet(requestSpec, responseSpec, CODE_URL + "/" + codeId + "?" + Utils.TENANT_IDENTIFIER, return Utils.performServerGet(requestSpec, responseSpec, CODE_URL + "/"
jsonAttributeToGetback); + codeId + "?" + Utils.TENANT_IDENTIFIER,
jsonAttributeToGetback);
} }
public static HashMap<String,Object> getCodeByName(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, public static HashMap<String, Object> getCodeByName(
final String codeName, final String jsonAttributeToGetback){ final RequestSpecification requestSpec,
final ResponseSpecification responseSpec, final String codeName) {
final HashMap<String, Object> code = new HashMap<>(); final HashMap<String, Object> code = new HashMap<>();
ArrayList<HashMap<String,Object>> getAllCodes = (ArrayList<HashMap<String,Object>>) CodeHelper.getAllCodes(requestSpec, responseSpec); ArrayList<HashMap<String, Object>> getAllCodes = CodeHelper
for (HashMap<String, Object>map : getAllCodes) { .getAllCodes(requestSpec, responseSpec);
for (HashMap<String, Object> map : getAllCodes) {
String name = (String) map.get("name"); String name = (String) map.get("name");
if (name.equals(codeName)) { if (name.equals(codeName)) {
code.put("id", map.get("id")); code.put("id", map.get("id"));
code.put("name", map.get("name")); code.put("name", map.get("name"));
code.put("position", map.get("position")); code.put("systemDefined", map.get("systemDefined"));
code.put("description",map.get("description"));
break; break;
} }
} }
return code; return code;
} }
public static HashMap<String,Object> retrieveOrCreateCodeValue(Integer codeId,final RequestSpecification requestSpec, public static HashMap<String, Object> retrieveOrCreateCodeValue(
final ResponseSpecification responseSpec,final String jsonAttributeToGetBack) { Integer codeId, final RequestSpecification requestSpec,
Integer codeValueId = null; final ResponseSpecification responseSpec) {
final List<HashMap<String,Object>> codeValuesList = Integer codeValueId = null;
(List<HashMap<String,Object>>) CodeHelper.getCodeValuesForCode(requestSpec,responseSpec, codeId,""); final List<HashMap<String, Object>> codeValuesList = CodeHelper
.getCodeValuesForCode(requestSpec, responseSpec, codeId, "");
/* If Code Values doesn't exist,then create Code value */ /* If Code Values doesn't exist,then create Code value */
if (codeValuesList.size() == 0) { if (codeValuesList.size() == 0) {
final Integer codeValuePosition = 0; final Integer codeValuePosition = 0;
final String codeValue = Utils.randomNameGenerator("", 3); final String codeValue = Utils.randomNameGenerator("", 3);
codeValueId = (Integer)CodeHelper.createCodeValue(requestSpec, responseSpec, codeId , codeValue,codeValuePosition, "resourceId"); codeValueId = (Integer) CodeHelper.createCodeValue(requestSpec,
responseSpec, codeId, codeValue, codeValuePosition,
"subResourceId");
} else { } else {
codeValueId = (Integer) codeValuesList.get(0).get("id"); codeValueId = (Integer) codeValuesList.get(0).get("id");
} }
return Utils.performServerGet(requestSpec, responseSpec, return Utils.performServerGet(requestSpec, responseSpec,
CODE_VALUE_URL.replace("[codeId]", codeId.toString()) + "/" + codeValueId.toString() + "?" + Utils.TENANT_IDENTIFIER, CODE_VALUE_URL.replace("[codeId]", codeId.toString()) + "/"
""); + codeValueId.toString() + "?"
+ Utils.TENANT_IDENTIFIER, "");
} }
public static ArrayList<HashMap<String,Object>> getAllCodes(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { public static ArrayList<HashMap<String, Object>> getAllCodes(
final RequestSpecification requestSpec,
final ResponseSpecification responseSpec) {
return Utils.performServerGet(requestSpec, responseSpec, CODE_URL + "?" + Utils.TENANT_IDENTIFIER, ""); return Utils.performServerGet(requestSpec, responseSpec, CODE_URL + "?"
+ Utils.TENANT_IDENTIFIER, "");
} }
public static Object getSystemDefinedCodes(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) { public static Object getSystemDefinedCodes(
final RequestSpecification requestSpec,
final ResponseSpecification responseSpec) {
final String getResponse = given().spec(requestSpec).expect().spec(responseSpec).when() final String getResponse = given().spec(requestSpec).expect()
.get(CodeHelper.CODE_URL + "?" + Utils.TENANT_IDENTIFIER).asString(); .spec(responseSpec).when()
.get(CodeHelper.CODE_URL + "?" + Utils.TENANT_IDENTIFIER)
.asString();
final JsonPath getResponseJsonPath = new JsonPath(getResponse); final JsonPath getResponseJsonPath = new JsonPath(getResponse);
// get any systemDefined code // get any systemDefined code
return getResponseJsonPath.get("find { e -> e.systemDefined == true }"); return getResponseJsonPath.get("find { e -> e.systemDefined == true }");
} }
public static String getTestCodeAsJSON(final String codeName) { public static String getTestCodeAsJSON(final String codeName) {
final HashMap<String, String> map = new HashMap<>(); final HashMap<String, String> map = new HashMap<>();
map.put(CODE_NAME_ATTRIBUTE_NAME, codeName); map.put(CODE_NAME_ATTRIBUTE_NAME, codeName);
return new Gson().toJson(map); return new Gson().toJson(map);
} }
public static String getTestCodeValueAsJSON(final String codeValueName, final String description, final Integer position) { public static String getTestCodeValueAsJSON(final String codeValueName,
final HashMap<String, Object> map = new HashMap<>(); final String description, final Integer position) {
map.put(CODE_VALUE_NAME_ATTRIBUTE_NAME, codeValueName); final HashMap<String, Object> map = new HashMap<>();
if (description != null) { map.put(CODE_VALUE_NAME_ATTRIBUTE_NAME, codeValueName);
map.put(CODE_VALUE_DESCRIPTION_ATTRIBUTE_NAME, description); if (description != null) {
} map.put(CODE_VALUE_DESCRIPTION_ATTRIBUTE_NAME, description);
map.put(CODE_VALUE_POSITION_ATTRIBUTE_NAME, position); }
return new Gson().toJson(map); map.put(CODE_VALUE_POSITION_ATTRIBUTE_NAME, position);
} return new Gson().toJson(map);
}
public static Object deleteCodeById(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, public static Object deleteCodeById(final RequestSpecification requestSpec,
final Integer codeId, final String jsonAttributeToGetback) { final ResponseSpecification responseSpec, final Integer codeId,
final String jsonAttributeToGetback) {
return Utils.performServerDelete(requestSpec, responseSpec, CODE_URL + "/" + codeId + "?" + Utils.TENANT_IDENTIFIER, return Utils.performServerDelete(requestSpec, responseSpec, CODE_URL
jsonAttributeToGetback); + "/" + codeId + "?" + Utils.TENANT_IDENTIFIER,
jsonAttributeToGetback);
} }
public static Object createCodeValue(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, public static Object createCodeValue(
final Integer codeId, final String codeValueName, final Integer position, final String jsonAttributeToGetback) { final RequestSpecification requestSpec,
String description = null; final ResponseSpecification responseSpec, final Integer codeId,
return createCodeValue(requestSpec, responseSpec, codeId, codeValueName, description, position, jsonAttributeToGetback); final String codeValueName, final Integer position,
} final String jsonAttributeToGetback) {
String description = null;
return createCodeValue(requestSpec, responseSpec, codeId,
codeValueName, description, position, jsonAttributeToGetback);
}
public static Object createCodeValue(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, public static Object createCodeValue(
final Integer codeId, final String codeValueName, final String description, final Integer position, final RequestSpecification requestSpec,
final String jsonAttributeToGetback) { final ResponseSpecification responseSpec, final Integer codeId,
final String codeValueName, final String description,
final Integer position, final String jsonAttributeToGetback) {
return Utils.performServerPost(requestSpec, responseSpec, CODE_VALUE_URL.replace("[codeId]", codeId.toString()) + "?" return Utils.performServerPost(requestSpec, responseSpec,
+ Utils.TENANT_IDENTIFIER, getTestCodeValueAsJSON(codeValueName, description, position), jsonAttributeToGetback); CODE_VALUE_URL.replace("[codeId]", codeId.toString()) + "?"
} + Utils.TENANT_IDENTIFIER,
getTestCodeValueAsJSON(codeValueName, description, position),
jsonAttributeToGetback);
}
public static List<HashMap<String,Object>> getCodeValuesForCode(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, public static List<HashMap<String, Object>> getCodeValuesForCode(
final Integer codeId, final String jsonAttributeToGetback) { final RequestSpecification requestSpec,
final ResponseSpecification responseSpec, final Integer codeId,
final String jsonAttributeToGetback) {
return Utils.performServerGet(requestSpec, responseSpec, CODE_VALUE_URL.replace("[codeId]", codeId.toString()) + "?" return Utils.performServerGet(requestSpec, responseSpec,
+ Utils.TENANT_IDENTIFIER, jsonAttributeToGetback); CODE_VALUE_URL.replace("[codeId]", codeId.toString()) + "?"
} + Utils.TENANT_IDENTIFIER, jsonAttributeToGetback);
}
public static Object getCodeValueById(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, public static Object getCodeValueById(
final Integer codeId, final Integer codeValueId, final String jsonAttributeToGetback) { final RequestSpecification requestSpec,
final ResponseSpecification responseSpec, final Integer codeId,
final Integer codeValueId, final String jsonAttributeToGetback) {
return Utils.performServerGet(requestSpec, responseSpec, return Utils.performServerGet(requestSpec, responseSpec,
CODE_VALUE_URL.replace("[codeId]", codeId.toString()) + "/" + codeValueId.toString() + "?" + Utils.TENANT_IDENTIFIER, CODE_VALUE_URL.replace("[codeId]", codeId.toString()) + "/"
jsonAttributeToGetback); + codeValueId.toString() + "?"
} + Utils.TENANT_IDENTIFIER, jsonAttributeToGetback);
}
public static Object deleteCodeValueById(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, public static Object deleteCodeValueById(
final Integer codeId, final Integer codeValueId, final String jsonAttributeToGetback) { final RequestSpecification requestSpec,
final ResponseSpecification responseSpec, final Integer codeId,
final Integer codeValueId, final String jsonAttributeToGetback) {
return Utils.performServerDelete(requestSpec, responseSpec, CODE_VALUE_URL.replace("[codeId]", codeId.toString()) + "/" return Utils.performServerDelete(requestSpec, responseSpec,
+ codeValueId.toString() + "?" + Utils.TENANT_IDENTIFIER, jsonAttributeToGetback); CODE_VALUE_URL.replace("[codeId]", codeId.toString()) + "/"
} + codeValueId.toString() + "?"
+ Utils.TENANT_IDENTIFIER, jsonAttributeToGetback);
}
public static Object updateCodeValue(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, public static Object updateCodeValue(
final Integer codeId, final Integer codeValueId, final String codeValueName, final Integer position, final RequestSpecification requestSpec,
final String jsonAttributeToGetback) { final ResponseSpecification responseSpec, final Integer codeId,
String description = null; final Integer codeValueId, final String codeValueName,
return updateCodeValue(requestSpec, responseSpec, codeId, codeValueId, codeValueName, description, position, jsonAttributeToGetback); final Integer position, final String jsonAttributeToGetback) {
} String description = null;
return updateCodeValue(requestSpec, responseSpec, codeId, codeValueId,
codeValueName, description, position, jsonAttributeToGetback);
}
public static Object updateCodeValue(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, public static Object updateCodeValue(
final Integer codeId, final Integer codeValueId, final String codeValueName, final String description, final Integer position, final RequestSpecification requestSpec,
final String jsonAttributeToGetback) { final ResponseSpecification responseSpec, final Integer codeId,
final Integer codeValueId, final String codeValueName,
final String description, final Integer position,
final String jsonAttributeToGetback) {
return Utils.performServerPut(requestSpec, responseSpec, CODE_VALUE_URL.replace("[codeId]", codeId.toString()) + "/" + codeValueId return Utils.performServerPut(requestSpec, responseSpec,
+ "?" + Utils.TENANT_IDENTIFIER, getTestCodeValueAsJSON(codeValueName, description, position), jsonAttributeToGetback); CODE_VALUE_URL.replace("[codeId]", codeId.toString()) + "/"
} + codeValueId + "?" + Utils.TENANT_IDENTIFIER,
getTestCodeValueAsJSON(codeValueName, description, position),
jsonAttributeToGetback);
}
} }
@@ -16,8 +16,8 @@ public class ClientApiConstants {
public static final String CLIENT_RESOURCE_NAME = "client"; public static final String CLIENT_RESOURCE_NAME = "client";
public static final String CLIENT_CLOSURE_REASON = "ClientClosureReason"; public static final String CLIENT_CLOSURE_REASON = "ClientClosureReason";
public static final String CLIENT_ACTION_REASON = "ClientActionReason"; public static final String CLIENT_ACTION_REASON = "ClientActionReason";
public static final String CLIENT_REJECT_REASON = "ClientRejectReason"; public static final String CLIENT_REJECT_REASON = "ClientRejectionReason";
public static final String CLIENT_WITHDRAW_REASON = "ClientWithdrawReason"; public static final String CLIENT_WITHDRAW_REASON = "ClientWithdrawalReason";
public static final String GENDER = "Gender"; public static final String GENDER = "Gender";
@@ -46,10 +46,10 @@ public class ClientApiConstants {
public static final String closureDateParamName = "closureDate"; public static final String closureDateParamName = "closureDate";
public static final String closureReasonIdParamName = "closureReasonId"; public static final String closureReasonIdParamName = "closureReasonId";
public static final String rejectDateParamName = "rejectionDate"; public static final String rejectionDateParamName = "rejectionDate";
public static final String rejectReasonIdParamName ="rejectionReasonId"; public static final String rejectionReasonIdParamName ="rejectionReasonId";
public static final String withdrawDateParamName = "withdrawalDate"; public static final String withdrawalDateParamName = "withdrawalDate";
public static final String withdrawReasonIdParamName ="withdrawalReasonId"; public static final String withdrawalReasonIdParamName ="withdrawalReasonId";
public static final String submittedOnDateParamName = "submittedOnDate"; public static final String submittedOnDateParamName = "submittedOnDate";
public static final String savingsProductIdParamName = "savingsProductId"; public static final String savingsProductIdParamName = "savingsProductId";
@@ -115,8 +115,8 @@ public class ClientApiConstants {
public static final Set<String> CLIENT_CLOSE_REQUEST_DATA_PARAMETERS = new HashSet<>(Arrays.asList(localeParamName, public static final Set<String> CLIENT_CLOSE_REQUEST_DATA_PARAMETERS = new HashSet<>(Arrays.asList(localeParamName,
dateFormatParamName, closureDateParamName, closureReasonIdParamName)); dateFormatParamName, closureDateParamName, closureReasonIdParamName));
public static final Set<String> CLIENT_REJECT_DATA_PARAMETERS = new HashSet<>(Arrays.asList(localeParamName,dateFormatParamName,rejectDateParamName,rejectReasonIdParamName)); public static final Set<String> CLIENT_REJECT_DATA_PARAMETERS = new HashSet<>(Arrays.asList(localeParamName,dateFormatParamName,rejectionDateParamName,rejectionReasonIdParamName));
public static final Set<String> CLIENT_WITHDRAW_DATA_PARAMETERS = new HashSet<>(Arrays.asList(localeParamName,dateFormatParamName,withdrawDateParamName,withdrawReasonIdParamName)); public static final Set<String> CLIENT_WITHDRAW_DATA_PARAMETERS = new HashSet<>(Arrays.asList(localeParamName,dateFormatParamName,withdrawalDateParamName,withdrawalReasonIdParamName));
} }
@@ -527,11 +527,11 @@ public final class ClientDataValidator {
final JsonElement element = command.parsedJson(); final JsonElement element = command.parsedJson();
final LocalDate rejectDate = this.fromApiJsonHelper.extractLocalDateNamed(ClientApiConstants.rejectDateParamName, element); final LocalDate rejectionDate = this.fromApiJsonHelper.extractLocalDateNamed(ClientApiConstants.rejectionDateParamName, element);
baseDataValidator.reset().parameter(ClientApiConstants.rejectDateParamName).value(rejectDate).notNull(); baseDataValidator.reset().parameter(ClientApiConstants.rejectionDateParamName).value(rejectionDate).notNull();
final Long rejectReasonId = this.fromApiJsonHelper.extractLongNamed(ClientApiConstants.rejectReasonIdParamName, element); final Long rejectionReasonId = this.fromApiJsonHelper.extractLongNamed(ClientApiConstants.rejectionReasonIdParamName, element);
baseDataValidator.reset().parameter(ClientApiConstants.rejectReasonIdParamName).value(rejectReasonId).notNull() baseDataValidator.reset().parameter(ClientApiConstants.rejectionReasonIdParamName).value(rejectionReasonId).notNull()
.longGreaterThanZero(); .longGreaterThanZero();
throwExceptionIfValidationWarningsExist(dataValidationErrors); throwExceptionIfValidationWarningsExist(dataValidationErrors);
@@ -553,11 +553,11 @@ public final class ClientDataValidator {
final JsonElement element = command.parsedJson(); final JsonElement element = command.parsedJson();
final LocalDate withdrawDate = this.fromApiJsonHelper.extractLocalDateNamed(ClientApiConstants.withdrawDateParamName, element); final LocalDate withdrawalDate = this.fromApiJsonHelper.extractLocalDateNamed(ClientApiConstants.withdrawalDateParamName, element);
baseDataValidator.reset().parameter(ClientApiConstants.withdrawDateParamName).value(withdrawDate).notNull(); baseDataValidator.reset().parameter(ClientApiConstants.withdrawalDateParamName).value(withdrawalDate).notNull();
final Long withdrawReasonId = this.fromApiJsonHelper.extractLongNamed(ClientApiConstants.withdrawReasonIdParamName, element); final Long withdrawalReasonId = this.fromApiJsonHelper.extractLongNamed(ClientApiConstants.withdrawalReasonIdParamName, element);
baseDataValidator.reset().parameter(ClientApiConstants.withdrawReasonIdParamName).value(withdrawReasonId).notNull() baseDataValidator.reset().parameter(ClientApiConstants.withdrawalReasonIdParamName).value(withdrawalReasonId).notNull()
.longGreaterThanZero(); .longGreaterThanZero();
throwExceptionIfValidationWarningsExist(dataValidationErrors); throwExceptionIfValidationWarningsExist(dataValidationErrors);
@@ -139,11 +139,11 @@ public final class Client extends AbstractPersistable<Long> {
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "reject_reason_cv_id", nullable = true) @JoinColumn(name = "reject_reason_cv_id", nullable = true)
private CodeValue rejectReason; private CodeValue rejectionReason;
@Column(name = "rejectedon_date", nullable = true) @Column(name = "rejectedon_date", nullable = true)
@Temporal(TemporalType.DATE) @Temporal(TemporalType.DATE)
private Date rejectDate; private Date rejectionDate;
@ManyToOne(optional = true) @ManyToOne(optional = true)
@JoinColumn(name = "rejectedon_userid", nullable = true) @JoinColumn(name = "rejectedon_userid", nullable = true)
@@ -151,11 +151,11 @@ public final class Client extends AbstractPersistable<Long> {
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "withdraw_reason_cv_id", nullable = true) @JoinColumn(name = "withdraw_reason_cv_id", nullable = true)
private CodeValue withdrawReason; private CodeValue withdrawalReason;
@Column(name = "withdrawn_on_date", nullable = true) @Column(name = "withdrawn_on_date", nullable = true)
@Temporal(TemporalType.DATE) @Temporal(TemporalType.DATE)
private Date withdrawDate; private Date withdrawalDate;
@ManyToOne(optional = true) @ManyToOne(optional = true)
@JoinColumn(name = "withdraw_on_userid", nullable = true) @JoinColumn(name = "withdraw_on_userid", nullable = true)
@@ -866,22 +866,22 @@ public final class Client extends AbstractPersistable<Long> {
return dateOfBirth; return dateOfBirth;
} }
public void reject(AppUser currentUser, CodeValue rejectReason, Date rejectDate) { public void reject(AppUser currentUser, CodeValue rejectionReason, Date rejectionDate) {
this.rejectReason = rejectReason; this.rejectionReason = rejectionReason;
this.rejectDate = rejectDate; this.rejectionDate = rejectionDate;
this.rejectedBy = currentUser; this.rejectedBy = currentUser;
this.updatedBy = currentUser; this.updatedBy = currentUser;
this.updatedOnDate = rejectDate; this.updatedOnDate = rejectionDate;
this.status = ClientStatus.REJECTED.getValue(); this.status = ClientStatus.REJECTED.getValue();
} }
public void withdraw(AppUser currentUser, CodeValue withdrawReason, Date withdrawDate) { public void withdraw(AppUser currentUser, CodeValue withdrawalReason, Date withdrawalDate) {
this.withdrawReason = withdrawReason; this.withdrawalReason = withdrawalReason;
this.withdrawDate = withdrawDate; this.withdrawalDate = withdrawalDate;
this.withdrawnBy = currentUser; this.withdrawnBy = currentUser;
this.updatedBy = currentUser; this.updatedBy = currentUser;
this.updatedOnDate = withdrawDate; this.updatedOnDate = withdrawalDate;
this.status = ClientStatus.WITHDRAWN.getValue(); this.status = ClientStatus.WITHDRAWN.getValue();
} }
@@ -604,22 +604,22 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
this.fromApiJsonDeserializer.validateRejection(command); this.fromApiJsonDeserializer.validateRejection(command);
final Client client = this.clientRepository.findOneWithNotFoundDetection(entityId); final Client client = this.clientRepository.findOneWithNotFoundDetection(entityId);
final LocalDate rejectDate = command.localDateValueOfParameterNamed(ClientApiConstants.rejectDateParamName); final LocalDate rejectionDate = command.localDateValueOfParameterNamed(ClientApiConstants.rejectionDateParamName);
final Long rejectReasonId = command.longValueOfParameterNamed(ClientApiConstants.rejectReasonIdParamName); final Long rejectionReasonId = command.longValueOfParameterNamed(ClientApiConstants.rejectionReasonIdParamName);
final CodeValue rejectReason = this.codeValueRepository.findOneByCodeNameAndIdWithNotFoundDetection( final CodeValue rejectionReason = this.codeValueRepository.findOneByCodeNameAndIdWithNotFoundDetection(
ClientApiConstants.CLIENT_REJECT_REASON, rejectReasonId); ClientApiConstants.CLIENT_REJECT_REASON, rejectionReasonId);
if (client.isNotPending()) { if (client.isNotPending()) {
final String errorMessage = "Only clients pending activation may be withdrawn."; final String errorMessage = "Only clients pending activation may be withdrawn.";
throw new InvalidClientStateTransitionException("rejection", "on.account.not.in.pending.activation.status", errorMessage, throw new InvalidClientStateTransitionException("rejection", "on.account.not.in.pending.activation.status", errorMessage,
rejectDate, client.getSubmittedOnDate()); rejectionDate, client.getSubmittedOnDate());
} else if (client.getSubmittedOnDate().isAfter(rejectDate)) { } else if (client.getSubmittedOnDate().isAfter(rejectionDate)) {
final String errorMessage = "The client rejection date cannot be before the client submitted date."; final String errorMessage = "The client rejection date cannot be before the client submitted date.";
throw new InvalidClientStateTransitionException("rejection", "date.cannot.before.client.submitted.date", errorMessage, throw new InvalidClientStateTransitionException("rejection", "date.cannot.before.client.submitted.date", errorMessage,
rejectDate, client.getSubmittedOnDate()); rejectionDate, client.getSubmittedOnDate());
} }
client.reject(currentUser, rejectReason, rejectDate.toDate()); client.reject(currentUser, rejectionReason, rejectionDate.toDate());
this.clientRepository.saveAndFlush(client); this.clientRepository.saveAndFlush(client);
return new CommandProcessingResultBuilder() // return new CommandProcessingResultBuilder() //
@@ -635,22 +635,22 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
this.fromApiJsonDeserializer.validateWithdrawn(command); this.fromApiJsonDeserializer.validateWithdrawn(command);
final Client client = this.clientRepository.findOneWithNotFoundDetection(entityId); final Client client = this.clientRepository.findOneWithNotFoundDetection(entityId);
final LocalDate withdrawDate = command.localDateValueOfParameterNamed(ClientApiConstants.withdrawDateParamName); final LocalDate withdrawalDate = command.localDateValueOfParameterNamed(ClientApiConstants.withdrawalDateParamName);
final Long withdrawReasonId = command.longValueOfParameterNamed(ClientApiConstants.withdrawReasonIdParamName); final Long withdrawalReasonId = command.longValueOfParameterNamed(ClientApiConstants.withdrawalReasonIdParamName);
final CodeValue withdrawReason = this.codeValueRepository.findOneByCodeNameAndIdWithNotFoundDetection( final CodeValue withdrawalReason = this.codeValueRepository.findOneByCodeNameAndIdWithNotFoundDetection(
ClientApiConstants.CLIENT_WITHDRAW_REASON, withdrawReasonId); ClientApiConstants.CLIENT_WITHDRAW_REASON, withdrawalReasonId);
if (client.isNotPending()) { if (client.isNotPending()) {
final String errorMessage = "Only clients pending activation may be withdrawn."; final String errorMessage = "Only clients pending activation may be withdrawn.";
throw new InvalidClientStateTransitionException("withdrawal", "on.account.not.in.pending.activation.status", errorMessage, throw new InvalidClientStateTransitionException("withdrawal", "on.account.not.in.pending.activation.status", errorMessage,
withdrawDate, client.getSubmittedOnDate()); withdrawalDate, client.getSubmittedOnDate());
} else if (client.getSubmittedOnDate().isAfter(withdrawDate)) { } else if (client.getSubmittedOnDate().isAfter(withdrawalDate)) {
final String errorMessage = "The client withdrawal date cannot be before the client submitted date."; final String errorMessage = "The client withdrawal date cannot be before the client submitted date.";
throw new InvalidClientStateTransitionException("withdrawal", "date.cannot.before.client.submitted.date", errorMessage, throw new InvalidClientStateTransitionException("withdrawal", "date.cannot.before.client.submitted.date", errorMessage,
withdrawDate, client.getSubmittedOnDate()); withdrawalDate, client.getSubmittedOnDate());
} }
client.withdraw(currentUser, withdrawReason, withdrawDate.toDate()); client.withdraw(currentUser, withdrawalReason, withdrawalDate.toDate());
this.clientRepository.saveAndFlush(client); this.clientRepository.saveAndFlush(client);
return new CommandProcessingResultBuilder() // return new CommandProcessingResultBuilder() //