initial code push
This commit is contained in:
+486
@@ -0,0 +1,486 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.CenterDomain;
|
||||
import org.apache.fineract.integrationtests.common.CenterHelper;
|
||||
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||
import org.apache.fineract.integrationtests.common.CommonConstants;
|
||||
import org.apache.fineract.integrationtests.common.GroupHelper;
|
||||
import org.apache.fineract.integrationtests.common.OfficeHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
|
||||
import org.apache.fineract.integrationtests.common.savings.SavingsAccountHelper;
|
||||
import org.apache.fineract.integrationtests.common.savings.SavingsProductHelper;
|
||||
import org.apache.fineract.integrationtests.common.system.AccountNumberPreferencesHelper;
|
||||
import org.apache.fineract.integrationtests.common.system.CodeHelper;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.jayway.restassured.builder.RequestSpecBuilder;
|
||||
import com.jayway.restassured.builder.ResponseSpecBuilder;
|
||||
import com.jayway.restassured.http.ContentType;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
public class AccountNumberPreferencesTest {
|
||||
|
||||
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 final String loanPrincipalAmount = "100000.00";
|
||||
private final String numberOfRepayments = "12";
|
||||
private final String interestRatePerPeriod = "18";
|
||||
private final String dateString = "4 September 2014";
|
||||
private final String minBalanceForInterestCalculation = null;
|
||||
private final String minRequiredBalance = null;
|
||||
private final String enforceMinRequiredBalance = "false";
|
||||
private LoanTransactionHelper loanTransactionHelper;
|
||||
private SavingsAccountHelper savingsAccountHelper;
|
||||
private AccountNumberPreferencesHelper accountNumberPreferencesHelper;
|
||||
private Integer clientAccountNumberPreferenceId;
|
||||
private Integer loanAccountNumberPreferenceId;
|
||||
private Integer savingsAccountNumberPreferenceId;
|
||||
private Integer groupsAccountNumberPreferenceId;
|
||||
private Integer centerAccountNumberPreferenceId;
|
||||
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 final String clientTypeName = "CLIENT_TYPE";
|
||||
private final String officeName = "OFFICE_NAME";
|
||||
private final String loanShortName = "LOAN_PRODUCT_SHORT_NAME";
|
||||
private final String savingsShortName = "SAVINGS_PRODUCT_SHORT_NAME";
|
||||
private Integer groupID;
|
||||
private Integer centerId;
|
||||
private String groupAccountNo;
|
||||
|
||||
@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<HashMap<String, Object>> preferenceIds = this.accountNumberPreferencesHelper.getAllAccountNumberPreferences();
|
||||
/* Deletion of valid account preference ID */
|
||||
for (HashMap<String, Object> preferenceId : preferenceIds) {
|
||||
Integer id = (Integer) preferenceId.get("id");
|
||||
HashMap<String, Object> delResponse = 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<String, Object> deletionError = 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);
|
||||
this.createAndValidateGroup(this.isAccountPreferenceSetUp);
|
||||
this.createAndValidateCenter(this.isAccountPreferenceSetUp);
|
||||
}
|
||||
|
||||
private void validateAccountNumberGenerationWithPreferences() {
|
||||
this.isAccountPreferenceSetUp = true;
|
||||
this.createAndValidateClientEntity(this.isAccountPreferenceSetUp);
|
||||
this.createAndValidateLoanEntity(this.isAccountPreferenceSetUp);
|
||||
this.createAndValidateSavingsEntity(this.isAccountPreferenceSetUp);
|
||||
this.createAndValidateGroup(this.isAccountPreferenceSetUp);
|
||||
this.createAndValidateCenter(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.groupsAccountNumberPreferenceId = (Integer) this.accountNumberPreferencesHelper.createGroupsAccountNumberPreference(
|
||||
this.responseSpec, "resourceId");
|
||||
System.out.println("Successfully created account number preferences for Groups (ID: " + this.groupsAccountNumberPreferenceId);
|
||||
|
||||
this.centerAccountNumberPreferenceId = (Integer) this.accountNumberPreferencesHelper.createCenterAccountNumberPreference(
|
||||
this.responseSpec, "resourceId");
|
||||
System.out.println("Successfully created account number preferences for Center (ID: " + this.centerAccountNumberPreferenceId);
|
||||
|
||||
this.accountNumberPreferencesHelper.verifyCreationOfAccountNumberPreferences(this.clientAccountNumberPreferenceId,
|
||||
this.loanAccountNumberPreferenceId, this.savingsAccountNumberPreferenceId, this.groupsAccountNumberPreferenceId,
|
||||
this.centerAccountNumberPreferenceId, 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<String, Object> creationError = 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<String, Object> creationError = 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<String, Object> accountNumberPreferences = this.accountNumberPreferencesHelper.updateAccountNumberPreference(
|
||||
this.clientAccountNumberPreferenceId, "101", this.responseSpec, "");
|
||||
|
||||
System.out.println("--------------------------UPDATION SUCCESSFUL FOR ACCOUNT NUMBER PREFERENCE ID "
|
||||
+ 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<String, Object> updationError = this.accountNumberPreferencesHelper.updateAccountNumberPreference(9999, "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<String, Object> updationError1 = 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 createAndValidateGroup(Boolean isAccountPreferenceSetUp) {
|
||||
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||
this.groupID = GroupHelper.createGroup(this.requestSpec, this.responseSpec);
|
||||
GroupHelper.verifyGroupCreatedOnServer(this.requestSpec, this.responseSpec, groupID);
|
||||
|
||||
this.groupID = GroupHelper.activateGroup(this.requestSpec, this.responseSpec, groupID.toString());
|
||||
GroupHelper.verifyGroupActivatedOnServer(this.requestSpec, this.responseSpec, groupID, true);
|
||||
|
||||
final String GROUP_URL = "/fineract-provider/api/v1/groups/" + this.groupID + "?" + Utils.TENANT_IDENTIFIER;
|
||||
this.groupAccountNo = Utils.performServerGet(requestSpec, responseSpec, GROUP_URL, "accountNo");
|
||||
|
||||
if (isAccountPreferenceSetUp) {
|
||||
String groupsPrefixName = (String) this.accountNumberPreferencesHelper.getAccountNumberPreference(
|
||||
this.groupsAccountNumberPreferenceId, "prefixType.value");
|
||||
|
||||
if (groupsPrefixName.equals(this.officeName)) {
|
||||
|
||||
final String groupOfficeName = Utils.performServerGet(requestSpec, responseSpec, GROUP_URL, "officeName");
|
||||
|
||||
this.validateAccountNumberLengthAndStartsWithPrefix(this.groupAccountNo, groupOfficeName);
|
||||
}
|
||||
} else {
|
||||
validateAccountNumberLengthAndStartsWithPrefix(this.groupAccountNo, null);
|
||||
}
|
||||
}
|
||||
|
||||
private void createAndValidateCenter(Boolean isAccountPreferenceSetUp) {
|
||||
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||
Integer officeId = new OfficeHelper(requestSpec, responseSpec).createOffice("01 July 2007");
|
||||
|
||||
String name = "CenterCreation" + new Timestamp(new java.util.Date().getTime());
|
||||
this.centerId = CenterHelper.createCenter(name, officeId, requestSpec, responseSpec);
|
||||
CenterDomain center = CenterHelper.retrieveByID(centerId, requestSpec, responseSpec);
|
||||
Assert.assertNotNull(center);
|
||||
Assert.assertTrue(center.getName().equals(name));
|
||||
|
||||
if (isAccountPreferenceSetUp) {
|
||||
String centerPrefixName = (String) this.accountNumberPreferencesHelper.getAccountNumberPreference(
|
||||
this.centerAccountNumberPreferenceId, "prefixType.value");
|
||||
final String CENTER_URL = "/fineract-provider/api/v1/centers/" + this.centerId + "?" + Utils.TENANT_IDENTIFIER;
|
||||
|
||||
if (centerPrefixName.equals(this.officeName)) {
|
||||
final String centerOfficeName = Utils.performServerGet(requestSpec, responseSpec, CENTER_URL, "officeName");
|
||||
this.validateAccountNumberLengthAndStartsWithPrefix(center.getAccountNo(), centerOfficeName);
|
||||
}
|
||||
} else {
|
||||
validateAccountNumberLengthAndStartsWithPrefix(center.getAccountNo(), null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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<String, Object> code = CodeHelper.getCodeByName(this.requestSpec, this.responseSpec, codeName);
|
||||
this.clientTypeCodeId = (Integer) code.get("id");
|
||||
|
||||
/* Retrieve/Create Code Values for the Code "ClientType" */
|
||||
HashMap<String, Object> codeValue = 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);
|
||||
|
||||
System.out.println("Loan Application :" + loanApplicationJSON);
|
||||
|
||||
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 + ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
+492
@@ -0,0 +1,492 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||
import org.apache.fineract.integrationtests.common.CommonConstants;
|
||||
import org.apache.fineract.integrationtests.common.OfficeHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.accounting.Account;
|
||||
import org.apache.fineract.integrationtests.common.accounting.AccountHelper;
|
||||
import org.apache.fineract.integrationtests.common.accounting.FinancialActivityAccountHelper;
|
||||
import org.apache.fineract.integrationtests.common.accounting.JournalEntry;
|
||||
import org.apache.fineract.integrationtests.common.accounting.JournalEntryHelper;
|
||||
import org.apache.fineract.integrationtests.common.accounting.Account.AccountType;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanStatusChecker;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
|
||||
import org.apache.fineract.integrationtests.common.savings.AccountTransferHelper;
|
||||
import org.apache.fineract.integrationtests.common.savings.SavingsAccountHelper;
|
||||
import org.apache.fineract.integrationtests.common.savings.SavingsProductHelper;
|
||||
import org.apache.fineract.integrationtests.common.savings.SavingsStatusChecker;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* JUnit Test Cases for Account Transfer for.
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unused" })
|
||||
public class AccountTransferTest {
|
||||
|
||||
public static final String MINIMUM_OPENING_BALANCE = "30000.0";
|
||||
public static final String ACCOUNT_TYPE_INDIVIDUAL = "INDIVIDUAL";
|
||||
public static final String ACCOUNT_TRANSFER_AMOUNT = "15000.0";
|
||||
public static final String ACCOUNT_TRANSFER_AMOUNT_ADJUST = "3000.0";
|
||||
public static final String FROM_LOAN_ACCOUNT_TYPE = "1";
|
||||
public static final String FROM_SAVINGS_ACCOUNT_TYPE = "2";
|
||||
public static final String TO_LOAN_ACCOUNT_TYPE = "1";
|
||||
public static final String TO_SAVINGS_ACCOUNT_TYPE = "2";
|
||||
|
||||
public static final String LOAN_APPROVAL_DATE = "01 March 2013";
|
||||
public static final String LOAN_APPROVAL_DATE_PLUS_ONE = "02 March 2013";
|
||||
public static final String LOAN_DISBURSAL_DATE = "01 March 2013";
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private SavingsAccountHelper savingsAccountHelper;
|
||||
private AccountTransferHelper accountTransferHelper;
|
||||
private LoanTransactionHelper loanTransactionHelper;
|
||||
private AccountHelper accountHelper;
|
||||
private JournalEntryHelper journalEntryHelper;
|
||||
|
||||
Float TRANSFER_AMOUNT = new Float(ACCOUNT_TRANSFER_AMOUNT);
|
||||
Float TRANSFER_AMOUNT_ADJUST = new Float(ACCOUNT_TRANSFER_AMOUNT_ADJUST);
|
||||
|
||||
private FinancialActivityAccountHelper financialActivityAccountHelper;
|
||||
private Integer financialActivityAccountId;
|
||||
private Account liabilityTransferAccount;
|
||||
|
||||
@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.accountHelper = new AccountHelper(this.requestSpec, this.responseSpec);
|
||||
this.journalEntryHelper = new JournalEntryHelper(this.requestSpec, this.responseSpec);
|
||||
this.financialActivityAccountHelper = new FinancialActivityAccountHelper(this.requestSpec);
|
||||
|
||||
List<HashMap> financialActivities = this.financialActivityAccountHelper.getAllFinancialActivityAccounts(this.responseSpec);
|
||||
if (financialActivities.isEmpty()) {
|
||||
/** Setup liability transfer account **/
|
||||
/** Create a Liability and an Asset Transfer Account **/
|
||||
liabilityTransferAccount = accountHelper.createLiabilityAccount();
|
||||
Assert.assertNotNull(liabilityTransferAccount);
|
||||
|
||||
/*** Create A Financial Activity to Account Mapping **/
|
||||
financialActivityAccountId = (Integer) financialActivityAccountHelper.createFinancialActivityAccount(
|
||||
FinancialActivityAccountsTest.liabilityTransferFinancialActivityId, liabilityTransferAccount.getAccountID(),
|
||||
responseSpec, CommonConstants.RESPONSE_RESOURCE_ID);
|
||||
Assert.assertNotNull(financialActivityAccountId);
|
||||
} else {
|
||||
for (HashMap financialActivity : financialActivities) {
|
||||
HashMap financialActivityData = (HashMap) financialActivity.get("financialActivityData");
|
||||
if (financialActivityData.get("id").equals(FinancialActivityAccountsTest.liabilityTransferFinancialActivityId)) {
|
||||
HashMap glAccountData = (HashMap) financialActivity.get("glAccountData");
|
||||
liabilityTransferAccount = new Account((Integer) glAccountData.get("id"), AccountType.LIABILITY);
|
||||
financialActivityAccountId = (Integer) financialActivity.get("id");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the Liability transfer account
|
||||
*/
|
||||
@After
|
||||
public void tearDown() {
|
||||
Integer deletedFinancialActivityAccountId = financialActivityAccountHelper.deleteFinancialActivityAccount(
|
||||
financialActivityAccountId, responseSpec, CommonConstants.RESPONSE_RESOURCE_ID);
|
||||
Assert.assertNotNull(deletedFinancialActivityAccountId);
|
||||
Assert.assertEquals(financialActivityAccountId, deletedFinancialActivityAccountId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFromSavingsToSavingsAccountTransfer() {
|
||||
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
|
||||
this.accountTransferHelper = new AccountTransferHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
final Account assetAccount = this.accountHelper.createAssetAccount();
|
||||
final Account incomeAccount = this.accountHelper.createIncomeAccount();
|
||||
final Account expenseAccount = this.accountHelper.createExpenseAccount();
|
||||
final Account liabilityAccount = this.accountHelper.createLiabilityAccount();
|
||||
|
||||
OfficeHelper officeHelper = new OfficeHelper(this.requestSpec, this.responseSpec);
|
||||
Integer toOfficeId = officeHelper.createOffice("01 January 2011");
|
||||
Assert.assertNotNull(toOfficeId);
|
||||
|
||||
// Creating Savings Account to which fund to be Transferred
|
||||
final Integer toClientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2011",
|
||||
String.valueOf(toOfficeId));
|
||||
Assert.assertNotNull(toClientID);
|
||||
|
||||
final Integer toSavingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE, assetAccount,
|
||||
incomeAccount, expenseAccount, liabilityAccount);
|
||||
Assert.assertNotNull(toSavingsProductID);
|
||||
|
||||
final Integer toSavingsID = this.savingsAccountHelper.applyForSavingsApplication(toClientID, toSavingsProductID,
|
||||
ACCOUNT_TYPE_INDIVIDUAL);
|
||||
Assert.assertNotNull(toSavingsProductID);
|
||||
|
||||
HashMap toSavingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, toSavingsID);
|
||||
SavingsStatusChecker.verifySavingsIsPending(toSavingsStatusHashMap);
|
||||
|
||||
toSavingsStatusHashMap = this.savingsAccountHelper.approveSavings(toSavingsID);
|
||||
SavingsStatusChecker.verifySavingsIsApproved(toSavingsStatusHashMap);
|
||||
|
||||
toSavingsStatusHashMap = this.savingsAccountHelper.activateSavings(toSavingsID);
|
||||
SavingsStatusChecker.verifySavingsIsActive(toSavingsStatusHashMap);
|
||||
|
||||
final HashMap toSavingsSummaryBefore = this.savingsAccountHelper.getSavingsSummary(toSavingsID);
|
||||
|
||||
Integer fromOfficeId = officeHelper.createOffice("01 January 2011");
|
||||
Assert.assertNotNull(fromOfficeId);
|
||||
|
||||
// Creating Savings Account from which the Fund has to be Transferred
|
||||
final Integer fromClientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2011",
|
||||
String.valueOf(fromOfficeId));
|
||||
Assert.assertNotNull(fromClientID);
|
||||
|
||||
final Integer fromSavingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE,
|
||||
assetAccount, incomeAccount, expenseAccount, liabilityAccount);
|
||||
Assert.assertNotNull(fromSavingsProductID);
|
||||
|
||||
final Integer fromSavingsID = this.savingsAccountHelper.applyForSavingsApplication(fromClientID, fromSavingsProductID,
|
||||
ACCOUNT_TYPE_INDIVIDUAL);
|
||||
Assert.assertNotNull(fromSavingsID);
|
||||
|
||||
HashMap fromSavingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, fromSavingsID);
|
||||
SavingsStatusChecker.verifySavingsIsPending(fromSavingsStatusHashMap);
|
||||
|
||||
fromSavingsStatusHashMap = this.savingsAccountHelper.approveSavings(fromSavingsID);
|
||||
SavingsStatusChecker.verifySavingsIsApproved(fromSavingsStatusHashMap);
|
||||
|
||||
fromSavingsStatusHashMap = this.savingsAccountHelper.activateSavings(fromSavingsID);
|
||||
SavingsStatusChecker.verifySavingsIsActive(fromSavingsStatusHashMap);
|
||||
|
||||
final HashMap fromSavingsSummaryBefore = this.savingsAccountHelper.getSavingsSummary(fromSavingsID);
|
||||
|
||||
Float fromSavingsBalance = new Float(MINIMUM_OPENING_BALANCE);
|
||||
Float toSavingsBalance = new Float(MINIMUM_OPENING_BALANCE);
|
||||
|
||||
this.accountTransferHelper.accountTransfer(fromClientID, fromSavingsID, fromClientID, toSavingsID, FROM_SAVINGS_ACCOUNT_TYPE,
|
||||
TO_SAVINGS_ACCOUNT_TYPE, ACCOUNT_TRANSFER_AMOUNT);
|
||||
|
||||
fromSavingsBalance -= new Float(ACCOUNT_TRANSFER_AMOUNT);
|
||||
toSavingsBalance += new Float(ACCOUNT_TRANSFER_AMOUNT);
|
||||
|
||||
HashMap fromSavingsSummaryAfter = this.savingsAccountHelper.getSavingsSummary(fromSavingsID);
|
||||
assertEquals("Verifying From Savings Account Balance after Account Transfer", fromSavingsBalance,
|
||||
fromSavingsSummaryAfter.get("accountBalance"));
|
||||
|
||||
HashMap toSavingsSummaryAfter = this.savingsAccountHelper.getSavingsSummary(toSavingsID);
|
||||
assertEquals("Verifying To Savings Account Balance after Account Transfer", toSavingsBalance,
|
||||
toSavingsSummaryAfter.get("accountBalance"));
|
||||
final JournalEntry[] office1LiabilityEntries = { new JournalEntry(new Float(ACCOUNT_TRANSFER_AMOUNT),
|
||||
JournalEntry.TransactionType.CREDIT) };
|
||||
final JournalEntry[] office2LiabilityEntries = { new JournalEntry(new Float(ACCOUNT_TRANSFER_AMOUNT),
|
||||
JournalEntry.TransactionType.DEBIT) };
|
||||
|
||||
this.journalEntryHelper.checkJournalEntryForLiabilityAccount(fromOfficeId, liabilityTransferAccount,
|
||||
AccountTransferHelper.ACCOUNT_TRANSFER_DATE, office1LiabilityEntries);
|
||||
this.journalEntryHelper.checkJournalEntryForLiabilityAccount(toOfficeId, liabilityTransferAccount,
|
||||
AccountTransferHelper.ACCOUNT_TRANSFER_DATE, office2LiabilityEntries);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFromSavingsToLoanAccountTransfer() {
|
||||
final Account assetAccount = this.accountHelper.createAssetAccount();
|
||||
final Account incomeAccount = this.accountHelper.createIncomeAccount();
|
||||
final Account expenseAccount = this.accountHelper.createExpenseAccount();
|
||||
final Account liabilityAccount = this.accountHelper.createLiabilityAccount();
|
||||
|
||||
final Account loanAssetAccount = this.accountHelper.createAssetAccount();
|
||||
final Account loanIncomeAccount = this.accountHelper.createIncomeAccount();
|
||||
final Account loanExpenseAccount = this.accountHelper.createExpenseAccount();
|
||||
final Account overpaymentAccount = this.accountHelper.createLiabilityAccount();
|
||||
|
||||
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
|
||||
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
|
||||
this.accountTransferHelper = new AccountTransferHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
OfficeHelper officeHelper = new OfficeHelper(this.requestSpec, this.responseSpec);
|
||||
Integer toOfficeId = officeHelper.createOffice("01 January 2011");
|
||||
Assert.assertNotNull(toOfficeId);
|
||||
|
||||
// Creating Loan Account to which fund to be Transferred
|
||||
final Integer toClientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2011",
|
||||
String.valueOf(toOfficeId));
|
||||
Assert.assertNotNull(toClientID);
|
||||
|
||||
Account toTransferAccount = accountHelper.createLiabilityAccount();
|
||||
Assert.assertNotNull(toTransferAccount);
|
||||
|
||||
final Integer toLoanProductID = createLoanProduct(loanAssetAccount, loanIncomeAccount, loanExpenseAccount, overpaymentAccount);
|
||||
Assert.assertNotNull(toLoanProductID);
|
||||
|
||||
final Integer toLoanID = applyForLoanApplication(toClientID, toLoanProductID);
|
||||
Assert.assertNotNull(toLoanID);
|
||||
|
||||
HashMap toLoanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, toLoanID);
|
||||
LoanStatusChecker.verifyLoanIsPending(toLoanStatusHashMap);
|
||||
|
||||
toLoanStatusHashMap = this.loanTransactionHelper.approveLoan(LOAN_APPROVAL_DATE, toLoanID);
|
||||
LoanStatusChecker.verifyLoanIsApproved(toLoanStatusHashMap);
|
||||
|
||||
toLoanStatusHashMap = this.loanTransactionHelper.disburseLoan(LOAN_DISBURSAL_DATE, toLoanID);
|
||||
LoanStatusChecker.verifyLoanIsActive(toLoanStatusHashMap);
|
||||
|
||||
Integer fromOfficeId = officeHelper.createOffice("01 January 2011");
|
||||
Assert.assertNotNull(fromOfficeId);
|
||||
|
||||
// Creating Savings Account from which the Fund has to be Transferred
|
||||
final Integer fromClientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2011",
|
||||
String.valueOf(fromOfficeId));
|
||||
Assert.assertNotNull(fromClientID);
|
||||
|
||||
final Integer fromSavingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE,
|
||||
assetAccount, incomeAccount, expenseAccount, liabilityAccount);
|
||||
Assert.assertNotNull(fromSavingsProductID);
|
||||
|
||||
final Integer fromSavingsID = this.savingsAccountHelper.applyForSavingsApplication(fromClientID, fromSavingsProductID,
|
||||
ACCOUNT_TYPE_INDIVIDUAL);
|
||||
Assert.assertNotNull(fromSavingsID);
|
||||
|
||||
HashMap fromSavingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, fromSavingsID);
|
||||
SavingsStatusChecker.verifySavingsIsPending(fromSavingsStatusHashMap);
|
||||
|
||||
fromSavingsStatusHashMap = this.savingsAccountHelper.approveSavings(fromSavingsID);
|
||||
SavingsStatusChecker.verifySavingsIsApproved(fromSavingsStatusHashMap);
|
||||
|
||||
fromSavingsStatusHashMap = this.savingsAccountHelper.activateSavings(fromSavingsID);
|
||||
SavingsStatusChecker.verifySavingsIsActive(fromSavingsStatusHashMap);
|
||||
|
||||
final HashMap fromSavingsSummaryBefore = this.savingsAccountHelper.getSavingsSummary(fromSavingsID);
|
||||
|
||||
Float fromSavingsBalance = new Float(MINIMUM_OPENING_BALANCE);
|
||||
|
||||
this.accountTransferHelper.accountTransfer(fromClientID, fromSavingsID, toClientID, toLoanID, FROM_SAVINGS_ACCOUNT_TYPE,
|
||||
TO_LOAN_ACCOUNT_TYPE, ACCOUNT_TRANSFER_AMOUNT_ADJUST);
|
||||
|
||||
fromSavingsBalance -= TRANSFER_AMOUNT_ADJUST;
|
||||
|
||||
HashMap fromSavingsSummaryAfter = this.savingsAccountHelper.getSavingsSummary(fromSavingsID);
|
||||
assertEquals("Verifying From Savings Account Balance after Account Transfer", fromSavingsBalance,
|
||||
fromSavingsSummaryAfter.get("accountBalance"));
|
||||
|
||||
HashMap toLoanSummaryAfter = this.loanTransactionHelper.getLoanSummary(requestSpec, responseSpec, toLoanID);
|
||||
assertEquals("Verifying To Loan Repayment Amount after Account Transfer", TRANSFER_AMOUNT_ADJUST,
|
||||
toLoanSummaryAfter.get("totalRepayment"));
|
||||
|
||||
final JournalEntry[] office1LiabilityEntries = { new JournalEntry(new Float(ACCOUNT_TRANSFER_AMOUNT_ADJUST),
|
||||
JournalEntry.TransactionType.CREDIT) };
|
||||
final JournalEntry[] office2LiabilityEntries = { new JournalEntry(new Float(ACCOUNT_TRANSFER_AMOUNT_ADJUST),
|
||||
JournalEntry.TransactionType.DEBIT) };
|
||||
|
||||
this.journalEntryHelper.checkJournalEntryForLiabilityAccount(fromOfficeId, liabilityTransferAccount,
|
||||
AccountTransferHelper.ACCOUNT_TRANSFER_DATE, office1LiabilityEntries);
|
||||
this.journalEntryHelper.checkJournalEntryForLiabilityAccount(toOfficeId, liabilityTransferAccount,
|
||||
AccountTransferHelper.ACCOUNT_TRANSFER_DATE, office2LiabilityEntries);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFromLoanToSavingsAccountTransfer() {
|
||||
final Account assetAccount = this.accountHelper.createAssetAccount();
|
||||
final Account incomeAccount = this.accountHelper.createIncomeAccount();
|
||||
final Account expenseAccount = this.accountHelper.createExpenseAccount();
|
||||
final Account liabilityAccount = this.accountHelper.createLiabilityAccount();
|
||||
|
||||
final Account loanAssetAccount = this.accountHelper.createAssetAccount();
|
||||
final Account loanIncomeAccount = this.accountHelper.createIncomeAccount();
|
||||
final Account loanExpenseAccount = this.accountHelper.createExpenseAccount();
|
||||
final Account overpaymentAccount = this.accountHelper.createLiabilityAccount();
|
||||
|
||||
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
|
||||
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
|
||||
this.accountTransferHelper = new AccountTransferHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
OfficeHelper officeHelper = new OfficeHelper(this.requestSpec, this.responseSpec);
|
||||
Integer toOfficeId = officeHelper.createOffice("01 January 2011");
|
||||
Assert.assertNotNull(toOfficeId);
|
||||
|
||||
// Creating Loan Account to which fund to be Transferred
|
||||
final Integer toClientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2011",
|
||||
String.valueOf(toOfficeId));
|
||||
Assert.assertNotNull(toClientID);
|
||||
|
||||
final Integer toSavingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE, assetAccount,
|
||||
incomeAccount, expenseAccount, liabilityAccount);
|
||||
Assert.assertNotNull(toSavingsProductID);
|
||||
|
||||
final Integer toSavingsID = this.savingsAccountHelper.applyForSavingsApplication(toClientID, toSavingsProductID,
|
||||
ACCOUNT_TYPE_INDIVIDUAL);
|
||||
Assert.assertNotNull(toSavingsID);
|
||||
|
||||
HashMap toSavingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, toSavingsID);
|
||||
SavingsStatusChecker.verifySavingsIsPending(toSavingsStatusHashMap);
|
||||
|
||||
toSavingsStatusHashMap = this.savingsAccountHelper.approveSavings(toSavingsID);
|
||||
SavingsStatusChecker.verifySavingsIsApproved(toSavingsStatusHashMap);
|
||||
|
||||
toSavingsStatusHashMap = this.savingsAccountHelper.activateSavings(toSavingsID);
|
||||
SavingsStatusChecker.verifySavingsIsActive(toSavingsStatusHashMap);
|
||||
|
||||
Integer fromOfficeId = officeHelper.createOffice("01 January 2011");
|
||||
Assert.assertNotNull(fromOfficeId);
|
||||
|
||||
// Creating Savings Account from which the Fund has to be Transferred
|
||||
final Integer fromClientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2011",
|
||||
String.valueOf(fromOfficeId));
|
||||
Assert.assertNotNull(fromClientID);
|
||||
|
||||
final Integer loanProductID = createLoanProduct(loanAssetAccount, loanIncomeAccount, loanExpenseAccount, overpaymentAccount);
|
||||
Assert.assertNotNull(loanProductID);
|
||||
|
||||
final Integer loanID = applyForLoanApplication(fromClientID, loanProductID);
|
||||
Assert.assertNotNull(loanID);
|
||||
|
||||
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
|
||||
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
|
||||
|
||||
loanStatusHashMap = this.loanTransactionHelper.approveLoan(LOAN_APPROVAL_DATE, loanID);
|
||||
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
|
||||
|
||||
loanStatusHashMap = this.loanTransactionHelper.disburseLoan(LOAN_DISBURSAL_DATE, loanID);
|
||||
LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
|
||||
|
||||
final Integer fromSavingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE,
|
||||
assetAccount, incomeAccount, expenseAccount, liabilityAccount);
|
||||
Assert.assertNotNull(fromSavingsProductID);
|
||||
|
||||
final Integer fromSavingsID = this.savingsAccountHelper.applyForSavingsApplication(fromClientID, fromSavingsProductID,
|
||||
ACCOUNT_TYPE_INDIVIDUAL);
|
||||
Assert.assertNotNull(fromSavingsID);
|
||||
|
||||
HashMap fromSavingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, fromSavingsID);
|
||||
SavingsStatusChecker.verifySavingsIsPending(fromSavingsStatusHashMap);
|
||||
|
||||
fromSavingsStatusHashMap = this.savingsAccountHelper.approveSavings(fromSavingsID);
|
||||
SavingsStatusChecker.verifySavingsIsApproved(fromSavingsStatusHashMap);
|
||||
|
||||
fromSavingsStatusHashMap = this.savingsAccountHelper.activateSavings(fromSavingsID);
|
||||
SavingsStatusChecker.verifySavingsIsActive(fromSavingsStatusHashMap);
|
||||
|
||||
final HashMap toSavingsSummaryBefore = this.savingsAccountHelper.getSavingsSummary(toSavingsID);
|
||||
|
||||
Float fromSavingsBalance = new Float(MINIMUM_OPENING_BALANCE);
|
||||
|
||||
this.accountTransferHelper.accountTransfer(fromClientID, fromSavingsID, fromClientID, loanID, FROM_SAVINGS_ACCOUNT_TYPE,
|
||||
TO_LOAN_ACCOUNT_TYPE, ACCOUNT_TRANSFER_AMOUNT);
|
||||
|
||||
fromSavingsBalance -= TRANSFER_AMOUNT;
|
||||
|
||||
HashMap fromSavingsSummaryAfter = this.savingsAccountHelper.getSavingsSummary(fromSavingsID);
|
||||
|
||||
// Verifying fromSavings Account Balance after Account Transfer
|
||||
assertEquals("Verifying From Savings Account Balance after Account Transfer", fromSavingsBalance,
|
||||
fromSavingsSummaryAfter.get("accountBalance"));
|
||||
|
||||
Float toSavingsBalance = new Float(MINIMUM_OPENING_BALANCE);
|
||||
|
||||
this.accountTransferHelper.accountTransfer(fromClientID, loanID, toClientID, toSavingsID, FROM_LOAN_ACCOUNT_TYPE,
|
||||
TO_SAVINGS_ACCOUNT_TYPE, ACCOUNT_TRANSFER_AMOUNT_ADJUST);
|
||||
|
||||
toSavingsBalance += TRANSFER_AMOUNT_ADJUST;
|
||||
|
||||
HashMap toSavingsSummaryAfter = this.savingsAccountHelper.getSavingsSummary(toSavingsID);
|
||||
|
||||
// Verifying toSavings Account Balance after Account Transfer
|
||||
assertEquals("Verifying From Savings Account Balance after Account Transfer", toSavingsBalance,
|
||||
toSavingsSummaryAfter.get("accountBalance"));
|
||||
|
||||
final JournalEntry[] office1LiabilityEntries = { new JournalEntry(new Float(ACCOUNT_TRANSFER_AMOUNT_ADJUST),
|
||||
JournalEntry.TransactionType.CREDIT) };
|
||||
final JournalEntry[] office2LiabilityEntries = { new JournalEntry(new Float(ACCOUNT_TRANSFER_AMOUNT_ADJUST),
|
||||
JournalEntry.TransactionType.DEBIT) };
|
||||
|
||||
this.journalEntryHelper.checkJournalEntryForLiabilityAccount(fromOfficeId, liabilityTransferAccount,
|
||||
AccountTransferHelper.ACCOUNT_TRANSFER_DATE, office1LiabilityEntries);
|
||||
this.journalEntryHelper.checkJournalEntryForLiabilityAccount(toOfficeId, liabilityTransferAccount,
|
||||
AccountTransferHelper.ACCOUNT_TRANSFER_DATE, office2LiabilityEntries);
|
||||
|
||||
}
|
||||
|
||||
private Integer createSavingsProduct(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String minOpenningBalance, final Account... accounts) {
|
||||
System.out.println("------------------------------CREATING NEW SAVINGS PRODUCT ---------------------------------------");
|
||||
SavingsProductHelper savingsProductHelper = new SavingsProductHelper();
|
||||
final String savingsProductJSON = savingsProductHelper //
|
||||
.withInterestCompoundingPeriodTypeAsDaily() //
|
||||
.withInterestPostingPeriodTypeAsMonthly() //
|
||||
.withInterestCalculationPeriodTypeAsDailyBalance() //
|
||||
.withMinimumOpenningBalance(minOpenningBalance).withAccountingRuleAsCashBased(accounts).build();
|
||||
return SavingsProductHelper.createSavingsProduct(savingsProductJSON, requestSpec, responseSpec);
|
||||
}
|
||||
|
||||
private Integer createLoanProduct(final Account... accounts) {
|
||||
System.out.println("------------------------------CREATING NEW LOAN PRODUCT ---------------------------------------");
|
||||
final String loanProductJSON = new LoanProductTestBuilder() //
|
||||
.withPrincipal("8,000.00") //
|
||||
.withNumberOfRepayments("4") //
|
||||
.withRepaymentAfterEvery("1") //
|
||||
.withRepaymentTypeAsMonth() //
|
||||
.withinterestRatePerPeriod("1") //
|
||||
.withInterestRateFrequencyTypeAsMonths() //
|
||||
.withAmortizationTypeAsEqualInstallments() //
|
||||
.withInterestTypeAsDecliningBalance() //
|
||||
.withAccountingRuleAsCashBased(accounts)//
|
||||
.build(null);
|
||||
return this.loanTransactionHelper.getLoanProductId(loanProductJSON);
|
||||
}
|
||||
|
||||
private Integer applyForLoanApplication(final Integer clientID, final Integer loanProductID) {
|
||||
System.out.println("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------");
|
||||
final String loanApplicationJSON = new LoanApplicationTestBuilder() //
|
||||
.withPrincipal("8,000.00") //
|
||||
.withLoanTermFrequency("4") //
|
||||
.withLoanTermFrequencyAsMonths() //
|
||||
.withNumberOfRepayments("4") //
|
||||
.withRepaymentEveryAfter("1") //
|
||||
.withRepaymentFrequencyTypeAsMonths() //
|
||||
.withInterestRatePerPeriod("2") //
|
||||
.withAmortizationTypeAsEqualInstallments() //
|
||||
.withInterestTypeAsDecliningBalance() //
|
||||
.withInterestCalculationPeriodTypeSameAsRepaymentPeriod() //
|
||||
.withExpectedDisbursementDate("10 January 2013") //
|
||||
.withSubmittedOnDate("10 January 2013") //
|
||||
.build(clientID.toString(), loanProductID.toString(), null);
|
||||
return this.loanTransactionHelper.getLoanId(loanApplicationJSON);
|
||||
}
|
||||
}
|
||||
+1078
File diff suppressed because it is too large
Load Diff
+425
@@ -0,0 +1,425 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.fineract.batch.domain.BatchRequest;
|
||||
import org.apache.fineract.batch.domain.BatchResponse;
|
||||
import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
|
||||
import org.apache.fineract.integrationtests.common.BatchHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
|
||||
import org.apache.fineract.integrationtests.common.savings.SavingsProductHelper;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Test class for
|
||||
* {@link org.apache.fineract.batch.command.CommandStrategyProvider}. This tests
|
||||
* the response provided by commandStrategy by injecting it with a
|
||||
* {@code BatchRequest}.
|
||||
*
|
||||
* @author RishabhShukla
|
||||
*
|
||||
* @see org.apache.fineract.integrationtests.common.BatchHelper
|
||||
* @see org.apache.fineract.batch.domain.BatchRequest
|
||||
*/
|
||||
public class BatchApiTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
|
||||
public BatchApiTest() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the essential settings for the TEST like contentType,
|
||||
* expectedStatusCode. It uses the '@Before' annotation provided by jUnit.
|
||||
*/
|
||||
@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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for the unimplemented command Strategies by returning 501 status
|
||||
* code. For a unknownRequest a statusCode 501 is returned back with
|
||||
* response.
|
||||
*
|
||||
* @see org.apache.fineract.batch.command.internal.UnknownCommandStrategy
|
||||
*/
|
||||
@Test
|
||||
public void shouldReturnStatusNotImplementedUnknownCommand() {
|
||||
|
||||
final BatchRequest br = new BatchRequest();
|
||||
br.setRequestId(4711L);
|
||||
br.setRelativeUrl("/nirvana");
|
||||
br.setMethod("POST");
|
||||
|
||||
final List<BatchResponse> response = BatchHelper.postWithSingleRequest(this.requestSpec, this.responseSpec, br);
|
||||
|
||||
// Verify that only 501 is returned as the status code
|
||||
for (BatchResponse resp : response) {
|
||||
Assert.assertEquals("Verify Status code 501", (long) 501, (long) resp.getStatusCode());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for the successful response for a createClient request from
|
||||
* createClientCommand. A successful response with statusCode '200' is
|
||||
* returned back.
|
||||
*
|
||||
* @see org.apache.fineract.batch.command.internal.CreateClientCommandStrategy
|
||||
*/
|
||||
@Test
|
||||
public void shouldReturnOkStatusForCreateClientCommand() {
|
||||
|
||||
final BatchRequest br = BatchHelper.createClientRequest(4712L, "");
|
||||
|
||||
final List<BatchResponse> response = BatchHelper.postWithSingleRequest(this.requestSpec, this.responseSpec, br);
|
||||
|
||||
// Verify that a 200 response is returned as the status code
|
||||
for (BatchResponse resp : response) {
|
||||
Assert.assertEquals("Verify Status code 200", (long) 200, (long) resp.getStatusCode());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for an erroneous response with statusCode '501' if transaction
|
||||
* fails. If Query Parameter 'enclosingTransaction' is set to 'true' and if
|
||||
* one of the request in BatchRequest fails then all transactions are rolled
|
||||
* back.
|
||||
*
|
||||
* @see org.apache.fineract.batch.command.internal.CreateClientCommandStrategy
|
||||
* @see org.apache.fineract.batch.api.BatchApiResource
|
||||
* @see org.apache.fineract.batch.service.BatchApiService
|
||||
*/
|
||||
@Test
|
||||
public void shouldRollBackAllTransactionsOnFailure() {
|
||||
|
||||
// Create first client request
|
||||
final BatchRequest br1 = BatchHelper.createClientRequest(4713L, "TestExtId11");
|
||||
|
||||
// Create second client request
|
||||
final BatchRequest br2 = BatchHelper.createClientRequest(4714L, "TestExtId12");
|
||||
|
||||
// Create third client request, having same externalID as second client,
|
||||
// hence cause of error
|
||||
final BatchRequest br3 = BatchHelper.createClientRequest(4715L, "TestExtId11");
|
||||
|
||||
final List<BatchRequest> batchRequests = new ArrayList<>();
|
||||
|
||||
batchRequests.add(br1);
|
||||
batchRequests.add(br2);
|
||||
batchRequests.add(br3);
|
||||
|
||||
final String jsonifiedRequest = BatchHelper.toJsonString(batchRequests);
|
||||
final List<BatchResponse> response = BatchHelper.postBatchRequestsWithEnclosingTransaction(this.requestSpec, this.responseSpec,
|
||||
jsonifiedRequest);
|
||||
|
||||
// Verifies that none of the client in BatchRequest is created on the
|
||||
// server
|
||||
BatchHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, "TestExtId11");
|
||||
BatchHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, "TestExtId12");
|
||||
|
||||
// Asserts that all the transactions have been successfully rolled back
|
||||
Assert.assertEquals(response.size(), 1);
|
||||
Assert.assertEquals("Verify Status code 400", (long) 400, (long) response.get(0).getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a client information was successfully updated through
|
||||
* updateClientCommand. A 'changes' parameter is returned in the response
|
||||
* after successful update of client information.
|
||||
*
|
||||
* @see org.apache.fineract.batch.command.internal.UpdateClientCommandStrategy
|
||||
*/
|
||||
@Test
|
||||
public void shouldReflectChangesOnClientUpdate() {
|
||||
|
||||
// Create a createClient Request
|
||||
final BatchRequest br1 = BatchHelper.createClientRequest(4716L, "");
|
||||
|
||||
// Create a clientUpdate Request
|
||||
final BatchRequest br2 = BatchHelper.updateClientRequest(4717L, 4716L);
|
||||
|
||||
final List<BatchRequest> batchRequests = new ArrayList<>();
|
||||
|
||||
batchRequests.add(br1);
|
||||
batchRequests.add(br2);
|
||||
|
||||
final String jsonifiedRequest = BatchHelper.toJsonString(batchRequests);
|
||||
|
||||
final List<BatchResponse> response = BatchHelper.postBatchRequestsWithoutEnclosingTransaction(this.requestSpec, this.responseSpec,
|
||||
jsonifiedRequest);
|
||||
|
||||
// Get the changes parameter from updateClient Response
|
||||
final JsonObject changes = new FromJsonHelper().parse(response.get(1).getBody()).getAsJsonObject().get("changes").getAsJsonObject();
|
||||
|
||||
// Asserts the client information is successfully updated
|
||||
Assert.assertEquals("Verify Firstname", "TestFirstName", changes.get("firstname").getAsString());
|
||||
Assert.assertEquals("Verify Lastname", "TestLastName", changes.get("lastname").getAsString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a ApplyLoanCommand was successfully executed and returned a
|
||||
* 200(OK) status. It creates a new client and apply a loan to that client.
|
||||
* This also verifies the successful resolution of dependencies among two
|
||||
* requests.
|
||||
*
|
||||
* @see org.apache.fineract.batch.command.internal.ApplyLoanCommandStrategy
|
||||
*/
|
||||
@Test
|
||||
public void shouldReturnOkStatusForApplyLoanCommand() {
|
||||
|
||||
final String loanProductJSON = new LoanProductTestBuilder() //
|
||||
.withPrincipal("10000000.00") //
|
||||
.withNumberOfRepayments("24") //
|
||||
.withRepaymentAfterEvery("1") //
|
||||
.withRepaymentTypeAsMonth() //
|
||||
.withinterestRatePerPeriod("2") //
|
||||
.withInterestRateFrequencyTypeAsMonths() //
|
||||
.withAmortizationTypeAsEqualPrincipalPayment() //
|
||||
.withInterestTypeAsDecliningBalance() //
|
||||
.currencyDetails("0", "100").build(null);
|
||||
|
||||
final Integer productId = new LoanTransactionHelper(this.requestSpec, this.responseSpec).getLoanProductId(loanProductJSON);
|
||||
|
||||
// Create a createClient Request
|
||||
final BatchRequest br1 = BatchHelper.createClientRequest(4718L, "");
|
||||
|
||||
// Create a activateClient Request
|
||||
final BatchRequest br2 = BatchHelper.activateClientRequest(4719L, 4718L);
|
||||
|
||||
// Create a ApplyLoan Request
|
||||
final BatchRequest br3 = BatchHelper.applyLoanRequest(4720L, 4719L, productId);
|
||||
|
||||
final List<BatchRequest> batchRequests = new ArrayList<>();
|
||||
|
||||
batchRequests.add(br1);
|
||||
batchRequests.add(br2);
|
||||
batchRequests.add(br3);
|
||||
|
||||
final String jsonifiedRequest = BatchHelper.toJsonString(batchRequests);
|
||||
|
||||
final List<BatchResponse> response = BatchHelper.postBatchRequestsWithoutEnclosingTransaction(this.requestSpec, this.responseSpec,
|
||||
jsonifiedRequest);
|
||||
|
||||
// Get the clientId parameter from createClient Response
|
||||
final JsonElement clientId = new FromJsonHelper().parse(response.get(0).getBody()).getAsJsonObject().get("clientId");
|
||||
|
||||
Assert.assertEquals("Verify Status Code 200" + clientId.getAsString(), 200L, (long) response.get(1).getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a new savings accounts was applied to an existing client and a
|
||||
* 200(OK) status was returned. It first creates a new client and a savings
|
||||
* product, then uses the cliendId and ProductId to apply a savings account.
|
||||
*
|
||||
* @see org.apache.fineract.batch.command.internal.ApplySavingsCommandStrategy
|
||||
*/
|
||||
@Test
|
||||
public void shouldReturnOkStatusForApplySavingsCommand() {
|
||||
|
||||
final SavingsProductHelper savingsProductHelper = new SavingsProductHelper();
|
||||
final String savingsProductJSON = savingsProductHelper //
|
||||
.withInterestCompoundingPeriodTypeAsDaily() //
|
||||
.withInterestPostingPeriodTypeAsMonthly() //
|
||||
.withInterestCalculationPeriodTypeAsDailyBalance() //
|
||||
.withMinimumOpenningBalance("5000").build();
|
||||
|
||||
final Integer productId = SavingsProductHelper.createSavingsProduct(savingsProductJSON, this.requestSpec, this.responseSpec);
|
||||
|
||||
// Create a createClient Request
|
||||
final BatchRequest br1 = BatchHelper.createClientRequest(4720L, "");
|
||||
|
||||
// Create a activateClient Request
|
||||
final BatchRequest br2 = BatchHelper.activateClientRequest(4721L, 4720L);
|
||||
|
||||
// Create a applySavings Request
|
||||
final BatchRequest br3 = BatchHelper.applySavingsRequest(4722L, 4721L, productId);
|
||||
|
||||
final List<BatchRequest> batchRequests = new ArrayList<>();
|
||||
|
||||
batchRequests.add(br1);
|
||||
batchRequests.add(br2);
|
||||
batchRequests.add(br3);
|
||||
|
||||
final String jsonifiedRequest = BatchHelper.toJsonString(batchRequests);
|
||||
|
||||
final List<BatchResponse> response = BatchHelper.postBatchRequestsWithoutEnclosingTransaction(this.requestSpec, this.responseSpec,
|
||||
jsonifiedRequest);
|
||||
|
||||
Assert.assertEquals("Verify Status Code 200", 200L, (long) response.get(1).getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a new charge was added to a newly created loan and charges are
|
||||
* Collected properly 200(OK) status was returned for successful responses.
|
||||
* It first creates a new client and apply a loan, then creates a new charge
|
||||
* for the create loan and then fetches all the applied charges
|
||||
*
|
||||
* @see org.apache.fineract.batch.command.internal.CollectChargesCommandStrategy
|
||||
* @see org.apache.fineract.batch.command.internal.CreateChargeCommandStrategy
|
||||
*/
|
||||
@Test
|
||||
public void shouldReturnOkStatusForCollectChargesCommand() {
|
||||
|
||||
final String loanProductJSON = new LoanProductTestBuilder() //
|
||||
.withPrincipal("10000000.00") //
|
||||
.withNumberOfRepayments("24") //
|
||||
.withRepaymentAfterEvery("1") //
|
||||
.withRepaymentTypeAsMonth() //
|
||||
.withinterestRatePerPeriod("2") //
|
||||
.withInterestRateFrequencyTypeAsMonths() //
|
||||
.withAmortizationTypeAsEqualPrincipalPayment() //
|
||||
.withInterestTypeAsDecliningBalance() //
|
||||
.currencyDetails("0", "100").build(null);
|
||||
|
||||
final Integer productId = new LoanTransactionHelper(this.requestSpec, this.responseSpec).getLoanProductId(loanProductJSON);
|
||||
|
||||
// Create a createClient Request
|
||||
final BatchRequest br1 = BatchHelper.createClientRequest(4722L, "");
|
||||
|
||||
// Create a activateClient Request
|
||||
final BatchRequest br2 = BatchHelper.activateClientRequest(4723L, 4722L);
|
||||
|
||||
// Create a ApplyLoan Request
|
||||
final BatchRequest br3 = BatchHelper.applyLoanRequest(4724L, 4723L, productId);
|
||||
|
||||
// Create a Collect Charges Request
|
||||
final BatchRequest br4 = BatchHelper.collectChargesRequest(4725L, 4724L);
|
||||
|
||||
final List<BatchRequest> batchRequests = new ArrayList<>();
|
||||
|
||||
batchRequests.add(br1);
|
||||
batchRequests.add(br2);
|
||||
batchRequests.add(br3);
|
||||
batchRequests.add(br4);
|
||||
|
||||
final String jsonifiedRequest = BatchHelper.toJsonString(batchRequests);
|
||||
|
||||
final List<BatchResponse> response = BatchHelper.postBatchRequestsWithoutEnclosingTransaction(this.requestSpec, this.responseSpec,
|
||||
jsonifiedRequest);
|
||||
|
||||
Assert.assertEquals("Verify Status Code 200 for Create Loan Charge", 200L, (long) response.get(3).getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for the successful activation of a pending client using
|
||||
* 'ActivateClientCommandStrategy'. A '200' status code is expected on
|
||||
* successful activation.
|
||||
*
|
||||
* @see org.apache.fineract.batch.command.internal.ActivateClientCommandStrategy
|
||||
*/
|
||||
@Test
|
||||
public void shouldReturnOkStatusOnSuccessfulClientActivation() {
|
||||
|
||||
// Create a createClient Request
|
||||
final BatchRequest br1 = BatchHelper.createClientRequest(4726L, "");
|
||||
|
||||
// Create a activateClient Request
|
||||
final BatchRequest br2 = BatchHelper.activateClientRequest(4727L, 4726L);
|
||||
|
||||
final List<BatchRequest> batchRequests = new ArrayList<>();
|
||||
|
||||
batchRequests.add(br1);
|
||||
batchRequests.add(br2);
|
||||
|
||||
final String jsonifiedRequest = BatchHelper.toJsonString(batchRequests);
|
||||
|
||||
final List<BatchResponse> response = BatchHelper.postBatchRequestsWithoutEnclosingTransaction(this.requestSpec, this.responseSpec,
|
||||
jsonifiedRequest);
|
||||
|
||||
Assert.assertEquals("Verify Status Code 200 for Create Client", 200L, (long) response.get(0).getStatusCode());
|
||||
Assert.assertEquals("Verify Status Code 200 for Activate Client", 200L, (long) response.get(1).getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for the successful approval and disbursal of a loan using
|
||||
* 'ApproveLoanCommandStrategy' and 'DisburseLoanCommandStrategy'. A '200'
|
||||
* status code is expected on successful activation.
|
||||
*
|
||||
* @see org.apache.fineract.batch.command.internal.ApproveLoanCommandStrategy
|
||||
* @see org.apache.fineract.batch.command.internal.DisburseLoanCommandStrategy
|
||||
*/
|
||||
@Test
|
||||
public void shouldReturnOkStatusOnSuccessfulLoanApprovalAndDisburse() {
|
||||
final String loanProductJSON = new LoanProductTestBuilder() //
|
||||
.withPrincipal("10000000.00") //
|
||||
.withNumberOfRepayments("24") //
|
||||
.withRepaymentAfterEvery("1") //
|
||||
.withRepaymentTypeAsMonth() //
|
||||
.withinterestRatePerPeriod("2") //
|
||||
.withInterestRateFrequencyTypeAsMonths() //
|
||||
.withAmortizationTypeAsEqualPrincipalPayment() //
|
||||
.withInterestTypeAsDecliningBalance() //
|
||||
.currencyDetails("0", "100").build(null);
|
||||
|
||||
final Integer productId = new LoanTransactionHelper(this.requestSpec, this.responseSpec).getLoanProductId(loanProductJSON);
|
||||
|
||||
// Create a createClient Request
|
||||
final BatchRequest br1 = BatchHelper.createClientRequest(4730L, "");
|
||||
|
||||
// Create a activateClient Request
|
||||
final BatchRequest br2 = BatchHelper.activateClientRequest(4731L, 4730L);
|
||||
|
||||
// Create a ApplyLoan Request
|
||||
final BatchRequest br3 = BatchHelper.applyLoanRequest(4732L, 4731L, productId);
|
||||
|
||||
// Create a approveLoan Request
|
||||
final BatchRequest br4 = BatchHelper.approveLoanRequest(4733L, 4732L);
|
||||
|
||||
// Create a disburseLoan Request
|
||||
final BatchRequest br5 = BatchHelper.disburseLoanRequest(4734L, 4733L);
|
||||
|
||||
final List<BatchRequest> batchRequests = new ArrayList<>();
|
||||
|
||||
batchRequests.add(br1);
|
||||
batchRequests.add(br2);
|
||||
batchRequests.add(br3);
|
||||
batchRequests.add(br4);
|
||||
batchRequests.add(br5);
|
||||
|
||||
final String jsonifiedRequest = BatchHelper.toJsonString(batchRequests);
|
||||
|
||||
final List<BatchResponse> response = BatchHelper.postBatchRequestsWithoutEnclosingTransaction(this.requestSpec, this.responseSpec,
|
||||
jsonifiedRequest);
|
||||
|
||||
Assert.assertEquals("Verify Status Code 200 for Approve Loan", 200L, (long) response.get(3).getStatusCode());
|
||||
Assert.assertEquals("Verify Status Code 200 for Disburse Loan", 200L, (long) response.get(4).getStatusCode());
|
||||
}
|
||||
}
|
||||
+140
@@ -0,0 +1,140 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.fineract.batch.domain.BatchRequest;
|
||||
import org.apache.fineract.batch.domain.BatchResponse;
|
||||
import org.apache.fineract.integrationtests.common.BatchHelper;
|
||||
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||
import org.apache.fineract.integrationtests.common.GroupHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Test class for testing the integration of Batch API with custom batch
|
||||
* requests and various user defined workflow. Like in the case of mifos
|
||||
* community-app
|
||||
*
|
||||
* @author Rishabh Shukla
|
||||
*/
|
||||
public class BatchRequestsIntegrationTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
|
||||
public BatchRequestsIntegrationTest() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the essential settings for the TEST like contentType,
|
||||
* expectedStatusCode. It uses the '@Before' annotation provided by jUnit.
|
||||
*/
|
||||
@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();
|
||||
}
|
||||
|
||||
@Test
|
||||
/**
|
||||
* Tests that a loan is successfully applied to client members of a group.
|
||||
* Firstly, it'll create a few new clients and then will add those clients
|
||||
* to the group. Then a few loans will be created and one of those loans
|
||||
* will be chosen at random and similarily a few of the created clients will
|
||||
* be chosen on random. Now, the selected loan will be applied to these
|
||||
* clients through Batch - API ApplyLoanCommandStrategy.
|
||||
*/
|
||||
public void shouldReturnOkStatusForLoansAppliedToSelectedClients() {
|
||||
|
||||
// Generate a random count of number of clients to be created
|
||||
final Integer clientsCount = (int) Math.ceil(Math.random() * 7) + 3;
|
||||
final Integer[] clientIDs = new Integer[clientsCount];
|
||||
|
||||
// Create a new group and get its groupId
|
||||
Integer groupID = GroupHelper.createGroup(this.requestSpec, this.responseSpec, true);
|
||||
|
||||
// Create new clients and add those to this group
|
||||
for (Integer i = 0; i < clientsCount; i++) {
|
||||
clientIDs[i] = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
groupID = GroupHelper.associateClient(this.requestSpec, this.responseSpec, groupID.toString(), clientIDs[i].toString());
|
||||
System.out.println("client " + clientIDs[i] + " has been added to the group " + groupID);
|
||||
}
|
||||
|
||||
// Generate a random count of number of new loan products to be created
|
||||
final Integer loansCount = (int) Math.ceil(Math.random() * 4) + 1;
|
||||
final Integer[] loanProducts = new Integer[loansCount];
|
||||
|
||||
// Create new loan Products
|
||||
for (Integer i = 0; i < loansCount; i++) {
|
||||
final String loanProductJSON = new LoanProductTestBuilder() //
|
||||
.withPrincipal(String.valueOf(10000.00 + Math.ceil(Math.random() * 1000000.00))) //
|
||||
.withNumberOfRepayments(String.valueOf(2 + (int) Math.ceil(Math.random() * 36))) //
|
||||
.withRepaymentAfterEvery(String.valueOf(1 + (int) Math.ceil(Math.random() * 3))) //
|
||||
.withRepaymentTypeAsMonth() //
|
||||
.withinterestRatePerPeriod(String.valueOf(1 + (int) Math.ceil(Math.random() * 4))) //
|
||||
.withInterestRateFrequencyTypeAsMonths() //
|
||||
.withAmortizationTypeAsEqualPrincipalPayment() //
|
||||
.withInterestTypeAsDecliningBalance() //
|
||||
.currencyDetails("0", "100").build(null);
|
||||
|
||||
loanProducts[i] = new LoanTransactionHelper(this.requestSpec, this.responseSpec).getLoanProductId(loanProductJSON);
|
||||
}
|
||||
|
||||
// Select anyone of the loan products at random
|
||||
final Integer loanProductID = loanProducts[(int) Math.floor(Math.random() * (loansCount - 1))];
|
||||
|
||||
final List<BatchRequest> batchRequests = new ArrayList<>();
|
||||
|
||||
// Select a few clients from created group at random
|
||||
Integer selClientsCount = (int) Math.ceil(Math.random() * clientsCount) + 2;
|
||||
for (int i = 0; i < selClientsCount; i++) {
|
||||
BatchRequest br = BatchHelper.applyLoanRequest((long) selClientsCount, null, loanProductID);
|
||||
br.setBody(br.getBody().replace("$.clientId", String.valueOf(clientIDs[(int) Math.floor(Math.random() * (clientsCount - 1))])));
|
||||
batchRequests.add(br);
|
||||
}
|
||||
|
||||
// Send the request to Batch - API
|
||||
final String jsonifiedRequest = BatchHelper.toJsonString(batchRequests);
|
||||
|
||||
final List<BatchResponse> response = BatchHelper.postBatchRequestsWithoutEnclosingTransaction(this.requestSpec, this.responseSpec,
|
||||
jsonifiedRequest);
|
||||
|
||||
// Verify that each loan has been applied successfully
|
||||
for (BatchResponse res : response) {
|
||||
Assert.assertEquals("Verify Status Code 200", 200L, (long) res.getStatusCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
+261
@@ -0,0 +1,261 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.CenterDomain;
|
||||
import org.apache.fineract.integrationtests.common.CenterHelper;
|
||||
import org.apache.fineract.integrationtests.common.OfficeHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.organisation.StaffHelper;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.jayway.restassured.builder.RequestSpecBuilder;
|
||||
import com.jayway.restassured.builder.ResponseSpecBuilder;
|
||||
import com.jayway.restassured.http.ContentType;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
public class CenterIntegrationTest {
|
||||
|
||||
private RequestSpecification requestSpec;
|
||||
private ResponseSpecification responseSpec;
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicCenterCreation() {
|
||||
int officeId = new OfficeHelper(requestSpec, responseSpec).createOffice("01 July 2007");
|
||||
|
||||
String name = "TestBasicCreation" + new Timestamp(new java.util.Date().getTime());
|
||||
int resourceId = CenterHelper.createCenter(name, officeId, requestSpec, responseSpec);
|
||||
CenterDomain center = CenterHelper.retrieveByID(resourceId, requestSpec, responseSpec);
|
||||
|
||||
Assert.assertNotNull(center);
|
||||
Assert.assertTrue(center.getName().equals(name));
|
||||
Assert.assertTrue(center.getOfficeId() == officeId);
|
||||
Assert.assertTrue(center.isActive() == false);
|
||||
|
||||
// Test retrieval by listing all centers
|
||||
int id = CenterHelper.listCenters(requestSpec, responseSpec).get(0).getId();
|
||||
Assert.assertTrue(id > 0);
|
||||
|
||||
CenterDomain retrievedCenter = CenterHelper.retrieveByID(id, requestSpec, responseSpec);
|
||||
Assert.assertNotNull(retrievedCenter);
|
||||
Assert.assertNotNull(retrievedCenter.getName());
|
||||
Assert.assertNotNull(retrievedCenter.getHierarchy());
|
||||
Assert.assertNotNull(retrievedCenter.getOfficeName());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFullCenterCreation() {
|
||||
|
||||
int officeId = new OfficeHelper(requestSpec, responseSpec).createOffice("01 July 2007");
|
||||
String name = "TestFullCreation" + new Timestamp(new java.util.Date().getTime());
|
||||
String externalId = Utils.randomStringGenerator("ID_", 7, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
int staffId = StaffHelper.createStaff(requestSpec, responseSpec);
|
||||
int[] groupMembers = generateGroupMembers(3, officeId);
|
||||
int resourceId = CenterHelper.createCenter(name, officeId, externalId, staffId, groupMembers, requestSpec, responseSpec);
|
||||
CenterDomain center = CenterHelper.retrieveByID(resourceId, requestSpec, responseSpec);
|
||||
|
||||
Assert.assertNotNull(center);
|
||||
Assert.assertTrue(center.getName().equals(name));
|
||||
Assert.assertTrue(center.getOfficeId() == officeId);
|
||||
Assert.assertTrue(center.getExternalId().equals(externalId));
|
||||
Assert.assertTrue(center.getStaffId() == staffId);
|
||||
Assert.assertTrue(center.isActive() == false);
|
||||
Assert.assertArrayEquals(center.getGroupMembers(), groupMembers);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListCenters() {
|
||||
ArrayList<CenterDomain> paginatedList = CenterHelper.paginatedListCenters(requestSpec, responseSpec);
|
||||
ArrayList<CenterDomain> list = CenterHelper.listCenters(requestSpec, responseSpec);
|
||||
|
||||
Assert.assertNotNull(paginatedList);
|
||||
Assert.assertNotNull(list);
|
||||
Assert.assertTrue(Arrays.equals(paginatedList.toArray(new CenterDomain[paginatedList.size()]),
|
||||
list.toArray(new CenterDomain[list.size()])));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVoidCenterRetrieval() {
|
||||
ArrayList<CenterDomain> arr = CenterHelper.listCenters(requestSpec, responseSpec);
|
||||
int id = arr.get(arr.size() - 1).getId() + 1;
|
||||
ResponseSpecification responseSpec = new ResponseSpecBuilder().expectStatusCode(404).build();
|
||||
CenterDomain center = CenterHelper.retrieveByID(id, requestSpec, responseSpec);
|
||||
Assert.assertNotNull(center);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Test
|
||||
public void testCenterUpdate() {
|
||||
int officeId = new OfficeHelper(requestSpec, responseSpec).createOffice("01 July 2007");
|
||||
String name = "TestFullCreation" + new Timestamp(new java.util.Date().getTime());
|
||||
String externalId = Utils.randomStringGenerator("ID_", 7, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
int staffId = StaffHelper.createStaff(requestSpec, responseSpec);
|
||||
int[] groupMembers = generateGroupMembers(3, officeId);
|
||||
int resourceId = CenterHelper.createCenter(name, officeId, externalId, staffId, groupMembers, requestSpec, responseSpec);
|
||||
|
||||
String newName = "TestCenterUpdateNew" + new Timestamp(new java.util.Date().getTime());
|
||||
String newExternalId = Utils.randomStringGenerator("newID_", 7, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
int newStaffId = StaffHelper.createStaff(requestSpec, responseSpec);
|
||||
int[] associateGroupMembers = generateGroupMembers(2, officeId);
|
||||
|
||||
int[] associateResponse = CenterHelper.associateGroups(resourceId, associateGroupMembers, requestSpec, responseSpec);
|
||||
Arrays.sort(associateResponse);
|
||||
Arrays.sort(associateGroupMembers);
|
||||
Assert.assertArrayEquals(associateResponse, associateGroupMembers);
|
||||
|
||||
int[] newGroupMembers = new int[5];
|
||||
for (int i = 0; i < 5; i++) {
|
||||
if (i < 3) {
|
||||
newGroupMembers[i] = groupMembers[i];
|
||||
} else {
|
||||
newGroupMembers[i] = associateGroupMembers[i % 3];
|
||||
}
|
||||
}
|
||||
|
||||
HashMap request = new HashMap();
|
||||
request.put("name", newName);
|
||||
request.put("externalId", newExternalId);
|
||||
request.put("staffId", newStaffId);
|
||||
HashMap response = CenterHelper.updateCenter(resourceId, request, requestSpec, responseSpec);
|
||||
Assert.assertNotNull(response);
|
||||
Assert.assertEquals(newName, response.get("name"));
|
||||
Assert.assertEquals(newExternalId, response.get("externalId"));
|
||||
Assert.assertEquals(newStaffId, response.get("staffId"));
|
||||
|
||||
CenterDomain center = CenterHelper.retrieveByID(resourceId, requestSpec, responseSpec);
|
||||
Assert.assertNotNull(center);
|
||||
Assert.assertEquals(newName, center.getName());
|
||||
Assert.assertEquals(newExternalId, center.getExternalId());
|
||||
Assert.assertEquals((Integer)newStaffId, center.getStaffId());
|
||||
Assert.assertArrayEquals(newGroupMembers, center.getGroupMembers());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCenterDeletion() {
|
||||
int officeId = new OfficeHelper(requestSpec, responseSpec).createOffice("01 July 2007");
|
||||
String name = "TestBasicCreation" + new Timestamp(new java.util.Date().getTime());
|
||||
int resourceId = CenterHelper.createCenter(name, officeId, requestSpec, responseSpec);
|
||||
|
||||
CenterHelper.deleteCenter(resourceId, requestSpec, responseSpec);
|
||||
ResponseSpecification responseSpec = new ResponseSpecBuilder().expectStatusCode(404).build();
|
||||
CenterDomain center = CenterHelper.retrieveByID(resourceId, requestSpec, responseSpec);
|
||||
Assert.assertNotNull(center);
|
||||
}
|
||||
|
||||
private int[] generateGroupMembers(int size, int officeId) {
|
||||
int[] groupMembers = new int[size];
|
||||
for (int i = 0; i < groupMembers.length; i++) {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("officeId", "" + officeId);
|
||||
map.put("name", Utils.randomStringGenerator("Group_Name_", 5));
|
||||
map.put("externalId", Utils.randomStringGenerator("ID_", 7, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("locale", "en");
|
||||
map.put("active", "true");
|
||||
map.put("activationDate", "04 March 2011");
|
||||
|
||||
groupMembers[i] = Utils.performServerPost(requestSpec, responseSpec, "/fineract-provider/api/v1/groups?"
|
||||
+ Utils.TENANT_IDENTIFIER, new Gson().toJson(map), "groupId");
|
||||
}
|
||||
return groupMembers;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaffAssignmentDuringCenterCreation() {
|
||||
|
||||
Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
|
||||
System.out.println("--------------creating first staff with id-------------" + staffId);
|
||||
Assert.assertNotNull(staffId);
|
||||
|
||||
int centerWithStaffId = CenterHelper.createCenterWithStaffId(this.requestSpec, this.responseSpec, staffId);
|
||||
CenterDomain center = CenterHelper.retrieveByID(centerWithStaffId, requestSpec, responseSpec);
|
||||
Assert.assertNotNull(center);
|
||||
Assert.assertTrue(center.getId() == centerWithStaffId);
|
||||
Assert.assertTrue(center.getStaffId() == staffId);
|
||||
Assert.assertTrue(center.isActive() == true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAssignStaffToCenter() {
|
||||
Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
|
||||
System.out.println("--------------creating first staff with id-------------" + staffId);
|
||||
Assert.assertNotNull(staffId);
|
||||
|
||||
Integer groupID = CenterHelper.createCenter(this.requestSpec, this.responseSpec);
|
||||
CenterHelper.verifyCenterCreatedOnServer(this.requestSpec, this.responseSpec, groupID);
|
||||
|
||||
HashMap assignStaffToCenterResponseMap = (HashMap) CenterHelper.assignStaff(this.requestSpec, this.responseSpec, groupID.toString(),
|
||||
staffId.longValue());
|
||||
assertEquals("Verify assigned staff id is the same as id sent", assignStaffToCenterResponseMap.get("staffId"), staffId);
|
||||
|
||||
CenterDomain center = CenterHelper.retrieveByID(groupID, requestSpec, responseSpec);
|
||||
Assert.assertNotNull(center);
|
||||
Assert.assertTrue(center.getId() == groupID);
|
||||
Assert.assertTrue(center.getStaffId() == staffId);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnassignStaffToCenter() {
|
||||
Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
|
||||
System.out.println("--------------creating first staff with id-------------" + staffId);
|
||||
Assert.assertNotNull(staffId);
|
||||
|
||||
Integer groupID = CenterHelper.createCenter(this.requestSpec, this.responseSpec);
|
||||
CenterHelper.verifyCenterCreatedOnServer(this.requestSpec, this.responseSpec, groupID);
|
||||
|
||||
HashMap assignStaffToCenterResponseMap = (HashMap) CenterHelper.assignStaff(this.requestSpec, this.responseSpec, groupID.toString(),
|
||||
staffId.longValue());
|
||||
assertEquals("Verify assigned staff id is the same as id sent", assignStaffToCenterResponseMap.get("staffId"), staffId);
|
||||
CenterDomain centerWithStaffAssigned = CenterHelper.retrieveByID(groupID, requestSpec, responseSpec);
|
||||
Assert.assertNotNull(centerWithStaffAssigned);
|
||||
Assert.assertTrue(centerWithStaffAssigned.getId() == groupID);
|
||||
Assert.assertTrue(centerWithStaffAssigned.getStaffId() == staffId);
|
||||
|
||||
HashMap unassignStaffToCenterResponseMap = (HashMap) CenterHelper.unassignStaff(this.requestSpec, this.responseSpec, groupID.toString(),
|
||||
staffId.longValue());
|
||||
assertEquals("Verify staffId is null after unassigning ", unassignStaffToCenterResponseMap.get("staffId"), null);
|
||||
CenterDomain centerWithStaffUnssigned = CenterHelper.retrieveByID(groupID, requestSpec, responseSpec);
|
||||
Assert.assertNotNull(centerWithStaffUnssigned);
|
||||
Assert.assertTrue(centerWithStaffUnssigned.getId() == groupID);
|
||||
Assert.assertTrue(centerWithStaffUnssigned.getStaffId() == null);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+326
@@ -0,0 +1,326 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.charges.ChargesHelper;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
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;
|
||||
|
||||
@SuppressWarnings({ "rawtypes" })
|
||||
public class ChargesTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testChargesForLoans() {
|
||||
|
||||
// Retrieving all Charges
|
||||
ArrayList<HashMap> allChargesData = ChargesHelper.getCharges(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(allChargesData);
|
||||
|
||||
// Testing Creation, Updation and Deletion of Disbursement Charge
|
||||
final Integer disbursementChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
|
||||
ChargesHelper.getLoanDisbursementJSON());
|
||||
Assert.assertNotNull(disbursementChargeId);
|
||||
|
||||
// Updating Charge Amount
|
||||
HashMap changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, disbursementChargeId,
|
||||
ChargesHelper.getModifyChargeJSON());
|
||||
|
||||
HashMap chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, disbursementChargeId);
|
||||
Assert.assertEquals("Verifying Charge after Modification", chargeDataAfterChanges.get("amount"), changes.get("amount"));
|
||||
|
||||
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, disbursementChargeId,
|
||||
ChargesHelper.getModifyChargeAsPecentageAmountJSON());
|
||||
|
||||
chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, disbursementChargeId);
|
||||
|
||||
HashMap chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargePaymentMode");
|
||||
Assert.assertEquals("Verifying Charge after Modification", chargeChangedData.get("id"), changes.get("chargePaymentMode"));
|
||||
|
||||
chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargeCalculationType");
|
||||
Assert.assertEquals("Verifying Charge after Modification", chargeChangedData.get("id"), changes.get("chargeCalculationType"));
|
||||
|
||||
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, disbursementChargeId,
|
||||
ChargesHelper.getModifyChargeAsPecentageLoanAmountWithInterestJSON());
|
||||
|
||||
chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, disbursementChargeId);
|
||||
|
||||
chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargeCalculationType");
|
||||
Assert.assertEquals("Verifying Charge after Modification", chargeChangedData.get("id"), changes.get("chargeCalculationType"));
|
||||
|
||||
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, disbursementChargeId,
|
||||
ChargesHelper.getModifyChargeAsPercentageInterestJSON());
|
||||
|
||||
chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, disbursementChargeId);
|
||||
|
||||
chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargeCalculationType");
|
||||
Assert.assertEquals("Verifying Charge after Modification", chargeChangedData.get("id"), changes.get("chargeCalculationType"));
|
||||
|
||||
Integer chargeIdAfterDeletion = ChargesHelper.deleteCharge(this.responseSpec, this.requestSpec, disbursementChargeId);
|
||||
Assert.assertEquals("Verifying Charge ID after deletion", disbursementChargeId, chargeIdAfterDeletion);
|
||||
|
||||
// Testing Creation, Updation and Deletion of Specified due date Charge
|
||||
final Integer specifiedDueDateChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
|
||||
ChargesHelper.getLoanSpecifiedDueDateJSON());
|
||||
Assert.assertNotNull(specifiedDueDateChargeId);
|
||||
|
||||
// Updating Charge Amount
|
||||
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, specifiedDueDateChargeId,
|
||||
ChargesHelper.getModifyChargeJSON());
|
||||
|
||||
chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, specifiedDueDateChargeId);
|
||||
Assert.assertEquals("Verifying Charge after Modification", chargeDataAfterChanges.get("amount"), changes.get("amount"));
|
||||
|
||||
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, specifiedDueDateChargeId,
|
||||
ChargesHelper.getModifyChargeAsPecentageAmountJSON());
|
||||
|
||||
chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, specifiedDueDateChargeId);
|
||||
|
||||
chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargePaymentMode");
|
||||
Assert.assertEquals("Verifying Charge after Modification", chargeChangedData.get("id"), changes.get("chargePaymentMode"));
|
||||
|
||||
chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargeCalculationType");
|
||||
Assert.assertEquals("Verifying Charge after Modification", chargeChangedData.get("id"), changes.get("chargeCalculationType"));
|
||||
|
||||
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, specifiedDueDateChargeId,
|
||||
ChargesHelper.getModifyChargeAsPecentageLoanAmountWithInterestJSON());
|
||||
|
||||
chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, specifiedDueDateChargeId);
|
||||
|
||||
chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargeCalculationType");
|
||||
Assert.assertEquals("Verifying Charge after Modification", chargeChangedData.get("id"), changes.get("chargeCalculationType"));
|
||||
|
||||
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, specifiedDueDateChargeId,
|
||||
ChargesHelper.getModifyChargeAsPercentageInterestJSON());
|
||||
|
||||
chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, specifiedDueDateChargeId);
|
||||
|
||||
chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargeCalculationType");
|
||||
Assert.assertEquals("Verifying Charge after Modification", chargeChangedData.get("id"), changes.get("chargeCalculationType"));
|
||||
|
||||
chargeIdAfterDeletion = ChargesHelper.deleteCharge(this.responseSpec, this.requestSpec, specifiedDueDateChargeId);
|
||||
Assert.assertEquals("Verifying Charge ID after deletion", specifiedDueDateChargeId, chargeIdAfterDeletion);
|
||||
|
||||
// Testing Creation, Updation and Deletion of Installment Fee Charge
|
||||
final Integer installmentFeeChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
|
||||
ChargesHelper.getLoanInstallmentFeeJSON());
|
||||
|
||||
// Updating Charge Amount
|
||||
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, installmentFeeChargeId,
|
||||
ChargesHelper.getModifyChargeJSON());
|
||||
|
||||
chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, installmentFeeChargeId);
|
||||
Assert.assertEquals("Verifying Charge after Modification", chargeDataAfterChanges.get("amount"), changes.get("amount"));
|
||||
|
||||
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, installmentFeeChargeId,
|
||||
ChargesHelper.getModifyChargeAsPecentageAmountJSON());
|
||||
|
||||
chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, installmentFeeChargeId);
|
||||
|
||||
chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargePaymentMode");
|
||||
Assert.assertEquals("Verifying Charge after Modification", chargeChangedData.get("id"), changes.get("chargePaymentMode"));
|
||||
|
||||
chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargeCalculationType");
|
||||
Assert.assertEquals("Verifying Charge after Modification", chargeChangedData.get("id"), changes.get("chargeCalculationType"));
|
||||
|
||||
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, installmentFeeChargeId,
|
||||
ChargesHelper.getModifyChargeAsPecentageLoanAmountWithInterestJSON());
|
||||
|
||||
chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, installmentFeeChargeId);
|
||||
|
||||
chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargeCalculationType");
|
||||
Assert.assertEquals("Verifying Charge after Modification", chargeChangedData.get("id"), changes.get("chargeCalculationType"));
|
||||
|
||||
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, installmentFeeChargeId,
|
||||
ChargesHelper.getModifyChargeAsPercentageInterestJSON());
|
||||
|
||||
chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, installmentFeeChargeId);
|
||||
|
||||
chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargeCalculationType");
|
||||
Assert.assertEquals("Verifying Charge after Modification", chargeChangedData.get("id"), changes.get("chargeCalculationType"));
|
||||
|
||||
chargeIdAfterDeletion = ChargesHelper.deleteCharge(this.responseSpec, this.requestSpec, installmentFeeChargeId);
|
||||
Assert.assertEquals("Verifying Charge ID after deletion", installmentFeeChargeId, chargeIdAfterDeletion);
|
||||
|
||||
// Testing Creation, Updation and Deletion of Overdue Installment Fee
|
||||
// Charge
|
||||
final Integer overdueFeeChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
|
||||
ChargesHelper.getLoanOverdueFeeJSON());
|
||||
Assert.assertNotNull(overdueFeeChargeId);
|
||||
|
||||
// Updating Charge Amount
|
||||
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, overdueFeeChargeId, ChargesHelper.getModifyChargeJSON());
|
||||
|
||||
chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, overdueFeeChargeId);
|
||||
Assert.assertEquals("Verifying Charge after Modification", chargeDataAfterChanges.get("amount"), changes.get("amount"));
|
||||
|
||||
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, overdueFeeChargeId,
|
||||
ChargesHelper.getModifyChargeAsPecentageAmountJSON());
|
||||
|
||||
chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, overdueFeeChargeId);
|
||||
|
||||
chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargePaymentMode");
|
||||
Assert.assertEquals("Verifying Charge after Modification", chargeChangedData.get("id"), changes.get("chargePaymentMode"));
|
||||
|
||||
chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargeCalculationType");
|
||||
Assert.assertEquals("Verifying Charge after Modification", chargeChangedData.get("id"), changes.get("chargeCalculationType"));
|
||||
|
||||
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, overdueFeeChargeId,
|
||||
ChargesHelper.getModifyChargeAsPecentageLoanAmountWithInterestJSON());
|
||||
|
||||
chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, overdueFeeChargeId);
|
||||
|
||||
chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargeCalculationType");
|
||||
Assert.assertEquals("Verifying Charge after Modification", chargeChangedData.get("id"), changes.get("chargeCalculationType"));
|
||||
|
||||
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, overdueFeeChargeId,
|
||||
ChargesHelper.getModifyChargeAsPercentageInterestJSON());
|
||||
|
||||
chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, overdueFeeChargeId);
|
||||
|
||||
chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargeCalculationType");
|
||||
Assert.assertEquals("Verifying Charge after Modification", chargeChangedData.get("id"), changes.get("chargeCalculationType"));
|
||||
|
||||
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, overdueFeeChargeId,
|
||||
ChargesHelper.getModifyChargeFeeFrequencyAsYearsJSON());
|
||||
|
||||
chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, overdueFeeChargeId);
|
||||
|
||||
chargeChangedData = (HashMap) chargeDataAfterChanges.get("feeFrequency");
|
||||
Assert.assertEquals("Verifying Charge after Modification", chargeChangedData.get("id"), changes.get("feeFrequency"));
|
||||
|
||||
chargeIdAfterDeletion = ChargesHelper.deleteCharge(this.responseSpec, this.requestSpec, overdueFeeChargeId);
|
||||
Assert.assertEquals("Verifying Charge ID after deletion", overdueFeeChargeId, chargeIdAfterDeletion);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testChargesForSavings() {
|
||||
|
||||
// Testing Creation, Updation and Deletion of Specified due date Charge
|
||||
final Integer specifiedDueDateChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
|
||||
ChargesHelper.getSavingsSpecifiedDueDateJSON());
|
||||
Assert.assertNotNull(specifiedDueDateChargeId);
|
||||
|
||||
// Updating Charge Amount
|
||||
HashMap changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, specifiedDueDateChargeId,
|
||||
ChargesHelper.getModifyChargeJSON());
|
||||
|
||||
HashMap chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, specifiedDueDateChargeId);
|
||||
Assert.assertEquals("Verifying Charge after Modification", chargeDataAfterChanges.get("amount"), changes.get("amount"));
|
||||
|
||||
Integer chargeIdAfterDeletion = ChargesHelper.deleteCharge(this.responseSpec, this.requestSpec, specifiedDueDateChargeId);
|
||||
Assert.assertEquals("Verifying Charge ID after deletion", specifiedDueDateChargeId, chargeIdAfterDeletion);
|
||||
|
||||
// Testing Creation, Updation and Deletion of Savings Activation Charge
|
||||
final Integer savingsActivationChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
|
||||
ChargesHelper.getSavingsActivationFeeJSON());
|
||||
Assert.assertNotNull(savingsActivationChargeId);
|
||||
|
||||
// Updating Charge Amount
|
||||
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, savingsActivationChargeId,
|
||||
ChargesHelper.getModifyChargeJSON());
|
||||
|
||||
chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, savingsActivationChargeId);
|
||||
Assert.assertEquals("Verifying Charge after Modification", chargeDataAfterChanges.get("amount"), changes.get("amount"));
|
||||
|
||||
chargeIdAfterDeletion = ChargesHelper.deleteCharge(this.responseSpec, this.requestSpec, savingsActivationChargeId);
|
||||
Assert.assertEquals("Verifying Charge ID after deletion", savingsActivationChargeId, chargeIdAfterDeletion);
|
||||
|
||||
// Testing Creation, Updation and Deletion of Charge for Withdrawal Fee
|
||||
final Integer withdrawalFeeChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
|
||||
ChargesHelper.getSavingsWithdrawalFeeJSON());
|
||||
Assert.assertNotNull(withdrawalFeeChargeId);
|
||||
|
||||
// Updating Charge-Calculation-Type to Withdrawal-Fee
|
||||
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, withdrawalFeeChargeId,
|
||||
ChargesHelper.getModifyWithdrawalFeeSavingsChargeJSON());
|
||||
|
||||
chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, withdrawalFeeChargeId);
|
||||
|
||||
HashMap chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargeCalculationType");
|
||||
Assert.assertEquals("Verifying Charge after Modification", chargeChangedData.get("id"), changes.get("chargeCalculationType"));
|
||||
|
||||
chargeIdAfterDeletion = ChargesHelper.deleteCharge(this.responseSpec, this.requestSpec, withdrawalFeeChargeId);
|
||||
Assert.assertEquals("Verifying Charge ID after deletion", withdrawalFeeChargeId, chargeIdAfterDeletion);
|
||||
|
||||
// Testing Creation, Updation and Deletion of Charge for Annual Fee
|
||||
final Integer annualFeeChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
|
||||
ChargesHelper.getSavingsAnnualFeeJSON());
|
||||
Assert.assertNotNull(annualFeeChargeId);
|
||||
|
||||
// Updating Charge Amount
|
||||
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, annualFeeChargeId, ChargesHelper.getModifyChargeJSON());
|
||||
|
||||
chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, annualFeeChargeId);
|
||||
Assert.assertEquals("Verifying Charge after Modification", chargeDataAfterChanges.get("amount"), changes.get("amount"));
|
||||
|
||||
chargeIdAfterDeletion = ChargesHelper.deleteCharge(this.responseSpec, this.requestSpec, annualFeeChargeId);
|
||||
Assert.assertEquals("Verifying Charge ID after deletion", annualFeeChargeId, chargeIdAfterDeletion);
|
||||
|
||||
// Testing Creation, Updation and Deletion of Charge for Monthly Fee
|
||||
final Integer monthlyFeeChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
|
||||
ChargesHelper.getSavingsMonthlyFeeJSON());
|
||||
Assert.assertNotNull(monthlyFeeChargeId);
|
||||
|
||||
// Updating Charge Amount
|
||||
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, monthlyFeeChargeId, ChargesHelper.getModifyChargeJSON());
|
||||
|
||||
chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, monthlyFeeChargeId);
|
||||
Assert.assertEquals("Verifying Charge after Modification", chargeDataAfterChanges.get("amount"), changes.get("amount"));
|
||||
|
||||
chargeIdAfterDeletion = ChargesHelper.deleteCharge(this.responseSpec, this.requestSpec, monthlyFeeChargeId);
|
||||
Assert.assertEquals("Verifying Charge ID after deletion", monthlyFeeChargeId, chargeIdAfterDeletion);
|
||||
|
||||
// Testing Creation, Updation and Deletion of Charge for Overdraft Fee
|
||||
final Integer overdraftFeeChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
|
||||
ChargesHelper.getSavingsOverdraftFeeJSON());
|
||||
Assert.assertNotNull(overdraftFeeChargeId);
|
||||
|
||||
// Updating Charge Amount
|
||||
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, overdraftFeeChargeId,
|
||||
ChargesHelper.getModifyChargeJSON());
|
||||
|
||||
chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, overdraftFeeChargeId);
|
||||
Assert.assertEquals("Verifying Charge after Modification", chargeDataAfterChanges.get("amount"), changes.get("amount"));
|
||||
|
||||
chargeIdAfterDeletion = ChargesHelper.deleteCharge(this.responseSpec, this.requestSpec, overdraftFeeChargeId);
|
||||
Assert.assertEquals("Verifying Charge ID after deletion", overdraftFeeChargeId, chargeIdAfterDeletion);
|
||||
}
|
||||
}
|
||||
+5051
File diff suppressed because it is too large
Load Diff
+832
@@ -0,0 +1,832 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.DateFormat;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||
import org.apache.fineract.integrationtests.common.CommonConstants;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.charges.ChargesHelper;
|
||||
import org.apache.fineract.integrationtests.common.savings.SavingsAccountHelper;
|
||||
import org.apache.fineract.integrationtests.common.savings.SavingsProductHelper;
|
||||
import org.apache.fineract.integrationtests.common.savings.SavingsStatusChecker;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Client Savings Integration Test for checking Savings Application.
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unused" })
|
||||
public class ClientSavingsIntegrationTest {
|
||||
|
||||
public static final String DEPOSIT_AMOUNT = "2000";
|
||||
public static final String WITHDRAW_AMOUNT = "1000";
|
||||
public static final String WITHDRAW_AMOUNT_ADJUSTED = "500";
|
||||
public static final String MINIMUM_OPENING_BALANCE = "1000.0";
|
||||
public static final String ACCOUNT_TYPE_INDIVIDUAL = "INDIVIDUAL";
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private SavingsAccountHelper savingsAccountHelper;
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSavingsAccount() {
|
||||
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(clientID);
|
||||
final String minBalanceForInterestCalculation = null;
|
||||
final String minRequiredBalance = null;
|
||||
final String enforceMinRequiredBalance = "false";
|
||||
final boolean allowOverdraft = false;
|
||||
final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE,
|
||||
minBalanceForInterestCalculation, minRequiredBalance, enforceMinRequiredBalance, allowOverdraft);
|
||||
Assert.assertNotNull(savingsProductID);
|
||||
|
||||
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID, ACCOUNT_TYPE_INDIVIDUAL);
|
||||
Assert.assertNotNull(savingsProductID);
|
||||
|
||||
HashMap modifications = this.savingsAccountHelper.updateSavingsAccount(clientID, savingsProductID, savingsId,
|
||||
ACCOUNT_TYPE_INDIVIDUAL);
|
||||
Assert.assertTrue(modifications.containsKey("submittedOnDate"));
|
||||
|
||||
HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap);
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.approveSavings(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap);
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.activateSavings(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap);
|
||||
|
||||
final HashMap summaryBefore = this.savingsAccountHelper.getSavingsSummary(savingsId);
|
||||
this.savingsAccountHelper.calculateInterestForSavings(savingsId);
|
||||
HashMap summary = this.savingsAccountHelper.getSavingsSummary(savingsId);
|
||||
assertEquals(summaryBefore, summary);
|
||||
|
||||
this.savingsAccountHelper.postInterestForSavings(savingsId);
|
||||
summary = this.savingsAccountHelper.getSavingsSummary(savingsId);
|
||||
Assert.assertFalse(summaryBefore.equals(summary));
|
||||
|
||||
final Object savingsInterest = this.savingsAccountHelper.getSavingsInterest(savingsId);
|
||||
// verifySavingsInterest(savingsInterest);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSavingsAccountWithMinBalanceForInterestCalculation() {
|
||||
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(clientID);
|
||||
final String minBalanceForInterestCalculation = "5000";
|
||||
final String minRequiredBalance = null;
|
||||
final String enforceMinRequiredBalance = "false";
|
||||
final boolean allowOverdraft = false;
|
||||
final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE,
|
||||
minBalanceForInterestCalculation, minRequiredBalance, enforceMinRequiredBalance, allowOverdraft);
|
||||
Assert.assertNotNull(savingsProductID);
|
||||
|
||||
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID, ACCOUNT_TYPE_INDIVIDUAL);
|
||||
Assert.assertNotNull(savingsProductID);
|
||||
|
||||
HashMap modifications = this.savingsAccountHelper.updateSavingsAccount(clientID, savingsProductID, savingsId,
|
||||
ACCOUNT_TYPE_INDIVIDUAL);
|
||||
Assert.assertTrue(modifications.containsKey("submittedOnDate"));
|
||||
|
||||
HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap);
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.approveSavings(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap);
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.activateSavings(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap);
|
||||
|
||||
final HashMap summaryBefore = this.savingsAccountHelper.getSavingsSummary(savingsId);
|
||||
this.savingsAccountHelper.calculateInterestForSavings(savingsId);
|
||||
HashMap summary = this.savingsAccountHelper.getSavingsSummary(savingsId);
|
||||
assertEquals(summaryBefore, summary);
|
||||
|
||||
this.savingsAccountHelper.postInterestForSavings(savingsId);
|
||||
summary = this.savingsAccountHelper.getSavingsSummary(savingsId);
|
||||
assertEquals(summaryBefore, summary);
|
||||
|
||||
final Object savingsInterest = this.savingsAccountHelper.getSavingsInterest(savingsId);
|
||||
Assert.assertNull(savingsInterest);
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testSavingsAccount_CLOSE_APPLICATION() {
|
||||
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
|
||||
final ResponseSpecification errorResponse = new ResponseSpecBuilder().expectStatusCode(400).build();
|
||||
final SavingsAccountHelper validationErrorHelper = new SavingsAccountHelper(this.requestSpec, errorResponse);
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(clientID);
|
||||
final String minBalanceForInterestCalculation = null;
|
||||
final String minRequiredBalance = "1000.0";
|
||||
final String enforceMinRequiredBalance = "true";
|
||||
final boolean allowOverdraft = false;
|
||||
final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE,
|
||||
minBalanceForInterestCalculation, minRequiredBalance, enforceMinRequiredBalance, allowOverdraft);
|
||||
Assert.assertNotNull(savingsProductID);
|
||||
|
||||
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID, ACCOUNT_TYPE_INDIVIDUAL);
|
||||
Assert.assertNotNull(savingsProductID);
|
||||
|
||||
HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap);
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.approveSavings(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap);
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.activateSavings(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap);
|
||||
|
||||
DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy", Locale.US);
|
||||
Calendar todaysDate = Calendar.getInstance();
|
||||
final String CLOSEDON_DATE = dateFormat.format(todaysDate.getTime());
|
||||
String withdrawBalance = "false";
|
||||
ArrayList<HashMap> savingsAccountErrorData = (ArrayList<HashMap>) validationErrorHelper.closeSavingsAccountAndGetBackRequiredField(
|
||||
savingsId, withdrawBalance, CommonConstants.RESPONSE_ERROR, CLOSEDON_DATE);
|
||||
assertEquals("validation.msg.savingsaccount.close.results.in.balance.not.zero",
|
||||
savingsAccountErrorData.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
withdrawBalance = "true";
|
||||
savingsStatusHashMap = this.savingsAccountHelper.closeSavingsAccount(savingsId, withdrawBalance);
|
||||
SavingsStatusChecker.verifySavingsAccountIsClosed(savingsStatusHashMap);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testSavingsAccount_WITH_ENFORCE_MIN_BALANCE() {
|
||||
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
|
||||
final ResponseSpecification errorResponse = new ResponseSpecBuilder().expectStatusCode(403).build();
|
||||
final SavingsAccountHelper validationErrorHelper = new SavingsAccountHelper(this.requestSpec, errorResponse);
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(clientID);
|
||||
final String minBalanceForInterestCalculation = null;
|
||||
final String minRequiredBalance = "1500.0";
|
||||
final String openningBalance = "1600";
|
||||
final String enforceMinRequiredBalance = "true";
|
||||
final boolean allowOverdraft = false;
|
||||
final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, openningBalance,
|
||||
minBalanceForInterestCalculation, minRequiredBalance, enforceMinRequiredBalance, allowOverdraft);
|
||||
Assert.assertNotNull(savingsProductID);
|
||||
|
||||
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID, ACCOUNT_TYPE_INDIVIDUAL);
|
||||
Assert.assertNotNull(savingsProductID);
|
||||
|
||||
HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap);
|
||||
|
||||
final Integer savingsActivationChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
|
||||
ChargesHelper.getSavingsActivationFeeJSON());
|
||||
Assert.assertNotNull(savingsActivationChargeId);
|
||||
|
||||
this.savingsAccountHelper.addChargesForSavings(savingsId, savingsActivationChargeId);
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.approveSavings(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap);
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.activateSavings(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap);
|
||||
|
||||
HashMap summary = this.savingsAccountHelper.getSavingsSummary(savingsId);
|
||||
Float balance = new Float(openningBalance);
|
||||
Float chargeAmt = 100f;
|
||||
balance -= chargeAmt;
|
||||
assertEquals("Verifying opening Balance", balance, summary.get("accountBalance"));
|
||||
|
||||
DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy");
|
||||
Calendar todaysDate = Calendar.getInstance();
|
||||
final String TRANSACTION_DATE = dateFormat.format(todaysDate.getTime());
|
||||
final String withdrawAmt = "800";
|
||||
ArrayList<HashMap> savingsAccountErrorData = (ArrayList<HashMap>) validationErrorHelper.withdrawalFromSavingsAccount(savingsId,
|
||||
withdrawAmt, TRANSACTION_DATE, CommonConstants.RESPONSE_ERROR);
|
||||
assertEquals("error.msg.savingsaccount.transaction.insufficient.account.balance",
|
||||
savingsAccountErrorData.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
Integer depositTransactionId = (Integer) this.savingsAccountHelper.depositToSavingsAccount(savingsId, DEPOSIT_AMOUNT,
|
||||
TRANSACTION_DATE, CommonConstants.RESPONSE_RESOURCE_ID);
|
||||
HashMap depositTransaction = this.savingsAccountHelper.getSavingsTransaction(savingsId, depositTransactionId);
|
||||
balance += new Float(DEPOSIT_AMOUNT);
|
||||
assertEquals("Verifying Deposit Amount", new Float(DEPOSIT_AMOUNT), depositTransaction.get("amount"));
|
||||
assertEquals("Verifying Balance after Deposit", balance, depositTransaction.get("runningBalance"));
|
||||
|
||||
Integer withdrawTransactionId = (Integer) this.savingsAccountHelper.withdrawalFromSavingsAccount(savingsId, withdrawAmt,
|
||||
TRANSACTION_DATE, CommonConstants.RESPONSE_RESOURCE_ID);
|
||||
HashMap withdrawTransaction = this.savingsAccountHelper.getSavingsTransaction(savingsId, withdrawTransactionId);
|
||||
balance -= new Float(withdrawAmt);
|
||||
assertEquals("Verifying Withdrawal Amount", new Float(withdrawAmt), withdrawTransaction.get("amount"));
|
||||
assertEquals("Verifying Balance after Withdrawal", balance, withdrawTransaction.get("runningBalance"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testSavingsAccount_DELETE_APPLICATION() {
|
||||
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
SavingsAccountHelper savingsAccountHelperValidationError = new SavingsAccountHelper(this.requestSpec,
|
||||
new ResponseSpecBuilder().build());
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(clientID);
|
||||
final String minBalanceForInterestCalculation = null;
|
||||
final String minRequiredBalance = null;
|
||||
final String enforceMinRequiredBalance = "false";
|
||||
final boolean allowOverdraft = false;
|
||||
final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE,
|
||||
minBalanceForInterestCalculation, minRequiredBalance, enforceMinRequiredBalance, allowOverdraft);
|
||||
Assert.assertNotNull(savingsProductID);
|
||||
|
||||
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID, ACCOUNT_TYPE_INDIVIDUAL);
|
||||
Assert.assertNotNull(savingsProductID);
|
||||
|
||||
HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap);
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.approveSavings(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap);
|
||||
|
||||
List<HashMap> error1 = (List<HashMap>) savingsAccountHelperValidationError.deleteSavingsApplication(savingsId,
|
||||
CommonConstants.RESPONSE_ERROR);
|
||||
assertEquals("validation.msg.savingsaccount.delete.not.in.submittedandpendingapproval.state",
|
||||
error1.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.undoApproval(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap);
|
||||
|
||||
this.savingsAccountHelper.deleteSavingsApplication(savingsId, CommonConstants.RESPONSE_RESOURCE_ID);
|
||||
|
||||
List<HashMap> error = savingsAccountHelperValidationError.getSavingsCollectionAttribute(savingsId, CommonConstants.RESPONSE_ERROR);
|
||||
assertEquals("error.msg.saving.account.id.invalid", error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testSavingsAccount_REJECT_APPLICATION() {
|
||||
|
||||
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
SavingsAccountHelper savingsAccountHelperValidationError = new SavingsAccountHelper(this.requestSpec,
|
||||
new ResponseSpecBuilder().build());
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(clientID);
|
||||
final String minBalanceForInterestCalculation = null;
|
||||
final String minRequiredBalance = null;
|
||||
final String enforceMinRequiredBalance = "false";
|
||||
final boolean allowOverdraft = false;
|
||||
final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE,
|
||||
minBalanceForInterestCalculation, minRequiredBalance, enforceMinRequiredBalance, allowOverdraft);
|
||||
Assert.assertNotNull(savingsProductID);
|
||||
|
||||
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID, ACCOUNT_TYPE_INDIVIDUAL);
|
||||
Assert.assertNotNull(savingsProductID);
|
||||
|
||||
HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap);
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.approveSavings(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap);
|
||||
|
||||
List<HashMap> error1 = savingsAccountHelperValidationError.rejectApplicationWithErrorCode(savingsId,
|
||||
SavingsAccountHelper.CREATED_DATE_PLUS_ONE);
|
||||
assertEquals("validation.msg.savingsaccount.reject.not.in.submittedandpendingapproval.state",
|
||||
error1.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.undoApproval(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap);
|
||||
|
||||
error1 = savingsAccountHelperValidationError.rejectApplicationWithErrorCode(savingsId, SavingsAccountHelper.getFutureDate());
|
||||
assertEquals("validation.msg.savingsaccount.reject.cannot.be.a.future.date",
|
||||
error1.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
error1 = savingsAccountHelperValidationError.rejectApplicationWithErrorCode(savingsId, SavingsAccountHelper.CREATED_DATE_MINUS_ONE);
|
||||
assertEquals("validation.msg.savingsaccount.reject.cannot.be.before.submittal.date",
|
||||
error1.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.rejectApplication(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsRejected(savingsStatusHashMap);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSavingsAccount_WITHDRAW_APPLICATION() {
|
||||
|
||||
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(clientID);
|
||||
final String minBalanceForInterestCalculation = null;
|
||||
final String minRequiredBalance = null;
|
||||
final String enforceMinRequiredBalance = "false";
|
||||
final boolean allowOverdraft = false;
|
||||
final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE,
|
||||
minBalanceForInterestCalculation, minRequiredBalance, enforceMinRequiredBalance, allowOverdraft);
|
||||
Assert.assertNotNull(savingsProductID);
|
||||
|
||||
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID, ACCOUNT_TYPE_INDIVIDUAL);
|
||||
Assert.assertNotNull(savingsProductID);
|
||||
|
||||
HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap);
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.withdrawApplication(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsWithdrawn(savingsStatusHashMap);
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testSavingsAccountTransactions() {
|
||||
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
|
||||
SavingsAccountHelper savingsAccountHelperValidationError = new SavingsAccountHelper(this.requestSpec,
|
||||
new ResponseSpecBuilder().build());
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(clientID);
|
||||
final String minBalanceForInterestCalculation = null;
|
||||
final String minRequiredBalance = null;
|
||||
final String enforceMinRequiredBalance = "false";
|
||||
final boolean allowOverdraft = false;
|
||||
final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE,
|
||||
minBalanceForInterestCalculation, minRequiredBalance, enforceMinRequiredBalance, allowOverdraft);
|
||||
Assert.assertNotNull(savingsProductID);
|
||||
|
||||
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID, ACCOUNT_TYPE_INDIVIDUAL);
|
||||
Assert.assertNotNull(savingsProductID);
|
||||
|
||||
HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap);
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.approveSavings(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap);
|
||||
|
||||
List<HashMap> error = (List) savingsAccountHelperValidationError.withdrawalFromSavingsAccount(savingsId, "100",
|
||||
SavingsAccountHelper.TRANSACTION_DATE, CommonConstants.RESPONSE_ERROR);
|
||||
assertEquals("error.msg.savingsaccount.transaction.account.is.not.active",
|
||||
error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
error = (List) savingsAccountHelperValidationError.depositToSavingsAccount(savingsId, "100", SavingsAccountHelper.TRANSACTION_DATE,
|
||||
CommonConstants.RESPONSE_ERROR);
|
||||
assertEquals("error.msg.savingsaccount.transaction.account.is.not.active",
|
||||
error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.activateSavings(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap);
|
||||
|
||||
HashMap summary = this.savingsAccountHelper.getSavingsSummary(savingsId);
|
||||
Float balance = new Float(MINIMUM_OPENING_BALANCE);
|
||||
assertEquals("Verifying opening Balance", balance, summary.get("accountBalance"));
|
||||
|
||||
Integer depositTransactionId = (Integer) this.savingsAccountHelper.depositToSavingsAccount(savingsId, DEPOSIT_AMOUNT,
|
||||
SavingsAccountHelper.TRANSACTION_DATE, CommonConstants.RESPONSE_RESOURCE_ID);
|
||||
HashMap depositTransaction = this.savingsAccountHelper.getSavingsTransaction(savingsId, depositTransactionId);
|
||||
balance += new Float(DEPOSIT_AMOUNT);
|
||||
assertEquals("Verifying Deposit Amount", new Float(DEPOSIT_AMOUNT), depositTransaction.get("amount"));
|
||||
assertEquals("Verifying Balance after Deposit", balance, depositTransaction.get("runningBalance"));
|
||||
|
||||
Integer withdrawTransactionId = (Integer) this.savingsAccountHelper.withdrawalFromSavingsAccount(savingsId, WITHDRAW_AMOUNT,
|
||||
SavingsAccountHelper.TRANSACTION_DATE, CommonConstants.RESPONSE_RESOURCE_ID);
|
||||
HashMap withdrawTransaction = this.savingsAccountHelper.getSavingsTransaction(savingsId, withdrawTransactionId);
|
||||
balance -= new Float(WITHDRAW_AMOUNT);
|
||||
assertEquals("Verifying Withdrawal Amount", new Float(WITHDRAW_AMOUNT), withdrawTransaction.get("amount"));
|
||||
assertEquals("Verifying Balance after Withdrawal", balance, withdrawTransaction.get("runningBalance"));
|
||||
|
||||
Integer newWithdrawTransactionId = this.savingsAccountHelper.updateSavingsAccountTransaction(savingsId, withdrawTransactionId,
|
||||
WITHDRAW_AMOUNT_ADJUSTED);
|
||||
HashMap newWithdrawTransaction = this.savingsAccountHelper.getSavingsTransaction(savingsId, newWithdrawTransactionId);
|
||||
balance = balance + new Float(WITHDRAW_AMOUNT) - new Float(WITHDRAW_AMOUNT_ADJUSTED);
|
||||
assertEquals("Verifying adjusted Amount", new Float(WITHDRAW_AMOUNT_ADJUSTED), newWithdrawTransaction.get("amount"));
|
||||
assertEquals("Verifying Balance after adjust", balance, newWithdrawTransaction.get("runningBalance"));
|
||||
summary = this.savingsAccountHelper.getSavingsSummary(savingsId);
|
||||
assertEquals("Verifying Adjusted Balance", balance, summary.get("accountBalance"));
|
||||
withdrawTransaction = this.savingsAccountHelper.getSavingsTransaction(savingsId, withdrawTransactionId);
|
||||
Assert.assertTrue((Boolean) withdrawTransaction.get("reversed"));
|
||||
|
||||
this.savingsAccountHelper.undoSavingsAccountTransaction(savingsId, newWithdrawTransactionId);
|
||||
newWithdrawTransaction = this.savingsAccountHelper.getSavingsTransaction(savingsId, withdrawTransactionId);
|
||||
Assert.assertTrue((Boolean) newWithdrawTransaction.get("reversed"));
|
||||
summary = this.savingsAccountHelper.getSavingsSummary(savingsId);
|
||||
balance += new Float(WITHDRAW_AMOUNT_ADJUSTED);
|
||||
assertEquals("Verifying Balance After Undo Transaction", balance, summary.get("accountBalance"));
|
||||
|
||||
error = (List) savingsAccountHelperValidationError.withdrawalFromSavingsAccount(savingsId, "5000",
|
||||
SavingsAccountHelper.TRANSACTION_DATE, CommonConstants.RESPONSE_ERROR);
|
||||
assertEquals("error.msg.savingsaccount.transaction.insufficient.account.balance",
|
||||
error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
error = (List) savingsAccountHelperValidationError.withdrawalFromSavingsAccount(savingsId, "5000",
|
||||
SavingsAccountHelper.getFutureDate(), CommonConstants.RESPONSE_ERROR);
|
||||
assertEquals("error.msg.savingsaccount.transaction.in.the.future", error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
error = (List) savingsAccountHelperValidationError.depositToSavingsAccount(savingsId, "5000", SavingsAccountHelper.getFutureDate(),
|
||||
CommonConstants.RESPONSE_ERROR);
|
||||
assertEquals("error.msg.savingsaccount.transaction.in.the.future", error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
error = (List) savingsAccountHelperValidationError.withdrawalFromSavingsAccount(savingsId, "5000",
|
||||
SavingsAccountHelper.CREATED_DATE_MINUS_ONE, CommonConstants.RESPONSE_ERROR);
|
||||
assertEquals("error.msg.savingsaccount.transaction.before.activation.date",
|
||||
error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
error = (List) savingsAccountHelperValidationError.depositToSavingsAccount(savingsId, "5000",
|
||||
SavingsAccountHelper.CREATED_DATE_MINUS_ONE, CommonConstants.RESPONSE_ERROR);
|
||||
assertEquals("error.msg.savingsaccount.transaction.before.activation.date",
|
||||
error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testSavingsAccountCharges() {
|
||||
|
||||
final ResponseSpecification erroResponseSpec = new ResponseSpecBuilder().build();
|
||||
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
|
||||
final SavingsAccountHelper validationErrorHelper = new SavingsAccountHelper(this.requestSpec, erroResponseSpec);
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(clientID);
|
||||
final String minBalanceForInterestCalculation = null;
|
||||
final String minRequiredBalance = null;
|
||||
final String enforceMinRequiredBalance = "false";
|
||||
final boolean allowOverdraft = false;
|
||||
final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE,
|
||||
minBalanceForInterestCalculation, minRequiredBalance, enforceMinRequiredBalance, allowOverdraft);
|
||||
Assert.assertNotNull(savingsProductID);
|
||||
|
||||
Assert.assertNotNull(savingsProductID);
|
||||
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID, ACCOUNT_TYPE_INDIVIDUAL);
|
||||
|
||||
HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap);
|
||||
|
||||
final Integer withdrawalChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
|
||||
ChargesHelper.getSavingsWithdrawalFeeJSON());
|
||||
Assert.assertNotNull(withdrawalChargeId);
|
||||
|
||||
this.savingsAccountHelper.addChargesForSavings(savingsId, withdrawalChargeId);
|
||||
ArrayList<HashMap> chargesPendingState = this.savingsAccountHelper.getSavingsCharges(savingsId);
|
||||
Assert.assertEquals(1, chargesPendingState.size());
|
||||
|
||||
Integer savingsChargeId = (Integer) chargesPendingState.get(0).get("id");
|
||||
HashMap chargeChanges = this.savingsAccountHelper.updateCharges(savingsChargeId, savingsId);
|
||||
Assert.assertTrue(chargeChanges.containsKey("amount"));
|
||||
|
||||
Integer deletedChargeId = this.savingsAccountHelper.deleteCharge(savingsChargeId, savingsId);
|
||||
assertEquals(savingsChargeId, deletedChargeId);
|
||||
|
||||
chargesPendingState = this.savingsAccountHelper.getSavingsCharges(savingsId);
|
||||
Assert.assertTrue(chargesPendingState == null || chargesPendingState.size() == 0);
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.approveSavings(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap);
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.activateSavings(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap);
|
||||
|
||||
final Integer chargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec, ChargesHelper.getSavingsAnnualFeeJSON());
|
||||
Assert.assertNotNull(chargeId);
|
||||
|
||||
ArrayList<HashMap> charges = this.savingsAccountHelper.getSavingsCharges(savingsId);
|
||||
Assert.assertTrue(charges == null || charges.size() == 0);
|
||||
|
||||
this.savingsAccountHelper.addChargesForSavings(savingsId, chargeId);
|
||||
charges = this.savingsAccountHelper.getSavingsCharges(savingsId);
|
||||
Assert.assertEquals(1, charges.size());
|
||||
|
||||
HashMap savingsChargeForPay = charges.get(0);
|
||||
Integer annualSavingsChargeId = (Integer) savingsChargeForPay.get("id");
|
||||
|
||||
ArrayList<HashMap> savingsAccountErrorData = (ArrayList<HashMap>) validationErrorHelper.inactivateCharge(annualSavingsChargeId,
|
||||
savingsId, CommonConstants.RESPONSE_ERROR);
|
||||
assertEquals("validation.msg.savingsaccountcharge.inactivation.of.charge.not.allowed.when.charge.is.due", savingsAccountErrorData
|
||||
.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(CommonConstants.dateFormat, Locale.US);
|
||||
Calendar cal = Calendar.getInstance();
|
||||
List dates = (List) savingsChargeForPay.get("dueDate");
|
||||
cal.set(Calendar.YEAR, (Integer) dates.get(0));
|
||||
cal.set(Calendar.MONTH, (Integer) dates.get(1) - 1);
|
||||
cal.set(Calendar.DAY_OF_MONTH, (Integer) dates.get(2));
|
||||
int n = 0;
|
||||
Calendar current = Calendar.getInstance();
|
||||
while (cal.compareTo(current) < 0) {
|
||||
n++;
|
||||
cal.set(Calendar.YEAR, (Integer) dates.get(0) + n);
|
||||
}
|
||||
cal.set(Calendar.YEAR, (Integer) dates.get(0));
|
||||
cal.set(Calendar.MONTH, (Integer) dates.get(1) - 1);
|
||||
cal.set(Calendar.DAY_OF_MONTH, (Integer) dates.get(2));
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
this.savingsAccountHelper.payCharge((Integer) savingsChargeForPay.get("id"), savingsId,
|
||||
((Float) savingsChargeForPay.get("amount")).toString(), sdf.format(cal.getTime()));
|
||||
HashMap paidCharge = this.savingsAccountHelper.getSavingsCharge(savingsId, (Integer) savingsChargeForPay.get("id"));
|
||||
Float expectedValue = (Float) savingsChargeForPay.get("amount") * i;
|
||||
assertEquals(expectedValue, paidCharge.get("amountPaid"));
|
||||
cal.set(Calendar.YEAR, (Integer) dates.get(0) + i);
|
||||
}
|
||||
|
||||
Integer inactivatedChargeId = (Integer) this.savingsAccountHelper.inactivateCharge(annualSavingsChargeId, savingsId,
|
||||
CommonConstants.RESPONSE_RESOURCE_ID);
|
||||
assertEquals("Inactivated Savings Charges Id", annualSavingsChargeId, inactivatedChargeId);
|
||||
|
||||
final Integer monthlyFeechargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
|
||||
ChargesHelper.getSavingsMonthlyFeeJSON());
|
||||
Assert.assertNotNull(monthlyFeechargeId);
|
||||
|
||||
this.savingsAccountHelper.addChargesForSavings(savingsId, monthlyFeechargeId);
|
||||
charges = this.savingsAccountHelper.getSavingsCharges(savingsId);
|
||||
Assert.assertEquals(2, charges.size());
|
||||
|
||||
HashMap savingsChargeForWaive = charges.get(1);
|
||||
final Integer monthlySavingsCharge = (Integer) savingsChargeForWaive.get("id");
|
||||
|
||||
savingsAccountErrorData = (ArrayList<HashMap>) validationErrorHelper.inactivateCharge(monthlySavingsCharge, savingsId,
|
||||
CommonConstants.RESPONSE_ERROR);
|
||||
assertEquals("validation.msg.savingsaccountcharge.inactivation.of.charge.not.allowed.when.charge.is.due", savingsAccountErrorData
|
||||
.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
this.savingsAccountHelper.waiveCharge((Integer) savingsChargeForWaive.get("id"), savingsId);
|
||||
HashMap waiveCharge = this.savingsAccountHelper.getSavingsCharge(savingsId, (Integer) savingsChargeForWaive.get("id"));
|
||||
assertEquals(savingsChargeForWaive.get("amount"), waiveCharge.get("amountWaived"));
|
||||
|
||||
this.savingsAccountHelper.waiveCharge((Integer) savingsChargeForWaive.get("id"), savingsId);
|
||||
waiveCharge = this.savingsAccountHelper.getSavingsCharge(savingsId, (Integer) savingsChargeForWaive.get("id"));
|
||||
BigDecimal totalWaiveAmount = BigDecimal.valueOf(Double.valueOf((Float) savingsChargeForWaive.get("amount")));
|
||||
totalWaiveAmount = totalWaiveAmount.add(totalWaiveAmount);
|
||||
assertEquals(totalWaiveAmount.floatValue(), waiveCharge.get("amountWaived"));
|
||||
|
||||
final Integer weeklyFeeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
|
||||
ChargesHelper.getSavingsWeeklyFeeJSON());
|
||||
Assert.assertNotNull(weeklyFeeId);
|
||||
|
||||
this.savingsAccountHelper.addChargesForSavings(savingsId, weeklyFeeId);
|
||||
charges = this.savingsAccountHelper.getSavingsCharges(savingsId);
|
||||
Assert.assertEquals(3, charges.size());
|
||||
|
||||
savingsChargeForPay = charges.get(2);
|
||||
final Integer weeklySavingsFeeId = (Integer) savingsChargeForPay.get("id");
|
||||
|
||||
savingsAccountErrorData = (ArrayList<HashMap>) validationErrorHelper.inactivateCharge(weeklySavingsFeeId, savingsId,
|
||||
CommonConstants.RESPONSE_ERROR);
|
||||
assertEquals("validation.msg.savingsaccountcharge.inactivation.of.charge.not.allowed.when.charge.is.due", savingsAccountErrorData
|
||||
.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
cal = Calendar.getInstance();
|
||||
dates = (List) savingsChargeForPay.get("dueDate");
|
||||
cal.set(Calendar.YEAR, (Integer) dates.get(0));
|
||||
cal.set(Calendar.MONTH, (Integer) dates.get(1) - 1);
|
||||
cal.set(Calendar.DAY_OF_MONTH, (Integer) dates.get(2));
|
||||
|
||||
// Depositing huge amount as scheduler job deducts the fee amount
|
||||
Integer depositTransactionId = (Integer) this.savingsAccountHelper.depositToSavingsAccount(savingsId, "100000",
|
||||
SavingsAccountHelper.TRANSACTION_DATE, CommonConstants.RESPONSE_RESOURCE_ID);
|
||||
Assert.assertNotNull(depositTransactionId);
|
||||
|
||||
this.savingsAccountHelper.payCharge((Integer) savingsChargeForPay.get("id"), savingsId,
|
||||
((Float) savingsChargeForPay.get("amount")).toString(), sdf.format(cal.getTime()));
|
||||
HashMap paidCharge = this.savingsAccountHelper.getSavingsCharge(savingsId, (Integer) savingsChargeForPay.get("id"));
|
||||
assertEquals(savingsChargeForPay.get("amount"), paidCharge.get("amountPaid"));
|
||||
List nextDueDates = (List) paidCharge.get("dueDate");
|
||||
LocalDate nextDueDate = new LocalDate((Integer) nextDueDates.get(0), (Integer) nextDueDates.get(1), (Integer) nextDueDates.get(2));
|
||||
LocalDate expectedNextDueDate = new LocalDate((Integer) dates.get(0), (Integer) dates.get(1), (Integer) dates.get(2))
|
||||
.plusWeeks((Integer) paidCharge.get("feeInterval"));
|
||||
assertEquals(expectedNextDueDate, nextDueDate);
|
||||
}
|
||||
|
||||
/***
|
||||
* Test case for overdraft account functionality. Open account with zero
|
||||
* balance, perform transactions then post interest and verify posted
|
||||
* interest
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testSavingsAccountWithOverdraft() {
|
||||
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
|
||||
final ResponseSpecification errorResponse = new ResponseSpecBuilder().expectStatusCode(400).build();
|
||||
final SavingsAccountHelper validationErrorHelper = new SavingsAccountHelper(this.requestSpec, errorResponse);
|
||||
|
||||
/***
|
||||
* Create a client to apply for savings account (overdraft account).
|
||||
*/
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(clientID);
|
||||
final String minBalanceForInterestCalculation = null;
|
||||
|
||||
/***
|
||||
* Create savings product with zero opening balance and overdraft
|
||||
* enabled
|
||||
*/
|
||||
final String zeroOpeningBalance = "0.0";
|
||||
final String minRequiredBalance = null;
|
||||
final String enforceMinRequiredBalance = "false";
|
||||
final boolean allowOverdraft = true;
|
||||
final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, zeroOpeningBalance,
|
||||
minBalanceForInterestCalculation, minRequiredBalance, enforceMinRequiredBalance, allowOverdraft);
|
||||
Assert.assertNotNull(savingsProductID);
|
||||
|
||||
/***
|
||||
* Apply for Savings account
|
||||
*/
|
||||
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID, ACCOUNT_TYPE_INDIVIDUAL);
|
||||
Assert.assertNotNull(savingsProductID);
|
||||
|
||||
HashMap modifications = this.savingsAccountHelper.updateSavingsAccount(clientID, savingsProductID, savingsId,
|
||||
ACCOUNT_TYPE_INDIVIDUAL);
|
||||
Assert.assertTrue(modifications.containsKey("submittedOnDate"));
|
||||
|
||||
HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap);
|
||||
|
||||
/***
|
||||
* Approve the savings account
|
||||
*/
|
||||
savingsStatusHashMap = this.savingsAccountHelper.approveSavings(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap);
|
||||
|
||||
DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy", Locale.US);
|
||||
Calendar todaysDate = Calendar.getInstance();
|
||||
todaysDate.add(Calendar.MONTH, -1);
|
||||
todaysDate.set(Calendar.DAY_OF_MONTH, 1);
|
||||
final String ACTIVATION_DATE = dateFormat.format(todaysDate.getTime());
|
||||
final Integer lastDayOfMonth = todaysDate.getActualMaximum(Calendar.DAY_OF_MONTH);
|
||||
todaysDate.set(Calendar.DAY_OF_MONTH, lastDayOfMonth);
|
||||
final String TRANSACTION_DATE = dateFormat.format(todaysDate.getTime());
|
||||
|
||||
/***
|
||||
* Activate the application and verify account status
|
||||
*
|
||||
* @param activationDate
|
||||
* this value is every time first day of previous month
|
||||
*/
|
||||
savingsStatusHashMap = activateSavingsAccount(savingsId, ACTIVATION_DATE);
|
||||
SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap);
|
||||
|
||||
/***
|
||||
* Verify the account summary
|
||||
*/
|
||||
final HashMap summaryBefore = this.savingsAccountHelper.getSavingsSummary(savingsId);
|
||||
this.savingsAccountHelper.calculateInterestForSavings(savingsId);
|
||||
HashMap summary = this.savingsAccountHelper.getSavingsSummary(savingsId);
|
||||
assertEquals(summaryBefore, summary);
|
||||
|
||||
Float balance = Float.valueOf(zeroOpeningBalance);
|
||||
|
||||
/***
|
||||
* Perform withdraw transaction, verify account balance(account balance
|
||||
* will go to negative as no deposits are there prior to this
|
||||
* transaction)
|
||||
*/
|
||||
Integer withdrawTransactionId = (Integer) this.savingsAccountHelper.withdrawalFromSavingsAccount(savingsId, WITHDRAW_AMOUNT,
|
||||
ACTIVATION_DATE, CommonConstants.RESPONSE_RESOURCE_ID);
|
||||
HashMap withdrawTransaction = this.savingsAccountHelper.getSavingsTransaction(savingsId, withdrawTransactionId);
|
||||
balance -= new Float(WITHDRAW_AMOUNT);
|
||||
assertEquals("Verifying Withdrawal Amount", new Float(WITHDRAW_AMOUNT), withdrawTransaction.get("amount"));
|
||||
assertEquals("Verifying Balance after Withdrawal", balance, withdrawTransaction.get("runningBalance"));
|
||||
|
||||
/***
|
||||
* Perform Deposit transaction on last day of month and verify account
|
||||
* balance.
|
||||
*
|
||||
* @param transactionDate
|
||||
* this value is every time last day of previous month
|
||||
*/
|
||||
Integer depositTransactionId = (Integer) this.savingsAccountHelper.depositToSavingsAccount(savingsId, DEPOSIT_AMOUNT,
|
||||
TRANSACTION_DATE, CommonConstants.RESPONSE_RESOURCE_ID);
|
||||
HashMap depositTransaction = this.savingsAccountHelper.getSavingsTransaction(savingsId, depositTransactionId);
|
||||
balance += new Float(DEPOSIT_AMOUNT);
|
||||
assertEquals("Verifying Deposit Amount", new Float(DEPOSIT_AMOUNT), depositTransaction.get("amount"));
|
||||
assertEquals("Verifying Balance after Deposit", balance, depositTransaction.get("runningBalance"));
|
||||
|
||||
/***
|
||||
* Perform Post interest transaction and verify the posted amount
|
||||
*/
|
||||
this.savingsAccountHelper.postInterestForSavings(savingsId);
|
||||
HashMap accountDetails = this.savingsAccountHelper.getSavingsDetails(savingsId);
|
||||
summary = (HashMap) accountDetails.get("summary");
|
||||
Float actualInterestPosted = Float.valueOf(summary.get("totalInterestPosted").toString());
|
||||
|
||||
/***
|
||||
* Calculate expected interest to be posted, interest should be posted
|
||||
* for one day only because deposit transaction happened on last day of
|
||||
* month before this account balance is negative.
|
||||
*/
|
||||
final Float nominalAnnualInterest = Float.valueOf(accountDetails.get("nominalAnnualInterestRate").toString());
|
||||
final HashMap interestCalculationDaysInYearType = (HashMap) accountDetails.get("interestCalculationDaysInYearType");
|
||||
final Integer daysInYear = Integer.valueOf(interestCalculationDaysInYearType.get("id").toString());
|
||||
double interestRateInFraction = (nominalAnnualInterest / 100);
|
||||
double perDay = (double) 1 / (daysInYear);
|
||||
double interestPerDay = interestRateInFraction * perDay;
|
||||
Float interestPosted = (float) (interestPerDay * balance * 1);
|
||||
|
||||
/***
|
||||
* Apply rounding on interestPosted, actualInterestPosted and verify
|
||||
* both are same
|
||||
*/
|
||||
DecimalFormat decimalFormat = new DecimalFormat("", new DecimalFormatSymbols(Locale.US));
|
||||
decimalFormat.applyPattern("#.###");
|
||||
interestPosted = new Float(decimalFormat.format(interestPosted));
|
||||
actualInterestPosted = new Float(decimalFormat.format(actualInterestPosted));
|
||||
assertEquals("Verifying interest posted", interestPosted, actualInterestPosted);
|
||||
|
||||
todaysDate = Calendar.getInstance();
|
||||
final String CLOSEDON_DATE = dateFormat.format(todaysDate.getTime());
|
||||
String withdrawBalance = "false";
|
||||
ArrayList<HashMap> savingsAccountErrorData = (ArrayList<HashMap>) validationErrorHelper.closeSavingsAccountAndGetBackRequiredField(
|
||||
savingsId, withdrawBalance, CommonConstants.RESPONSE_ERROR, CLOSEDON_DATE);
|
||||
assertEquals("validation.msg.savingsaccount.close.results.in.balance.not.zero",
|
||||
savingsAccountErrorData.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
}
|
||||
|
||||
private HashMap activateSavingsAccount(final Integer savingsId, final String activationDate) {
|
||||
final HashMap status = this.savingsAccountHelper.activateSavingsAccount(savingsId, activationDate);
|
||||
return status;
|
||||
}
|
||||
|
||||
private Integer createSavingsProduct(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String minOpenningBalance, String minBalanceForInterestCalculation, String minRequiredBalance,
|
||||
String enforceMinRequiredBalance, final boolean allowOverdraft) {
|
||||
System.out.println("------------------------------CREATING NEW SAVINGS PRODUCT ---------------------------------------");
|
||||
SavingsProductHelper savingsProductHelper = new SavingsProductHelper();
|
||||
if (allowOverdraft) {
|
||||
final String overDraftLimit = "2000.0";
|
||||
savingsProductHelper = savingsProductHelper.withOverDraft(overDraftLimit);
|
||||
}
|
||||
|
||||
final String savingsProductJSON = savingsProductHelper
|
||||
//
|
||||
.withInterestCompoundingPeriodTypeAsDaily()
|
||||
//
|
||||
.withInterestPostingPeriodTypeAsMonthly()
|
||||
//
|
||||
.withInterestCalculationPeriodTypeAsDailyBalance()
|
||||
//
|
||||
.withMinBalanceForInterestCalculation(minBalanceForInterestCalculation)
|
||||
//
|
||||
.withMinRequiredBalance(minRequiredBalance).withEnforceMinRequiredBalance(enforceMinRequiredBalance)
|
||||
.withMinimumOpenningBalance(minOpenningBalance).build();
|
||||
return SavingsProductHelper.createSavingsProduct(savingsProductJSON, requestSpec, responseSpec);
|
||||
}
|
||||
|
||||
/*
|
||||
* private void verifySavingsInterest(final Object savingsInterest) {
|
||||
* System.out.println(
|
||||
* "--------------------VERIFYING THE BALANCE, INTEREST --------------------------"
|
||||
* );
|
||||
*
|
||||
* assertEquals("Verifying Interest Calculation", new Float("238.3399"),
|
||||
* savingsInterest); }
|
||||
*/
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ClientStatusChecker {
|
||||
|
||||
public static void verifyClientIsActive(final HashMap<String, Object> clientStatusHashMap) {
|
||||
assertEquals((int) clientStatusHashMap.get("id"), 300);
|
||||
}
|
||||
|
||||
public static void verifyClientClosed(final HashMap<String, Object> clientStatusHashMap) {
|
||||
System.out.println("\n-------------------------------------- VERIFYING CLIENT IS CLOSED ------------------------------------");
|
||||
assertEquals((int) clientStatusHashMap.get("id"), 600);
|
||||
System.out.println("Client Status:" + clientStatusHashMap + "\n");
|
||||
}
|
||||
|
||||
public static void verifyClientPending(final HashMap<String, Object> clientStatusHashMap) {
|
||||
System.out.println("\n-------------------------------------- VERIFYING CLIENT IS PENDING ------------------------------------");
|
||||
assertEquals((int) clientStatusHashMap.get("id"), 100);
|
||||
System.out.println("Client Status:" + clientStatusHashMap + "\n");
|
||||
}
|
||||
|
||||
public static void verifyClientRejected(final HashMap<String, Object> clientStatusHashMap) {
|
||||
System.out.println("\n-------------------------------------- VERIFYING CLIENT IS REJECTED ------------------------------------");
|
||||
assertEquals((int) clientStatusHashMap.get("id"), 700);
|
||||
System.out.println("Client Status:" + clientStatusHashMap + "\n");
|
||||
}
|
||||
|
||||
public static void verifyClientActiavted(final HashMap<String, Object> clientStatusHashMap) {
|
||||
System.out.println("\n-------------------------------------- VERIFYING CLIENT IS ACTIVATED ------------------------------------");
|
||||
assertEquals((int) clientStatusHashMap.get("id"), 300);
|
||||
System.out.println("Client Status:" + clientStatusHashMap + "\n");
|
||||
}
|
||||
|
||||
public static void verifyClientWithdrawn(final HashMap<String, Object> clientStatusHashMap) {
|
||||
System.out.println("\n-------------------------------------- VERIFYING CLIENT IS WITHDRAWN ------------------------------------");
|
||||
assertEquals((int) clientStatusHashMap.get("id"), 800);
|
||||
System.out.println("Client Status:" + clientStatusHashMap + "\n");
|
||||
}
|
||||
|
||||
}
|
||||
+148
@@ -0,0 +1,148 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.jayway.restassured.builder.RequestSpecBuilder;
|
||||
import com.jayway.restassured.builder.ResponseSpecBuilder;
|
||||
import com.jayway.restassured.http.ContentType;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
public class ClientTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private ClientHelper clientHelper;
|
||||
|
||||
@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();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClientStatus() {
|
||||
this.clientHelper = new ClientHelper(this.requestSpec, this.responseSpec);
|
||||
final Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(clientId);
|
||||
|
||||
HashMap<String, Object> status = ClientHelper.getClientStatus(requestSpec, responseSpec, String.valueOf(clientId));
|
||||
ClientStatusChecker.verifyClientIsActive(status);
|
||||
|
||||
HashMap<String, Object> clientStatusHashMap = this.clientHelper.closeClient(clientId);
|
||||
ClientStatusChecker.verifyClientClosed(clientStatusHashMap);
|
||||
|
||||
clientStatusHashMap = this.clientHelper.reactivateClient(clientId);
|
||||
ClientStatusChecker.verifyClientPending(clientStatusHashMap);
|
||||
|
||||
clientStatusHashMap = this.clientHelper.rejectClient(clientId);
|
||||
ClientStatusChecker.verifyClientRejected(clientStatusHashMap);
|
||||
|
||||
clientStatusHashMap = this.clientHelper.activateClient(clientId);
|
||||
ClientStatusChecker.verifyClientActiavted(clientStatusHashMap);
|
||||
|
||||
clientStatusHashMap = this.clientHelper.closeClient(clientId);
|
||||
ClientStatusChecker.verifyClientClosed(clientStatusHashMap);
|
||||
|
||||
clientStatusHashMap = this.clientHelper.reactivateClient(clientId);
|
||||
ClientStatusChecker.verifyClientPending(clientStatusHashMap);
|
||||
|
||||
clientStatusHashMap = this.clientHelper.withdrawClient(clientId);
|
||||
ClientStatusChecker.verifyClientWithdrawn(clientStatusHashMap);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClientAsPersonStatus() {
|
||||
|
||||
this.clientHelper = new ClientHelper(this.requestSpec, this.responseSpec);
|
||||
final Integer clientId = ClientHelper.createClientAsPerson(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(clientId);
|
||||
|
||||
HashMap<String, Object> status = ClientHelper.getClientStatus(requestSpec, responseSpec, String.valueOf(clientId));
|
||||
ClientStatusChecker.verifyClientIsActive(status);
|
||||
|
||||
HashMap<String, Object> clientStatusHashMap = this.clientHelper.closeClient(clientId);
|
||||
ClientStatusChecker.verifyClientClosed(clientStatusHashMap);
|
||||
|
||||
clientStatusHashMap = this.clientHelper.reactivateClient(clientId);
|
||||
ClientStatusChecker.verifyClientPending(clientStatusHashMap);
|
||||
|
||||
clientStatusHashMap = this.clientHelper.rejectClient(clientId);
|
||||
ClientStatusChecker.verifyClientRejected(clientStatusHashMap);
|
||||
|
||||
clientStatusHashMap = this.clientHelper.activateClient(clientId);
|
||||
ClientStatusChecker.verifyClientActiavted(clientStatusHashMap);
|
||||
|
||||
clientStatusHashMap = this.clientHelper.closeClient(clientId);
|
||||
ClientStatusChecker.verifyClientClosed(clientStatusHashMap);
|
||||
|
||||
clientStatusHashMap = this.clientHelper.reactivateClient(clientId);
|
||||
ClientStatusChecker.verifyClientPending(clientStatusHashMap);
|
||||
|
||||
clientStatusHashMap = this.clientHelper.withdrawClient(clientId);
|
||||
ClientStatusChecker.verifyClientWithdrawn(clientStatusHashMap);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClientAsEntityStatus() {
|
||||
|
||||
this.clientHelper = new ClientHelper(this.requestSpec, this.responseSpec);
|
||||
final Integer clientId = ClientHelper.createClientAsEntity(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(clientId);
|
||||
|
||||
HashMap<String, Object> status = ClientHelper.getClientStatus(requestSpec, responseSpec, String.valueOf(clientId));
|
||||
ClientStatusChecker.verifyClientIsActive(status);
|
||||
|
||||
HashMap<String, Object> clientStatusHashMap = this.clientHelper.closeClient(clientId);
|
||||
ClientStatusChecker.verifyClientClosed(clientStatusHashMap);
|
||||
|
||||
clientStatusHashMap = this.clientHelper.reactivateClient(clientId);
|
||||
ClientStatusChecker.verifyClientPending(clientStatusHashMap);
|
||||
|
||||
clientStatusHashMap = this.clientHelper.rejectClient(clientId);
|
||||
ClientStatusChecker.verifyClientRejected(clientStatusHashMap);
|
||||
|
||||
clientStatusHashMap = this.clientHelper.activateClient(clientId);
|
||||
ClientStatusChecker.verifyClientActiavted(clientStatusHashMap);
|
||||
|
||||
clientStatusHashMap = this.clientHelper.closeClient(clientId);
|
||||
ClientStatusChecker.verifyClientClosed(clientStatusHashMap);
|
||||
|
||||
clientStatusHashMap = this.clientHelper.reactivateClient(clientId);
|
||||
ClientStatusChecker.verifyClientPending(clientStatusHashMap);
|
||||
|
||||
clientStatusHashMap = this.clientHelper.withdrawClient(clientId);
|
||||
ClientStatusChecker.verifyClientWithdrawn(clientStatusHashMap);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+165
@@ -0,0 +1,165 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.accounting.Account;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.jayway.restassured.builder.RequestSpecBuilder;
|
||||
import com.jayway.restassured.builder.ResponseSpecBuilder;
|
||||
import com.jayway.restassured.http.ContentType;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
public class ConcurrencyIntegrationTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private LoanTransactionHelper loanTransactionHelper;
|
||||
|
||||
private static final String NO_ACCOUNTING = "1";
|
||||
|
||||
final int MYTHREADS = 30;
|
||||
|
||||
@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.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyConcurrentLoanRepayments() {
|
||||
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
ClientHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, clientID);
|
||||
final Integer loanProductID = createLoanProduct(false, NO_ACCOUNTING);
|
||||
final Integer loanID = applyForLoanApplication(clientID, loanProductID, "12,000.00");
|
||||
this.loanTransactionHelper.approveLoan("20 September 2011", loanID);
|
||||
this.loanTransactionHelper.disburseLoan("20 September 2011", loanID, "12,000.00");
|
||||
|
||||
ExecutorService executor = Executors.newFixedThreadPool(MYTHREADS);
|
||||
Calendar date = Calendar.getInstance();
|
||||
date.set(2011, 9, 20);
|
||||
Float repaymentAmount = 100.0f;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
System.out.println("Starting concurrent transaction number " + i);
|
||||
date.add(Calendar.DAY_OF_MONTH, 1);
|
||||
repaymentAmount = repaymentAmount + 100;
|
||||
Runnable worker = new LoanRepaymentExecutor(loanTransactionHelper, loanID, repaymentAmount, date);
|
||||
executor.execute(worker);
|
||||
}
|
||||
|
||||
executor.shutdown();
|
||||
// Wait until all threads are finish
|
||||
while (!executor.isTerminated()) {
|
||||
|
||||
}
|
||||
System.out.println("\nFinished all threads");
|
||||
|
||||
}
|
||||
|
||||
private Integer createLoanProduct(final boolean multiDisburseLoan, final String accountingRule, final Account... accounts) {
|
||||
System.out.println("------------------------------CREATING NEW LOAN PRODUCT ---------------------------------------");
|
||||
LoanProductTestBuilder builder = new LoanProductTestBuilder() //
|
||||
.withPrincipal("12,000.00") //
|
||||
.withNumberOfRepayments("4") //
|
||||
.withRepaymentAfterEvery("1") //
|
||||
.withRepaymentTypeAsMonth() //
|
||||
.withinterestRatePerPeriod("1") //
|
||||
.withInterestRateFrequencyTypeAsMonths() //
|
||||
.withAmortizationTypeAsEqualInstallments() //
|
||||
.withInterestTypeAsDecliningBalance() //
|
||||
.withTranches(multiDisburseLoan) //
|
||||
.withAccounting(accountingRule, accounts);
|
||||
|
||||
if (multiDisburseLoan) {
|
||||
builder = builder.withInterestCalculationPeriodTypeAsRepaymentPeriod(true);
|
||||
}
|
||||
final String loanProductJSON = builder.build(null);
|
||||
return this.loanTransactionHelper.getLoanProductId(loanProductJSON);
|
||||
}
|
||||
|
||||
private Integer applyForLoanApplication(final Integer clientID, final Integer loanProductID, String principal) {
|
||||
System.out.println("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------");
|
||||
final String loanApplicationJSON = new LoanApplicationTestBuilder() //
|
||||
.withPrincipal(principal) //
|
||||
.withLoanTermFrequency("4") //
|
||||
.withLoanTermFrequencyAsMonths() //
|
||||
.withNumberOfRepayments("4") //
|
||||
.withRepaymentEveryAfter("1") //
|
||||
.withRepaymentFrequencyTypeAsMonths() //
|
||||
.withInterestRatePerPeriod("2") //
|
||||
.withAmortizationTypeAsEqualInstallments() //
|
||||
.withInterestTypeAsDecliningBalance() //
|
||||
.withInterestCalculationPeriodTypeSameAsRepaymentPeriod() //
|
||||
.withExpectedDisbursementDate("20 September 2011") //
|
||||
.withSubmittedOnDate("20 September 2011") //
|
||||
.build(clientID.toString(), loanProductID.toString(), null);
|
||||
return this.loanTransactionHelper.getLoanId(loanApplicationJSON);
|
||||
}
|
||||
|
||||
public static class LoanRepaymentExecutor implements Runnable {
|
||||
|
||||
private final Integer loanId;
|
||||
private final Float repaymentAmount;
|
||||
private final String repaymentDate;
|
||||
private final LoanTransactionHelper loanTransactionHelper;
|
||||
|
||||
DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy", Locale.US);
|
||||
|
||||
LoanRepaymentExecutor(LoanTransactionHelper loanTransactionHelper, Integer loanId, Float repaymentAmount, Calendar repaymentDate) {
|
||||
this.loanId = loanId;
|
||||
this.repaymentAmount = repaymentAmount;
|
||||
this.repaymentDate = dateFormat.format(repaymentDate.getTime());
|
||||
this.loanTransactionHelper = loanTransactionHelper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
this.loanTransactionHelper.makeRepayment(repaymentDate, repaymentAmount, loanId);
|
||||
} catch (Exception e) {
|
||||
System.out.println("Found an exception" + e.getMessage());
|
||||
System.out.println("Details of failed concurrent transaction (date, amount, loanId) are " + repaymentDate + ","
|
||||
+ repaymentAmount + "," + loanId);
|
||||
throw (e);
|
||||
}
|
||||
System.out.println("Details of passed concurrent transaction, details (date, amount, loanId) are " + repaymentDate + ","
|
||||
+ repaymentAmount + "," + loanId);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.CurrenciesHelper;
|
||||
import org.apache.fineract.integrationtests.common.CurrencyDomain;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
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;
|
||||
|
||||
@SuppressWarnings({ "unused", "rawtypes" })
|
||||
public class CurrenciesTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCurrencyElements() {
|
||||
|
||||
CurrencyDomain currency = CurrenciesHelper.getCurrencybyCode(requestSpec, responseSpec, "USD");
|
||||
CurrencyDomain usd = CurrencyDomain.create("USD", "US Dollar", 2, "$", "currency.USD", "US Dollar ($)").build();
|
||||
|
||||
Assert.assertTrue(currency.getDecimalPlaces() >= 0);
|
||||
Assert.assertNotNull(currency.getName());
|
||||
Assert.assertNotNull(currency.getDisplaySymbol());
|
||||
Assert.assertNotNull(currency.getDisplayLabel());
|
||||
Assert.assertNotNull(currency.getNameCode());
|
||||
|
||||
Assert.assertEquals(usd, currency);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateCurrencySelection() {
|
||||
|
||||
// Test updation
|
||||
ArrayList<String> currenciestoUpdate = new ArrayList<String>();
|
||||
currenciestoUpdate.add("KES");
|
||||
currenciestoUpdate.add("BND");
|
||||
currenciestoUpdate.add("LBP");
|
||||
currenciestoUpdate.add("GHC");
|
||||
currenciestoUpdate.add("USD");
|
||||
|
||||
ArrayList<String> currenciesOutput = CurrenciesHelper.updateSelectedCurrencies(this.requestSpec, this.responseSpec,
|
||||
currenciestoUpdate);
|
||||
Assert.assertNotNull(currenciesOutput);
|
||||
|
||||
Assert.assertEquals("Verifying Do Outputed Currencies Match after Updation", currenciestoUpdate, currenciesOutput);
|
||||
|
||||
// Test that output matches updation
|
||||
ArrayList<CurrencyDomain> currenciesBeforeUpdate = new ArrayList<CurrencyDomain>();
|
||||
for (String e : currenciestoUpdate) {
|
||||
currenciesBeforeUpdate.add(CurrenciesHelper.getCurrencybyCode(requestSpec, responseSpec, e));
|
||||
}
|
||||
Collections.sort(currenciesBeforeUpdate);
|
||||
|
||||
ArrayList<CurrencyDomain> currenciesAfterUpdate = CurrenciesHelper.getSelectedCurrencies(requestSpec, responseSpec);
|
||||
Assert.assertNotNull(currenciesAfterUpdate);
|
||||
|
||||
Assert.assertEquals("Verifying Do Selected Currencies Match after Updation", currenciesBeforeUpdate, currenciesAfterUpdate);
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.savings.SavingsAccountHelper;
|
||||
import org.junit.Before;
|
||||
|
||||
import com.jayway.restassured.builder.RequestSpecBuilder;
|
||||
import com.jayway.restassured.builder.ResponseSpecBuilder;
|
||||
import com.jayway.restassured.http.ContentType;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
public class CurrencyIntegrationTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private SavingsAccountHelper savingsAccountHelper;
|
||||
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
+368
@@ -0,0 +1,368 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.*;
|
||||
import org.apache.fineract.integrationtests.common.loans.*;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Tests loan schedule change based on group meeting changes and loan
|
||||
* rescheduling
|
||||
**/
|
||||
@SuppressWarnings({ "rawtypes" })
|
||||
@Ignore
|
||||
public class DisbursalAndRepaymentScheduleTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private ResponseSpecification responseSpecForStatusCode403;
|
||||
private ResponseSpecification generalResponseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private LoanTransactionHelper loanTransactionHelper;
|
||||
private LoanRescheduleRequestHelper loanRescheduleRequestHelper;
|
||||
private Integer loanRescheduleRequestId;
|
||||
private Integer clientId;
|
||||
private Integer groupId;
|
||||
private Integer groupCalendarId;
|
||||
private Integer loanProductId;
|
||||
private Integer loanId;
|
||||
private final String loanPrincipalAmount = "100000.00";
|
||||
private final String numberOfRepayments = "12";
|
||||
private final String interestRatePerPeriod = "18";
|
||||
|
||||
private final SimpleDateFormat dateFormatterStandard = new SimpleDateFormat("dd MMMM yyyy");
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
Utils.initializeRESTAssured();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRescheduleJLGLoanSynk() {
|
||||
System.out.println("---------------------------------STARTING RESCHEDULE JLG LOAN TEST ------------------------------------------");
|
||||
|
||||
Calendar meetingCalendar = Calendar.getInstance();
|
||||
meetingCalendar.setFirstDayOfWeek(Calendar.MONDAY);
|
||||
meetingCalendar.setTime(new java.util.Date());
|
||||
|
||||
int today = meetingCalendar.get(Calendar.DAY_OF_WEEK);
|
||||
// making sure that the meeting calendar is set for the coming monday.
|
||||
if (today >= Calendar.MONDAY) {
|
||||
meetingCalendar.add(Calendar.DAY_OF_YEAR, +(Calendar.MONDAY - today + 7));
|
||||
} else {
|
||||
meetingCalendar.add(Calendar.DAY_OF_YEAR, +(Calendar.MONDAY - today));
|
||||
}
|
||||
|
||||
Calendar groupMeetingChangeCalendar = (Calendar) meetingCalendar.clone();
|
||||
|
||||
meetingCalendar.add(Calendar.WEEK_OF_YEAR, -3);
|
||||
|
||||
final String groupMeetingDate = this.dateFormatterStandard.format(meetingCalendar.getTime());
|
||||
|
||||
final String disbursalDate = groupMeetingDate; // first meeting date
|
||||
// after group creation
|
||||
|
||||
final String rescheduleSubmittedDate = this.dateFormatterStandard.format(new java.util.Date());
|
||||
|
||||
final String loanType = "jlg";
|
||||
final String rescheduleInterestRate = "28.0";
|
||||
groupMeetingChangeCalendar.add(Calendar.DAY_OF_YEAR, 1);
|
||||
final String groupMeetingNewStartDate = this.dateFormatterStandard.format(groupMeetingChangeCalendar.getTime());
|
||||
// The date
|
||||
// from
|
||||
// which we
|
||||
// start the
|
||||
// new group
|
||||
// meeting
|
||||
// occasion,
|
||||
// this is a
|
||||
// tuesday.
|
||||
groupMeetingChangeCalendar.add(Calendar.WEEK_OF_YEAR, 2);
|
||||
final String rescheduleDate = this.dateFormatterStandard.format(groupMeetingChangeCalendar.getTime());
|
||||
|
||||
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
|
||||
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
|
||||
this.requestSpec.header("Fineract-Platform-TenantId", "default");
|
||||
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||
this.generalResponseSpec = new ResponseSpecBuilder().build();
|
||||
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
this.loanRescheduleRequestHelper = new LoanRescheduleRequestHelper(this.requestSpec, this.responseSpec);
|
||||
System.out.println("---------------------------------CREATING ENTITIES AND JLG LOAN ------------------------------------------");
|
||||
// create all required entities
|
||||
this.createRequiredEntitiesForJLGLoanSync(groupMeetingDate);
|
||||
|
||||
final String loanApplicationJSON = new LoanApplicationTestBuilder().withPrincipal(loanPrincipalAmount).withLoanTermFrequency("24")
|
||||
.withLoanTermFrequencyAsWeeks().withNumberOfRepayments("12").withRepaymentEveryAfter("2")
|
||||
.withRepaymentFrequencyTypeAsMonths().withAmortizationTypeAsEqualInstallments().withInterestCalculationPeriodTypeAsDays()
|
||||
.withInterestRatePerPeriod(interestRatePerPeriod).withRepaymentFrequencyTypeAsWeeks().withSubmittedOnDate(disbursalDate)
|
||||
.withExpectedDisbursementDate(disbursalDate).withLoanType(loanType).withSyncDisbursementWithMeetin()
|
||||
.withCalendarID(this.groupCalendarId.toString())
|
||||
.build(this.clientId.toString(), this.groupId.toString(), this.loanProductId.toString(), null);
|
||||
|
||||
this.loanId = this.loanTransactionHelper.getLoanId(loanApplicationJSON);
|
||||
|
||||
// Test for loan account is created
|
||||
Assert.assertNotNull(this.loanId);
|
||||
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, this.loanId);
|
||||
|
||||
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
|
||||
|
||||
// Test for loan account is created, can be approved
|
||||
this.loanTransactionHelper.approveLoan(disbursalDate, this.loanId);
|
||||
loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, this.loanId);
|
||||
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
|
||||
|
||||
// Test for loan account approved can be disbursed
|
||||
this.loanTransactionHelper.disburseLoan(disbursalDate, this.loanId);
|
||||
loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, this.loanId);
|
||||
LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
|
||||
|
||||
System.out.println("---------------------------------CHANGING GROUP MEETING DATE ------------------------------------------");
|
||||
CalendarHelper.updateMeetingCalendarForGroup(this.requestSpec, this.responseSpec, this.groupId, this.groupCalendarId.toString(),
|
||||
groupMeetingNewStartDate, "2", "2", "2"); // New meeting dates
|
||||
// will be the tuesday
|
||||
// after the
|
||||
// coming
|
||||
// monday
|
||||
|
||||
ArrayList loanRepaymnetSchedule = this.loanTransactionHelper
|
||||
.getLoanRepaymentSchedule(requestSpec, generalResponseSpec, this.loanId);
|
||||
|
||||
ArrayList dueDateLoanSchedule = (ArrayList) ((HashMap) loanRepaymnetSchedule.get(2)).get("dueDate");
|
||||
Calendar dueDateCalendar = Calendar.getInstance();
|
||||
dueDateCalendar.setFirstDayOfWeek(Calendar.MONDAY);
|
||||
dueDateCalendar.set((Integer) dueDateLoanSchedule.get(0), (Integer) dueDateLoanSchedule.get(1) - 1,
|
||||
(Integer) dueDateLoanSchedule.get(2));
|
||||
assertEquals("AFTER MEETING CHANGE DATE THE NEXT REPAYMENT SHOULD BE ON TUESDAY", 3, dueDateCalendar.get(Calendar.DAY_OF_WEEK));
|
||||
|
||||
System.out.println("---------------------------------CREATING LOAN RESCHEDULE REQUEST------------------------------------------");
|
||||
|
||||
String requestJSON = new LoanRescheduleRequestTestBuilder().updateGraceOnInterest("2").updateGraceOnPrincipal("2")
|
||||
.updateNewInterestRate(rescheduleInterestRate).updateRescheduleFromDate(rescheduleDate)
|
||||
.updateSubmittedOnDate(rescheduleSubmittedDate).build(this.loanId.toString());
|
||||
|
||||
this.loanRescheduleRequestId = this.loanRescheduleRequestHelper.createLoanRescheduleRequest(requestJSON);
|
||||
this.loanRescheduleRequestHelper.verifyCreationOfLoanRescheduleRequest(this.loanRescheduleRequestId);
|
||||
|
||||
loanRepaymnetSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(requestSpec, generalResponseSpec, this.loanId);
|
||||
dueDateLoanSchedule = (ArrayList) ((HashMap) loanRepaymnetSchedule.get(2)).get("dueDate");
|
||||
dueDateCalendar.set((Integer) dueDateLoanSchedule.get(0), (Integer) dueDateLoanSchedule.get(1) - 1,
|
||||
(Integer) dueDateLoanSchedule.get(2));
|
||||
assertEquals("AFTER MEETING CHANGE DATE THE NEXT REPAYMENT SHOULD BE ON TUESDAY, EVEN AFTER LOAN RESCHEDULE REQUEST WAS SENT", 3,
|
||||
dueDateCalendar.get(Calendar.DAY_OF_WEEK));
|
||||
|
||||
System.out.println("Successfully created loan reschedule request (ID: " + this.loanRescheduleRequestId + ")");
|
||||
|
||||
System.out.println("-----------------------------APPROVING LOAN RESCHEDULE REQUEST--------------------------");
|
||||
|
||||
requestJSON = new LoanRescheduleRequestTestBuilder().updateSubmittedOnDate(rescheduleSubmittedDate)
|
||||
.getApproveLoanRescheduleRequestJSON();
|
||||
this.loanRescheduleRequestHelper.approveLoanRescheduleRequest(this.loanRescheduleRequestId, requestJSON);
|
||||
|
||||
final HashMap response = (HashMap) this.loanRescheduleRequestHelper.getLoanRescheduleRequest(loanRescheduleRequestId, "statusEnum");
|
||||
assertTrue((Boolean) response.get("approved"));
|
||||
|
||||
loanRepaymnetSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(requestSpec, generalResponseSpec, this.loanId);
|
||||
|
||||
dueDateLoanSchedule = (ArrayList) ((HashMap) loanRepaymnetSchedule.get(2)).get("dueDate");
|
||||
dueDateCalendar.set((Integer) dueDateLoanSchedule.get(0), (Integer) dueDateLoanSchedule.get(1) - 1,
|
||||
(Integer) dueDateLoanSchedule.get(2));
|
||||
assertEquals("AFTER MEETING CHANGE DATE THE NEXT REPAYMENT SHOULD BE ON TUESDAY, EVEN AFTER RESCHEDULE", 3,
|
||||
dueDateCalendar.get(Calendar.DAY_OF_WEEK));
|
||||
System.out.println("Successfully changed group meeting date (CAELNDAR ID: " + this.groupCalendarId
|
||||
+ ") and rescheduled loan (RESCHEDULE ID: " + this.loanRescheduleRequestId + ")");
|
||||
|
||||
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpecForStatusCode403);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testChangeGroupMeetingMaturedOnDate() {
|
||||
System.out
|
||||
.println("---------------------------------STARTING GROUP LOAN MEETING CHANGE DATE EXPECTED MATURED CHANGE------------------------------------------");
|
||||
|
||||
Calendar meetingCalendar = Calendar.getInstance();
|
||||
meetingCalendar.setFirstDayOfWeek(Calendar.MONDAY);
|
||||
meetingCalendar.setTime(new java.util.Date());
|
||||
|
||||
int today = meetingCalendar.get(Calendar.DAY_OF_WEEK);
|
||||
// making sure that the meeting calendar is set for the coming monday.
|
||||
if (today >= Calendar.MONDAY) {
|
||||
meetingCalendar.add(Calendar.DAY_OF_YEAR, +(Calendar.MONDAY - today + 7));
|
||||
} else {
|
||||
meetingCalendar.add(Calendar.DAY_OF_YEAR, +(Calendar.MONDAY - today));
|
||||
}
|
||||
|
||||
Calendar groupMeetingChangeCalendar = (Calendar) meetingCalendar.clone();
|
||||
|
||||
meetingCalendar.add(Calendar.WEEK_OF_YEAR, -3);
|
||||
|
||||
final String groupMeetingDate = this.dateFormatterStandard.format(meetingCalendar.getTime());
|
||||
|
||||
final String disbursalDate = groupMeetingDate; // first meeting date
|
||||
// after group creation
|
||||
|
||||
final String loanType = "jlg";
|
||||
groupMeetingChangeCalendar.add(Calendar.DAY_OF_YEAR, 1);
|
||||
final String groupMeetingNewStartDate = this.dateFormatterStandard.format(groupMeetingChangeCalendar.getTime());
|
||||
// The date
|
||||
// from
|
||||
// which we
|
||||
// start the
|
||||
// new group
|
||||
// meeting
|
||||
// occasion,
|
||||
// this is a
|
||||
// tuesday.
|
||||
|
||||
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
|
||||
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
|
||||
this.requestSpec.header("Fineract-Platform-TenantId", "default");
|
||||
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||
this.generalResponseSpec = new ResponseSpecBuilder().build();
|
||||
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
this.loanRescheduleRequestHelper = new LoanRescheduleRequestHelper(this.requestSpec, this.responseSpec);
|
||||
System.out.println("---------------------------------CREATING ENTITIES AND JLG LOAN ------------------------------------------");
|
||||
// create all required entities
|
||||
this.createRequiredEntitiesForJLGLoanSync(groupMeetingDate);
|
||||
|
||||
final String loanApplicationJSON = new LoanApplicationTestBuilder().withPrincipal(loanPrincipalAmount).withLoanTermFrequency("24")
|
||||
.withLoanTermFrequencyAsWeeks().withNumberOfRepayments("12").withRepaymentEveryAfter("2")
|
||||
.withRepaymentFrequencyTypeAsMonths().withAmortizationTypeAsEqualInstallments().withInterestCalculationPeriodTypeAsDays()
|
||||
.withInterestRatePerPeriod(interestRatePerPeriod).withRepaymentFrequencyTypeAsWeeks().withSubmittedOnDate(disbursalDate)
|
||||
.withExpectedDisbursementDate(disbursalDate).withLoanType(loanType).withSyncDisbursementWithMeetin()
|
||||
.withCalendarID(this.groupCalendarId.toString())
|
||||
.build(this.clientId.toString(), this.groupId.toString(), this.loanProductId.toString(), null);
|
||||
|
||||
this.loanId = this.loanTransactionHelper.getLoanId(loanApplicationJSON);
|
||||
|
||||
// Test for loan account is created
|
||||
Assert.assertNotNull(this.loanId);
|
||||
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, this.loanId);
|
||||
|
||||
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
|
||||
|
||||
// Test for loan account is created, can be approved
|
||||
this.loanTransactionHelper.approveLoan(disbursalDate, this.loanId);
|
||||
loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, this.loanId);
|
||||
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
|
||||
|
||||
// Test for loan account approved can be disbursed
|
||||
this.loanTransactionHelper.disburseLoan(disbursalDate, this.loanId);
|
||||
loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, this.loanId);
|
||||
LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
|
||||
|
||||
System.out.println("---------------------------------CHANGING GROUP MEETING DATE ------------------------------------------");
|
||||
CalendarHelper.updateMeetingCalendarForGroup(this.requestSpec, this.responseSpec, this.groupId, this.groupCalendarId.toString(),
|
||||
groupMeetingNewStartDate, "2", "2", "2"); // New meeting dates
|
||||
// will be the tuesday
|
||||
// after the
|
||||
// coming
|
||||
// monday
|
||||
|
||||
Calendar expectedMaturityCalendar = Calendar.getInstance();
|
||||
expectedMaturityCalendar.setFirstDayOfWeek(Calendar.MONDAY);
|
||||
ArrayList expectedMaturityDate = ((ArrayList) ((HashMap) this.loanTransactionHelper.getLoanDetail(requestSpec, generalResponseSpec,
|
||||
this.loanId, "timeline")).get("expectedMaturityDate"));
|
||||
|
||||
expectedMaturityCalendar.set((Integer) expectedMaturityDate.get(0), (Integer) expectedMaturityDate.get(1) - 1,
|
||||
(Integer) expectedMaturityDate.get(2));
|
||||
|
||||
assertEquals("AFTER MEETING CHANGE DATE THE EXPECTED MATURITY SHOULD BE ON TUESDAY", 3,
|
||||
expectedMaturityCalendar.get(Calendar.DAY_OF_WEEK));
|
||||
|
||||
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpecForStatusCode403);
|
||||
}
|
||||
|
||||
/**
|
||||
* entities for jlg loan
|
||||
**/
|
||||
private void createRequiredEntitiesForJLGLoanSync(final String groupActivationDate) {
|
||||
this.createGroupEntityWithCalendar("2", "2", "1", groupActivationDate);// frequency=2:Weekly
|
||||
// , interval=2:
|
||||
// Every two weeks ,
|
||||
// repeatsOnDay=1:Monday
|
||||
// groupActivationDate is decided by the current date
|
||||
this.createClientEntity();
|
||||
this.associateClientToGroup(this.groupId, this.clientId);
|
||||
this.createLoanProductEntity();
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Associate client to the group
|
||||
*/
|
||||
|
||||
private void associateClientToGroup(final Integer groupId, final Integer clientId) {
|
||||
GroupHelper.associateClient(this.requestSpec, this.responseSpec, groupId.toString(), clientId.toString());
|
||||
GroupHelper.verifyGroupMembers(this.requestSpec, this.responseSpec, groupId, clientId);
|
||||
}
|
||||
|
||||
private void createGroupEntityWithCalendar(final String frequency, final String interval, final String repeatsOnDay,
|
||||
final String groupActivationDate) {
|
||||
this.groupId = GroupHelper.createGroup(this.requestSpec, this.responseSpec, groupActivationDate);
|
||||
GroupHelper.verifyGroupCreatedOnServer(this.requestSpec, this.responseSpec, this.groupId);
|
||||
|
||||
final String startDate = groupActivationDate;
|
||||
|
||||
this.setGroupCalendarId(CalendarHelper.createMeetingCalendarForGroup(this.requestSpec, this.responseSpec, this.groupId, startDate,
|
||||
frequency, interval, repeatsOnDay));
|
||||
}
|
||||
|
||||
/**
|
||||
* create a new client
|
||||
**/
|
||||
private void createClientEntity() {
|
||||
this.clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
ClientHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, this.clientId);
|
||||
}
|
||||
|
||||
/**
|
||||
* create a new loan product
|
||||
**/
|
||||
private void createLoanProductEntity() {
|
||||
final String loanProductJSON = new LoanProductTestBuilder().withPrincipal(loanPrincipalAmount)
|
||||
.withNumberOfRepayments(numberOfRepayments).withinterestRatePerPeriod(interestRatePerPeriod)
|
||||
.withInterestRateFrequencyTypeAsYear().build(null);
|
||||
this.loanProductId = this.loanTransactionHelper.getLoanProductId(loanProductJSON);
|
||||
}
|
||||
|
||||
public void setGroupCalendarId(Integer groupCalendarId) {
|
||||
this.groupCalendarId = groupCalendarId;
|
||||
}
|
||||
}
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.ExternalServicesConfigurationHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
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;
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked", "static-access" })
|
||||
public class ExternalServicesConfigurationTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private ExternalServicesConfigurationHelper externalServicesConfigurationHelper;
|
||||
private ResponseSpecification httpStatusForidden;
|
||||
|
||||
@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.httpStatusForidden = new ResponseSpecBuilder().expectStatusCode(403).build();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExternalServicesConfiguration() {
|
||||
this.externalServicesConfigurationHelper = new ExternalServicesConfigurationHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
// Checking for S3
|
||||
String configName = "s3_access_key";
|
||||
ArrayList<HashMap> externalServicesConfig = this.externalServicesConfigurationHelper
|
||||
.getExternalServicesConfigurationByServiceName(requestSpec, responseSpec, "S3");
|
||||
Assert.assertNotNull(externalServicesConfig);
|
||||
for (Integer configIndex = 0; configIndex < (externalServicesConfig.size()); configIndex++) {
|
||||
String name = (String) externalServicesConfig.get(configIndex).get("name");
|
||||
String value = null;
|
||||
if (name.equals(configName)) {
|
||||
value = (String) externalServicesConfig.get(configIndex).get("value");
|
||||
if(value == null){
|
||||
value = "testnull";
|
||||
}
|
||||
String newValue = "test";
|
||||
System.out.println(name + ":" + value);
|
||||
HashMap arrayListValue = this.externalServicesConfigurationHelper.updateValueForExternaServicesConfiguration(requestSpec,
|
||||
responseSpec, "S3", name, newValue);
|
||||
Assert.assertNotNull(arrayListValue.get("value"));
|
||||
Assert.assertEquals(arrayListValue.get("value"), newValue);
|
||||
HashMap arrayListValue1 = this.externalServicesConfigurationHelper.updateValueForExternaServicesConfiguration(requestSpec,
|
||||
responseSpec, "S3", name, value);
|
||||
Assert.assertNotNull(arrayListValue1.get("value"));
|
||||
Assert.assertEquals(arrayListValue1.get("value"), value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Checking for SMTP:
|
||||
|
||||
configName = "username";
|
||||
externalServicesConfig = this.externalServicesConfigurationHelper.getExternalServicesConfigurationByServiceName(requestSpec,
|
||||
responseSpec, "SMTP");
|
||||
Assert.assertNotNull(externalServicesConfig);
|
||||
for (Integer configIndex = 0; configIndex < (externalServicesConfig.size()); configIndex++) {
|
||||
String name = (String) externalServicesConfig.get(configIndex).get("name");
|
||||
String value = null;
|
||||
if (name.equals(configName)) {
|
||||
value = (String) externalServicesConfig.get(configIndex).get("value");
|
||||
if(value == null){
|
||||
value = "testnull";
|
||||
}
|
||||
String newValue = "test";
|
||||
System.out.println(name + ":" + value);
|
||||
HashMap arrayListValue = this.externalServicesConfigurationHelper.updateValueForExternaServicesConfiguration(requestSpec,
|
||||
responseSpec, "SMTP", name, newValue);
|
||||
Assert.assertNotNull(arrayListValue.get("value"));
|
||||
Assert.assertEquals(arrayListValue.get("value"), newValue);
|
||||
HashMap arrayListValue1 = this.externalServicesConfigurationHelper.updateValueForExternaServicesConfiguration(requestSpec,
|
||||
responseSpec, "SMTP", name, value);
|
||||
Assert.assertNotNull(arrayListValue1.get("value"));
|
||||
Assert.assertEquals(arrayListValue1.get("value"), value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+164
@@ -0,0 +1,164 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.fineract.accounting.common.AccountingConstants.FINANCIAL_ACTIVITY;
|
||||
import org.apache.fineract.accounting.financialactivityaccount.exception.DuplicateFinancialActivityAccountFoundException;
|
||||
import org.apache.fineract.accounting.financialactivityaccount.exception.FinancialActivityAccountInvalidException;
|
||||
import org.apache.fineract.integrationtests.common.CommonConstants;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.accounting.Account;
|
||||
import org.apache.fineract.integrationtests.common.accounting.AccountHelper;
|
||||
import org.apache.fineract.integrationtests.common.accounting.FinancialActivityAccountHelper;
|
||||
import org.junit.Assert;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
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;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class FinancialActivityAccountsTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private ResponseSpecification responseSpecForValidationError;
|
||||
private ResponseSpecification responseSpecForDomainRuleViolation;
|
||||
private ResponseSpecification responseSpecForResourceNotFoundError;
|
||||
private RequestSpecification requestSpec;
|
||||
private AccountHelper accountHelper;
|
||||
private FinancialActivityAccountHelper financialActivityAccountHelper;
|
||||
private final Integer assetTransferFinancialActivityId = FINANCIAL_ACTIVITY.ASSET_TRANSFER.getValue();
|
||||
public static final Integer liabilityTransferFinancialActivityId = FINANCIAL_ACTIVITY.LIABILITY_TRANSFER.getValue();
|
||||
|
||||
@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.responseSpecForValidationError = new ResponseSpecBuilder().expectStatusCode(400).build();
|
||||
this.responseSpecForDomainRuleViolation = new ResponseSpecBuilder().expectStatusCode(403).build();
|
||||
this.responseSpecForResourceNotFoundError = new ResponseSpecBuilder().expectStatusCode(404).build();
|
||||
this.accountHelper = new AccountHelper(this.requestSpec, this.responseSpec);
|
||||
this.financialActivityAccountHelper = new FinancialActivityAccountHelper(this.requestSpec);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testFinancialActivityAccounts() {
|
||||
|
||||
/** Create a Liability and an Asset Transfer Account **/
|
||||
Account liabilityTransferAccount = accountHelper.createLiabilityAccount();
|
||||
Account assetTransferAccount = accountHelper.createAssetAccount();
|
||||
Assert.assertNotNull(assetTransferAccount);
|
||||
Assert.assertNotNull(liabilityTransferAccount);
|
||||
|
||||
/*** Create A Financial Activity to Account Mapping **/
|
||||
Integer financialActivityAccountId = (Integer) financialActivityAccountHelper.createFinancialActivityAccount(
|
||||
liabilityTransferFinancialActivityId, liabilityTransferAccount.getAccountID(), responseSpec,
|
||||
CommonConstants.RESPONSE_RESOURCE_ID);
|
||||
Assert.assertNotNull(financialActivityAccountId);
|
||||
|
||||
/***
|
||||
* Fetch Created Financial Activity to Account Mapping and validate
|
||||
* created values
|
||||
**/
|
||||
assertFinancialActivityAccountCreation(financialActivityAccountId, liabilityTransferFinancialActivityId, liabilityTransferAccount);
|
||||
|
||||
/**
|
||||
* Update Existing Financial Activity to Account Mapping and assert
|
||||
* changes
|
||||
**/
|
||||
Account newLiabilityTransferAccount = accountHelper.createLiabilityAccount();
|
||||
Assert.assertNotNull(newLiabilityTransferAccount);
|
||||
|
||||
HashMap changes = (HashMap) financialActivityAccountHelper.updateFinancialActivityAccount(financialActivityAccountId,
|
||||
liabilityTransferFinancialActivityId, newLiabilityTransferAccount.getAccountID(), responseSpec,
|
||||
CommonConstants.RESPONSE_CHANGES);
|
||||
Assert.assertEquals(newLiabilityTransferAccount.getAccountID(), changes.get("glAccountId"));
|
||||
|
||||
/** Validate update works correctly **/
|
||||
assertFinancialActivityAccountCreation(financialActivityAccountId, liabilityTransferFinancialActivityId,
|
||||
newLiabilityTransferAccount);
|
||||
|
||||
/** Update with Invalid Financial Activity should fail **/
|
||||
List<HashMap> invalidFinancialActivityUpdateError = (List<HashMap>) financialActivityAccountHelper.updateFinancialActivityAccount(
|
||||
financialActivityAccountId, 232, newLiabilityTransferAccount.getAccountID(), responseSpecForValidationError,
|
||||
CommonConstants.RESPONSE_ERROR);
|
||||
assertEquals("validation.msg.financialactivityaccount.financialActivityId.is.not.one.of.expected.enumerations",
|
||||
invalidFinancialActivityUpdateError.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
/** Creating Duplicate Financial Activity should fail **/
|
||||
List<HashMap> duplicateFinancialActivityAccountError = (List<HashMap>) financialActivityAccountHelper
|
||||
.createFinancialActivityAccount(liabilityTransferFinancialActivityId, liabilityTransferAccount.getAccountID(),
|
||||
responseSpecForDomainRuleViolation, CommonConstants.RESPONSE_ERROR);
|
||||
assertEquals(DuplicateFinancialActivityAccountFoundException.getErrorcode(),
|
||||
duplicateFinancialActivityAccountError.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
/**
|
||||
* Associating incorrect GL account types with a financial activity
|
||||
* should fail
|
||||
**/
|
||||
List<HashMap> invalidFinancialActivityAccountError = (List<HashMap>) financialActivityAccountHelper.updateFinancialActivityAccount(
|
||||
financialActivityAccountId, assetTransferFinancialActivityId, newLiabilityTransferAccount.getAccountID(),
|
||||
responseSpecForDomainRuleViolation, CommonConstants.RESPONSE_ERROR);
|
||||
assertEquals(FinancialActivityAccountInvalidException.getErrorcode(),
|
||||
invalidFinancialActivityAccountError.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
/** Should be able to delete a Financial Activity to Account Mapping **/
|
||||
Integer deletedFinancialActivityAccountId = financialActivityAccountHelper.deleteFinancialActivityAccount(
|
||||
financialActivityAccountId, responseSpec, CommonConstants.RESPONSE_RESOURCE_ID);
|
||||
Assert.assertNotNull(deletedFinancialActivityAccountId);
|
||||
Assert.assertEquals(financialActivityAccountId, deletedFinancialActivityAccountId);
|
||||
|
||||
/*** Trying to fetch a Deleted Account Mapping should give me a 404 **/
|
||||
financialActivityAccountHelper.getFinancialActivityAccount(deletedFinancialActivityAccountId, responseSpecForResourceNotFoundError);
|
||||
}
|
||||
|
||||
private void assertFinancialActivityAccountCreation(Integer financialActivityAccountId, Integer financialActivityId, Account glAccount) {
|
||||
HashMap mappingDetails = financialActivityAccountHelper.getFinancialActivityAccount(financialActivityAccountId, responseSpec);
|
||||
Assert.assertEquals(financialActivityId, ((HashMap) mappingDetails.get("financialActivityData")).get("id"));
|
||||
Assert.assertEquals(glAccount.getAccountID(), ((HashMap) mappingDetails.get("glAccountData")).get("id"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the Financial activities
|
||||
*/
|
||||
@After
|
||||
public void tearDown() {
|
||||
List<HashMap> financialActivities = this.financialActivityAccountHelper.getAllFinancialActivityAccounts(this.responseSpec);
|
||||
for (HashMap financialActivity : financialActivities) {
|
||||
Integer financialActivityAccountId = (Integer) financialActivity.get("id");
|
||||
Integer deletedFinancialActivityAccountId = this.financialActivityAccountHelper.deleteFinancialActivityAccount(
|
||||
financialActivityAccountId, this.responseSpec, CommonConstants.RESPONSE_RESOURCE_ID);
|
||||
Assert.assertNotNull(deletedFinancialActivityAccountId);
|
||||
Assert.assertEquals(financialActivityAccountId, deletedFinancialActivityAccountId);
|
||||
}
|
||||
}
|
||||
}
|
||||
+2079
File diff suppressed because it is too large
Load Diff
+154
@@ -0,0 +1,154 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||
import org.apache.fineract.integrationtests.common.CommonConstants;
|
||||
import org.apache.fineract.integrationtests.common.GlobalConfigurationHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.savings.SavingsAccountHelper;
|
||||
import org.apache.fineract.integrationtests.common.savings.SavingsProductHelper;
|
||||
import org.apache.fineract.integrationtests.common.savings.SavingsStatusChecker;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
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;
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unused", "unchecked" })
|
||||
public class FlexibleSavingsInterestPostingIntegrationTest {
|
||||
|
||||
public static final String ACCOUNT_TYPE_INDIVIDUAL = "INDIVIDUAL";
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private SavingsProductHelper savingsProductHelper;
|
||||
private SavingsAccountHelper savingsAccountHelper;
|
||||
|
||||
@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.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
|
||||
this.savingsProductHelper = new SavingsProductHelper();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSavingsInterestPostingAtPeriodEnd() {
|
||||
// client activation, savings activation and 1st transaction date
|
||||
final String startDate = "01 December 2013";
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, startDate);
|
||||
Assert.assertNotNull(clientID);
|
||||
|
||||
// Configuring global config flags
|
||||
configureInterestPosting(true, 4);
|
||||
|
||||
final Integer savingsId = createSavingsAccount(clientID, startDate);
|
||||
|
||||
Integer depositTransactionId = (Integer) this.savingsAccountHelper.depositToSavingsAccount(savingsId, "1000", startDate,
|
||||
CommonConstants.RESPONSE_RESOURCE_ID);
|
||||
|
||||
/***
|
||||
* Perform Post interest transaction and verify the posted transaction
|
||||
* date
|
||||
*/
|
||||
this.savingsAccountHelper.postInterestForSavings(savingsId);
|
||||
HashMap accountDetails = this.savingsAccountHelper.getSavingsDetails(savingsId);
|
||||
ArrayList<HashMap<String, Object>> transactions = (ArrayList<HashMap<String, Object>>) accountDetails.get("transactions");
|
||||
HashMap<String, Object> interestPostingTransaction = transactions.get(transactions.size() - 2);
|
||||
for (Entry<String, Object> entry : interestPostingTransaction.entrySet())
|
||||
System.out.println(entry.getKey() + "-" + entry.getValue().toString());
|
||||
// 1st Dec 13 to 31st March 14 - 365 days, daily compounding using daily
|
||||
// balance
|
||||
// 33.7016 obtained from formula in excel provided by Subramanya
|
||||
assertEquals("Equality check for interest posted amount", "33.7016", interestPostingTransaction.get("amount").toString());
|
||||
assertEquals("Date check for Interest Posting transaction", "[2014, 3, 31]", interestPostingTransaction.get("date").toString());
|
||||
|
||||
}
|
||||
|
||||
private Integer createSavingsAccount(final Integer clientID, final String startDate) {
|
||||
final Integer savingsProductID = createSavingsProduct();
|
||||
Assert.assertNotNull(savingsProductID);
|
||||
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplicationOnDate(clientID, savingsProductID,
|
||||
ACCOUNT_TYPE_INDIVIDUAL, startDate);
|
||||
Assert.assertNotNull(savingsId);
|
||||
HashMap savingsStatusHashMap = this.savingsAccountHelper.approveSavingsOnDate(savingsId, startDate);
|
||||
SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap);
|
||||
savingsStatusHashMap = this.savingsAccountHelper.activateSavingsAccount(savingsId, startDate);
|
||||
SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap);
|
||||
return savingsId;
|
||||
}
|
||||
|
||||
private void configureInterestPosting(final Boolean periodEndEnable, final Integer financialYearBeginningMonth) {
|
||||
final ArrayList<HashMap> globalConfig = GlobalConfigurationHelper.getAllGlobalConfigurations(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(globalConfig);
|
||||
|
||||
// Updating flag for interest posting at period end
|
||||
Integer periodEndConfigId = (Integer) globalConfig.get(10).get("id");
|
||||
Assert.assertNotNull(periodEndConfigId);
|
||||
|
||||
HashMap periodEndConfigData = GlobalConfigurationHelper.getGlobalConfigurationById(this.requestSpec, this.responseSpec,
|
||||
periodEndConfigId.toString());
|
||||
Assert.assertNotNull(periodEndConfigData);
|
||||
|
||||
Boolean enabled = (Boolean) globalConfig.get(10).get("enabled");
|
||||
|
||||
if (enabled != periodEndEnable)
|
||||
periodEndConfigId = GlobalConfigurationHelper.updateEnabledFlagForGlobalConfiguration(this.requestSpec, this.responseSpec,
|
||||
periodEndConfigId.toString(), periodEndEnable);
|
||||
|
||||
// Updating value for financial year beginning month
|
||||
Integer financialYearBeginningConfigId = (Integer) globalConfig.get(11).get("id");
|
||||
Assert.assertNotNull(financialYearBeginningConfigId);
|
||||
|
||||
HashMap financialYearBeginningConfigData = GlobalConfigurationHelper.getGlobalConfigurationById(this.requestSpec,
|
||||
this.responseSpec, financialYearBeginningConfigId.toString());
|
||||
Assert.assertNotNull(financialYearBeginningConfigData);
|
||||
|
||||
financialYearBeginningConfigId = GlobalConfigurationHelper.updateValueForGlobalConfiguration(this.requestSpec, this.responseSpec,
|
||||
financialYearBeginningConfigId.toString(), financialYearBeginningMonth.toString());
|
||||
Assert.assertNotNull(financialYearBeginningConfigId);
|
||||
}
|
||||
|
||||
private Integer createSavingsProduct() {
|
||||
final String savingsProductJSON = this.savingsProductHelper.withInterestCompoundingPeriodTypeAsDaily()
|
||||
.withInterestPostingPeriodTypeAsAnnual().withInterestCalculationPeriodTypeAsDailyBalance().build();
|
||||
return SavingsProductHelper.createSavingsProduct(savingsProductJSON, requestSpec, responseSpec);
|
||||
}
|
||||
|
||||
// Reset configuration fields
|
||||
@After
|
||||
public void tearDown() {
|
||||
configureInterestPosting(false, 1);
|
||||
}
|
||||
|
||||
}
|
||||
+347
@@ -0,0 +1,347 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.funds.FundsHelper;
|
||||
import org.apache.fineract.integrationtests.common.funds.FundsResourceHandler;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
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.*;
|
||||
|
||||
/**
|
||||
* Funds Integration Test for checking Funds Application.
|
||||
*/
|
||||
public class FundsIntegrationTest {
|
||||
|
||||
private ResponseSpecification statusOkResponseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
Utils.initializeRESTAssured();
|
||||
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
|
||||
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
|
||||
this.statusOkResponseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateFund() {
|
||||
FundsHelper fh = FundsHelper
|
||||
.create(Utils.randomNameGenerator("", 10))
|
||||
.externalId(Utils.randomNameGenerator("fund-", 5))
|
||||
.build();
|
||||
String jsonData = fh.toJSON();
|
||||
|
||||
final Long fundID = createFund(jsonData, this.requestSpec, this.statusOkResponseSpec);
|
||||
Assert.assertNotNull(fundID);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateFundWithEmptyName() {
|
||||
FundsHelper fh = FundsHelper
|
||||
.create(null)
|
||||
.externalId(Utils.randomNameGenerator("fund-", 5))
|
||||
.build();
|
||||
String jsonData = fh.toJSON();
|
||||
|
||||
ResponseSpecification responseSpec = new ResponseSpecBuilder().expectStatusCode(400).build();
|
||||
final Long fundID = createFund(jsonData, this.requestSpec, responseSpec);
|
||||
Assert.assertNull(fundID);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateFundWithEmptyExternalId() {
|
||||
FundsHelper fh = FundsHelper
|
||||
.create(Utils.randomNameGenerator("", 10))
|
||||
.externalId(null)
|
||||
.build();
|
||||
String jsonData = fh.toJSON();
|
||||
|
||||
final Long fundID = createFund(jsonData, this.requestSpec, this.statusOkResponseSpec);
|
||||
Assert.assertNotNull(fundID);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateFundWithDuplicateName() {
|
||||
FundsHelper fh = FundsHelper
|
||||
.create(Utils.randomNameGenerator("", 10))
|
||||
.externalId(Utils.randomNameGenerator("fund-", 5))
|
||||
.build();
|
||||
String jsonData = fh.toJSON();
|
||||
|
||||
final Long fundID = createFund(jsonData, this.requestSpec, this.statusOkResponseSpec);
|
||||
Assert.assertNotNull(fundID);
|
||||
|
||||
FundsHelper fh2 = FundsHelper
|
||||
.create(fh.getName())
|
||||
.externalId(Utils.randomNameGenerator("fund-", 5))
|
||||
.build();
|
||||
jsonData = fh2.toJSON();
|
||||
|
||||
ResponseSpecification responseSpec = new ResponseSpecBuilder().expectStatusCode(403).build();
|
||||
final Long fundID2 = createFund(jsonData, this.requestSpec, responseSpec);
|
||||
Assert.assertNull(fundID2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateFundWithDuplicateExternalId() {
|
||||
FundsHelper fh = FundsHelper
|
||||
.create(Utils.randomNameGenerator("", 10))
|
||||
.externalId(Utils.randomNameGenerator("fund-", 5))
|
||||
.build();
|
||||
String jsonData = fh.toJSON();
|
||||
|
||||
final Long fundID = createFund(jsonData, this.requestSpec, this.statusOkResponseSpec);
|
||||
Assert.assertNotNull(fundID);
|
||||
|
||||
FundsHelper fh2 = FundsHelper
|
||||
.create(Utils.randomNameGenerator("", 10))
|
||||
.externalId(fh.getExternalId())
|
||||
.build();
|
||||
jsonData = fh2.toJSON();
|
||||
|
||||
ResponseSpecification responseSpec = new ResponseSpecBuilder().expectStatusCode(403).build();
|
||||
final Long fundID2 = createFund(jsonData, this.requestSpec, responseSpec);
|
||||
Assert.assertNull(fundID2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateFundWithInvalidName() {
|
||||
FundsHelper fh = FundsHelper
|
||||
.create(Utils.randomNameGenerator("", 120))
|
||||
.externalId(Utils.randomNameGenerator("fund-", 5))
|
||||
.build();
|
||||
String jsonData = fh.toJSON();
|
||||
|
||||
ResponseSpecification responseSpec = new ResponseSpecBuilder().expectStatusCode(400).build();
|
||||
final Long fundID = createFund(jsonData, this.requestSpec, responseSpec);
|
||||
Assert.assertNull(fundID);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateFundWithInvalidExternalId() {
|
||||
FundsHelper fh = FundsHelper
|
||||
.create(Utils.randomNameGenerator("", 10))
|
||||
.externalId(Utils.randomNameGenerator("fund-", 120))
|
||||
.build();
|
||||
String jsonData = fh.toJSON();
|
||||
|
||||
ResponseSpecification responseSpec = new ResponseSpecBuilder().expectStatusCode(400).build();
|
||||
final Long fundID = createFund(jsonData, this.requestSpec, responseSpec);
|
||||
Assert.assertNull(fundID);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRetrieveFund() {
|
||||
FundsHelper fh = FundsHelper
|
||||
.create(Utils.randomNameGenerator("", 10))
|
||||
.externalId(Utils.randomNameGenerator("fund-", 5))
|
||||
.build();
|
||||
String jsonData = fh.toJSON();
|
||||
|
||||
final Long fundID = createFund(jsonData, this.requestSpec, this.statusOkResponseSpec);
|
||||
Assert.assertNotNull(fundID);
|
||||
|
||||
jsonData = FundsResourceHandler.retrieveFund(fundID, this.requestSpec, this.statusOkResponseSpec);
|
||||
FundsHelper fh2 = FundsHelper.fromJSON(jsonData);
|
||||
|
||||
assertEquals(fh.getName(), fh2.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRetrieveAllFunds() {
|
||||
FundsHelper fh = FundsHelper
|
||||
.create(Utils.randomNameGenerator("", 10))
|
||||
.externalId(Utils.randomNameGenerator("fund-", 5))
|
||||
.build();
|
||||
String jsonData = fh.toJSON();
|
||||
|
||||
final Long fundID = createFund(jsonData, this.requestSpec, this.statusOkResponseSpec);
|
||||
Assert.assertNotNull(fundID);
|
||||
|
||||
List<FundsHelper> fhList = FundsResourceHandler.retrieveAllFunds(this.requestSpec, this.statusOkResponseSpec);
|
||||
|
||||
Assert.assertNotNull(fhList);
|
||||
Assert.assertThat(fhList.size(), greaterThanOrEqualTo(1));
|
||||
Assert.assertThat(fhList, hasItem(fh));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRetrieveUnknownFund() {
|
||||
ResponseSpecification responseSpec = new ResponseSpecBuilder().expectStatusCode(404).build();
|
||||
String jsonData = FundsResourceHandler.retrieveFund(Long.MAX_VALUE, this.requestSpec, responseSpec);
|
||||
HashMap<String, String> map = new Gson().fromJson(jsonData, HashMap.class);
|
||||
assertEquals(map.get("userMessageGlobalisationCode"), "error.msg.resource.not.found");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateFund() {
|
||||
FundsHelper fh = FundsHelper
|
||||
.create(Utils.randomNameGenerator("", 10))
|
||||
.externalId(Utils.randomNameGenerator("fund-", 5))
|
||||
.build();
|
||||
String jsonData = fh.toJSON();
|
||||
|
||||
final Long fundID = createFund(jsonData, this.requestSpec, this.statusOkResponseSpec);
|
||||
Assert.assertNotNull(fundID);
|
||||
|
||||
String newName = Utils.randomNameGenerator("", 10);
|
||||
String newExternalId = Utils.randomNameGenerator("fund-", 5);
|
||||
FundsHelper fh2 = FundsResourceHandler.updateFund(fundID, newName, newExternalId, this.requestSpec, this.statusOkResponseSpec);
|
||||
|
||||
Assert.assertEquals(newName, fh2.getName());
|
||||
Assert.assertEquals(newExternalId, fh2.getExternalId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateUnknownFund() {
|
||||
String newName = Utils.randomNameGenerator("", 10);
|
||||
String newExternalId = Utils.randomNameGenerator("fund-", 5);
|
||||
ResponseSpecification responseSpec = new ResponseSpecBuilder().expectStatusCode(404).build();
|
||||
FundsHelper fh = FundsResourceHandler.updateFund(Long.MAX_VALUE, newName, newExternalId, this.requestSpec,
|
||||
responseSpec);
|
||||
Assert.assertNull(fh);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateFundWithInvalidNewName() {
|
||||
FundsHelper fh = FundsHelper
|
||||
.create(Utils.randomNameGenerator("", 10))
|
||||
.externalId(Utils.randomNameGenerator("fund-", 5))
|
||||
.build();
|
||||
String jsonData = fh.toJSON();
|
||||
|
||||
final Long fundID = createFund(jsonData, this.requestSpec, this.statusOkResponseSpec);
|
||||
Assert.assertNotNull(fundID);
|
||||
|
||||
String newName = Utils.randomNameGenerator("", 120);
|
||||
String newExternalId = Utils.randomNameGenerator("fund-", 5);
|
||||
ResponseSpecification responseSpec = new ResponseSpecBuilder().expectStatusCode(400).build();
|
||||
FundsHelper fh2 = FundsResourceHandler.updateFund(fundID, newName, newExternalId, this.requestSpec,
|
||||
responseSpec);
|
||||
|
||||
Assert.assertNull(fh2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateFundWithNewExternalId() {
|
||||
FundsHelper fh = FundsHelper
|
||||
.create(Utils.randomNameGenerator("", 10))
|
||||
.externalId(Utils.randomNameGenerator("fund-", 5))
|
||||
.build();
|
||||
String jsonData = fh.toJSON();
|
||||
|
||||
final Long fundID = createFund(jsonData, this.requestSpec, this.statusOkResponseSpec);
|
||||
Assert.assertNotNull(fundID);
|
||||
|
||||
String newExternalId = Utils.randomNameGenerator("fund-", 5);
|
||||
FundsHelper fh2 = FundsResourceHandler.updateFund(fundID, null, newExternalId, this.requestSpec, this.statusOkResponseSpec);
|
||||
|
||||
Assert.assertEquals(newExternalId, fh2.getExternalId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateFundWithInvalidNewExternalId() {
|
||||
FundsHelper fh = FundsHelper
|
||||
.create(Utils.randomNameGenerator("", 10))
|
||||
.externalId(Utils.randomNameGenerator("fund-", 5))
|
||||
.build();
|
||||
String jsonData = fh.toJSON();
|
||||
|
||||
final Long fundID = createFund(jsonData, this.requestSpec, this.statusOkResponseSpec);
|
||||
Assert.assertNotNull(fundID);
|
||||
|
||||
String newName = Utils.randomNameGenerator("", 10);
|
||||
String newExternalId = Utils.randomNameGenerator("fund-", 120);
|
||||
ResponseSpecification responseSpec = new ResponseSpecBuilder().expectStatusCode(400).build();
|
||||
FundsHelper fh2 = FundsResourceHandler.updateFund(fundID, newName, newExternalId, this.requestSpec,
|
||||
responseSpec);
|
||||
|
||||
Assert.assertNull(fh2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateFundWithNewName() {
|
||||
FundsHelper fh = FundsHelper
|
||||
.create(Utils.randomNameGenerator("", 10))
|
||||
.externalId(Utils.randomNameGenerator("fund-", 5))
|
||||
.build();
|
||||
String jsonData = fh.toJSON();
|
||||
|
||||
final Long fundID = createFund(jsonData, this.requestSpec, this.statusOkResponseSpec);
|
||||
Assert.assertNotNull(fundID);
|
||||
|
||||
String newName = Utils.randomNameGenerator("", 10);
|
||||
FundsHelper fh2 = FundsResourceHandler.updateFund(fundID, newName, null, this.requestSpec, this.statusOkResponseSpec);
|
||||
|
||||
Assert.assertEquals(newName, fh2.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateFundWithEmptyParams() {
|
||||
FundsHelper fh = FundsHelper
|
||||
.create(Utils.randomNameGenerator("", 10))
|
||||
.externalId(Utils.randomNameGenerator("fund-", 5))
|
||||
.build();
|
||||
String jsonData = fh.toJSON();
|
||||
|
||||
final Long fundID = createFund(jsonData, this.requestSpec, this.statusOkResponseSpec);
|
||||
Assert.assertNotNull(fundID);
|
||||
|
||||
FundsHelper fh2 = FundsResourceHandler.updateFund(fundID, null, null, this.requestSpec, this.statusOkResponseSpec);
|
||||
|
||||
Assert.assertNull(fh2.getName());
|
||||
Assert.assertNull(fh2.getExternalId());
|
||||
|
||||
// assert that there was no change in
|
||||
// the name and external ID of the fund
|
||||
jsonData = FundsResourceHandler.retrieveFund(fundID, this.requestSpec, this.statusOkResponseSpec);
|
||||
FundsHelper fh3 = new Gson().fromJson(jsonData, FundsHelper.class);
|
||||
|
||||
Assert.assertEquals(fh.getName(), fh3.getName());
|
||||
Assert.assertEquals(fh.getExternalId(), fh3.getExternalId());
|
||||
}
|
||||
|
||||
private Long createFund(final String fundJSON,
|
||||
final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec) {
|
||||
String fundId = String.valueOf(FundsResourceHandler.createFund(fundJSON, requestSpec, responseSpec));
|
||||
if (fundId.equals("null")) {
|
||||
// Invalid JSON data parameters
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Long(fundId);
|
||||
}
|
||||
|
||||
}
|
||||
+221
@@ -0,0 +1,221 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.CommonConstants;
|
||||
import org.apache.fineract.integrationtests.common.GlobalConfigurationHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
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;
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked", "static-access" })
|
||||
public class GlobalConfigurationTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private GlobalConfigurationHelper globalConfigurationHelper;
|
||||
private ResponseSpecification httpStatusForidden;
|
||||
|
||||
@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.httpStatusForidden = new ResponseSpecBuilder().expectStatusCode(403).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGlobalConfigurations() {
|
||||
this.globalConfigurationHelper = new GlobalConfigurationHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
// Retrieving All Global Configuration details
|
||||
final ArrayList<HashMap> globalConfig = this.globalConfigurationHelper.getAllGlobalConfigurations(this.requestSpec,
|
||||
this.responseSpec);
|
||||
Assert.assertNotNull(globalConfig);
|
||||
|
||||
String configName = "penalty-wait-period";
|
||||
for (Integer configIndex = 0; configIndex < (globalConfig.size() - 1); configIndex++) {
|
||||
if (globalConfig.get(configIndex).get("name").equals(configName)) {
|
||||
Integer configId = (Integer) globalConfig.get(configIndex).get("id");
|
||||
Assert.assertNotNull(configId);
|
||||
|
||||
HashMap configDataBefore = this.globalConfigurationHelper.getGlobalConfigurationById(this.requestSpec, this.responseSpec,
|
||||
configId.toString());
|
||||
Assert.assertNotNull(configDataBefore);
|
||||
|
||||
Integer value = (Integer) configDataBefore.get("value") + 1;
|
||||
|
||||
// Updating Value for penalty-wait-period Global Configuration
|
||||
configId = this.globalConfigurationHelper.updateValueForGlobalConfiguration(this.requestSpec, this.responseSpec,
|
||||
configId.toString(), value.toString());
|
||||
Assert.assertNotNull(configId);
|
||||
|
||||
HashMap configDataAfter = this.globalConfigurationHelper.getGlobalConfigurationById(this.requestSpec, this.responseSpec,
|
||||
configId.toString());
|
||||
|
||||
// Verifying Value for penalty-wait-period after Updation
|
||||
Assert.assertEquals("Verifying Global Config Value after Updation", value, configDataAfter.get("value"));
|
||||
|
||||
// Updating Enabled Flag for penalty-wait-period Global
|
||||
// Configuration
|
||||
Boolean enabled = (Boolean) globalConfig.get(configIndex).get("enabled");
|
||||
|
||||
if (enabled == true) {
|
||||
enabled = false;
|
||||
} else {
|
||||
enabled = true;
|
||||
}
|
||||
|
||||
configId = this.globalConfigurationHelper.updateEnabledFlagForGlobalConfiguration(this.requestSpec, this.responseSpec,
|
||||
configId.toString(), enabled);
|
||||
|
||||
configDataAfter = this.globalConfigurationHelper.getGlobalConfigurationById(this.requestSpec, this.responseSpec,
|
||||
configId.toString());
|
||||
|
||||
// Verifying Enabled Flag for penalty-wait-period after Updation
|
||||
Assert.assertEquals("Verifying Enabled Flag Global Config after Updation", enabled, configDataAfter.get("enabled"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGlobalConfigurationIsCacheEnabled() {
|
||||
this.globalConfigurationHelper = new GlobalConfigurationHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
// Retrieving Is Cache Enabled Global Configuration details
|
||||
ArrayList<HashMap> isCacheGlobalConfig = this.globalConfigurationHelper.getGlobalConfigurationIsCacheEnabled(this.requestSpec,
|
||||
this.responseSpec);
|
||||
Assert.assertNotNull(isCacheGlobalConfig);
|
||||
|
||||
for (Integer cacheType = 0; cacheType <= ((isCacheGlobalConfig.size()) - 1); cacheType++) {
|
||||
|
||||
// Retrieving Is Cache Enabled Global Configuration details
|
||||
isCacheGlobalConfig = this.globalConfigurationHelper.getGlobalConfigurationIsCacheEnabled(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(isCacheGlobalConfig);
|
||||
|
||||
HashMap cacheTypeAsHashMap = (HashMap) isCacheGlobalConfig.get(cacheType).get("cacheType");
|
||||
Integer cacheTypeId = (Integer) cacheTypeAsHashMap.get("id");
|
||||
String cacheTypeValue = (String) cacheTypeAsHashMap.get("value");
|
||||
Boolean enabled = (Boolean) isCacheGlobalConfig.get(cacheType).get("enabled");
|
||||
|
||||
if (cacheTypeValue.compareTo("No cache") == 0 && enabled == true) {
|
||||
cacheTypeId += 1;
|
||||
} else if (cacheTypeValue.compareTo("Single node") == 0 && enabled == true) {
|
||||
cacheTypeId -= 1;
|
||||
}
|
||||
|
||||
HashMap changes = this.globalConfigurationHelper.updateIsCacheEnabledForGlobalConfiguration(this.requestSpec,
|
||||
this.responseSpec, cacheTypeId.toString());
|
||||
Assert.assertEquals("Verifying Is Cache Enabled Global Config after Updation", cacheTypeId, changes.get("cacheType"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGlobalConfigForcePasswordResetDays() {
|
||||
|
||||
// Retrieving All Global Configuration details
|
||||
final ArrayList<HashMap> globalConfig = this.globalConfigurationHelper
|
||||
.getAllGlobalConfigurations(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(globalConfig);
|
||||
|
||||
String configName = "force-password-reset-days";
|
||||
String newValue = "0";
|
||||
String newBooleanValue = "true";
|
||||
|
||||
for (Integer configIndex = 0; configIndex < (globalConfig.size() - 1); configIndex++) {
|
||||
if (globalConfig.get(configIndex).get("name").equals(configName)) {
|
||||
Integer configId = (Integer) globalConfig.get(configIndex).get(
|
||||
"id");
|
||||
Assert.assertNotNull(configId);
|
||||
|
||||
/*
|
||||
* Update force-password-reset-days with value as 0 and Enable
|
||||
* as true - failure case
|
||||
*/
|
||||
ArrayList error = (ArrayList) this.globalConfigurationHelper
|
||||
.updatePasswordResetDaysForGlobalConfiguration(
|
||||
this.requestSpec, this.httpStatusForidden,
|
||||
configId, newValue, newBooleanValue,
|
||||
CommonConstants.RESPONSE_ERROR);
|
||||
HashMap hash = (HashMap) error.get(0);
|
||||
|
||||
Assert.assertEquals(
|
||||
"Force Password Reset days value must be greater than zero.",
|
||||
"error.msg.password.reset.days.value.must.be.greater.than.zero",
|
||||
hash.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
/*
|
||||
* Update force-password-reset-days with value as 50 and Enable
|
||||
* as true - success case
|
||||
*/
|
||||
final HashMap updateSuccess = (HashMap) this.globalConfigurationHelper
|
||||
.updatePasswordResetDaysForGlobalConfiguration(
|
||||
this.requestSpec, this.responseSpec, configId,
|
||||
"50", newBooleanValue, "changes");
|
||||
Assert.assertNotNull(updateSuccess);
|
||||
|
||||
/* Update with value as 0 and Enable as false - success case */
|
||||
final HashMap updateSuccess1 = (HashMap) this.globalConfigurationHelper
|
||||
.updatePasswordResetDaysForGlobalConfiguration(
|
||||
this.requestSpec, this.responseSpec, configId,
|
||||
newValue, "false", "changes");
|
||||
Assert.assertNotNull(updateSuccess1);
|
||||
|
||||
/* Update without sending value and Enable as true - failure case*/
|
||||
ArrayList failure = (ArrayList) this.globalConfigurationHelper
|
||||
.updatePasswordResetDaysForGlobalConfiguration(
|
||||
this.requestSpec, this.httpStatusForidden, configId,
|
||||
null, newBooleanValue, CommonConstants.RESPONSE_ERROR);
|
||||
HashMap failureHash = (HashMap) failure.get(0);
|
||||
Assert.assertEquals(
|
||||
"Force Password Reset days value must be greater than zero.",
|
||||
"error.msg.password.reset.days.value.must.be.greater.than.zero",
|
||||
failureHash.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* Update other global configuration property */
|
||||
String otherConfigName = "maker-checker";
|
||||
for (Integer configIndex = 0; configIndex < (globalConfig.size() - 1); configIndex++) {
|
||||
if (globalConfig.get(configIndex).get("name")
|
||||
.equals(otherConfigName)) {
|
||||
String configId = (globalConfig.get(configIndex).get("id"))
|
||||
.toString();
|
||||
Integer updateConfigId = this.globalConfigurationHelper
|
||||
.updateValueForGlobalConfiguration(this.requestSpec,
|
||||
this.responseSpec, configId, newValue);
|
||||
Assert.assertNotNull(updateConfigId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||
import org.apache.fineract.integrationtests.common.GroupHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Group Loan Integration Test for checking Loan Application Repayment Schedule.
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public class GroupLoanIntegrationTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private LoanTransactionHelper loanTransactionHelper;
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkGroupLoanCreateAndDisburseFlow() {
|
||||
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
Integer groupID = GroupHelper.createGroup(this.requestSpec, this.responseSpec, true);
|
||||
groupID = GroupHelper.associateClient(this.requestSpec, this.responseSpec, groupID.toString(), clientID.toString());
|
||||
|
||||
final Integer loanProductID = createLoanProduct();
|
||||
final Integer loanID = applyForLoanApplication(groupID, loanProductID);
|
||||
final ArrayList<HashMap> loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec,
|
||||
loanID);
|
||||
verifyLoanRepaymentSchedule(loanSchedule);
|
||||
|
||||
}
|
||||
|
||||
private Integer createLoanProduct() {
|
||||
System.out.println("------------------------------CREATING NEW LOAN PRODUCT ---------------------------------------");
|
||||
final String loanProductJSON = new LoanProductTestBuilder() //
|
||||
.withPrincipal("12,000.00") //
|
||||
.withNumberOfRepayments("4") //
|
||||
.withRepaymentAfterEvery("1") //
|
||||
.withRepaymentTypeAsMonth() //
|
||||
.withinterestRatePerPeriod("1") //
|
||||
.withInterestRateFrequencyTypeAsMonths() //
|
||||
.withAmortizationTypeAsEqualInstallments() //
|
||||
.withInterestTypeAsDecliningBalance() //
|
||||
.build(null);
|
||||
return this.loanTransactionHelper.getLoanProductId(loanProductJSON);
|
||||
}
|
||||
|
||||
private Integer applyForLoanApplication(final Integer groupID, final Integer loanProductID) {
|
||||
System.out.println("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------");
|
||||
final String loanApplicationJSON = new LoanApplicationTestBuilder() //
|
||||
.withPrincipal("12,000.00") //
|
||||
.withLoanTermFrequency("4") //
|
||||
.withLoanTermFrequencyAsMonths() //
|
||||
.withNumberOfRepayments("4") //
|
||||
.withRepaymentEveryAfter("1") //
|
||||
.withRepaymentFrequencyTypeAsMonths() //
|
||||
.withInterestRatePerPeriod("2") //
|
||||
.withAmortizationTypeAsEqualInstallments() //
|
||||
.withInterestTypeAsDecliningBalance() //
|
||||
.withInterestCalculationPeriodTypeSameAsRepaymentPeriod() //
|
||||
.withExpectedDisbursementDate("20 September 2011") //
|
||||
.withSubmittedOnDate("20 September 2011") //
|
||||
.withLoanType("group").build(groupID.toString(), loanProductID.toString(), null);
|
||||
System.out.println(loanApplicationJSON);
|
||||
return this.loanTransactionHelper.getLoanId(loanApplicationJSON);
|
||||
}
|
||||
|
||||
private void verifyLoanRepaymentSchedule(final ArrayList<HashMap> loanSchedule) {
|
||||
System.out.println("--------------------VERIFYING THE PRINCIPAL DUES,INTEREST DUE AND DUE DATE--------------------------");
|
||||
|
||||
assertEquals("Checking for Due Date for 1st Month", new ArrayList<>(Arrays.asList(2011, 10, 20)),
|
||||
loanSchedule.get(1).get("dueDate"));
|
||||
assertEquals("Checking for Principal Due for 1st Month", new Float("2911.49"), loanSchedule.get(1).get("principalOriginalDue"));
|
||||
assertEquals("Checking for Interest Due for 1st Month", new Float("240.00"), loanSchedule.get(1).get("interestOriginalDue"));
|
||||
|
||||
assertEquals("Checking for Due Date for 2nd Month", new ArrayList<>(Arrays.asList(2011, 11, 20)),
|
||||
loanSchedule.get(2).get("dueDate"));
|
||||
assertEquals("Checking for Principal Due for 2nd Month", new Float("2969.72"), loanSchedule.get(2).get("principalDue"));
|
||||
assertEquals("Checking for Interest Due for 2nd Month", new Float("181.77"), loanSchedule.get(2).get("interestOriginalDue"));
|
||||
|
||||
assertEquals("Checking for Due Date for 3rd Month", new ArrayList<>(Arrays.asList(2011, 12, 20)),
|
||||
loanSchedule.get(3).get("dueDate"));
|
||||
assertEquals("Checking for Principal Due for 3rd Month", new Float("3029.11"), loanSchedule.get(3).get("principalDue"));
|
||||
assertEquals("Checking for Interest Due for 3rd Month", new Float("122.38"), loanSchedule.get(3).get("interestOriginalDue"));
|
||||
|
||||
assertEquals("Checking for Due Date for 4th Month", new ArrayList<>(Arrays.asList(2012, 1, 20)),
|
||||
loanSchedule.get(4).get("dueDate"));
|
||||
assertEquals("Checking for Principal Due for 4th Month", new Float("3089.68"), loanSchedule.get(4).get("principalDue"));
|
||||
assertEquals("Checking for Interest Due for 4th Month", new Float("61.79"), loanSchedule.get(4).get("interestOriginalDue"));
|
||||
}
|
||||
}
|
||||
+553
@@ -0,0 +1,553 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||
import org.apache.fineract.integrationtests.common.CommonConstants;
|
||||
import org.apache.fineract.integrationtests.common.GroupHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.charges.ChargesHelper;
|
||||
import org.apache.fineract.integrationtests.common.savings.SavingsAccountHelper;
|
||||
import org.apache.fineract.integrationtests.common.savings.SavingsProductHelper;
|
||||
import org.apache.fineract.integrationtests.common.savings.SavingsStatusChecker;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Group Savings Integration Test for checking Savings Application.
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unused" })
|
||||
public class GroupSavingsIntegrationTest {
|
||||
|
||||
public static final String DEPOSIT_AMOUNT = "2000";
|
||||
public static final String WITHDRAW_AMOUNT = "1000";
|
||||
public static final String WITHDRAW_AMOUNT_ADJUSTED = "500";
|
||||
public static final String MINIMUM_OPENING_BALANCE = "1000.0";
|
||||
public static final String ACCOUNT_TYPE_GROUP = "GROUP";
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private SavingsAccountHelper savingsAccountHelper;
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSavingsAccount() {
|
||||
this.savingsAccountHelper = new SavingsAccountHelper(requestSpec, responseSpec);
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(clientID);
|
||||
|
||||
Integer groupID = GroupHelper.createGroup(this.requestSpec, this.responseSpec, true);
|
||||
Assert.assertNotNull(groupID);
|
||||
|
||||
groupID = GroupHelper.associateClient(this.requestSpec, this.responseSpec, groupID.toString(), clientID.toString());
|
||||
Assert.assertNotNull(groupID);
|
||||
|
||||
final String minBalanceForInterestCalculation = null;
|
||||
final String minRequiredBalance = null;
|
||||
final String enforceMinRequiredBalance = "false";
|
||||
final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE,
|
||||
minBalanceForInterestCalculation, minRequiredBalance, enforceMinRequiredBalance);
|
||||
Assert.assertNotNull(savingsProductID);
|
||||
|
||||
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(groupID, savingsProductID, ACCOUNT_TYPE_GROUP);
|
||||
Assert.assertNotNull(savingsId);
|
||||
|
||||
HashMap modifications = this.savingsAccountHelper.updateSavingsAccount(groupID, savingsProductID, savingsId, ACCOUNT_TYPE_GROUP);
|
||||
Assert.assertTrue(modifications.containsKey("submittedOnDate"));
|
||||
|
||||
HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap);
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.approveSavings(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap);
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.activateSavings(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap);
|
||||
|
||||
final HashMap summaryBefore = this.savingsAccountHelper.getSavingsSummary(savingsId);
|
||||
this.savingsAccountHelper.calculateInterestForSavings(savingsId);
|
||||
HashMap summary = this.savingsAccountHelper.getSavingsSummary(savingsId);
|
||||
assertEquals(summaryBefore, summary);
|
||||
|
||||
this.savingsAccountHelper.postInterestForSavings(savingsId);
|
||||
summary = this.savingsAccountHelper.getSavingsSummary(savingsId);
|
||||
Assert.assertFalse(summaryBefore.equals(summary));
|
||||
|
||||
final Object savingsInterest = this.savingsAccountHelper.getSavingsInterest(savingsId);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testSavingsAccount_CLOSE_APPLICATION() {
|
||||
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
|
||||
final ResponseSpecification errorResponse = new ResponseSpecBuilder().expectStatusCode(400).build();
|
||||
final SavingsAccountHelper validationErrorHelper = new SavingsAccountHelper(this.requestSpec, errorResponse);
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(clientID);
|
||||
|
||||
Integer groupID = GroupHelper.createGroup(this.requestSpec, this.responseSpec, true);
|
||||
Assert.assertNotNull(groupID);
|
||||
|
||||
groupID = GroupHelper.associateClient(this.requestSpec, this.responseSpec, groupID.toString(), clientID.toString());
|
||||
Assert.assertNotNull(groupID);
|
||||
|
||||
final String minBalanceForInterestCalculation = null;
|
||||
final String minRequiredBalance = "1000.0";
|
||||
final String enforceMinRequiredBalance = "true";
|
||||
final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE,
|
||||
minBalanceForInterestCalculation, minRequiredBalance, enforceMinRequiredBalance);
|
||||
Assert.assertNotNull(savingsProductID);
|
||||
|
||||
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(groupID, savingsProductID, ACCOUNT_TYPE_GROUP);
|
||||
Assert.assertNotNull(savingsId);
|
||||
|
||||
HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap);
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.approveSavings(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap);
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.activateSavings(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap);
|
||||
|
||||
DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy", Locale.US);
|
||||
Calendar todaysDate = Calendar.getInstance();
|
||||
final String CLOSEDON_DATE = dateFormat.format(todaysDate.getTime());
|
||||
String withdrawBalance = "false";
|
||||
ArrayList<HashMap> savingsAccountErrorData = (ArrayList<HashMap>) validationErrorHelper.closeSavingsAccountAndGetBackRequiredField(
|
||||
savingsId, withdrawBalance, CommonConstants.RESPONSE_ERROR, CLOSEDON_DATE);
|
||||
assertEquals("validation.msg.savingsaccount.close.results.in.balance.not.zero",
|
||||
savingsAccountErrorData.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
withdrawBalance = "true";
|
||||
savingsStatusHashMap = this.savingsAccountHelper.closeSavingsAccount(savingsId, withdrawBalance);
|
||||
SavingsStatusChecker.verifySavingsAccountIsClosed(savingsStatusHashMap);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testSavingsAccount_DELETE_APPLICATION() {
|
||||
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
SavingsAccountHelper savingsAccountHelperValidationError = new SavingsAccountHelper(this.requestSpec,
|
||||
new ResponseSpecBuilder().build());
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(clientID);
|
||||
|
||||
Integer groupID = GroupHelper.createGroup(this.requestSpec, this.responseSpec, true);
|
||||
Assert.assertNotNull(groupID);
|
||||
|
||||
groupID = GroupHelper.associateClient(this.requestSpec, this.responseSpec, groupID.toString(), clientID.toString());
|
||||
Assert.assertNotNull(groupID);
|
||||
|
||||
final String minBalanceForInterestCalculation = null;
|
||||
final String minRequiredBalance = null;
|
||||
final String enforceMinRequiredBalance = "false";
|
||||
final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE,
|
||||
minBalanceForInterestCalculation, minRequiredBalance, enforceMinRequiredBalance);
|
||||
Assert.assertNotNull(savingsProductID);
|
||||
|
||||
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(groupID, savingsProductID, ACCOUNT_TYPE_GROUP);
|
||||
Assert.assertNotNull(savingsId);
|
||||
|
||||
HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap);
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.approveSavings(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap);
|
||||
|
||||
List<HashMap> error1 = (List<HashMap>) savingsAccountHelperValidationError.deleteSavingsApplication(savingsId,
|
||||
CommonConstants.RESPONSE_ERROR);
|
||||
assertEquals("validation.msg.savingsaccount.delete.not.in.submittedandpendingapproval.state",
|
||||
error1.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.undoApproval(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap);
|
||||
|
||||
this.savingsAccountHelper.deleteSavingsApplication(savingsId, CommonConstants.RESPONSE_RESOURCE_ID);
|
||||
|
||||
List<HashMap> error = savingsAccountHelperValidationError.getSavingsCollectionAttribute(savingsId, CommonConstants.RESPONSE_ERROR);
|
||||
assertEquals("error.msg.saving.account.id.invalid", error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testSavingsAccount_REJECT_APPLICATION() {
|
||||
|
||||
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
SavingsAccountHelper savingsAccountHelperValidationError = new SavingsAccountHelper(this.requestSpec,
|
||||
new ResponseSpecBuilder().build());
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(clientID);
|
||||
|
||||
Integer groupID = GroupHelper.createGroup(this.requestSpec, this.responseSpec, true);
|
||||
Assert.assertNotNull(groupID);
|
||||
|
||||
groupID = GroupHelper.associateClient(this.requestSpec, this.responseSpec, groupID.toString(), clientID.toString());
|
||||
Assert.assertNotNull(groupID);
|
||||
|
||||
final String minBalanceForInterestCalculation = null;
|
||||
final String minRequiredBalance = null;
|
||||
final String enforceMinRequiredBalance = "false";
|
||||
final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE,
|
||||
minBalanceForInterestCalculation, minRequiredBalance, enforceMinRequiredBalance);
|
||||
Assert.assertNotNull(savingsProductID);
|
||||
|
||||
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(groupID, savingsProductID, ACCOUNT_TYPE_GROUP);
|
||||
Assert.assertNotNull(savingsId);
|
||||
|
||||
HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap);
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.approveSavings(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap);
|
||||
|
||||
List<HashMap> error1 = savingsAccountHelperValidationError.rejectApplicationWithErrorCode(savingsId,
|
||||
SavingsAccountHelper.CREATED_DATE_PLUS_ONE);
|
||||
assertEquals("validation.msg.savingsaccount.reject.not.in.submittedandpendingapproval.state",
|
||||
error1.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.undoApproval(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap);
|
||||
|
||||
error1 = savingsAccountHelperValidationError.rejectApplicationWithErrorCode(savingsId, SavingsAccountHelper.getFutureDate());
|
||||
assertEquals("validation.msg.savingsaccount.reject.cannot.be.a.future.date",
|
||||
error1.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
error1 = savingsAccountHelperValidationError.rejectApplicationWithErrorCode(savingsId, SavingsAccountHelper.CREATED_DATE_MINUS_ONE);
|
||||
assertEquals("validation.msg.savingsaccount.reject.cannot.be.before.submittal.date",
|
||||
error1.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.rejectApplication(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsRejected(savingsStatusHashMap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSavingsAccount_WITHDRAW_APPLICATION() {
|
||||
|
||||
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(clientID);
|
||||
|
||||
Integer groupID = GroupHelper.createGroup(this.requestSpec, this.responseSpec, true);
|
||||
Assert.assertNotNull(groupID);
|
||||
|
||||
groupID = GroupHelper.associateClient(this.requestSpec, this.responseSpec, groupID.toString(), clientID.toString());
|
||||
Assert.assertNotNull(groupID);
|
||||
|
||||
final String minBalanceForInterestCalculation = null;
|
||||
final String minRequiredBalance = null;
|
||||
final String enforceMinRequiredBalance = "false";
|
||||
final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE,
|
||||
minBalanceForInterestCalculation, minRequiredBalance, enforceMinRequiredBalance);
|
||||
Assert.assertNotNull(savingsProductID);
|
||||
|
||||
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(groupID, savingsProductID, ACCOUNT_TYPE_GROUP);
|
||||
Assert.assertNotNull(savingsId);
|
||||
|
||||
HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap);
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.withdrawApplication(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsWithdrawn(savingsStatusHashMap);
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testSavingsAccountTransactions() {
|
||||
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
|
||||
SavingsAccountHelper savingsAccountHelperValidationError = new SavingsAccountHelper(this.requestSpec,
|
||||
new ResponseSpecBuilder().build());
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(clientID);
|
||||
|
||||
Integer groupID = GroupHelper.createGroup(this.requestSpec, this.responseSpec, true);
|
||||
Assert.assertNotNull(groupID);
|
||||
|
||||
groupID = GroupHelper.associateClient(this.requestSpec, this.responseSpec, groupID.toString(), clientID.toString());
|
||||
Assert.assertNotNull(groupID);
|
||||
|
||||
final String minBalanceForInterestCalculation = null;
|
||||
final String minRequiredBalance = null;
|
||||
final String enforceMinRequiredBalance = "false";
|
||||
final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE,
|
||||
minBalanceForInterestCalculation, minRequiredBalance, enforceMinRequiredBalance);
|
||||
Assert.assertNotNull(savingsProductID);
|
||||
|
||||
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(groupID, savingsProductID, ACCOUNT_TYPE_GROUP);
|
||||
Assert.assertNotNull(savingsId);
|
||||
|
||||
HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap);
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.approveSavings(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap);
|
||||
|
||||
List<HashMap> error = (List) savingsAccountHelperValidationError.withdrawalFromSavingsAccount(savingsId, "100",
|
||||
SavingsAccountHelper.TRANSACTION_DATE, CommonConstants.RESPONSE_ERROR);
|
||||
assertEquals("error.msg.savingsaccount.transaction.account.is.not.active",
|
||||
error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
error = (List) savingsAccountHelperValidationError.depositToSavingsAccount(savingsId, "100", SavingsAccountHelper.TRANSACTION_DATE,
|
||||
CommonConstants.RESPONSE_ERROR);
|
||||
assertEquals("error.msg.savingsaccount.transaction.account.is.not.active",
|
||||
error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.activateSavings(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap);
|
||||
|
||||
HashMap summary = this.savingsAccountHelper.getSavingsSummary(savingsId);
|
||||
Float balance = new Float(MINIMUM_OPENING_BALANCE);
|
||||
assertEquals("Verifying opening Balance", balance, summary.get("accountBalance"));
|
||||
|
||||
Integer depositTransactionId = (Integer) this.savingsAccountHelper.depositToSavingsAccount(savingsId, DEPOSIT_AMOUNT,
|
||||
SavingsAccountHelper.TRANSACTION_DATE, CommonConstants.RESPONSE_RESOURCE_ID);
|
||||
HashMap depositTransaction = this.savingsAccountHelper.getSavingsTransaction(savingsId, depositTransactionId);
|
||||
balance += new Float(DEPOSIT_AMOUNT);
|
||||
assertEquals("Verifying Deposit Amount", new Float(DEPOSIT_AMOUNT), depositTransaction.get("amount"));
|
||||
assertEquals("Verifying Balance after Deposit", balance, depositTransaction.get("runningBalance"));
|
||||
|
||||
Integer withdrawTransactionId = (Integer) this.savingsAccountHelper.withdrawalFromSavingsAccount(savingsId, WITHDRAW_AMOUNT,
|
||||
SavingsAccountHelper.TRANSACTION_DATE, CommonConstants.RESPONSE_RESOURCE_ID);
|
||||
HashMap withdrawTransaction = this.savingsAccountHelper.getSavingsTransaction(savingsId, withdrawTransactionId);
|
||||
balance -= new Float(WITHDRAW_AMOUNT);
|
||||
assertEquals("Verifying Withdrawal Amount", new Float(WITHDRAW_AMOUNT), withdrawTransaction.get("amount"));
|
||||
assertEquals("Verifying Balance after Withdrawal", balance, withdrawTransaction.get("runningBalance"));
|
||||
|
||||
Integer newWithdrawTransactionId = this.savingsAccountHelper.updateSavingsAccountTransaction(savingsId, withdrawTransactionId,
|
||||
WITHDRAW_AMOUNT_ADJUSTED);
|
||||
HashMap newWithdrawTransaction = this.savingsAccountHelper.getSavingsTransaction(savingsId, newWithdrawTransactionId);
|
||||
balance = balance + new Float(WITHDRAW_AMOUNT) - new Float(WITHDRAW_AMOUNT_ADJUSTED);
|
||||
assertEquals("Verifying adjusted Amount", new Float(WITHDRAW_AMOUNT_ADJUSTED), newWithdrawTransaction.get("amount"));
|
||||
assertEquals("Verifying Balance after adjust", balance, newWithdrawTransaction.get("runningBalance"));
|
||||
summary = this.savingsAccountHelper.getSavingsSummary(savingsId);
|
||||
assertEquals("Verifying Adjusted Balance", balance, summary.get("accountBalance"));
|
||||
withdrawTransaction = this.savingsAccountHelper.getSavingsTransaction(savingsId, withdrawTransactionId);
|
||||
Assert.assertTrue((Boolean) withdrawTransaction.get("reversed"));
|
||||
|
||||
this.savingsAccountHelper.undoSavingsAccountTransaction(savingsId, newWithdrawTransactionId);
|
||||
newWithdrawTransaction = this.savingsAccountHelper.getSavingsTransaction(savingsId, withdrawTransactionId);
|
||||
Assert.assertTrue((Boolean) newWithdrawTransaction.get("reversed"));
|
||||
summary = this.savingsAccountHelper.getSavingsSummary(savingsId);
|
||||
balance += new Float(WITHDRAW_AMOUNT_ADJUSTED);
|
||||
assertEquals("Verifying Balance After Undo Transaction", balance, summary.get("accountBalance"));
|
||||
|
||||
error = (List) savingsAccountHelperValidationError.withdrawalFromSavingsAccount(savingsId, "5000",
|
||||
SavingsAccountHelper.TRANSACTION_DATE, CommonConstants.RESPONSE_ERROR);
|
||||
assertEquals("error.msg.savingsaccount.transaction.insufficient.account.balance",
|
||||
error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
error = (List) savingsAccountHelperValidationError.withdrawalFromSavingsAccount(savingsId, "5000",
|
||||
SavingsAccountHelper.getFutureDate(), CommonConstants.RESPONSE_ERROR);
|
||||
assertEquals("error.msg.savingsaccount.transaction.in.the.future", error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
error = (List) savingsAccountHelperValidationError.depositToSavingsAccount(savingsId, "5000", SavingsAccountHelper.getFutureDate(),
|
||||
CommonConstants.RESPONSE_ERROR);
|
||||
assertEquals("error.msg.savingsaccount.transaction.in.the.future", error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
error = (List) savingsAccountHelperValidationError.withdrawalFromSavingsAccount(savingsId, "5000",
|
||||
SavingsAccountHelper.CREATED_DATE_MINUS_ONE, CommonConstants.RESPONSE_ERROR);
|
||||
assertEquals("error.msg.savingsaccount.transaction.before.activation.date",
|
||||
error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
error = (List) savingsAccountHelperValidationError.depositToSavingsAccount(savingsId, "5000",
|
||||
SavingsAccountHelper.CREATED_DATE_MINUS_ONE, CommonConstants.RESPONSE_ERROR);
|
||||
assertEquals("error.msg.savingsaccount.transaction.before.activation.date",
|
||||
error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testSavingsAccountCharges() {
|
||||
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(clientID);
|
||||
|
||||
Integer groupID = GroupHelper.createGroup(this.requestSpec, this.responseSpec, true);
|
||||
Assert.assertNotNull(groupID);
|
||||
|
||||
groupID = GroupHelper.associateClient(this.requestSpec, this.responseSpec, groupID.toString(), clientID.toString());
|
||||
Assert.assertNotNull(groupID);
|
||||
|
||||
final String minBalanceForInterestCalculation = null;
|
||||
final String minRequiredBalance = null;
|
||||
final String enforceMinRequiredBalance = "false";
|
||||
final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE,
|
||||
minBalanceForInterestCalculation, minRequiredBalance, enforceMinRequiredBalance);
|
||||
Assert.assertNotNull(savingsProductID);
|
||||
|
||||
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(groupID, savingsProductID, ACCOUNT_TYPE_GROUP);
|
||||
Assert.assertNotNull(savingsId);
|
||||
|
||||
HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap);
|
||||
|
||||
final Integer withdrawalChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
|
||||
ChargesHelper.getSavingsWithdrawalFeeJSON());
|
||||
Assert.assertNotNull(withdrawalChargeId);
|
||||
|
||||
this.savingsAccountHelper.addChargesForSavings(savingsId, withdrawalChargeId);
|
||||
ArrayList<HashMap> chargesPendingState = this.savingsAccountHelper.getSavingsCharges(savingsId);
|
||||
Assert.assertEquals(1, chargesPendingState.size());
|
||||
|
||||
Integer savingsChargeId = (Integer) chargesPendingState.get(0).get("id");
|
||||
HashMap chargeChanges = this.savingsAccountHelper.updateCharges(savingsChargeId, savingsId);
|
||||
Assert.assertTrue(chargeChanges.containsKey("amount"));
|
||||
|
||||
Integer deletedChargeId = this.savingsAccountHelper.deleteCharge(savingsChargeId, savingsId);
|
||||
assertEquals(savingsChargeId, deletedChargeId);
|
||||
|
||||
chargesPendingState = this.savingsAccountHelper.getSavingsCharges(savingsId);
|
||||
Assert.assertTrue(chargesPendingState == null || chargesPendingState.size() == 0);
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.approveSavings(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap);
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.activateSavings(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap);
|
||||
|
||||
final Integer chargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec, ChargesHelper.getSavingsAnnualFeeJSON());
|
||||
Assert.assertNotNull(chargeId);
|
||||
|
||||
ArrayList<HashMap> charges = this.savingsAccountHelper.getSavingsCharges(savingsId);
|
||||
Assert.assertTrue(charges == null || charges.size() == 0);
|
||||
|
||||
this.savingsAccountHelper.addChargesForSavings(savingsId, chargeId);
|
||||
charges = this.savingsAccountHelper.getSavingsCharges(savingsId);
|
||||
Assert.assertEquals(1, charges.size());
|
||||
|
||||
HashMap savingsChargeForPay = charges.get(0);
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(CommonConstants.dateFormat, Locale.US);
|
||||
Calendar cal = Calendar.getInstance();
|
||||
List dates = (List) savingsChargeForPay.get("dueDate");
|
||||
cal.set(Calendar.YEAR, (Integer) dates.get(0));
|
||||
cal.set(Calendar.MONTH, (Integer) dates.get(1) - 1);
|
||||
cal.set(Calendar.DAY_OF_MONTH, (Integer) dates.get(2));
|
||||
|
||||
this.savingsAccountHelper.payCharge((Integer) savingsChargeForPay.get("id"), savingsId,
|
||||
((Float) savingsChargeForPay.get("amount")).toString(), sdf.format(cal.getTime()));
|
||||
HashMap paidCharge = this.savingsAccountHelper.getSavingsCharge(savingsId, (Integer) savingsChargeForPay.get("id"));
|
||||
assertEquals(savingsChargeForPay.get("amount"), paidCharge.get("amountPaid"));
|
||||
|
||||
final Integer monthlyFeechargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
|
||||
ChargesHelper.getSavingsMonthlyFeeJSON());
|
||||
Assert.assertNotNull(monthlyFeechargeId);
|
||||
|
||||
this.savingsAccountHelper.addChargesForSavings(savingsId, monthlyFeechargeId);
|
||||
charges = this.savingsAccountHelper.getSavingsCharges(savingsId);
|
||||
Assert.assertEquals(2, charges.size());
|
||||
|
||||
HashMap savingsChargeForWaive = charges.get(1);
|
||||
this.savingsAccountHelper.waiveCharge((Integer) savingsChargeForWaive.get("id"), savingsId);
|
||||
HashMap waiveCharge = this.savingsAccountHelper.getSavingsCharge(savingsId, (Integer) savingsChargeForWaive.get("id"));
|
||||
assertEquals(savingsChargeForWaive.get("amount"), waiveCharge.get("amountWaived"));
|
||||
|
||||
this.savingsAccountHelper.waiveCharge((Integer) savingsChargeForWaive.get("id"), savingsId);
|
||||
waiveCharge = this.savingsAccountHelper.getSavingsCharge(savingsId, (Integer) savingsChargeForWaive.get("id"));
|
||||
BigDecimal totalWaiveAmount = BigDecimal.valueOf(Double.valueOf((Float) savingsChargeForWaive.get("amount")));
|
||||
totalWaiveAmount = totalWaiveAmount.add(totalWaiveAmount);
|
||||
assertEquals(totalWaiveAmount.floatValue(), waiveCharge.get("amountWaived"));
|
||||
|
||||
final Integer weeklyFeeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec, ChargesHelper.getSavingsWeeklyFeeJSON());
|
||||
Assert.assertNotNull(weeklyFeeId);
|
||||
|
||||
this.savingsAccountHelper.addChargesForSavings(savingsId, weeklyFeeId);
|
||||
charges = this.savingsAccountHelper.getSavingsCharges(savingsId);
|
||||
Assert.assertEquals(3, charges.size());
|
||||
|
||||
savingsChargeForPay = charges.get(2);
|
||||
cal = Calendar.getInstance();
|
||||
dates = (List) savingsChargeForPay.get("dueDate");
|
||||
cal.set(Calendar.YEAR, (Integer) dates.get(0));
|
||||
cal.set(Calendar.MONTH, (Integer) dates.get(1) - 1);
|
||||
cal.set(Calendar.DAY_OF_MONTH, (Integer) dates.get(2));
|
||||
|
||||
// Depositing huge amount as scheduler job deducts the fee amount
|
||||
Integer depositTransactionId = (Integer) this.savingsAccountHelper.depositToSavingsAccount(savingsId, "100000",
|
||||
SavingsAccountHelper.TRANSACTION_DATE, CommonConstants.RESPONSE_RESOURCE_ID);
|
||||
Assert.assertNotNull(depositTransactionId);
|
||||
|
||||
this.savingsAccountHelper.payCharge((Integer) savingsChargeForPay.get("id"), savingsId,
|
||||
((Float) savingsChargeForPay.get("amount")).toString(), sdf.format(cal.getTime()));
|
||||
paidCharge = this.savingsAccountHelper.getSavingsCharge(savingsId, (Integer) savingsChargeForPay.get("id"));
|
||||
assertEquals(savingsChargeForPay.get("amount"), paidCharge.get("amountPaid"));
|
||||
List nextDueDates = (List) paidCharge.get("dueDate");
|
||||
LocalDate nextDueDate = new LocalDate((Integer) nextDueDates.get(0), (Integer) nextDueDates.get(1), (Integer) nextDueDates.get(2));
|
||||
LocalDate expectedNextDueDate = new LocalDate((Integer) dates.get(0), (Integer) dates.get(1), (Integer) dates.get(2))
|
||||
.plusWeeks((Integer) paidCharge.get("feeInterval"));
|
||||
assertEquals(expectedNextDueDate, nextDueDate);
|
||||
cal = Calendar.getInstance();
|
||||
|
||||
this.savingsAccountHelper.closeSavingsAccountAndGetBackRequiredField(savingsId, "true", null, sdf.format(cal.getTime()));
|
||||
|
||||
}
|
||||
|
||||
public static Integer createSavingsProduct(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String minOpenningBalance, final String minBalanceForInterestCalculation, final String minRequiredBalance,
|
||||
final String enforceMinRequiredBalance) {
|
||||
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(minOpenningBalance).build();
|
||||
return SavingsProductHelper.createSavingsProduct(savingsProductJSON, requestSpec, responseSpec);
|
||||
}
|
||||
}
|
||||
Executable
+178
@@ -0,0 +1,178 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||
import org.apache.fineract.integrationtests.common.GroupHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
|
||||
import org.apache.fineract.integrationtests.common.organisation.StaffHelper;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Group Test for checking Group: Creation, Activation, Client Association,
|
||||
* Updating & Deletion
|
||||
*/
|
||||
public class GroupTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private LoanTransactionHelper loanTransactionHelper;
|
||||
private final String principal = "10000.00";
|
||||
private final String accountingRule = "1";
|
||||
private final String numberOfRepayments = "5";
|
||||
private final String interestRatePerPeriod = "18";
|
||||
|
||||
@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.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkGroupFunctions() {
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
Integer groupID = GroupHelper.createGroup(this.requestSpec, this.responseSpec);
|
||||
GroupHelper.verifyGroupCreatedOnServer(this.requestSpec, this.responseSpec, groupID);
|
||||
|
||||
groupID = GroupHelper.activateGroup(this.requestSpec, this.responseSpec, groupID.toString());
|
||||
GroupHelper.verifyGroupActivatedOnServer(this.requestSpec, this.responseSpec, groupID, true);
|
||||
|
||||
groupID = GroupHelper.associateClient(this.requestSpec, this.responseSpec, groupID.toString(), clientID.toString());
|
||||
GroupHelper.verifyGroupMembers(this.requestSpec, this.responseSpec, groupID, clientID);
|
||||
|
||||
groupID = GroupHelper.disAssociateClient(this.requestSpec, this.responseSpec, groupID.toString(), clientID.toString());
|
||||
GroupHelper.verifyEmptyGroupMembers(this.requestSpec, this.responseSpec, groupID);
|
||||
|
||||
final String updatedGroupName = GroupHelper.randomNameGenerator("Group-", 5);
|
||||
groupID = GroupHelper.updateGroup(this.requestSpec, this.responseSpec, updatedGroupName, groupID.toString());
|
||||
GroupHelper.verifyGroupDetails(this.requestSpec, this.responseSpec, groupID, "name", updatedGroupName);
|
||||
|
||||
// NOTE: removed as consistently provides false positive result on
|
||||
// cloudbees server.
|
||||
// groupID = GroupHelper.createGroup(this.requestSpec,
|
||||
// this.responseSpec);
|
||||
// GroupHelper.deleteGroup(this.requestSpec, this.responseSpec,
|
||||
// groupID.toString());
|
||||
// GroupHelper.verifyGroupDeleted(this.requestSpec, this.responseSpec,
|
||||
// groupID);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assignStaffToGroup() {
|
||||
Integer groupID = GroupHelper.createGroup(this.requestSpec, this.responseSpec);
|
||||
GroupHelper.verifyGroupCreatedOnServer(this.requestSpec, this.responseSpec, groupID);
|
||||
|
||||
final String updateGroupName = Utils.randomNameGenerator("Savings Group Help_", 5);
|
||||
groupID = GroupHelper.activateGroup(this.requestSpec, this.responseSpec, groupID.toString());
|
||||
Integer updateGroupId = GroupHelper.updateGroup(this.requestSpec, this.responseSpec, updateGroupName, groupID.toString());
|
||||
|
||||
// create client and add client to group
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
groupID = GroupHelper.associateClient(this.requestSpec, this.responseSpec, groupID.toString(), clientID.toString());
|
||||
GroupHelper.verifyGroupMembers(this.requestSpec, this.responseSpec, groupID, clientID);
|
||||
|
||||
// create staff
|
||||
Integer createStaffId1 = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
|
||||
System.out.println("--------------creating first staff with id-------------" + createStaffId1);
|
||||
Assert.assertNotNull(createStaffId1);
|
||||
|
||||
Integer createStaffId2 = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
|
||||
System.out.println("--------------creating second staff with id-------------" + createStaffId2);
|
||||
Assert.assertNotNull(createStaffId2);
|
||||
|
||||
// assign staff "createStaffId1" to group
|
||||
HashMap assignStaffGroupId = (HashMap) GroupHelper.assignStaff(this.requestSpec, this.responseSpec, groupID.toString(),
|
||||
createStaffId1.longValue());
|
||||
assertEquals("Verify assigned staff id is the same as id sent", assignStaffGroupId.get("staffId"), createStaffId1);
|
||||
|
||||
// assign staff "createStaffId2" to client
|
||||
final HashMap assignStaffToClientChanges = (HashMap) ClientHelper.assignStaffToClient(this.requestSpec, this.responseSpec,
|
||||
clientID.toString(), createStaffId2.toString());
|
||||
assertEquals("Verify assigned staff id is the same as id sent", assignStaffToClientChanges.get("staffId"), createStaffId2);
|
||||
|
||||
final Integer loanProductId = this.createLoanProduct();
|
||||
|
||||
final Integer loanId = this.applyForLoanApplication(clientID, loanProductId, this.principal);
|
||||
|
||||
this.loanTransactionHelper.approveLoan("20 September 2014", loanId);
|
||||
this.loanTransactionHelper.disburseLoan("20 September 2014", loanId);
|
||||
|
||||
final HashMap assignStaffAndInheritStaffForClientAccounts = (HashMap) GroupHelper.assignStaffInheritStaffForClientAccounts(
|
||||
this.requestSpec, this.responseSpec, groupID.toString(), createStaffId1.toString());
|
||||
final Integer getClientStaffId = ClientHelper.getClientsStaffId(this.requestSpec, this.responseSpec, clientID.toString());
|
||||
|
||||
// assert if client staff officer has change Note client was assigned
|
||||
// staff with createStaffId2
|
||||
assertNotEquals("Verify if client stuff has changed", assignStaffAndInheritStaffForClientAccounts.get("staffId"), createStaffId2);
|
||||
assertEquals("Verify if client inherited staff assigned above", assignStaffAndInheritStaffForClientAccounts.get("staffId"),
|
||||
getClientStaffId);
|
||||
|
||||
// assert if clients loan officer has changed
|
||||
final Integer loanOfficerId = this.loanTransactionHelper.getLoanOfficerId(loanId.toString());
|
||||
assertEquals("Verify if client loan inherited staff", assignStaffAndInheritStaffForClientAccounts.get("staffId"), loanOfficerId);
|
||||
|
||||
}
|
||||
|
||||
private Integer createLoanProduct() {
|
||||
final String loanProductJSON = new LoanProductTestBuilder().withPrincipal(this.principal)
|
||||
.withNumberOfRepayments(this.numberOfRepayments).withinterestRatePerPeriod(this.interestRatePerPeriod)
|
||||
.withInterestRateFrequencyTypeAsYear().build(null);
|
||||
return this.loanTransactionHelper.getLoanProductId(loanProductJSON);
|
||||
}
|
||||
|
||||
private Integer applyForLoanApplication(final Integer clientID, final Integer loanProductID, String principal) {
|
||||
System.out.println("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------");
|
||||
final String loanApplicationJSON = new LoanApplicationTestBuilder() //
|
||||
.withPrincipal(principal) //
|
||||
.withLoanTermFrequency("4") //
|
||||
.withLoanTermFrequencyAsMonths() //
|
||||
.withNumberOfRepayments("4") //
|
||||
.withRepaymentEveryAfter("1") //
|
||||
.withRepaymentFrequencyTypeAsMonths() //
|
||||
.withInterestRatePerPeriod("2") //
|
||||
.withAmortizationTypeAsEqualInstallments() //
|
||||
.withInterestTypeAsDecliningBalance() //
|
||||
.withInterestCalculationPeriodTypeSameAsRepaymentPeriod() //
|
||||
.withExpectedDisbursementDate("20 September 2014") //
|
||||
.withSubmittedOnDate("20 September 2014") //
|
||||
.build(clientID.toString(), loanProductID.toString(), null);
|
||||
return this.loanTransactionHelper.getLoanId(loanApplicationJSON);
|
||||
}
|
||||
|
||||
}
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.HookHelper;
|
||||
import org.apache.fineract.integrationtests.common.OfficeHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.http.conn.HttpHostConnectException;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.jayway.restassured.RestAssured;
|
||||
import com.jayway.restassured.builder.RequestSpecBuilder;
|
||||
import com.jayway.restassured.builder.ResponseSpecBuilder;
|
||||
import com.jayway.restassured.http.ContentType;
|
||||
import com.jayway.restassured.path.json.JsonPath;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
public class HookIntegrationTest {
|
||||
|
||||
private RequestSpecification requestSpec;
|
||||
private ResponseSpecification responseSpec;
|
||||
|
||||
private HookHelper hookHelper;
|
||||
private OfficeHelper officeHelper;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
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.hookHelper = new HookHelper(this.requestSpec, this.responseSpec);
|
||||
this.officeHelper = new OfficeHelper(this.requestSpec, this.responseSpec);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSendOfficeCreationNotification() {
|
||||
// Subject to https://echo-webhook.herokuapp.com being up
|
||||
// See
|
||||
// http://www.jamesward.com/2014/06/11/testing-webhooks-was-a-pain-so-i-fixed-the-glitch
|
||||
final String payloadURL = "http://echo-webhook.herokuapp.com:80/Z7RXoCBdLSFMDrpn?";
|
||||
this.hookHelper.createHook(payloadURL);
|
||||
final Integer createdOfficeID = this.officeHelper.createOffice("01 January 2012");
|
||||
try {
|
||||
|
||||
/**
|
||||
* sleep for a three seconds after each failure to increase the
|
||||
* likelihood of the previous request for creating office completing
|
||||
**/
|
||||
|
||||
for (int i = 0; i < 6; i++) {
|
||||
try {
|
||||
final String json = RestAssured.get(payloadURL.replace("?", "")).asString();
|
||||
final Integer notificationOfficeId = JsonPath.with(json).get("officeId");
|
||||
Assert.assertEquals("Equality check for created officeId and hook received payload officeId", createdOfficeID,
|
||||
notificationOfficeId);
|
||||
System.out.println("Notification Office Id - " + notificationOfficeId);
|
||||
i = 6;
|
||||
} catch (Exception e) {
|
||||
TimeUnit.SECONDS.sleep(3);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
} catch (final Exception e) {
|
||||
if (e instanceof HttpHostConnectException) {
|
||||
fail("Failed to connect to https://echo-webhook.herokuapp.com platform");
|
||||
}
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createUpdateAndDeleteHook(){
|
||||
final String payloadURL = "http://echo-webhook.herokuapp.com:80/Z7RXoCBdLSFMDrpn?";
|
||||
final String updateURL = "http://localhost";
|
||||
|
||||
Long hookId = this.hookHelper.createHook(payloadURL).longValue();
|
||||
Assert.assertNotNull(hookId);
|
||||
this.hookHelper.verifyHookCreatedOnServer(hookId);
|
||||
System.out.println("---------------------SUCCESSFULLY CREATED AND VERIFIED HOOK-------------------------"+hookId);
|
||||
this.hookHelper.updateHook(updateURL, hookId);
|
||||
this.hookHelper.verifyUpdateHook(updateURL, hookId);
|
||||
System.out.println("---------------------SUCCESSFULLY UPDATED AND VERIFIED HOOK-------------------------"+hookId);
|
||||
this.hookHelper.deleteHook(hookId);
|
||||
this.hookHelper.verifyDeleteHook(hookId);
|
||||
System.out.println("---------------------SUCCESSFULLY DELETED AND VERIFIED HOOK-------------------------"+hookId);
|
||||
|
||||
}
|
||||
}
|
||||
+281
@@ -0,0 +1,281 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||
import org.apache.fineract.integrationtests.common.CommonConstants;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanStatusChecker;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
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;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class LoanApplicationApprovalTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private ResponseSpecification responseSpecForStatusCode403;
|
||||
private ResponseSpecification responseSpecForStatusCode400;
|
||||
private RequestSpecification requestSpec;
|
||||
private LoanTransactionHelper loanTransactionHelper;
|
||||
|
||||
@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.responseSpecForStatusCode403 = new ResponseSpecBuilder().expectStatusCode(403).build();
|
||||
this.responseSpecForStatusCode400 = new ResponseSpecBuilder().expectStatusCode(400).build();
|
||||
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
|
||||
}
|
||||
|
||||
/*
|
||||
* Positive test case: Approved amount non zero is less than proposed amount
|
||||
*/
|
||||
@Test
|
||||
public void loanApplicationApprovedAmountLessThanProposedAmount() {
|
||||
|
||||
final String proposedAmount = "8000";
|
||||
final String approvalAmount = "5000";
|
||||
final String approveDate = "20 September 2012";
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2012");
|
||||
final Integer loanProductID = this.loanTransactionHelper.getLoanProductId(new LoanProductTestBuilder().build(null));
|
||||
final Integer loanID = applyForLoanApplication(clientID, loanProductID, proposedAmount);
|
||||
|
||||
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
|
||||
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
|
||||
|
||||
final String expectedDisbursementDate = null;
|
||||
List<HashMap> approveTranches = null;
|
||||
loanStatusHashMap = this.loanTransactionHelper.approveLoanWithApproveAmount(approveDate, expectedDisbursementDate, approvalAmount,
|
||||
loanID, approveTranches);
|
||||
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Negative test case: Approved amount non zero is greater than proposed
|
||||
* amount
|
||||
*/
|
||||
@Test
|
||||
public void loanApplicationApprovedAmountGreaterThanProposedAmount() {
|
||||
|
||||
final String proposedAmount = "5000";
|
||||
final String approvalAmount = "9000";
|
||||
final String approveDate = "20 September 2011";
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2012");
|
||||
final Integer loanProductID = this.loanTransactionHelper.getLoanProductId(new LoanProductTestBuilder().build(null));
|
||||
final Integer loanID = applyForLoanApplication(clientID, loanProductID, proposedAmount);
|
||||
|
||||
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
|
||||
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
|
||||
|
||||
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpecForStatusCode403);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<HashMap> error = (List<HashMap>) this.loanTransactionHelper.approveLoan(approveDate, approvalAmount, loanID,
|
||||
CommonConstants.RESPONSE_ERROR);
|
||||
|
||||
assertEquals("error.msg.loan.approval.amount.can't.be.greater.than.loan.amount.demanded",
|
||||
error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
}
|
||||
|
||||
public HashMap createTrancheDetail(final String date, final String amount) {
|
||||
HashMap<String, Object> detail = new HashMap<>();
|
||||
detail.put("expectedDisbursementDate", date);
|
||||
detail.put("principal", amount);
|
||||
|
||||
return detail;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loanApplicationApprovalAndValidationForMultiDisburseLoans() {
|
||||
|
||||
List<HashMap> createTranches = new ArrayList<>();
|
||||
createTranches.add(createTrancheDetail("1 March 2014", "1000"));
|
||||
createTranches.add(createTrancheDetail("23 March 2014", "4000"));
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2014");
|
||||
System.out.println("---------------------------------CLIENT CREATED WITH ID---------------------------------------------------"
|
||||
+ clientID);
|
||||
|
||||
final Integer loanProductID = this.loanTransactionHelper.getLoanProductId(new LoanProductTestBuilder()
|
||||
.withInterestTypeAsDecliningBalance().withTranches(true).withInterestCalculationPeriodTypeAsRepaymentPeriod(true)
|
||||
.build(null));
|
||||
System.out.println("----------------------------------LOAN PRODUCT CREATED WITH ID-------------------------------------------"
|
||||
+ loanProductID);
|
||||
|
||||
this.trancheLoansApprovedAmountLesserThanProposedAmount(clientID, loanProductID, createTranches);
|
||||
this.trancheLoansApprovalValidation(clientID, loanProductID, createTranches);
|
||||
|
||||
}
|
||||
|
||||
private void trancheLoansApprovedAmountLesserThanProposedAmount(Integer clientID, Integer loanProductID, List<HashMap> createTranches) {
|
||||
final String proposedAmount = "5000";
|
||||
final String approvalAmount = "2000";
|
||||
final String approveDate = "1 March 2014";
|
||||
final String expectedDisbursementDate = "1 March 2014";
|
||||
|
||||
List<HashMap> approveTranches = new ArrayList<>();
|
||||
approveTranches.add(createTrancheDetail("1 March 2014", "1000"));
|
||||
approveTranches.add(createTrancheDetail("23 March 2014", "1000"));
|
||||
|
||||
final Integer loanID = applyForLoanApplicationWithTranches(clientID, loanProductID, proposedAmount, createTranches);
|
||||
System.out.println("-----------------------------------LOAN CREATED WITH LOANID-------------------------------------------------"
|
||||
+ loanID);
|
||||
|
||||
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
|
||||
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
|
||||
|
||||
System.out.println("-----------------------------------APPROVE LOAN-----------------------------------------------------------");
|
||||
loanStatusHashMap = this.loanTransactionHelper.approveLoanWithApproveAmount(approveDate, expectedDisbursementDate, approvalAmount,
|
||||
loanID, approveTranches);
|
||||
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
|
||||
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
|
||||
System.out
|
||||
.println("-----------------------------------MULTI DISBURSAL LOAN APPROVED SUCCESSFULLY---------------------------------------");
|
||||
|
||||
}
|
||||
|
||||
private void trancheLoansApprovalValidation(Integer clientID, Integer loanProductID, List<HashMap> createTranches) {
|
||||
final String proposedAmount = "5000";
|
||||
final String approvalAmount1 = "10000";
|
||||
final String approvalAmount2 = "3000";
|
||||
final String approvalAmount3 = "400";
|
||||
final String approvalAmount4 = "200";
|
||||
|
||||
final String approveDate = "1 March 2014";
|
||||
final String expectedDisbursementDate = "1 March 2014";
|
||||
|
||||
List<HashMap> approveTranche1 = new ArrayList<>();
|
||||
approveTranche1.add(createTrancheDetail("1 March 2014", "5000"));
|
||||
approveTranche1.add(createTrancheDetail("23 March 2014", "5000"));
|
||||
|
||||
List<HashMap> approveTranche2 = new ArrayList<>();
|
||||
approveTranche2.add(createTrancheDetail("1 March 2014", "1000"));
|
||||
approveTranche2.add(createTrancheDetail("23 March 2014", "1000"));
|
||||
approveTranche2.add(createTrancheDetail("23 March 2014", "1000"));
|
||||
|
||||
List<HashMap> approveTranche3 = new ArrayList<>();
|
||||
approveTranche3.add(createTrancheDetail("1 March 2014", "100"));
|
||||
approveTranche3.add(createTrancheDetail("23 March 2014", "100"));
|
||||
approveTranche3.add(createTrancheDetail("24 March 2014", "100"));
|
||||
approveTranche3.add(createTrancheDetail("25 March 2014", "100"));
|
||||
|
||||
List<HashMap> approveTranche4 = new ArrayList<>();
|
||||
approveTranche4.add(createTrancheDetail("1 March 2014", "100"));
|
||||
approveTranche4.add(createTrancheDetail("23 March 2014", "100"));
|
||||
approveTranche4.add(createTrancheDetail("24 March 2014", "100"));
|
||||
|
||||
final Integer loanID = applyForLoanApplicationWithTranches(clientID, loanProductID, proposedAmount, createTranches);
|
||||
System.out.println("-----------------------------------LOAN CREATED WITH LOANID-------------------------------------------------"
|
||||
+ loanID);
|
||||
|
||||
HashMap<String, Object> loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
|
||||
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
|
||||
|
||||
System.out.println("-----------------------------------APPROVE LOAN-----------------------------------------------------------");
|
||||
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpecForStatusCode400);
|
||||
|
||||
/* Tranches with same expected disbursement date */
|
||||
List<HashMap<String, Object>> error = this.loanTransactionHelper.approveLoanForTranches(approveDate, expectedDisbursementDate,
|
||||
approvalAmount2, loanID, approveTranche2, CommonConstants.RESPONSE_ERROR);
|
||||
assertEquals("validation.msg.loan.expectedDisbursementDate.disbursement.date.must.be.unique.for.tranches",
|
||||
error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
/* Sum of tranches is greater than approved amount */
|
||||
error = this.loanTransactionHelper.approveLoanForTranches(approveDate, expectedDisbursementDate, approvalAmount4, loanID,
|
||||
approveTranche4, CommonConstants.RESPONSE_ERROR);
|
||||
assertEquals("validation.msg.loan.principal.sum.of.multi.disburse.amounts.must.be.equal.to.or.lesser.than.approved.principal",
|
||||
error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpecForStatusCode403);
|
||||
|
||||
/* Sum of tranches exceeds the proposed amount */
|
||||
error = this.loanTransactionHelper.approveLoanForTranches(approveDate, expectedDisbursementDate, approvalAmount1, loanID,
|
||||
approveTranche1, CommonConstants.RESPONSE_ERROR);
|
||||
assertEquals("error.msg.loan.approval.amount.can't.be.greater.than.loan.amount.demanded",
|
||||
error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
/* No. of tranches exceeds the max tranche count at product level */
|
||||
error = this.loanTransactionHelper.approveLoanForTranches(approveDate, expectedDisbursementDate, approvalAmount3, loanID,
|
||||
approveTranche3, CommonConstants.RESPONSE_ERROR);
|
||||
assertEquals("error.msg.disbursementData.exceeding.max.tranche.count", error.get(0)
|
||||
.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
/* If tranches are not specified for a multi-disburse loan */
|
||||
/**
|
||||
* error =
|
||||
* this.loanTransactionHelper.approveLoanForTranches(approveDate,
|
||||
* expectedDisbursementDate, approvalAmount5, loanID, approveTranche5,
|
||||
* CommonConstants.RESPONSE_ERROR);
|
||||
* assertEquals("error.msg.disbursementData.required",
|
||||
* error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
**/
|
||||
}
|
||||
|
||||
private Integer applyForLoanApplication(final Integer clientID, final Integer loanProductID, final String proposedAmount) {
|
||||
final String loanApplication = new LoanApplicationTestBuilder().withPrincipal(proposedAmount).withLoanTermFrequency("5")
|
||||
.withLoanTermFrequencyAsMonths().withNumberOfRepayments("5").withRepaymentEveryAfter("1")
|
||||
.withRepaymentFrequencyTypeAsMonths().withInterestRatePerPeriod("2").withExpectedDisbursementDate("04 April 2012")
|
||||
.withSubmittedOnDate("02 April 2012").build(clientID.toString(), loanProductID.toString(), null);
|
||||
return this.loanTransactionHelper.getLoanId(loanApplication);
|
||||
}
|
||||
|
||||
public Integer applyForLoanApplicationWithTranches(final Integer clientID, final Integer loanProductID, String principal,
|
||||
List<HashMap> tranches) {
|
||||
System.out.println("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------");
|
||||
final String loanApplicationJSON = new LoanApplicationTestBuilder()
|
||||
//
|
||||
.withPrincipal(principal)
|
||||
//
|
||||
.withLoanTermFrequency("5")
|
||||
//
|
||||
.withLoanTermFrequencyAsMonths()
|
||||
//
|
||||
.withNumberOfRepayments("5").withRepaymentEveryAfter("1").withRepaymentFrequencyTypeAsMonths() //
|
||||
.withInterestRatePerPeriod("2") //
|
||||
.withExpectedDisbursementDate("1 March 2014") //
|
||||
.withTranches(tranches) //
|
||||
.withInterestTypeAsDecliningBalance() //
|
||||
.withSubmittedOnDate("1 March 2014") //
|
||||
.build(clientID.toString(), loanProductID.toString(), null);
|
||||
|
||||
return this.loanTransactionHelper.getLoanId(loanApplicationJSON);
|
||||
}
|
||||
|
||||
}
|
||||
+157
@@ -0,0 +1,157 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.fineract.integrationtests.LoanApplicationApprovalTest;
|
||||
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanStatusChecker;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
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;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class LoanApplicationUndoLastTrancheTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private LoanTransactionHelper loanTransactionHelper;
|
||||
private LoanApplicationApprovalTest loanApplicationApprovalTest;
|
||||
|
||||
@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.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
|
||||
this.loanApplicationApprovalTest = new LoanApplicationApprovalTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void LoanApplicationUndoLastTranche() {
|
||||
|
||||
final String proposedAmount = "5000";
|
||||
final String approvalAmount = "2000";
|
||||
final String approveDate = "1 March 2014";
|
||||
final String expectedDisbursementDate = "1 March 2014";
|
||||
final String disbursalDate = "1 March 2014";
|
||||
|
||||
// CREATE CLIENT
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2014");
|
||||
System.out.println("---------------------------------CLIENT CREATED WITH ID---------------------------------------------------"
|
||||
+ clientID);
|
||||
|
||||
// CREATE LOAN MULTIDISBURSAL PRODUCT
|
||||
final Integer loanProductID = this.loanTransactionHelper.getLoanProductId(new LoanProductTestBuilder()
|
||||
.withInterestTypeAsDecliningBalance().withTranches(true).withInterestCalculationPeriodTypeAsRepaymentPeriod(true)
|
||||
.build(null));
|
||||
System.out.println("----------------------------------LOAN PRODUCT CREATED WITH ID-------------------------------------------"
|
||||
+ loanProductID);
|
||||
|
||||
// CREATE TRANCHES
|
||||
List<HashMap> createTranches = new ArrayList<>();
|
||||
createTranches.add(this.loanApplicationApprovalTest.createTrancheDetail("1 March 2014", "1000"));
|
||||
createTranches.add(this.loanApplicationApprovalTest.createTrancheDetail("23 June 2014", "4000"));
|
||||
|
||||
// APPROVE TRANCHES
|
||||
List<HashMap> approveTranches = new ArrayList<>();
|
||||
approveTranches.add(this.loanApplicationApprovalTest.createTrancheDetail("1 March 2014", "1000"));
|
||||
approveTranches.add(this.loanApplicationApprovalTest.createTrancheDetail("23 June 2014", "1000"));
|
||||
|
||||
// APPLY FOR LOAN WITH TRANCHES
|
||||
final Integer loanID = applyForLoanApplicationWithTranches(clientID, loanProductID, proposedAmount, createTranches);
|
||||
System.out.println("-----------------------------------LOAN CREATED WITH LOANID-------------------------------------------------"
|
||||
+ loanID);
|
||||
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
|
||||
|
||||
// VALIDATE THE LOAN STATUS
|
||||
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
|
||||
|
||||
System.out.println("-----------------------------------APPROVE LOAN-----------------------------------------------------------");
|
||||
loanStatusHashMap = this.loanTransactionHelper.approveLoanWithApproveAmount(approveDate, expectedDisbursementDate, approvalAmount,
|
||||
loanID, approveTranches);
|
||||
|
||||
// VALIDATE THE LOAN IS APPROVED
|
||||
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
|
||||
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
|
||||
|
||||
// DISBURSE A LOAN
|
||||
this.loanTransactionHelper.disburseLoan(disbursalDate, loanID);
|
||||
loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
|
||||
|
||||
// VALIDATE THE LOAN IS ACTIVE STATUS
|
||||
LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
|
||||
|
||||
System.out.println("-------------Make repayment 1-----------");
|
||||
this.loanTransactionHelper.makeRepayment("01 April 2014", Float.valueOf("420"), loanID);
|
||||
System.out.println("-------------Make repayment 2-----------");
|
||||
this.loanTransactionHelper.makeRepayment("01 May 2014", Float.valueOf("412"), loanID);
|
||||
System.out.println("-------------Make repayment 3-----------");
|
||||
this.loanTransactionHelper.makeRepayment("01 June 2014", Float.valueOf("204"), loanID);
|
||||
// DISBURSE A SECOND TRANCHE
|
||||
this.loanTransactionHelper.disburseLoan("23 June 2014", loanID);
|
||||
// UNDO LAST TRANCHE
|
||||
Float disbursedAmount = this.loanTransactionHelper.undoLastDisbursal(loanID);
|
||||
validateDisbursedAmount(disbursedAmount);
|
||||
}
|
||||
|
||||
private void validateDisbursedAmount(Float disbursedAmount) {
|
||||
Assert.assertEquals(Float.valueOf("1000.0"), disbursedAmount);
|
||||
|
||||
}
|
||||
|
||||
public Integer applyForLoanApplicationWithTranches(final Integer clientID, final Integer loanProductID, String principal,
|
||||
List<HashMap> tranches) {
|
||||
System.out.println("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------");
|
||||
final String loanApplicationJSON = new LoanApplicationTestBuilder()
|
||||
//
|
||||
.withPrincipal(principal)
|
||||
//
|
||||
.withLoanTermFrequency("5")
|
||||
//
|
||||
.withLoanTermFrequencyAsMonths()
|
||||
//
|
||||
.withNumberOfRepayments("5").withRepaymentEveryAfter("1").withRepaymentFrequencyTypeAsMonths() //
|
||||
.withInterestRatePerPeriod("2") //
|
||||
.withExpectedDisbursementDate("1 March 2014") //
|
||||
.withTranches(tranches) //
|
||||
.withInterestTypeAsDecliningBalance() //
|
||||
.withSubmittedOnDate("1 March 2014") //
|
||||
.build(clientID.toString(), loanProductID.toString(), null);
|
||||
|
||||
return this.loanTransactionHelper.getLoanId(loanApplicationJSON);
|
||||
}
|
||||
|
||||
}
|
||||
+501
@@ -0,0 +1,501 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.MathContext;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanDisbursementTestBuilder;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanStatusChecker;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
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;
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public class LoanDisbursementDetailsIntegrationTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private LoanTransactionHelper loanTransactionHelper;
|
||||
private Integer loanID;
|
||||
private Integer disbursementId;
|
||||
final String approveDate = "01 March 2014";
|
||||
final String expectedDisbursementDate = "01 March 2014";
|
||||
final String proposedAmount = "5000";
|
||||
final String approvalAmount = "5000";
|
||||
|
||||
@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.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createAndValidateMultiDisburseLoansBasedOnEmi() {
|
||||
List<HashMap> createTranches = new ArrayList<>();
|
||||
String id = null;
|
||||
String installmentAmount = "800";
|
||||
String withoutInstallmentAmount = "";
|
||||
String proposedAmount = "10000";
|
||||
createTranches.add(this.loanTransactionHelper.createTrancheDetail(id, "01 June 2015", "5000"));
|
||||
createTranches.add(this.loanTransactionHelper.createTrancheDetail(id, "01 Sep 2015", "5000"));
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2014");
|
||||
System.out.println("---------------------------------CLIENT CREATED WITH ID---------------------------------------------------"
|
||||
+ clientID);
|
||||
|
||||
final Integer loanProductID = this.loanTransactionHelper.getLoanProductId(new LoanProductTestBuilder()
|
||||
.withInterestTypeAsDecliningBalance().withMoratorium("", "").withAmortizationTypeAsEqualInstallments().withTranches(true)
|
||||
.withInterestCalculationPeriodTypeAsRepaymentPeriod(true).build(null));
|
||||
System.out.println("----------------------------------LOAN PRODUCT CREATED WITH ID-------------------------------------------"
|
||||
+ loanProductID);
|
||||
|
||||
final Integer loanIDWithEmi = applyForLoanApplicationWithEmiAmount(clientID, loanProductID, proposedAmount, createTranches,
|
||||
installmentAmount);
|
||||
|
||||
System.out
|
||||
.println("-----------------------------------LOAN CREATED WITH EMI LOANID-------------------------------------------------"
|
||||
+ loanIDWithEmi);
|
||||
|
||||
HashMap repaymentScheduleWithEmi = (HashMap) this.loanTransactionHelper.getLoanDetail(this.requestSpec, this.responseSpec,
|
||||
loanIDWithEmi, "repaymentSchedule");
|
||||
|
||||
ArrayList<HashMap> periods = (ArrayList<HashMap>) repaymentScheduleWithEmi.get("periods");
|
||||
assertEquals(periods.size(), 15);
|
||||
|
||||
this.validateRepaymentScheduleWithEMI(periods);
|
||||
|
||||
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanIDWithEmi);
|
||||
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
|
||||
|
||||
System.out.println("-----------------------------------APPROVE LOAN-----------------------------------------------------------");
|
||||
loanStatusHashMap = this.loanTransactionHelper.approveLoanWithApproveAmount("01 June 2015", "01 June 2015", "10000", loanIDWithEmi,
|
||||
createTranches);
|
||||
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
|
||||
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
|
||||
System.out
|
||||
.println("-----------------------------------MULTI DISBURSAL LOAN WITH EMI APPROVED SUCCESSFULLY---------------------------------------");
|
||||
|
||||
final Integer loanIDWithoutEmi = applyForLoanApplicationWithEmiAmount(clientID, loanProductID, proposedAmount, createTranches,
|
||||
withoutInstallmentAmount);
|
||||
|
||||
HashMap repaymentScheduleWithoutEmi = (HashMap) this.loanTransactionHelper.getLoanDetail(this.requestSpec, this.responseSpec,
|
||||
loanIDWithoutEmi, "repaymentSchedule");
|
||||
|
||||
ArrayList<HashMap> periods1 = (ArrayList<HashMap>) repaymentScheduleWithEmi.get("periods");
|
||||
assertEquals(periods1.size(), 15);
|
||||
|
||||
System.out
|
||||
.println("-----------------------------------LOAN CREATED WITHOUT EMI LOANID-------------------------------------------------"
|
||||
+ loanIDWithoutEmi);
|
||||
|
||||
/* To be uncommented once issue MIFOSX-2006 is closed. */
|
||||
// this.validateRepaymentScheduleWithoutEMI(periods1);
|
||||
|
||||
HashMap loanStatusMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanIDWithoutEmi);
|
||||
LoanStatusChecker.verifyLoanIsPending(loanStatusMap);
|
||||
|
||||
System.out.println("-----------------------------------APPROVE LOAN-----------------------------------------------------------");
|
||||
loanStatusHashMap = this.loanTransactionHelper.approveLoanWithApproveAmount("01 June 2015", "01 June 2015", "10000",
|
||||
loanIDWithoutEmi, createTranches);
|
||||
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
|
||||
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
|
||||
System.out
|
||||
.println("-----------------------------------MULTI DISBURSAL LOAN WITHOUT EMI APPROVED SUCCESSFULLY---------------------------------------");
|
||||
|
||||
}
|
||||
|
||||
private void validateRepaymentScheduleWithEMI(ArrayList<HashMap> periods) {
|
||||
LoanDisbursementTestBuilder expectedRepaymentSchedule0 = new LoanDisbursementTestBuilder("[2015, 6, 1]", 0.0f, 0.0f, null, null,
|
||||
5000.0f, null, null, null);
|
||||
|
||||
LoanDisbursementTestBuilder expectedRepaymentSchedule1 = new LoanDisbursementTestBuilder("[2015, 7, 1]", 800f, 800.0f, 50.0f,
|
||||
750.0f, 4250.0f, 750.0f, 750.0f, "[2015, 6, 1]");
|
||||
|
||||
LoanDisbursementTestBuilder expectedRepaymentSchedule2 = new LoanDisbursementTestBuilder("[2015, 8, 1]", 800.0f, 800.0f, 42.5f,
|
||||
757.5f, 3492.5f, 757.5f, 757.5f, "[2015, 7, 1]");
|
||||
|
||||
LoanDisbursementTestBuilder expectedRepaymentSchedule3 = new LoanDisbursementTestBuilder("[2015, 9, 1]", 0.0f, 0.0f, null, null,
|
||||
5000.0f, null, null, null);
|
||||
|
||||
LoanDisbursementTestBuilder expectedRepaymentSchedule4 = new LoanDisbursementTestBuilder("[2015, 9, 1]", 800.0f, 800.0f, 34.92f,
|
||||
765.08f, 7727.42f, 765.08f, 765.08f, "[2015, 8, 1]");
|
||||
|
||||
LoanDisbursementTestBuilder expectedRepaymentSchedule5 = new LoanDisbursementTestBuilder("[2015, 10, 1]", 800.0f, 800.0f, 77.27f,
|
||||
722.73f, 7004.69f, 722.73f, 722.73f, "[2015, 9, 1]");
|
||||
|
||||
LoanDisbursementTestBuilder expectedRepaymentSchedule6 = new LoanDisbursementTestBuilder("[2015, 11, 1]", 800.0f, 800.0f, 70.05f,
|
||||
729.95f, 6274.74f, 729.95f, 729.95f, "[2015, 10, 1]");
|
||||
|
||||
LoanDisbursementTestBuilder expectedRepaymentSchedule7 = new LoanDisbursementTestBuilder("[2015, 12, 1]", 800.0f, 800.0f, 62.75f,
|
||||
737.25f, 5537.49f, 737.25f, 737.25f, "[2015, 11, 1]");
|
||||
|
||||
LoanDisbursementTestBuilder expectedRepaymentSchedule8 = new LoanDisbursementTestBuilder("[2016, 1, 1]", 800.0f, 800.0f, 55.37f,
|
||||
744.63f, 4792.86f, 744.63f, 744.63f, "[2015, 12, 1]");
|
||||
|
||||
LoanDisbursementTestBuilder expectedRepaymentSchedule9 = new LoanDisbursementTestBuilder("[2016, 2, 1]", 800.0f, 800.0f, 47.93f,
|
||||
752.07f, 4040.79f, 752.07f, 752.07f, "[2016, 1, 1]");
|
||||
|
||||
LoanDisbursementTestBuilder expectedRepaymentSchedule10 = new LoanDisbursementTestBuilder("[2016, 3, 1]", 800.0f, 800.0f, 40.41f,
|
||||
759.59f, 3281.2f, 759.59f, 759.59f, "[2016, 2, 1]");
|
||||
|
||||
LoanDisbursementTestBuilder expectedRepaymentSchedule11 = new LoanDisbursementTestBuilder("[2016, 4, 1]", 800.0f, 800.0f, 32.81f,
|
||||
767.19f, 2514.01f, 767.19f, 767.19f, "[2016, 3, 1]");
|
||||
|
||||
LoanDisbursementTestBuilder expectedRepaymentSchedule12 = new LoanDisbursementTestBuilder("[2016, 5, 1]", 800.0f, 800.0f, 25.14f,
|
||||
774.86f, 1739.15f, 774.86f, 774.86f, "[2016, 4, 1]");
|
||||
|
||||
LoanDisbursementTestBuilder expectedRepaymentSchedule13 = new LoanDisbursementTestBuilder("[2016, 6, 1]", 800.0f, 800.0f, 17.39f,
|
||||
782.61f, 956.54f, 782.61f, 782.61f, "[2016, 5, 1]");
|
||||
|
||||
LoanDisbursementTestBuilder expectedRepaymentSchedule14 = new LoanDisbursementTestBuilder("[2016, 7, 1]", 966.11f, 966.11f, 9.57f,
|
||||
956.54f, 0.0f, 956.54f, 956.54f, "[2016, 6, 1]");
|
||||
|
||||
ArrayList<LoanDisbursementTestBuilder> list = new ArrayList<LoanDisbursementTestBuilder>();
|
||||
list.add(expectedRepaymentSchedule0);
|
||||
list.add(expectedRepaymentSchedule1);
|
||||
list.add(expectedRepaymentSchedule2);
|
||||
list.add(expectedRepaymentSchedule3);
|
||||
list.add(expectedRepaymentSchedule4);
|
||||
list.add(expectedRepaymentSchedule5);
|
||||
list.add(expectedRepaymentSchedule6);
|
||||
list.add(expectedRepaymentSchedule7);
|
||||
list.add(expectedRepaymentSchedule8);
|
||||
list.add(expectedRepaymentSchedule9);
|
||||
list.add(expectedRepaymentSchedule10);
|
||||
list.add(expectedRepaymentSchedule11);
|
||||
list.add(expectedRepaymentSchedule12);
|
||||
list.add(expectedRepaymentSchedule13);
|
||||
list.add(expectedRepaymentSchedule14);
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
this.assertRepaymentScheduleValuesWithEMI(periods.get(i), list.get(i), i);
|
||||
}
|
||||
}
|
||||
|
||||
private void assertRepaymentScheduleValuesWithEMI(HashMap period, LoanDisbursementTestBuilder expectedRepaymentSchedule, int position) {
|
||||
|
||||
assertEquals(period.get("dueDate").toString(), expectedRepaymentSchedule.getDueDate());
|
||||
assertEquals(period.get("principalLoanBalanceOutstanding"), expectedRepaymentSchedule.getPrincipalLoanBalanceOutstanding());
|
||||
System.out.println(period.get("totalOriginalDueForPeriod").toString());
|
||||
assertEquals(new Float(period.get("totalOriginalDueForPeriod").toString()), expectedRepaymentSchedule
|
||||
.getTotalOriginalDueForPeriod().floatValue(), 0.0f);
|
||||
|
||||
assertEquals(new Float(period.get("totalOutstandingForPeriod").toString()).floatValue(),
|
||||
expectedRepaymentSchedule.getTotalOutstandingForPeriod(), 0.0f);
|
||||
|
||||
if (position != 0 && position != 3) {
|
||||
|
||||
assertEquals(new Float(period.get("interestOutstanding").toString()).floatValue(),
|
||||
expectedRepaymentSchedule.getInterestOutstanding(), 0.0f);
|
||||
assertEquals(new Float(period.get("principalOutstanding").toString()).floatValue(),
|
||||
expectedRepaymentSchedule.getPrincipalOutstanding(), 0.0f);
|
||||
assertEquals(new Float(period.get("principalDue").toString()).floatValue(), expectedRepaymentSchedule.getPrincipalDue(), 0.0f);
|
||||
assertEquals(new Float(period.get("principalOriginalDue").toString()).floatValue(),
|
||||
expectedRepaymentSchedule.getPrincipalOriginalDue(), 0.0f);
|
||||
assertEquals(period.get("fromDate").toString(), expectedRepaymentSchedule.getFromDate());
|
||||
}
|
||||
}
|
||||
|
||||
/* Uncomment and modify test builder values once MIFOSX-2006 is closed. */
|
||||
/*
|
||||
* private void validateRepaymentScheduleWithoutEMI(ArrayList<HashMap>
|
||||
* periods){ LoanDisbursementTestBuilder expectedRepaymentSchedule0 = new
|
||||
* LoanDisbursementTestBuilder( "[2015, 6, 1]", 0.0f, 0.0f, null, null,
|
||||
* 5000.0f, null, null, null);
|
||||
*
|
||||
* LoanDisbursementTestBuilder expectedRepaymentSchedule1 = new
|
||||
* LoanDisbursementTestBuilder( "[2015, 7, 1]", 800.0f, 800.0f, 50.0f,
|
||||
* 750.0f, 4250.0f, 750.0f, 750.0f, "[2015, 6, 1]");
|
||||
*
|
||||
* LoanDisbursementTestBuilder expectedRepaymentSchedule2 = new
|
||||
* LoanDisbursementTestBuilder( "[2015, 8, 1]", 800.0f, 800.0f, 42.5f,
|
||||
* 757.5f, 3492.5f, 757.5f, 757.5f, "[2015, 7, 1]");
|
||||
*
|
||||
* LoanDisbursementTestBuilder expectedRepaymentSchedule3 = new
|
||||
* LoanDisbursementTestBuilder( "[2015, 9, 1]", 0.0f, 0.0f, null, null,
|
||||
* 5000.0f, null, null, null);
|
||||
*
|
||||
* LoanDisbursementTestBuilder expectedRepaymentSchedule4 = new
|
||||
* LoanDisbursementTestBuilder( "[2015, 9, 1]", 800.0f, 800.0f, 34.92f,
|
||||
* 765.08f, 7727.42f, 765.08f, 765.08f, "[2015, 8, 1]");
|
||||
*
|
||||
* LoanDisbursementTestBuilder expectedRepaymentSchedule5 = new
|
||||
* LoanDisbursementTestBuilder( "[2015, 10, 1]", 800.0f, 800.0f, 77.27f,
|
||||
* 722.73f, 7004.69f, 722.73f, 722.73f, "[2015, 9, 1]");
|
||||
*
|
||||
* LoanDisbursementTestBuilder expectedRepaymentSchedule6 = new
|
||||
* LoanDisbursementTestBuilder( "[2015, 11, 1]", 800.0f, 800.0f, 70.05f,
|
||||
* 729.95f, 6274.74f, 729.95f, 729.95f, "[2015, 10, 1]");
|
||||
*
|
||||
* LoanDisbursementTestBuilder expectedRepaymentSchedule7 = new
|
||||
* LoanDisbursementTestBuilder( "[2015, 12, 1]", 800.0f, 800.0f, 62.75f,
|
||||
* 737.25f, 5537.49f, 737.25f, 737.25f, "[2015, 11, 1]");
|
||||
*
|
||||
* LoanDisbursementTestBuilder expectedRepaymentSchedule8 = new
|
||||
* LoanDisbursementTestBuilder( "[2016, 1, 1]", 800.0f, 800.0f, 55.37f,
|
||||
* 744.63f, 4792.86f, 744.63f, 744.63f, "[2015, 12, 1]");
|
||||
*
|
||||
* LoanDisbursementTestBuilder expectedRepaymentSchedule9 = new
|
||||
* LoanDisbursementTestBuilder( "[2016, 2, 1]", 800.0f, 800.0f, 47.93f,
|
||||
* 752.07f, 4040.79f, 752.07f, 752.07f, "[2016, 1, 1]");
|
||||
*
|
||||
* LoanDisbursementTestBuilder expectedRepaymentSchedule10 = new
|
||||
* LoanDisbursementTestBuilder( "[2016, 3, 1]", 800.0f, 800.0f, 40.41f,
|
||||
* 759.59f, 3281.2f, 759.59f, 759.59f, "[2016, 2, 1]");
|
||||
*
|
||||
* LoanDisbursementTestBuilder expectedRepaymentSchedule11 = new
|
||||
* LoanDisbursementTestBuilder( "[2016, 4, 1]", 800.0f, 800.0f, 32.81f,
|
||||
* 767.19f, 2514.01f, 767.19f, 767.19f, "[2016, 3, 1]");
|
||||
*
|
||||
* LoanDisbursementTestBuilder expectedRepaymentSchedule12 = new
|
||||
* LoanDisbursementTestBuilder( "[2016, 5, 1]", 800.0f, 800.0f, 25.14f,
|
||||
* 774.86f, 1739.15f, 774.86f, 774.86f, "[2016, 4, 1]");
|
||||
*
|
||||
* LoanDisbursementTestBuilder expectedRepaymentSchedule13 = new
|
||||
* LoanDisbursementTestBuilder( "[2016, 6, 1]", 800.0f, 800.0f, 17.39f,
|
||||
* 782.61f, 956.54f, 782.61f, 782.61f, "[2016, 5, 1]");
|
||||
*
|
||||
* LoanDisbursementTestBuilder expectedRepaymentSchedule14 = new
|
||||
* LoanDisbursementTestBuilder( "[2016, 7, 1]", 966.11f, 966.11f, 9.57f,
|
||||
* 956.54f, 0.0f, 956.54f, 956.54f, "[2016, 6, 1]");
|
||||
*
|
||||
* ArrayList<LoanDisbursementTestBuilder> list = new
|
||||
* ArrayList<LoanDisbursementTestBuilder>();
|
||||
* list.add(expectedRepaymentSchedule0);
|
||||
* list.add(expectedRepaymentSchedule1);
|
||||
* list.add(expectedRepaymentSchedule2);
|
||||
* list.add(expectedRepaymentSchedule3);
|
||||
* list.add(expectedRepaymentSchedule4);
|
||||
* list.add(expectedRepaymentSchedule5);
|
||||
* list.add(expectedRepaymentSchedule6);
|
||||
* list.add(expectedRepaymentSchedule7);
|
||||
* list.add(expectedRepaymentSchedule8);
|
||||
* list.add(expectedRepaymentSchedule9);
|
||||
* list.add(expectedRepaymentSchedule10);
|
||||
* list.add(expectedRepaymentSchedule11);
|
||||
* list.add(expectedRepaymentSchedule12);
|
||||
* list.add(expectedRepaymentSchedule13);
|
||||
* list.add(expectedRepaymentSchedule14);
|
||||
*
|
||||
* for (int i = 0; i < list.size(); i++) {
|
||||
* this.assertRepaymentScheduleValuesWithoutEMI(periods.get(i), list.get(i),
|
||||
* i); } }
|
||||
*
|
||||
* private void assertRepaymentScheduleValuesWithoutEMI(HashMap period,
|
||||
* LoanDisbursementTestBuilder expectedRepaymentSchedule, int position) {
|
||||
*
|
||||
* assertEquals(period.get("dueDate").toString(),
|
||||
* expectedRepaymentSchedule.getDueDate());
|
||||
* assertEquals(period.get("principalLoanBalanceOutstanding"),
|
||||
* expectedRepaymentSchedule.getPrincipalLoanBalanceOutstanding());
|
||||
* assertEquals(period.get("totalOriginalDueForPeriod"),
|
||||
* expectedRepaymentSchedule.getTotalOriginalDueForPeriod());
|
||||
* assertEquals(period.get("totalOutstandingForPeriod"),
|
||||
* expectedRepaymentSchedule.getTotalOutstandingForPeriod());
|
||||
*
|
||||
* if (position != 0 && position != 3) {
|
||||
*
|
||||
* assertEquals(period.get("interestOutstanding"),
|
||||
* expectedRepaymentSchedule.getInterestOutstanding());
|
||||
* assertEquals(period.get("principalOutstanding"),
|
||||
* expectedRepaymentSchedule.getPrincipalOutstanding());
|
||||
* assertEquals(period.get("principalDue"),
|
||||
* expectedRepaymentSchedule.getPrincipalDue());
|
||||
* assertEquals(period.get("principalOriginalDue"),
|
||||
* expectedRepaymentSchedule.getPrincipalOriginalDue());
|
||||
* assertEquals(period.get("fromDate").toString(),
|
||||
* expectedRepaymentSchedule.getFromDate()); } }
|
||||
*/
|
||||
private Integer applyForLoanApplicationWithEmiAmount(final Integer clientID, final Integer loanProductID, final String proposedAmount,
|
||||
List<HashMap> tranches, final String installmentAmount) {
|
||||
|
||||
System.out.println("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------");
|
||||
final String loanApplicationJSON = new LoanApplicationTestBuilder()
|
||||
//
|
||||
.withPrincipal(proposedAmount)
|
||||
//
|
||||
.withLoanTermFrequency("12")
|
||||
//
|
||||
.withLoanTermFrequencyAsMonths()
|
||||
//
|
||||
.withNumberOfRepayments("12").withRepaymentEveryAfter("1").withRepaymentFrequencyTypeAsMonths() //
|
||||
.withInterestRatePerPeriod("1") //
|
||||
.withExpectedDisbursementDate("01 June 2015") //
|
||||
.withTranches(tranches) //
|
||||
.withFixedEmiAmount(installmentAmount) //
|
||||
.withInterestTypeAsDecliningBalance() //
|
||||
.withSubmittedOnDate("01 June 2015") //
|
||||
.withAmortizationTypeAsEqualInstallments() //
|
||||
.build(clientID.toString(), loanProductID.toString(), null);
|
||||
|
||||
return this.loanTransactionHelper.getLoanId(loanApplicationJSON);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createApproveAndValidateMultiDisburseLoan() {
|
||||
|
||||
List<HashMap> createTranches = new ArrayList<>();
|
||||
String id = null;
|
||||
createTranches.add(this.loanTransactionHelper.createTrancheDetail(id, "01 March 2014", "1000"));
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2014");
|
||||
System.out.println("---------------------------------CLIENT CREATED WITH ID---------------------------------------------------"
|
||||
+ clientID);
|
||||
|
||||
final Integer loanProductID = this.loanTransactionHelper.getLoanProductId(new LoanProductTestBuilder()
|
||||
.withInterestTypeAsDecliningBalance().withTranches(true).withInterestCalculationPeriodTypeAsRepaymentPeriod(true)
|
||||
.build(null));
|
||||
System.out.println("----------------------------------LOAN PRODUCT CREATED WITH ID-------------------------------------------"
|
||||
+ loanProductID);
|
||||
|
||||
this.loanID = applyForLoanApplicationWithTranches(clientID, loanProductID, proposedAmount, createTranches);
|
||||
System.out.println("-----------------------------------LOAN CREATED WITH LOANID-------------------------------------------------"
|
||||
+ loanID);
|
||||
|
||||
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
|
||||
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
|
||||
|
||||
System.out.println("-----------------------------------APPROVE LOAN-----------------------------------------------------------");
|
||||
loanStatusHashMap = this.loanTransactionHelper.approveLoanWithApproveAmount(approveDate, expectedDisbursementDate, approvalAmount,
|
||||
loanID, createTranches);
|
||||
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
|
||||
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
|
||||
System.out
|
||||
.println("-----------------------------------MULTI DISBURSAL LOAN APPROVED SUCCESSFULLY---------------------------------------");
|
||||
ArrayList<HashMap> disbursementDetails = (ArrayList<HashMap>) this.loanTransactionHelper.getLoanDetail(this.requestSpec,
|
||||
this.responseSpec, this.loanID, "disbursementDetails");
|
||||
this.disbursementId = (Integer) disbursementDetails.get(0).get("id");
|
||||
this.editLoanDisbursementDetails();
|
||||
}
|
||||
|
||||
private void editLoanDisbursementDetails() {
|
||||
this.editDateAndPrincipalOfExistingTranche();
|
||||
this.addNewDisbursementDetails();
|
||||
this.deleteDisbursmentDetails();
|
||||
}
|
||||
|
||||
private void addNewDisbursementDetails() {
|
||||
List<HashMap> addTranches = new ArrayList<>();
|
||||
ArrayList<HashMap> disbursementDetails = (ArrayList<HashMap>) this.loanTransactionHelper.getLoanDetail(this.requestSpec,
|
||||
this.responseSpec, this.loanID, "disbursementDetails");
|
||||
ArrayList expectedDisbursementDate = (ArrayList) disbursementDetails.get(0).get("expectedDisbursementDate");
|
||||
String date = formatExpectedDisbursementDate(expectedDisbursementDate.toString());
|
||||
|
||||
String id = null;
|
||||
addTranches.add(this.loanTransactionHelper.createTrancheDetail(disbursementDetails.get(0).get("id").toString(), date,
|
||||
disbursementDetails.get(0).get("principal").toString()));
|
||||
addTranches.add(this.loanTransactionHelper.createTrancheDetail(id, "3 March 2014", "2000"));
|
||||
addTranches.add(this.loanTransactionHelper.createTrancheDetail(id, "4 March 2014", "500"));
|
||||
|
||||
/* Add disbursement detail */
|
||||
this.loanTransactionHelper.addAndDeleteDisbursementDetail(this.loanID, this.approvalAmount, this.expectedDisbursementDate,
|
||||
addTranches, "");
|
||||
}
|
||||
|
||||
private void deleteDisbursmentDetails() {
|
||||
List<HashMap> deleteTranches = new ArrayList<>();
|
||||
ArrayList<HashMap> disbursementDetails = (ArrayList<HashMap>) this.loanTransactionHelper.getLoanDetail(this.requestSpec,
|
||||
this.responseSpec, this.loanID, "disbursementDetails");
|
||||
/* Delete the last tranche */
|
||||
for (int i = 0; i < disbursementDetails.size() - 1; i++) {
|
||||
ArrayList expectedDisbursementDate = (ArrayList) disbursementDetails.get(i).get("expectedDisbursementDate");
|
||||
String disbursementDate = formatExpectedDisbursementDate(expectedDisbursementDate.toString());
|
||||
deleteTranches.add(this.loanTransactionHelper.createTrancheDetail(disbursementDetails.get(i).get("id").toString(),
|
||||
disbursementDate, disbursementDetails.get(i).get("principal").toString()));
|
||||
}
|
||||
|
||||
/* Add disbursement detail */
|
||||
this.loanTransactionHelper.addAndDeleteDisbursementDetail(this.loanID, this.approvalAmount, this.expectedDisbursementDate,
|
||||
deleteTranches, "");
|
||||
}
|
||||
|
||||
private void editDateAndPrincipalOfExistingTranche() {
|
||||
String updatedExpectedDisbursementDate = "01 March 2014";
|
||||
String updatedPrincipal = "900";
|
||||
/* Update */
|
||||
this.loanTransactionHelper.editDisbursementDetail(this.loanID, this.disbursementId, this.approvalAmount,
|
||||
this.expectedDisbursementDate, updatedExpectedDisbursementDate, updatedPrincipal, "");
|
||||
/* Validate Edit */
|
||||
ArrayList<HashMap> disbursementDetails = (ArrayList<HashMap>) this.loanTransactionHelper.getLoanDetail(this.requestSpec,
|
||||
this.responseSpec, this.loanID, "disbursementDetails");
|
||||
assertEquals(Float.valueOf(updatedPrincipal), disbursementDetails.get(0).get("principal"));
|
||||
ArrayList expectedDisbursementDate = (ArrayList) disbursementDetails.get(0).get("expectedDisbursementDate");
|
||||
String date = formatExpectedDisbursementDate(expectedDisbursementDate.toString());
|
||||
assertEquals(updatedExpectedDisbursementDate, date);
|
||||
|
||||
}
|
||||
|
||||
private String formatExpectedDisbursementDate(String expectedDisbursementDate) {
|
||||
|
||||
SimpleDateFormat source = new SimpleDateFormat("[yyyy, MM, dd]");
|
||||
SimpleDateFormat target = new SimpleDateFormat("dd MMMM yyyy");
|
||||
String date = null;
|
||||
try {
|
||||
date = target.format(source.parse(expectedDisbursementDate));
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return date;
|
||||
}
|
||||
|
||||
private Integer applyForLoanApplicationWithTranches(final Integer clientID, final Integer loanProductID, String principal,
|
||||
List<HashMap> tranches) {
|
||||
System.out.println("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------");
|
||||
final String loanApplicationJSON = new LoanApplicationTestBuilder()
|
||||
//
|
||||
.withPrincipal(principal)
|
||||
//
|
||||
.withLoanTermFrequency("5")
|
||||
//
|
||||
.withLoanTermFrequencyAsMonths()
|
||||
//
|
||||
.withNumberOfRepayments("5").withRepaymentEveryAfter("1").withRepaymentFrequencyTypeAsMonths() //
|
||||
.withInterestRatePerPeriod("2") //
|
||||
.withExpectedDisbursementDate("01 March 2014") //
|
||||
.withTranches(tranches) //
|
||||
.withInterestTypeAsDecliningBalance() //
|
||||
.withSubmittedOnDate("01 March 2014") //
|
||||
.build(clientID.toString(), loanProductID.toString(), null);
|
||||
|
||||
return this.loanTransactionHelper.getLoanId(loanApplicationJSON);
|
||||
}
|
||||
|
||||
}
|
||||
+241
@@ -0,0 +1,241 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.accounting.Account;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanStatusChecker;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
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;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class LoanRepaymentRescheduleAtDisbursementTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private LoanTransactionHelper loanTransactionHelper;
|
||||
private LoanApplicationApprovalTest loanApplicationApprovalTest;
|
||||
private ResponseSpecification generalResponseSpec;
|
||||
|
||||
@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.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
|
||||
this.loanApplicationApprovalTest = new LoanApplicationApprovalTest();
|
||||
this.generalResponseSpec = new ResponseSpecBuilder().build();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testLoanRepaymentRescheduleAtDisbursement(){
|
||||
|
||||
final String approvalAmount = "10000";
|
||||
final String approveDate = "01 March 2015";
|
||||
final String expectedDisbursementDate = "01 March 2015";
|
||||
final String disbursementDate = "01 March 2015";
|
||||
final String adjustRepaymentDate = "16 March 2015";
|
||||
final String recalculationRestFrequencyDate = "01 January 2012";
|
||||
|
||||
// CREATE CLIENT
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2014");
|
||||
System.out.println("---------------------------------CLIENT CREATED WITH ID---------------------------------------------------"
|
||||
+ clientID);
|
||||
|
||||
// CREATE LOAN MULTIDISBURSAL PRODUCT WITH INTEREST RECALCULATION
|
||||
final Integer loanProductID = createLoanProductWithInterestRecalculation(LoanProductTestBuilder.RBI_INDIA_STRATEGY,
|
||||
LoanProductTestBuilder.RECALCULATION_COMPOUNDING_METHOD_NONE,
|
||||
LoanProductTestBuilder.RECALCULATION_STRATEGY_REDUCE_NUMBER_OF_INSTALLMENTS,
|
||||
LoanProductTestBuilder.RECALCULATION_FREQUENCY_TYPE_DAILY, "0", recalculationRestFrequencyDate,
|
||||
LoanProductTestBuilder.INTEREST_APPLICABLE_STRATEGY_ON_PRE_CLOSE_DATE, null);
|
||||
|
||||
// CREATE TRANCHES
|
||||
List<HashMap> createTranches = new ArrayList<>();
|
||||
createTranches.add(this.loanApplicationApprovalTest.createTrancheDetail("01 March 2015", "5000"));
|
||||
createTranches.add(this.loanApplicationApprovalTest.createTrancheDetail("01 May 2015", "5000"));
|
||||
|
||||
// APPROVE TRANCHES
|
||||
List<HashMap> approveTranches = new ArrayList<>();
|
||||
approveTranches.add(this.loanApplicationApprovalTest.createTrancheDetail("01 March 2015", "5000"));
|
||||
approveTranches.add(this.loanApplicationApprovalTest.createTrancheDetail("01 May 2015", "5000"));
|
||||
|
||||
// APPLY FOR TRANCHE LOAN WITH INTEREST RECALCULATION
|
||||
final Integer loanID = applyForLoanApplicationForInterestRecalculation(clientID, loanProductID, disbursementDate,
|
||||
recalculationRestFrequencyDate, LoanApplicationTestBuilder.RBI_INDIA_STRATEGY, new ArrayList<HashMap>(0), createTranches);
|
||||
|
||||
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
|
||||
|
||||
// VALIDATE THE LOAN STATUS
|
||||
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
|
||||
|
||||
System.out.println("-----------------------------------APPROVE LOAN-----------------------------------------------------------");
|
||||
loanStatusHashMap = this.loanTransactionHelper.approveLoanWithApproveAmount(approveDate, expectedDisbursementDate, approvalAmount,
|
||||
loanID, approveTranches);
|
||||
|
||||
// VALIDATE THE LOAN IS APPROVED
|
||||
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
|
||||
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
|
||||
|
||||
// DISBURSE A FIRST TRANCHE
|
||||
this.loanTransactionHelper.disburseLoanWithRepaymentReschedule(disbursementDate, loanID, adjustRepaymentDate);
|
||||
loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
|
||||
|
||||
ArrayList<HashMap> loanRepaymnetSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(requestSpec, generalResponseSpec, loanID);
|
||||
HashMap firstInstallement = loanRepaymnetSchedule.get(1);
|
||||
Map<String, Object> expectedvalues = new HashMap<>(3);
|
||||
Calendar date = Calendar.getInstance(Utils.getTimeZoneOfTenant());
|
||||
date.set(2015, Calendar.MARCH, 16);
|
||||
expectedvalues.put("dueDate", getDateAsArray(date, 0));
|
||||
expectedvalues.put("principalDue", "834.71");
|
||||
expectedvalues.put("interestDue", "49.32");
|
||||
expectedvalues.put("feeChargesDue", "0");
|
||||
expectedvalues.put("penaltyChargesDue", "0");
|
||||
expectedvalues.put("totalDueForPeriod", "884.03");
|
||||
|
||||
// VALIDATE REPAYMENT SCHEDULE
|
||||
verifyLoanRepaymentSchedule(firstInstallement, expectedvalues);
|
||||
|
||||
}
|
||||
|
||||
private void verifyLoanRepaymentSchedule(final HashMap firstInstallement, final Map<String, Object> expectedvalues) {
|
||||
|
||||
assertEquals(expectedvalues.get("dueDate"), firstInstallement.get("dueDate"));
|
||||
assertEquals(String.valueOf(expectedvalues.get("principalDue")), String.valueOf(firstInstallement.get("principalDue")));
|
||||
assertEquals(String.valueOf(expectedvalues.get("interestDue")), String.valueOf(firstInstallement.get("interestDue")));
|
||||
assertEquals(String.valueOf(expectedvalues.get("feeChargesDue")), String.valueOf(firstInstallement.get("feeChargesDue")));
|
||||
assertEquals(String.valueOf(expectedvalues.get("penaltyChargesDue")), String.valueOf(firstInstallement.get("penaltyChargesDue")));
|
||||
assertEquals(String.valueOf(expectedvalues.get("totalDueForPeriod")), String.valueOf(firstInstallement.get("totalDueForPeriod")));
|
||||
|
||||
}
|
||||
|
||||
private Integer createLoanProductWithInterestRecalculation(final String repaymentStrategy,
|
||||
final String interestRecalculationCompoundingMethod, final String rescheduleStrategyMethod,
|
||||
final String recalculationRestFrequencyType, final String recalculationRestFrequencyInterval,
|
||||
final String recalculationRestFrequencyDate, final String preCloseInterestCalculationStrategy, final Account[] accounts) {
|
||||
final String recalculationCompoundingFrequencyType = null;
|
||||
final String recalculationCompoundingFrequencyInterval = null;
|
||||
final String recalculationCompoundingFrequencyDate = null;
|
||||
return createLoanProductWithInterestRecalculation(repaymentStrategy, interestRecalculationCompoundingMethod,
|
||||
rescheduleStrategyMethod, recalculationRestFrequencyType, recalculationRestFrequencyInterval,
|
||||
recalculationRestFrequencyDate, recalculationCompoundingFrequencyType, recalculationCompoundingFrequencyInterval,
|
||||
recalculationCompoundingFrequencyDate, preCloseInterestCalculationStrategy, accounts, null, false);
|
||||
}
|
||||
|
||||
private Integer createLoanProductWithInterestRecalculation(final String repaymentStrategy,
|
||||
final String interestRecalculationCompoundingMethod, final String rescheduleStrategyMethod,
|
||||
final String recalculationRestFrequencyType, final String recalculationRestFrequencyInterval,
|
||||
final String recalculationRestFrequencyDate, final String recalculationCompoundingFrequencyType,
|
||||
final String recalculationCompoundingFrequencyInterval, final String recalculationCompoundingFrequencyDate,
|
||||
final String preCloseInterestCalculationStrategy, final Account[] accounts, final String chargeId,
|
||||
boolean isArrearsBasedOnOriginalSchedule) {
|
||||
System.out.println("------------------------------CREATING NEW LOAN PRODUCT ---------------------------------------");
|
||||
LoanProductTestBuilder builder = new LoanProductTestBuilder()
|
||||
.withPrincipal("10000.00")
|
||||
.withNumberOfRepayments("12")
|
||||
.withRepaymentAfterEvery("2")
|
||||
.withRepaymentTypeAsWeek()
|
||||
.withinterestRatePerPeriod("2")
|
||||
.withInterestRateFrequencyTypeAsMonths()
|
||||
.withTranches(true)
|
||||
.withInterestCalculationPeriodTypeAsRepaymentPeriod(true)
|
||||
.withRepaymentStrategy(repaymentStrategy)
|
||||
.withInterestTypeAsDecliningBalance()
|
||||
.withInterestRecalculationDetails(interestRecalculationCompoundingMethod, rescheduleStrategyMethod,
|
||||
preCloseInterestCalculationStrategy)
|
||||
.withInterestRecalculationRestFrequencyDetails(recalculationRestFrequencyType, recalculationRestFrequencyInterval,
|
||||
recalculationRestFrequencyDate)
|
||||
.withInterestRecalculationCompoundingFrequencyDetails(recalculationCompoundingFrequencyType,
|
||||
recalculationCompoundingFrequencyInterval, recalculationCompoundingFrequencyDate);
|
||||
if (accounts != null) {
|
||||
builder = builder.withAccountingRulePeriodicAccrual(accounts);
|
||||
}
|
||||
|
||||
if (isArrearsBasedOnOriginalSchedule) builder = builder.withArrearsConfiguration();
|
||||
|
||||
final String loanProductJSON = builder.build(chargeId);
|
||||
return this.loanTransactionHelper.getLoanProductId(loanProductJSON);
|
||||
}
|
||||
|
||||
private Integer applyForLoanApplicationForInterestRecalculation(final Integer clientID, final Integer loanProductID,
|
||||
final String disbursementDate, final String restStartDate, final String repaymentStrategy, final List<HashMap> charges, List<HashMap> tranches) {
|
||||
final String graceOnInterestPayment = null;
|
||||
final String compoundingStartDate = null;
|
||||
final String graceOnPrincipalPayment = null;
|
||||
return applyForLoanApplicationForInterestRecalculation(clientID, loanProductID, disbursementDate, restStartDate,
|
||||
compoundingStartDate, repaymentStrategy, charges, graceOnInterestPayment, graceOnPrincipalPayment,tranches);
|
||||
}
|
||||
|
||||
private Integer applyForLoanApplicationForInterestRecalculation(final Integer clientID, final Integer loanProductID,
|
||||
final String disbursementDate, final String restStartDate, final String compoundingStartDate, final String repaymentStrategy,
|
||||
final List<HashMap> charges, final String graceOnInterestPayment, final String graceOnPrincipalPayment, List<HashMap> tranches) {
|
||||
System.out.println("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------");
|
||||
final String loanApplicationJSON = new LoanApplicationTestBuilder() //
|
||||
.withPrincipal("10000.00") //
|
||||
.withLoanTermFrequency("24") //
|
||||
.withLoanTermFrequencyAsWeeks() //
|
||||
.withNumberOfRepayments("12") //
|
||||
.withRepaymentEveryAfter("2") //
|
||||
.withRepaymentFrequencyTypeAsWeeks() //
|
||||
.withInterestRatePerPeriod("2") //
|
||||
.withAmortizationTypeAsEqualInstallments() //
|
||||
.withTranches(tranches)
|
||||
.withFixedEmiAmount("") //
|
||||
.withInterestTypeAsDecliningBalance() //
|
||||
.withInterestCalculationPeriodTypeAsDays() //
|
||||
.withInterestCalculationPeriodTypeAsDays() //
|
||||
.withExpectedDisbursementDate(disbursementDate) //
|
||||
.withSubmittedOnDate(disbursementDate) //
|
||||
.withRestFrequencyDate(restStartDate)//
|
||||
.withwithRepaymentStrategy(repaymentStrategy) //
|
||||
.withCharges(charges)//
|
||||
.build(clientID.toString(), loanProductID.toString(), null);
|
||||
return this.loanTransactionHelper.getLoanId(loanApplicationJSON);
|
||||
}
|
||||
|
||||
private List getDateAsArray(Calendar date, int addPeriod) {
|
||||
return getDateAsArray(date, addPeriod, Calendar.DAY_OF_MONTH);
|
||||
}
|
||||
|
||||
private List getDateAsArray(Calendar date, int addvalue, int type) {
|
||||
date.add(type, addvalue);
|
||||
return new ArrayList<>(Arrays.asList(date.get(Calendar.YEAR), date.get(Calendar.MONTH) + 1,
|
||||
date.get(Calendar.DAY_OF_MONTH)));
|
||||
}
|
||||
}
|
||||
+219
@@ -0,0 +1,219 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||
import org.apache.fineract.integrationtests.common.LoanRescheduleRequestHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanRescheduleRequestTestBuilder;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Test the creation, approval and rejection of a loan reschedule request
|
||||
**/
|
||||
@SuppressWarnings({ "rawtypes" })
|
||||
public class LoanRescheduleRequestTest {
|
||||
private ResponseSpecification responseSpec;
|
||||
private ResponseSpecification generalResponseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private LoanTransactionHelper loanTransactionHelper;
|
||||
private LoanRescheduleRequestHelper loanRescheduleRequestHelper;
|
||||
private Integer clientId;
|
||||
private Integer loanProductId;
|
||||
private Integer loanId;
|
||||
private Integer loanRescheduleRequestId;
|
||||
private String loanPrincipalAmount = "100000.00";
|
||||
private String numberOfRepayments = "12";
|
||||
private String interestRatePerPeriod = "18";
|
||||
private String dateString = "4 September 2014";
|
||||
|
||||
@Before
|
||||
public void initialize() {
|
||||
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.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
|
||||
this.loanRescheduleRequestHelper = new LoanRescheduleRequestHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
this.generalResponseSpec = new ResponseSpecBuilder().build();
|
||||
|
||||
// create all required entities
|
||||
this.createRequiredEntities();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the client, loan product, and loan entities
|
||||
**/
|
||||
private void createRequiredEntities() {
|
||||
this.createClientEntity();
|
||||
this.createLoanProductEntity();
|
||||
this.createLoanEntity();
|
||||
}
|
||||
|
||||
/**
|
||||
* create a new client
|
||||
**/
|
||||
private void createClientEntity() {
|
||||
this.clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
|
||||
ClientHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, this.clientId);
|
||||
}
|
||||
|
||||
/**
|
||||
* create a new loan product
|
||||
**/
|
||||
private void createLoanProductEntity() {
|
||||
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 + ")");
|
||||
}
|
||||
|
||||
/**
|
||||
* submit a new loan application, approve and disburse the loan
|
||||
**/
|
||||
private void createLoanEntity() {
|
||||
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);
|
||||
|
||||
System.out.println("Sucessfully created loan (ID: " + this.loanId + ")");
|
||||
|
||||
this.approveLoanApplication();
|
||||
this.disburseLoan();
|
||||
}
|
||||
|
||||
/**
|
||||
* approve the loan application
|
||||
**/
|
||||
private void approveLoanApplication() {
|
||||
|
||||
if(this.loanId != null) {
|
||||
this.loanTransactionHelper.approveLoan(this.dateString, this.loanId);
|
||||
System.out.println("Successfully approved loan (ID: " + this.loanId + ")");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* disburse the newly created loan
|
||||
**/
|
||||
private void disburseLoan() {
|
||||
|
||||
if(this.loanId != null) {
|
||||
this.loanTransactionHelper.disburseLoan(this.dateString, this.loanId);
|
||||
System.out.println("Successfully disbursed loan (ID: " + this.loanId + ")");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* create new loan reschedule request
|
||||
**/
|
||||
private void createLoanRescheduleRequest() {
|
||||
System.out.println("---------------------------------CREATING LOAN RESCHEDULE REQUEST------------------------------------------");
|
||||
|
||||
final String requestJSON = new LoanRescheduleRequestTestBuilder().build(this.loanId.toString());
|
||||
|
||||
this.loanRescheduleRequestId = this.loanRescheduleRequestHelper.createLoanRescheduleRequest(requestJSON);
|
||||
this.loanRescheduleRequestHelper.verifyCreationOfLoanRescheduleRequest(this.loanRescheduleRequestId);
|
||||
|
||||
System.out.println("Successfully created loan reschedule request (ID: " + this.loanRescheduleRequestId + ")");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateLoanRescheduleRequest() {
|
||||
this.createLoanRescheduleRequest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRejectLoanRescheduleRequest() {
|
||||
this.createLoanRescheduleRequest();
|
||||
|
||||
System.out.println("-----------------------------REJECTING LOAN RESCHEDULE REQUEST--------------------------");
|
||||
|
||||
final String requestJSON = new LoanRescheduleRequestTestBuilder().getRejectLoanRescheduleRequestJSON();
|
||||
this.loanRescheduleRequestHelper.rejectLoanRescheduleRequest(this.loanRescheduleRequestId, requestJSON);
|
||||
|
||||
final HashMap response = (HashMap) this.loanRescheduleRequestHelper.getLoanRescheduleRequest(loanRescheduleRequestId, "statusEnum");
|
||||
assertTrue((Boolean)response.get("rejected"));
|
||||
|
||||
System.out.println("Successfully rejected loan reschedule request (ID: " + this.loanRescheduleRequestId + ")");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApproveLoanRescheduleRequest() {
|
||||
this.createLoanRescheduleRequest();
|
||||
|
||||
System.out.println("-----------------------------APPROVING LOAN RESCHEDULE REQUEST--------------------------");
|
||||
|
||||
final String requestJSON = new LoanRescheduleRequestTestBuilder().getApproveLoanRescheduleRequestJSON();
|
||||
this.loanRescheduleRequestHelper.approveLoanRescheduleRequest(this.loanRescheduleRequestId, requestJSON);
|
||||
|
||||
final HashMap response = (HashMap) this.loanRescheduleRequestHelper.getLoanRescheduleRequest(loanRescheduleRequestId, "statusEnum");
|
||||
assertTrue((Boolean)response.get("approved"));
|
||||
|
||||
final Integer numberOfRepayments = (Integer) this.loanTransactionHelper.getLoanDetail(requestSpec, generalResponseSpec, loanId, "numberOfRepayments");
|
||||
final HashMap loanSummary = this.loanTransactionHelper.getLoanSummary(requestSpec, generalResponseSpec, loanId);
|
||||
final Float totalExpectedRepayment = (Float) loanSummary.get("totalExpectedRepayment");
|
||||
|
||||
assertEquals("NUMBER OF REPAYMENTS SHOULD BE 16, NOT 12", "16", numberOfRepayments.toString());
|
||||
assertEquals("TOTAL EXPECTED REPAYMENT MUST BE EQUAL TO 118000.0", "118000.0", totalExpectedRepayment.toString());
|
||||
|
||||
System.out.println("Successfully approved loan reschedule request (ID: " + this.loanRescheduleRequestId + ")");
|
||||
}
|
||||
}
|
||||
+204
@@ -0,0 +1,204 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanStatusChecker;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Client Loan Integration Test for checking Loan Disbursement with Waive
|
||||
* Interest and Write-Off.
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes" })
|
||||
public class LoanWithWaiveInterestAndWriteOffIntegrationTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
|
||||
private final String LP_PRINCIPAL = "12,000.00", LP_REPAYMENTS = "2", LP_REPAYMENT_PERIOD = "6", LP_INTEREST_RATE = "1",
|
||||
PRINCIPAL = "4,500.00", LOAN_TERM_FREQUENCY = "18", NUMBER_OF_REPAYMENTS = "9", REPAYMENT_PERIOD = "2",
|
||||
DISBURSEMENT_DATE = "30 October 2010", LOAN_APPLICATION_SUBMISSION_DATE = "23 September 2010",
|
||||
EXPECTED_DISBURSAL_DATE = "28 October 2010", RATE_OF_INTEREST_PER_PERIOD = "2", DATE_OF_JOINING = "04 March 2009",
|
||||
INTEREST_VALUE_AMOUNT = "40.00";
|
||||
private LoanTransactionHelper loanTransactionHelper;
|
||||
|
||||
@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.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkClientLoanCreateAndDisburseFlow() {
|
||||
// CREATE CLIENT
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, this.DATE_OF_JOINING);
|
||||
ClientHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, clientID);
|
||||
|
||||
// CREATE LOAN PRODUCT
|
||||
final Integer loanProductID = createLoanProduct();
|
||||
// APPLY FOR LOAN
|
||||
final Integer loanID = applyForLoanApplication(clientID, loanProductID);
|
||||
|
||||
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
|
||||
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
|
||||
|
||||
System.out.println("-----------------------------------APPROVE LOAN-----------------------------------------");
|
||||
loanStatusHashMap = this.loanTransactionHelper.approveLoan("28 September 2010", loanID);
|
||||
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
|
||||
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
|
||||
|
||||
// UNDO APPROVAL
|
||||
loanStatusHashMap = this.loanTransactionHelper.undoApproval(loanID);
|
||||
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
|
||||
|
||||
System.out.println("-----------------------------------RE-APPROVE LOAN-----------------------------------------");
|
||||
loanStatusHashMap = this.loanTransactionHelper.approveLoan("1 October 2010", loanID);
|
||||
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
|
||||
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
|
||||
|
||||
// DISBURSE
|
||||
loanStatusHashMap = this.loanTransactionHelper.disburseLoan(this.DISBURSEMENT_DATE, loanID);
|
||||
System.out.println("DISBURSE " + loanStatusHashMap);
|
||||
LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
|
||||
|
||||
// PERFORM REPAYMENTS AND CHECK LOAN STATUS
|
||||
this.loanTransactionHelper.verifyRepaymentScheduleEntryFor(1, 4000.0F, loanID);
|
||||
this.loanTransactionHelper.makeRepayment("1 January 2011", 540.0f, loanID);
|
||||
|
||||
// UNDO DISBURSE LOAN
|
||||
loanStatusHashMap = this.loanTransactionHelper.undoDisbursal(loanID);
|
||||
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
|
||||
|
||||
// DIBURSE AGAIN
|
||||
loanStatusHashMap = this.loanTransactionHelper.disburseLoan(this.DISBURSEMENT_DATE, loanID);
|
||||
System.out.println("DISBURSE " + loanStatusHashMap);
|
||||
LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
|
||||
|
||||
// MAKE REPAYMENTS
|
||||
final float repayment_with_interest = 540.0f;
|
||||
final float repayment_without_interest = 500.0f;
|
||||
|
||||
this.loanTransactionHelper.verifyRepaymentScheduleEntryFor(1, 4000.0F, loanID);
|
||||
this.loanTransactionHelper.makeRepayment("1 January 2011", repayment_with_interest, loanID);
|
||||
this.loanTransactionHelper.makeRepayment("1 March 2011", repayment_with_interest, loanID);
|
||||
this.loanTransactionHelper.waiveInterest("1 May 2011", this.INTEREST_VALUE_AMOUNT, loanID);
|
||||
this.loanTransactionHelper.makeRepayment("1 May 2011", repayment_without_interest, loanID);
|
||||
this.loanTransactionHelper.makeRepayment("1 July 2011", repayment_with_interest, loanID);
|
||||
this.loanTransactionHelper.waiveInterest("1 September 2011", this.INTEREST_VALUE_AMOUNT, loanID);
|
||||
this.loanTransactionHelper.makeRepayment("1 September 2011", repayment_without_interest, loanID);
|
||||
this.loanTransactionHelper.makeRepayment("1 November 2011", repayment_with_interest, loanID);
|
||||
this.loanTransactionHelper.waiveInterest("1 January 2012", this.INTEREST_VALUE_AMOUNT, loanID);
|
||||
this.loanTransactionHelper.makeRepayment("1 January 2012", repayment_without_interest, loanID);
|
||||
this.loanTransactionHelper.verifyRepaymentScheduleEntryFor(7, 1000.0f, loanID);
|
||||
|
||||
// WRITE OFF LOAN AND CHECK ACCOUNT IS CLOSED
|
||||
LoanStatusChecker.verifyLoanAccountIsClosed(this.loanTransactionHelper.writeOffLoan("1 March 2012", loanID));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkClientLoan_WRITTEN_OFF() {
|
||||
// CREATE CLIENT
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, this.DATE_OF_JOINING);
|
||||
ClientHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, clientID);
|
||||
|
||||
// CREATE LOAN PRODUCT
|
||||
final Integer loanProductID = createLoanProduct();
|
||||
// APPLY FOR LOAN
|
||||
final Integer loanID = applyForLoanApplication(clientID, loanProductID);
|
||||
|
||||
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
|
||||
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
|
||||
|
||||
System.out.println("-----------------------------------APPROVE LOAN-----------------------------------------");
|
||||
loanStatusHashMap = this.loanTransactionHelper.approveLoan("28 September 2010", loanID);
|
||||
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
|
||||
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
|
||||
|
||||
// DISBURSE
|
||||
loanStatusHashMap = this.loanTransactionHelper.disburseLoan(this.DISBURSEMENT_DATE, loanID);
|
||||
System.out.println("DISBURSE " + loanStatusHashMap);
|
||||
LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
|
||||
|
||||
// MAKE REPAYMENTS
|
||||
final float repayment_with_interest = 680.0f;
|
||||
|
||||
this.loanTransactionHelper.verifyRepaymentScheduleEntryFor(1, 4000.0F, loanID);
|
||||
this.loanTransactionHelper.makeRepayment("1 January 2011", repayment_with_interest, loanID);
|
||||
|
||||
HashMap toLoanSummaryAfter = this.loanTransactionHelper.getLoanSummary(requestSpec, responseSpec, loanID);
|
||||
Assert.assertTrue("Checking for Principal paid ",
|
||||
new Float("500.0").compareTo(new Float(String.valueOf(toLoanSummaryAfter.get("principalPaid")))) == 0);
|
||||
Assert.assertTrue("Checking for interestPaid paid ",
|
||||
new Float("180.0").compareTo(new Float(String.valueOf(toLoanSummaryAfter.get("interestPaid")))) == 0);
|
||||
Assert.assertTrue("Checking for total paid ",
|
||||
new Float("680.0").compareTo(new Float(String.valueOf(toLoanSummaryAfter.get("totalRepayment")))) == 0);
|
||||
|
||||
// WRITE OFF LOAN AND CHECK ACCOUNT IS CLOSED
|
||||
LoanStatusChecker.verifyLoanAccountIsClosed(this.loanTransactionHelper.writeOffLoan("1 January 2011", loanID));
|
||||
toLoanSummaryAfter = this.loanTransactionHelper.getLoanSummary(requestSpec, responseSpec, loanID);
|
||||
Assert.assertTrue("Checking for Principal written off ",
|
||||
new Float("4000.0").compareTo(new Float(String.valueOf(toLoanSummaryAfter.get("principalWrittenOff")))) == 0);
|
||||
Assert.assertTrue("Checking for interestPaid written off ",
|
||||
new Float("1440.0").compareTo(new Float(String.valueOf(toLoanSummaryAfter.get("interestWrittenOff")))) == 0);
|
||||
Assert.assertTrue("Checking for total written off ",
|
||||
new Float("5440.0").compareTo(new Float(String.valueOf(toLoanSummaryAfter.get("totalWrittenOff")))) == 0);
|
||||
|
||||
}
|
||||
|
||||
private Integer createLoanProduct() {
|
||||
System.out.println("------------------------------CREATING NEW LOAN PRODUCT ---------------------------------------");
|
||||
final String loanProductJSON = new LoanProductTestBuilder().withPrincipal(this.LP_PRINCIPAL).withRepaymentTypeAsMonth()
|
||||
.withRepaymentAfterEvery(this.LP_REPAYMENT_PERIOD).withNumberOfRepayments(this.LP_REPAYMENTS).withRepaymentTypeAsMonth()
|
||||
.withinterestRatePerPeriod(this.LP_INTEREST_RATE).withInterestRateFrequencyTypeAsMonths()
|
||||
.withAmortizationTypeAsEqualPrincipalPayment().withInterestTypeAsFlat().build(null);
|
||||
|
||||
return this.loanTransactionHelper.getLoanProductId(loanProductJSON);
|
||||
}
|
||||
|
||||
private Integer applyForLoanApplication(final Integer clientID, final Integer loanProductID) {
|
||||
System.out.println("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------");
|
||||
final String loanApplicationJSON = new LoanApplicationTestBuilder().withPrincipal(this.PRINCIPAL)
|
||||
.withLoanTermFrequency(this.LOAN_TERM_FREQUENCY).withLoanTermFrequencyAsMonths()
|
||||
.withNumberOfRepayments(this.NUMBER_OF_REPAYMENTS).withRepaymentEveryAfter(this.REPAYMENT_PERIOD)
|
||||
.withRepaymentFrequencyTypeAsMonths().withInterestRatePerPeriod(this.RATE_OF_INTEREST_PER_PERIOD)
|
||||
.withInterestTypeAsFlatBalance().withAmortizationTypeAsEqualInstallments()
|
||||
.withInterestCalculationPeriodTypeSameAsRepaymentPeriod().withExpectedDisbursementDate(this.EXPECTED_DISBURSAL_DATE)
|
||||
.withSubmittedOnDate(this.LOAN_APPLICATION_SUBMISSION_DATE).build(clientID.toString(), loanProductID.toString(), null);
|
||||
return this.loanTransactionHelper.getLoanId(loanApplicationJSON);
|
||||
}
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanStatusChecker;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
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;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class LoanWithdrawnByApplicantIntegrationTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private LoanTransactionHelper loanTransactionHelper;
|
||||
|
||||
@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.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loanWithdrawnByApplicant() {
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2012");
|
||||
final Integer loanProductID = this.loanTransactionHelper.getLoanProductId(new LoanProductTestBuilder().build(null));
|
||||
final Integer loanID = applyForLoanApplication(clientID, loanProductID);
|
||||
|
||||
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
|
||||
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
|
||||
|
||||
this.loanTransactionHelper.withdrawLoanApplicationByClient("03 April 2012", loanID);
|
||||
loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
|
||||
LoanStatusChecker.verifyLoanAccountIsNotActive(loanStatusHashMap);
|
||||
|
||||
}
|
||||
|
||||
private Integer applyForLoanApplication(final Integer clientID, final Integer loanProductID) {
|
||||
final String loanApplication = new LoanApplicationTestBuilder().withPrincipal("5000").withLoanTermFrequency("5")
|
||||
.withLoanTermFrequencyAsMonths().withNumberOfRepayments("5").withRepaymentEveryAfter("1")
|
||||
.withRepaymentFrequencyTypeAsMonths().withInterestRatePerPeriod("2").withExpectedDisbursementDate("04 April 2012")
|
||||
.withSubmittedOnDate("02 April 2012").build(clientID.toString(), loanProductID.toString(), null);
|
||||
return this.loanTransactionHelper.getLoanId(loanApplication);
|
||||
}
|
||||
}
|
||||
+220
@@ -0,0 +1,220 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.CalendarHelper;
|
||||
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||
import org.apache.fineract.integrationtests.common.CommonConstants;
|
||||
import org.apache.fineract.integrationtests.common.GroupHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanStatusChecker;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Test the creation, approval and rejection of a loan reschedule request
|
||||
**/
|
||||
@SuppressWarnings({ "rawtypes" })
|
||||
public class MinimumDaysBetweenDisbursalAndFirstRepaymentTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private ResponseSpecification responseSpecForStatusCode403;
|
||||
private RequestSpecification requestSpec;
|
||||
private LoanTransactionHelper loanTransactionHelper;
|
||||
private Integer clientId;
|
||||
private Integer groupId;
|
||||
private Integer groupCalendarId;
|
||||
private Integer loanProductId;
|
||||
private Integer loanId;
|
||||
private final String loanPrincipalAmount = "100000.00";
|
||||
private final String numberOfRepayments = "12";
|
||||
private final String interestRatePerPeriod = "18";
|
||||
private final String groupActivationDate = "1 August 2014";
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
Utils.initializeRESTAssured();
|
||||
}
|
||||
|
||||
/*
|
||||
* MinimumDaysBetweenDisbursalAndFirstRepayment is set to 7 days and days
|
||||
* between disbursal date and first repayment is set as 7. system should
|
||||
* allow to create this loan and allow to disburse
|
||||
*/
|
||||
@Test
|
||||
public void createLoanEntity_WITH_DAY_BETWEEN_DISB_DATE_AND_REPAY_START_DATE_GREATER_THAN_MIN_DAY_CRITERIA() {
|
||||
|
||||
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
|
||||
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
|
||||
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
// create all required entities
|
||||
this.createRequiredEntities();
|
||||
|
||||
final String disbursalDate = "4 September 2014";
|
||||
final String firstRepaymentDate = "11 September 2014";
|
||||
|
||||
final String loanApplicationJSON = new LoanApplicationTestBuilder().withPrincipal(loanPrincipalAmount)
|
||||
.withLoanTermFrequency(numberOfRepayments).withLoanTermFrequencyAsWeeks().withNumberOfRepayments(numberOfRepayments)
|
||||
.withRepaymentEveryAfter("1").withRepaymentFrequencyTypeAsMonths().withAmortizationTypeAsEqualInstallments()
|
||||
.withInterestCalculationPeriodTypeAsDays().withInterestRatePerPeriod(interestRatePerPeriod)
|
||||
.withRepaymentFrequencyTypeAsWeeks().withSubmittedOnDate(disbursalDate).withExpectedDisbursementDate(disbursalDate)
|
||||
.withPrincipalGrace("2").withInterestGrace("2").withFirstRepaymentDate(firstRepaymentDate)
|
||||
.build(this.clientId.toString(), this.loanProductId.toString(), null);
|
||||
|
||||
this.loanId = this.loanTransactionHelper.getLoanId(loanApplicationJSON);
|
||||
|
||||
// Test for loan account is created
|
||||
Assert.assertNotNull(this.loanId);
|
||||
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, this.loanId);
|
||||
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
|
||||
|
||||
// Test for loan account is created, can be approved
|
||||
this.loanTransactionHelper.approveLoan(disbursalDate, this.loanId);
|
||||
loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, this.loanId);
|
||||
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
|
||||
|
||||
// Test for loan account approved can be disbursed
|
||||
this.loanTransactionHelper.disburseLoan(disbursalDate, this.loanId);
|
||||
loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, this.loanId);
|
||||
LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* MinimumDaysBetweenDisbursalAndFirstRepayment is set to 7 days and days
|
||||
* between disbursal date and first repayment is set as 7. system should
|
||||
* allow to create this loan and allow to disburse
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void createLoanEntity_WITH_DAY_BETWEEN_DISB_DATE_AND_REPAY_START_DATE_LESS_THAN_MIN_DAY_CRITERIA() {
|
||||
|
||||
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
|
||||
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
|
||||
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||
this.responseSpecForStatusCode403 = new ResponseSpecBuilder().expectStatusCode(403).build();
|
||||
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
|
||||
// create all required entities
|
||||
this.createRequiredEntities();
|
||||
|
||||
// loanTransactionHelper is reassigned to accept 403 status code from
|
||||
// server
|
||||
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpecForStatusCode403);
|
||||
|
||||
final String disbursalDate = "4 September 2014";
|
||||
final String firstRepaymentDate = "5 September 2014";
|
||||
|
||||
final String loanApplicationJSON = new LoanApplicationTestBuilder().withPrincipal(loanPrincipalAmount)
|
||||
.withLoanTermFrequency(numberOfRepayments).withLoanTermFrequencyAsWeeks().withNumberOfRepayments(numberOfRepayments)
|
||||
.withRepaymentEveryAfter("1").withRepaymentFrequencyTypeAsMonths().withAmortizationTypeAsEqualInstallments()
|
||||
.withInterestCalculationPeriodTypeAsDays().withInterestRatePerPeriod(interestRatePerPeriod)
|
||||
.withRepaymentFrequencyTypeAsWeeks().withSubmittedOnDate(disbursalDate).withExpectedDisbursementDate(disbursalDate)
|
||||
.withPrincipalGrace("2").withInterestGrace("2").withFirstRepaymentDate(firstRepaymentDate)
|
||||
.build(this.clientId.toString(), this.loanProductId.toString(), null);
|
||||
|
||||
List<HashMap> error = (List<HashMap>) this.loanTransactionHelper.createLoanAccount(loanApplicationJSON,
|
||||
CommonConstants.RESPONSE_ERROR);
|
||||
assertEquals("error.msg.loan.days.between.first.repayment.and.disbursal.are.less.than.minimum.allowed",
|
||||
error.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the client, loan product, and loan entities
|
||||
**/
|
||||
private void createRequiredEntities() {
|
||||
final String minimumDaysBetweenDisbursalAndFirstRepayment = "7"; // &
|
||||
// days
|
||||
this.createGroupEntityWithCalendar();
|
||||
this.createClientEntity();
|
||||
this.associateClientToGroup(this.groupId, this.clientId);
|
||||
this.createLoanProductEntity(minimumDaysBetweenDisbursalAndFirstRepayment);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Associate client to the group
|
||||
*/
|
||||
|
||||
private void associateClientToGroup(final Integer groupId, final Integer clientId) {
|
||||
GroupHelper.associateClient(this.requestSpec, this.responseSpec, groupId.toString(), clientId.toString());
|
||||
GroupHelper.verifyGroupMembers(this.requestSpec, this.responseSpec, groupId, clientId);
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a new group
|
||||
*/
|
||||
|
||||
private void createGroupEntityWithCalendar() {
|
||||
this.groupId = GroupHelper.createGroup(this.requestSpec, this.responseSpec, this.groupActivationDate);
|
||||
GroupHelper.verifyGroupCreatedOnServer(this.requestSpec, this.responseSpec, this.groupId);
|
||||
|
||||
final String startDate = this.groupActivationDate;
|
||||
final String frequency = "2"; // 2:Weekly
|
||||
final String interval = "1"; // Every one week
|
||||
final String repeatsOnDay = "1"; // 1:Monday
|
||||
|
||||
this.setGroupCalendarId(CalendarHelper.createMeetingCalendarForGroup(this.requestSpec, this.responseSpec, this.groupId, startDate,
|
||||
frequency, interval, repeatsOnDay));
|
||||
}
|
||||
|
||||
/**
|
||||
* create a new client
|
||||
**/
|
||||
private void createClientEntity() {
|
||||
this.clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
ClientHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, this.clientId);
|
||||
}
|
||||
|
||||
/**
|
||||
* create a new loan product
|
||||
**/
|
||||
private void createLoanProductEntity(final String minimumDaysBetweenDisbursalAndFirstRepayment) {
|
||||
final String loanProductJSON = new LoanProductTestBuilder().withPrincipal(loanPrincipalAmount)
|
||||
.withNumberOfRepayments(numberOfRepayments).withinterestRatePerPeriod(interestRatePerPeriod)
|
||||
.withInterestRateFrequencyTypeAsYear()
|
||||
.withMinimumDaysBetweenDisbursalAndFirstRepayment(minimumDaysBetweenDisbursalAndFirstRepayment).build(null);
|
||||
this.loanProductId = this.loanTransactionHelper.getLoanProductId(loanProductJSON);
|
||||
}
|
||||
|
||||
public Integer getGroupCalendarId() {
|
||||
return groupCalendarId;
|
||||
}
|
||||
|
||||
public void setGroupCalendarId(Integer groupCalendarId) {
|
||||
this.groupCalendarId = groupCalendarId;
|
||||
}
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.OfficeDomain;
|
||||
import org.apache.fineract.integrationtests.common.OfficeHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.jayway.restassured.builder.RequestSpecBuilder;
|
||||
import com.jayway.restassured.builder.ResponseSpecBuilder;
|
||||
import com.jayway.restassured.http.ContentType;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
public class OfficeIntegrationTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOfficeModification() {
|
||||
OfficeHelper oh = new OfficeHelper(requestSpec, responseSpec);
|
||||
int officeId = oh.createOffice("01 July 2007");
|
||||
String name = Utils.randomNameGenerator("New_Office_", 4);
|
||||
String date = "02 July 2007";
|
||||
String[] dateArr = { "2007", "7", "2" };
|
||||
|
||||
oh.updateOffice(officeId, name, date);
|
||||
OfficeDomain newOffice = oh.retrieveOfficeByID(officeId);
|
||||
|
||||
Assert.assertTrue(name.equals(newOffice.getName()));
|
||||
Assert.assertArrayEquals(dateArr, newOffice.getOpeningDate());
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.CommonConstants;
|
||||
import org.apache.fineract.integrationtests.common.PasswordPreferencesHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
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;
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public class PasswordPreferencesIntegrationTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private ResponseSpecification generalResponseSpec;
|
||||
|
||||
@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.generalResponseSpec = new ResponseSpecBuilder().build();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updatePasswordPreferences() {
|
||||
String validationPolicyId = "2";
|
||||
PasswordPreferencesHelper.updatePasswordPreferences(requestSpec, responseSpec, validationPolicyId);
|
||||
this.validateIfThePasswordIsUpdated(validationPolicyId);
|
||||
}
|
||||
|
||||
private void validateIfThePasswordIsUpdated(String validationPolicyId){
|
||||
Integer id = PasswordPreferencesHelper.getActivePasswordPreference(requestSpec, responseSpec);
|
||||
assertEquals(validationPolicyId, id.toString());
|
||||
System.out.println("---------------------------------PASSWORD PREFERENCE VALIDATED SUCCESSFULLY-----------------------------------------");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateWithInvalidPolicyId() {
|
||||
String invalidValidationPolicyId = "2000";
|
||||
final List<HashMap> error = (List) PasswordPreferencesHelper.updateWithInvalidValidationPolicyId(requestSpec, generalResponseSpec, invalidValidationPolicyId,
|
||||
CommonConstants.RESPONSE_ERROR);
|
||||
assertEquals("Password Validation Policy with identifier 2000 does not exist", "error.msg.password.validation.policy.id.invalid",
|
||||
error.get(0).get("userMessageGlobalisationCode"));
|
||||
}
|
||||
|
||||
}
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.PaymentTypeDomain;
|
||||
import org.apache.fineract.integrationtests.common.PaymentTypeHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.jayway.restassured.builder.RequestSpecBuilder;
|
||||
import com.jayway.restassured.builder.ResponseSpecBuilder;
|
||||
import com.jayway.restassured.http.ContentType;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
public class PaymentTypeIntegrationTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
|
||||
@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();
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Test
|
||||
public void testPaymentType() {
|
||||
String name = PaymentTypeHelper.randomNameGenerator("P_T", 5);
|
||||
String description = PaymentTypeHelper.randomNameGenerator("PT_Desc", 15);
|
||||
Boolean isCashPayment = true;
|
||||
Integer position = 1;
|
||||
|
||||
Integer paymentTypeId = PaymentTypeHelper.createPaymentType(requestSpec, responseSpec, name, description, isCashPayment, position);
|
||||
Assert.assertNotNull(paymentTypeId);
|
||||
PaymentTypeHelper.verifyPaymentTypeCreatedOnServer(requestSpec, responseSpec, paymentTypeId);
|
||||
PaymentTypeDomain paymentTypeResponse = PaymentTypeHelper.retrieveById(requestSpec, responseSpec, paymentTypeId);
|
||||
Assert.assertEquals(name, paymentTypeResponse.getName());
|
||||
Assert.assertEquals(description, paymentTypeResponse.getDescription());
|
||||
Assert.assertEquals(isCashPayment, paymentTypeResponse.getIsCashPayment());
|
||||
Assert.assertEquals(position, paymentTypeResponse.getPosition());
|
||||
|
||||
// Update Payment Type
|
||||
String newName = PaymentTypeHelper.randomNameGenerator("P_TU", 5);
|
||||
String newDescription = PaymentTypeHelper.randomNameGenerator("PTU_Desc", 15);
|
||||
Boolean isCashPaymentUpdatedValue = false;
|
||||
Integer newPosition = 2;
|
||||
|
||||
HashMap request = new HashMap();
|
||||
request.put("name", newName);
|
||||
request.put("description", newDescription);
|
||||
request.put("isCashPayment", isCashPaymentUpdatedValue);
|
||||
request.put("position", newPosition);
|
||||
PaymentTypeHelper.updatePaymentType(paymentTypeId, request, requestSpec, responseSpec);
|
||||
PaymentTypeDomain paymentTypeUpdatedResponse = PaymentTypeHelper.retrieveById(requestSpec, responseSpec, paymentTypeId);
|
||||
Assert.assertEquals(newName, paymentTypeUpdatedResponse.getName());
|
||||
Assert.assertEquals(newDescription, paymentTypeUpdatedResponse.getDescription());
|
||||
Assert.assertEquals(isCashPaymentUpdatedValue, paymentTypeUpdatedResponse.getIsCashPayment());
|
||||
Assert.assertEquals(newPosition, paymentTypeUpdatedResponse.getPosition());
|
||||
|
||||
// Delete
|
||||
Integer deletedPaymentTypeId = PaymentTypeHelper.deletePaymentType(paymentTypeId, requestSpec, responseSpec);
|
||||
Assert.assertEquals(paymentTypeId, deletedPaymentTypeId);
|
||||
ResponseSpecification responseSpecification = new ResponseSpecBuilder().expectStatusCode(404).build();
|
||||
PaymentTypeHelper.retrieveById(requestSpec, responseSpecification, paymentTypeId);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+2607
File diff suppressed because it is too large
Load Diff
+167
@@ -0,0 +1,167 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.organisation.StaffHelper;
|
||||
import org.apache.fineract.integrationtests.useradministration.roles.RolesHelper;
|
||||
import org.apache.fineract.integrationtests.useradministration.users.UserHelper;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.jayway.restassured.builder.RequestSpecBuilder;
|
||||
import com.jayway.restassured.builder.ResponseSpecBuilder;
|
||||
import com.jayway.restassured.http.ContentType;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
public class RolesTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
@SuppressWarnings("cast")
|
||||
@Test
|
||||
public void testCreateRolesStatus() {
|
||||
|
||||
System.out.println("---------------------------------CREATING A ROLE---------------------------------------------");
|
||||
final Integer roleId = RolesHelper.createRole(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(roleId);
|
||||
|
||||
System.out.println("--------------------------------- Getting ROLE -------------------------------");
|
||||
HashMap<String, Object> role = RolesHelper.getRoleDetails(requestSpec, responseSpec, roleId);
|
||||
assertEquals((Integer) role.get("id"), roleId);
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("cast")
|
||||
@Test
|
||||
public void testDisableRolesStatus() {
|
||||
|
||||
System.out.println("---------------------------------CREATING A ROLE---------------------------------------------");
|
||||
final Integer roleId = RolesHelper.createRole(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(roleId);
|
||||
|
||||
System.out.println("--------------------------------- Getting ROLE -------------------------------");
|
||||
HashMap<String, Object> role = RolesHelper.getRoleDetails(requestSpec, responseSpec, roleId);
|
||||
assertEquals((Integer) role.get("id"), roleId);
|
||||
|
||||
System.out.println("--------------------------------- DISABLING ROLE -------------------------------");
|
||||
final Integer disableRoleId = RolesHelper.disableRole(this.requestSpec, this.responseSpec, roleId);
|
||||
assertEquals(disableRoleId, roleId);
|
||||
role = RolesHelper.getRoleDetails(requestSpec, responseSpec, roleId);
|
||||
assertEquals((Integer) role.get("id"), roleId);
|
||||
assertEquals((Boolean) role.get("disabled"), true);
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("cast")
|
||||
@Test
|
||||
public void testEnableRolesStatus() {
|
||||
|
||||
System.out.println("---------------------------------CREATING A ROLE---------------------------------------------");
|
||||
final Integer roleId = RolesHelper.createRole(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(roleId);
|
||||
|
||||
System.out.println("--------------------------------- Getting ROLE -------------------------------");
|
||||
HashMap<String, Object> role = RolesHelper.getRoleDetails(requestSpec, responseSpec, roleId);
|
||||
assertEquals((Integer) role.get("id"), roleId);
|
||||
|
||||
System.out.println("--------------------------------- DISABLING ROLE -------------------------------");
|
||||
final Integer disableRoleId = RolesHelper.disableRole(this.requestSpec, this.responseSpec, roleId);
|
||||
assertEquals(disableRoleId, roleId);
|
||||
role = RolesHelper.getRoleDetails(requestSpec, responseSpec, roleId);
|
||||
assertEquals((Integer) role.get("id"), roleId);
|
||||
assertEquals((Boolean) role.get("disabled"), true);
|
||||
|
||||
System.out.println("--------------------------------- ENABLING ROLE -------------------------------");
|
||||
final Integer enableRoleId = RolesHelper.enableRole(this.requestSpec, this.responseSpec, roleId);
|
||||
assertEquals(enableRoleId, roleId);
|
||||
role = RolesHelper.getRoleDetails(requestSpec, responseSpec, roleId);
|
||||
assertEquals((Integer) role.get("id"), roleId);
|
||||
assertEquals((Boolean) role.get("disabled"), false);
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("cast")
|
||||
@Test
|
||||
public void testDeleteRoleStatus() {
|
||||
|
||||
System.out.println("-------------------------------- CREATING A ROLE---------------------------------------------");
|
||||
final Integer roleId = RolesHelper.createRole(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(roleId);
|
||||
|
||||
System.out.println("--------------------------------- Getting ROLE -------------------------------");
|
||||
HashMap<String, Object> role = RolesHelper.getRoleDetails(requestSpec, responseSpec, roleId);
|
||||
assertEquals((Integer) role.get("id"), roleId);
|
||||
|
||||
System.out.println("--------------------------------- DELETE ROLE -------------------------------");
|
||||
final Integer deleteRoleId = RolesHelper.deleteRole(this.requestSpec, this.responseSpec, roleId);
|
||||
assertEquals(deleteRoleId, roleId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRoleShouldGetDeletedIfNoActiveUserExists() {
|
||||
final Integer roleId = RolesHelper.createRole(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(roleId);
|
||||
|
||||
final Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(staffId);
|
||||
|
||||
final Integer userId = UserHelper.createUser(this.requestSpec, this.responseSpec, roleId, staffId);
|
||||
Assert.assertNotNull(userId);
|
||||
|
||||
final Integer deletedUserId = UserHelper.deleteUser(this.requestSpec, this.responseSpec, userId);
|
||||
Assert.assertEquals(deletedUserId, userId);
|
||||
|
||||
final Integer deletedRoleId = RolesHelper.deleteRole(this.requestSpec, this.responseSpec, roleId);
|
||||
assertEquals(deletedRoleId, roleId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRoleShouldNotGetDeletedIfActiveUserExists() {
|
||||
final Integer roleId = RolesHelper.createRole(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(roleId);
|
||||
|
||||
final Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(staffId);
|
||||
|
||||
final Integer userId = UserHelper.createUser(this.requestSpec, this.responseSpec, roleId, staffId);
|
||||
Assert.assertNotNull(userId);
|
||||
|
||||
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(403).build();
|
||||
final Integer deletedRoleId = RolesHelper.deleteRole(this.requestSpec, this.responseSpec, roleId);
|
||||
assertNotEquals(deletedRoleId, roleId);
|
||||
}
|
||||
|
||||
}
|
||||
+123
@@ -0,0 +1,123 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.SchedulerJobHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
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;
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked", "static-access" })
|
||||
public class SchedulerJobsTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private ResponseSpecification responseSpecForSchedulerJob;
|
||||
private SchedulerJobHelper schedulerJobHelper;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
Utils.initializeRESTAssured();
|
||||
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
|
||||
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
|
||||
this.requestSpec.header("Fineract-Platform-TenantId", "default");
|
||||
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||
this.responseSpecForSchedulerJob = new ResponseSpecBuilder().expectStatusCode(202).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSchedulerJobs() throws InterruptedException {
|
||||
this.schedulerJobHelper = new SchedulerJobHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
// Retrieving Status of Scheduler
|
||||
HashMap schedulerStatus = this.schedulerJobHelper.getSchedulerStatus(this.requestSpec, this.responseSpec);
|
||||
Boolean status = (Boolean) schedulerStatus.get("active");
|
||||
if (status == true) {
|
||||
this.schedulerJobHelper.updateSchedulerStatus(this.requestSpec, this.responseSpecForSchedulerJob, "stop");
|
||||
schedulerStatus = this.schedulerJobHelper.getSchedulerStatus(this.requestSpec, this.responseSpec);
|
||||
// Verifying Status of the Scheduler after updation
|
||||
Assert.assertEquals("Verifying Scheduler Job Status", false, schedulerStatus.get("active"));
|
||||
} else {
|
||||
this.schedulerJobHelper.updateSchedulerStatus(this.requestSpec, this.responseSpecForSchedulerJob, "start");
|
||||
schedulerStatus = this.schedulerJobHelper.getSchedulerStatus(this.requestSpec, this.responseSpec);
|
||||
// Verifying Status of the Scheduler after updation
|
||||
Assert.assertEquals("Verifying Scheduler Job Status", true, schedulerStatus.get("active"));
|
||||
}
|
||||
|
||||
// Retrieving All Scheduler Jobs
|
||||
ArrayList<HashMap> allSchedulerJobsData = this.schedulerJobHelper.getAllSchedulerJobs(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(allSchedulerJobsData);
|
||||
|
||||
for (Integer jobIndex = 0; jobIndex < allSchedulerJobsData.size(); jobIndex++) {
|
||||
|
||||
Integer jobId = (Integer) allSchedulerJobsData.get(jobIndex).get("jobId");
|
||||
|
||||
// Retrieving Scheduler Job by ID
|
||||
HashMap schedulerJob = this.schedulerJobHelper.getSchedulerJobById(this.requestSpec, this.responseSpec, jobId.toString());
|
||||
Assert.assertNotNull(schedulerJob);
|
||||
|
||||
Boolean active = (Boolean) schedulerJob.get("active");
|
||||
|
||||
if (active == true) {
|
||||
active = false;
|
||||
} else {
|
||||
active = true;
|
||||
}
|
||||
|
||||
// Updating Scheduler Job
|
||||
HashMap changes = this.schedulerJobHelper.updateSchedulerJob(this.requestSpec, this.responseSpec, jobId.toString(),
|
||||
active.toString());
|
||||
// Verifying Scheduler Job updation
|
||||
Assert.assertEquals("Verifying Scheduler Job Updation", active, changes.get("active"));
|
||||
|
||||
// Executing Scheduler Job
|
||||
this.schedulerJobHelper.runSchedulerJob(this.requestSpec, jobId.toString());
|
||||
|
||||
// Retrieving Scheduler Job by ID
|
||||
schedulerJob = this.schedulerJobHelper.getSchedulerJobById(this.requestSpec, this.responseSpec, jobId.toString());
|
||||
Assert.assertNotNull(schedulerJob);
|
||||
|
||||
// Waiting for Job to complete
|
||||
while ((Boolean) schedulerJob.get("currentlyRunning") == true) {
|
||||
Thread.sleep(15000);
|
||||
schedulerJob = this.schedulerJobHelper.getSchedulerJobById(this.requestSpec, this.responseSpec, jobId.toString());
|
||||
Assert.assertNotNull(schedulerJob);
|
||||
System.out.println("Job is Still Running");
|
||||
}
|
||||
ArrayList<HashMap> jobHistoryData = this.schedulerJobHelper.getSchedulerJobHistory(this.requestSpec, this.responseSpec,
|
||||
jobId.toString());
|
||||
|
||||
// Verifying the Status of the Recently executed Scheduler Job
|
||||
Assert.assertEquals("Verifying Last Scheduler Job Status", "success",
|
||||
jobHistoryData.get(jobHistoryData.size() - 1).get("status"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+915
@@ -0,0 +1,915 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||
import org.apache.fineract.integrationtests.common.GlobalConfigurationHelper;
|
||||
import org.apache.fineract.integrationtests.common.HolidayHelper;
|
||||
import org.apache.fineract.integrationtests.common.SchedulerJobHelper;
|
||||
import org.apache.fineract.integrationtests.common.StandingInstructionsHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.accounting.Account;
|
||||
import org.apache.fineract.integrationtests.common.accounting.AccountHelper;
|
||||
import org.apache.fineract.integrationtests.common.accounting.JournalEntry;
|
||||
import org.apache.fineract.integrationtests.common.accounting.JournalEntryHelper;
|
||||
import org.apache.fineract.integrationtests.common.charges.ChargesHelper;
|
||||
import org.apache.fineract.integrationtests.common.fixeddeposit.FixedDepositAccountHelper;
|
||||
import org.apache.fineract.integrationtests.common.fixeddeposit.FixedDepositAccountStatusChecker;
|
||||
import org.apache.fineract.integrationtests.common.fixeddeposit.FixedDepositProductHelper;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanStatusChecker;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
|
||||
import org.apache.fineract.integrationtests.common.savings.SavingsAccountHelper;
|
||||
import org.apache.fineract.integrationtests.common.savings.SavingsProductHelper;
|
||||
import org.apache.fineract.integrationtests.common.savings.SavingsStatusChecker;
|
||||
import org.apache.fineract.portfolio.account.PortfolioAccountType;
|
||||
import org.apache.fineract.portfolio.account.domain.AccountTransferType;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
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;
|
||||
|
||||
@SuppressWarnings({ "unused", "unchecked", "rawtypes", "static-access", "cast" })
|
||||
public class SchedulerJobsTestResults {
|
||||
|
||||
private static final String FROM_ACCOUNT_TYPE_LOAN = "1";
|
||||
private static final String FROM_ACCOUNT_TYPE_SAVINGS = "2";
|
||||
private static final String TO_ACCOUNT_TYPE_LOAN = "1";
|
||||
private static final String TO_ACCOUNT_TYPE_SAVINGS = "2";
|
||||
private final String DATE_OF_JOINING = "01 January 2011";
|
||||
|
||||
private final String TRANSACTION_DATE = "01 March 2013";
|
||||
public static final String ACCOUNT_TYPE_INDIVIDUAL = "INDIVIDUAL";
|
||||
public static final String MINIMUM_OPENING_BALANCE = "1000";
|
||||
|
||||
Float SP_BALANCE = new Float(MINIMUM_OPENING_BALANCE);
|
||||
|
||||
private static ResponseSpecification responseSpec;
|
||||
private static RequestSpecification requestSpec;
|
||||
private ResponseSpecification responseSpecForSchedulerJob;
|
||||
private SchedulerJobHelper schedulerJobHelper;
|
||||
private SavingsAccountHelper savingsAccountHelper;
|
||||
private LoanTransactionHelper loanTransactionHelper;
|
||||
private HolidayHelper holidayHelper;
|
||||
private GlobalConfigurationHelper globalConfigurationHelper;
|
||||
private AccountHelper accountHelper;
|
||||
private JournalEntryHelper journalEntryHelper;
|
||||
private StandingInstructionsHelper standingInstructionsHelper;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
Utils.initializeRESTAssured();
|
||||
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
|
||||
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
|
||||
this.requestSpec.header("Fineract-Platform-TenantId", "default");
|
||||
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||
this.responseSpecForSchedulerJob = new ResponseSpecBuilder().expectStatusCode(202).build();
|
||||
this.accountHelper = new AccountHelper(this.requestSpec, this.responseSpec);
|
||||
this.journalEntryHelper = new JournalEntryHelper(this.requestSpec, this.responseSpec);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApplyAnnualFeeForSavingsJobOutcome() throws InterruptedException {
|
||||
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
|
||||
this.schedulerJobHelper = new SchedulerJobHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(clientID);
|
||||
|
||||
final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec,
|
||||
ClientSavingsIntegrationTest.MINIMUM_OPENING_BALANCE);
|
||||
Assert.assertNotNull(savingsProductID);
|
||||
|
||||
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID,
|
||||
ClientSavingsIntegrationTest.ACCOUNT_TYPE_INDIVIDUAL);
|
||||
Assert.assertNotNull(savingsProductID);
|
||||
|
||||
HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap);
|
||||
|
||||
final Integer annualFeeChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
|
||||
ChargesHelper.getSavingsAnnualFeeJSON());
|
||||
Assert.assertNotNull(annualFeeChargeId);
|
||||
|
||||
this.savingsAccountHelper.addChargesForSavings(savingsId, annualFeeChargeId);
|
||||
ArrayList<HashMap> chargesPendingState = this.savingsAccountHelper.getSavingsCharges(savingsId);
|
||||
Assert.assertEquals(1, chargesPendingState.size());
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.approveSavings(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap);
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.activateSavings(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap);
|
||||
|
||||
HashMap summaryBefore = this.savingsAccountHelper.getSavingsSummary(savingsId);
|
||||
String JobName = "Apply Annual Fee For Savings";
|
||||
|
||||
this.schedulerJobHelper.executeJob(JobName);
|
||||
final HashMap chargeData = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, annualFeeChargeId);
|
||||
|
||||
Float chargeAmount = (Float) chargeData.get("amount");
|
||||
|
||||
final HashMap summaryAfter = this.savingsAccountHelper.getSavingsSummary(savingsId);
|
||||
Assert.assertEquals("Verifying Annual Fee after Running Scheduler Job for Apply Anual Fee", chargeAmount,
|
||||
(Float) summaryAfter.get("totalAnnualFees"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInterestPostingForSavingsJobOutcome() throws InterruptedException {
|
||||
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
|
||||
this.schedulerJobHelper = new SchedulerJobHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(clientID);
|
||||
|
||||
final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec,
|
||||
ClientSavingsIntegrationTest.MINIMUM_OPENING_BALANCE);
|
||||
Assert.assertNotNull(savingsProductID);
|
||||
|
||||
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID,
|
||||
ClientSavingsIntegrationTest.ACCOUNT_TYPE_INDIVIDUAL);
|
||||
Assert.assertNotNull(savingsProductID);
|
||||
|
||||
HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap);
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.approveSavings(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap);
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.activateSavings(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap);
|
||||
|
||||
final HashMap summaryBefore = this.savingsAccountHelper.getSavingsSummary(savingsId);
|
||||
|
||||
String JobName = "Post Interest For Savings";
|
||||
|
||||
this.schedulerJobHelper.executeJob(JobName);
|
||||
final HashMap summaryAfter = this.savingsAccountHelper.getSavingsSummary(savingsId);
|
||||
|
||||
Assert.assertNotSame("Verifying the Balance after running Post Interest for Savings Job", summaryBefore.get("accountBalance"),
|
||||
summaryAfter.get("accountBalance"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransferFeeForLoansFromSavingsJobOutcome() throws InterruptedException {
|
||||
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
|
||||
this.schedulerJobHelper = new SchedulerJobHelper(this.requestSpec, this.responseSpec);
|
||||
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(clientID);
|
||||
|
||||
final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec,
|
||||
ClientSavingsIntegrationTest.MINIMUM_OPENING_BALANCE);
|
||||
Assert.assertNotNull(savingsProductID);
|
||||
|
||||
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID,
|
||||
ClientSavingsIntegrationTest.ACCOUNT_TYPE_INDIVIDUAL);
|
||||
Assert.assertNotNull(savingsProductID);
|
||||
|
||||
HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap);
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.approveSavings(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap);
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.activateSavings(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap);
|
||||
|
||||
final Integer loanProductID = createLoanProduct(null);
|
||||
Assert.assertNotNull(loanProductID);
|
||||
|
||||
final Integer loanID = applyForLoanApplication(clientID.toString(), loanProductID.toString(), savingsId.toString());
|
||||
Assert.assertNotNull(loanID);
|
||||
|
||||
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
|
||||
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
|
||||
|
||||
loanStatusHashMap = this.loanTransactionHelper.approveLoan(AccountTransferTest.LOAN_APPROVAL_DATE, loanID);
|
||||
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
|
||||
|
||||
Integer specifiedDueDateChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
|
||||
ChargesHelper.getLoanSpecifiedDueDateWithAccountTransferJSON());
|
||||
Assert.assertNotNull(specifiedDueDateChargeId);
|
||||
|
||||
this.loanTransactionHelper.addChargesForLoan(loanID,
|
||||
LoanTransactionHelper.getSpecifiedDueDateChargesForLoanAsJSON(specifiedDueDateChargeId.toString(), "12 March 2013", "100"));
|
||||
ArrayList<HashMap> chargesPendingState = this.loanTransactionHelper.getLoanCharges(loanID);
|
||||
Assert.assertEquals(1, chargesPendingState.size());
|
||||
|
||||
loanStatusHashMap = this.loanTransactionHelper.disburseLoan(AccountTransferTest.LOAN_DISBURSAL_DATE, loanID);
|
||||
LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
|
||||
final HashMap summaryBefore = this.savingsAccountHelper.getSavingsSummary(savingsId);
|
||||
|
||||
String JobName = "Transfer Fee For Loans From Savings";
|
||||
this.schedulerJobHelper.executeJob(JobName);
|
||||
final HashMap summaryAfter = this.savingsAccountHelper.getSavingsSummary(savingsId);
|
||||
|
||||
final HashMap chargeData = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, specifiedDueDateChargeId);
|
||||
|
||||
Float chargeAmount = (Float) chargeData.get("amount");
|
||||
|
||||
final Float balance = (Float) summaryBefore.get("accountBalance") - chargeAmount;
|
||||
|
||||
Assert.assertEquals("Verifying the Balance after running Transfer Fee for Loans from Savings", balance,
|
||||
(Float) summaryAfter.get("accountBalance"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApplyHolidaysToLoansJobOutcome() throws InterruptedException {
|
||||
this.schedulerJobHelper = new SchedulerJobHelper(this.requestSpec, this.responseSpec);
|
||||
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
|
||||
this.holidayHelper = new HolidayHelper(this.requestSpec, this.responseSpec);
|
||||
this.globalConfigurationHelper = new GlobalConfigurationHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(clientID);
|
||||
|
||||
Integer holidayId = this.holidayHelper.createHolidays(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(holidayId);
|
||||
|
||||
final Integer loanProductID = createLoanProduct(null);
|
||||
Assert.assertNotNull(loanProductID);
|
||||
|
||||
final Integer loanID = applyForLoanApplication(clientID.toString(), loanProductID.toString(), null);
|
||||
Assert.assertNotNull(loanID);
|
||||
|
||||
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
|
||||
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
|
||||
|
||||
loanStatusHashMap = this.loanTransactionHelper.approveLoan(AccountTransferTest.LOAN_APPROVAL_DATE, loanID);
|
||||
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
|
||||
|
||||
loanStatusHashMap = this.loanTransactionHelper.disburseLoan(AccountTransferTest.LOAN_DISBURSAL_DATE, loanID);
|
||||
LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
|
||||
|
||||
// Retrieving All Global Configuration details
|
||||
final ArrayList<HashMap> globalConfig = this.globalConfigurationHelper.getAllGlobalConfigurations(this.requestSpec,
|
||||
this.responseSpec);
|
||||
Assert.assertNotNull(globalConfig);
|
||||
|
||||
// Updating Value for reschedule-repayments-on-holidays Global
|
||||
// Configuration
|
||||
Integer configId = (Integer) globalConfig.get(3).get("id");
|
||||
Assert.assertNotNull(configId);
|
||||
|
||||
HashMap configData = this.globalConfigurationHelper.getGlobalConfigurationById(this.requestSpec, this.responseSpec,
|
||||
configId.toString());
|
||||
Assert.assertNotNull(configData);
|
||||
|
||||
Boolean enabled = (Boolean) globalConfig.get(3).get("enabled");
|
||||
|
||||
if (enabled == false) {
|
||||
enabled = true;
|
||||
configId = this.globalConfigurationHelper.updateEnabledFlagForGlobalConfiguration(this.requestSpec, this.responseSpec,
|
||||
configId.toString(), enabled);
|
||||
}
|
||||
final ArrayList<HashMap> repaymentScheduleDataBeforeJob = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec,
|
||||
this.responseSpec, loanID);
|
||||
|
||||
holidayId = this.holidayHelper.activateHolidays(this.requestSpec, this.responseSpec, holidayId.toString());
|
||||
Assert.assertNotNull(holidayId);
|
||||
|
||||
String JobName = "Apply Holidays To Loans";
|
||||
|
||||
this.schedulerJobHelper.executeJob(JobName);
|
||||
final ArrayList<HashMap> repaymentScheduleDataAfterJob = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec,
|
||||
this.responseSpec, loanID);
|
||||
|
||||
HashMap holidayData = this.holidayHelper.getHolidayById(this.requestSpec, this.responseSpec, holidayId.toString());
|
||||
ArrayList<Integer> repaymentsRescheduledDate = (ArrayList<Integer>) holidayData.get("repaymentsRescheduledTo");
|
||||
|
||||
ArrayList<Integer> rescheduleDateAfter = (ArrayList<Integer>) repaymentScheduleDataAfterJob.get(2).get("fromDate");
|
||||
|
||||
Assert.assertEquals("Verifying Repayment Rescheduled Date after Running Apply Holidays to Loans Scheduler Job",
|
||||
repaymentsRescheduledDate, repaymentsRescheduledDate);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApplyDueFeeChargesForSavingsJobOutcome() throws InterruptedException {
|
||||
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
|
||||
this.schedulerJobHelper = new SchedulerJobHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(clientID);
|
||||
|
||||
final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec,
|
||||
ClientSavingsIntegrationTest.MINIMUM_OPENING_BALANCE);
|
||||
Assert.assertNotNull(savingsProductID);
|
||||
|
||||
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID,
|
||||
ClientSavingsIntegrationTest.ACCOUNT_TYPE_INDIVIDUAL);
|
||||
Assert.assertNotNull(savingsProductID);
|
||||
|
||||
HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap);
|
||||
|
||||
final Integer specifiedDueDateChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
|
||||
ChargesHelper.getSavingsSpecifiedDueDateJSON());
|
||||
Assert.assertNotNull(specifiedDueDateChargeId);
|
||||
|
||||
this.savingsAccountHelper.addChargesForSavings(savingsId, specifiedDueDateChargeId);
|
||||
ArrayList<HashMap> chargesPendingState = this.savingsAccountHelper.getSavingsCharges(savingsId);
|
||||
Assert.assertEquals(1, chargesPendingState.size());
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.approveSavings(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap);
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.activateSavings(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap);
|
||||
|
||||
HashMap summaryBefore = this.savingsAccountHelper.getSavingsSummary(savingsId);
|
||||
|
||||
String JobName = "Pay Due Savings Charges";
|
||||
|
||||
this.schedulerJobHelper.executeJob(JobName);
|
||||
HashMap summaryAfter = this.savingsAccountHelper.getSavingsSummary(savingsId);
|
||||
|
||||
final HashMap chargeData = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, specifiedDueDateChargeId);
|
||||
|
||||
Float chargeAmount = (Float) chargeData.get("amount");
|
||||
|
||||
final Float balance = (Float) summaryBefore.get("accountBalance") - chargeAmount;
|
||||
|
||||
Assert.assertEquals("Verifying the Balance after running Pay due Savings Charges", balance,
|
||||
(Float) summaryAfter.get("accountBalance"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateAccountingRunningBalancesJobOutcome() throws InterruptedException {
|
||||
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
|
||||
this.schedulerJobHelper = new SchedulerJobHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
final Account assetAccount = this.accountHelper.createAssetAccount();
|
||||
final Account incomeAccount = this.accountHelper.createIncomeAccount();
|
||||
final Account expenseAccount = this.accountHelper.createExpenseAccount();
|
||||
final Account liabilityAccount = this.accountHelper.createLiabilityAccount();
|
||||
|
||||
final Integer accountID = assetAccount.getAccountID();
|
||||
|
||||
final Integer savingsProductID = createSavingsProduct(MINIMUM_OPENING_BALANCE, assetAccount, incomeAccount, expenseAccount,
|
||||
liabilityAccount);
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, this.DATE_OF_JOINING);
|
||||
final Integer savingsID = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID, ACCOUNT_TYPE_INDIVIDUAL);
|
||||
|
||||
HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsID);
|
||||
SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap);
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.approveSavings(savingsID);
|
||||
SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap);
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.activateSavings(savingsID);
|
||||
SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap);
|
||||
|
||||
// Checking initial Account entries.
|
||||
final JournalEntry[] assetAccountInitialEntry = { new JournalEntry(this.SP_BALANCE, JournalEntry.TransactionType.DEBIT) };
|
||||
final JournalEntry[] liablilityAccountInitialEntry = { new JournalEntry(this.SP_BALANCE, JournalEntry.TransactionType.CREDIT) };
|
||||
this.journalEntryHelper.checkJournalEntryForAssetAccount(assetAccount, this.TRANSACTION_DATE, assetAccountInitialEntry);
|
||||
this.journalEntryHelper
|
||||
.checkJournalEntryForLiabilityAccount(liabilityAccount, this.TRANSACTION_DATE, liablilityAccountInitialEntry);
|
||||
|
||||
String JobName = "Update Accounting Running Balances";
|
||||
|
||||
this.schedulerJobHelper.executeJob(JobName);
|
||||
final HashMap runningBalanceAfter = this.accountHelper.getAccountingWithRunningBalanceById(accountID.toString());
|
||||
|
||||
final Integer INT_BALANCE = new Integer(MINIMUM_OPENING_BALANCE);
|
||||
|
||||
Assert.assertEquals("Verifying Account Running Balance after running Update Accounting Running Balances Scheduler Job",
|
||||
INT_BALANCE, runningBalanceAfter.get("organizationRunningBalance"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateLoanArrearsAgingJobOutcome() throws InterruptedException {
|
||||
this.schedulerJobHelper = new SchedulerJobHelper(this.requestSpec, this.responseSpec);
|
||||
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(clientID);
|
||||
|
||||
final Integer loanProductID = createLoanProduct(null);
|
||||
Assert.assertNotNull(loanProductID);
|
||||
|
||||
final Integer loanID = applyForLoanApplication(clientID.toString(), loanProductID.toString(), null);
|
||||
Assert.assertNotNull(loanID);
|
||||
|
||||
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
|
||||
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
|
||||
|
||||
loanStatusHashMap = this.loanTransactionHelper.approveLoan(AccountTransferTest.LOAN_APPROVAL_DATE, loanID);
|
||||
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
|
||||
|
||||
loanStatusHashMap = this.loanTransactionHelper.disburseLoan(AccountTransferTest.LOAN_DISBURSAL_DATE, loanID);
|
||||
LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
|
||||
|
||||
String JobName = "Update Loan Arrears Ageing";
|
||||
|
||||
this.schedulerJobHelper.executeJob(JobName);
|
||||
HashMap loanSummaryData = this.loanTransactionHelper.getLoanSummary(this.requestSpec, this.responseSpec, loanID);
|
||||
|
||||
Float totalLoanArrearsAging = (Float) loanSummaryData.get("principalOverdue") + (Float) loanSummaryData.get("interestOverdue");
|
||||
|
||||
Assert.assertEquals("Verifying Arrears Aging after Running Update Loan Arrears Aging Scheduler Job", totalLoanArrearsAging,
|
||||
loanSummaryData.get("totalOverdue"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateLoanPaidInAdvanceJobOutcome() throws InterruptedException {
|
||||
this.schedulerJobHelper = new SchedulerJobHelper(this.requestSpec, this.responseSpec);
|
||||
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy", Locale.US);
|
||||
|
||||
Calendar todayDate = Calendar.getInstance();
|
||||
final String currentDate = dateFormat.format(todayDate.getTime());
|
||||
|
||||
todayDate.add(Calendar.MONTH, -1);
|
||||
final String LOAN_DISBURSEMENT_DATE = dateFormat.format(todayDate.getTime());
|
||||
|
||||
todayDate = Calendar.getInstance();
|
||||
todayDate.add(Calendar.DATE, -5);
|
||||
final String LOAN_FIRST_REPAYMENT_DATE = dateFormat.format(todayDate.getTime());
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(clientID);
|
||||
|
||||
final Integer loanProductID = createLoanProduct(null);
|
||||
Assert.assertNotNull(loanProductID);
|
||||
|
||||
final Integer loanID = applyForLoanApplication(clientID.toString(), loanProductID.toString(), null);
|
||||
Assert.assertNotNull(loanID);
|
||||
|
||||
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
|
||||
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
|
||||
|
||||
loanStatusHashMap = this.loanTransactionHelper.approveLoan(AccountTransferTest.LOAN_APPROVAL_DATE, loanID);
|
||||
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
|
||||
|
||||
loanStatusHashMap = this.loanTransactionHelper.disburseLoan(LOAN_DISBURSEMENT_DATE, loanID);
|
||||
LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
|
||||
|
||||
ArrayList<HashMap> loanScheduleBefore = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec,
|
||||
loanID);
|
||||
|
||||
Float totalDueForCurrentPeriod = (Float) loanScheduleBefore.get(1).get("totalDueForPeriod");
|
||||
|
||||
this.loanTransactionHelper.makeRepayment(LOAN_FIRST_REPAYMENT_DATE, totalDueForCurrentPeriod, loanID);
|
||||
|
||||
HashMap loanSummary = this.loanTransactionHelper.getLoanSummary(this.requestSpec, this.responseSpec, loanID);
|
||||
|
||||
String JobName = "Update Loan Paid In Advance";
|
||||
this.schedulerJobHelper.executeJob(JobName);
|
||||
// Retrieving Loan Repayment Schedule after the successful
|
||||
// completion of
|
||||
// Update Loan Paid in Advance Scheduler Job
|
||||
ArrayList<HashMap> loanScheduleAfter = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec,
|
||||
loanID);
|
||||
|
||||
loanSummary = this.loanTransactionHelper.getLoanSummary(this.requestSpec, this.responseSpec, loanID);
|
||||
|
||||
Float totalPaidInAdvance = (Float) loanScheduleAfter.get(1).get("totalPaidInAdvanceForPeriod");
|
||||
|
||||
Assert.assertEquals("Verifying Loan Repayment in Advance after Running Update Loan Paid in Advance Scheduler Job",
|
||||
totalDueForCurrentPeriod, totalPaidInAdvance);
|
||||
|
||||
}
|
||||
|
||||
// Invalid test case as it won't affect summary (Loan summary is properly
|
||||
// updated before running this job)
|
||||
@Ignore
|
||||
@Test
|
||||
public void testUpdateLoanSummaryJobOutcome() throws InterruptedException {
|
||||
this.schedulerJobHelper = new SchedulerJobHelper(this.requestSpec, this.responseSpec);
|
||||
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy", Locale.US);
|
||||
|
||||
Calendar todaysDate = Calendar.getInstance();
|
||||
final String currentDate = dateFormat.format(todaysDate.getTime());
|
||||
|
||||
todaysDate.add(Calendar.MONTH, -1);
|
||||
final String LOAN_DISBURSEMENT_DATE = dateFormat.format(todaysDate.getTime());
|
||||
|
||||
todaysDate = Calendar.getInstance();
|
||||
todaysDate.add(Calendar.DATE, -5);
|
||||
final String LOAN_FIRST_REPAYMENT_DATE = dateFormat.format(todaysDate.getTime());
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(clientID);
|
||||
|
||||
final Integer loanProductID = createLoanProduct(null);
|
||||
Assert.assertNotNull(loanProductID);
|
||||
|
||||
final Integer loanID = applyForLoanApplication(clientID.toString(), loanProductID.toString(), null);
|
||||
Assert.assertNotNull(loanID);
|
||||
|
||||
Integer disburseChargeId = ChargesHelper
|
||||
.createCharges(this.requestSpec, this.responseSpec, ChargesHelper.getLoanDisbursementJSON());
|
||||
Assert.assertNotNull(disburseChargeId);
|
||||
|
||||
this.loanTransactionHelper.addChargesForLoan(loanID,
|
||||
LoanTransactionHelper.getDisbursementChargesForLoanAsJSON(disburseChargeId.toString()));
|
||||
ArrayList<HashMap> chargesPendingState = this.loanTransactionHelper.getLoanCharges(loanID);
|
||||
Assert.assertEquals(1, chargesPendingState.size());
|
||||
|
||||
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
|
||||
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
|
||||
|
||||
loanStatusHashMap = this.loanTransactionHelper.approveLoan(AccountTransferTest.LOAN_APPROVAL_DATE, loanID);
|
||||
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
|
||||
|
||||
loanStatusHashMap = this.loanTransactionHelper.disburseLoan(LOAN_DISBURSEMENT_DATE, loanID);
|
||||
LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
|
||||
|
||||
HashMap loanSummaryBefore = this.loanTransactionHelper.getLoanSummary(this.requestSpec, this.responseSpec, loanID);
|
||||
|
||||
String JobName = "Update loan Summary";
|
||||
this.schedulerJobHelper.executeJob(JobName);
|
||||
Float expectedSummaryAfterJob = (Float) loanSummaryBefore.get("totalExpectedRepayment")
|
||||
/* - (Float) loanSummaryBefore.get("feeChargesPaid")*/;
|
||||
HashMap loanSummaryAfter = this.loanTransactionHelper.getLoanSummary(this.requestSpec, this.responseSpec, loanID);
|
||||
Assert.assertEquals("Verifying Loan Summary after Running Update Loan Summary Scheduler Job", expectedSummaryAfterJob,
|
||||
(Float) loanSummaryAfter.get("totalExpectedRepayment"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteStandingInstructionsJobOutcome() throws InterruptedException {
|
||||
this.schedulerJobHelper = new SchedulerJobHelper(this.requestSpec, this.responseSpec);
|
||||
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
|
||||
this.standingInstructionsHelper = new StandingInstructionsHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy", Locale.US);
|
||||
DateFormat monthDayFormat = new SimpleDateFormat("dd MMMM", Locale.US);
|
||||
|
||||
Calendar todaysDate = Calendar.getInstance();
|
||||
todaysDate.add(Calendar.WEEK_OF_YEAR, -1);
|
||||
final String VALID_FROM = dateFormat.format(todaysDate.getTime());
|
||||
|
||||
final String MONTH_DAY = monthDayFormat.format(todaysDate.getTime());
|
||||
|
||||
todaysDate.add(Calendar.YEAR, 1);
|
||||
final String VALID_TO = dateFormat.format(todaysDate.getTime());
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(clientID);
|
||||
|
||||
final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec,
|
||||
ClientSavingsIntegrationTest.MINIMUM_OPENING_BALANCE);
|
||||
Assert.assertNotNull(savingsProductID);
|
||||
|
||||
final Integer fromSavingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID,
|
||||
ClientSavingsIntegrationTest.ACCOUNT_TYPE_INDIVIDUAL);
|
||||
Assert.assertNotNull(savingsProductID);
|
||||
|
||||
HashMap fromSavingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, fromSavingsId);
|
||||
SavingsStatusChecker.verifySavingsIsPending(fromSavingsStatusHashMap);
|
||||
|
||||
fromSavingsStatusHashMap = this.savingsAccountHelper.approveSavings(fromSavingsId);
|
||||
SavingsStatusChecker.verifySavingsIsApproved(fromSavingsStatusHashMap);
|
||||
|
||||
fromSavingsStatusHashMap = this.savingsAccountHelper.activateSavings(fromSavingsId);
|
||||
SavingsStatusChecker.verifySavingsIsActive(fromSavingsStatusHashMap);
|
||||
|
||||
final Integer toSavingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID,
|
||||
ClientSavingsIntegrationTest.ACCOUNT_TYPE_INDIVIDUAL);
|
||||
Assert.assertNotNull(savingsProductID);
|
||||
|
||||
HashMap toSavingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, toSavingsId);
|
||||
SavingsStatusChecker.verifySavingsIsPending(toSavingsStatusHashMap);
|
||||
|
||||
toSavingsStatusHashMap = this.savingsAccountHelper.approveSavings(toSavingsId);
|
||||
SavingsStatusChecker.verifySavingsIsApproved(toSavingsStatusHashMap);
|
||||
|
||||
toSavingsStatusHashMap = this.savingsAccountHelper.activateSavings(toSavingsId);
|
||||
SavingsStatusChecker.verifySavingsIsActive(toSavingsStatusHashMap);
|
||||
|
||||
HashMap fromSavingsSummaryBefore = this.savingsAccountHelper.getSavingsSummary(fromSavingsId);
|
||||
Float fromSavingsBalanceBefore = (Float) fromSavingsSummaryBefore.get("accountBalance");
|
||||
|
||||
HashMap toSavingsSummaryBefore = this.savingsAccountHelper.getSavingsSummary(toSavingsId);
|
||||
Float toSavingsBalanceBefore = (Float) toSavingsSummaryBefore.get("accountBalance");
|
||||
|
||||
Integer standingInstructionId = this.standingInstructionsHelper.createStandingInstruction(clientID.toString(),
|
||||
fromSavingsId.toString(), toSavingsId.toString(), FROM_ACCOUNT_TYPE_SAVINGS, TO_ACCOUNT_TYPE_SAVINGS, VALID_FROM, VALID_TO,
|
||||
MONTH_DAY);
|
||||
Assert.assertNotNull(standingInstructionId);
|
||||
|
||||
String JobName = "Execute Standing Instruction";
|
||||
this.schedulerJobHelper.executeJob(JobName);
|
||||
HashMap fromSavingsSummaryAfter = this.savingsAccountHelper.getSavingsSummary(fromSavingsId);
|
||||
Float fromSavingsBalanceAfter = (Float) fromSavingsSummaryAfter.get("accountBalance");
|
||||
|
||||
HashMap toSavingsSummaryAfter = this.savingsAccountHelper.getSavingsSummary(toSavingsId);
|
||||
Float toSavingsBalanceAfter = (Float) toSavingsSummaryAfter.get("accountBalance");
|
||||
|
||||
final HashMap standingInstructionData = this.standingInstructionsHelper
|
||||
.getStandingInstructionById(standingInstructionId.toString());
|
||||
Float expectedFromSavingsBalance = fromSavingsBalanceBefore - (Float) standingInstructionData.get("amount");
|
||||
Float expectedToSavingsBalance = toSavingsBalanceBefore + (Float) standingInstructionData.get("amount");
|
||||
|
||||
Assert.assertEquals("Verifying From Savings Balance after Successful completion of Scheduler Job", expectedFromSavingsBalance,
|
||||
fromSavingsBalanceAfter);
|
||||
Assert.assertEquals("Verifying To Savings Balance after Successful completion of Scheduler Job", expectedToSavingsBalance,
|
||||
toSavingsBalanceAfter);
|
||||
Integer fromAccountType = PortfolioAccountType.SAVINGS.getValue();
|
||||
Integer transferType = AccountTransferType.ACCOUNT_TRANSFER.getValue();
|
||||
List<HashMap> standinInstructionHistoryData = this.standingInstructionsHelper.getStandingInstructionHistory(fromSavingsId,
|
||||
fromAccountType, clientID, transferType);
|
||||
Assert.assertEquals("Verifying the no of stainding instruction transactions logged for the client", 1,
|
||||
standinInstructionHistoryData.size());
|
||||
HashMap loggedTransaction = standinInstructionHistoryData.get(0);
|
||||
|
||||
Assert.assertEquals("Verifying transferred amount and logged transaction amounts", (Float) standingInstructionData.get("amount"),
|
||||
(Float) loggedTransaction.get("amount"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApplyPenaltyForOverdueLoansJobOutcome() throws InterruptedException {
|
||||
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
|
||||
this.schedulerJobHelper = new SchedulerJobHelper(this.requestSpec, this.responseSpec);
|
||||
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(clientID);
|
||||
|
||||
Integer overdueFeeChargeId = ChargesHelper
|
||||
.createCharges(this.requestSpec, this.responseSpec, ChargesHelper.getLoanOverdueFeeJSON());
|
||||
Assert.assertNotNull(overdueFeeChargeId);
|
||||
|
||||
final Integer loanProductID = createLoanProduct(overdueFeeChargeId.toString());
|
||||
Assert.assertNotNull(loanProductID);
|
||||
|
||||
final Integer loanID = applyForLoanApplication(clientID.toString(), loanProductID.toString(), null);
|
||||
Assert.assertNotNull(loanID);
|
||||
|
||||
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
|
||||
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
|
||||
|
||||
loanStatusHashMap = this.loanTransactionHelper.approveLoan(AccountTransferTest.LOAN_APPROVAL_DATE, loanID);
|
||||
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
|
||||
|
||||
loanStatusHashMap = this.loanTransactionHelper.disburseLoan(AccountTransferTest.LOAN_APPROVAL_DATE_PLUS_ONE, loanID);
|
||||
LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
|
||||
|
||||
ArrayList<HashMap> repaymentScheduleDataBefore = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec,
|
||||
this.responseSpec, loanID);
|
||||
|
||||
String JobName = "Apply penalty to overdue loans";
|
||||
this.schedulerJobHelper.executeJob(JobName);
|
||||
|
||||
final HashMap chargeData = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, overdueFeeChargeId);
|
||||
|
||||
Float chargeAmount = (Float) chargeData.get("amount");
|
||||
|
||||
ArrayList<HashMap> repaymentScheduleDataAfter = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec,
|
||||
this.responseSpec, loanID);
|
||||
|
||||
Assert.assertEquals("Verifying From Penalty Charges due fot first Repayment after Successful completion of Scheduler Job",
|
||||
chargeAmount, (Float) repaymentScheduleDataAfter.get(1).get("penaltyChargesDue"));
|
||||
|
||||
loanStatusHashMap = this.loanTransactionHelper.undoDisbursal(loanID);
|
||||
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
|
||||
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateOverdueDaysForNPA() throws InterruptedException {
|
||||
this.schedulerJobHelper = new SchedulerJobHelper(this.requestSpec, this.responseSpec);
|
||||
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(clientID);
|
||||
|
||||
final Integer loanProductID = createLoanProduct(null);
|
||||
Assert.assertNotNull(loanProductID);
|
||||
|
||||
final Integer loanID = applyForLoanApplication(clientID.toString(), loanProductID.toString(), null);
|
||||
Assert.assertNotNull(loanID);
|
||||
|
||||
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
|
||||
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
|
||||
|
||||
loanStatusHashMap = this.loanTransactionHelper.approveLoan(AccountTransferTest.LOAN_APPROVAL_DATE, loanID);
|
||||
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
|
||||
|
||||
loanStatusHashMap = this.loanTransactionHelper.disburseLoan(AccountTransferTest.LOAN_DISBURSAL_DATE, loanID);
|
||||
LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
|
||||
|
||||
final Boolean isNPABefore = (Boolean) this.loanTransactionHelper.getLoanDetail(requestSpec, responseSpec, loanID, "isNPA");
|
||||
Assert.assertFalse(isNPABefore);
|
||||
// Integer jobId = (Integer) allSchedulerJobsData.get(1).get("jobId");
|
||||
String JobName = "Update Non Performing Assets";
|
||||
this.schedulerJobHelper.executeJob(JobName);
|
||||
final Boolean isNPAAfter = (Boolean) this.loanTransactionHelper.getLoanDetail(requestSpec, responseSpec, loanID, "isNPA");
|
||||
Assert.assertTrue(isNPAAfter);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInterestTransferForSavings() throws InterruptedException {
|
||||
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
|
||||
this.schedulerJobHelper = new SchedulerJobHelper(this.requestSpec, this.responseSpec);
|
||||
FixedDepositProductHelper fixedDepositProductHelper = new FixedDepositProductHelper(this.requestSpec, this.responseSpec);
|
||||
AccountHelper accountHelper = new AccountHelper(this.requestSpec, this.responseSpec);
|
||||
FixedDepositAccountHelper fixedDepositAccountHelper = new FixedDepositAccountHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy", Locale.US);
|
||||
DateFormat monthDayFormat = new SimpleDateFormat("dd MMM", Locale.US);
|
||||
|
||||
Calendar todaysDate = Calendar.getInstance();
|
||||
todaysDate.add(Calendar.MONTH, -3);
|
||||
final String VALID_FROM = dateFormat.format(todaysDate.getTime());
|
||||
todaysDate.add(Calendar.YEAR, 10);
|
||||
final String VALID_TO = dateFormat.format(todaysDate.getTime());
|
||||
|
||||
todaysDate = Calendar.getInstance();
|
||||
todaysDate.add(Calendar.MONTH, -2);
|
||||
final String SUBMITTED_ON_DATE = dateFormat.format(todaysDate.getTime());
|
||||
final String APPROVED_ON_DATE = dateFormat.format(todaysDate.getTime());
|
||||
final String ACTIVATION_DATE = dateFormat.format(todaysDate.getTime());
|
||||
todaysDate.add(Calendar.MONTH, 1);
|
||||
final String WHOLE_TERM = "1";
|
||||
|
||||
Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(clientId);
|
||||
Float balance = new Float(MINIMUM_OPENING_BALANCE) + new Float(FixedDepositAccountHelper.depositAmount);
|
||||
final Integer savingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, String.valueOf(balance));
|
||||
Assert.assertNotNull(savingsProductID);
|
||||
|
||||
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientId, savingsProductID,
|
||||
ClientSavingsIntegrationTest.ACCOUNT_TYPE_INDIVIDUAL);
|
||||
Assert.assertNotNull(savingsId);
|
||||
|
||||
HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(this.requestSpec, this.responseSpec, savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap);
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.approveSavings(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap);
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.activateSavings(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap);
|
||||
HashMap summary = savingsAccountHelper.getSavingsSummary(savingsId);
|
||||
assertEquals("Verifying opening Balance", balance, summary.get("accountBalance"));
|
||||
|
||||
Integer fixedDepositProductId = createFixedDepositProduct(VALID_FROM, VALID_TO);
|
||||
Assert.assertNotNull(fixedDepositProductId);
|
||||
|
||||
Integer fixedDepositAccountId = applyForFixedDepositApplication(clientId.toString(), fixedDepositProductId.toString(), VALID_FROM,
|
||||
VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM, savingsId.toString(), true, fixedDepositAccountHelper);
|
||||
Assert.assertNotNull(fixedDepositAccountId);
|
||||
|
||||
HashMap fixedDepositAccountStatusHashMap = FixedDepositAccountStatusChecker.getStatusOfFixedDepositAccount(this.requestSpec,
|
||||
this.responseSpec, fixedDepositAccountId.toString());
|
||||
FixedDepositAccountStatusChecker.verifyFixedDepositIsPending(fixedDepositAccountStatusHashMap);
|
||||
|
||||
fixedDepositAccountStatusHashMap = fixedDepositAccountHelper.approveFixedDeposit(fixedDepositAccountId, APPROVED_ON_DATE);
|
||||
FixedDepositAccountStatusChecker.verifyFixedDepositIsApproved(fixedDepositAccountStatusHashMap);
|
||||
|
||||
fixedDepositAccountStatusHashMap = fixedDepositAccountHelper.activateFixedDeposit(fixedDepositAccountId, ACTIVATION_DATE);
|
||||
FixedDepositAccountStatusChecker.verifyFixedDepositIsActive(fixedDepositAccountStatusHashMap);
|
||||
summary = savingsAccountHelper.getSavingsSummary(savingsId);
|
||||
balance = new Float(MINIMUM_OPENING_BALANCE);
|
||||
assertEquals("Verifying Balance", balance, summary.get("accountBalance"));
|
||||
|
||||
fixedDepositAccountHelper.postInterestForFixedDeposit(fixedDepositAccountId);
|
||||
|
||||
HashMap fixedDepositSummary = savingsAccountHelper.getSavingsSummary(fixedDepositAccountId);
|
||||
Float interestPosted = (Float) fixedDepositSummary.get("accountBalance") - new Float(FixedDepositAccountHelper.depositAmount);
|
||||
|
||||
String JobName = "Transfer Interest To Savings";
|
||||
this.schedulerJobHelper.executeJob(JobName);
|
||||
fixedDepositSummary = savingsAccountHelper.getSavingsSummary(fixedDepositAccountId);
|
||||
assertEquals("Verifying opening Balance", new Float(FixedDepositAccountHelper.depositAmount),
|
||||
fixedDepositSummary.get("accountBalance"));
|
||||
|
||||
summary = savingsAccountHelper.getSavingsSummary(savingsId);
|
||||
balance = new Float(MINIMUM_OPENING_BALANCE) + interestPosted;
|
||||
validateNumberForEqualExcludePrecission(String.valueOf(balance), String.valueOf(summary.get("accountBalance")));
|
||||
}
|
||||
|
||||
private Integer createSavingsProduct(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String minOpenningBalance) {
|
||||
System.out.println("------------------------------CREATING NEW SAVINGS PRODUCT ---------------------------------------");
|
||||
SavingsProductHelper savingsProductHelper = new SavingsProductHelper();
|
||||
final String savingsProductJSON = savingsProductHelper //
|
||||
.withInterestCompoundingPeriodTypeAsDaily() //
|
||||
.withInterestPostingPeriodTypeAsMonthly() //
|
||||
.withInterestCalculationPeriodTypeAsDailyBalance() //
|
||||
.withMinimumOpenningBalance(minOpenningBalance).build();
|
||||
return SavingsProductHelper.createSavingsProduct(savingsProductJSON, requestSpec, responseSpec);
|
||||
}
|
||||
|
||||
private static Integer createSavingsProduct(final String minOpenningBalance, final Account... accounts) {
|
||||
System.out.println("------------------------------CREATING NEW SAVINGS PRODUCT ---------------------------------------");
|
||||
final String savingsProductJSON = new SavingsProductHelper().withInterestCompoundingPeriodTypeAsDaily() //
|
||||
.withInterestPostingPeriodTypeAsQuarterly() //
|
||||
.withInterestCalculationPeriodTypeAsDailyBalance() //
|
||||
.withMinimumOpenningBalance(minOpenningBalance).withAccountingRuleAsCashBased(accounts).build();
|
||||
return SavingsProductHelper.createSavingsProduct(savingsProductJSON, requestSpec, responseSpec);
|
||||
}
|
||||
|
||||
private Integer createLoanProduct(final String chargeId) {
|
||||
System.out.println("------------------------------CREATING NEW LOAN PRODUCT ---------------------------------------");
|
||||
final String loanProductJSON = new LoanProductTestBuilder() //
|
||||
.withPrincipal("15,000.00") //
|
||||
.withNumberOfRepayments("4") //
|
||||
.withRepaymentAfterEvery("1") //
|
||||
.withRepaymentTypeAsMonth() //
|
||||
.withinterestRatePerPeriod("1") //
|
||||
.withInterestRateFrequencyTypeAsMonths() //
|
||||
.withAmortizationTypeAsEqualInstallments() //
|
||||
.withInterestTypeAsDecliningBalance() //
|
||||
.build(chargeId);
|
||||
return this.loanTransactionHelper.getLoanProductId(loanProductJSON);
|
||||
}
|
||||
|
||||
private Integer applyForLoanApplication(final String clientID, final String loanProductID, final String savingsID) {
|
||||
System.out.println("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------");
|
||||
final String loanApplicationJSON = new LoanApplicationTestBuilder() //
|
||||
.withPrincipal("15,000.00") //
|
||||
.withLoanTermFrequency("4") //
|
||||
.withLoanTermFrequencyAsMonths() //
|
||||
.withNumberOfRepayments("4") //
|
||||
.withRepaymentEveryAfter("1") //
|
||||
.withRepaymentFrequencyTypeAsMonths() //
|
||||
.withInterestRatePerPeriod("2") //
|
||||
.withAmortizationTypeAsEqualInstallments() //
|
||||
.withInterestTypeAsDecliningBalance() //
|
||||
.withInterestCalculationPeriodTypeSameAsRepaymentPeriod() //
|
||||
.withExpectedDisbursementDate("10 January 2013") //
|
||||
.withSubmittedOnDate("10 January 2013") //
|
||||
.build(clientID, loanProductID, savingsID);
|
||||
return this.loanTransactionHelper.getLoanId(loanApplicationJSON);
|
||||
}
|
||||
|
||||
private Integer createFixedDepositProduct(final String validFrom, final String validTo, Account... accounts) {
|
||||
System.out.println("------------------------------CREATING NEW FIXED DEPOSIT PRODUCT ---------------------------------------");
|
||||
FixedDepositProductHelper fixedDepositProductHelper = new FixedDepositProductHelper(this.requestSpec, this.responseSpec);
|
||||
final String fixedDepositProductJSON = fixedDepositProductHelper //
|
||||
// .withAccountingRuleAsCashBased(accounts)
|
||||
.build(validFrom, validTo);
|
||||
return FixedDepositProductHelper.createFixedDepositProduct(fixedDepositProductJSON, requestSpec, responseSpec);
|
||||
}
|
||||
|
||||
private Integer applyForFixedDepositApplication(final String clientID, final String productID, final String validFrom,
|
||||
final String validTo, final String submittedOnDate, final String penalInterestType, String savingsId,
|
||||
final boolean transferInterest, final FixedDepositAccountHelper fixedDepositAccountHelper) {
|
||||
System.out.println("--------------------------------APPLYING FOR FIXED DEPOSIT ACCOUNT --------------------------------");
|
||||
final String fixedDepositApplicationJSON = new FixedDepositAccountHelper(this.requestSpec, this.responseSpec)
|
||||
//
|
||||
.withSubmittedOnDate(submittedOnDate).withSavings(savingsId).transferInterest(true)
|
||||
.withLockinPeriodFrequency("1", FixedDepositAccountHelper.DAYS)
|
||||
.build(clientID, productID, validFrom, validTo, penalInterestType);
|
||||
return fixedDepositAccountHelper.applyFixedDepositApplication(fixedDepositApplicationJSON, this.requestSpec, this.responseSpec);
|
||||
}
|
||||
|
||||
public void validateNumberForEqualExcludePrecission(String val, String val2) {
|
||||
DecimalFormat twoDForm = new DecimalFormat("#", new DecimalFormatSymbols(Locale.US));
|
||||
Assert.assertTrue(new Float(twoDForm.format(new Float(val))).compareTo(new Float(twoDForm.format(new Float(val2)))) == 0);
|
||||
}
|
||||
}
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import com.sun.jersey.core.util.Base64;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.ImageHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.accounting.AccountHelper;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
|
||||
import org.apache.fineract.integrationtests.common.organisation.StaffHelper;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
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.io.IOException;
|
||||
|
||||
public class StaffImageApiTest {
|
||||
|
||||
private RequestSpecification requestSpec;
|
||||
private ResponseSpecification responseSpec;
|
||||
private LoanTransactionHelper loanTransactionHelper;
|
||||
private AccountHelper accountHelper;
|
||||
|
||||
@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.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
|
||||
this.accountHelper = new AccountHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createStaffImage() {
|
||||
|
||||
Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
|
||||
Integer imageId = ImageHelper.createImageForStaff(this.requestSpec, this.responseSpec, staffId);
|
||||
Assert.assertNotNull("Image id should not be null", imageId);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getStaffImage(){
|
||||
Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
|
||||
Integer imageId = ImageHelper.createImageForStaff(this.requestSpec, this.responseSpec, staffId);
|
||||
Assert.assertNotNull("Image id should not be null", imageId);
|
||||
String imageAsText = ImageHelper.getStaffImageAsText(this.requestSpec, this.responseSpec, staffId);
|
||||
Assert.assertNotNull("Image id should not be null", imageAsText);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getStaffImageAsBinary(){
|
||||
Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
|
||||
Integer imageId = ImageHelper.createImageForStaff(this.requestSpec, this.responseSpec, staffId);
|
||||
Assert.assertNotNull("Image id should not be null", imageId);
|
||||
byte[] imageAsBytes = ImageHelper.getStaffImageAsBinary(this.requestSpec, this.responseSpec, staffId);
|
||||
Assert.assertNotNull("Image content should not be null", imageAsBytes);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateImage() {
|
||||
|
||||
Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
|
||||
Integer imageId = ImageHelper.createImageForStaff(this.requestSpec, this.responseSpec, staffId);
|
||||
Assert.assertNotNull("Image id should not be null", imageId);
|
||||
imageId = ImageHelper.updateImageForStaff(this.requestSpec, this.responseSpec, staffId);
|
||||
Assert.assertNotNull("Image id should not be null", imageId);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteStaffImage() {
|
||||
|
||||
Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
|
||||
Integer imageId = ImageHelper.createImageForStaff(this.requestSpec, this.responseSpec, staffId);
|
||||
Assert.assertNotNull("Image id should not be null", imageId);
|
||||
imageId = ImageHelper.deleteStaffImage(this.requestSpec, this.responseSpec, staffId);
|
||||
Assert.assertNotNull("Image id should not be null", imageId);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
+239
@@ -0,0 +1,239 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.organisation.StaffHelper;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.jayway.restassured.builder.RequestSpecBuilder;
|
||||
import com.jayway.restassured.builder.ResponseSpecBuilder;
|
||||
import com.jayway.restassured.http.ContentType;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
public class StaffTest {
|
||||
|
||||
private RequestSpecification requestSpec;
|
||||
private ResponseSpecification responseSpec;
|
||||
private ResponseSpecification responseSpecForValidationError;
|
||||
private ResponseSpecification responseSpecForNotFoundError;
|
||||
|
||||
@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.responseSpecForValidationError = new ResponseSpecBuilder().expectStatusCode(400).build();
|
||||
this.responseSpecForNotFoundError = new ResponseSpecBuilder().expectStatusCode(404).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaffCreate() {
|
||||
final HashMap response = StaffHelper.createStaffMap(requestSpec, responseSpec);
|
||||
|
||||
Assert.assertNotNull(response);
|
||||
Assert.assertEquals(response.get("officeId"), 1);
|
||||
Assert.assertNotNull(response.get("resourceId"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaffCreateValidationError() {
|
||||
|
||||
final String noOfficeJson = StaffHelper.createStaffWithJSONFields("firstname", "lastname");
|
||||
final String noFirstnameJson = StaffHelper.createStaffWithJSONFields("officeId", "lastname");
|
||||
final String noLastnameJson = StaffHelper.createStaffWithJSONFields("officeId", "firstname");
|
||||
|
||||
StaffHelper.createStaffWithJson(requestSpec, responseSpecForValidationError, noOfficeJson);
|
||||
StaffHelper.createStaffWithJson(requestSpec, responseSpecForValidationError, noFirstnameJson);
|
||||
StaffHelper.createStaffWithJson(requestSpec, responseSpecForValidationError, noLastnameJson);
|
||||
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
|
||||
map.put("officeId", 1);
|
||||
map.put("firstname", Utils.randomNameGenerator("michael_", 5));
|
||||
map.put("lastname", Utils.randomNameGenerator("Doe_", 4));
|
||||
|
||||
/** Long firstname test */
|
||||
map.put("firstname", Utils.randomNameGenerator("michael_", 43));
|
||||
StaffHelper.createStaffWithJson(requestSpec, responseSpecForValidationError, new Gson().toJson(map));
|
||||
map.put("firstname", Utils.randomNameGenerator("michael_", 5));
|
||||
|
||||
/** Long lastname test */
|
||||
map.put("lastname", Utils.randomNameGenerator("Doe_", 47));
|
||||
StaffHelper.createStaffWithJson(requestSpec, responseSpecForValidationError, new Gson().toJson(map));
|
||||
map.put("lastname", Utils.randomNameGenerator("Doe_",4));
|
||||
|
||||
/** Long mobileNo test */
|
||||
map.put("mobileNo", Utils.randomNameGenerator("num_", 47));
|
||||
StaffHelper.createStaffWithJson(requestSpec, responseSpecForValidationError, new Gson().toJson(map));
|
||||
}
|
||||
|
||||
public void testStaffCreateMaxNameLength() {
|
||||
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
|
||||
map.put("officeId", 1);
|
||||
map.put("firstname", Utils.randomNameGenerator("michael_", 42));
|
||||
map.put("lastname", Utils.randomNameGenerator("Doe_", 46));
|
||||
|
||||
StaffHelper.createStaffWithJson(requestSpec, responseSpec, new Gson().toJson(map));
|
||||
}
|
||||
|
||||
public void testStaffCreateExternalIdValidationError() {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
|
||||
map.put("officeId", 1);
|
||||
map.put("firstname", Utils.randomNameGenerator("michael_", 5));
|
||||
map.put("lastname", Utils.randomNameGenerator("Doe_", 4));
|
||||
|
||||
map.put("externalId", Utils.randomStringGenerator("EXT", 98));
|
||||
StaffHelper.createStaffWithJson(requestSpec, responseSpecForValidationError, new Gson().toJson(map));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaffFetch() {
|
||||
final HashMap response = StaffHelper.getStaff(requestSpec, responseSpec, 1);
|
||||
Assert.assertNotNull(response);
|
||||
Assert.assertNotNull(response.get("id"));
|
||||
Assert.assertEquals(response.get("id"), 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaffListFetch() {
|
||||
StaffHelper.getStaffList(requestSpec, responseSpec);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaffListStatusAll() {
|
||||
StaffHelper.getStaffListWithState(requestSpec, responseSpec, "all");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaffListStatusActive() {
|
||||
final List<HashMap> responseActive = (List<HashMap>) StaffHelper.getStaffListWithState(requestSpec, responseSpec, "active");
|
||||
for(final HashMap staff : responseActive) {
|
||||
Assert.assertNotNull(staff.get("id"));
|
||||
Assert.assertEquals(staff.get("isActive"), true);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaffListStatusInactive() {
|
||||
final List<HashMap> responseInactive = (List<HashMap>) StaffHelper.getStaffListWithState(requestSpec, responseSpec, "inactive");
|
||||
|
||||
for(final HashMap staff : responseInactive) {
|
||||
Assert.assertNotNull(staff.get("id"));
|
||||
Assert.assertEquals(staff.get("isActive"), false);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaffListFetchWrongState() {
|
||||
StaffHelper.getStaffListWithState(requestSpec, responseSpecForValidationError, "xyz");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaffFetchNotFound() {
|
||||
StaffHelper.getStaff(requestSpec, responseSpecForNotFoundError, Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaffUpdate() {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
final String firstname = Utils.randomNameGenerator("michael_", 10);
|
||||
final String lastname = Utils.randomNameGenerator("Doe_", 10);
|
||||
final String externalId = Utils.randomStringGenerator("EXT", 97);
|
||||
final String mobileNo = Utils.randomStringGenerator("num_", 10);
|
||||
|
||||
map.put("firstname", firstname);
|
||||
map.put("lastname", lastname);
|
||||
map.put("externalId", externalId);
|
||||
map.put("mobileNo", mobileNo);
|
||||
|
||||
final HashMap response = (HashMap) StaffHelper.updateStaff(requestSpec, responseSpec, 1, map);
|
||||
final HashMap changes = (HashMap) response.get("changes");
|
||||
|
||||
Assert.assertEquals(1, response.get("resourceId"));
|
||||
Assert.assertEquals(firstname, changes.get("firstname"));
|
||||
Assert.assertEquals(lastname, changes.get("lastname"));
|
||||
Assert.assertEquals(externalId, changes.get("externalId"));
|
||||
Assert.assertEquals(mobileNo, changes.get("mobileNo"));
|
||||
}
|
||||
|
||||
public void testStaffUpdateLongExternalIdError() {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("externalId", Utils.randomStringGenerator("EXT", 98));
|
||||
|
||||
StaffHelper.updateStaff(requestSpec, responseSpecForValidationError, 1, map);
|
||||
}
|
||||
|
||||
public void testStaffUpdateWrongActiveState() {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("isActive", "xyz");
|
||||
|
||||
StaffHelper.updateStaff(requestSpec, responseSpecForValidationError, 1, map);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaffUpdateNotFoundError() {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("firstname", Utils.randomNameGenerator("michael_", 5));
|
||||
|
||||
StaffHelper.updateStaff(requestSpec, responseSpecForNotFoundError, Integer.MAX_VALUE, map);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaffUpdateValidationError() {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
final String firstname = Utils.randomNameGenerator("michael_", 5);
|
||||
final String lastname = Utils.randomNameGenerator("Doe_", 4);
|
||||
final String firstnameLong = Utils.randomNameGenerator("michael_", 43);
|
||||
final String lastnameLong = Utils.randomNameGenerator("Doe_", 47);
|
||||
|
||||
map.put("firstname", firstname);
|
||||
map.put("lastname", lastname);
|
||||
|
||||
/** Test long firstname */
|
||||
map.put("firstname", firstnameLong);
|
||||
StaffHelper.updateStaff(requestSpec, responseSpecForValidationError, 1, map);
|
||||
map.put("firstname", firstname);
|
||||
|
||||
/** Test long lastname */
|
||||
map.put("lastname", lastnameLong);
|
||||
StaffHelper.updateStaff(requestSpec, responseSpecForValidationError, 1, map);
|
||||
map.put("lastname", lastname);
|
||||
|
||||
/** Long mobileNo test */
|
||||
map.put("mobileNo", Utils.randomNameGenerator("num_", 47));
|
||||
StaffHelper.updateStaff(requestSpec, responseSpecForValidationError, 1, map);
|
||||
map.remove("mobileNo");
|
||||
|
||||
/** Test unsupported parameter */
|
||||
map.put("xyz", "xyz");
|
||||
StaffHelper.updateStaff(requestSpec, responseSpecForValidationError, 1, map);
|
||||
}
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
|
||||
import org.junit.Before;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Client Loan Integration Test for checking Loan Application Repayment
|
||||
* Schedule.
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public class SurveyIntegrationTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private LoanTransactionHelper loanTransactionHelper;
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
}
|
||||
+283
@@ -0,0 +1,283 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.CommonConstants;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.system.CodeHelper;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Test for creating, updating, deleting codes and code values
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public class SystemCodeTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private ResponseSpecification generalResponseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
|
||||
@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.generalResponseSpec = new ResponseSpecBuilder().build();
|
||||
|
||||
}
|
||||
|
||||
// @Ignore()
|
||||
@Test
|
||||
// scenario 57, 58, 59, 60
|
||||
public void testCreateCode() {
|
||||
final String codeName = "Client Marital Status";
|
||||
|
||||
final Integer createResponseId = (Integer) CodeHelper.createCode(this.requestSpec, this.responseSpec, codeName,
|
||||
CodeHelper.RESPONSE_ID_ATTRIBUTE_NAME);
|
||||
|
||||
// verify code created
|
||||
|
||||
final HashMap newCodeAttributes = (HashMap) CodeHelper.getCodeById(this.requestSpec, this.responseSpec, createResponseId, "");
|
||||
|
||||
Assert.assertNotNull(newCodeAttributes);
|
||||
assertEquals("Verify value of codeId", createResponseId, newCodeAttributes.get(CodeHelper.CODE_ID_ATTRIBUTE_NAME));
|
||||
|
||||
assertEquals("Verify code name", codeName, newCodeAttributes.get(CodeHelper.CODE_NAME_ATTRIBUTE_NAME));
|
||||
assertEquals("Verify system defined is false", false, newCodeAttributes.get(CodeHelper.CODE_SYSTEM_DEFINED_ATTRIBUTE_NAME));
|
||||
|
||||
// update code
|
||||
final HashMap updateChangeResponse = (HashMap) CodeHelper.updateCode(this.requestSpec, this.responseSpec, createResponseId,
|
||||
codeName + "(CHANGE)", "changes");
|
||||
|
||||
assertEquals("Verify code name updated", codeName + "(CHANGE)", updateChangeResponse.get(CodeHelper.CODE_NAME_ATTRIBUTE_NAME));
|
||||
|
||||
// delete code
|
||||
final Integer deleteResponseId = (Integer) CodeHelper.deleteCodeById(this.requestSpec, this.responseSpec, createResponseId,
|
||||
CodeHelper.RESPONSE_ID_ATTRIBUTE_NAME);
|
||||
assertEquals("Verify code deleted", createResponseId, deleteResponseId);
|
||||
|
||||
// verify code deleted
|
||||
final HashMap deletedCodeValues = (HashMap) CodeHelper
|
||||
.getCodeById(this.requestSpec, this.generalResponseSpec, deleteResponseId, "");
|
||||
|
||||
Assert.assertNotNull(deletedCodeValues);
|
||||
assertNull("Verify value of codeId", deletedCodeValues.get(CodeHelper.CODE_ID_ATTRIBUTE_NAME));
|
||||
|
||||
assertNull("Verify code name", deletedCodeValues.get(CodeHelper.CODE_NAME_ATTRIBUTE_NAME));
|
||||
assertNull("Verify system defined is false", deletedCodeValues.get(CodeHelper.CODE_SYSTEM_DEFINED_ATTRIBUTE_NAME));
|
||||
}
|
||||
|
||||
// @Ignore()
|
||||
@Test
|
||||
// scenario 57, 60
|
||||
public void testPreventCreateDuplicateCode() {
|
||||
final String codeName = "Client Marital Status";
|
||||
|
||||
// create code
|
||||
final Integer createResponseId = (Integer) CodeHelper.createCode(this.requestSpec, this.responseSpec, codeName,
|
||||
CodeHelper.RESPONSE_ID_ATTRIBUTE_NAME);
|
||||
|
||||
// verify code created
|
||||
final HashMap newCodeAttributes = (HashMap) CodeHelper.getCodeById(this.requestSpec, this.responseSpec, createResponseId, "");
|
||||
|
||||
Assert.assertNotNull(newCodeAttributes);
|
||||
assertEquals("Verify value of codeId", createResponseId, newCodeAttributes.get(CodeHelper.CODE_ID_ATTRIBUTE_NAME));
|
||||
|
||||
assertEquals("Verify code name", codeName, newCodeAttributes.get(CodeHelper.CODE_NAME_ATTRIBUTE_NAME));
|
||||
assertEquals("Verify system defined is false", false, newCodeAttributes.get(CodeHelper.CODE_SYSTEM_DEFINED_ATTRIBUTE_NAME));
|
||||
|
||||
// try to create duplicate-- should fail
|
||||
final List<HashMap> error = (List) CodeHelper.createCode(this.requestSpec, this.generalResponseSpec, codeName,
|
||||
CommonConstants.RESPONSE_ERROR);
|
||||
|
||||
assertEquals("Verify duplication error", "error.msg.code.duplicate.name", error.get(0).get("userMessageGlobalisationCode"));
|
||||
|
||||
// delete code that was just created
|
||||
|
||||
final Integer deleteResponseId = (Integer) CodeHelper.deleteCodeById(this.requestSpec, this.responseSpec, createResponseId,
|
||||
CodeHelper.RESPONSE_ID_ATTRIBUTE_NAME);
|
||||
assertEquals("Verify code deleted", createResponseId, deleteResponseId);
|
||||
|
||||
// verify code deleted
|
||||
final HashMap deletedCodeAttributes = (HashMap) CodeHelper.getCodeById(this.requestSpec, this.generalResponseSpec,
|
||||
deleteResponseId, "");
|
||||
|
||||
Assert.assertNotNull(deletedCodeAttributes);
|
||||
assertNull("Verify value of codeId", deletedCodeAttributes.get(CodeHelper.CODE_ID_ATTRIBUTE_NAME));
|
||||
|
||||
assertNull("Verify code name", deletedCodeAttributes.get(CodeHelper.CODE_NAME_ATTRIBUTE_NAME));
|
||||
assertNull("Verify system defined is false", deletedCodeAttributes.get(CodeHelper.CODE_SYSTEM_DEFINED_ATTRIBUTE_NAME));
|
||||
|
||||
}
|
||||
|
||||
// @Ignore
|
||||
@Test
|
||||
public void testUpdateDeleteSystemDefinedCode() {
|
||||
|
||||
// get any systemDefined code
|
||||
final HashMap systemDefinedCode = (HashMap) CodeHelper.getSystemDefinedCodes(this.requestSpec, this.responseSpec);
|
||||
|
||||
// delete system-defined code should fail
|
||||
final List<HashMap> error = (List) CodeHelper.deleteCodeById(this.requestSpec, this.generalResponseSpec,
|
||||
(Integer) systemDefinedCode.get(CodeHelper.CODE_ID_ATTRIBUTE_NAME), CommonConstants.RESPONSE_ERROR);
|
||||
|
||||
assertEquals("Cannot delete system-defined code", "error.msg.code.systemdefined", error.get(0).get("userMessageGlobalisationCode"));
|
||||
|
||||
// update system-defined code should fail
|
||||
|
||||
final List<HashMap> updateError = (List) CodeHelper.updateCode(this.requestSpec, this.generalResponseSpec,
|
||||
(Integer) systemDefinedCode.get(CodeHelper.CODE_ID_ATTRIBUTE_NAME),
|
||||
systemDefinedCode.get(CodeHelper.CODE_NAME_ATTRIBUTE_NAME) + "CHANGE", CommonConstants.RESPONSE_ERROR);
|
||||
|
||||
assertEquals("Cannot update system-defined code", "error.msg.code.systemdefined",
|
||||
updateError.get(0).get("userMessageGlobalisationCode"));
|
||||
|
||||
}
|
||||
|
||||
// @Ignore
|
||||
@Test
|
||||
public void testCodeValuesNotAssignedToTable() {
|
||||
|
||||
final String codeName = Utils.randomNameGenerator("Marital Status1", 10);
|
||||
|
||||
final String codeValue1 = "Married1";
|
||||
final String codeValue2 = "Unmarried1";
|
||||
|
||||
final int codeValue1Position = 1;
|
||||
final int codeValue2Position = 1;
|
||||
|
||||
final String codeDescription1 = "Description11";
|
||||
final String codeDescription2 = "Description22";
|
||||
|
||||
// create code
|
||||
final Integer createCodeResponseId = (Integer) CodeHelper.createCode(this.requestSpec, this.responseSpec, codeName,
|
||||
CodeHelper.RESPONSE_ID_ATTRIBUTE_NAME);
|
||||
|
||||
// create first code value
|
||||
final Integer createCodeValueResponseId1 = (Integer) CodeHelper.createCodeValue(this.requestSpec, this.responseSpec,
|
||||
createCodeResponseId, codeValue1, codeDescription1, codeValue1Position, CodeHelper.SUBRESPONSE_ID_ATTRIBUTE_NAME);
|
||||
|
||||
// create second code value
|
||||
final Integer createCodeValueResponseId2 = (Integer) CodeHelper.createCodeValue(this.requestSpec, this.responseSpec,
|
||||
createCodeResponseId, codeValue2, codeDescription2, codeValue1Position, CodeHelper.SUBRESPONSE_ID_ATTRIBUTE_NAME);
|
||||
|
||||
// verify two code values created
|
||||
|
||||
final List<HashMap> codeValuesList = (List) CodeHelper.getCodeValuesForCode(this.requestSpec, this.responseSpec,
|
||||
createCodeResponseId, "");
|
||||
|
||||
assertEquals("Number of code values returned matches number created", 2, codeValuesList.size());
|
||||
|
||||
// verify values of first code value
|
||||
final HashMap codeValuesAttributes1 = (HashMap) CodeHelper.getCodeValueById(this.requestSpec, this.responseSpec,
|
||||
createCodeResponseId, createCodeValueResponseId1, "");
|
||||
|
||||
Assert.assertNotNull(codeValuesAttributes1);
|
||||
assertEquals("Verify value of codeValueId", createCodeValueResponseId1,
|
||||
codeValuesAttributes1.get(CodeHelper.CODE_VALUE_ID_ATTRIBUTE_NAME));
|
||||
|
||||
assertEquals("Verify value of code name", codeValue1, codeValuesAttributes1.get(CodeHelper.CODE_VALUE_NAME_ATTRIBUTE_NAME));
|
||||
|
||||
assertEquals("Verify value of code description", codeDescription1,
|
||||
codeValuesAttributes1.get(CodeHelper.CODE_VALUE_DESCRIPTION_ATTRIBUTE_NAME));
|
||||
|
||||
assertEquals("Verify position of code value", codeValue1Position,
|
||||
codeValuesAttributes1.get(CodeHelper.CODE_VALUE_POSITION_ATTRIBUTE_NAME));
|
||||
|
||||
// verify values of second code value
|
||||
final HashMap codeValuesAttributes2 = (HashMap) CodeHelper.getCodeValueById(this.requestSpec, this.responseSpec,
|
||||
createCodeResponseId, createCodeValueResponseId2, "");
|
||||
|
||||
Assert.assertNotNull(codeValuesAttributes2);
|
||||
assertEquals("Verify value of codeValueId", createCodeValueResponseId2,
|
||||
codeValuesAttributes2.get(CodeHelper.CODE_VALUE_ID_ATTRIBUTE_NAME));
|
||||
|
||||
assertEquals("Verify value of code name", codeValue2, codeValuesAttributes2.get(CodeHelper.CODE_VALUE_NAME_ATTRIBUTE_NAME));
|
||||
|
||||
assertEquals("Verify value of code description", codeDescription2,
|
||||
codeValuesAttributes2.get(CodeHelper.CODE_VALUE_DESCRIPTION_ATTRIBUTE_NAME));
|
||||
|
||||
assertEquals("Verify position of code value", codeValue2Position,
|
||||
codeValuesAttributes2.get(CodeHelper.CODE_VALUE_POSITION_ATTRIBUTE_NAME));
|
||||
|
||||
// update code value 1
|
||||
final HashMap codeValueChanges = (HashMap) CodeHelper.updateCodeValue(this.requestSpec, this.responseSpec, createCodeResponseId,
|
||||
createCodeValueResponseId1, codeValue1 + "CHANGE", codeDescription1 + "CHANGE", 4, "changes");
|
||||
|
||||
assertEquals("Verify changed code value name", codeValueChanges.get("name"), codeValue1 + "CHANGE");
|
||||
|
||||
assertEquals("Verify changed code value description", codeValueChanges.get("description"), codeDescription1 + "CHANGE");
|
||||
|
||||
// delete code value
|
||||
Integer deletedCodeValueResponseId1 = (Integer) CodeHelper.deleteCodeValueById(this.requestSpec, this.generalResponseSpec,
|
||||
createCodeResponseId, createCodeValueResponseId1, CodeHelper.SUBRESPONSE_ID_ATTRIBUTE_NAME);
|
||||
|
||||
// Verify code value deleted
|
||||
|
||||
final ArrayList<HashMap> deletedCodeValueAttributes1 = (ArrayList<HashMap>) CodeHelper.getCodeValueById(this.requestSpec,
|
||||
this.generalResponseSpec, createCodeResponseId, deletedCodeValueResponseId1, CommonConstants.RESPONSE_ERROR);
|
||||
|
||||
assertEquals("error.msg.codevalue.id.invalid", deletedCodeValueAttributes1.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
final List<HashMap> deletedCodeValuesList = (List) CodeHelper.getCodeValuesForCode(this.requestSpec, this.responseSpec,
|
||||
createCodeResponseId, "");
|
||||
|
||||
assertEquals("Number of code values is 1", 1, deletedCodeValuesList.size());
|
||||
|
||||
final Integer deletedCodeValueResponseId2 = (Integer) CodeHelper.deleteCodeValueById(this.requestSpec, this.generalResponseSpec,
|
||||
createCodeResponseId, createCodeValueResponseId2, CodeHelper.SUBRESPONSE_ID_ATTRIBUTE_NAME);
|
||||
|
||||
final ArrayList<HashMap> deletedCodeValueAttributes2 = (ArrayList<HashMap>) CodeHelper.getCodeValueById(this.requestSpec,
|
||||
this.generalResponseSpec, createCodeResponseId, deletedCodeValueResponseId2, CommonConstants.RESPONSE_ERROR);
|
||||
|
||||
assertEquals("error.msg.codevalue.id.invalid", deletedCodeValueAttributes2.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
final List<HashMap> deletedCodeValuesList1 = (List) CodeHelper.getCodeValuesForCode(this.requestSpec, this.responseSpec,
|
||||
createCodeResponseId, "");
|
||||
|
||||
assertEquals("Number of code values is 0", 0, deletedCodeValuesList1.size());
|
||||
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testCodeValuesAssignedToTable() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.jayway.restassured.builder.RequestSpecBuilder;
|
||||
import com.jayway.restassured.builder.ResponseSpecBuilder;
|
||||
import com.jayway.restassured.http.ContentType;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
public class TemplateIntegrationTest {
|
||||
|
||||
private final String GET_TEMPLATES_URL = "/fineract-provider/api/v1/templates?tenantIdentifier=default";
|
||||
private final String GET_TEMPLATE_ID_URL = "/fineract-provider/api/v1/templates/%s?tenantIdentifier=default";
|
||||
private final String RESPONSE_ATTRIBUTE_NAME = "name";
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
final HashMap<String, String> metadata = new HashMap<>();
|
||||
metadata.put("user", "resource_url");
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("name", "foo");
|
||||
map.put("text", "Hello {{template}}");
|
||||
map.put("mappers", metadata);
|
||||
|
||||
ArrayList<?> get = Utils.performServerGet(this.requestSpec, this.responseSpec, this.GET_TEMPLATES_URL, "");
|
||||
final int entriesBeforeTest = get.size();
|
||||
|
||||
final Integer id = Utils.performServerPost(this.requestSpec, this.responseSpec, this.GET_TEMPLATES_URL, new Gson().toJson(map), "resourceId");
|
||||
|
||||
final String templateUrlForId = String.format(this.GET_TEMPLATE_ID_URL, id);
|
||||
|
||||
final String getrequest2 = Utils.performServerGet(this.requestSpec, this.responseSpec, templateUrlForId, this.RESPONSE_ATTRIBUTE_NAME);
|
||||
|
||||
Assert.assertTrue(getrequest2.equals("foo"));
|
||||
|
||||
Utils.performServerDelete(this.requestSpec, this.responseSpec, templateUrlForId, "");
|
||||
|
||||
get = Utils.performServerGet(this.requestSpec, this.responseSpec, this.GET_TEMPLATES_URL, "");
|
||||
final int entriesAfterTest = get.size();
|
||||
|
||||
Assert.assertEquals(entriesBeforeTest, entriesAfterTest);
|
||||
}
|
||||
}
|
||||
fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/WorkingDaysTest.java
Executable
+70
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.CommonConstants;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.WorkingDaysHelper;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
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;
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public class WorkingDaysTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private ResponseSpecification generalResponseSpec;
|
||||
|
||||
@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.generalResponseSpec = new ResponseSpecBuilder().build();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateWorkingDays() {
|
||||
HashMap response = (HashMap) WorkingDaysHelper.updateWorkingDays(requestSpec, responseSpec);
|
||||
Assert.assertNotNull(response.get("resourceId"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateWorkingDaysWithWrongRecurrencePattern() {
|
||||
final List<HashMap> error = (List) WorkingDaysHelper.updateWorkingDaysWithWrongRecurrence(requestSpec, generalResponseSpec,
|
||||
CommonConstants.RESPONSE_ERROR);
|
||||
assertEquals("Verify wrong recurrence pattern error", "error.msg.recurring.rule.parsing.error",
|
||||
error.get(0).get("userMessageGlobalisationCode"));
|
||||
}
|
||||
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.xbrl.XBRLIntegrationTestHelper;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
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;
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public class XBRLIntegrationTest {
|
||||
|
||||
private RequestSpecification requestSpec;
|
||||
private ResponseSpecification responseSpec;
|
||||
|
||||
private XBRLIntegrationTestHelper xbrlHelper;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
Utils.initializeRESTAssured();
|
||||
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
|
||||
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
|
||||
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRetrieveTaxonomyList() {
|
||||
this.xbrlHelper = new XBRLIntegrationTestHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
final ArrayList<HashMap> taxonomyList = this.xbrlHelper.getTaxonomyList();
|
||||
verifyTaxonomyList(taxonomyList);
|
||||
}
|
||||
|
||||
private void verifyTaxonomyList(final ArrayList<HashMap> taxonomyList) {
|
||||
System.out.println("--------------------VERIFYING TAXONOMY LIST--------------------------");
|
||||
assertEquals("Checking for the 1st taxonomy", "AdministrativeExpense", taxonomyList.get(0).get("name"));
|
||||
}
|
||||
|
||||
}
|
||||
+366
@@ -0,0 +1,366 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.fineract.batch.domain.BatchRequest;
|
||||
import org.apache.fineract.batch.domain.BatchResponse;
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
/**
|
||||
* Helper class for {@link org.apache.fineract.integrationtests.BatchApiTest}. It
|
||||
* takes care of creation of {@code BatchRequest} list and posting this list to
|
||||
* the server.
|
||||
*
|
||||
* @author Rishabh Shukla
|
||||
*
|
||||
* @see org.apache.fineract.integrationtests.BatchApiTest
|
||||
*/
|
||||
public class BatchHelper {
|
||||
|
||||
private static final String BATCH_API_URL = "/fineract-provider/api/v1/batches?" + Utils.TENANT_IDENTIFIER;
|
||||
private static final String BATCH_API_URL_EXT = BATCH_API_URL + "&enclosingTransaction=true";
|
||||
|
||||
private BatchHelper() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a JSON String for a list of {@code BatchRequest}s
|
||||
*
|
||||
* @param batchRequests
|
||||
* @return JSON String of BatchRequest
|
||||
*/
|
||||
public static String toJsonString(final List<BatchRequest> batchRequests) {
|
||||
return new Gson().toJson(batchRequests);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the converted string response into JSON.
|
||||
*
|
||||
* @param json
|
||||
* @return List<BatchResponse>
|
||||
*/
|
||||
private static List<BatchResponse> fromJsonString(final String json) {
|
||||
return new Gson().fromJson(json, new TypeToken<List<BatchResponse>>() {}.getType());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of BatchResponse with query parameter enclosing
|
||||
* transaction set to false by posting the jsonified BatchRequest to the
|
||||
* server.
|
||||
*
|
||||
* @param requestSpec
|
||||
* @param responseSpec
|
||||
* @param jsonifiedBatchRequests
|
||||
* @return a list of BatchResponse
|
||||
*/
|
||||
public static List<BatchResponse> postBatchRequestsWithoutEnclosingTransaction(final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec, final String jsonifiedBatchRequests) {
|
||||
final String response = Utils.performServerPost(requestSpec, responseSpec, BATCH_API_URL, jsonifiedBatchRequests, null);
|
||||
return BatchHelper.fromJsonString(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of BatchResponse with query parameter enclosing
|
||||
* transaction set to true by posting the jsonified BatchRequest to the
|
||||
* server.
|
||||
*
|
||||
* @param requestSpec
|
||||
* @param responseSpec
|
||||
* @param jsonifiedBatchRequests
|
||||
* @return a list of BatchResponse
|
||||
*/
|
||||
public static List<BatchResponse> postBatchRequestsWithEnclosingTransaction(final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec, final String jsonifiedBatchRequests) {
|
||||
final String response = Utils.performServerPost(requestSpec, responseSpec, BATCH_API_URL_EXT, jsonifiedBatchRequests, null);
|
||||
return BatchHelper.fromJsonString(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a BatchResponse based on the given BatchRequest, by posting the
|
||||
* request to the server.
|
||||
*
|
||||
* @param BatchRequest
|
||||
* @return List<BatchResponse>
|
||||
*/
|
||||
public static List<BatchResponse> postWithSingleRequest(final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec, final BatchRequest br) {
|
||||
|
||||
final List<BatchRequest> batchRequests = new ArrayList<>();
|
||||
batchRequests.add(br);
|
||||
|
||||
final String jsonifiedRequest = BatchHelper.toJsonString(batchRequests);
|
||||
final List<BatchResponse> response = BatchHelper.postBatchRequestsWithoutEnclosingTransaction(requestSpec, responseSpec,
|
||||
jsonifiedRequest);
|
||||
|
||||
// Verifies that the response result is there
|
||||
Assert.assertNotNull(response);
|
||||
Assert.assertTrue(response.size() > 0);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a
|
||||
* {@link org.apache.fineract.batch.command.internal.CreateClientCommandStrategy}
|
||||
* Request as one of the request in Batch.
|
||||
*
|
||||
* @param reqId
|
||||
* @param externalId
|
||||
* @return BatchRequest
|
||||
*/
|
||||
public static BatchRequest createClientRequest(final Long requestId, final String externalId) {
|
||||
|
||||
final BatchRequest br = new BatchRequest();
|
||||
br.setRequestId(requestId);
|
||||
br.setRelativeUrl("clients");
|
||||
br.setMethod("POST");
|
||||
|
||||
final String extId;
|
||||
if (externalId.equals("")) {
|
||||
extId = "ext" + String.valueOf((10000 * Math.random())) + String.valueOf((10000 * Math.random()));
|
||||
} else {
|
||||
extId = externalId;
|
||||
}
|
||||
|
||||
final String body = "{ \"officeId\": 1, \"firstname\": \"Petra\", \"lastname\": \"Yton\"," + "\"externalId\": " + extId
|
||||
+ ", \"dateFormat\": \"dd MMMM yyyy\", \"locale\": \"en\"," + "\"active\": false, \"submittedOnDate\": \"04 March 2009\"}";
|
||||
|
||||
br.setBody(body);
|
||||
|
||||
return br;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a
|
||||
* {@link org.apache.fineract.batch.command.internal.UpdateClientCommandStrategy}
|
||||
* Request with given requestId and reference.
|
||||
*
|
||||
* @param reqId
|
||||
* @param clientId
|
||||
* @return BatchRequest
|
||||
*/
|
||||
public static BatchRequest updateClientRequest(final Long requestId, final Long reference) {
|
||||
|
||||
final BatchRequest br = new BatchRequest();
|
||||
|
||||
br.setRequestId(requestId);
|
||||
br.setRelativeUrl("clients/$.clientId");
|
||||
br.setMethod("PUT");
|
||||
br.setReference(reference);
|
||||
br.setBody("{\"firstname\": \"TestFirstName\", \"lastname\": \"TestLastName\"}");
|
||||
|
||||
return br;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a
|
||||
* {@link org.apache.fineract.batch.command.internal.ApplyLoanCommandStrategy}
|
||||
* Request with given requestId and reference.
|
||||
*
|
||||
* @param requestId
|
||||
* @param reference
|
||||
* @param productId
|
||||
* @return BatchRequest
|
||||
*/
|
||||
public static BatchRequest applyLoanRequest(final Long requestId, final Long reference, final Integer productId) {
|
||||
|
||||
final BatchRequest br = new BatchRequest();
|
||||
|
||||
br.setRequestId(requestId);
|
||||
br.setRelativeUrl("loans");
|
||||
br.setMethod("POST");
|
||||
br.setReference(reference);
|
||||
|
||||
final String body = "{\"dateFormat\": \"dd MMMM yyyy\", \"locale\": \"en_GB\", \"clientId\": \"$.clientId\"," + "\"productId\": "
|
||||
+ productId + ", \"principal\": \"10,000.00\", \"loanTermFrequency\": 12,"
|
||||
+ "\"loanTermFrequencyType\": 2, \"loanType\": \"individual\", \"numberOfRepayments\": 10,"
|
||||
+ "\"repaymentEvery\": 1, \"repaymentFrequencyType\": 2, \"interestRatePerPeriod\": 10,"
|
||||
+ "\"amortizationType\": 1, \"interestType\": 0, \"interestCalculationPeriodType\": 1,"
|
||||
+ "\"transactionProcessingStrategyId\": 1, \"expectedDisbursementDate\": \"10 Jun 2013\","
|
||||
+ "\"submittedOnDate\": \"10 Jun 2013\"}";
|
||||
br.setBody(body);
|
||||
|
||||
return br;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a
|
||||
* {@link org.apache.fineract.batch.command.internal.ApplySavingsCommandStrategy}
|
||||
* Request with given requestId and reference.
|
||||
*
|
||||
* @param requestId
|
||||
* @param reference
|
||||
* @param productId
|
||||
* @return BatchRequest
|
||||
*/
|
||||
public static BatchRequest applySavingsRequest(final Long requestId, final Long reference, final Integer productId) {
|
||||
|
||||
final BatchRequest br = new BatchRequest();
|
||||
|
||||
br.setRequestId(requestId);
|
||||
br.setRelativeUrl("savingsaccounts");
|
||||
br.setMethod("POST");
|
||||
br.setReference(reference);
|
||||
|
||||
final String body = "{\"clientId\": \"$.clientId\", \"productId\": " + productId + ","
|
||||
+ "\"locale\": \"en\", \"dateFormat\": \"dd MMMM yyyy\", \"submittedOnDate\": \"01 March 2011\"}";
|
||||
br.setBody(body);
|
||||
|
||||
return br;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a
|
||||
* {@link org.apache.fineract.batch.command.internal.CreateChargeCommandStrategy}
|
||||
* Request with given requestId and reference
|
||||
*
|
||||
* @param requestId
|
||||
* @param reference
|
||||
* @return BatchRequest
|
||||
*/
|
||||
public static BatchRequest createChargeRequest(final Long requestId, final Long reference) {
|
||||
|
||||
final BatchRequest br = new BatchRequest();
|
||||
br.setRequestId(requestId);
|
||||
br.setRelativeUrl("loans/$.loanId/charges");
|
||||
br.setMethod("POST");
|
||||
br.setReference(reference);
|
||||
|
||||
final String body = "{\"chargeId\": \"2\", \"locale\": \"en\", \"amount\": \"100\", "
|
||||
+ "\"dateFormat\": \"dd MMMM yyyy\", \"dueDate\": \"29 April 2013\"}";
|
||||
br.setBody(body);
|
||||
|
||||
return br;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a
|
||||
* {@link org.apache.fineract.batch.command.internal.CollectChargesCommandStrategy}
|
||||
* Request with given requestId and reference.
|
||||
*
|
||||
* @param requestId
|
||||
* @param reference
|
||||
* @return BatchRequest
|
||||
*/
|
||||
public static BatchRequest collectChargesRequest(final Long requestId, final Long reference) {
|
||||
|
||||
final BatchRequest br = new BatchRequest();
|
||||
|
||||
br.setRequestId(requestId);
|
||||
br.setRelativeUrl("loans/$.loanId/charges");
|
||||
br.setReference(reference);
|
||||
br.setMethod("GET");
|
||||
br.setBody("{ }");
|
||||
|
||||
return br;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a
|
||||
* {@link org.apache.fineract.batch.command.internal.ActivateClientCommandStrategy}
|
||||
* Request with given requestId and reference.
|
||||
*
|
||||
*
|
||||
* @param requestId
|
||||
* @param reference
|
||||
* @return BatchRequest
|
||||
*/
|
||||
public static BatchRequest activateClientRequest(final Long requestId, final Long reference) {
|
||||
|
||||
final BatchRequest br = new BatchRequest();
|
||||
|
||||
br.setRequestId(requestId);
|
||||
br.setRelativeUrl("clients/$.clientId?command=activate");
|
||||
br.setReference(reference);
|
||||
br.setMethod("POST");
|
||||
br.setBody("{\"locale\": \"en\", \"dateFormat\": \"dd MMMM yyyy\", \"activationDate\": \"01 March 2011\"}");
|
||||
|
||||
return br;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a
|
||||
* {@link org.apache.fineract.batch.command.internal.ApproveLoanCommandStrategy}
|
||||
* Request with given requestId and reference.
|
||||
*
|
||||
*
|
||||
* @param requestId
|
||||
* @param reference
|
||||
* @return BatchRequest
|
||||
*/
|
||||
public static BatchRequest approveLoanRequest(final Long requestId, final Long reference) {
|
||||
final BatchRequest br = new BatchRequest();
|
||||
|
||||
br.setRequestId(requestId);
|
||||
br.setRelativeUrl("loans/$.loanId?command=approve");
|
||||
br.setReference(reference);
|
||||
br.setMethod("POST");
|
||||
br.setBody("{\"locale\": \"en\", \"dateFormat\": \"dd MMMM yyyy\", \"approvedOnDate\": \"12 September 2013\","
|
||||
+ "\"note\": \"Loan approval note\"}");
|
||||
|
||||
return br;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a
|
||||
* {@link org.apache.fineract.batch.command.internal.DisburseLoanCommandStrategy}
|
||||
* Request with given requestId and reference.
|
||||
*
|
||||
*
|
||||
* @param requestId
|
||||
* @param reference
|
||||
* @return BatchRequest
|
||||
*/
|
||||
public static BatchRequest disburseLoanRequest(final Long requestId, final Long reference) {
|
||||
final BatchRequest br = new BatchRequest();
|
||||
|
||||
br.setRequestId(requestId);
|
||||
br.setRelativeUrl("loans/$.loanId?command=disburse");
|
||||
br.setReference(reference);
|
||||
br.setMethod("POST");
|
||||
br.setBody("{\"locale\": \"en\", \"dateFormat\": \"dd MMMM yyyy\", \"actualDisbursementDate\": \"15 September 2013\"}");
|
||||
|
||||
return br;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that the client with given externalId is not created on the
|
||||
* server.
|
||||
*
|
||||
* @param requestSpec
|
||||
* @param responseSpec
|
||||
* @param externalId
|
||||
*/
|
||||
public static void verifyClientCreatedOnServer(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String externalId) {
|
||||
System.out.println("------------------------------CHECK CLIENT DETAILS------------------------------------\n");
|
||||
final String CLIENT_URL = "/fineract-provider/api/v1/clients?externalId=" + externalId + "&" + Utils.TENANT_IDENTIFIER;
|
||||
final Integer responseRecords = Utils.performServerGet(requestSpec, responseSpec, CLIENT_URL, "totalFilteredRecords");
|
||||
Assert.assertEquals("No records found with given externalId", (long) responseRecords, (long) 0);
|
||||
}
|
||||
}
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common;
|
||||
|
||||
import static com.jayway.restassured.path.json.JsonPath.from;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
public class CalendarHelper {
|
||||
|
||||
private static final String BASE_URL = "/fineract-provider/api/v1/";
|
||||
private static final String PARENT_ENTITY_NAME = "groups/";
|
||||
private static final String ENITY_NAME = "/calendars";
|
||||
|
||||
public static Integer createMeetingCalendarForGroup(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer groupId, final String startDate, final String frequency, final String interval, final String repeatsOnDay) {
|
||||
|
||||
System.out.println("---------------------------------CREATING A MEETING CALENDAR FOR THE GROUP------------------------------");
|
||||
|
||||
final String CALENDAR_RESOURCE_URL = BASE_URL + PARENT_ENTITY_NAME + groupId + ENITY_NAME + "?" + Utils.TENANT_IDENTIFIER;
|
||||
|
||||
System.out.println(CALENDAR_RESOURCE_URL);
|
||||
|
||||
return Utils.performServerPost(requestSpec, responseSpec, CALENDAR_RESOURCE_URL,
|
||||
getTestCalendarAsJSON(frequency, interval, repeatsOnDay, startDate), "resourceId");
|
||||
}
|
||||
|
||||
public static Integer updateMeetingCalendarForGroup(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer groupId, String calendarID, final String startDate, final String frequency, final String interval,
|
||||
final String repeatsOnDay) {
|
||||
|
||||
System.out.println("---------------------------------UPDATING A MEETING CALENDAR FOR THE GROUP------------------------------");
|
||||
|
||||
final String CALENDAR_RESOURCE_URL = BASE_URL + PARENT_ENTITY_NAME + groupId + ENITY_NAME + "/" + calendarID;
|
||||
|
||||
System.out.println(CALENDAR_RESOURCE_URL);
|
||||
// TODO: check that resource id indeed exists in calendar update put.
|
||||
return Utils.performServerPut(requestSpec, responseSpec, CALENDAR_RESOURCE_URL,
|
||||
getTestCalendarAsJSON(frequency, interval, repeatsOnDay, startDate), "resourceId");
|
||||
}
|
||||
|
||||
public static String getTestCalendarAsJSON(final String frequency, final String interval, final String repeatsOnDay,
|
||||
final String startDate) {
|
||||
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("locale", "en");
|
||||
map.put("frequency", frequency);
|
||||
map.put("interval", interval);
|
||||
map.put("repeating", "true");
|
||||
map.put("repeatsOnDay", repeatsOnDay);
|
||||
map.put("title", Utils.randomNameGenerator("groups_CollectionMeeting", 4));
|
||||
map.put("typeId", "1");
|
||||
map.put("startDate", startDate);
|
||||
System.out.println("map : " + map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static void verifyCalendarCreatedOnServer(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer generatedGroupId, final Integer generatedCalendarId) {
|
||||
System.out.println("------------------------------CHECK CALENDAR DETAILS------------------------------------\n");
|
||||
final String CLIENT_URL = "/fineract-provider/api/v1/groups/" + generatedGroupId + "?associations=all&" + Utils.TENANT_IDENTIFIER;
|
||||
final String responseCalendarDetailsinJSON = Utils.performServerGet(requestSpec, responseSpec, CLIENT_URL,
|
||||
"collectionMeetingCalendar");
|
||||
final Integer responseCalendarId = from(responseCalendarDetailsinJSON).get("id");
|
||||
assertEquals("ERROR IN CREATING THE CALENDAR", generatedCalendarId, responseCalendarId);
|
||||
}
|
||||
}
|
||||
+248
@@ -0,0 +1,248 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.fineract.infrastructure.core.service.DateUtils;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
public class CenterDomain implements Comparable<CenterDomain> {
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private Integer id;
|
||||
private String accountNo;
|
||||
private HashMap status;
|
||||
private boolean active;
|
||||
private String name;
|
||||
private String externalId;
|
||||
private Integer staffId;
|
||||
private Integer officeId;
|
||||
private String officeName;
|
||||
private String hierarchy;
|
||||
private ArrayList<HashMap> groupMembers;
|
||||
|
||||
private Builder(final Integer id, final Integer statusid, final String statuscode, final String statusvalue, final boolean active,
|
||||
final String name, final String externalId, final Integer staffId, final int officeID, final String officeName,
|
||||
final String hierarchy, final ArrayList<HashMap> groupMembers) {
|
||||
this.id = id;
|
||||
this.accountNo = accountNo;
|
||||
this.status = new HashMap();
|
||||
this.status.put("id", statusid);
|
||||
this.status.put("code", statuscode);
|
||||
this.status.put("value", statusvalue);
|
||||
this.active = active;
|
||||
this.name = name;
|
||||
this.externalId = externalId;
|
||||
this.staffId = staffId;
|
||||
this.officeId = officeID;
|
||||
this.officeName = officeName;
|
||||
this.hierarchy = hierarchy;
|
||||
this.groupMembers = groupMembers;
|
||||
}
|
||||
|
||||
public CenterDomain build() {
|
||||
return new CenterDomain(this.id, this.accountNo, (int) this.status.get("id"), (String) this.status.get("code"),
|
||||
(String) this.status.get("value"), this.active, this.name, this.externalId, this.staffId, this.officeId,
|
||||
this.officeName, this.hierarchy, groupMembers);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Integer id;
|
||||
private String accountNo;
|
||||
private HashMap status;
|
||||
private boolean active;
|
||||
private String name;
|
||||
private String externalId;
|
||||
private Integer staffId;
|
||||
private Integer officeId;
|
||||
private String officeName;
|
||||
private String hierarchy;
|
||||
private ArrayList<HashMap> groupMembers;
|
||||
|
||||
CenterDomain() {
|
||||
/* super(); */
|
||||
}
|
||||
|
||||
private CenterDomain(final Integer id, final String accountNo, final Integer statusid, final String statuscode, final String statusvalue, final boolean active,
|
||||
final String name, final String externalId, final Integer staffId, final Integer officeID, final String officeName,
|
||||
final String hierarchy, final ArrayList<HashMap> groupMembers) {
|
||||
this.id = id;
|
||||
this.accountNo = accountNo;
|
||||
this.status = new HashMap();
|
||||
this.status.put("id", statusid);
|
||||
this.status.put("code", statuscode);
|
||||
this.status.put("value", statusvalue);
|
||||
this.active = active;
|
||||
this.name = name;
|
||||
this.externalId = externalId;
|
||||
this.staffId = staffId;
|
||||
this.officeId = officeID;
|
||||
this.officeName = officeName;
|
||||
this.hierarchy = hierarchy;
|
||||
this.groupMembers = groupMembers;
|
||||
}
|
||||
|
||||
public String toJSON() {
|
||||
return new Gson().toJson(this);
|
||||
}
|
||||
|
||||
public static CurrencyDomain fromJSON(final String jsonData) {
|
||||
return new Gson().fromJson(jsonData, CurrencyDomain.class);
|
||||
}
|
||||
|
||||
public static Builder create(final Integer id, final Integer statusid, final String statuscode, final String statusvalue,
|
||||
final boolean active, final String name, final String externalId, final Integer staffId, final Integer officeID,
|
||||
final String officeName, final String hierarchy, final ArrayList<HashMap> groupMembers) {
|
||||
return new Builder(id, statusid, statuscode, statusvalue, active, name, externalId, staffId, officeID, officeName, hierarchy,
|
||||
groupMembers);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public static String jsonRequestToCreateCenter(Integer id, Integer statusId, String statusCode, String statusValue, Boolean active,
|
||||
String activationDate, String submittedDate, String name, String externalId, Integer staffId, Integer officeID,
|
||||
String officeName, String hierarchy, final int[] groupMembers) {
|
||||
// String ids = String.valueOf(id);
|
||||
final HashMap map = new HashMap<>();
|
||||
if (id != null) map.put("id", id);
|
||||
if (statusId != null) map.put("statusId", statusId);
|
||||
if (statusCode != null) map.put("statusCode", statusCode);
|
||||
if (statusValue != null) map.put("statusValue", statusValue);
|
||||
map.put("officeId", "1");
|
||||
map.put("name", randomNameGenerator("Center_Name_", 5));
|
||||
map.put("externalId", randomIDGenerator("ID_", 7));
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("locale", "en");
|
||||
if (staffId != null) {
|
||||
map.put("staffId", String.valueOf(staffId));
|
||||
}
|
||||
if (active) {
|
||||
map.put("active", "true");
|
||||
map.put("locale", "en");
|
||||
map.put("dateFormat", "dd MMM yyyy");
|
||||
map.put("activationDate", activationDate);
|
||||
} else {
|
||||
map.put("active", "false");
|
||||
if (submittedDate == null)
|
||||
map.put("submittedOnDate", DateUtils.getDateOfTenant());
|
||||
else
|
||||
map.put("submittedOnDate", submittedDate);
|
||||
}
|
||||
if (externalId != null) map.put("externalId", externalId);
|
||||
if (groupMembers != null) map.put("groupMembers", groupMembers);
|
||||
System.out.println(map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static String randomNameGenerator(final String prefix, final int lenOfRandomSuffix) {
|
||||
return Utils.randomStringGenerator(prefix, lenOfRandomSuffix);
|
||||
}
|
||||
|
||||
private static String randomIDGenerator(final String prefix, final int lenOfRandomSuffix) {
|
||||
return Utils.randomStringGenerator(prefix, lenOfRandomSuffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
}
|
||||
|
||||
public String getExternalId() {
|
||||
return this.externalId;
|
||||
}
|
||||
|
||||
public Integer getStaffId() {
|
||||
return this.staffId;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public HashMap getStatus() {
|
||||
return this.status;
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return this.active;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public Integer getOfficeId() {
|
||||
return this.officeId;
|
||||
}
|
||||
|
||||
public String getOfficeName() {
|
||||
return this.officeName;
|
||||
}
|
||||
|
||||
public String getHierarchy() {
|
||||
return this.hierarchy;
|
||||
}
|
||||
|
||||
public String getAccountNo(){
|
||||
return this.accountNo;
|
||||
}
|
||||
|
||||
public int[] getGroupMembers() {
|
||||
int[] groupMemberList = new int[this.groupMembers.size()];
|
||||
for (int i = 0; i < groupMemberList.length; i++) {
|
||||
groupMemberList[i] = ((Double) this.groupMembers.get(i).get("id")).intValue();
|
||||
}
|
||||
return groupMemberList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 1;
|
||||
|
||||
if (this.id >= 0) hash += this.id;
|
||||
if (this.status != null) {
|
||||
if ((Double) this.status.get("id") >= 0) hash += (Double) this.status.get("id");
|
||||
if ((String) this.status.get("code") != null) hash += this.status.get("code").hashCode();
|
||||
if ((String) this.status.get("value") != null) hash += this.status.get("value").hashCode();
|
||||
}
|
||||
if (this.name != null) hash += this.name.hashCode();
|
||||
if (this.officeId >= 0) hash += this.officeId;
|
||||
if (this.officeName != null) hash += this.officeName.hashCode();
|
||||
if (this.hierarchy != null) hash += this.hierarchy.hashCode();
|
||||
if (this.groupMembers != null) hash += this.groupMembers.hashCode();
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this) { return true; }
|
||||
|
||||
if (!(obj instanceof CenterDomain)) return false;
|
||||
|
||||
CenterDomain cd = (CenterDomain) obj;
|
||||
|
||||
if (this.hashCode() == cd.hashCode()) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(CenterDomain cd) {
|
||||
return ((Integer) this.id).compareTo(cd.getId());
|
||||
}
|
||||
}
|
||||
+268
@@ -0,0 +1,268 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import java.util.HashMap;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.gson.Gson;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public class CenterHelper {
|
||||
|
||||
private static final String CENTERS_URL = "/fineract-provider/api/v1/centers";
|
||||
|
||||
public static final String CREATED_DATE = "29 December 2014";
|
||||
private static final String CREATE_CENTER_URL = "/fineract-provider/api/v1/centers?" + Utils.TENANT_IDENTIFIER;
|
||||
|
||||
public static CenterDomain retrieveByID(int id, final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
final String GET_CENTER_BY_ID_URL = CENTERS_URL + "/" + id + "?associations=groupMembers&" + Utils.TENANT_IDENTIFIER;
|
||||
System.out.println("------------------------ RETRIEVING CENTER AT " + id + "-------------------------");
|
||||
final String jsonData = new Gson().toJson(Utils.performServerGet(requestSpec, responseSpec, GET_CENTER_BY_ID_URL, ""));
|
||||
return new Gson().fromJson(jsonData, new TypeToken<CenterDomain>() {}.getType());
|
||||
}
|
||||
|
||||
public static ArrayList<CenterDomain> paginatedListCenters(final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec) {
|
||||
final String GET_CENTER = CENTERS_URL + "?paged=true&limit=-1&" + Utils.TENANT_IDENTIFIER;
|
||||
System.out.println("------------------------ RETRIEVING CENTERS-------------------------");
|
||||
final String jsonData = new Gson().toJson(Utils.performServerGet(requestSpec, responseSpec, GET_CENTER, "pageItems"));
|
||||
return new Gson().fromJson(jsonData, new TypeToken<ArrayList<CenterDomain>>() {}.getType());
|
||||
}
|
||||
|
||||
public static ArrayList<CenterDomain> listCenters(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
final String GET_CENTER = CENTERS_URL + "?limit=-1&" + Utils.TENANT_IDENTIFIER;
|
||||
System.out.println("------------------------ RETRIEVING CENTERS-------------------------");
|
||||
final String jsonData = new Gson().toJson(Utils.performServerGet(requestSpec, responseSpec, GET_CENTER, ""));
|
||||
return new Gson().fromJson(jsonData, new TypeToken<ArrayList<CenterDomain>>() {}.getType());
|
||||
}
|
||||
|
||||
public static int createCenter(final String name, final int officeId, final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec) {
|
||||
return createCenter(name, officeId, null, -1, null, null, requestSpec, responseSpec);
|
||||
}
|
||||
|
||||
public static int createCenter(final String name, final int officeId, final String activationDate,
|
||||
final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
return createCenter(name, officeId, null, -1, null, activationDate, requestSpec, responseSpec);
|
||||
}
|
||||
|
||||
public static int createCenter(final String name, final int officeId, final String externalId, final int staffId,
|
||||
final int[] groupMembers, final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
return createCenter(name, officeId, externalId, staffId, groupMembers, null, requestSpec, responseSpec);
|
||||
}
|
||||
|
||||
public static int createCenter(final String name, final int officeId, final String externalId, final int staffId,
|
||||
final int[] groupMembers, final String activationDate, final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec) {
|
||||
final String CREATE_CENTER_URL = CENTERS_URL + "?" + Utils.TENANT_IDENTIFIER;
|
||||
HashMap hm = new HashMap();
|
||||
hm.put("name", name);
|
||||
hm.put("officeId", officeId);
|
||||
hm.put("active", false);
|
||||
|
||||
if (externalId != null) hm.put("externalId", externalId);
|
||||
if (staffId != -1) hm.put("staffId", staffId);
|
||||
if (groupMembers != null) hm.put("groupMembers", groupMembers);
|
||||
if (activationDate != null) {
|
||||
hm.put("active", true);
|
||||
hm.put("locale", "en");
|
||||
hm.put("dateFormat", "dd MMM yyyy");
|
||||
hm.put("activationDate", activationDate);
|
||||
}
|
||||
|
||||
System.out.println("------------------------CREATING CENTER-------------------------");
|
||||
return Utils.performServerPost(requestSpec, responseSpec, CREATE_CENTER_URL, new Gson().toJson(hm), "resourceId");
|
||||
}
|
||||
|
||||
public static HashMap<String, String> updateCenter(final int id, HashMap request, final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec) {
|
||||
final String UPDATE_CENTER_URL = CENTERS_URL + "/" + id + "?" + Utils.TENANT_IDENTIFIER;
|
||||
System.out.println("---------------------------------UPDATE CENTER AT " + id + "---------------------------------------------");
|
||||
HashMap<String, String> hash = Utils.performServerPut(requestSpec, responseSpec, UPDATE_CENTER_URL, new Gson().toJson(request),
|
||||
"changes");
|
||||
return hash;
|
||||
}
|
||||
|
||||
public static int[] associateGroups(final int id, final int[] groupMembers, final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec) {
|
||||
final String ASSOCIATE_GROUP_CENTER_URL = CENTERS_URL + "/" + id + "?command=associateGroups&" + Utils.TENANT_IDENTIFIER;
|
||||
HashMap groupMemberHashMap = new HashMap();
|
||||
groupMemberHashMap.put("groupMembers", groupMembers);
|
||||
System.out.println("---------------------------------ASSOCIATING GROUPS AT " + id + "--------------------------------------------");
|
||||
HashMap hash = Utils.performServerPost(requestSpec, responseSpec, ASSOCIATE_GROUP_CENTER_URL,
|
||||
new Gson().toJson(groupMemberHashMap), "changes");
|
||||
System.out.println(hash);
|
||||
ArrayList<String> arr = (ArrayList<String>) hash.get("groupMembers");
|
||||
int[] ret = new int[arr.size()];
|
||||
for (int i = 0; i < ret.length; i++) {
|
||||
ret[i] = Integer.parseInt(arr.get(i));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static void deleteCenter(final int id, final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
final String DELETE_CENTER_URL = CENTERS_URL + "/" + id + "?" + Utils.TENANT_IDENTIFIER;
|
||||
System.out.println("---------------------------------DELETING CENTER AT " + id + "--------------------------------------------");
|
||||
Utils.performServerDelete(requestSpec, responseSpec, DELETE_CENTER_URL, "");
|
||||
}
|
||||
|
||||
public static Integer createCenter(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
@SuppressWarnings("unused") final boolean active) {
|
||||
System.out.println("---------------------------------CREATING A CENTER---------------------------------------------");
|
||||
return createCenter(requestSpec, responseSpec, "CREATED_DATE");
|
||||
}
|
||||
|
||||
public static Integer createCenter(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String activationDate) {
|
||||
System.out.println("---------------------------------CREATING A CENTER---------------------------------------------");
|
||||
return Utils.performServerPost(requestSpec, responseSpec, CREATE_CENTER_URL, getTestCenterAsJSON(true, activationDate), "groupId");
|
||||
}
|
||||
|
||||
public static Integer createCenter(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
System.out.println("---------------------------------CREATING A CENTER---------------------------------------------");
|
||||
return Utils.performServerPost(requestSpec, responseSpec, CREATE_CENTER_URL, getTestCenterAsJSON(true, CenterHelper.CREATED_DATE),
|
||||
"groupId");
|
||||
}
|
||||
|
||||
public static int createCenterWithStaffId(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer staffId) {
|
||||
System.out.println("---------------------------------CREATING A CENTER---------------------------------------------");
|
||||
return Utils.performServerPost(requestSpec, responseSpec, CREATE_CENTER_URL,
|
||||
getTestCenterWithStaffAsJSON(true, CenterHelper.CREATED_DATE, staffId), "groupId");
|
||||
}
|
||||
|
||||
public static void verifyCenterCreatedOnServer(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer generatedCenterID) {
|
||||
System.out.println("------------------------------CHECK CENTER DETAILS------------------------------------\n");
|
||||
final String CENTER_URL = "/fineract-provider/api/v1/centers/" + generatedCenterID + "?" + Utils.TENANT_IDENTIFIER;
|
||||
final Integer responseCenterID = Utils.performServerGet(requestSpec, responseSpec, CENTER_URL, "id");
|
||||
assertEquals("ERROR IN CREATING THE CENTER", generatedCenterID, responseCenterID);
|
||||
}
|
||||
|
||||
public static void verifyCenterActivatedOnServer(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer generatedCenterID, final boolean generatedCenterStatus) {
|
||||
System.out.println("------------------------------CHECK CENTER STATUS------------------------------------\n");
|
||||
final String CENTER_URL = "/fineract-provider/api/v1/centers/" + generatedCenterID + "?" + Utils.TENANT_IDENTIFIER;
|
||||
final Boolean responseCenterStatus = Utils.performServerGet(requestSpec, responseSpec, CENTER_URL, "active");
|
||||
assertEquals("ERROR IN ACTIVATING THE CENTER", generatedCenterStatus, responseCenterStatus);
|
||||
}
|
||||
|
||||
public static Integer activateCenter(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String centerId) {
|
||||
final String CENTER_ASSOCIATE_URL = "/fineract-provider/api/v1/centers/" + centerId + "?command=activate&" + Utils.TENANT_IDENTIFIER;
|
||||
System.out.println("---------------------------------ACTIVATE A CENTER---------------------------------------------");
|
||||
return Utils.performServerPost(requestSpec, responseSpec, CENTER_ASSOCIATE_URL, activateCenterAsJSON(""), "groupId");
|
||||
}
|
||||
|
||||
public static String getTestCenterWithStaffAsJSON(final boolean active, final String activationDate, final Integer staffId) {
|
||||
|
||||
Integer id = null;
|
||||
Integer statusid = null;
|
||||
String statuscode = null;
|
||||
String statusvalue = null;
|
||||
String name = null;
|
||||
String externalId = null;
|
||||
Integer officeID = null;
|
||||
String officeName = null;
|
||||
String hierarchy = null;
|
||||
int[] groupMembers = null;
|
||||
String submittedDate = null;
|
||||
|
||||
return CenterDomain.jsonRequestToCreateCenter(id, statusid, statuscode, statusvalue, active, activationDate,submittedDate,name,
|
||||
externalId, staffId, officeID, officeName, hierarchy, groupMembers);
|
||||
}
|
||||
|
||||
public static String getTestCenterAsJSON(final boolean active, final String activationDate) {
|
||||
|
||||
Integer id = null;
|
||||
Integer statusid = null;
|
||||
String statuscode = null;
|
||||
String statusvalue = null;
|
||||
String name = null;
|
||||
String externalId = null;
|
||||
Integer officeID = null;
|
||||
String officeName = null;
|
||||
Integer staffId = null;
|
||||
String hierarchy = null;
|
||||
final int[] groupMembers = null;
|
||||
String submittedDate = null;
|
||||
|
||||
return CenterDomain.jsonRequestToCreateCenter(id, statusid, statuscode, statusvalue, active, activationDate,submittedDate,name,
|
||||
externalId, staffId, officeID, officeName, hierarchy, groupMembers);
|
||||
|
||||
}
|
||||
|
||||
public static String assignStaffAsJSON(final Long staffId) {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("staffId", staffId);
|
||||
System.out.println("map : " + map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static String unassignStaffAsJSON(final Long staffId) {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("staffId", staffId);
|
||||
System.out.println("map : " + map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static String activateCenterAsJSON(final String activationDate) {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("locale", "en");
|
||||
if (StringUtils.isNotEmpty(activationDate)) {
|
||||
map.put("activationDate", activationDate);
|
||||
} else {
|
||||
map.put("activationDate", "CREATED_DATE");
|
||||
System.out.println("defaulting to fixed date: CREATED_DATE");
|
||||
}
|
||||
System.out.println("map : " + map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static String randomNameGenerator(final String prefix, final int lenOfRandomSuffix) {
|
||||
return Utils.randomStringGenerator(prefix, lenOfRandomSuffix);
|
||||
}
|
||||
|
||||
private static String randomIDGenerator(final String prefix, final int lenOfRandomSuffix) {
|
||||
return Utils.randomStringGenerator(prefix, lenOfRandomSuffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
}
|
||||
|
||||
public static Object assignStaff(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String groupId, final Long staffId) {
|
||||
final String GROUP_ASSIGN_STAFF_URL = "/fineract-provider/api/v1/groups/" + groupId + "?" + Utils.TENANT_IDENTIFIER
|
||||
+ "&command=assignStaff";
|
||||
System.out.println("---------------------------------Assign Staff---------------------------------------------");
|
||||
return Utils.performServerPost(requestSpec, responseSpec, GROUP_ASSIGN_STAFF_URL, assignStaffAsJSON(staffId), "changes");
|
||||
}
|
||||
|
||||
public static Object unassignStaff(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String groupId, final Long staffId) {
|
||||
final String GROUP_ASSIGN_STAFF_URL = "/fineract-provider/api/v1/groups/" + groupId + "?" + Utils.TENANT_IDENTIFIER
|
||||
+ "&command=unassignStaff";
|
||||
System.out.println("---------------------------------Unassign Staff---------------------------------------------");
|
||||
return Utils.performServerPost(requestSpec, responseSpec, GROUP_ASSIGN_STAFF_URL, unassignStaffAsJSON(staffId), "changes");
|
||||
}
|
||||
|
||||
}
|
||||
+175
@@ -0,0 +1,175 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.charges.ChargesHelper;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
*
|
||||
* IntegrationTest for ClientCharges.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* @author lenovo
|
||||
*
|
||||
*/
|
||||
public class ClientChargesTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clientChargeTest() {
|
||||
|
||||
// Creates clientCharge
|
||||
final Integer chargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
|
||||
ChargesHelper.getChargeSpecifiedDueDateJSON());
|
||||
Assert.assertNotNull(chargeId);
|
||||
|
||||
// creates client with activation date
|
||||
final Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 November 2012");
|
||||
Assert.assertNotNull(clientId);
|
||||
|
||||
/**
|
||||
* create a charge for loan and try to associate to client created in
|
||||
* the above lines.it will be an invalid scenario the reason is client
|
||||
* is not allowed to have only client charge.
|
||||
*
|
||||
*/
|
||||
final Integer loanChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
|
||||
ChargesHelper.getLoanSpecifiedDueDateJSON());
|
||||
Assert.assertNotNull(loanChargeId);
|
||||
ResponseSpecification responseLoanChargeFailure = new ResponseSpecBuilder().expectStatusCode(403).build();
|
||||
final Integer clientLoanChargeId = ClientHelper.addChargesForClient(this.requestSpec, responseLoanChargeFailure, clientId,
|
||||
ClientHelper.getSpecifiedDueDateChargesClientAsJSON(loanChargeId.toString(), "29 October 2011"));
|
||||
Assert.assertNull(clientLoanChargeId);
|
||||
|
||||
/**
|
||||
* associates a clientCharge to a client and pay client charge for 10
|
||||
* USD--success scenario
|
||||
**/
|
||||
final Integer clientChargeId = ClientHelper.addChargesForClient(this.requestSpec, this.responseSpec, clientId,
|
||||
ClientHelper.getSpecifiedDueDateChargesClientAsJSON(chargeId.toString(), "29 October 2011"));
|
||||
Assert.assertNotNull(clientChargeId);
|
||||
final String clientChargePaidTransactionId = ClientHelper.payChargesForClients(this.requestSpec, this.responseSpec, clientId,
|
||||
clientChargeId, ClientHelper.getPayChargeJSON("25 AUGUST 2015", "10"));
|
||||
Assert.assertNotNull(clientChargePaidTransactionId);
|
||||
isValidOutstandingAmount(ClientHelper.getClientCharge(requestSpec, responseSpec, clientId.toString(), clientChargeId.toString()),
|
||||
(float) 190.0);
|
||||
|
||||
/**
|
||||
* Revert the paid client charge transaction by passing the
|
||||
* clientChargePaidTransactionId and ensure the same is reverted.
|
||||
*/
|
||||
final Integer undoTrxnId = ClientHelper.revertClientChargeTransaction(this.requestSpec, this.responseSpec,
|
||||
clientId.toString(), clientChargePaidTransactionId);
|
||||
Assert.assertNotNull(undoTrxnId);
|
||||
isReversedTransaction(clientId.toString(), undoTrxnId.toString());
|
||||
/**
|
||||
* Now pay client charge for 20 USD and ensure the outstanding amount is
|
||||
* updated properly
|
||||
*/
|
||||
ResponseSpecification responseSpecFailure = new ResponseSpecBuilder().expectStatusCode(400).build();
|
||||
final String responseId_futureDate_failure = ClientHelper.payChargesForClients(this.requestSpec, responseSpecFailure, clientId,
|
||||
clientChargeId, ClientHelper.getPayChargeJSON("28 AUGUST 2016", "20"));
|
||||
Assert.assertNull(responseId_futureDate_failure);
|
||||
|
||||
// waived off the outstanding client charge
|
||||
final String waiveOffClientChargeTransactionId = ClientHelper.waiveChargesForClients(this.requestSpec, this.responseSpec, clientId,
|
||||
clientChargeId, ClientHelper.getWaiveChargeJSON("100", clientChargeId.toString()));
|
||||
Assert.assertNotNull(waiveOffClientChargeTransactionId);
|
||||
|
||||
/**
|
||||
* Revert the waived off client charge transaction by passing the
|
||||
* waiveOffClientChargeTransactionId and ensured the transaction is
|
||||
* reversed.
|
||||
*/
|
||||
final Integer undoWaiveTrxnId = ClientHelper.revertClientChargeTransaction(this.requestSpec, this.responseSpec, clientId.toString(),
|
||||
waiveOffClientChargeTransactionId);
|
||||
Assert.assertNotNull(undoWaiveTrxnId);
|
||||
isReversedTransaction(clientId.toString(), undoWaiveTrxnId.toString());
|
||||
/**
|
||||
* pay client charge before client activation date and ensured its a
|
||||
* failure test case
|
||||
*/
|
||||
|
||||
final String responseId_activationDate_failure = ClientHelper.payChargesForClients(this.requestSpec, responseSpecFailure, clientId,
|
||||
clientChargeId, ClientHelper.getPayChargeJSON("30 October 2011", "20"));
|
||||
Assert.assertNull(responseId_activationDate_failure);
|
||||
/**
|
||||
* pay client charge more than outstanding amount amount and ensured its
|
||||
* a failure test case
|
||||
*/
|
||||
final String responseId_moreAmount_failure = ClientHelper.payChargesForClients(this.requestSpec, responseSpecFailure, clientId,
|
||||
clientChargeId, ClientHelper.getPayChargeJSON("25 AUGUST 2015", "300"));
|
||||
Assert.assertNull(responseId_moreAmount_failure);
|
||||
/**
|
||||
* pay client charge for 10 USD and ensure outstanding amount is updated
|
||||
* properly
|
||||
*/
|
||||
final String chargePaid_responseId = ClientHelper.payChargesForClients(this.requestSpec, this.responseSpec, clientId,
|
||||
clientChargeId, ClientHelper.getPayChargeJSON("25 AUGUST 2015", "100"));
|
||||
Assert.assertNotNull(chargePaid_responseId);
|
||||
|
||||
isValidOutstandingAmount(ClientHelper.getClientCharge(requestSpec, responseSpec, clientId.toString(), clientChargeId.toString()),
|
||||
(float) 100.0);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* It checks whether the client charge transaction is reversed or not.
|
||||
*
|
||||
* @param clientId
|
||||
* @param transactionId
|
||||
*/
|
||||
private void isReversedTransaction(String clientId, String transactionId) {
|
||||
final Boolean isReversed = ClientHelper.getClientTransactions(this.requestSpec, this.responseSpec, clientId.toString(),
|
||||
transactionId);
|
||||
Assert.assertTrue(isReversed);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the outStandingAmount is equal to expected Amount or not
|
||||
* after paying or after waiving off the client charge.
|
||||
*
|
||||
* @param outStandingAmount
|
||||
* @param expectedAmount
|
||||
*/
|
||||
private void isValidOutstandingAmount(Object outStandingAmount, Object expectedAmount) {
|
||||
Assert.assertEquals((float) outStandingAmount, expectedAmount);
|
||||
}
|
||||
|
||||
}
|
||||
+442
@@ -0,0 +1,442 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.fineract.infrastructure.codes.domain.CodeValue;
|
||||
import org.apache.fineract.integrationtests.common.system.CodeHelper;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
public class ClientHelper {
|
||||
|
||||
private final RequestSpecification requestSpec;
|
||||
private final ResponseSpecification responseSpec;
|
||||
|
||||
private static final String CREATE_CLIENT_URL = "/fineract-provider/api/v1/clients?" + Utils.TENANT_IDENTIFIER;
|
||||
private static final String CLIENT_URL = "/fineract-provider/api/v1/clients";
|
||||
private static final String CLOSE_CLIENT_COMMAND = "close";
|
||||
private static final String REACTIVATE_CLIENT_COMMAND = "reactivate";
|
||||
private static final String REJECT_CLIENT_COMMAND = "reject";
|
||||
private static final String ACTIVATE_CLIENT_COMMAND = "activate";
|
||||
private static final String WITHDRAW_CLIENT_COMMAND = "withdraw";
|
||||
|
||||
public static final String CREATED_DATE = "27 November 2014";
|
||||
public static final String CREATED_DATE_PLUS_ONE = "28 November 2014";
|
||||
public static final String CREATED_DATE_MINUS_ONE = "27 November 2014";
|
||||
public static final String TRANSACTION_DATE = "01 March 2013";
|
||||
public static final String LAST_TRANSACTION_DATE = "01 March 2013";
|
||||
public static final String DATE_FORMAT = "dd MMMM yyyy";
|
||||
|
||||
public ClientHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
this.requestSpec = requestSpec;
|
||||
this.responseSpec = responseSpec;
|
||||
}
|
||||
|
||||
public static Integer createClient(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
return createClient(requestSpec, responseSpec, "04 March 2011");
|
||||
}
|
||||
|
||||
public static Integer createClient(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String activationDate) {
|
||||
return createClient(requestSpec, responseSpec, activationDate, "1");
|
||||
}
|
||||
|
||||
public static Integer createClient(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String activationDate, final String officeId) {
|
||||
System.out.println("---------------------------------CREATING A CLIENT---------------------------------------------");
|
||||
return Utils.performServerPost(requestSpec, responseSpec, CREATE_CLIENT_URL, getTestClientAsJSON(activationDate, officeId),
|
||||
"clientId");
|
||||
}
|
||||
|
||||
public static Integer createClientAsPerson(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
return createClientAsPerson(requestSpec, responseSpec, "04 March 2011");
|
||||
}
|
||||
|
||||
public static Integer createClientAsPerson(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String activationDate) {
|
||||
return createClientAsPerson(requestSpec, responseSpec, activationDate, "1");
|
||||
}
|
||||
|
||||
public static Integer createClientAsPerson(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String activationDate, final String officeId) {
|
||||
|
||||
System.out.println("---------------------------------CREATING A CLIENT NON PERSON(ORGANISATION)---------------------------------------------");
|
||||
return Utils.performServerPost(requestSpec, responseSpec, CREATE_CLIENT_URL, getTestPersonClientAsJSON(activationDate, officeId),
|
||||
"clientId");
|
||||
}
|
||||
|
||||
public static Integer createClientAsEntity(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
return createClientAsEntity(requestSpec, responseSpec, "04 March 2011");
|
||||
}
|
||||
|
||||
public static Integer createClientAsEntity(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String activationDate) {
|
||||
return createClientAsEntity(requestSpec, responseSpec, activationDate, "1");
|
||||
}
|
||||
|
||||
public static Integer createClientAsEntity(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String activationDate, final String officeId) {
|
||||
|
||||
Integer constitutionCodeId = (Integer) CodeHelper.getCodeByName(requestSpec, responseSpec, "Constitution").get("id");
|
||||
Integer soleProprietorCodeValueId = (Integer) CodeHelper.retrieveOrCreateCodeValue(constitutionCodeId, requestSpec, responseSpec).get("id");
|
||||
|
||||
System.out.println("---------------------------------CREATING A CLIENT NON PERSON(ORGANISATION)---------------------------------------------");
|
||||
return Utils.performServerPost(requestSpec, responseSpec, CREATE_CLIENT_URL, getTestEntityClientAsJSON(activationDate, officeId, soleProprietorCodeValueId),
|
||||
"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()), jsonAttributeToGetBack);
|
||||
}
|
||||
|
||||
public static Object assignStaffToClient(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String clientId, final String staffId) {
|
||||
final String CLIENT_ASSIGN_STAFF_URL = "/fineract-provider/api/v1/clients/" + clientId + "?" + Utils.TENANT_IDENTIFIER
|
||||
+ "&command=assignStaff";
|
||||
|
||||
System.out.println("---------------------------------CREATING A CLIENT---------------------------------------------");
|
||||
return Utils.performServerPost(requestSpec, responseSpec, CLIENT_ASSIGN_STAFF_URL, assignStaffToClientAsJson(staffId), "changes");
|
||||
}
|
||||
|
||||
public static Integer getClientsStaffId(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String clientId) {
|
||||
return (Integer) getClient(requestSpec, responseSpec, clientId, "staffId");
|
||||
}
|
||||
|
||||
public static String getTestClientAsJSON(final String dateOfJoining, final String officeId) {
|
||||
final HashMap<String, String> 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", DATE_FORMAT);
|
||||
map.put("locale", "en");
|
||||
map.put("active", "true");
|
||||
map.put("activationDate", dateOfJoining);
|
||||
System.out.println("map : " + map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static String getTestPersonClientAsJSON(final String dateOfJoining, final String officeId) {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("officeId", officeId);
|
||||
map.put("fullname", Utils.randomNameGenerator("Client_FullName_", 5));
|
||||
map.put("externalId", randomIDGenerator("ID_", 7));
|
||||
map.put("dateFormat", DATE_FORMAT);
|
||||
map.put("locale", "en");
|
||||
map.put("active", "true");
|
||||
map.put("activationDate", dateOfJoining);
|
||||
map.put("legalFormId", 1);
|
||||
|
||||
System.out.println("map : " + map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static String getTestEntityClientAsJSON(final String dateOfJoining, final String officeId, final Integer soleProprietorCodeValueId) {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("officeId", officeId);
|
||||
map.put("fullname", Utils.randomNameGenerator("Client_FullName_", 5));
|
||||
map.put("externalId", randomIDGenerator("ID_", 7));
|
||||
map.put("dateFormat", DATE_FORMAT);
|
||||
map.put("locale", "en");
|
||||
map.put("active", "true");
|
||||
map.put("activationDate", dateOfJoining);
|
||||
map.put("legalFormId", 2);
|
||||
|
||||
final HashMap<String, Object> clientNonPersonMap = new HashMap<>();
|
||||
clientNonPersonMap.put("constitutionId", soleProprietorCodeValueId);
|
||||
map.put("clientNonPersonDetails", clientNonPersonMap);
|
||||
|
||||
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<String, String> 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", DATE_FORMAT);
|
||||
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<String, String> map = new HashMap<>();
|
||||
map.put("staffId", staffId);
|
||||
System.out.println("map : " + map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static void verifyClientCreatedOnServer(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer generatedClientID) {
|
||||
System.out.println("------------------------------CHECK CLIENT DETAILS------------------------------------\n");
|
||||
final String CLIENT_URL = "/fineract-provider/api/v1/clients/" + generatedClientID + "?" + Utils.TENANT_IDENTIFIER;
|
||||
final Integer responseClientID = Utils.performServerGet(requestSpec, responseSpec, CLIENT_URL, "id");
|
||||
assertEquals("ERROR IN CREATING THE CLIENT", generatedClientID, responseClientID);
|
||||
}
|
||||
|
||||
public static Object getClient(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, final String clientId,
|
||||
final String jsonReturn) {
|
||||
final String GET_CLIENT_URL = "/fineract-provider/api/v1/clients/" + clientId + "?" + Utils.TENANT_IDENTIFIER;
|
||||
System.out.println("---------------------------------GET A CLIENT---------------------------------------------");
|
||||
return Utils.performServerGet(requestSpec, responseSpec, GET_CLIENT_URL, jsonReturn);
|
||||
|
||||
}
|
||||
|
||||
/* Client status is a map.So adding SuppressWarnings */
|
||||
@SuppressWarnings("unchecked")
|
||||
public static HashMap<String, Object> getClientStatus(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String clientId) {
|
||||
return (HashMap<String, Object>) getClient(requestSpec, responseSpec, clientId, "status");
|
||||
}
|
||||
|
||||
private static String randomIDGenerator(final String prefix, final int lenOfRandomSuffix) {
|
||||
return Utils.randomStringGenerator(prefix, lenOfRandomSuffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
}
|
||||
|
||||
private String getCloseClientAsJSON() {
|
||||
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);
|
||||
Integer closureReasonId = (Integer) codeValue.get("id");
|
||||
|
||||
map.put("closureReasonId", closureReasonId.toString());
|
||||
map.put("locale", CommonConstants.locale);
|
||||
map.put("dateFormat", CommonConstants.dateFormat);
|
||||
map.put("closureDate", CREATED_DATE_PLUS_ONE);
|
||||
|
||||
String clientJson = new Gson().toJson(map);
|
||||
System.out.println(clientJson);
|
||||
return clientJson;
|
||||
|
||||
}
|
||||
|
||||
private String getReactivateClientAsJSON() {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("locale", CommonConstants.locale);
|
||||
map.put("dateFormat", CommonConstants.dateFormat);
|
||||
map.put("reactivationDate", CREATED_DATE_PLUS_ONE);
|
||||
String clientJson = new Gson().toJson(map);
|
||||
System.out.println(clientJson);
|
||||
return clientJson;
|
||||
|
||||
}
|
||||
|
||||
private String getRejectClientAsJSON() {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
/* Retrieve Code id for the Code "ClientRejectReason" */
|
||||
String codeName = "ClientRejectReason";
|
||||
HashMap<String, Object> code = CodeHelper.getCodeByName(this.requestSpec, this.responseSpec, codeName);
|
||||
Integer clientRejectionReasonCodeId = (Integer) code.get("id");
|
||||
|
||||
/* Retrieve/Create Code Values for the Code "ClientRejectReason" */
|
||||
HashMap<String, Object> codeValue = CodeHelper.retrieveOrCreateCodeValue(clientRejectionReasonCodeId, this.requestSpec,
|
||||
this.responseSpec);
|
||||
Integer rejectionReasonId = (Integer) codeValue.get("id");
|
||||
|
||||
map.put("locale", CommonConstants.locale);
|
||||
map.put("dateFormat", CommonConstants.dateFormat);
|
||||
map.put("rejectionDate", CREATED_DATE_PLUS_ONE);
|
||||
map.put("rejectionReasonId", rejectionReasonId.toString());
|
||||
String clientJson = new Gson().toJson(map);
|
||||
System.out.println(clientJson);
|
||||
return clientJson;
|
||||
|
||||
}
|
||||
|
||||
private String getActivateClientAsJSON() {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("locale", CommonConstants.locale);
|
||||
map.put("dateFormat", CommonConstants.dateFormat);
|
||||
map.put("activationDate", CREATED_DATE_PLUS_ONE);
|
||||
String clientJson = new Gson().toJson(map);
|
||||
System.out.println(clientJson);
|
||||
return clientJson;
|
||||
|
||||
}
|
||||
|
||||
private String getWithdrawClientAsJSON() {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
/* Retrieve Code id for the Code "ClientWithdrawReason" */
|
||||
String codeName = "ClientWithdrawReason";
|
||||
HashMap<String, Object> code = CodeHelper.getCodeByName(this.requestSpec, this.responseSpec, codeName);
|
||||
Integer clientWithdrawReasonCodeId = (Integer) code.get("id");
|
||||
|
||||
/* Retrieve/Create Code Values for the Code "ClientWithdrawReason" */
|
||||
HashMap<String, Object> codeValue = CodeHelper.retrieveOrCreateCodeValue(clientWithdrawReasonCodeId, this.requestSpec,
|
||||
this.responseSpec);
|
||||
Integer withdrawalReasonId = (Integer) codeValue.get("id");
|
||||
|
||||
map.put("locale", CommonConstants.locale);
|
||||
map.put("dateFormat", CommonConstants.dateFormat);
|
||||
map.put("withdrawalDate", CREATED_DATE_PLUS_ONE);
|
||||
map.put("withdrawalReasonId", withdrawalReasonId.toString());
|
||||
String clientJson = new Gson().toJson(map);
|
||||
System.out.println(clientJson);
|
||||
return clientJson;
|
||||
|
||||
}
|
||||
|
||||
public static String getSpecifiedDueDateChargesClientAsJSON(final String chargeId, final String dueDate) {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("locale", "en_GB");
|
||||
map.put("dateFormat", DATE_FORMAT);
|
||||
map.put("dueDate", dueDate);
|
||||
map.put("chargeId", chargeId);
|
||||
map.put("amount", "200");
|
||||
String json = new Gson().toJson(map);
|
||||
return json;
|
||||
}
|
||||
|
||||
public static String getPayChargeJSON(final String date, String amount) {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("locale", "en_GB");
|
||||
map.put("dateFormat", DATE_FORMAT);
|
||||
map.put("transactionDate", date);
|
||||
map.put("amount", amount);
|
||||
String json = new Gson().toJson(map);
|
||||
System.out.println(json);
|
||||
return json;
|
||||
}
|
||||
|
||||
public static String getWaiveChargeJSON(final String amount, String clientChargeId) {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("locale", "en_GB");
|
||||
map.put("amount", amount);
|
||||
map.put("clientChargeId", clientChargeId);
|
||||
String json = new Gson().toJson(map);
|
||||
System.out.println(json);
|
||||
return json;
|
||||
}
|
||||
|
||||
public HashMap<String, Object> closeClient(final Integer clientId) {
|
||||
System.out.println("--------------------------------- CLOSE CLIENT -------------------------------");
|
||||
return performClientActions(createClientOperationURL(CLOSE_CLIENT_COMMAND, clientId), getCloseClientAsJSON(), clientId);
|
||||
}
|
||||
|
||||
public HashMap<String, Object> reactivateClient(final Integer clientId) {
|
||||
System.out.println("--------------------------------- REACTIVATE CLIENT -------------------------------");
|
||||
return performClientActions(createClientOperationURL(REACTIVATE_CLIENT_COMMAND, clientId), getReactivateClientAsJSON(), clientId);
|
||||
}
|
||||
|
||||
public HashMap<String, Object> rejectClient(final Integer clientId) {
|
||||
System.out.println("--------------------------------- REJECT CLIENT -------------------------------");
|
||||
return performClientActions(createClientOperationURL(REJECT_CLIENT_COMMAND, clientId), getRejectClientAsJSON(), clientId);
|
||||
}
|
||||
|
||||
public HashMap<String, Object> activateClient(final Integer clientId) {
|
||||
System.out.println("--------------------------------- ACTIVATE CLIENT -------------------------------");
|
||||
return performClientActions(createClientOperationURL(ACTIVATE_CLIENT_COMMAND, clientId), getActivateClientAsJSON(), clientId);
|
||||
}
|
||||
|
||||
public HashMap<String, Object> withdrawClient(final Integer clientId) {
|
||||
System.out.println("--------------------------------- WITHDRAWN CLIENT -------------------------------");
|
||||
return performClientActions(createClientOperationURL(WITHDRAW_CLIENT_COMMAND, clientId), getWithdrawClientAsJSON(), clientId);
|
||||
}
|
||||
|
||||
private String createClientOperationURL(final String command, final Integer clientId) {
|
||||
return CLIENT_URL + "/" + clientId + "?command=" + command + "&" + Utils.TENANT_IDENTIFIER;
|
||||
}
|
||||
|
||||
private HashMap<String, Object> performClientActions(final String postURLForClient, final String jsonToBeSent, final Integer clientId) {
|
||||
Utils.performServerPost(this.requestSpec, this.responseSpec, postURLForClient, jsonToBeSent, CommonConstants.RESPONSE_STATUS);
|
||||
HashMap<String, Object> response = ClientHelper.getClientStatus(requestSpec, responseSpec, String.valueOf(clientId));
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
public static Integer addChargesForClient(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer clientId, final String request) {
|
||||
System.out.println("--------------------------------- ADD CHARGES FOR Client --------------------------------");
|
||||
final String ADD_CHARGES_URL = "/fineract-provider/api/v1/clients/" + clientId + "/charges?" + Utils.TENANT_IDENTIFIER;
|
||||
final HashMap<?, ?> response = Utils.performServerPost(requestSpec, responseSpec, ADD_CHARGES_URL, request, "");
|
||||
return (Integer) response.get("resourceId");
|
||||
}
|
||||
|
||||
public static String payChargesForClients(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer clientId, final Integer clientChargeId, final String json) {
|
||||
System.out.println("--------------------------------- PAY CHARGES FOR CLIENT --------------------------------");
|
||||
final String CHARGES_URL = "/fineract-provider/api/v1/clients/" + clientId + "/charges/" + clientChargeId + "?command=paycharge&"
|
||||
+ Utils.TENANT_IDENTIFIER;
|
||||
final HashMap<?, ?> response = Utils.performServerPost(requestSpec, responseSpec, CHARGES_URL, json, "");
|
||||
return response.get("transactionId") != null ? response.get("transactionId").toString() : null;
|
||||
}
|
||||
|
||||
public static String waiveChargesForClients(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer clientId, final Integer clientChargeId, final String json) {
|
||||
System.out.println("--------------------------------- WAIVE CHARGES FOR CLIENT --------------------------------");
|
||||
final String CHARGES_URL = "/fineract-provider/api/v1/clients/" + clientId + "/charges/" + clientChargeId + "?command=waive&"
|
||||
+ Utils.TENANT_IDENTIFIER;
|
||||
|
||||
final HashMap<?, ?> response = Utils.performServerPost(requestSpec, responseSpec, CHARGES_URL, json, "");
|
||||
return response.get("transactionId").toString();
|
||||
}
|
||||
|
||||
public static Integer revertClientChargeTransaction(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String clientId, String clientChargeId) {
|
||||
System.out.println("---------------------------------UNDO TRANSACTION---------------------------------------------");
|
||||
final String CHARGES_URL = "/fineract-provider/api/v1/clients/" + clientId + "/transactions/" + clientChargeId + "?command=undo&"
|
||||
+ Utils.TENANT_IDENTIFIER;
|
||||
|
||||
final HashMap<?, ?> response = Utils.performServerPost(requestSpec, responseSpec, CHARGES_URL, "", "");
|
||||
return (Integer) response.get("resourceId");
|
||||
|
||||
}
|
||||
|
||||
public static Object getClientCharge(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String clientId, final String clientChargeId) {
|
||||
System.out.println("---------------------------------GET CLIENT CHARGE---------------------------------------------");
|
||||
final String CHARGES_URL = "/fineract-provider/api/v1/clients/" + clientId + "/charges/" + clientChargeId + "?"
|
||||
+ Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerGet(requestSpec, responseSpec, CHARGES_URL, "amountOutstanding");
|
||||
}
|
||||
|
||||
public static Boolean getClientTransactions(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String clientId, final String transactionId) {
|
||||
System.out.println("---------------------------------GET CLIENT CHARGE TRANSACTIONS---------------------------------------------");
|
||||
final String CHARGES_URL = "/fineract-provider/api/v1/clients/" + clientId + "/transactions/" + transactionId + "?"
|
||||
+ Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerGet(requestSpec, responseSpec, CHARGES_URL, "reversed");
|
||||
}
|
||||
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common;
|
||||
|
||||
|
||||
public interface CommonConstants {
|
||||
|
||||
public final static String locale = "en";
|
||||
public static final String dateFormat = "dd MMMM yyyy";
|
||||
public static final String RESPONSE_RESOURCE_ID = "resourceId";
|
||||
public static final String RESPONSE_CHANGES = "changes";
|
||||
public static final String RESPONSE_STATUS = "status";
|
||||
public static final String RESPONSE_ERROR = "errors";
|
||||
public static final String RESPONSE_ERROR_MESSAGE_CODE = "userMessageGlobalisationCode";
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.gson.Gson;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
@SuppressWarnings({ "unused", "rawtypes", "unchecked" })
|
||||
public class CurrenciesHelper {
|
||||
|
||||
private static final String CURRENCIES_URL = "/fineract-provider/api/v1/currencies";
|
||||
|
||||
public static ArrayList<CurrencyDomain> getAllCurrencies(final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec) {
|
||||
final String GET_ALL_CURRENCIES_URL = CURRENCIES_URL + "?" + Utils.TENANT_IDENTIFIER;
|
||||
System.out.println("------------------------ RETRIEVING ALL CURRENCIES -------------------------");
|
||||
final HashMap response = Utils.performServerGet(requestSpec, responseSpec, GET_ALL_CURRENCIES_URL, "");
|
||||
ArrayList<HashMap> selectedCurrencyOptions = (ArrayList<HashMap>) response.get("selectedCurrencyOptions");
|
||||
ArrayList<HashMap> currencyOptions = (ArrayList<HashMap>) response.get("currencyOptions");
|
||||
currencyOptions.addAll(selectedCurrencyOptions);
|
||||
final String jsonData = new Gson().toJson(new ArrayList<HashMap>(selectedCurrencyOptions));
|
||||
return new Gson().fromJson(jsonData, new TypeToken<ArrayList<CurrencyDomain>>() {}.getType());
|
||||
}
|
||||
|
||||
public static ArrayList<CurrencyDomain> getSelectedCurrencies(final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec) {
|
||||
final String GET_ALL_SELECTED_CURRENCIES_URL = CURRENCIES_URL + "?fields=selectedCurrencyOptions" + "&" + Utils.TENANT_IDENTIFIER;
|
||||
System.out.println("------------------------ RETRIEVING ALL SELECTED CURRENCIES -------------------------");
|
||||
final HashMap response = Utils.performServerGet(requestSpec, responseSpec, GET_ALL_SELECTED_CURRENCIES_URL, "");
|
||||
final String jsonData = new Gson().toJson(response.get("selectedCurrencyOptions"));
|
||||
return new Gson().fromJson(jsonData, new TypeToken<ArrayList<CurrencyDomain>>() {}.getType());
|
||||
}
|
||||
|
||||
public static CurrencyDomain getCurrencybyCode(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String code) {
|
||||
ArrayList<CurrencyDomain> currenciesList = getAllCurrencies(requestSpec, responseSpec);
|
||||
for (CurrencyDomain e : currenciesList) {
|
||||
if (e.getCode().equals(code)) return e;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ArrayList<String> updateSelectedCurrencies(final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec, final ArrayList<String> currencies) {
|
||||
final String CURRENCIES_UPDATE_URL = CURRENCIES_URL + "?" + Utils.TENANT_IDENTIFIER;
|
||||
System.out.println("---------------------------------UPDATE SELECTED CURRENCIES LIST---------------------------------------------");
|
||||
HashMap hash = Utils.performServerPut(requestSpec, responseSpec, CURRENCIES_UPDATE_URL, currenciesToJSON(currencies), "changes");
|
||||
return (ArrayList<String>) hash.get("currencies");
|
||||
}
|
||||
|
||||
private static String currenciesToJSON(final ArrayList<String> currencies) {
|
||||
HashMap map = new HashMap<>();
|
||||
map.put("currencies", currencies);
|
||||
System.out.println("map : " + map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
}
|
||||
+140
@@ -0,0 +1,140 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
public class CurrencyDomain implements Comparable<CurrencyDomain> {
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private String code;
|
||||
private String name;
|
||||
private int decimalPlaces;
|
||||
private String displaySymbol;
|
||||
private String nameCode;
|
||||
private String displayLabel;
|
||||
|
||||
private Builder(final String code, final String name, final int decimalPlaces, final String displaySymbol, final String nameCode,
|
||||
final String displayLabel) {
|
||||
this.code = code;
|
||||
this.name = name;
|
||||
this.decimalPlaces = decimalPlaces;
|
||||
this.displaySymbol = displaySymbol;
|
||||
this.nameCode = nameCode;
|
||||
this.displayLabel = displayLabel;
|
||||
}
|
||||
|
||||
public CurrencyDomain build() {
|
||||
return new CurrencyDomain(this.code, this.name, this.decimalPlaces, this.displaySymbol, this.nameCode, this.displayLabel);
|
||||
}
|
||||
}
|
||||
|
||||
private String code;
|
||||
private String name;
|
||||
private int decimalPlaces;
|
||||
private String displaySymbol;
|
||||
private String nameCode;
|
||||
private String displayLabel;
|
||||
|
||||
CurrencyDomain() {
|
||||
super();
|
||||
}
|
||||
|
||||
private CurrencyDomain(final String code, final String name, final int decimalPlaces, final String displaySymbol,
|
||||
final String nameCode, final String displayLabel) {
|
||||
super();
|
||||
this.code = code;
|
||||
this.name = name;
|
||||
this.decimalPlaces = decimalPlaces;
|
||||
this.displaySymbol = displaySymbol;
|
||||
this.nameCode = nameCode;
|
||||
this.displayLabel = displayLabel;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
public int getDecimalPlaces() {
|
||||
return this.decimalPlaces;
|
||||
}
|
||||
|
||||
public String getDisplaySymbol() {
|
||||
return this.displaySymbol;
|
||||
}
|
||||
|
||||
public String getNameCode() {
|
||||
return this.nameCode;
|
||||
}
|
||||
|
||||
public String getDisplayLabel() {
|
||||
return this.displayLabel;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String toJSON() {
|
||||
return new Gson().toJson(this);
|
||||
}
|
||||
|
||||
public static CurrencyDomain fromJSON(final String jsonData) {
|
||||
return new Gson().fromJson(jsonData, CurrencyDomain.class);
|
||||
}
|
||||
|
||||
public static Builder create(final String code, final String name, final int decimalPlaces, final String displaySymbol,
|
||||
final String nameCode, final String displayLabel) {
|
||||
return new Builder(code, name, decimalPlaces, displaySymbol, nameCode, displayLabel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 1;
|
||||
|
||||
if (this.name != null) hash += this.name.hashCode();
|
||||
if (this.code != null) hash += this.code.hashCode();
|
||||
if (this.decimalPlaces >= 0) hash += this.decimalPlaces;
|
||||
if (this.displaySymbol != null) hash += this.displaySymbol.hashCode();
|
||||
if (this.nameCode != null) hash += this.nameCode.hashCode();
|
||||
if (this.displayLabel != null) hash += this.displayLabel.hashCode();
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this) { return true; }
|
||||
|
||||
if (!(obj instanceof CurrencyDomain)) return false;
|
||||
|
||||
CurrencyDomain cd = (CurrencyDomain) obj;
|
||||
|
||||
if (this.name.equals(cd.name) && this.code.equals(cd.code) && this.decimalPlaces == cd.decimalPlaces
|
||||
&& this.displaySymbol.equals(cd.displaySymbol) && this.nameCode.equals(cd.nameCode)
|
||||
&& this.displayLabel.equals(cd.displayLabel)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(CurrencyDomain cd) {
|
||||
return this.name.compareTo(cd.getName());
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
public class ExternalServicesConfigurationHelper {
|
||||
|
||||
private final RequestSpecification requestSpec;
|
||||
private final ResponseSpecification responseSpec;
|
||||
|
||||
public ExternalServicesConfigurationHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
this.requestSpec = requestSpec;
|
||||
this.responseSpec = responseSpec;
|
||||
}
|
||||
|
||||
public static ArrayList<HashMap> getExternalServicesConfigurationByServiceName(final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec, final String serviceName) {
|
||||
final String GET_EXTERNAL_SERVICES_CONFIG_BY_SERVICE_NAME_URL = "/fineract-provider/api/v1/externalservice/" + serviceName + "?"
|
||||
+ Utils.TENANT_IDENTIFIER;
|
||||
System.out.println("------------------------ RETRIEVING GLOBAL CONFIGURATION BY ID -------------------------");
|
||||
return Utils.performServerGet(requestSpec, responseSpec, GET_EXTERNAL_SERVICES_CONFIG_BY_SERVICE_NAME_URL, "");
|
||||
}
|
||||
|
||||
public static HashMap updateValueForExternaServicesConfiguration(final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec, final String serviceName, final String name, final String value) {
|
||||
final String EXTERNAL_SERVICES_CONFIG_UPDATE_URL = "/fineract-provider/api/v1/externalservice/" + serviceName + "?"
|
||||
+ Utils.TENANT_IDENTIFIER;
|
||||
System.out.println("---------------------------------UPDATE VALUE FOR GLOBAL CONFIG---------------------------------------------");
|
||||
HashMap map = Utils.performServerPut(requestSpec, responseSpec, EXTERNAL_SERVICES_CONFIG_UPDATE_URL,
|
||||
updateExternalServicesConfigUpdateValueAsJSON(name, value), "");
|
||||
|
||||
return (HashMap) map.get("changes");
|
||||
}
|
||||
|
||||
public static String updateExternalServicesConfigUpdateValueAsJSON(final String name, final String value) {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put(name, value);
|
||||
System.out.println("map : " + map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
}
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
@SuppressWarnings({ "unused", "rawtypes" })
|
||||
public class GlobalConfigurationHelper {
|
||||
|
||||
private final RequestSpecification requestSpec;
|
||||
private final ResponseSpecification responseSpec;
|
||||
|
||||
public GlobalConfigurationHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
this.requestSpec = requestSpec;
|
||||
this.responseSpec = responseSpec;
|
||||
}
|
||||
|
||||
public static ArrayList getAllGlobalConfigurations(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
final String GET_ALL_GLOBAL_CONFIG_URL = "/fineract-provider/api/v1/configurations?" + Utils.TENANT_IDENTIFIER;
|
||||
System.out.println("------------------------ RETRIEVING ALL GLOBAL CONFIGURATIONS -------------------------");
|
||||
final HashMap response = Utils.performServerGet(requestSpec, responseSpec, GET_ALL_GLOBAL_CONFIG_URL, "");
|
||||
return (ArrayList) response.get("globalConfiguration");
|
||||
}
|
||||
|
||||
public static HashMap getGlobalConfigurationById(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String configId) {
|
||||
final String GET_GLOBAL_CONFIG_BY_ID_URL = "/fineract-provider/api/v1/configurations/" + configId + "?" + Utils.TENANT_IDENTIFIER;
|
||||
System.out.println("------------------------ RETRIEVING GLOBAL CONFIGURATION BY ID -------------------------");
|
||||
return Utils.performServerGet(requestSpec, responseSpec, GET_GLOBAL_CONFIG_BY_ID_URL, "");
|
||||
}
|
||||
|
||||
public static Integer updateValueForGlobalConfiguration(final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec, final String configId, final String value) {
|
||||
final String GLOBAL_CONFIG_UPDATE_URL = "/fineract-provider/api/v1/configurations/" + configId + "?" + Utils.TENANT_IDENTIFIER;
|
||||
System.out.println("---------------------------------UPDATE VALUE FOR GLOBAL CONFIG---------------------------------------------");
|
||||
return Utils.performServerPut(requestSpec, responseSpec, GLOBAL_CONFIG_UPDATE_URL, updateGlobalConfigUpdateValueAsJSON(value),
|
||||
"resourceId");
|
||||
}
|
||||
|
||||
public static Integer updateEnabledFlagForGlobalConfiguration(final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec, final String configId, final Boolean enabled) {
|
||||
final String GLOBAL_CONFIG_UPDATE_URL = "/fineract-provider/api/v1/configurations/" + configId + "?" + Utils.TENANT_IDENTIFIER;
|
||||
System.out
|
||||
.println("---------------------------------UPDATE GLOBAL CONFIG FOR ENABLED FLAG---------------------------------------------");
|
||||
return Utils.performServerPut(requestSpec, responseSpec, GLOBAL_CONFIG_UPDATE_URL,
|
||||
updateGlobalConfigUpdateEnabledFlagAsJSON(enabled), "resourceId");
|
||||
}
|
||||
|
||||
public static ArrayList getGlobalConfigurationIsCacheEnabled(final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec) {
|
||||
final String GET_IS_CACHE_GLOBAL_CONFIG_URL = "/fineract-provider/api/v1/caches?" + Utils.TENANT_IDENTIFIER;
|
||||
System.out.println("------------------------ RETRIEVING IS CACHE ENABLED GLOBAL CONFIGURATION -------------------------");
|
||||
final ArrayList<HashMap> response = Utils.performServerGet(requestSpec, responseSpec, GET_IS_CACHE_GLOBAL_CONFIG_URL, "");
|
||||
return response;
|
||||
}
|
||||
|
||||
public static HashMap updateIsCacheEnabledForGlobalConfiguration(final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec, final String cacheType) {
|
||||
final String IS_CACHE_GLOBAL_CONFIG_UPDATE_URL = "/fineract-provider/api/v1/caches?" + Utils.TENANT_IDENTIFIER;
|
||||
System.out.println("------------------UPDATE GLOBAL CONFIG FOR IS CACHE ENABLED----------------------");
|
||||
return Utils.performServerPut(requestSpec, responseSpec, IS_CACHE_GLOBAL_CONFIG_UPDATE_URL,
|
||||
updateIsCacheEnabledGlobalConfigUpdateAsJSON(cacheType), "changes");
|
||||
}
|
||||
|
||||
public static Object updatePasswordResetDaysForGlobalConfiguration(final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec, final Integer configId, final String value, final String enabled, final String jsonAttributeToGetBack) {
|
||||
final String UPDATE_URL = "/fineract-provider/api/v1/configurations/" + configId + "?" + Utils.TENANT_IDENTIFIER;
|
||||
System.out.println("------------------UPDATE GLOBAL CONFIG FOR FORCE PASSWORD RESET DAYS----------------------");
|
||||
return Utils.performServerPut(requestSpec, responseSpec, UPDATE_URL,
|
||||
updatePasswordResetDaysGlobalConfigAsJSON(value, enabled), jsonAttributeToGetBack);
|
||||
}
|
||||
|
||||
public static String updateGlobalConfigUpdateValueAsJSON(final String value) {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("value", value);
|
||||
System.out.println("map : " + map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static String updatePasswordResetDaysGlobalConfigAsJSON(final String value, final String enabled) {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
if(value != null){
|
||||
map.put("value", value);
|
||||
}
|
||||
map.put("enabled", enabled);
|
||||
System.out.println("map : " + map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static String updateGlobalConfigUpdateEnabledFlagAsJSON(final Boolean enabled) {
|
||||
final HashMap<String, Boolean> map = new HashMap<String, Boolean>();
|
||||
map.put("enabled", enabled);
|
||||
System.out.println("map : " + map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static String updateIsCacheEnabledGlobalConfigUpdateAsJSON(final String cacheType) {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("cacheType", cacheType);
|
||||
System.out.println("map : " + map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
}
|
||||
+230
@@ -0,0 +1,230 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
public class GroupHelper {
|
||||
|
||||
private static final String CREATE_GROUP_URL = "/fineract-provider/api/v1/groups?" + Utils.TENANT_IDENTIFIER;
|
||||
|
||||
public static Integer createGroup(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
@SuppressWarnings("unused") final boolean active) {
|
||||
System.out.println("---------------------------------CREATING A GROUP---------------------------------------------");
|
||||
return createGroup(requestSpec, responseSpec, "04 March 2011");
|
||||
}
|
||||
|
||||
public static Integer createGroup(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String activationDate) {
|
||||
System.out.println("---------------------------------CREATING A GROUP---------------------------------------------");
|
||||
return Utils.performServerPost(requestSpec, responseSpec, CREATE_GROUP_URL, getTestGroupAsJSON(true, activationDate), "groupId");
|
||||
}
|
||||
|
||||
public static Integer createGroup(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
System.out.println("---------------------------------CREATING A GROUP---------------------------------------------");
|
||||
return Utils.performServerPost(requestSpec, responseSpec, CREATE_GROUP_URL, getTestGroupAsJSON(false, ""), "groupId");
|
||||
}
|
||||
|
||||
public static Integer associateClient(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String groupId, final String clientMember) {
|
||||
final String GROUP_ASSOCIATE_URL = "/fineract-provider/api/v1/groups/" + groupId
|
||||
+ "?command=associateClients&" + Utils.TENANT_IDENTIFIER;
|
||||
System.out.println("---------------------------------Associate Client To A GROUP---------------------------------------------");
|
||||
return Utils.performServerPost(requestSpec, responseSpec, GROUP_ASSOCIATE_URL, associateClientAsJSON(clientMember), "groupId");
|
||||
}
|
||||
|
||||
public static Integer disAssociateClient(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String groupId, final String clientMember) {
|
||||
final String GROUP_ASSOCIATE_URL = "/fineract-provider/api/v1/groups/" + groupId
|
||||
+ "?command=disassociateClients&" + Utils.TENANT_IDENTIFIER;
|
||||
System.out.println("---------------------------------Disassociate Client To A GROUP---------------------------------------------");
|
||||
return Utils.performServerPost(requestSpec, responseSpec, GROUP_ASSOCIATE_URL, associateClientAsJSON(clientMember), "groupId");
|
||||
}
|
||||
|
||||
public static Integer activateGroup(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String groupId) {
|
||||
final String GROUP_ASSOCIATE_URL = "/fineract-provider/api/v1/groups/" + groupId + "?command=activate&" + Utils.TENANT_IDENTIFIER;
|
||||
System.out.println("---------------------------------Activate A GROUP---------------------------------------------");
|
||||
return Utils.performServerPost(requestSpec, responseSpec, GROUP_ASSOCIATE_URL, activateGroupAsJSON(""), "groupId");
|
||||
}
|
||||
|
||||
public static Integer updateGroup(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, final String name,
|
||||
final String groupId) {
|
||||
final String GROUP_ASSOCIATE_URL = "/fineract-provider/api/v1/groups/" + groupId + "?" + Utils.TENANT_IDENTIFIER;
|
||||
System.out.println("---------------------------------UPDATE GROUP---------------------------------------------");
|
||||
return Utils.performServerPut(requestSpec, responseSpec, GROUP_ASSOCIATE_URL, updateGroupAsJSON(name), "groupId");
|
||||
}
|
||||
|
||||
public static Integer deleteGroup(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, final String groupId) {
|
||||
final String GROUP_ASSOCIATE_URL = "/fineract-provider/api/v1/groups/" + groupId + "?" + Utils.TENANT_IDENTIFIER;
|
||||
System.out.println("---------------------------------DELETE GROUP---------------------------------------------");
|
||||
return Utils.performServerDelete(requestSpec, responseSpec, GROUP_ASSOCIATE_URL, "groupId");
|
||||
}
|
||||
|
||||
|
||||
public static Object assignStaff(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, final String groupId,final Long staffId){
|
||||
final String GROUP_ASSIGN_STAFF_URL = "/fineract-provider/api/v1/groups/" + groupId + "?" + Utils.TENANT_IDENTIFIER + "&command=assignStaff";
|
||||
System.out.println("---------------------------------DELETE GROUP---------------------------------------------");
|
||||
return Utils.performServerPost(requestSpec, responseSpec, GROUP_ASSIGN_STAFF_URL,assignStaffAsJSON(staffId),"changes");
|
||||
}
|
||||
public static Object assignStaffInheritStaffForClientAccounts(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, final String groupId,final String staffId){
|
||||
final String GROUP_ASSIGN_STAFF_URL = "/fineract-provider/api/v1/groups/" + groupId + "?" + Utils.TENANT_IDENTIFIER + "&command=assignStaff";
|
||||
System.out.println("---------------------------------DELETE GROUP---------------------------------------------");
|
||||
return Utils.performServerPost(requestSpec, responseSpec, GROUP_ASSIGN_STAFF_URL,assignStaffAndInheritStaffForClientAccountsAsJSON(staffId),"changes");
|
||||
}
|
||||
|
||||
|
||||
public static String getTestGroupAsJSON(final boolean active, final String activationDate) {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("officeId", "1");
|
||||
map.put("name", randomNameGenerator("Group_Name_", 5));
|
||||
map.put("externalId", randomIDGenerator("ID_", 7));
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("locale", "en");
|
||||
if (active) {
|
||||
map.put("active", "true");
|
||||
map.put("activationDate", activationDate);
|
||||
} else {
|
||||
map.put("active", "false");
|
||||
map.put("submittedOnDate", "04 March 2011");
|
||||
System.out.println("defaulting to inactive group: 04 March 2011");
|
||||
}
|
||||
|
||||
System.out.println("map : " + map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static String associateClientAsJSON(final String clientMember) {
|
||||
final HashMap<String, List<String>> map = new HashMap<String, List<String>>();
|
||||
final List<String> list = new ArrayList<>();
|
||||
list.add(clientMember);
|
||||
map.put("clientMembers", list);
|
||||
System.out.println("map : " + map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static String activateGroupAsJSON(final String activationDate) {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("locale", "en");
|
||||
if (StringUtils.isNotEmpty(activationDate)) {
|
||||
map.put("activationDate", activationDate);
|
||||
} else {
|
||||
map.put("activationDate", "04 March 2011");
|
||||
System.out.println("defaulting to fixed date: 04 March 2011");
|
||||
}
|
||||
System.out.println("map : " + map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static String updateGroupAsJSON(final String name) {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("name", name);
|
||||
System.out.println("map : " + map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
public static String assignStaffAsJSON(final Long staffId) {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("staffId", staffId);
|
||||
System.out.println("map : " + map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
public static String assignStaffAndInheritStaffForClientAccountsAsJSON(final String staffId) {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("staffId", staffId);
|
||||
map.put("inheritStaffForClientAccounts","true");
|
||||
System.out.println("map : " + map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
|
||||
public static void verifyGroupCreatedOnServer(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer generatedGroupID) {
|
||||
System.out.println("------------------------------CHECK GROUP DETAILS------------------------------------\n");
|
||||
final String GROUP_URL = "/fineract-provider/api/v1/groups/" + generatedGroupID + "?" + Utils.TENANT_IDENTIFIER;
|
||||
final Integer responseGroupID = Utils.performServerGet(requestSpec, responseSpec, GROUP_URL, "id");
|
||||
assertEquals("ERROR IN CREATING THE GROUP", generatedGroupID, responseGroupID);
|
||||
}
|
||||
|
||||
public static void verifyGroupDetails(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer generatedGroupID, final String field, final String expectedValue) {
|
||||
System.out.println("------------------------------CHECK GROUP DETAILS------------------------------------\n");
|
||||
final String GROUP_URL = "/fineract-provider/api/v1/groups/" + generatedGroupID + "?" + Utils.TENANT_IDENTIFIER;
|
||||
final String responseValue = Utils.performServerGet(requestSpec, responseSpec, GROUP_URL, field);
|
||||
assertEquals("ERROR IN CREATING THE GROUP", expectedValue, responseValue);
|
||||
}
|
||||
|
||||
public static void verifyGroupActivatedOnServer(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer generatedGroupID, final boolean generatedGroupStatus) {
|
||||
System.out.println("------------------------------CHECK GROUP STATUS------------------------------------\n");
|
||||
final String GROUP_URL = "/fineract-provider/api/v1/groups/" + generatedGroupID + "?" + Utils.TENANT_IDENTIFIER;
|
||||
final Boolean responseGroupStatus = Utils.performServerGet(requestSpec, responseSpec, GROUP_URL, "active");
|
||||
assertEquals("ERROR IN ACTIVATING THE GROUP", generatedGroupStatus, responseGroupStatus);
|
||||
}
|
||||
|
||||
public static void verifyGroupMembers(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer generatedGroupID, final Integer groupMember) {
|
||||
List<String> list = new ArrayList<>();
|
||||
System.out.println("------------------------------CHECK GROUP MEMBERS------------------------------------\n");
|
||||
final String GROUP_URL = "/fineract-provider/api/v1/groups/" + generatedGroupID
|
||||
+ "?associations=clientMembers&" + Utils.TENANT_IDENTIFIER;
|
||||
list = Utils.performServerGet(requestSpec, responseSpec, GROUP_URL, "clientMembers");
|
||||
assertTrue("ERROR IN GROUP MEMBER", list.toString().contains("id=" + groupMember.toString()));
|
||||
}
|
||||
|
||||
public static void verifyEmptyGroupMembers(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer generatedGroupID) {
|
||||
List<String> list = new ArrayList<>();
|
||||
System.out.println("------------------------------CHECK EMPTY GROUP MEMBER LIST------------------------------------\n");
|
||||
final String GROUP_URL = "/fineract-provider/api/v1/groups/" + generatedGroupID
|
||||
+ "?associations=clientMembers&" + Utils.TENANT_IDENTIFIER;
|
||||
list = Utils.performServerGet(requestSpec, responseSpec, GROUP_URL, "clientMembers");
|
||||
assertEquals("GROUP MEMBER LIST NOT EMPTY", list, null);
|
||||
}
|
||||
|
||||
public static void verifyGroupDeleted(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer generatedGroupID) {
|
||||
List<String> list = new ArrayList<>();
|
||||
System.out.println("------------------------------CHECK GROUP DELETED------------------------------------\n");
|
||||
final String GROUP_URL = "/fineract-provider/api/v1/groups/?" + Utils.TENANT_IDENTIFIER;
|
||||
list = Utils.performServerGet(requestSpec, responseSpec, GROUP_URL, "pageItems");
|
||||
|
||||
assertFalse("GROUP NOT DELETED", list.toString().contains("id=" + generatedGroupID.toString()));
|
||||
}
|
||||
|
||||
public static String randomNameGenerator(final String prefix, final int lenOfRandomSuffix) {
|
||||
return Utils.randomStringGenerator(prefix, lenOfRandomSuffix);
|
||||
}
|
||||
|
||||
private static String randomIDGenerator(final String prefix, final int lenOfRandomSuffix) {
|
||||
return Utils.randomStringGenerator(prefix, lenOfRandomSuffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
}
|
||||
}
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.jayway.restassured.specification.RequestSender;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
@SuppressWarnings({ "unused", "rawtypes" })
|
||||
public class HolidayHelper {
|
||||
|
||||
private static final String HOLIDAYS_URL = "/fineract-provider/api/v1/holidays";
|
||||
private static final String CREATE_HOLIDAY_URL = HOLIDAYS_URL + "?" + Utils.TENANT_IDENTIFIER;
|
||||
|
||||
private static final String OFFICE_ID = "1";
|
||||
|
||||
private final RequestSpecification requestSpec;
|
||||
private final ResponseSpecification responseSpec;
|
||||
|
||||
public HolidayHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
this.requestSpec = requestSpec;
|
||||
this.responseSpec = responseSpec;
|
||||
}
|
||||
|
||||
public static String getCreateHolidayDataAsJSON() {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
List<HashMap<String, String>> offices = new ArrayList<HashMap<String, String>>();
|
||||
HashMap<String, String> officeMap = new HashMap<>();
|
||||
officeMap.put("officeId", OFFICE_ID);
|
||||
offices.add(officeMap);
|
||||
|
||||
map.put("offices", offices);
|
||||
map.put("locale", "en");
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("name", Utils.randomNameGenerator("HOLIDAY_", 5));
|
||||
map.put("fromDate", "01 April 2013");
|
||||
map.put("toDate", "01 April 2013");
|
||||
map.put("repaymentsRescheduledTo", "08 April 2013");
|
||||
|
||||
String HolidayCreateJson = new Gson().toJson(map);
|
||||
System.out.println(HolidayCreateJson);
|
||||
return HolidayCreateJson;
|
||||
}
|
||||
|
||||
public static String getActivateHolidayDataAsJSON() {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
String activateHoliday = new Gson().toJson(map);
|
||||
System.out.println(activateHoliday);
|
||||
return activateHoliday;
|
||||
}
|
||||
|
||||
public static Integer createHolidays(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
return Utils.performServerPost(requestSpec, responseSpec, CREATE_HOLIDAY_URL, getCreateHolidayDataAsJSON(), "resourceId");
|
||||
}
|
||||
|
||||
public static Integer activateHolidays(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, final String holidayID) {
|
||||
final String ACTIVATE_HOLIDAY_URL = HOLIDAYS_URL + "/" + holidayID + "?command=activate&" + Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerPost(requestSpec, responseSpec, ACTIVATE_HOLIDAY_URL, getActivateHolidayDataAsJSON(), "resourceId");
|
||||
}
|
||||
|
||||
public static HashMap getHolidayById(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String holidayID) {
|
||||
final String GET_HOLIDAY_BY_ID_URL = HOLIDAYS_URL + "/" + holidayID + "?" + Utils.TENANT_IDENTIFIER;
|
||||
System.out.println("------------------------ RETRIEVING HOLIDAY BY ID -------------------------");
|
||||
final HashMap response = Utils.performServerGet(requestSpec, responseSpec, GET_HOLIDAY_BY_ID_URL, "");
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.jayway.restassured.builder.ResponseSpecBuilder;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
public class HookHelper {
|
||||
|
||||
private final RequestSpecification requestSpec;
|
||||
private final ResponseSpecification responseSpec;
|
||||
|
||||
private static final String CREATE_HOOK_URL = "/fineract-provider/api/v1/hooks?" + Utils.TENANT_IDENTIFIER;
|
||||
|
||||
public HookHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
this.requestSpec = requestSpec;
|
||||
this.responseSpec = responseSpec;
|
||||
}
|
||||
|
||||
public Integer createHook(final String payloadURL) {
|
||||
System.out.println("---------------------------------CREATING A HOOK---------------------------------------------");
|
||||
return Utils.performServerPost(requestSpec, responseSpec, CREATE_HOOK_URL, getTestHookAsJson(payloadURL),
|
||||
"resourceId");
|
||||
}
|
||||
|
||||
public String getTestHookAsJson(final String payloadURL) {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("name", "Web");
|
||||
map.put("displayName", Utils.randomNameGenerator("Hook_DisplayName_", 5));
|
||||
map.put("isActive", "true");
|
||||
final HashMap<String, String> config = new HashMap<>();
|
||||
config.put("Content Type", "json");
|
||||
config.put("Payload URL", payloadURL);
|
||||
map.put("config", config);
|
||||
final ArrayList<HashMap<String, String>> events = new ArrayList<>();
|
||||
final HashMap<String, String> createOfficeEvent = new HashMap<>();
|
||||
createOfficeEvent.put("actionName", "CREATE");
|
||||
createOfficeEvent.put("entityName", "OFFICE");
|
||||
events.add(createOfficeEvent);
|
||||
map.put("events", events);
|
||||
System.out.println("map : " + map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public Integer updateHook(final String payloadURL, final Long hookId) {
|
||||
System.out.println("---------------------------------UPDATING HOOK---------------------------------------------");
|
||||
final String UPDATE_HOOK_URL = "/fineract-provider/api/v1/hooks/" + hookId + "?" + Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerPut(this.requestSpec, this.responseSpec, UPDATE_HOOK_URL, getTestHookAsJson(payloadURL), "resourceId");
|
||||
}
|
||||
|
||||
public Integer deleteHook(final Long hookId) {
|
||||
System.out.println("---------------------------------DELETING HOOK---------------------------------------------");
|
||||
final String DELETE_HOOK_URL = "/fineract-provider/api/v1/hooks/" + hookId + "?" + Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerDelete(this.requestSpec, this.responseSpec, DELETE_HOOK_URL, "resourceId");
|
||||
}
|
||||
|
||||
public void verifyHookCreatedOnServer(final Long hookId) {
|
||||
System.out.println("------------------------------CHECK CREATE HOOK DETAILS------------------------------------\n");
|
||||
final String GET_URL = "/fineract-provider/api/v1/hooks/" + hookId + "?" + Utils.TENANT_IDENTIFIER;
|
||||
final Integer responseHookId = Utils.performServerGet(this.requestSpec, this.responseSpec, GET_URL, "id");
|
||||
assertEquals(hookId.toString(), responseHookId.toString());
|
||||
}
|
||||
|
||||
public void verifyUpdateHook(final String updateURL, final Long hookId) {
|
||||
System.out.println("------------------------------CHECK UPDATE HOOK DETAILS------------------------------------\n");
|
||||
final String GET_URL = "/fineract-provider/api/v1/hooks/" + hookId + "?" + Utils.TENANT_IDENTIFIER;
|
||||
ArrayList map = Utils.performServerGet(this.requestSpec, this.responseSpec, GET_URL, "config");
|
||||
HashMap<String, String> hash = (HashMap<String, String>) map.get(1);
|
||||
assertEquals(updateURL, hash.get("fieldValue"));
|
||||
}
|
||||
|
||||
public void verifyDeleteHook(final Long hookId) {
|
||||
System.out.println("------------------------------CHECK DELETE HOOK DETAILS------------------------------------\n");
|
||||
final String GET_URL = "/fineract-provider/api/v1/hooks/" + hookId + "?" + Utils.TENANT_IDENTIFIER;
|
||||
ResponseSpecification responseSpec404 = new ResponseSpecBuilder().expectStatusCode(404).build();
|
||||
ArrayList array = Utils.performServerGet(this.requestSpec, responseSpec404, GET_URL, "errors");
|
||||
HashMap<String, String> map = (HashMap<String, String>)array.get(0);
|
||||
assertEquals("error.msg.hook.identifier.not.found",map.get("userMessageGlobalisationCode"));
|
||||
}
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common;
|
||||
|
||||
import org.apache.http.HttpHeaders;
|
||||
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
public class ImageHelper {
|
||||
|
||||
private static final String STAFF_IMAGE_URL = "/fineract-provider/api/v1/staff/";
|
||||
private static final String IMAGES_URI = "/images";
|
||||
|
||||
public static Integer createImageForStaff(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
Integer staffId) {
|
||||
System.out.println("---------------------------------CREATING AN IMAGE FOR STAFF---------------------------------------------");
|
||||
String URL = STAFF_IMAGE_URL + staffId + IMAGES_URI + "?" + Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerPost(requestSpec, responseSpec, URL, generateImageAsText(), "resourceId");
|
||||
}
|
||||
|
||||
public static Integer updateImageForStaff(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
Integer staffId) {
|
||||
System.out.println("---------------------------------UPDATING AN IMAGE FOR STAFF---------------------------------------------");
|
||||
String URL = STAFF_IMAGE_URL + staffId + IMAGES_URI + "?" + Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerPut(requestSpec, responseSpec, URL, generateImageAsText(), "resourceId");
|
||||
}
|
||||
|
||||
public static String getStaffImageAsText(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
Integer staffId) {
|
||||
System.out.println("---------------------------------RETRIEVING STAFF IMAGE---------------------------------------------");
|
||||
String URL = STAFF_IMAGE_URL + staffId + IMAGES_URI + "?" + Utils.TENANT_IDENTIFIER;
|
||||
requestSpec.header(HttpHeaders.ACCEPT, "text/plain");
|
||||
return Utils.performGetTextResponse(requestSpec, responseSpec, URL);
|
||||
}
|
||||
|
||||
public static byte[] getStaffImageAsBinary(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
Integer staffId) {
|
||||
System.out.println("---------------------------------RETRIEVING STAFF IMAGE---------------------------------------------");
|
||||
String URL = STAFF_IMAGE_URL + staffId + IMAGES_URI + "?" + Utils.TENANT_IDENTIFIER;
|
||||
requestSpec.header(HttpHeaders.ACCEPT, "application/octet-stream");
|
||||
return Utils.performGetBinaryResponse(requestSpec, responseSpec, URL);
|
||||
}
|
||||
|
||||
public static Integer deleteStaffImage(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, Integer staffId) {
|
||||
System.out.println("---------------------------------RETRIEVING STAFF IMAGE---------------------------------------------");
|
||||
String URL = STAFF_IMAGE_URL + staffId + IMAGES_URI + "?" + Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerDelete(requestSpec, responseSpec, URL, "resourceId");
|
||||
}
|
||||
|
||||
private static String generateImageAsText() {
|
||||
return "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJ\n"
|
||||
+ "bWFnZVJlYWR5ccllPAAAAJ1JREFUeNpi+P//PwMIA4E9EG8E4idQDGLbw+WhiiqA+D8OXAFVAzbp\n"
|
||||
+ "DxBvB2JLIGaGYkuoGEjOhhFIHAbij0BdPgxYACMj42ogJQpifwBiXSDeC8JIbt4LxSC5DyxQjTeB\n"
|
||||
+ "+BeaYb+Q5EBOAVutCzMJHUNNPADzzDokiYdAfAmJvwLkGeTgWQfyKZICS6hYBTwc0QL8ORSjBDhA\n" + "gAEAOg13B6R/SAgAAAAASUVORK5CYII=";
|
||||
}
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
public class LoanRescheduleRequestHelper {
|
||||
private final RequestSpecification requestSpec;
|
||||
private final ResponseSpecification responseSpec;
|
||||
|
||||
private static final String LOAN_RESCHEDULE_REQUEST_URL = "/fineract-provider/api/v1/rescheduleloans";
|
||||
|
||||
public LoanRescheduleRequestHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
this.requestSpec = requestSpec;
|
||||
this.responseSpec = responseSpec;
|
||||
}
|
||||
|
||||
public Integer createLoanRescheduleRequest(final String requestJSON) {
|
||||
final String URL = LOAN_RESCHEDULE_REQUEST_URL + "?" + Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerPost(this.requestSpec, this.responseSpec, URL, requestJSON, "resourceId");
|
||||
}
|
||||
|
||||
public Integer rejectLoanRescheduleRequest(final Integer requestId, final String requestJSON) {
|
||||
final String URL = LOAN_RESCHEDULE_REQUEST_URL + "/" + requestId + "?" + Utils.TENANT_IDENTIFIER + "&command=reject";
|
||||
|
||||
return Utils.performServerPost(this.requestSpec, this.responseSpec, URL, requestJSON, "resourceId");
|
||||
}
|
||||
|
||||
public Integer approveLoanRescheduleRequest(final Integer requestId, final String requestJSON) {
|
||||
final String URL = LOAN_RESCHEDULE_REQUEST_URL + "/" + requestId + "?" + Utils.TENANT_IDENTIFIER + "&command=approve";
|
||||
|
||||
return Utils.performServerPost(this.requestSpec, this.responseSpec, URL, requestJSON, "resourceId");
|
||||
}
|
||||
|
||||
public Object getLoanRescheduleRequest(final Integer requestId, final String param) {
|
||||
final String URL = LOAN_RESCHEDULE_REQUEST_URL + "/" + requestId + "?" + Utils.TENANT_IDENTIFIER;
|
||||
|
||||
return Utils.performServerGet(requestSpec, responseSpec, URL, param);
|
||||
}
|
||||
|
||||
public void verifyCreationOfLoanRescheduleRequest(final Integer requestId) {
|
||||
final String URL = LOAN_RESCHEDULE_REQUEST_URL + "/" + requestId + "?" + Utils.TENANT_IDENTIFIER;
|
||||
|
||||
final Integer id = Utils.performServerGet(requestSpec, responseSpec, URL, "id");
|
||||
assertEquals("ERROR IN CREATING LOAN RESCHEDULE REQUEST", requestId, id);
|
||||
}
|
||||
}
|
||||
+153
@@ -0,0 +1,153 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
public class OfficeDomain {
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
private String nameDecorated;
|
||||
private String externalId;
|
||||
private String[] openingDate;
|
||||
private String hierarchy;
|
||||
|
||||
private Builder(final int id, final String name,
|
||||
final String nameDecorated, final String externalId,
|
||||
final String[] openingDate, final String hierarchy) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.nameDecorated = nameDecorated;
|
||||
this.externalId = externalId;
|
||||
this.openingDate = openingDate;
|
||||
this.hierarchy = hierarchy;
|
||||
}
|
||||
|
||||
public OfficeDomain build() {
|
||||
return new OfficeDomain(this.id, this.name, this.nameDecorated,
|
||||
this.externalId, this.openingDate, this.hierarchy);
|
||||
}
|
||||
}
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
private String nameDecorated;
|
||||
private String externalId;
|
||||
private String[] openingDate;
|
||||
private String hierarchy;
|
||||
|
||||
OfficeDomain() {
|
||||
super();
|
||||
}
|
||||
|
||||
private OfficeDomain(final int id, final String name,
|
||||
final String nameDecorated, final String externalId,
|
||||
final String[] openingDate, final String hierarchy) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.nameDecorated = nameDecorated;
|
||||
this.externalId = externalId;
|
||||
this.openingDate = openingDate;
|
||||
this.hierarchy = hierarchy;
|
||||
}
|
||||
|
||||
public String toJSON() {
|
||||
return new Gson().toJson(this);
|
||||
}
|
||||
|
||||
public static OfficeDomain fromJSON(final String jsonData) {
|
||||
return new Gson().fromJson(jsonData, OfficeDomain.class);
|
||||
}
|
||||
|
||||
public static Builder create(final int id, final String name,
|
||||
final String nameDecorated, final String externalId,
|
||||
final String[] openingDate, final String hierarchy) {
|
||||
return new Builder(id, name, nameDecorated, externalId, openingDate,
|
||||
hierarchy);
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getNameDecorated() {
|
||||
return this.nameDecorated;
|
||||
}
|
||||
|
||||
public String getExternalId() {
|
||||
return this.externalId;
|
||||
}
|
||||
|
||||
public String[] getOpeningDate() {
|
||||
return this.openingDate;
|
||||
}
|
||||
|
||||
public String getHierarchy() {
|
||||
return this.hierarchy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 1;
|
||||
|
||||
if (this.id > 0)
|
||||
hash += this.id;
|
||||
if (this.name != null)
|
||||
hash += this.name.hashCode();
|
||||
if (this.nameDecorated != null)
|
||||
hash += this.nameDecorated.hashCode();
|
||||
if (this.externalId != null)
|
||||
hash += this.externalId.hashCode();
|
||||
if (this.openingDate != null)
|
||||
hash += this.openingDate.hashCode();
|
||||
if (this.hierarchy != null)
|
||||
hash += this.hierarchy.hashCode();
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(obj instanceof OfficeDomain))
|
||||
return false;
|
||||
|
||||
OfficeDomain od = (OfficeDomain) obj;
|
||||
|
||||
if (this.id == od.getId() && this.name.equals(od.getName())
|
||||
&& this.nameDecorated.equals(od.getName())
|
||||
&& this.externalId.equals(od.getExternalId())
|
||||
&& this.openingDate.equals(od.getOpeningDate())
|
||||
&& this.hierarchy.equals(od.getHierarchy()))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.gson.Gson;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
public class OfficeHelper {
|
||||
|
||||
private static final String OFFICE_URL = "/fineract-provider/api/v1/offices";
|
||||
private final RequestSpecification requestSpec;
|
||||
private final ResponseSpecification responseSpec;
|
||||
|
||||
public OfficeHelper(final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec) {
|
||||
this.requestSpec = requestSpec;
|
||||
this.responseSpec = responseSpec;
|
||||
}
|
||||
|
||||
public OfficeDomain retrieveOfficeByID(int id) {
|
||||
final String json = new Gson().toJson(Utils.performServerGet(
|
||||
requestSpec, responseSpec, OFFICE_URL + "/" + id + "?"
|
||||
+ Utils.TENANT_IDENTIFIER, ""));
|
||||
return new Gson().fromJson(json, new TypeToken<OfficeDomain>() {
|
||||
}.getType());
|
||||
}
|
||||
|
||||
public Integer createOffice(final String openingDate) {
|
||||
String json = getAsJSON(openingDate);
|
||||
return Utils.performServerPost(this.requestSpec, this.responseSpec,
|
||||
OFFICE_URL + "?" + Utils.TENANT_IDENTIFIER, json,
|
||||
CommonConstants.RESPONSE_RESOURCE_ID);
|
||||
}
|
||||
|
||||
public Integer updateOffice(int id, String name, String openingDate) {
|
||||
final HashMap map = new HashMap<>();
|
||||
map.put("name", name);
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("locale", "en");
|
||||
map.put("openingDate", openingDate);
|
||||
|
||||
System.out.println("map : " + map);
|
||||
|
||||
return Utils.performServerPut(requestSpec, responseSpec, OFFICE_URL
|
||||
+ "/" + id + "?" + Utils.TENANT_IDENTIFIER,
|
||||
new Gson().toJson(map), "resourceId");
|
||||
}
|
||||
|
||||
public static String getAsJSON(final String openingDate) {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("parentId", "1");
|
||||
map.put("name", Utils.randomNameGenerator("Office_", 4));
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("locale", "en");
|
||||
map.put("openingDate", openingDate);
|
||||
System.out.println("map : " + map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
public class PasswordPreferencesHelper {
|
||||
|
||||
private static final String PASSWORD_PREFERENCES_URL = "/fineract-provider/api/v1/passwordpreferences";
|
||||
|
||||
public static Object updatePasswordPreferences(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
String validationPolicyId) {
|
||||
final String UPDATE_PASSWORD_PREFERENCES_URL = PASSWORD_PREFERENCES_URL + "?" + Utils.TENANT_IDENTIFIER;
|
||||
System.out.println("---------------------------------UPDATE PASSWORD PREFERENCE---------------------------------------------");
|
||||
return Utils.performServerPut(requestSpec, responseSpec, UPDATE_PASSWORD_PREFERENCES_URL, updatePreferencesAsJson(validationPolicyId), "");
|
||||
}
|
||||
|
||||
public static Object updateWithInvalidValidationPolicyId(final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec,String invalidValidationPolicyId, String jsonAttributeToGetback) {
|
||||
final String UPDATE_PASSWORD_PREFERENCES_URL = PASSWORD_PREFERENCES_URL + "?" + Utils.TENANT_IDENTIFIER;
|
||||
System.out
|
||||
.println("---------------------------------UPDATE PASSWORD PREFERENCES WITH INVALID ID-----------------------------------------");
|
||||
return Utils.performServerPut(requestSpec, responseSpec, UPDATE_PASSWORD_PREFERENCES_URL, updatePreferencesWithInvalidId(invalidValidationPolicyId),
|
||||
jsonAttributeToGetback);
|
||||
}
|
||||
|
||||
public static String updatePreferencesAsJson(String validationPolicyId) {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("validationPolicyId", validationPolicyId);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static String updatePreferencesWithInvalidId(String invalidValidationPolicyId) {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("validationPolicyId", invalidValidationPolicyId);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
|
||||
public static int getActivePasswordPreference(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
return Utils.performServerGet(requestSpec, responseSpec, PASSWORD_PREFERENCES_URL + "?" + Utils.TENANT_IDENTIFIER, "id");
|
||||
}
|
||||
|
||||
public static HashMap<String, Object> getAllPreferences(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
|
||||
return Utils.performServerGet(requestSpec, responseSpec, PASSWORD_PREFERENCES_URL + "/template" + "?" + Utils.TENANT_IDENTIFIER, "");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common;
|
||||
|
||||
public class PaymentTypeDomain {
|
||||
|
||||
private Integer id;
|
||||
private String name;
|
||||
private String description;
|
||||
private Boolean isCashPayment;
|
||||
private Integer position;
|
||||
|
||||
private PaymentTypeDomain(final Integer id, final String name, final String description, final Boolean isCashPayment,
|
||||
final Integer position) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.isCashPayment = isCashPayment;
|
||||
this.position = position;
|
||||
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public Boolean getIsCashPayment() {
|
||||
return this.isCashPayment;
|
||||
}
|
||||
|
||||
public void setIsCashPayment(Boolean isCashPayment) {
|
||||
this.isCashPayment = isCashPayment;
|
||||
}
|
||||
|
||||
public Integer getPosition() {
|
||||
return this.position;
|
||||
}
|
||||
|
||||
public void setPosition(Integer position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
}
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.gson.Gson;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public class PaymentTypeHelper {
|
||||
|
||||
private static final String CREATE_PAYMENTTYPE_URL = "/fineract-provider/api/v1/paymenttypes?" + Utils.TENANT_IDENTIFIER;
|
||||
private static final String PAYMENTTYPE_URL = "/fineract-provider/api/v1/paymenttypes";
|
||||
|
||||
public static Integer createPaymentType(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String name, final String description, final Boolean isCashPayment, final Integer position) {
|
||||
System.out.println("---------------------------------CREATING A PAYMENT TYPE---------------------------------------------");
|
||||
return Utils.performServerPost(requestSpec, responseSpec, CREATE_PAYMENTTYPE_URL,
|
||||
getJsonToCreatePaymentType(name, description, isCashPayment, position), "resourceId");
|
||||
}
|
||||
|
||||
public static String getJsonToCreatePaymentType(final String name, final String description, final Boolean isCashPayment,
|
||||
final Integer position) {
|
||||
HashMap hm = new HashMap();
|
||||
hm.put("name", name);
|
||||
if (description != null) hm.put("description", description);
|
||||
hm.put("isCashPayment", isCashPayment);
|
||||
if (position != null) hm.put("position", position);
|
||||
|
||||
System.out.println("------------------------CREATING PAYMENT TYPE-------------------------" + hm);
|
||||
return new Gson().toJson(hm);
|
||||
}
|
||||
|
||||
public static void verifyPaymentTypeCreatedOnServer(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer generatedPaymentTypeID) {
|
||||
System.out.println("------------------------------CHECK PAYMENT DETAILS------------------------------------\n");
|
||||
final String GET_PAYMENTTYPE_URL = PAYMENTTYPE_URL + "/" + generatedPaymentTypeID + "?" + Utils.TENANT_IDENTIFIER;
|
||||
final Integer responsePaymentTypeID = Utils.performServerGet(requestSpec, responseSpec, GET_PAYMENTTYPE_URL, "id");
|
||||
assertEquals("ERROR IN CREATING THE PAYMENT TYPE", generatedPaymentTypeID, responsePaymentTypeID);
|
||||
}
|
||||
|
||||
public static PaymentTypeDomain retrieveById(RequestSpecification requestSpec, ResponseSpecification responseSpec,
|
||||
final Integer paymentTypeId) {
|
||||
final String GET_PAYMENTTYPE_URL = PAYMENTTYPE_URL + "/" + paymentTypeId + "?" + Utils.TENANT_IDENTIFIER;
|
||||
System.out.println("---------------------------------GET PAYMENT TYPE---------------------------------------------");
|
||||
final String jsonData = new Gson().toJson(Utils.performServerGet(requestSpec, responseSpec, GET_PAYMENTTYPE_URL, ""));
|
||||
return new Gson().fromJson(jsonData, new TypeToken<PaymentTypeDomain>() {}.getType());
|
||||
|
||||
}
|
||||
|
||||
public static HashMap<String, String> updatePaymentType(final int id, HashMap request, final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec) {
|
||||
final String UPDATE_PAYMENTTYPE_URL = PAYMENTTYPE_URL + "/" + id + "?" + Utils.TENANT_IDENTIFIER;
|
||||
System.out.println("---------------------------------UPDATE PAYMENT TYPE " + id + "---------------------------------------------");
|
||||
HashMap<String, String> hash = Utils.performServerPut(requestSpec, responseSpec, UPDATE_PAYMENTTYPE_URL,
|
||||
new Gson().toJson(request), "changes");
|
||||
return hash;
|
||||
}
|
||||
|
||||
public static Integer deletePaymentType(final int id, final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
final String DELETE_PAYMENTTYPE_URL = PAYMENTTYPE_URL + "/" + id + "?" + Utils.TENANT_IDENTIFIER;
|
||||
System.out.println("---------------------------------DELETING PAYMENT TYPE " + id + "--------------------------------------------");
|
||||
return Utils.performServerDelete(requestSpec, responseSpec, DELETE_PAYMENTTYPE_URL, "resourceId");
|
||||
}
|
||||
|
||||
public static String randomNameGenerator(final String prefix, final int lenOfRandomSuffix) {
|
||||
return Utils.randomStringGenerator(prefix, lenOfRandomSuffix);
|
||||
}
|
||||
|
||||
}
|
||||
+241
@@ -0,0 +1,241 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.accounting.Account;
|
||||
import org.apache.fineract.integrationtests.common.accounting.AccountHelper;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanStatusChecker;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
|
||||
import org.apache.fineract.integrationtests.common.provisioning.ProvisioningHelper;
|
||||
import org.apache.fineract.integrationtests.common.provisioning.ProvisioningTransactionHelper;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Assume;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
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;
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public class ProvisioningIntegrationTest {
|
||||
|
||||
private static final String NONE = "1";
|
||||
private final static int LOANPRODUCTS_SIZE = 10;
|
||||
|
||||
private RequestSpecification requestSpec;
|
||||
private ResponseSpecification responseSpec;
|
||||
private AccountHelper accountHelper;
|
||||
private LoanTransactionHelper loanTransactionHelper;
|
||||
|
||||
@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.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
|
||||
this.accountHelper = new AccountHelper(this.requestSpec, this.responseSpec);
|
||||
Assume.assumeTrue(!isAlreadyProvisioningEntriesCreated());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateProvisioningCriteria() {
|
||||
ProvisioningTransactionHelper transactionHelper = new ProvisioningTransactionHelper(requestSpec, responseSpec);
|
||||
ArrayList<Integer> loanProducts = new ArrayList<>(LOANPRODUCTS_SIZE);
|
||||
List<Integer> loans = new ArrayList<>();
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
ClientHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, clientID);
|
||||
for (int i = 0; i < LOANPRODUCTS_SIZE; i++) {
|
||||
final Integer loanProductID = createLoanProduct(false, NONE);
|
||||
loanProducts.add(loanProductID);
|
||||
Assert.assertNotNull(loanProductID);
|
||||
final Integer loanID = applyForLoanApplication(clientID, loanProductID, null, null, "1,00,000.00");
|
||||
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
|
||||
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
|
||||
loanStatusHashMap = this.loanTransactionHelper.approveLoan("20 September 2011", loanID);
|
||||
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
|
||||
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
|
||||
System.out.println("-------------------------------DISBURSE LOAN-------------------------------------------");
|
||||
loanStatusHashMap = this.loanTransactionHelper.disburseLoan("20 September 2011", loanID);
|
||||
LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
|
||||
loans.add(loanID);
|
||||
Assert.assertNotNull(loanID);
|
||||
}
|
||||
|
||||
ArrayList categories = transactionHelper.retrieveAllProvisioningCategories();
|
||||
Assert.assertTrue(categories.size() > 0) ;
|
||||
Account liability = accountHelper.createLiabilityAccount() ;
|
||||
Account expense = accountHelper.createExpenseAccount() ;
|
||||
Map requestCriteria = ProvisioningHelper.createProvisioingCriteriaJson(loanProducts, categories, liability, expense);
|
||||
String provisioningCriteriaCreateJson = new Gson().toJson(requestCriteria);
|
||||
Integer criteriaId = transactionHelper.createProvisioningCriteria(provisioningCriteriaCreateJson);
|
||||
Assert.assertNotNull(criteriaId);
|
||||
|
||||
Map newCriteria = transactionHelper.retrieveProvisioningCriteria(criteriaId) ;
|
||||
validateProvisioningCriteria(requestCriteria, newCriteria) ;
|
||||
|
||||
ArrayList definitions = (ArrayList)newCriteria.get("definitions") ;
|
||||
for(int i = 0 ; i < definitions.size(); i++) {
|
||||
Map criteriadefinition = (Map) definitions.get(i) ;
|
||||
criteriadefinition.put("provisioningPercentage", new Float(20.0)) ;
|
||||
}
|
||||
newCriteria.put("locale", "en");
|
||||
String updateCriteriaString = new Gson().toJson(newCriteria) ;
|
||||
Integer criteriaId1 = transactionHelper.updateProvisioningCriteria(criteriaId, updateCriteriaString) ;
|
||||
Map updatedCriteria = transactionHelper.retrieveProvisioningCriteria(criteriaId1) ;
|
||||
validateProvisioningCriteria(newCriteria, updatedCriteria) ;
|
||||
|
||||
transactionHelper.deleteProvisioningCriteria(criteriaId1) ;
|
||||
|
||||
categories = transactionHelper.retrieveAllProvisioningCategories();
|
||||
liability = accountHelper.createLiabilityAccount() ;
|
||||
expense = accountHelper.createExpenseAccount() ;
|
||||
requestCriteria = ProvisioningHelper.createProvisioingCriteriaJson(loanProducts, categories, liability, expense);
|
||||
provisioningCriteriaCreateJson = new Gson().toJson(requestCriteria);
|
||||
criteriaId = transactionHelper.createProvisioningCriteria(provisioningCriteriaCreateJson);
|
||||
Assert.assertNotNull(criteriaId);
|
||||
|
||||
String provisioningEntryJson = ProvisioningHelper.createProvisioningEntryJson();
|
||||
Integer provisioningEntryId = transactionHelper.createProvisioningEntries(provisioningEntryJson);
|
||||
Assert.assertNotNull(provisioningEntryId);
|
||||
|
||||
transactionHelper.updateProvisioningEntry("recreateprovisioningentry", provisioningEntryId, "") ;
|
||||
transactionHelper.updateProvisioningEntry("createjournalentry", provisioningEntryId, "") ;
|
||||
Map entry = transactionHelper.retrieveProvisioningEntry(provisioningEntryId) ;
|
||||
Assert.assertTrue((Boolean)entry.get("journalEntry")) ;
|
||||
Map provisioningEntry = transactionHelper.retrieveProvisioningEntries(provisioningEntryId) ;
|
||||
Assert.assertTrue(((ArrayList)provisioningEntry.get("pageItems")).size() > 0) ;
|
||||
}
|
||||
|
||||
private void validateProvisioningCriteria(Map requestCriteria, Map newCriteria) {
|
||||
|
||||
//criteria name validation
|
||||
String requestCriteriaName = (String)requestCriteria.get("criteriaName") ;
|
||||
String criteriaName = (String)newCriteria.get("criteriaName") ;
|
||||
Assert.assertEquals(criteriaName, requestCriteriaName) ;
|
||||
|
||||
//loan products validation
|
||||
ArrayList requestProducts = (ArrayList)requestCriteria.get("loanProducts") ;
|
||||
ArrayList products = (ArrayList)newCriteria.get("loanProducts") ;
|
||||
Assert.assertEquals(products.size(), requestProducts.size()) ;
|
||||
|
||||
ArrayList requestedDefinitions = (ArrayList)requestCriteria.get("definitions") ;
|
||||
ArrayList newdefintions = (ArrayList) newCriteria.get("definitions") ;
|
||||
Assert.assertEquals(newdefintions.size(), requestedDefinitions.size()) ;
|
||||
for(int i = 0 ; i < newdefintions.size() ; i++) {
|
||||
Map requestedMap = (Map)requestedDefinitions.get(i) ;
|
||||
Map newMap = (Map)newdefintions.get(i) ;
|
||||
checkProperty("categoryId", requestedMap, newMap) ;
|
||||
checkProperty("categoryName", requestedMap, newMap) ;
|
||||
checkProperty("minAge", requestedMap, newMap) ;
|
||||
checkProperty("maxAge", requestedMap, newMap) ;
|
||||
checkProperty("provisioningPercentage", requestedMap, newMap) ;
|
||||
checkProperty("liabilityAccount", requestedMap, newMap) ;
|
||||
checkProperty("expenseAccount", requestedMap, newMap) ;
|
||||
}
|
||||
}
|
||||
|
||||
private void checkProperty(String propertyName, Map requestMap, Map newMap) {
|
||||
Object requested = requestMap.get(propertyName) ;
|
||||
Object modified = newMap.get(propertyName) ;
|
||||
Assert.assertEquals(requested, modified) ;
|
||||
}
|
||||
|
||||
private Integer createLoanProduct(final boolean multiDisburseLoan, final String accountingRule, final Account... accounts) {
|
||||
System.out.println("------------------------------CREATING NEW LOAN PRODUCT ---------------------------------------");
|
||||
LoanProductTestBuilder builder = new LoanProductTestBuilder() //
|
||||
.withPrincipal("1,00,000.00") //
|
||||
.withNumberOfRepayments("4") //
|
||||
.withRepaymentAfterEvery("1") //
|
||||
.withRepaymentTypeAsMonth() //
|
||||
.withinterestRatePerPeriod("1") //
|
||||
.withInterestRateFrequencyTypeAsMonths() //
|
||||
.withAmortizationTypeAsEqualInstallments() //
|
||||
.withInterestTypeAsDecliningBalance() //
|
||||
.withTranches(multiDisburseLoan) //
|
||||
.withAccounting(accountingRule, accounts);
|
||||
if (multiDisburseLoan) {
|
||||
builder = builder.withInterestCalculationPeriodTypeAsRepaymentPeriod(true);
|
||||
}
|
||||
final String loanProductJSON = builder.build(null);
|
||||
|
||||
return this.loanTransactionHelper.getLoanProductId(loanProductJSON);
|
||||
}
|
||||
|
||||
private Integer applyForLoanApplication(final Integer clientID, final Integer loanProductID, List<HashMap> charges,
|
||||
final String savingsId, String principal) {
|
||||
System.out.println("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------");
|
||||
final String loanApplicationJSON = new LoanApplicationTestBuilder() //
|
||||
.withPrincipal(principal) //
|
||||
.withLoanTermFrequency("4") //
|
||||
.withLoanTermFrequencyAsMonths() //
|
||||
.withNumberOfRepayments("4") //
|
||||
.withRepaymentEveryAfter("1") //
|
||||
.withRepaymentFrequencyTypeAsMonths() //
|
||||
.withInterestRatePerPeriod("2") //
|
||||
.withAmortizationTypeAsEqualInstallments() //
|
||||
.withInterestTypeAsDecliningBalance() //
|
||||
.withInterestCalculationPeriodTypeSameAsRepaymentPeriod() //
|
||||
.withExpectedDisbursementDate("20 September 2011") //
|
||||
.withSubmittedOnDate("20 September 2011") //
|
||||
.withCharges(charges).build(clientID.toString(), loanProductID.toString(), savingsId);
|
||||
return this.loanTransactionHelper.getLoanId(loanApplicationJSON);
|
||||
}
|
||||
|
||||
private boolean isAlreadyProvisioningEntriesCreated() {
|
||||
ProvisioningTransactionHelper transactionHelper = new ProvisioningTransactionHelper(requestSpec, responseSpec);
|
||||
Map entries = transactionHelper.retrieveAllProvisioningEntries() ;
|
||||
ArrayList<Map> pageItems = (ArrayList)entries.get("pageItems") ;
|
||||
boolean provisioningetryAlreadyCreated = false ;
|
||||
if(pageItems != null) {
|
||||
for(Map item: pageItems) {
|
||||
String date = (String)item.get("createdDate") ;
|
||||
DateFormat formatter = new SimpleDateFormat("MMM dd, yyyy");
|
||||
try {
|
||||
Date date1 = formatter.parse(date) ;
|
||||
DateFormat simple = new SimpleDateFormat("dd MMMM yyyy");
|
||||
String formattedString = simple.format(Utils.getLocalDateOfTenant().toDate());
|
||||
Date currentDate = simple.parse(formattedString) ;
|
||||
if(date1.getTime() == currentDate.getTime()) {
|
||||
provisioningetryAlreadyCreated = true ;
|
||||
break ;
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return provisioningetryAlreadyCreated ;
|
||||
}
|
||||
}
|
||||
+148
@@ -0,0 +1,148 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.jayway.restassured.builder.ResponseSpecBuilder;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public class SchedulerJobHelper {
|
||||
|
||||
private final RequestSpecification requestSpec;
|
||||
private final ResponseSpecification responseSpec;
|
||||
|
||||
public SchedulerJobHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
this.requestSpec = requestSpec;
|
||||
this.responseSpec = responseSpec;
|
||||
}
|
||||
|
||||
public static ArrayList getAllSchedulerJobs(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
final String GET_ALL_SCHEDULER_JOBS_URL = "/fineract-provider/api/v1/jobs?" + Utils.TENANT_IDENTIFIER;
|
||||
System.out.println("------------------------ RETRIEVING ALL SCHEDULER JOBS -------------------------");
|
||||
final ArrayList response = Utils.performServerGet(requestSpec, responseSpec, GET_ALL_SCHEDULER_JOBS_URL, "");
|
||||
return response;
|
||||
}
|
||||
|
||||
public static HashMap getSchedulerJobById(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String jobId) {
|
||||
final String GET_SCHEDULER_JOB_BY_ID_URL = "/fineract-provider/api/v1/jobs/" + jobId + "?" + Utils.TENANT_IDENTIFIER;
|
||||
System.out.println("------------------------ RETRIEVING SCHEDULER JOB BY ID -------------------------");
|
||||
final HashMap response = Utils.performServerGet(requestSpec, responseSpec, GET_SCHEDULER_JOB_BY_ID_URL, "");
|
||||
return response;
|
||||
}
|
||||
|
||||
public static HashMap getSchedulerStatus(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
final String GET_SCHEDULER_STATUS_URL = "/fineract-provider/api/v1/scheduler?" + Utils.TENANT_IDENTIFIER;
|
||||
System.out.println("------------------------ RETRIEVING SCHEDULER STATUS -------------------------");
|
||||
final HashMap response = Utils.performServerGet(requestSpec, responseSpec, GET_SCHEDULER_STATUS_URL, "");
|
||||
return response;
|
||||
}
|
||||
|
||||
public static void updateSchedulerStatus(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String command) {
|
||||
final String UPDATE_SCHEDULER_STATUS_URL = "/fineract-provider/api/v1/scheduler?command=" + command + "&" + Utils.TENANT_IDENTIFIER;
|
||||
System.out.println("------------------------ UPDATING SCHEDULER STATUS -------------------------");
|
||||
Utils.performServerPost(requestSpec, responseSpec, UPDATE_SCHEDULER_STATUS_URL, runSchedulerJobAsJSON(), null);
|
||||
}
|
||||
|
||||
public static HashMap updateSchedulerJob(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String jobId, final String active) {
|
||||
final String UPDATE_SCHEDULER_JOB_URL = "/fineract-provider/api/v1/jobs/" + jobId + "?" + Utils.TENANT_IDENTIFIER;
|
||||
System.out.println("------------------------ UPDATING SCHEDULER JOB -------------------------");
|
||||
final HashMap response = Utils.performServerPut(requestSpec, responseSpec, UPDATE_SCHEDULER_JOB_URL,
|
||||
updateSchedulerJobAsJSON(active), "changes");
|
||||
return response;
|
||||
}
|
||||
|
||||
public static String updateSchedulerJobAsJSON(final String active) {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("active", active);
|
||||
System.out.println("map : " + map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static ArrayList getSchedulerJobHistory(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String jobId) {
|
||||
final String GET_SCHEDULER_STATUS_URL = "/fineract-provider/api/v1/jobs/" + jobId + "/runhistory?" + Utils.TENANT_IDENTIFIER;
|
||||
System.out.println("------------------------ RETRIEVING SCHEDULER JOB HISTORY -------------------------");
|
||||
final HashMap response = Utils.performServerGet(requestSpec, responseSpec, GET_SCHEDULER_STATUS_URL, "");
|
||||
return (ArrayList) response.get("pageItems");
|
||||
}
|
||||
|
||||
public static void runSchedulerJob(final RequestSpecification requestSpec, final String jobId) {
|
||||
final ResponseSpecification responseSpec = new ResponseSpecBuilder().expectStatusCode(202).build();
|
||||
final String RUN_SCHEDULER_JOB_URL = "/fineract-provider/api/v1/jobs/" + jobId + "?command=executeJob&" + Utils.TENANT_IDENTIFIER;
|
||||
System.out.println("------------------------ RUN SCHEDULER JOB -------------------------");
|
||||
Utils.performServerPost(requestSpec, responseSpec, RUN_SCHEDULER_JOB_URL, runSchedulerJobAsJSON(), null);
|
||||
}
|
||||
|
||||
public static String runSchedulerJobAsJSON() {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
String runSchedulerJob = new Gson().toJson(map);
|
||||
System.out.println(runSchedulerJob);
|
||||
return runSchedulerJob;
|
||||
}
|
||||
|
||||
public void executeJob(String JobName) throws InterruptedException {
|
||||
ArrayList<HashMap> allSchedulerJobsData = getAllSchedulerJobs(this.requestSpec, this.responseSpec);
|
||||
Assert.assertNotNull(allSchedulerJobsData);
|
||||
|
||||
for (Integer jobIndex = 0; jobIndex < allSchedulerJobsData.size(); jobIndex++) {
|
||||
if (allSchedulerJobsData.get(jobIndex).get("displayName").equals(JobName)) {
|
||||
Integer jobId = (Integer) allSchedulerJobsData.get(jobIndex).get("jobId");
|
||||
|
||||
// Executing Scheduler Job
|
||||
runSchedulerJob(this.requestSpec, jobId.toString());
|
||||
|
||||
// Retrieving Scheduler Job by ID
|
||||
HashMap schedulerJob = getSchedulerJobById(this.requestSpec, this.responseSpec, jobId.toString());
|
||||
Assert.assertNotNull(schedulerJob);
|
||||
|
||||
// Waiting for Job to complete
|
||||
while ((Boolean) schedulerJob.get("currentlyRunning") == true) {
|
||||
Thread.sleep(15000);
|
||||
schedulerJob = getSchedulerJobById(this.requestSpec, this.responseSpec, jobId.toString());
|
||||
Assert.assertNotNull(schedulerJob);
|
||||
System.out.println("Job is Still Running");
|
||||
}
|
||||
|
||||
ArrayList<HashMap> jobHistoryData = getSchedulerJobHistory(this.requestSpec, this.responseSpec, jobId.toString());
|
||||
|
||||
// print error associated with recent job failure (if any)
|
||||
System.out.println("Job run error message (printed only if the job fails: "
|
||||
+ jobHistoryData.get(jobHistoryData.size() - 1).get("jobRunErrorMessage"));
|
||||
System.out.println("Job failure error log (printed only if the job fails: "
|
||||
+ jobHistoryData.get(jobHistoryData.size() - 1).get("jobRunErrorLog"));
|
||||
|
||||
// Verifying the Status of the Recently executed Scheduler Job
|
||||
Assert.assertEquals("Verifying Last Scheduler Job Status", "success",
|
||||
jobHistoryData.get(jobHistoryData.size() - 1).get("status"));
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
|
||||
import ch.qos.logback.classic.pattern.Util;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
@SuppressWarnings({ "unused", "rawtypes", "unchecked" })
|
||||
public class StandingInstructionsHelper {
|
||||
|
||||
private static final String STANDING_INSTRUCTIONS_URL = "/fineract-provider/api/v1/standinginstructions";
|
||||
private static final String STANDING_INSTRUCTIONS_RUNHISTORY_URL = "/fineract-provider/api/v1/standinginstructionrunhistory";
|
||||
private static final String LOCALE = "en_GB";
|
||||
private static final String OFFICE_ID = "1";
|
||||
private static final String INSTRUCTION_TYPE_FIXED = "1";
|
||||
private static final String INSTRUCTION_TYPE_DUES = "2";
|
||||
private static final String PRIORITY_URGENT = "1";
|
||||
private static final String PRIORITY_HIGH = "2";
|
||||
private static final String PRIORITY_MEDIUM = "3";
|
||||
private static final String PRIORITY_LOW = "4";
|
||||
private static final String RECURRENCE_FREQUENCY_DAYS = "0";
|
||||
private static final String RECURRENCE_FREQUENCY_WEEKS = "1";
|
||||
private static final String RECURRENCE_FREQUENCY_MONTHS = "2";
|
||||
private static final String RECURRENCE_FREQUENCY_YEARS = "3";
|
||||
private static final String RECURRENCE_TYPE_PERIODIC = "1";
|
||||
private static final String RECURRENCE_TYPE_AS_PER_DUES = "2";
|
||||
private static final String STATUS_ACTIVE = "1";
|
||||
private static final String STATUS_DISABLED = "2";
|
||||
private static final String TRANSFER_TYPE_ACCOUNT_TRANSFER = "1";
|
||||
private static final String TRANSFER_TYPE_LOAN_REPAYMENT = "2";
|
||||
private static final String ACCOUNT_TRANSFER_DATE = "01 March 2013";
|
||||
|
||||
private String transferDate = "";
|
||||
private String officeId = OFFICE_ID;
|
||||
|
||||
private RequestSpecification requestSpec;
|
||||
private ResponseSpecification responseSpec;
|
||||
|
||||
public StandingInstructionsHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
this.requestSpec = requestSpec;
|
||||
this.responseSpec = responseSpec;
|
||||
}
|
||||
|
||||
public String build(final String clientId, final String fromAccountId, final String toAccountId, final String fromAccountType,
|
||||
final String toAccountType, final String validFrom, final String validTo, final String monthDay) {
|
||||
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("name", Utils.randomNameGenerator("STANDING_INSTRUCTION_", 5));
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("monthDayFormat", "dd MMMM");
|
||||
map.put("locale", LOCALE);
|
||||
map.put("fromClientId", clientId);
|
||||
map.put("fromAccountId", fromAccountId);
|
||||
map.put("fromAccountType", fromAccountType);
|
||||
map.put("fromOfficeId", this.officeId);
|
||||
map.put("toClientId", clientId);
|
||||
map.put("toAccountId", toAccountId);
|
||||
map.put("toAccountType", toAccountType);
|
||||
map.put("toOfficeId", this.officeId);
|
||||
map.put("amount", "500");
|
||||
map.put("transferType", TRANSFER_TYPE_ACCOUNT_TRANSFER);
|
||||
map.put("priority", PRIORITY_URGENT);
|
||||
map.put("status", STATUS_ACTIVE);
|
||||
map.put("instructionType", INSTRUCTION_TYPE_FIXED);
|
||||
map.put("validFrom", validFrom);
|
||||
map.put("validTill", validTo);
|
||||
map.put("recurrenceType", RECURRENCE_TYPE_PERIODIC);
|
||||
map.put("recurrenceInterval", "1");
|
||||
map.put("recurrenceFrequency", RECURRENCE_FREQUENCY_WEEKS);
|
||||
map.put("recurrenceOnMonthDay", monthDay);
|
||||
String savingsApplicationJSON = new Gson().toJson(map);
|
||||
System.out.println(savingsApplicationJSON);
|
||||
return savingsApplicationJSON;
|
||||
}
|
||||
|
||||
public Integer createStandingInstruction(final String clientId, final String fromAccountId, final String toAccountId,
|
||||
final String fromAccountType, final String toAccountType, final String validFrom, final String validTo, final String monthDay) {
|
||||
System.out.println("-------------------------------- CREATE STANDING INSTRUCTIONS --------------------------------");
|
||||
final String standingInstructionAsJSON = new StandingInstructionsHelper(this.requestSpec, this.responseSpec) //
|
||||
.build(clientId.toString(), fromAccountId.toString(), toAccountId.toString(), fromAccountType, toAccountType, validFrom,
|
||||
validTo, monthDay);
|
||||
return Utils.performServerPost(this.requestSpec, this.responseSpec, STANDING_INSTRUCTIONS_URL + "?" + Utils.TENANT_IDENTIFIER,
|
||||
standingInstructionAsJSON, "resourceId");
|
||||
}
|
||||
|
||||
public HashMap getStandingInstructionById(final String standingInstructionId) {
|
||||
|
||||
System.out.println("----------------------------- RETRIEVING STANDING INSTRUCTION BY ID---------------------------");
|
||||
final String GET_STANDING_INSTRUCTION_BY_ID_URL = STANDING_INSTRUCTIONS_URL + "/" + standingInstructionId + "?"
|
||||
+ Utils.TENANT_IDENTIFIER;
|
||||
final HashMap response = Utils.performServerGet(this.requestSpec, this.responseSpec, GET_STANDING_INSTRUCTION_BY_ID_URL, "");
|
||||
return response;
|
||||
}
|
||||
|
||||
public List<HashMap> getStandingInstructionHistory(Integer fromSavingsId, Integer fromAccountType, Integer fromClientId, Integer transferType) {
|
||||
final String STANDING_INSTRUCTIONS_HISTORY_URL = STANDING_INSTRUCTIONS_RUNHISTORY_URL + "?" + Utils.TENANT_IDENTIFIER
|
||||
+ "&fromSavingsId=" + fromSavingsId + "&fromAccountType=" + fromAccountType + "&clientId=" + fromClientId
|
||||
+ "&transferType=" + transferType;
|
||||
System.out.println("STANDING_INSTRUCTIONS_HISTORY_URL="+STANDING_INSTRUCTIONS_HISTORY_URL);
|
||||
final List<HashMap> response = (List<HashMap>) Utils.performServerGet(this.requestSpec, this.responseSpec,
|
||||
STANDING_INSTRUCTIONS_HISTORY_URL, "pageItems");
|
||||
return response;
|
||||
}
|
||||
}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class SurveyHelper {
|
||||
|
||||
private static final String FULFIL_SURVEY_URL = "/fineract-provider/api/v1/survey/ppi_kenya_2009/clientId?" + Utils.TENANT_IDENTIFIER;
|
||||
|
||||
public static Integer fulfilSurvey(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
return fulfilSurvey(requestSpec, responseSpec, "04 March 2011");
|
||||
}
|
||||
|
||||
public static Integer fulfilSurvey(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String activationDate) {
|
||||
System.out.println("---------------------------------FULFIL PPI ---------------------------------------------");
|
||||
return Utils.performServerPost(requestSpec, responseSpec,FULFIL_SURVEY_URL, getTestPPIAsJSON(), "clientId");
|
||||
}
|
||||
|
||||
public static String getTestPPIAsJSON() {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
|
||||
map.put("date", "2014-05-19 00:00:00");
|
||||
map.put("ppi_household_members_cd_q1_householdmembers","107");
|
||||
map.put("ppi_highestschool_cd_q2_highestschool","112");
|
||||
map.put("ppi_businessoccupation_cd_q3_businessoccupation","116");
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("locale", "en");
|
||||
map.put("ppi_habitablerooms_cd_q4_habitablerooms", "120");
|
||||
|
||||
map.put("ppi_floortype_cd_q5_floortype", "124");
|
||||
map.put("ppi_lightingsource_cd_q6_lightingsource", "126");
|
||||
map.put("ppi_irons_cd_q7_irons", "128");
|
||||
map.put("ppi_mosquitonets_cd_q8_mosquitonets", "132");
|
||||
map.put("ppi_towels_cd_q9_towels", "134");
|
||||
map.put("ppi_fryingpans_cd_q10_fryingpans", "138");
|
||||
|
||||
System.out.println("map : " + map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static void verifySurveyCreatedOnServer(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer generatedClientID) {
|
||||
System.out.println("------------------------------CHECK CLIENT DETAILS------------------------------------\n");
|
||||
final String SURVEY_URL = "/fineract-provider/api/v1/Survey/ppi_kenya_2009/clientid/entryId" + generatedClientID + "?" + Utils.TENANT_IDENTIFIER;
|
||||
final Integer responseClientID = Utils.performServerGet(requestSpec, responseSpec, SURVEY_URL, "id");
|
||||
assertEquals("ERROR IN CREATING THE CLIENT", generatedClientID, responseClientID);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+168
@@ -0,0 +1,168 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common;
|
||||
|
||||
import static com.jayway.restassured.RestAssured.given;
|
||||
import static com.jayway.restassured.path.json.JsonPath.from;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.http.conn.HttpHostConnectException;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.joda.time.LocalDate;
|
||||
|
||||
import com.jayway.restassured.RestAssured;
|
||||
import com.jayway.restassured.path.json.JsonPath;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
/**
|
||||
* Util for RestAssured tests. This class here in src/integrationTest is
|
||||
* copy/pasted to src/test; please keep them in sync.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class Utils {
|
||||
|
||||
public static final String TENANT_IDENTIFIER = "tenantIdentifier=default";
|
||||
|
||||
public static final String TENANT_TIME_ZONE = "Asia/Kolkata";
|
||||
|
||||
private static final String LOGIN_URL = "/fineract-provider/api/v1/authentication?username=mifos&password=password&" + TENANT_IDENTIFIER;
|
||||
|
||||
public static void initializeRESTAssured() {
|
||||
RestAssured.baseURI = "https://localhost";
|
||||
RestAssured.port = 8443;
|
||||
RestAssured.keystore("src/main/resources/keystore.jks", "openmf");
|
||||
}
|
||||
|
||||
public static String loginIntoServerAndGetBase64EncodedAuthenticationKey() {
|
||||
try {
|
||||
System.out.println("-----------------------------------LOGIN-----------------------------------------");
|
||||
final String json = RestAssured.post(LOGIN_URL).asString();
|
||||
assertThat("Failed to login into fineract platform", StringUtils.isBlank(json), is(false));
|
||||
return JsonPath.with(json).get("base64EncodedAuthenticationKey");
|
||||
} catch (final Exception e) {
|
||||
if (e instanceof HttpHostConnectException) {
|
||||
final HttpHostConnectException hh = (HttpHostConnectException) e;
|
||||
fail("Failed to connect to fineract platform:" + hh.getMessage());
|
||||
}
|
||||
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T performServerGet(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String getURL, final String jsonAttributeToGetBack) {
|
||||
final String json = given().spec(requestSpec).expect().spec(responseSpec).log().ifError().when().get(getURL).andReturn().asString();
|
||||
if (jsonAttributeToGetBack == null) { return (T) json; }
|
||||
return (T) from(json).get(jsonAttributeToGetBack);
|
||||
}
|
||||
|
||||
public static String performGetTextResponse(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String getURL){
|
||||
return given().spec(requestSpec).expect().spec(responseSpec).log().ifError().when().get(getURL).andReturn().asString();
|
||||
}
|
||||
|
||||
public static byte[] performGetBinaryResponse(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String getURL){
|
||||
return given().spec(requestSpec).expect().spec(responseSpec).log().ifError().when().get(getURL).andReturn().asByteArray();
|
||||
}
|
||||
|
||||
public static <T> T performServerPost(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String postURL, final String jsonBodyToSend, final String jsonAttributeToGetBack) {
|
||||
final String json = given().spec(requestSpec).body(jsonBodyToSend).expect().spec(responseSpec).log().ifError().when().post(postURL)
|
||||
.andReturn().asString();
|
||||
if (jsonAttributeToGetBack == null) { return (T) json; }
|
||||
return (T) from(json).get(jsonAttributeToGetBack);
|
||||
}
|
||||
|
||||
public static <T> T performServerPut(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String putURL, final String jsonBodyToSend, final String jsonAttributeToGetBack) {
|
||||
final String json = given().spec(requestSpec).body(jsonBodyToSend).expect().spec(responseSpec).log().ifError().when().put(putURL)
|
||||
.andReturn().asString();
|
||||
return (T) from(json).get(jsonAttributeToGetBack);
|
||||
}
|
||||
|
||||
public static <T> T performServerDelete(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String deleteURL, final String jsonAttributeToGetBack) {
|
||||
final String json = given().spec(requestSpec).expect().spec(responseSpec).log().ifError().when().delete(deleteURL).andReturn()
|
||||
.asString();
|
||||
return (T) from(json).get(jsonAttributeToGetBack);
|
||||
}
|
||||
|
||||
public static String convertDateToURLFormat(final String dateToBeConvert) {
|
||||
final SimpleDateFormat oldFormat = new SimpleDateFormat("dd MMMMMM yyyy", Locale.US);
|
||||
final SimpleDateFormat newFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
String reformattedStr = "";
|
||||
try {
|
||||
reformattedStr = newFormat.format(oldFormat.parse(dateToBeConvert));
|
||||
} catch (final ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return reformattedStr;
|
||||
}
|
||||
|
||||
public static String randomStringGenerator(final String prefix, final int len, final String sourceSetString) {
|
||||
final int lengthOfSource = sourceSetString.length();
|
||||
final Random rnd = new Random();
|
||||
final StringBuilder sb = new StringBuilder(len);
|
||||
for (int i = 0; i < len; i++) {
|
||||
sb.append((sourceSetString).charAt(rnd.nextInt(lengthOfSource)));
|
||||
}
|
||||
return (prefix + (sb.toString()));
|
||||
}
|
||||
|
||||
public static String randomStringGenerator(final String prefix, final int len) {
|
||||
return randomStringGenerator(prefix, len, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
}
|
||||
|
||||
public static String randomNameGenerator(final String prefix, final int lenOfRandomSuffix) {
|
||||
return randomStringGenerator(prefix, lenOfRandomSuffix);
|
||||
}
|
||||
|
||||
public static String convertDateToURLFormat(final Calendar dateToBeConvert) {
|
||||
DateFormat dateFormat = new SimpleDateFormat("dd MMMMMM yyyy");
|
||||
dateFormat.setTimeZone(Utils.getTimeZoneOfTenant());
|
||||
return dateFormat.format(dateToBeConvert.getTime());
|
||||
}
|
||||
|
||||
public static LocalDate getLocalDateOfTenant() {
|
||||
LocalDate today = new LocalDate();
|
||||
final DateTimeZone zone = DateTimeZone.forID(TENANT_TIME_ZONE);
|
||||
if (zone != null) {
|
||||
today = new LocalDate(zone);
|
||||
}
|
||||
return today;
|
||||
}
|
||||
|
||||
public static TimeZone getTimeZoneOfTenant() {
|
||||
return TimeZone.getTimeZone(TENANT_TIME_ZONE);
|
||||
}
|
||||
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
public class WorkingDaysHelper {
|
||||
|
||||
private static final String WORKINGDAYS_URL = "/fineract-provider/api/v1/workingdays";
|
||||
|
||||
public static Object updateWorkingDays(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
final String UPDATE_WORKINGDAYS_URL = WORKINGDAYS_URL + "?" + Utils.TENANT_IDENTIFIER;
|
||||
System.out.println("---------------------------------UPDATE WORKINGDAY---------------------------------------------");
|
||||
return Utils.performServerPut(requestSpec, responseSpec, UPDATE_WORKINGDAYS_URL, updateWorkingDaysAsJson(), "");
|
||||
}
|
||||
|
||||
public static Object updateWorkingDaysWithWrongRecurrence(final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec, String jsonAttributeToGetback) {
|
||||
final String UPDATE_WORKINGDAYS_URL = WORKINGDAYS_URL + "?" + Utils.TENANT_IDENTIFIER;
|
||||
System.out
|
||||
.println("---------------------------------UPDATE WORKINGDAY WITH WRONG RECURRENCE-----------------------------------------");
|
||||
return Utils.performServerPut(requestSpec, responseSpec, UPDATE_WORKINGDAYS_URL, updateWorkingDayWithWrongRecur(),
|
||||
jsonAttributeToGetback);
|
||||
}
|
||||
|
||||
public static String updateWorkingDaysAsJson() {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("recurrence", "FREQ=WEEKLY;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR,SA,SU");
|
||||
map.put("locale", "en");
|
||||
map.put("repaymentRescheduleType", randomInt(1, 4));
|
||||
map.put("extendTermForDailyRepayments", false);
|
||||
System.out.println("map : " + map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static String updateWorkingDayWithWrongRecur() {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("recurrence", "FREQ=WEEKLY;INTERVAL=1;BYDAY=MP,TI,TE,TH");
|
||||
map.put("locale", "en");
|
||||
map.put("repaymentRescheduleType", randomInt(1, 4));
|
||||
map.put("extendTermForDailyRepayments", false);
|
||||
System.out.println("map : " + map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static int randomInt(int low, int high) {
|
||||
int i = new Random().nextInt(high) + low;
|
||||
return i;
|
||||
}
|
||||
|
||||
public static int workingDaysId(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
HashMap<String, Object> workingDays = getAllWorkingDays(requestSpec, responseSpec);
|
||||
return (int) workingDays.get("id");
|
||||
}
|
||||
|
||||
public static HashMap<String, Object> getAllWorkingDays(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
|
||||
return Utils.performServerGet(requestSpec, responseSpec, WORKINGDAYS_URL + "?" + Utils.TENANT_IDENTIFIER, "");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common.accounting;
|
||||
|
||||
public class Account {
|
||||
|
||||
public enum AccountType {
|
||||
ASSET("1"), INCOME("4"), EXPENSE("5"), LIABILITY("2"), EQUITY("3");
|
||||
|
||||
private final String accountValue;
|
||||
|
||||
AccountType(final String accountValue) {
|
||||
this.accountValue = accountValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.accountValue;
|
||||
}
|
||||
}
|
||||
|
||||
private final AccountType accountType;
|
||||
private final Integer accountID;
|
||||
|
||||
public Account(final Integer accountID, final AccountType accountType) {
|
||||
this.accountID = accountID;
|
||||
this.accountType = accountType;
|
||||
}
|
||||
|
||||
public AccountType getAccountType() {
|
||||
return this.accountType;
|
||||
}
|
||||
|
||||
public Integer getAccountID() {
|
||||
return this.accountID;
|
||||
}
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common.accounting;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class AccountHelper {
|
||||
|
||||
private final String CREATE_GL_ACCOUNT_URL = "/fineract-provider/api/v1/glaccounts?" + Utils.TENANT_IDENTIFIER;
|
||||
private final String GL_ACCOUNT_ID_RESPONSE = "resourceId";
|
||||
|
||||
private final RequestSpecification requestSpec;
|
||||
private final ResponseSpecification responseSpec;
|
||||
|
||||
public AccountHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
this.requestSpec = requestSpec;
|
||||
this.responseSpec = responseSpec;
|
||||
}
|
||||
|
||||
public Account createAssetAccount() {
|
||||
final String assetAccountJSON = new GLAccountBuilder().withAccountTypeAsAsset().build();
|
||||
final Integer accountID = Utils.performServerPost(this.requestSpec, this.responseSpec, this.CREATE_GL_ACCOUNT_URL,
|
||||
assetAccountJSON, this.GL_ACCOUNT_ID_RESPONSE);
|
||||
return new Account(accountID, Account.AccountType.ASSET);
|
||||
}
|
||||
|
||||
public Account createIncomeAccount() {
|
||||
final String assetAccountJSON = new GLAccountBuilder().withAccountTypeAsIncome().build();
|
||||
final Integer accountID = Utils.performServerPost(this.requestSpec, this.responseSpec, this.CREATE_GL_ACCOUNT_URL,
|
||||
assetAccountJSON, this.GL_ACCOUNT_ID_RESPONSE);
|
||||
return new Account(accountID, Account.AccountType.INCOME);
|
||||
}
|
||||
|
||||
public Account createExpenseAccount() {
|
||||
final String assetAccountJSON = new GLAccountBuilder().withAccountTypeAsExpense().build();
|
||||
final Integer accountID = Utils.performServerPost(this.requestSpec, this.responseSpec, this.CREATE_GL_ACCOUNT_URL,
|
||||
assetAccountJSON, this.GL_ACCOUNT_ID_RESPONSE);
|
||||
return new Account(accountID, Account.AccountType.EXPENSE);
|
||||
}
|
||||
|
||||
public Account createLiabilityAccount() {
|
||||
final String liabilityAccountJSON = new GLAccountBuilder().withAccountTypeAsLiability().build();
|
||||
final Integer accountID = Utils.performServerPost(this.requestSpec, this.responseSpec, this.CREATE_GL_ACCOUNT_URL,
|
||||
liabilityAccountJSON, this.GL_ACCOUNT_ID_RESPONSE);
|
||||
return new Account(accountID, Account.AccountType.LIABILITY);
|
||||
}
|
||||
|
||||
public ArrayList getAccountingWithRunningBalances() {
|
||||
final String GET_RUNNING_BALANCE_URL = "/fineract-provider/api/v1/glaccounts?fetchRunningBalance=true";
|
||||
final ArrayList<HashMap> accountRunningBalance = Utils.performServerGet(this.requestSpec, this.responseSpec, GET_RUNNING_BALANCE_URL, "");
|
||||
return accountRunningBalance;
|
||||
}
|
||||
|
||||
public HashMap getAccountingWithRunningBalanceById(final String accountId) {
|
||||
final String GET_RUNNING_BALANCE_URL = "/fineract-provider/api/v1/glaccounts/" + accountId + "?fetchRunningBalance=true";
|
||||
final HashMap accountRunningBalance = Utils.performServerGet(this.requestSpec, this.responseSpec, GET_RUNNING_BALANCE_URL, "");
|
||||
return accountRunningBalance;
|
||||
}
|
||||
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common.accounting;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class FinancialActivityAccountHelper {
|
||||
|
||||
private static final String FINANCIAL_ACTIVITY_ACCOUNT_MAPPING_URL = "/fineract-provider/api/v1/financialactivityaccounts";
|
||||
private final RequestSpecification requestSpec;
|
||||
|
||||
public FinancialActivityAccountHelper(final RequestSpecification requestSpec) {
|
||||
this.requestSpec = requestSpec;
|
||||
}
|
||||
|
||||
public Object createFinancialActivityAccount(Integer financialActivityId, Integer glAccountId,
|
||||
final ResponseSpecification responseSpecification, String jsonBack) {
|
||||
String json = FinancialActivityAccountsMappingBuilder.build(financialActivityId, glAccountId);
|
||||
return Utils.performServerPost(this.requestSpec, responseSpecification, FINANCIAL_ACTIVITY_ACCOUNT_MAPPING_URL + "?"
|
||||
+ Utils.TENANT_IDENTIFIER, json, jsonBack);
|
||||
}
|
||||
|
||||
public Object updateFinancialActivityAccount(Integer financialActivityAccountId, Integer financialActivityId, Integer glAccountId,
|
||||
final ResponseSpecification responseSpecification, String jsonBack) {
|
||||
String json = FinancialActivityAccountsMappingBuilder.build(financialActivityId, glAccountId);
|
||||
return Utils.performServerPut(this.requestSpec, responseSpecification, FINANCIAL_ACTIVITY_ACCOUNT_MAPPING_URL + "/"
|
||||
+ financialActivityAccountId + "?" + Utils.TENANT_IDENTIFIER, json, jsonBack);
|
||||
}
|
||||
|
||||
public HashMap getFinancialActivityAccount(final Integer financialActivityAccountId, final ResponseSpecification responseSpecification) {
|
||||
final String url = FINANCIAL_ACTIVITY_ACCOUNT_MAPPING_URL + "/" + financialActivityAccountId + "?" + Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerGet(requestSpec, responseSpecification, url, "");
|
||||
}
|
||||
|
||||
public List<HashMap> getAllFinancialActivityAccounts(final ResponseSpecification responseSpecification) {
|
||||
final String url = FINANCIAL_ACTIVITY_ACCOUNT_MAPPING_URL + "?" + Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerGet(this.requestSpec, responseSpecification, url, "");
|
||||
}
|
||||
|
||||
public Integer deleteFinancialActivityAccount(final Integer financialActivityAccountId,
|
||||
final ResponseSpecification responseSpecification, String jsonBack) {
|
||||
final String url = FINANCIAL_ACTIVITY_ACCOUNT_MAPPING_URL + "/" + financialActivityAccountId + "?" + Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerDelete(this.requestSpec, responseSpecification, url, jsonBack);
|
||||
}
|
||||
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common.accounting;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
public class FinancialActivityAccountsMappingBuilder {
|
||||
|
||||
public static String build(Integer financialActivityId, Integer glAccountId) {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("financialActivityId", financialActivityId);
|
||||
map.put("glAccountId", glAccountId);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
}
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common.accounting;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
public class GLAccountBuilder {
|
||||
|
||||
public static final String ASSET_ACCOUNT = "1";
|
||||
public static final String LIABILITY_ACCOUNT = "2";
|
||||
public static final String EQUITY_ACCOUNT = "3";
|
||||
public static final String INCOME_ACCOUNT = "4";
|
||||
public static final String EXPENSE_ACCOUNT = "5";
|
||||
|
||||
private static final String ACCOUNT_USAGE_DETAIL = "1";
|
||||
private static final String ACCOUNT_USAGE_HEADER = "2";
|
||||
private static final String MANUAL_ENTRIES_ALLOW = "true";
|
||||
private static final String MANUAL_ENTRIES_NOT_ALLOW = "false";
|
||||
|
||||
private static String name = Utils.randomStringGenerator("ACCOUNT_NAME_", 5);
|
||||
|
||||
private static String GLCode = "";
|
||||
private static String accountType = "";
|
||||
private static String accountUsage = ACCOUNT_USAGE_DETAIL;
|
||||
private static String manualEntriesAllowed = MANUAL_ENTRIES_ALLOW;
|
||||
private static String description = "DEFAULT_DESCRIPTION";
|
||||
|
||||
public String build() {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("name", GLAccountBuilder.name);
|
||||
map.put("glCode", GLAccountBuilder.GLCode);
|
||||
map.put("manualEntriesAllowed", GLAccountBuilder.manualEntriesAllowed);
|
||||
map.put("type", GLAccountBuilder.accountType);
|
||||
map.put("usage", GLAccountBuilder.accountUsage);
|
||||
map.put("description", GLAccountBuilder.description);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public GLAccountBuilder withAccountTypeAsAsset() {
|
||||
GLAccountBuilder.accountType = ASSET_ACCOUNT;
|
||||
GLAccountBuilder.GLCode = Utils.randomStringGenerator("ASSET_", 2);
|
||||
GLAccountBuilder.GLCode += Calendar.getInstance().getTimeInMillis() + ""; // Added
|
||||
// unique
|
||||
// timestamp
|
||||
// for
|
||||
// avoiding
|
||||
// random
|
||||
// collisions
|
||||
return this;
|
||||
}
|
||||
|
||||
public GLAccountBuilder withAccountTypeAsLiability() {
|
||||
GLAccountBuilder.accountType = LIABILITY_ACCOUNT;
|
||||
GLAccountBuilder.GLCode = Utils.randomStringGenerator("LIABILITY_", 2);
|
||||
GLAccountBuilder.GLCode += Calendar.getInstance().getTimeInMillis() + "";
|
||||
return this;
|
||||
}
|
||||
|
||||
public GLAccountBuilder withAccountTypeAsAsEquity() {
|
||||
GLAccountBuilder.accountType = EQUITY_ACCOUNT;
|
||||
GLAccountBuilder.GLCode = Utils.randomStringGenerator("EQUITY_", 2);
|
||||
GLAccountBuilder.GLCode += Calendar.getInstance().getTimeInMillis() + "";
|
||||
return this;
|
||||
}
|
||||
|
||||
public GLAccountBuilder withAccountTypeAsIncome() {
|
||||
GLAccountBuilder.accountType = INCOME_ACCOUNT;
|
||||
GLAccountBuilder.GLCode = Utils.randomStringGenerator("INCOME_", 2);
|
||||
GLAccountBuilder.GLCode += Calendar.getInstance().getTimeInMillis() + "";
|
||||
return this;
|
||||
}
|
||||
|
||||
public GLAccountBuilder withAccountTypeAsExpense() {
|
||||
GLAccountBuilder.accountType = EXPENSE_ACCOUNT;
|
||||
GLAccountBuilder.GLCode = Utils.randomStringGenerator("EXPENSE_", 2);
|
||||
GLAccountBuilder.GLCode += Calendar.getInstance().getTimeInMillis() + "";
|
||||
return this;
|
||||
}
|
||||
|
||||
public GLAccountBuilder withAccountUsageAsHeader() {
|
||||
GLAccountBuilder.accountUsage = ACCOUNT_USAGE_HEADER;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GLAccountBuilder withMaualEntriesNotAllowed() {
|
||||
GLAccountBuilder.manualEntriesAllowed = MANUAL_ENTRIES_NOT_ALLOW;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common.accounting;
|
||||
|
||||
public class JournalEntry {
|
||||
|
||||
public enum TransactionType {
|
||||
CREDIT("CREDIT"), DEBIT("DEBIT");
|
||||
|
||||
private TransactionType(final String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
private final String type;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.type;
|
||||
}
|
||||
}
|
||||
|
||||
private final Float transactionAmount;
|
||||
private final TransactionType transactionType;
|
||||
private final Integer officeId;
|
||||
|
||||
public JournalEntry(final float transactionAmount, final TransactionType type) {
|
||||
this.transactionAmount = transactionAmount;
|
||||
this.transactionType = type;
|
||||
this.officeId = null;
|
||||
}
|
||||
|
||||
public Float getTransactionAmount() {
|
||||
return this.transactionAmount;
|
||||
}
|
||||
|
||||
public String getTransactionType() {
|
||||
return this.transactionType.toString();
|
||||
}
|
||||
|
||||
}
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common.accounting;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class JournalEntryHelper {
|
||||
|
||||
private final RequestSpecification requestSpec;
|
||||
private final ResponseSpecification responseSpec;
|
||||
|
||||
public JournalEntryHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
this.requestSpec = requestSpec;
|
||||
this.responseSpec = responseSpec;
|
||||
}
|
||||
|
||||
public void checkJournalEntryForExpenseAccount(final Account expenseAccount, final String date, final JournalEntry... accountEntries) {
|
||||
checkJournalEntry(null, expenseAccount, date, accountEntries);
|
||||
}
|
||||
|
||||
public void checkJournalEntryForAssetAccount(final Account assetAccount, final String date, final JournalEntry... accountEntries) {
|
||||
checkJournalEntry(null, assetAccount, date, accountEntries);
|
||||
}
|
||||
|
||||
public void checkJournalEntryForIncomeAccount(final Account incomeAccount, final String date, final JournalEntry... accountEntries) {
|
||||
checkJournalEntry(null, incomeAccount, date, accountEntries);
|
||||
}
|
||||
|
||||
public void checkJournalEntryForLiabilityAccount(final Account liabilityAccount, final String date,
|
||||
final JournalEntry... accountEntries) {
|
||||
checkJournalEntry(null, liabilityAccount, date, accountEntries);
|
||||
}
|
||||
|
||||
public void checkJournalEntryForLiabilityAccount(final Integer officeId, final Account liabilityAccount, final String date,
|
||||
final JournalEntry... accountEntries) {
|
||||
checkJournalEntry(officeId, liabilityAccount, date, accountEntries);
|
||||
}
|
||||
|
||||
public void ensureNoAccountingTransactionsWithTransactionId(final String transactionId) {
|
||||
ArrayList<HashMap> transactions = getJournalEntriesByTransactionId(transactionId);
|
||||
assertTrue("Tranasactions are is not empty", transactions.isEmpty());
|
||||
|
||||
}
|
||||
|
||||
private String getEntryValueFromJournalEntry(final ArrayList<HashMap> entryResponse, final int entryNumber) {
|
||||
final HashMap map = (HashMap) entryResponse.get(entryNumber).get("entryType");
|
||||
return (String) map.get("value");
|
||||
}
|
||||
|
||||
private Float getTransactionAmountFromJournalEntry(final ArrayList<HashMap> entryResponse, final int entryNumber) {
|
||||
return (Float) entryResponse.get(entryNumber).get("amount");
|
||||
}
|
||||
|
||||
private void checkJournalEntry(final Integer officeId, final Account account, final String date, final JournalEntry... accountEntries) {
|
||||
final String url = createURLForGettingAccountEntries(account, date, officeId);
|
||||
final ArrayList<HashMap> response = Utils.performServerGet(this.requestSpec, this.responseSpec, url, "pageItems");
|
||||
for (int i = 0; i < accountEntries.length; i++) {
|
||||
assertThat(getEntryValueFromJournalEntry(response, i), equalTo(accountEntries[i].getTransactionType()));
|
||||
assertThat(getTransactionAmountFromJournalEntry(response, i), equalTo(accountEntries[i].getTransactionAmount()));
|
||||
}
|
||||
}
|
||||
|
||||
private String createURLForGettingAccountEntries(final Account account, final String date, final Integer officeId) {
|
||||
String url = new String("/fineract-provider/api/v1/journalentries?glAccountId=" + account.getAccountID() + "&type="
|
||||
+ account.getAccountType() + "&fromDate=" + date + "&toDate=" + date + "&tenantIdentifier=default"
|
||||
+ "&orderBy=id&sortOrder=desc&locale=en&dateFormat=dd MMMM yyyy");
|
||||
if (officeId != null) {
|
||||
url = url + "&officeId=" + officeId;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
private ArrayList<HashMap> getJournalEntriesByTransactionId(final String transactionId) {
|
||||
final String url = createURLForGettingAccountEntriesByTransactionId(transactionId);
|
||||
final ArrayList<HashMap> response = Utils.performServerGet(this.requestSpec, this.responseSpec, url, "pageItems");
|
||||
return response;
|
||||
}
|
||||
|
||||
private String createURLForGettingAccountEntriesByTransactionId(final String transactionId) {
|
||||
return new String("/fineract-provider/api/v1/journalentries?transactionId=" + transactionId + "&tenantIdentifier=default"
|
||||
+ "&orderBy=id&sortOrder=desc&locale=en&dateFormat=dd MMMM yyyy");
|
||||
}
|
||||
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common.accounting;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
public class PeriodicAccrualAccountingHelper {
|
||||
|
||||
private static final String PERIODIC_ACCRUAL_URL = "/fineract-provider/api/v1/runaccruals";
|
||||
private final RequestSpecification requestSpec;
|
||||
private final ResponseSpecification responseSpec;
|
||||
|
||||
public PeriodicAccrualAccountingHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
this.requestSpec = requestSpec;
|
||||
this.responseSpec = responseSpec;
|
||||
}
|
||||
|
||||
public Object runPeriodicAccrualAccounting(String date) {
|
||||
String json = getRunPeriodicAccrual(date);
|
||||
return Utils.performServerPost(this.requestSpec, this.responseSpec, PERIODIC_ACCRUAL_URL + "?" + Utils.TENANT_IDENTIFIER, json, "");
|
||||
}
|
||||
|
||||
private String getRunPeriodicAccrual(String date) {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("locale", "en_GB");
|
||||
map.put("tillDate", date);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
}
|
||||
+412
@@ -0,0 +1,412 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common.charges;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.CommonConstants;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public class ChargesHelper {
|
||||
|
||||
private static final String CHARGES_URL = "/fineract-provider/api/v1/charges";
|
||||
private static final String CREATE_CHARGES_URL = CHARGES_URL + "?" + Utils.TENANT_IDENTIFIER;
|
||||
|
||||
private static final Integer CHARGE_APPLIES_TO_LOAN = 1;
|
||||
private static final Integer CHARGE_APPLIES_TO_SAVINGS = 2;
|
||||
private static final Integer CHARGE_APPLIES_TO_CLIENT = 3;
|
||||
|
||||
private static final Integer CHARGE_DISBURSEMENT_FEE = 1;
|
||||
private static final Integer CHARGE_SPECIFIED_DUE_DATE = 2;
|
||||
private static final Integer CHARGE_SAVINGS_ACTIVATION_FEE = 3;
|
||||
private static final Integer CHARGE_WITHDRAWAL_FEE = 5;
|
||||
private static final Integer CHARGE_ANNUAL_FEE = 6;
|
||||
private static final Integer CHARGE_MONTHLY_FEE = 7;
|
||||
private static final Integer CHARGE_INSTALLMENT_FEE = 8;
|
||||
private static final Integer CHARGE_OVERDUE_INSTALLMENT_FEE = 9;
|
||||
private static final Integer CHARGE_OVERDRAFT_FEE = 10;
|
||||
private static final Integer WEEKLY_FEE = 11;
|
||||
|
||||
private static final Integer CHARGE_CLIENT_SPECIFIED_DUE_DATE = 1;
|
||||
|
||||
public static final Integer CHARGE_CALCULATION_TYPE_FLAT = 1;
|
||||
public static final Integer CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT = 2;
|
||||
public static final Integer CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT_AND_INTEREST = 3;
|
||||
public static final Integer CHARGE_CALCULATION_TYPE_PERCENTAGE_INTEREST = 4;
|
||||
|
||||
private static final Integer CHARGE_PAYMENT_MODE_REGULAR = 0;
|
||||
private static final Integer CHARGE_PAYMENT_MODE_ACCOUNT_TRANSFER = 1;
|
||||
|
||||
private static final Integer CHARGE_FEE_FREQUENCY_DAYS = 0;
|
||||
private static final Integer CHARGE_FEE_FREQUENCY_WEEKS = 1;
|
||||
private static final Integer CHARGE_FEE_FREQUENCY_MONTHS = 2;
|
||||
private static final Integer CHARGE_FEE_FREQUENCY_YEARS = 3;
|
||||
|
||||
private final static boolean active = true;
|
||||
private final static boolean penalty = true;
|
||||
private final static String amount = "100";
|
||||
private final static String currencyCode = "USD";
|
||||
public final static String feeOnMonthDay = "04 March";
|
||||
private final static String monthDayFormat = "dd MMM";
|
||||
|
||||
public static String getSavingsSpecifiedDueDateJSON() {
|
||||
final HashMap<String, Object> map = populateDefaultsForSavings();
|
||||
map.put("chargeTimeType", CHARGE_SPECIFIED_DUE_DATE);
|
||||
map.put("feeInterval", 2);
|
||||
String chargesCreateJson = new Gson().toJson(map);
|
||||
System.out.println(chargesCreateJson);
|
||||
return chargesCreateJson;
|
||||
}
|
||||
|
||||
public static String getSavingsActivationFeeJSON() {
|
||||
final HashMap<String, Object> map = populateDefaultsForSavings();
|
||||
map.put("chargeTimeType", CHARGE_SAVINGS_ACTIVATION_FEE);
|
||||
String chargesCreateJson = new Gson().toJson(map);
|
||||
System.out.println(chargesCreateJson);
|
||||
return chargesCreateJson;
|
||||
}
|
||||
|
||||
public static String getSavingsWithdrawalFeeJSON() {
|
||||
final HashMap<String, Object> map = populateDefaultsForSavings();
|
||||
map.put("chargeTimeType", CHARGE_WITHDRAWAL_FEE);
|
||||
String chargesCreateJson = new Gson().toJson(map);
|
||||
System.out.println(chargesCreateJson);
|
||||
return chargesCreateJson;
|
||||
}
|
||||
|
||||
public static String getSavingsAnnualFeeJSON() {
|
||||
final HashMap<String, Object> map = populateDefaultsForSavings();
|
||||
map.put("feeOnMonthDay", ChargesHelper.feeOnMonthDay);
|
||||
map.put("chargeTimeType", CHARGE_ANNUAL_FEE);
|
||||
String chargesCreateJson = new Gson().toJson(map);
|
||||
System.out.println(chargesCreateJson);
|
||||
return chargesCreateJson;
|
||||
}
|
||||
|
||||
public static String getSavingsMonthlyFeeJSON() {
|
||||
final HashMap<String, Object> map = populateDefaultsForSavings();
|
||||
map.put("feeOnMonthDay", ChargesHelper.feeOnMonthDay);
|
||||
map.put("chargeTimeType", CHARGE_MONTHLY_FEE);
|
||||
map.put("feeInterval", 2);
|
||||
String chargesCreateJson = new Gson().toJson(map);
|
||||
System.out.println(chargesCreateJson);
|
||||
return chargesCreateJson;
|
||||
}
|
||||
|
||||
public static String getSavingsWeeklyFeeJSON() {
|
||||
final HashMap<String, Object> map = populateDefaultsForSavings();
|
||||
map.put("chargeTimeType", WEEKLY_FEE);
|
||||
map.put("feeInterval", 1);
|
||||
String chargesCreateJson = new Gson().toJson(map);
|
||||
System.out.println(chargesCreateJson);
|
||||
return chargesCreateJson;
|
||||
}
|
||||
|
||||
public static String getSavingsOverdraftFeeJSON() {
|
||||
final HashMap<String, Object> map = populateDefaultsForSavings();
|
||||
map.put("chargeTimeType", CHARGE_OVERDRAFT_FEE);
|
||||
String chargesCreateJson = new Gson().toJson(map);
|
||||
System.out.println(chargesCreateJson);
|
||||
return chargesCreateJson;
|
||||
}
|
||||
|
||||
public static HashMap<String, Object> populateDefaultsForSavings() {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("active", ChargesHelper.active);
|
||||
map.put("amount", ChargesHelper.amount);
|
||||
map.put("chargeAppliesTo", ChargesHelper.CHARGE_APPLIES_TO_SAVINGS);
|
||||
map.put("chargeCalculationType", ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT);
|
||||
map.put("currencyCode", ChargesHelper.currencyCode);
|
||||
map.put("locale", CommonConstants.locale);
|
||||
map.put("monthDayFormat", ChargesHelper.monthDayFormat);
|
||||
map.put("name", Utils.randomNameGenerator("Charge_Savings_", 6));
|
||||
return map;
|
||||
}
|
||||
|
||||
public static String getLoanDisbursementJSON() {
|
||||
return getLoanDisbursementJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT, ChargesHelper.amount);
|
||||
}
|
||||
|
||||
public static String getLoanDisbursementJSON(final Integer chargeCalculationType, final String amount) {
|
||||
return getLoanDisbursementJSON(chargeCalculationType, amount, ChargesHelper.CHARGE_PAYMENT_MODE_REGULAR);
|
||||
}
|
||||
|
||||
public static String getLoanDisbursementAccountTransferJSON(final Integer chargeCalculationType, final String amount) {
|
||||
return getLoanDisbursementJSON(chargeCalculationType, amount, ChargesHelper.CHARGE_PAYMENT_MODE_ACCOUNT_TRANSFER);
|
||||
}
|
||||
|
||||
public static String getLoanDisbursementJSON(final Integer chargeCalculationType, final String amount, final Integer paymentmode) {
|
||||
final HashMap<String, Object> map = populateDefaultsForLoan();
|
||||
map.put("chargeTimeType", CHARGE_DISBURSEMENT_FEE);
|
||||
map.put("chargePaymentMode", paymentmode);
|
||||
map.put("amount", amount);
|
||||
map.put("chargeCalculationType", chargeCalculationType);
|
||||
String chargesCreateJson = new Gson().toJson(map);
|
||||
System.out.println(chargesCreateJson);
|
||||
return chargesCreateJson;
|
||||
}
|
||||
|
||||
public static String getLoanSpecifiedDueDateJSON() {
|
||||
return getLoanSpecifiedDueDateJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT, ChargesHelper.amount, ChargesHelper.penalty);
|
||||
}
|
||||
|
||||
public static String getLoanSpecifiedDueDateJSON(final Integer chargeCalculationType, final String amount, boolean penalty) {
|
||||
return getLoanSpecifiedDueDateJSON(chargeCalculationType, amount, penalty, ChargesHelper.CHARGE_PAYMENT_MODE_REGULAR);
|
||||
}
|
||||
|
||||
public static String getLoanSpecifiedDueDateJSON(final Integer chargeCalculationType, final String amount, final boolean penalty,
|
||||
final Integer paymentMode) {
|
||||
final HashMap<String, Object> map = populateDefaultsForLoan();
|
||||
map.put("chargeTimeType", CHARGE_SPECIFIED_DUE_DATE);
|
||||
map.put("chargePaymentMode", paymentMode);
|
||||
map.put("penalty", penalty);
|
||||
map.put("amount", amount);
|
||||
map.put("chargeCalculationType", chargeCalculationType);
|
||||
|
||||
String chargesCreateJson = new Gson().toJson(map);
|
||||
System.out.println(chargesCreateJson);
|
||||
return chargesCreateJson;
|
||||
}
|
||||
|
||||
public static String getLoanSpecifiedDueDateWithAccountTransferJSON(final Integer chargeCalculationType, final String amount,
|
||||
boolean penalty) {
|
||||
return getLoanSpecifiedDueDateJSON(chargeCalculationType, amount, penalty, ChargesHelper.CHARGE_PAYMENT_MODE_ACCOUNT_TRANSFER);
|
||||
}
|
||||
|
||||
public static String getLoanSpecifiedDueDateWithAccountTransferJSON() {
|
||||
return getLoanSpecifiedDueDateJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT, ChargesHelper.amount, ChargesHelper.penalty,
|
||||
ChargesHelper.CHARGE_PAYMENT_MODE_ACCOUNT_TRANSFER);
|
||||
}
|
||||
|
||||
public static String getLoanInstallmentJSON(final Integer chargeCalculationType, final String amount, boolean penalty) {
|
||||
return getLoanInstallmentJSON(chargeCalculationType, amount, penalty, ChargesHelper.CHARGE_PAYMENT_MODE_REGULAR);
|
||||
}
|
||||
|
||||
public static String getLoanInstallmentJSON(final Integer chargeCalculationType, final String amount, final boolean penalty,
|
||||
final Integer paymentMode) {
|
||||
final HashMap<String, Object> map = populateDefaultsForLoan();
|
||||
map.put("chargeTimeType", CHARGE_INSTALLMENT_FEE);
|
||||
map.put("chargePaymentMode", paymentMode);
|
||||
map.put("penalty", penalty);
|
||||
map.put("amount", amount);
|
||||
map.put("chargeCalculationType", chargeCalculationType);
|
||||
|
||||
String chargesCreateJson = new Gson().toJson(map);
|
||||
System.out.println(chargesCreateJson);
|
||||
return chargesCreateJson;
|
||||
}
|
||||
|
||||
public static String getLoanInstallmentWithAccountTransferJSON(final Integer chargeCalculationType, final String amount, boolean penalty) {
|
||||
return getLoanInstallmentJSON(chargeCalculationType, amount, penalty, ChargesHelper.CHARGE_PAYMENT_MODE_ACCOUNT_TRANSFER);
|
||||
}
|
||||
|
||||
public static String getLoanInstallmentFeeJSON() {
|
||||
return getLoanInstallmentJSON(ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT, ChargesHelper.amount, ChargesHelper.penalty);
|
||||
}
|
||||
|
||||
public static String getLoanOverdueFeeJSON() {
|
||||
final HashMap<String, Object> map = populateDefaultsForLoan();
|
||||
map.put("penalty", ChargesHelper.penalty);
|
||||
map.put("chargePaymentMode", ChargesHelper.CHARGE_PAYMENT_MODE_REGULAR);
|
||||
map.put("chargeTimeType", CHARGE_OVERDUE_INSTALLMENT_FEE);
|
||||
map.put("feeFrequency", ChargesHelper.CHARGE_FEE_FREQUENCY_MONTHS);
|
||||
map.put("feeOnMonthDay", ChargesHelper.feeOnMonthDay);
|
||||
map.put("feeInterval", 2);
|
||||
String chargesCreateJson = new Gson().toJson(map);
|
||||
System.out.println(chargesCreateJson);
|
||||
return chargesCreateJson;
|
||||
}
|
||||
|
||||
public static String getLoanOverdueFeeJSONWithCalculattionTypePercentage() {
|
||||
final HashMap<String, Object> map = populateDefaultsForLoan();
|
||||
map.put("penalty", ChargesHelper.penalty);
|
||||
map.put("amount", "10");
|
||||
map.put("chargePaymentMode", ChargesHelper.CHARGE_PAYMENT_MODE_REGULAR);
|
||||
map.put("chargeTimeType", CHARGE_OVERDUE_INSTALLMENT_FEE);
|
||||
map.put("chargeCalculationType", ChargesHelper.CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT_AND_INTEREST);
|
||||
String chargesCreateJson = new Gson().toJson(map);
|
||||
System.out.println(chargesCreateJson);
|
||||
return chargesCreateJson;
|
||||
}
|
||||
|
||||
public static HashMap<String, Object> populateDefaultsForLoan() {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("active", ChargesHelper.active);
|
||||
map.put("amount", ChargesHelper.amount);
|
||||
map.put("chargeAppliesTo", ChargesHelper.CHARGE_APPLIES_TO_LOAN);
|
||||
map.put("chargeCalculationType", ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT);
|
||||
map.put("currencyCode", ChargesHelper.currencyCode);
|
||||
map.put("locale", CommonConstants.locale);
|
||||
map.put("monthDayFormat", ChargesHelper.monthDayFormat);
|
||||
map.put("name", Utils.randomNameGenerator("Charge_Loans_", 6));
|
||||
return map;
|
||||
}
|
||||
|
||||
public static HashMap<String, Object> populateDefaultsClientCharge() {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("active", ChargesHelper.active);
|
||||
map.put("amount", ChargesHelper.amount);
|
||||
map.put("chargeAppliesTo", ChargesHelper.CHARGE_APPLIES_TO_CLIENT);
|
||||
map.put("chargeCalculationType", ChargesHelper.CHARGE_CALCULATION_TYPE_FLAT);
|
||||
map.put("chargeTimeType",ChargesHelper.CHARGE_SPECIFIED_DUE_DATE);
|
||||
map.put("currencyCode", ChargesHelper.currencyCode);
|
||||
map.put("locale", CommonConstants.locale);
|
||||
map.put("monthDayFormat", ChargesHelper.monthDayFormat);
|
||||
map.put("name", Utils.randomNameGenerator("Charge_client_", 8));
|
||||
return map;
|
||||
}
|
||||
|
||||
public static Integer createCharges(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String request) {
|
||||
return Utils.performServerPost(requestSpec, responseSpec, CREATE_CHARGES_URL, request, "resourceId");
|
||||
}
|
||||
|
||||
public static ArrayList<HashMap> getCharges(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
return (ArrayList) Utils.performServerGet(requestSpec, responseSpec, CHARGES_URL + "?" + Utils.TENANT_IDENTIFIER, "");
|
||||
}
|
||||
|
||||
public static HashMap getChargeById(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer chargeId) {
|
||||
return Utils.performServerGet(requestSpec, responseSpec, CHARGES_URL + "/" + chargeId + "?" + Utils.TENANT_IDENTIFIER, "");
|
||||
}
|
||||
|
||||
public static HashMap getChargeChanges(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer chargeId) {
|
||||
return Utils.performServerGet(requestSpec, responseSpec, CHARGES_URL + "/" + chargeId + "?" + Utils.TENANT_IDENTIFIER,
|
||||
CommonConstants.RESPONSE_CHANGES);
|
||||
}
|
||||
|
||||
public static HashMap updateCharges(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer chargeId, final String request) {
|
||||
return Utils.performServerPut(requestSpec, responseSpec, CHARGES_URL + "/" + chargeId + "?" + Utils.TENANT_IDENTIFIER, request,
|
||||
CommonConstants.RESPONSE_CHANGES);
|
||||
}
|
||||
|
||||
public static Integer deleteCharge(final ResponseSpecification responseSpec, final RequestSpecification requestSpec,
|
||||
final Integer chargeId) {
|
||||
return Utils.performServerDelete(requestSpec, responseSpec, CHARGES_URL + "/" + chargeId + "?" + Utils.TENANT_IDENTIFIER,
|
||||
CommonConstants.RESPONSE_RESOURCE_ID);
|
||||
}
|
||||
|
||||
public static String getModifyChargeJSON() {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("locale", CommonConstants.locale);
|
||||
map.put("amount", "200.0");
|
||||
String json = new Gson().toJson(map);
|
||||
System.out.println(json);
|
||||
return json;
|
||||
}
|
||||
|
||||
public static String getModifyWithdrawalFeeSavingsChargeJSON() {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("locale", CommonConstants.locale);
|
||||
map.put("chargeCalculationType", CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT);
|
||||
String json = new Gson().toJson(map);
|
||||
System.out.println(json);
|
||||
return json;
|
||||
}
|
||||
|
||||
public static String getModifyChargeAsPecentageAmountJSON() {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("locale", CommonConstants.locale);
|
||||
map.put("chargeCalculationType", CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT);
|
||||
map.put("chargePaymentMode", CHARGE_PAYMENT_MODE_ACCOUNT_TRANSFER);
|
||||
String json = new Gson().toJson(map);
|
||||
System.out.println(json);
|
||||
return json;
|
||||
}
|
||||
|
||||
public static String getModifyChargeAsPecentageLoanAmountWithInterestJSON() {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("locale", CommonConstants.locale);
|
||||
map.put("chargeCalculationType", CHARGE_CALCULATION_TYPE_PERCENTAGE_AMOUNT_AND_INTEREST);
|
||||
map.put("chargePaymentMode", CHARGE_PAYMENT_MODE_ACCOUNT_TRANSFER);
|
||||
String json = new Gson().toJson(map);
|
||||
System.out.println(json);
|
||||
return json;
|
||||
}
|
||||
|
||||
public static String getModifyChargeAsPercentageInterestJSON() {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("locale", CommonConstants.locale);
|
||||
map.put("chargeCalculationType", CHARGE_CALCULATION_TYPE_PERCENTAGE_INTEREST);
|
||||
map.put("chargePaymentMode", CHARGE_PAYMENT_MODE_ACCOUNT_TRANSFER);
|
||||
String json = new Gson().toJson(map);
|
||||
System.out.println(json);
|
||||
return json;
|
||||
}
|
||||
|
||||
public static String getModifyChargeFeeFrequencyAsDaysJSON() {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("locale", CommonConstants.locale);
|
||||
map.put("feeFrequency", ChargesHelper.CHARGE_FEE_FREQUENCY_DAYS);
|
||||
map.put("feeInterval", 2);
|
||||
String json = new Gson().toJson(map);
|
||||
System.out.println(json);
|
||||
return json;
|
||||
}
|
||||
|
||||
public static String getModifyChargeFeeFrequencyAsWeeksJSON() {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("locale", CommonConstants.locale);
|
||||
map.put("feeFrequency", ChargesHelper.CHARGE_FEE_FREQUENCY_WEEKS);
|
||||
map.put("feeInterval", 2);
|
||||
String json = new Gson().toJson(map);
|
||||
System.out.println(json);
|
||||
return json;
|
||||
}
|
||||
|
||||
public static String getModifyChargeFeeFrequencyAsMonthsJSON() {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("locale", CommonConstants.locale);
|
||||
map.put("feeFrequency", ChargesHelper.CHARGE_FEE_FREQUENCY_MONTHS);
|
||||
map.put("feeInterval", 2);
|
||||
String json = new Gson().toJson(map);
|
||||
System.out.println(json);
|
||||
return json;
|
||||
}
|
||||
|
||||
public static String getModifyChargeFeeFrequencyAsYearsJSON() {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("locale", CommonConstants.locale);
|
||||
map.put("feeFrequency", ChargesHelper.CHARGE_FEE_FREQUENCY_YEARS);
|
||||
map.put("feeInterval", 2);
|
||||
String json = new Gson().toJson(map);
|
||||
System.out.println(json);
|
||||
return json;
|
||||
}
|
||||
|
||||
public static String getChargeSpecifiedDueDateJSON() {
|
||||
final HashMap<String, Object> map = populateDefaultsClientCharge();
|
||||
String chargesCreateJson = new Gson().toJson(map);
|
||||
System.out.println("chargesCreateJson:"+chargesCreateJson);
|
||||
return chargesCreateJson;
|
||||
}
|
||||
|
||||
public static String applyCharge(RequestSpecification requestSpec,ResponseSpecification responseSpec, String chargeId,String json) {
|
||||
return Utils.performServerPost(requestSpec, responseSpec, CHARGES_URL + "/" + chargeId + "?" + Utils.TENANT_IDENTIFIER, json,"status");
|
||||
|
||||
}
|
||||
}
|
||||
+490
@@ -0,0 +1,490 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common.fixeddeposit;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.CommonConstants;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
@SuppressWarnings({ "unused", "rawtypes" })
|
||||
public class FixedDepositAccountHelper {
|
||||
|
||||
private final RequestSpecification requestSpec;
|
||||
private final ResponseSpecification responseSpec;
|
||||
|
||||
public FixedDepositAccountHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
this.requestSpec = requestSpec;
|
||||
this.responseSpec = responseSpec;
|
||||
}
|
||||
|
||||
private static final String FIXED_DEPOSIT_ACCOUNT_URL = "/fineract-provider/api/v1/fixeddepositaccounts";
|
||||
private static final String APPLY_FIXED_DEPOSIT_ACCOUNT_URL = FIXED_DEPOSIT_ACCOUNT_URL + "?" + Utils.TENANT_IDENTIFIER;
|
||||
private static final String APPROVE_FIXED_DEPOSIT_COMMAND = "approve";
|
||||
private static final String UNDO_APPROVAL_FIXED_DEPOSIT_COMMAND = "undoapproval";
|
||||
private static final String REJECT_FIXED_DEPOSIT_COMMAND = "reject";
|
||||
private static final String WITHDRAWN_BY_CLIENT_FIXED_DEPOSIT_COMMAND = "withdrawnByApplicant";
|
||||
private static final String ACTIVATE_FIXED_DEPOSIT_COMMAND = "activate";
|
||||
private static final String CLOSE_FIXED_DEPOSIT_COMMAND = "close";
|
||||
private static final String POST_INTEREST_FIXED_DEPOSIT_COMMAND = "postInterest";
|
||||
private static final String CALCULATE_INTEREST_FIXED_DEPOSIT_COMMAND = "calculateInterest";
|
||||
private static final String CALCULATE_PREMATURE_AMOUNT_COMMAND = "calculatePrematureAmount";
|
||||
private static final String PREMATURE_CLOSE_COMMAND = "prematureClose";
|
||||
|
||||
private static final String LOCALE = "en_GB";
|
||||
private static final String DIGITS_AFTER_DECIMAL = "4";
|
||||
private static final String IN_MULTIPLES_OF = "100";
|
||||
private static final String USD = "USD";
|
||||
public static final String DAYS = "0";
|
||||
private static final String WEEKS = "1";
|
||||
private static final String MONTHS = "2";
|
||||
private static final String YEARS = "3";
|
||||
private static final String DAILY = "1";
|
||||
private static final String MONTHLY = "4";
|
||||
private static final String QUARTERLY = "5";
|
||||
private static final String BI_ANNUALLY = "6";
|
||||
private static final String ANNUALLY = "7";
|
||||
private static final String INTEREST_CALCULATION_USING_DAILY_BALANCE = "1";
|
||||
private static final String INTEREST_CALCULATION_USING_AVERAGE_DAILY_BALANCE = "2";
|
||||
private static final String DAYS_360 = "360";
|
||||
private static final String DAYS_365 = "365";
|
||||
public final static String depositAmount = "100000";
|
||||
|
||||
private String interestCompoundingPeriodType = MONTHLY;
|
||||
private String interestPostingPeriodType = MONTHLY;
|
||||
private String interestCalculationType = INTEREST_CALCULATION_USING_DAILY_BALANCE;
|
||||
private String lockinPeriodFrequency = "1";
|
||||
private String lockingPeriodFrequencyType = MONTHS;
|
||||
private final String minDepositTerm = "6";
|
||||
private final String minDepositTermTypeId = MONTHS;
|
||||
private final String maxDepositTerm = "10";
|
||||
private final String maxDepositTermTypeId = YEARS;
|
||||
private final String inMultiplesOfDepositTerm = "2";
|
||||
private final String inMultiplesOfDepositTermTypeId = MONTHS;
|
||||
private final String preClosurePenalInterest = "2";
|
||||
private String interestCalculationDaysInYearType = DAYS_365;
|
||||
private final boolean preClosurePenalApplicable = true;
|
||||
private final boolean isActiveChart = true;
|
||||
private final String currencyCode = USD;
|
||||
|
||||
private final String depositPeriod = "14";
|
||||
private final String depositPeriodFrequencyId = MONTHS;
|
||||
private String submittedOnDate = "";
|
||||
private String savingsId = null;
|
||||
private boolean transferInterest = false;
|
||||
|
||||
public String build(final String clientId, final String productId, final String validFrom, final String validTo,
|
||||
final String penalInterestType) {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
|
||||
List<HashMap<String, String>> chartSlabs = new ArrayList<HashMap<String, String>>();
|
||||
HashMap<String, String> chartSlabsMap1 = new HashMap<>();
|
||||
chartSlabsMap1.put("description", "First");
|
||||
chartSlabsMap1.put("periodType", MONTHS);
|
||||
chartSlabsMap1.put("fromPeriod", "1");
|
||||
chartSlabsMap1.put("toPeriod", "6");
|
||||
chartSlabsMap1.put("annualInterestRate", "5");
|
||||
chartSlabsMap1.put("locale", LOCALE);
|
||||
chartSlabs.add(0, chartSlabsMap1);
|
||||
|
||||
HashMap<String, String> chartSlabsMap2 = new HashMap<>();
|
||||
chartSlabsMap2.put("description", "Second");
|
||||
chartSlabsMap2.put("periodType", MONTHS);
|
||||
chartSlabsMap2.put("fromPeriod", "7");
|
||||
chartSlabsMap2.put("toPeriod", "12");
|
||||
chartSlabsMap2.put("annualInterestRate", "6");
|
||||
chartSlabsMap2.put("locale", LOCALE);
|
||||
chartSlabs.add(1, chartSlabsMap2);
|
||||
|
||||
HashMap<String, String> chartSlabsMap3 = new HashMap<>();
|
||||
chartSlabsMap3.put("description", "Third");
|
||||
chartSlabsMap3.put("periodType", MONTHS);
|
||||
chartSlabsMap3.put("fromPeriod", "13");
|
||||
chartSlabsMap3.put("toPeriod", "18");
|
||||
chartSlabsMap3.put("annualInterestRate", "7");
|
||||
chartSlabsMap3.put("locale", LOCALE);
|
||||
chartSlabs.add(2, chartSlabsMap3);
|
||||
|
||||
HashMap<String, String> chartSlabsMap4 = new HashMap<>();
|
||||
chartSlabsMap4.put("description", "Fourth");
|
||||
chartSlabsMap4.put("periodType", MONTHS);
|
||||
chartSlabsMap4.put("fromPeriod", "19");
|
||||
chartSlabsMap4.put("toPeriod", "24");
|
||||
chartSlabsMap4.put("annualInterestRate", "8");
|
||||
chartSlabsMap4.put("locale", LOCALE);
|
||||
chartSlabs.add(3, chartSlabsMap4);
|
||||
|
||||
List<HashMap<String, Object>> charts = new ArrayList<HashMap<String, Object>>();
|
||||
HashMap<String, Object> chartsMap = new HashMap<>();
|
||||
chartsMap.put("fromDate", validFrom);
|
||||
chartsMap.put("endDate", validTo);
|
||||
chartsMap.put("dateFormat", "dd MMMM yyyy");
|
||||
chartsMap.put("locale", LOCALE);
|
||||
chartsMap.put("isActiveChart", this.isActiveChart);
|
||||
chartsMap.put("chartSlabs", chartSlabs);
|
||||
charts.add(chartsMap);
|
||||
|
||||
map.put("charts", charts);
|
||||
map.put("productId", productId);
|
||||
map.put("clientId", clientId);
|
||||
map.put("interestCalculationDaysInYearType", this.interestCalculationDaysInYearType);
|
||||
map.put("locale", LOCALE);
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("monthDayFormat", "dd MMM");
|
||||
map.put("interestCalculationType", this.interestCalculationType);
|
||||
map.put("interestCompoundingPeriodType", this.interestCompoundingPeriodType);
|
||||
map.put("interestPostingPeriodType", this.interestPostingPeriodType);
|
||||
map.put("lockinPeriodFrequency", this.lockinPeriodFrequency);
|
||||
map.put("lockinPeriodFrequencyType", this.lockingPeriodFrequencyType);
|
||||
map.put("preClosurePenalApplicable", "true");
|
||||
map.put("minDepositTermTypeId", this.minDepositTermTypeId);
|
||||
map.put("minDepositTerm", this.minDepositTerm);
|
||||
map.put("maxDepositTermTypeId", this.maxDepositTermTypeId);
|
||||
map.put("maxDepositTerm", this.maxDepositTerm);
|
||||
map.put("preClosurePenalApplicable", this.preClosurePenalApplicable);
|
||||
map.put("inMultiplesOfDepositTerm", this.inMultiplesOfDepositTerm);
|
||||
map.put("inMultiplesOfDepositTermTypeId", this.inMultiplesOfDepositTermTypeId);
|
||||
map.put("preClosurePenalInterest", this.preClosurePenalInterest);
|
||||
map.put("preClosurePenalInterestOnTypeId", penalInterestType);
|
||||
map.put("depositAmount", depositAmount);
|
||||
map.put("depositPeriod", this.depositPeriod);
|
||||
map.put("depositPeriodFrequencyId", this.depositPeriodFrequencyId);
|
||||
map.put("submittedOnDate", this.submittedOnDate);
|
||||
map.put("linkAccountId", savingsId);
|
||||
map.put("transferInterestToSavings", transferInterest);
|
||||
|
||||
String fixedDepositAccountJson = new Gson().toJson(map);
|
||||
System.out.println(fixedDepositAccountJson);
|
||||
return fixedDepositAccountJson;
|
||||
}
|
||||
|
||||
public static Integer applyFixedDepositApplication(final String fixedDepositAccountAsJson, final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec) {
|
||||
System.out.println("--------------------- APPLYING FOR FIXED DEPOSIT ACCOUNT ------------------------");
|
||||
return Utils.performServerPost(requestSpec, responseSpec, APPLY_FIXED_DEPOSIT_ACCOUNT_URL, fixedDepositAccountAsJson,
|
||||
CommonConstants.RESPONSE_RESOURCE_ID);
|
||||
}
|
||||
|
||||
public static HashMap getFixedDepositAccountById(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer accountID) {
|
||||
final String GET_FIXED_DEPOSIT_BY_ID_URL = FIXED_DEPOSIT_ACCOUNT_URL + "/" + accountID + "?" + Utils.TENANT_IDENTIFIER;
|
||||
System.out.println("------------------------ RETRIEVING FIXED DEPOSIT ACCOUNT BY ID -------------------------");
|
||||
return Utils.performServerGet(requestSpec, responseSpec, GET_FIXED_DEPOSIT_BY_ID_URL, "");
|
||||
}
|
||||
|
||||
public HashMap getFixedDepositSummary(final Integer accountID) {
|
||||
final String URL = FIXED_DEPOSIT_ACCOUNT_URL + "/" + accountID + "?" + Utils.TENANT_IDENTIFIER;
|
||||
final HashMap response = Utils.performServerGet(requestSpec, responseSpec, URL, "summary");
|
||||
return response;
|
||||
}
|
||||
|
||||
public static Float getInterestRate(ArrayList<ArrayList<HashMap>> interestSlabData, Integer depositPeriod) {
|
||||
|
||||
Float annualInterestRate = 0.0f;
|
||||
for (Integer slabIndex = 0; slabIndex < interestSlabData.get(0).size(); slabIndex++) {
|
||||
Integer fromPeriod = (Integer) interestSlabData.get(0).get(slabIndex).get("fromPeriod");
|
||||
Integer toPeriod = (Integer) interestSlabData.get(0).get(slabIndex).get("toPeriod");
|
||||
if (depositPeriod >= fromPeriod && depositPeriod <= toPeriod) {
|
||||
annualInterestRate = (Float) interestSlabData.get(0).get(slabIndex).get("annualInterestRate");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return annualInterestRate;
|
||||
}
|
||||
|
||||
public static Float getPrincipalAfterCompoundingInterest(Calendar currentDate, Float principal, Integer depositPeriod,
|
||||
double interestPerDay, Integer compoundingInterval, Integer postingInterval) {
|
||||
|
||||
Float totalInterest = 0.0f;
|
||||
Float interestEarned = 0.0f;
|
||||
|
||||
for (int i = 1; i <= depositPeriod; i++) {
|
||||
Integer daysInMonth = currentDate.getActualMaximum(Calendar.DATE);
|
||||
for (int j = 0; j < daysInMonth; j++) {
|
||||
|
||||
interestEarned = (float) (principal * interestPerDay);
|
||||
totalInterest += interestEarned;
|
||||
if (compoundingInterval == 0) {
|
||||
principal += interestEarned;
|
||||
}
|
||||
}
|
||||
if ((i % postingInterval) == 0 || i == depositPeriod) {
|
||||
if (compoundingInterval != 0) {
|
||||
principal += totalInterest;
|
||||
}
|
||||
totalInterest = 0.0f;
|
||||
System.out.println(principal);
|
||||
|
||||
}
|
||||
currentDate.add(Calendar.MONTH, 1);
|
||||
interestEarned = 0.0f;
|
||||
}
|
||||
return principal;
|
||||
}
|
||||
|
||||
public HashMap updateFixedDepositAccount(final String clientID, final String productID, final String accountID, final String validFrom,
|
||||
final String validTo, final String penalInterestType, final String submittedOnDate) {
|
||||
|
||||
final String fixedDepositApplicationJSON = new FixedDepositAccountHelper(this.requestSpec, this.responseSpec) //
|
||||
.withSubmittedOnDate(submittedOnDate) //
|
||||
.build(clientID, productID, validFrom, validTo, penalInterestType);
|
||||
|
||||
return Utils.performServerPut(this.requestSpec, this.responseSpec, FIXED_DEPOSIT_ACCOUNT_URL + "/" + accountID + "?"
|
||||
+ Utils.TENANT_IDENTIFIER, fixedDepositApplicationJSON, CommonConstants.RESPONSE_CHANGES);
|
||||
}
|
||||
|
||||
public HashMap updateInterestCalculationConfigForFixedDeposit(final String clientID, final String productID, final String accountID,
|
||||
final String submittedOnDate, final String validFrom, final String validTo, final String numberOfDaysPerYear,
|
||||
final String penalInterestType, final String interestCalculationType, final String interestCompoundingPeriodType,
|
||||
final String interestPostingPeriodType) {
|
||||
|
||||
final String fixedDepositApplicationJSON = new FixedDepositAccountHelper(this.requestSpec, this.responseSpec) //
|
||||
.withSubmittedOnDate(submittedOnDate) //
|
||||
.withNumberOfDaysPerYear(numberOfDaysPerYear) //
|
||||
.withInterestCalculationPeriodType(interestCalculationType) //
|
||||
.withInterestCompoundingPeriodType(interestCompoundingPeriodType) //
|
||||
.withInterestPostingPeriodType(interestPostingPeriodType) //
|
||||
.build(clientID, productID, validFrom, validTo, penalInterestType);
|
||||
|
||||
return Utils.performServerPut(this.requestSpec, this.responseSpec, FIXED_DEPOSIT_ACCOUNT_URL + "/" + accountID + "?"
|
||||
+ Utils.TENANT_IDENTIFIER, fixedDepositApplicationJSON, CommonConstants.RESPONSE_CHANGES);
|
||||
}
|
||||
|
||||
public HashMap approveFixedDeposit(final Integer fixedDepositAccountID, final String approvedOnDate) {
|
||||
System.out.println("--------------------------------- APPROVING FIXED DEPOSIT APPLICATION ------------------------------------");
|
||||
return performFixedDepositApplicationActions(createFixedDepositOperationURL(APPROVE_FIXED_DEPOSIT_COMMAND, fixedDepositAccountID),
|
||||
getApproveFixedDepositAccountAsJSON(approvedOnDate));
|
||||
}
|
||||
|
||||
public HashMap undoApproval(final Integer fixedDepositAccountID) {
|
||||
System.out.println("--------------------------------- UNDO APPROVING FIXED DEPOSIT APPLICATION -------------------------------");
|
||||
final String undoBodyJson = "{'note':'UNDO APPROVAL'}";
|
||||
return performFixedDepositApplicationActions(
|
||||
createFixedDepositOperationURL(UNDO_APPROVAL_FIXED_DEPOSIT_COMMAND, fixedDepositAccountID), undoBodyJson);
|
||||
}
|
||||
|
||||
public HashMap rejectApplication(final Integer fixedDepositAccountID, final String rejectedOnDate) {
|
||||
System.out.println("--------------------------------- REJECT FIXED DEPOSIT APPLICATION -------------------------------");
|
||||
return performFixedDepositApplicationActions(createFixedDepositOperationURL(REJECT_FIXED_DEPOSIT_COMMAND, fixedDepositAccountID),
|
||||
getRejectedFixedDepositAsJSON(rejectedOnDate));
|
||||
}
|
||||
|
||||
public HashMap withdrawApplication(final Integer fixedDepositAccountID, final String withdrawApplicationOnDate) {
|
||||
System.out.println("--------------------------------- Withdraw FIXED DEPOSIT APPLICATION -------------------------------");
|
||||
return performFixedDepositApplicationActions(
|
||||
createFixedDepositOperationURL(WITHDRAWN_BY_CLIENT_FIXED_DEPOSIT_COMMAND, fixedDepositAccountID),
|
||||
getWithdrawnFixedDepositAccountAsJSON(withdrawApplicationOnDate));
|
||||
}
|
||||
|
||||
public HashMap activateFixedDeposit(final Integer fixedDepositAccountID, final String activationDate) {
|
||||
System.out.println("---------------------------------- ACTIVATING FIXED DEPOSIT APPLICATION ----------------------------------");
|
||||
return performFixedDepositApplicationActions(createFixedDepositOperationURL(ACTIVATE_FIXED_DEPOSIT_COMMAND, fixedDepositAccountID),
|
||||
getActivatedFixedDepositAccountAsJSON(activationDate));
|
||||
}
|
||||
|
||||
public Object deleteFixedDepositApplication(final Integer fixedDepositAccountID, final String jsonAttributeToGetBack) {
|
||||
System.out.println("---------------------------------- DELETE FIXED DEPOSIT APPLICATION ----------------------------------");
|
||||
return Utils.performServerDelete(this.requestSpec, this.responseSpec, FIXED_DEPOSIT_ACCOUNT_URL + "/" + fixedDepositAccountID + "?"
|
||||
+ Utils.TENANT_IDENTIFIER, jsonAttributeToGetBack);
|
||||
|
||||
}
|
||||
|
||||
public Integer calculateInterestForFixedDeposit(final Integer fixedDepositAccountId) {
|
||||
System.out.println("--------------------------------- CALCULATING INTEREST FOR FIXED DEPOSIT --------------------------------");
|
||||
return (Integer) performFixedDepositActions(
|
||||
createFixedDepositCalculateInterestURL(CALCULATE_INTEREST_FIXED_DEPOSIT_COMMAND, fixedDepositAccountId),
|
||||
getCalculatedInterestForFixedDepositApplicationAsJSON(), CommonConstants.RESPONSE_RESOURCE_ID);
|
||||
}
|
||||
|
||||
public Integer postInterestForFixedDeposit(final Integer fixedDepositAccountId) {
|
||||
System.out.println("--------------------------------- POST INTEREST FOR FIXED DEPOSIT --------------------------------");
|
||||
return (Integer) performFixedDepositActions(
|
||||
createFixedDepositCalculateInterestURL(POST_INTEREST_FIXED_DEPOSIT_COMMAND, fixedDepositAccountId),
|
||||
getCalculatedInterestForFixedDepositApplicationAsJSON(), CommonConstants.RESPONSE_RESOURCE_ID);
|
||||
}
|
||||
|
||||
public HashMap calculatePrematureAmountForFixedDeposit(final Integer fixedDepositAccountId, final String closedOnDate) {
|
||||
System.out.println("--------------------- CALCULATING PREMATURE AMOUNT FOR FIXED DEPOSIT ----------------------------");
|
||||
return (HashMap) performFixedDepositActions(
|
||||
createFixedDepositCalculateInterestURL(CALCULATE_PREMATURE_AMOUNT_COMMAND, fixedDepositAccountId),
|
||||
getCalculatedPrematureAmountForFixedDepositAccountAsJSON(closedOnDate), "");
|
||||
}
|
||||
|
||||
public Object prematureCloseForFixedDeposit(final Integer fixedDepositAccountId, final String closedOnDate, final String closureType,
|
||||
final Integer toSavingsId, final String jsonAttributeToGetBack) {
|
||||
System.out.println("--------------------- PREMATURE CLOSE FOR FIXED DEPOSIT ----------------------------");
|
||||
return performFixedDepositActions(createFixedDepositCalculateInterestURL(PREMATURE_CLOSE_COMMAND, fixedDepositAccountId),
|
||||
getPrematureCloseForFixedDepositAccountAsJSON(closedOnDate, closureType, toSavingsId), jsonAttributeToGetBack);
|
||||
}
|
||||
|
||||
private String getApproveFixedDepositAccountAsJSON(final String approvedOnDate) {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("locale", CommonConstants.locale);
|
||||
map.put("dateFormat", CommonConstants.dateFormat);
|
||||
map.put("approvedOnDate", approvedOnDate);
|
||||
map.put("note", "Approval NOTE");
|
||||
String fixedDepositAccountApproveJson = new Gson().toJson(map);
|
||||
System.out.println(fixedDepositAccountApproveJson);
|
||||
return fixedDepositAccountApproveJson;
|
||||
}
|
||||
|
||||
private String getRejectedFixedDepositAsJSON(final String rejectedOnDate) {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("locale", CommonConstants.locale);
|
||||
map.put("dateFormat", CommonConstants.dateFormat);
|
||||
map.put("rejectedOnDate", rejectedOnDate);
|
||||
map.put("note", "Rejected NOTE");
|
||||
String fixedDepositAccountJson = new Gson().toJson(map);
|
||||
System.out.println(fixedDepositAccountJson);
|
||||
return fixedDepositAccountJson;
|
||||
}
|
||||
|
||||
private String getWithdrawnFixedDepositAccountAsJSON(final String withdrawnApplicationOnDate) {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("locale", CommonConstants.locale);
|
||||
map.put("dateFormat", CommonConstants.dateFormat);
|
||||
map.put("withdrawnOnDate", withdrawnApplicationOnDate);
|
||||
map.put("note", "Withdraw NOTE");
|
||||
String fixedDepositAccountJson = new Gson().toJson(map);
|
||||
System.out.println(fixedDepositAccountJson);
|
||||
return fixedDepositAccountJson;
|
||||
}
|
||||
|
||||
private String getActivatedFixedDepositAccountAsJSON(final String activationDate) {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("locale", CommonConstants.locale);
|
||||
map.put("dateFormat", CommonConstants.dateFormat);
|
||||
map.put("activatedOnDate", activationDate);
|
||||
String fixedDepositAccountActivateJson = new Gson().toJson(map);
|
||||
System.out.println(fixedDepositAccountActivateJson);
|
||||
return fixedDepositAccountActivateJson;
|
||||
}
|
||||
|
||||
private String getCalculatedInterestForFixedDepositApplicationAsJSON() {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
String fixedDepositAccountCalculatedInterestJson = new Gson().toJson(map);
|
||||
System.out.println(fixedDepositAccountCalculatedInterestJson);
|
||||
return fixedDepositAccountCalculatedInterestJson;
|
||||
}
|
||||
|
||||
private String getCalculatedPrematureAmountForFixedDepositAccountAsJSON(final String closedOnDate) {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("locale", CommonConstants.locale);
|
||||
map.put("dateFormat", CommonConstants.dateFormat);
|
||||
map.put("closedOnDate", closedOnDate);
|
||||
String fixedDepositAccountPrematureClosureJson = new Gson().toJson(map);
|
||||
System.out.println(fixedDepositAccountPrematureClosureJson);
|
||||
return fixedDepositAccountPrematureClosureJson;
|
||||
}
|
||||
|
||||
private String getPrematureCloseForFixedDepositAccountAsJSON(final String closedOnDate, final String closureType,
|
||||
final Integer toSavingsId) {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("locale", CommonConstants.locale);
|
||||
map.put("dateFormat", CommonConstants.dateFormat);
|
||||
map.put("closedOnDate", closedOnDate);
|
||||
map.put("onAccountClosureId", closureType);
|
||||
if (toSavingsId != null) {
|
||||
map.put("toSavingsAccountId", toSavingsId);
|
||||
map.put("transferDescription", "Transferring To Savings Account");
|
||||
}
|
||||
String fixedDepositAccountPrematureCloseJson = new Gson().toJson(map);
|
||||
System.out.println(fixedDepositAccountPrematureCloseJson);
|
||||
return fixedDepositAccountPrematureCloseJson;
|
||||
}
|
||||
|
||||
private String createFixedDepositOperationURL(final String command, final Integer fixedDepositAccountID) {
|
||||
return FIXED_DEPOSIT_ACCOUNT_URL + "/" + fixedDepositAccountID + "?command=" + command + "&" + Utils.TENANT_IDENTIFIER;
|
||||
}
|
||||
|
||||
private Object performFixedDepositActions(final String postURLForFixedDeposit, final String jsonToBeSent,
|
||||
final String jsonAttributeToGetBack) {
|
||||
return Utils.performServerPost(this.requestSpec, this.responseSpec, postURLForFixedDeposit, jsonToBeSent, jsonAttributeToGetBack);
|
||||
}
|
||||
|
||||
private HashMap performFixedDepositApplicationActions(final String postURLForFixedDepositAction, final String jsonToBeSent) {
|
||||
HashMap status = null;
|
||||
final HashMap response = Utils.performServerPost(this.requestSpec, this.responseSpec, postURLForFixedDepositAction, jsonToBeSent,
|
||||
CommonConstants.RESPONSE_CHANGES);
|
||||
if (response != null) {
|
||||
status = (HashMap) response.get("status");
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
private String createFixedDepositCalculateInterestURL(final String command, final Integer fixedDepositAccountID) {
|
||||
return FIXED_DEPOSIT_ACCOUNT_URL + "/" + fixedDepositAccountID + "?command=" + command + "&" + Utils.TENANT_IDENTIFIER;
|
||||
}
|
||||
|
||||
public static ArrayList retrieveAllFixedDepositAccounts(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
System.out.println("-------------------- RETRIEVING ALL FIXED DEPOSIT ACCOUNTS ---------------------");
|
||||
final ArrayList response = Utils.performServerGet(requestSpec, responseSpec, FIXED_DEPOSIT_ACCOUNT_URL + "?"
|
||||
+ Utils.TENANT_IDENTIFIER, "");
|
||||
return response;
|
||||
}
|
||||
|
||||
public FixedDepositAccountHelper withSubmittedOnDate(final String fixedDepositApplicationSubmittedDate) {
|
||||
this.submittedOnDate = fixedDepositApplicationSubmittedDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public FixedDepositAccountHelper withNumberOfDaysPerYear(final String numberOfDaysPerYearTypeId) {
|
||||
this.interestCalculationDaysInYearType = numberOfDaysPerYearTypeId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public FixedDepositAccountHelper withInterestCalculationPeriodType(final String interestCalculationTypeId) {
|
||||
this.interestCalculationType = interestCalculationTypeId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public FixedDepositAccountHelper withInterestCompoundingPeriodType(final String interestCompoundingPeriodTypeId) {
|
||||
this.interestCompoundingPeriodType = interestCompoundingPeriodTypeId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public FixedDepositAccountHelper withInterestPostingPeriodType(final String interestPostingPeriodTypeId) {
|
||||
this.interestPostingPeriodType = interestPostingPeriodTypeId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public FixedDepositAccountHelper withSavings(final String savingsId) {
|
||||
this.savingsId = savingsId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public FixedDepositAccountHelper transferInterest(final boolean transferInterest) {
|
||||
this.transferInterest = transferInterest;
|
||||
return this;
|
||||
}
|
||||
|
||||
public FixedDepositAccountHelper withLockinPeriodFrequency(final String lockingPeriodFrequencyType, final String lockinPeriodFrequency) {
|
||||
this.lockingPeriodFrequencyType = lockingPeriodFrequencyType;
|
||||
this.lockinPeriodFrequency = lockinPeriodFrequency;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common.fixeddeposit;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class FixedDepositAccountStatusChecker {
|
||||
|
||||
private static final String FIXED_DEPOSIT_ACCOUNT_URL = "/fineract-provider/api/v1/fixeddepositaccounts";
|
||||
|
||||
public static void verifyFixedDepositIsApproved(final HashMap fixedDepositStatusHashMap) {
|
||||
System.out.println("-------------------- VERIFYING FIXED DEPOSIT APPLICATION IS APPROVED --------------------");
|
||||
assertTrue("Error in Approving Fixed deposit application", getStatus(fixedDepositStatusHashMap, "approved"));
|
||||
System.out.println(fixedDepositStatusHashMap);
|
||||
}
|
||||
|
||||
public static void verifyFixedDepositIsPending(final HashMap fixedDepositStatusHashMap) {
|
||||
System.out.println("-------------------- VERIFYING FIXED DEPOSIT APPLICATION IS PENDING --------------------");
|
||||
assertTrue("FIXED DEPOSIT ACCOUNT IS NOT IN PENDING STATE", getStatus(fixedDepositStatusHashMap, "submittedAndPendingApproval"));
|
||||
System.out.println(fixedDepositStatusHashMap);
|
||||
}
|
||||
|
||||
public static void verifyFixedDepositIsActive(final HashMap fixedDepositStatusHashMap) {
|
||||
System.out.println("----------------- VERIFYING FIXED DEPOSIT APPLICATION IS ACTIVE -----------------");
|
||||
assertTrue("ERROR IN ACTIVATING THE FIXED DEPOSIT APPLICATION", getStatus(fixedDepositStatusHashMap, "active"));
|
||||
System.out.println(fixedDepositStatusHashMap);
|
||||
}
|
||||
|
||||
public static void verifyFixedDepositIsRejected(final HashMap fixedDepositStatusHashMap) {
|
||||
System.out.println("-------------- VERIFYING FIXED DEPOSIT APPLICATION IS REJECTED ----------------");
|
||||
assertTrue("ERROR IN REJECTING THE FIXED DEPOSIT APPLICATION", getStatus(fixedDepositStatusHashMap, "rejected"));
|
||||
System.out.println(fixedDepositStatusHashMap);
|
||||
}
|
||||
|
||||
public static void verifyFixedDepositIsWithdrawn(final HashMap fixedDepositStatusHashMap) {
|
||||
System.out.println("---------------- VERIFYING FIXED DEPOSIT APPLICATION IS WITHDRAWN ----------------");
|
||||
assertTrue("ERROR IN WITHDRAW THE FIXED DEPOSIT APPLICATION", getStatus(fixedDepositStatusHashMap, "withdrawnByApplicant"));
|
||||
System.out.println(fixedDepositStatusHashMap);
|
||||
}
|
||||
|
||||
public static void verifyFixedDepositAccountIsClosed(final HashMap fixedDepositStatusHashMap) {
|
||||
System.out.println("--------------------- VERIFYING FIXED DEPOSIT APPLICATION IS CLOSED ---------------------");
|
||||
assertTrue("ERROR IN CLOSING THE FIXED DEPOSIT APPLICATION", getStatus(fixedDepositStatusHashMap, "closed"));
|
||||
System.out.println(fixedDepositStatusHashMap);
|
||||
}
|
||||
|
||||
public static void verifyFixedDepositAccountIsNotActive(final HashMap fixedDepositStatusHashMap) {
|
||||
System.out.println("------------------ VERIFYING FIXED DEPOSIT APPLICATION IS INACTIVE --------------------");
|
||||
Assert.assertFalse(getStatus(fixedDepositStatusHashMap, "active"));
|
||||
System.out.println(fixedDepositStatusHashMap);
|
||||
}
|
||||
|
||||
public static HashMap getStatusOfFixedDepositAccount(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String fixedDepositAccountID) {
|
||||
final String GET_STATUS_OF_FIXED_DEPOSIT_ACCOUNT_URL = FIXED_DEPOSIT_ACCOUNT_URL + "/" + fixedDepositAccountID + "?"
|
||||
+ Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerGet(requestSpec, responseSpec, GET_STATUS_OF_FIXED_DEPOSIT_ACCOUNT_URL, "status");
|
||||
}
|
||||
|
||||
public static void verifyFixedDepositAccountIsPrematureClosed(HashMap fixedDepositStatusHashMap) {
|
||||
System.out.println("--------------------- VERIFYING FIXED DEPOSIT APPLICATION IS CLOSED ---------------------");
|
||||
assertTrue("ERROR IN PREMATURELY CLOSING THE FIXED DEPOSIT ACCOUNT", getStatus(fixedDepositStatusHashMap, "prematureClosed"));
|
||||
System.out.println(fixedDepositStatusHashMap);
|
||||
}
|
||||
|
||||
private static boolean getStatus(final HashMap fixedDepositStatusMap, final String fixedDepositStatusString) {
|
||||
return (Boolean) fixedDepositStatusMap.get(fixedDepositStatusString);
|
||||
}
|
||||
}
|
||||
+254
@@ -0,0 +1,254 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common.fixeddeposit;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.CommonConstants;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.accounting.Account;
|
||||
import org.apache.fineract.integrationtests.common.accounting.Account.AccountType;
|
||||
import org.apache.fineract.integrationtests.common.savings.SavingsProductHelper;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
@SuppressWarnings({ "unused", "rawtypes" })
|
||||
public class FixedDepositProductHelper {
|
||||
|
||||
private final RequestSpecification requestSpec;
|
||||
private final ResponseSpecification responseSpec;
|
||||
|
||||
public FixedDepositProductHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
this.requestSpec = requestSpec;
|
||||
this.responseSpec = responseSpec;
|
||||
}
|
||||
|
||||
private static final String FIXED_DEPOSIT_PRODUCT_URL = "/fineract-provider/api/v1/fixeddepositproducts";
|
||||
private static final String INTEREST_CHART_URL = "/fineract-provider/api/v1/interestratecharts";
|
||||
private static final String CREATE_FIXED_DEPOSIT_PRODUCT_URL = FIXED_DEPOSIT_PRODUCT_URL + "?" + Utils.TENANT_IDENTIFIER;
|
||||
|
||||
private static final String LOCALE = "en_GB";
|
||||
private static final String DIGITS_AFTER_DECIMAL = "4";
|
||||
private static final String IN_MULTIPLES_OF = "100";
|
||||
private static final String USD = "USD";
|
||||
private static final String DAYS = "0";
|
||||
private static final String WEEKS = "1";
|
||||
private static final String MONTHS = "2";
|
||||
private static final String YEARS = "3";
|
||||
private static final String DAILY = "1";
|
||||
private static final String MONTHLY = "4";
|
||||
private static final String QUARTERLY = "5";
|
||||
private static final String BI_ANNUALLY = "6";
|
||||
private static final String ANNUALLY = "7";
|
||||
private static final String INTEREST_CALCULATION_USING_DAILY_BALANCE = "1";
|
||||
private static final String INTEREST_CALCULATION_USING_AVERAGE_DAILY_BALANCE = "2";
|
||||
private static final String DAYS_360 = "360";
|
||||
private static final String DAYS_365 = "365";
|
||||
private static final String NONE = "1";
|
||||
private static final String CASH_BASED = "2";
|
||||
private static final String ACCRUAL_PERIODIC = "3";
|
||||
private static final String ACCRUAL_UPFRONT = "4";
|
||||
private static final String WHOLE_TERM = "1";
|
||||
private static final String TILL_PREMATURE_WITHDRAWAL = "2";
|
||||
|
||||
private String name = Utils.randomNameGenerator("FIXED_DEPOSIT_PRODUCT_", 6);
|
||||
private String shortName = Utils.randomNameGenerator("", 4);
|
||||
private String description = Utils.randomNameGenerator("", 20);
|
||||
private String interestCompoundingPeriodType = MONTHLY;
|
||||
private String interestPostingPeriodType = MONTHLY;
|
||||
private String interestCalculationType = INTEREST_CALCULATION_USING_DAILY_BALANCE;
|
||||
private String accountingRule = NONE;
|
||||
private String lockinPeriodFrequency = "1";
|
||||
private String lockingPeriodFrequencyType = MONTHS;
|
||||
private String minDepositTerm = "6";
|
||||
private String minDepositTermTypeId = MONTHS;
|
||||
private String maxDepositTerm = "10";
|
||||
private String maxDepositTermTypeId = YEARS;
|
||||
private String inMultiplesOfDepositTerm = "2";
|
||||
private final String depositAmount = "100000";
|
||||
private String inMultiplesOfDepositTermTypeId = MONTHS;
|
||||
private String preClosurePenalInterest = "2";
|
||||
private String preClosurePenalInterestOnTypeId = WHOLE_TERM;
|
||||
private final boolean preClosurePenalApplicable = true;
|
||||
private final String currencyCode = USD;
|
||||
private final String interestCalculationDaysInYearType = DAYS_365;
|
||||
private Account[] accountList = null;
|
||||
|
||||
public String build(final String validFrom, final String validTo) {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
|
||||
List<HashMap<String, String>> chartSlabs = new ArrayList<HashMap<String, String>>();
|
||||
HashMap<String, String> chartSlabsMap1 = new HashMap<>();
|
||||
chartSlabsMap1.put("description", "First");
|
||||
chartSlabsMap1.put("periodType", MONTHS);
|
||||
chartSlabsMap1.put("fromPeriod", "1");
|
||||
chartSlabsMap1.put("toPeriod", "6");
|
||||
chartSlabsMap1.put("annualInterestRate", "5");
|
||||
chartSlabsMap1.put("locale", LOCALE);
|
||||
chartSlabs.add(0, chartSlabsMap1);
|
||||
|
||||
HashMap<String, String> chartSlabsMap2 = new HashMap<>();
|
||||
chartSlabsMap2.put("description", "Second");
|
||||
chartSlabsMap2.put("periodType", MONTHS);
|
||||
chartSlabsMap2.put("fromPeriod", "7");
|
||||
chartSlabsMap2.put("toPeriod", "12");
|
||||
chartSlabsMap2.put("annualInterestRate", "6");
|
||||
chartSlabsMap2.put("locale", LOCALE);
|
||||
chartSlabs.add(1, chartSlabsMap2);
|
||||
|
||||
HashMap<String, String> chartSlabsMap3 = new HashMap<>();
|
||||
chartSlabsMap3.put("description", "Third");
|
||||
chartSlabsMap3.put("periodType", MONTHS);
|
||||
chartSlabsMap3.put("fromPeriod", "13");
|
||||
chartSlabsMap3.put("toPeriod", "18");
|
||||
chartSlabsMap3.put("annualInterestRate", "7");
|
||||
chartSlabsMap3.put("locale", LOCALE);
|
||||
chartSlabs.add(2, chartSlabsMap3);
|
||||
|
||||
HashMap<String, String> chartSlabsMap4 = new HashMap<>();
|
||||
chartSlabsMap4.put("description", "Fourth");
|
||||
chartSlabsMap4.put("periodType", MONTHS);
|
||||
chartSlabsMap4.put("fromPeriod", "19");
|
||||
chartSlabsMap4.put("toPeriod", "24");
|
||||
chartSlabsMap4.put("annualInterestRate", "8");
|
||||
chartSlabsMap4.put("locale", LOCALE);
|
||||
chartSlabs.add(3, chartSlabsMap4);
|
||||
|
||||
List<HashMap<String, Object>> charts = new ArrayList<HashMap<String, Object>>();
|
||||
HashMap<String, Object> chartsMap = new HashMap<>();
|
||||
chartsMap.put("fromDate", validFrom);
|
||||
chartsMap.put("endDate", validTo);
|
||||
chartsMap.put("dateFormat", "dd MMMM yyyy");
|
||||
chartsMap.put("locale", LOCALE);
|
||||
chartsMap.put("chartSlabs", chartSlabs);
|
||||
charts.add(chartsMap);
|
||||
|
||||
map.put("charts", charts);
|
||||
map.put("name", this.name);
|
||||
map.put("shortName", this.shortName);
|
||||
map.put("description", this.description);
|
||||
map.put("currencyCode", this.currencyCode);
|
||||
map.put("interestCalculationDaysInYearType", this.interestCalculationDaysInYearType);
|
||||
map.put("locale", LOCALE);
|
||||
map.put("digitsAfterDecimal", DIGITS_AFTER_DECIMAL);
|
||||
map.put("inMultiplesOf", IN_MULTIPLES_OF);
|
||||
map.put("interestCalculationType", this.interestCalculationType);
|
||||
map.put("interestCompoundingPeriodType", this.interestCompoundingPeriodType);
|
||||
map.put("interestPostingPeriodType", this.interestPostingPeriodType);
|
||||
map.put("accountingRule", this.accountingRule);
|
||||
map.put("lockinPeriodFrequency", this.lockinPeriodFrequency);
|
||||
map.put("lockinPeriodFrequencyType", this.lockingPeriodFrequencyType);
|
||||
map.put("preClosurePenalApplicable", "true");
|
||||
map.put("minDepositTermTypeId", this.minDepositTermTypeId);
|
||||
map.put("minDepositTerm", this.minDepositTerm);
|
||||
map.put("maxDepositTermTypeId", this.maxDepositTermTypeId);
|
||||
map.put("maxDepositTerm", this.maxDepositTerm);
|
||||
map.put("depositAmount", this.depositAmount);
|
||||
map.put("preClosurePenalApplicable", this.preClosurePenalApplicable);
|
||||
map.put("inMultiplesOfDepositTerm", this.inMultiplesOfDepositTerm);
|
||||
map.put("inMultiplesOfDepositTermTypeId", this.inMultiplesOfDepositTermTypeId);
|
||||
map.put("preClosurePenalInterest", this.preClosurePenalInterest);
|
||||
map.put("preClosurePenalInterestOnTypeId", this.preClosurePenalInterestOnTypeId);
|
||||
|
||||
if (this.accountingRule.equals(CASH_BASED)) {
|
||||
map.putAll(getAccountMappingForCashBased());
|
||||
}
|
||||
|
||||
String FixedDepositProductCreateJson = new Gson().toJson(map);
|
||||
System.out.println(FixedDepositProductCreateJson);
|
||||
return FixedDepositProductCreateJson;
|
||||
}
|
||||
|
||||
public FixedDepositProductHelper withAccountingRuleAsNone() {
|
||||
this.accountingRule = NONE;
|
||||
return this;
|
||||
}
|
||||
|
||||
public FixedDepositProductHelper withAccountingRuleAsCashBased(final Account[] account_list) {
|
||||
this.accountingRule = CASH_BASED;
|
||||
this.accountList = account_list;
|
||||
return this;
|
||||
}
|
||||
|
||||
private Map<String, String> getAccountMappingForCashBased() {
|
||||
final Map<String, String> map = new HashMap<>();
|
||||
if (accountList != null) {
|
||||
for (int i = 0; i < this.accountList.length; i++) {
|
||||
if (this.accountList[i].getAccountType().equals(Account.AccountType.ASSET)) {
|
||||
final String ID = this.accountList[i].getAccountID().toString();
|
||||
map.put("savingsReferenceAccountId", ID);
|
||||
}
|
||||
if (this.accountList[i].getAccountType().equals(Account.AccountType.LIABILITY)) {
|
||||
final String ID = this.accountList[i].getAccountID().toString();
|
||||
map.put("savingsControlAccountId", ID);
|
||||
map.put("transfersInSuspenseAccountId", ID);
|
||||
}
|
||||
if (this.accountList[i].getAccountType().equals(Account.AccountType.EXPENSE)) {
|
||||
final String ID = this.accountList[i].getAccountID().toString();
|
||||
map.put("interestOnSavingsAccountId", ID);
|
||||
}
|
||||
if (this.accountList[i].getAccountType().equals(Account.AccountType.INCOME)) {
|
||||
final String ID = this.accountList[i].getAccountID().toString();
|
||||
map.put("incomeFromFeeAccountId", ID);
|
||||
map.put("incomeFromPenaltyAccountId", ID);
|
||||
}
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public static Integer createFixedDepositProduct(final String fixedDepositProductCreateJson, final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec) {
|
||||
System.out.println("--------------------- CREATING FIXED DEPOSIT PRODUCT ------------------------");
|
||||
return Utils.performServerPost(requestSpec, responseSpec, CREATE_FIXED_DEPOSIT_PRODUCT_URL, fixedDepositProductCreateJson,
|
||||
CommonConstants.RESPONSE_RESOURCE_ID);
|
||||
}
|
||||
|
||||
public static ArrayList retrieveAllFixedDepositProducts(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
System.out.println("-------------------- RETRIEVING ALL FIXED DEPOSIT PRODUCTS ---------------------");
|
||||
final ArrayList response = Utils.performServerGet(requestSpec, responseSpec, FIXED_DEPOSIT_PRODUCT_URL + "?"
|
||||
+ Utils.TENANT_IDENTIFIER, "");
|
||||
return response;
|
||||
}
|
||||
|
||||
public static HashMap retrieveFixedDepositProductById(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String productId) {
|
||||
System.out.println("------------------------ RETRIEVING FIXED DEPOSIT PRODUCT BY ID ------------------------");
|
||||
final String GET_FD_PRODUCT_BY_ID_URL = FIXED_DEPOSIT_PRODUCT_URL + "/" + productId + "?" + Utils.TENANT_IDENTIFIER;
|
||||
final HashMap response = Utils.performServerGet(requestSpec, responseSpec, GET_FD_PRODUCT_BY_ID_URL, "");
|
||||
return response;
|
||||
}
|
||||
|
||||
public static ArrayList getInterestRateChartSlabsByProductId(final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec, final Integer productId) {
|
||||
System.out.println("-------------------- RETRIEVE INTEREST CHART BY PRODUCT ID ---------------------");
|
||||
final ArrayList response = Utils.performServerGet(requestSpec, responseSpec, INTEREST_CHART_URL + "?productId=" + productId,
|
||||
"chartSlabs");
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common.funds;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
public class FundsHelper {
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private String name;
|
||||
private String externalId;
|
||||
|
||||
private Builder(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Builder externalId(final String externalId) {
|
||||
this.externalId = externalId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public FundsHelper build() {
|
||||
return new FundsHelper(this.name, this.externalId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private String name;
|
||||
private String externalId;
|
||||
private Long resourceId;
|
||||
|
||||
FundsHelper() {
|
||||
super();
|
||||
}
|
||||
|
||||
private FundsHelper(final String name,
|
||||
final String externalId) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.externalId = externalId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getExternalId() {
|
||||
return this.externalId;
|
||||
}
|
||||
|
||||
public Long getResourceId() {
|
||||
return this.resourceId;
|
||||
}
|
||||
|
||||
public String toJSON() {
|
||||
return new Gson().toJson(this);
|
||||
}
|
||||
|
||||
public static FundsHelper fromJSON(final String jsonData) {
|
||||
return new Gson().fromJson(jsonData, FundsHelper.class);
|
||||
}
|
||||
|
||||
public static Builder create(final String name) {
|
||||
return new Builder(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
if (this.name != null) {
|
||||
return this.name.hashCode();
|
||||
}
|
||||
return super.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(o instanceof FundsHelper)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
FundsHelper fh = (FundsHelper)o;
|
||||
|
||||
if (this.name.equals(fh.name)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common.funds;
|
||||
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.gson.Gson;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class FundsResourceHandler {
|
||||
|
||||
private static final String FUNDS_URL = "/fineract-provider/api/v1/funds";
|
||||
private static final String CREATE_FUNDS_URL = FUNDS_URL + "?" + Utils.TENANT_IDENTIFIER;
|
||||
|
||||
public static Integer createFund(final String fundJSON,
|
||||
final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec) {
|
||||
return Utils.performServerPost(requestSpec, responseSpec, CREATE_FUNDS_URL, fundJSON, "resourceId");
|
||||
}
|
||||
|
||||
public static List<FundsHelper> retrieveAllFunds(final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec) {
|
||||
final String URL = FUNDS_URL + "?" + Utils.TENANT_IDENTIFIER;
|
||||
List<HashMap<String, Object>> list = Utils.performServerGet(requestSpec, responseSpec, URL, "");
|
||||
final String jsonData = new Gson().toJson(list);
|
||||
return new Gson().fromJson(jsonData, new TypeToken<List<FundsHelper>>(){}.getType());
|
||||
}
|
||||
|
||||
public static String retrieveFund(final Long fundID,
|
||||
final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec) {
|
||||
final String URL = FUNDS_URL + "/" + fundID + "?" + Utils.TENANT_IDENTIFIER;
|
||||
final HashMap response = Utils.performServerGet(requestSpec, responseSpec, URL, "");
|
||||
return new Gson().toJson(response);
|
||||
}
|
||||
|
||||
public static FundsHelper updateFund(final Long fundID,
|
||||
final String newName,
|
||||
final String newExternalId,
|
||||
final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec) {
|
||||
FundsHelper fh = FundsHelper.create(newName).externalId(newExternalId).build();
|
||||
String updateJSON = new Gson().toJson(fh);
|
||||
|
||||
final String URL = FUNDS_URL + "/" + fundID + "?" + Utils.TENANT_IDENTIFIER;
|
||||
final HashMap<String, String> response = Utils.performServerPut(requestSpec, responseSpec, URL, updateJSON, "changes");
|
||||
final String jsonData = new Gson().toJson(response);
|
||||
return new Gson().fromJson(jsonData, FundsHelper.class);
|
||||
}
|
||||
|
||||
}
|
||||
+330
@@ -0,0 +1,330 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common.loans;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
public class LoanApplicationTestBuilder {
|
||||
|
||||
private static final String DAYS = "0";
|
||||
private static final String WEEKS = "1";
|
||||
private static final String MONTHS = "2";
|
||||
private static final String YEARS = "3";
|
||||
private static final String DECLINING_BALANCE = "0";
|
||||
private static final String FLAT_BALANCE = "1";
|
||||
private static final String EQUAL_PRINCIPAL_PAYMENTS = "0";
|
||||
private static final String EQUAL_INSTALLMENTS = "1";
|
||||
private static final String CALCULATION_PERIOD_SAME_AS_REPAYMENT_PERIOD = "1";
|
||||
public static final String DEFAULT_STRATEGY = "1";
|
||||
public static final String RBI_INDIA_STRATEGY = "4";
|
||||
|
||||
private String principal = "10,000";
|
||||
private String loanTermFrequency = "";
|
||||
private String loanTermFrequencyType = "";
|
||||
private String numberOfRepayment = "0";
|
||||
private String repaymentPeriod = "0";
|
||||
private String repaymentFrequencyType = "";
|
||||
|
||||
private String interestRate = "2";
|
||||
private String interestType = FLAT_BALANCE;
|
||||
private String amortizationType = EQUAL_PRINCIPAL_PAYMENTS;
|
||||
private String interestCalculationPeriodType = CALCULATION_PERIOD_SAME_AS_REPAYMENT_PERIOD;
|
||||
private String transactionProcessingID = DEFAULT_STRATEGY;
|
||||
private String expectedDisbursmentDate = "";
|
||||
private String submittedOnDate = "";
|
||||
private String loanType = "individual";
|
||||
private String fixedEmiAmount = "10000";
|
||||
private String maxOutstandingLoanBalance = "36000";
|
||||
private String graceOnPrincipalPayment = null;
|
||||
private String graceOnInterestPayment = null;
|
||||
@SuppressWarnings("rawtypes")
|
||||
private List<HashMap> disbursementData = null;
|
||||
@SuppressWarnings("rawtypes")
|
||||
private List<HashMap> charges = new ArrayList<>();
|
||||
private String recalculationRestFrequencyDate = null;
|
||||
private String recalculationCompoundingFrequencyDate = null;
|
||||
private String repaymentsStartingFromDate = null;
|
||||
|
||||
private String calendarId;
|
||||
private boolean syncDisbursementWithMeeting = false;
|
||||
|
||||
public String build(final String clientID, final String groupID, final String loanProductId, final String savingsID) {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("groupId", groupID);
|
||||
map.put("clientId", clientID);
|
||||
if (this.loanType == "jlg") {
|
||||
if (this.calendarId != null) {
|
||||
map.put("calendarId", this.calendarId);
|
||||
}
|
||||
map.put("syncDisbursementWithMeeting", this.syncDisbursementWithMeeting);
|
||||
}
|
||||
return build(map, loanProductId, savingsID);
|
||||
}
|
||||
|
||||
public String build(final String ID, final String loanProductId, final String savingsID) {
|
||||
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
|
||||
if (this.loanType == "group") {
|
||||
map.put("groupId", ID);
|
||||
} else {
|
||||
map.put("clientId", ID);
|
||||
}
|
||||
return build(map, loanProductId, savingsID);
|
||||
}
|
||||
|
||||
private String build(final HashMap<String, Object> map, final String loanProductId, final String savingsID) {
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("locale", "en_GB");
|
||||
map.put("productId", loanProductId);
|
||||
map.put("principal", this.principal);
|
||||
map.put("loanTermFrequency", this.loanTermFrequency);
|
||||
map.put("loanTermFrequencyType", this.loanTermFrequencyType);
|
||||
map.put("numberOfRepayments", this.numberOfRepayment);
|
||||
map.put("repaymentEvery", this.repaymentPeriod);
|
||||
map.put("repaymentFrequencyType", this.repaymentFrequencyType);
|
||||
map.put("interestRatePerPeriod", this.interestRate);
|
||||
map.put("amortizationType", this.amortizationType);
|
||||
map.put("interestType", this.interestType);
|
||||
map.put("interestCalculationPeriodType", this.interestCalculationPeriodType);
|
||||
map.put("transactionProcessingStrategyId", this.transactionProcessingID);
|
||||
map.put("expectedDisbursementDate", this.expectedDisbursmentDate);
|
||||
map.put("submittedOnDate", this.submittedOnDate);
|
||||
map.put("loanType", this.loanType);
|
||||
if (repaymentsStartingFromDate != null) {
|
||||
map.put("repaymentsStartingFromDate", this.repaymentsStartingFromDate);
|
||||
}
|
||||
if (charges != null) {
|
||||
map.put("charges", charges);
|
||||
}
|
||||
if (savingsID != null) {
|
||||
map.put("linkAccountId", savingsID);
|
||||
}
|
||||
|
||||
if (graceOnPrincipalPayment != null) {
|
||||
map.put("graceOnPrincipalPayment", graceOnPrincipalPayment);
|
||||
}
|
||||
|
||||
if (graceOnInterestPayment != null) {
|
||||
map.put("graceOnInterestPayment", graceOnInterestPayment);
|
||||
}
|
||||
|
||||
if (disbursementData != null) {
|
||||
map.put("disbursementData", disbursementData);
|
||||
map.put("fixedEmiAmount", fixedEmiAmount);
|
||||
map.put("maxOutstandingLoanBalance", maxOutstandingLoanBalance);
|
||||
|
||||
}
|
||||
if (recalculationRestFrequencyDate != null) {
|
||||
map.put("recalculationRestFrequencyDate", recalculationRestFrequencyDate);
|
||||
}
|
||||
if (recalculationCompoundingFrequencyDate != null) {
|
||||
map.put("recalculationCompoundingFrequencyDate", recalculationCompoundingFrequencyDate);
|
||||
}
|
||||
|
||||
System.out.println("Loan Application request : " + map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public LoanApplicationTestBuilder withPrincipal(final String principalAmount) {
|
||||
this.principal = principalAmount;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanApplicationTestBuilder withLoanTermFrequency(final String loanToBePayedDuration) {
|
||||
this.loanTermFrequency = loanToBePayedDuration;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanApplicationTestBuilder withLoanTermFrequencyAsDays() {
|
||||
this.loanTermFrequencyType = DAYS;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanApplicationTestBuilder withLoanTermFrequencyAsMonths() {
|
||||
this.loanTermFrequencyType = MONTHS;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanApplicationTestBuilder withLoanTermFrequencyAsWeeks() {
|
||||
this.loanTermFrequencyType = WEEKS;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanApplicationTestBuilder withLoanTermFrequencyAsYears() {
|
||||
this.loanTermFrequencyType = YEARS;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanApplicationTestBuilder withNumberOfRepayments(final String numberOfRepayments) {
|
||||
this.numberOfRepayment = numberOfRepayments;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanApplicationTestBuilder withRepaymentEveryAfter(final String repaymentPeriod) {
|
||||
this.repaymentPeriod = repaymentPeriod;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanApplicationTestBuilder withRepaymentFrequencyTypeAsDays() {
|
||||
this.repaymentFrequencyType = DAYS;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanApplicationTestBuilder withRepaymentFrequencyTypeAsMonths() {
|
||||
this.repaymentFrequencyType = MONTHS;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanApplicationTestBuilder withRepaymentFrequencyTypeAsWeeks() {
|
||||
this.repaymentFrequencyType = WEEKS;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanApplicationTestBuilder withRepaymentFrequencyTypeAsYear() {
|
||||
this.repaymentFrequencyType = YEARS;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanApplicationTestBuilder withInterestRatePerPeriod(final String interestRate) {
|
||||
this.interestRate = interestRate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanApplicationTestBuilder withInterestTypeAsFlatBalance() {
|
||||
this.interestType = FLAT_BALANCE;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanApplicationTestBuilder withInterestTypeAsDecliningBalance() {
|
||||
this.interestType = DECLINING_BALANCE;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanApplicationTestBuilder withAmortizationTypeAsEqualInstallments() {
|
||||
this.amortizationType = EQUAL_INSTALLMENTS;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanApplicationTestBuilder withAmortizationTypeAsEqualPrincipalPayments() {
|
||||
this.amortizationType = EQUAL_PRINCIPAL_PAYMENTS;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanApplicationTestBuilder withInterestCalculationPeriodTypeSameAsRepaymentPeriod() {
|
||||
this.interestCalculationPeriodType = CALCULATION_PERIOD_SAME_AS_REPAYMENT_PERIOD;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanApplicationTestBuilder withInterestCalculationPeriodTypeAsDays() {
|
||||
this.interestCalculationPeriodType = DAYS;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanApplicationTestBuilder withExpectedDisbursementDate(final String expectedDisbursementDate) {
|
||||
this.expectedDisbursmentDate = expectedDisbursementDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanApplicationTestBuilder withSubmittedOnDate(final String loanApplicationSubmittedDate) {
|
||||
this.submittedOnDate = loanApplicationSubmittedDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanApplicationTestBuilder withCharges(final List<HashMap> charges) {
|
||||
this.charges = charges;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanApplicationTestBuilder withLoanType(final String loanType) {
|
||||
this.loanType = loanType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanApplicationTestBuilder withPrincipalGrace(final String graceOnPrincipalPayment) {
|
||||
this.graceOnPrincipalPayment = graceOnPrincipalPayment;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanApplicationTestBuilder withInterestGrace(final String graceOnInterestPayment) {
|
||||
this.graceOnInterestPayment = graceOnInterestPayment;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanApplicationTestBuilder withTranches(final List<HashMap> disbursementData) {
|
||||
this.disbursementData = disbursementData;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanApplicationTestBuilder withwithRepaymentStrategy(final String transactionProcessingStrategy) {
|
||||
this.transactionProcessingID = transactionProcessingStrategy;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanApplicationTestBuilder withRestFrequencyDate(final String recalculationRestFrequencyDate) {
|
||||
this.recalculationRestFrequencyDate = recalculationRestFrequencyDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanApplicationTestBuilder withCompoundingFrequencyDate(final String recalculationCompoundingFrequencyDate) {
|
||||
this.recalculationCompoundingFrequencyDate = recalculationCompoundingFrequencyDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanApplicationTestBuilder withFirstRepaymentDate(final String firstRepaymentDate) {
|
||||
this.repaymentsStartingFromDate = firstRepaymentDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* calendarID parameter is used to sync repayments with group meetings,
|
||||
* especially when using jlg loans
|
||||
*
|
||||
* @param calendarId
|
||||
* the id of the calender record of the group meeting from
|
||||
* m_calendar table
|
||||
* @return
|
||||
*/
|
||||
public LoanApplicationTestBuilder withCalendarID(String calendarId) {
|
||||
this.calendarId = calendarId;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* This indicator is used mainly for jlg loans when we want to sync
|
||||
* disbursement with the group meetings (it seems that if we do use this
|
||||
* parameter we should also use calendarID to sync repayment with group
|
||||
* meetings)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public LoanApplicationTestBuilder withSyncDisbursementWithMeetin() {
|
||||
this.syncDisbursementWithMeeting = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanApplicationTestBuilder withFixedEmiAmount(final String installmentAmount) {
|
||||
this.fixedEmiAmount = installmentAmount;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common.loans;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class LoanDisbursementTestBuilder {
|
||||
|
||||
String dueDate = null;
|
||||
Float totalOriginalDueForPeriod = null;
|
||||
Float totalOutstandingForPeriod = null;
|
||||
Float interestOutstanding = null;
|
||||
Float principalOutstanding = null;
|
||||
Float principalLoanBalanceOutstanding = null;
|
||||
Float principalDue = null;
|
||||
Float principalOriginalDue = null;
|
||||
String fromDate = null;
|
||||
|
||||
public LoanDisbursementTestBuilder(String dueDate,Float totalOriginalDueForPeriod,Float totalOutstandingForPeriod,
|
||||
Float interestOutstanding, Float principalOutstanding, Float principalLoanBalanceOutstanding, Float principalDue,
|
||||
Float principalOriginalDue, String fromDate) {
|
||||
this.dueDate = dueDate;
|
||||
this.totalOriginalDueForPeriod = totalOriginalDueForPeriod;
|
||||
this.totalOutstandingForPeriod = totalOutstandingForPeriod;
|
||||
this.interestOutstanding = interestOutstanding;
|
||||
this.principalOutstanding = principalOutstanding;
|
||||
this.principalLoanBalanceOutstanding = principalLoanBalanceOutstanding;
|
||||
this.principalDue = principalDue;
|
||||
this.principalOriginalDue = principalOriginalDue;
|
||||
this.fromDate = fromDate;
|
||||
}
|
||||
|
||||
public String getDueDate() {
|
||||
return this.dueDate;
|
||||
}
|
||||
|
||||
public Float getTotalOriginalDueForPeriod() {
|
||||
return this.totalOriginalDueForPeriod;
|
||||
}
|
||||
|
||||
public Float getTotalOutstandingForPeriod() {
|
||||
return this.totalOutstandingForPeriod;
|
||||
}
|
||||
|
||||
public Float getInterestOutstanding() {
|
||||
return this.interestOutstanding;
|
||||
}
|
||||
|
||||
public Float getPrincipalOutstanding() {
|
||||
return this.principalOutstanding;
|
||||
}
|
||||
|
||||
public Float getPrincipalLoanBalanceOutstanding() {
|
||||
return this.principalLoanBalanceOutstanding;
|
||||
}
|
||||
|
||||
public Float getPrincipalDue() {
|
||||
return this.principalDue;
|
||||
}
|
||||
|
||||
public Float getPrincipalOriginalDue() {
|
||||
return this.principalOriginalDue;
|
||||
}
|
||||
|
||||
public String getFromDate() {
|
||||
return this.fromDate;
|
||||
}
|
||||
|
||||
/*public HashMap<String, String> build(String dueDate,String totalOriginalDueForPeriod,String totalOutstandingForPeriod,
|
||||
String interestOutstanding, String principalOutstanding, String principalLoanBalanceOutstanding, String principalDue,
|
||||
String principalOriginalDue, String fromDate) {
|
||||
HashMap<String, String> expectedRepaymentSchedule = new HashMap<String, String>();
|
||||
expectedRepaymentSchedule.put("dueDate", dueDate);
|
||||
expectedRepaymentSchedule.put("totalOriginalDueForPeriod",
|
||||
totalOriginalDueForPeriod);
|
||||
expectedRepaymentSchedule.put("totalOutstandingForPeriod",
|
||||
totalOutstandingForPeriod);
|
||||
expectedRepaymentSchedule.put("interestOutstanding", interestOutstanding);
|
||||
expectedRepaymentSchedule.put("principalOutstanding",
|
||||
principalOutstanding);
|
||||
expectedRepaymentSchedule.put("principalLoanBalanceOutstanding",
|
||||
principalLoanBalanceOutstanding);
|
||||
expectedRepaymentSchedule.put("principalDue", principalDue);
|
||||
expectedRepaymentSchedule.put("principalOriginalDue",
|
||||
principalOriginalDue);
|
||||
expectedRepaymentSchedule.put("fromDate", fromDate);
|
||||
|
||||
return expectedRepaymentSchedule;
|
||||
}*/
|
||||
}
|
||||
+493
@@ -0,0 +1,493 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common.loans;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.accounting.Account;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
public class LoanProductTestBuilder {
|
||||
|
||||
private static final String LOCALE = "en_GB";
|
||||
private static final String USD = "USD";
|
||||
private static final String DAYS = "0";
|
||||
private static final String WEEK = "1";
|
||||
private static final String MONTHS = "2";
|
||||
private static final String YEARS = "3";
|
||||
private static final String CALCULATION_PERIOD_SAME_AS_REPAYMENT_PERIOD = "1";
|
||||
private static final String EQUAL_PRINCIPAL_PAYMENTS = "0";
|
||||
private static final String EQUAL_INSTALLMENTS = "1";
|
||||
private static final String DECLINING_BALANCE = "0";
|
||||
private static final String FLAT_BALANCE = "1";
|
||||
public static final String DEFAULT_STRATEGY = "1";
|
||||
// private static final String HEAVENS_FAMILY_STRATEGY ="2";
|
||||
// private static final String CREO_CORE_STRATEGY ="3";
|
||||
public static final String RBI_INDIA_STRATEGY = "4";
|
||||
|
||||
public static final String RECALCULATION_FREQUENCY_TYPE_SAME_AS_REPAYMENT_PERIOD = "1";
|
||||
public static final String RECALCULATION_FREQUENCY_TYPE_DAILY = "2";
|
||||
public static final String RECALCULATION_FREQUENCY_TYPE_WEEKLY = "3";
|
||||
public static final String RECALCULATION_FREQUENCY_TYPE_MONTHLY = "4";
|
||||
|
||||
public static final String RECALCULATION_STRATEGY_RESCHEDULE_NEXT_REPAYMENTS = "1";
|
||||
public static final String RECALCULATION_STRATEGY_REDUCE_NUMBER_OF_INSTALLMENTS = "2";
|
||||
public static final String RECALCULATION_STRATEGY_REDUCE_EMI_AMOUN = "3";
|
||||
|
||||
public static final String RECALCULATION_COMPOUNDING_METHOD_NONE = "0";
|
||||
public static final String RECALCULATION_COMPOUNDING_METHOD_INTEREST = "1";
|
||||
public static final String RECALCULATION_COMPOUNDING_METHOD_FEE = "2";
|
||||
public static final String RECALCULATION_COMPOUNDING_METHOD_INTEREST_AND_FEE = "3";
|
||||
|
||||
private static final String NONE = "1";
|
||||
private static final String CASH_BASED = "2";
|
||||
private static final String ACCRUAL_PERIODIC = "3";
|
||||
private static final String ACCRUAL_UPFRONT = "4";
|
||||
|
||||
public static final String INTEREST_APPLICABLE_STRATEGY_REST_DATE = "2";
|
||||
public static final String INTEREST_APPLICABLE_STRATEGY_ON_PRE_CLOSE_DATE = "1";
|
||||
|
||||
private String digitsAfterDecimal = "2";
|
||||
private String inMultiplesOf = "0";
|
||||
|
||||
private String nameOfLoanProduct = Utils.randomNameGenerator("LOAN_PRODUCT_", 6);
|
||||
private final String shortName = Utils.randomNameGenerator("", 4);
|
||||
private String principal = "10000.00";
|
||||
private String numberOfRepayments = "5";
|
||||
private String repaymentFrequency = MONTHS;
|
||||
private String repaymentPeriod = "1";
|
||||
private String interestRatePerPeriod = "2";
|
||||
private String interestRateFrequencyType = MONTHS;
|
||||
private String interestType = FLAT_BALANCE;
|
||||
private String overdueDaysForNPA = "5";
|
||||
private String interestCalculationPeriodType = CALCULATION_PERIOD_SAME_AS_REPAYMENT_PERIOD;
|
||||
private String inArrearsTolerance = "0";
|
||||
private String transactionProcessingStrategy = DEFAULT_STRATEGY;
|
||||
private String accountingRule = NONE;
|
||||
private final String currencyCode = USD;
|
||||
private String amortizationType = EQUAL_INSTALLMENTS;
|
||||
private String minPrincipal = "1000.00";
|
||||
private String maxPrincipal = "10000000.00";
|
||||
private Account[] accountList = null;
|
||||
|
||||
private Boolean multiDisburseLoan = false;
|
||||
private final String outstandingLoanBalance = "35000";
|
||||
private final String maxTrancheCount = "3";
|
||||
|
||||
private Boolean isInterestRecalculationEnabled = false;
|
||||
private String daysInYearType = "1";
|
||||
private String daysInMonthType = "1";
|
||||
private String interestRecalculationCompoundingMethod = "0";
|
||||
private String preCloseInterestCalculationStrategy = INTEREST_APPLICABLE_STRATEGY_ON_PRE_CLOSE_DATE;
|
||||
private String rescheduleStrategyMethod = "1";
|
||||
private String recalculationRestFrequencyType = "1";
|
||||
private String recalculationRestFrequencyInterval = "0";
|
||||
private String recalculationRestFrequencyDate = null;
|
||||
private String recalculationCompoundingFrequencyType = null;
|
||||
private String recalculationCompoundingFrequencyInterval = null;
|
||||
private String recalculationCompoundingFrequencyDate = null;
|
||||
private String minimumDaysBetweenDisbursalAndFirstRepayment = null;
|
||||
private Boolean holdGuaranteeFunds = null;
|
||||
private String mandatoryGuarantee = null;
|
||||
private String minimumGuaranteeFromOwnFunds = null;
|
||||
private String minimumGuaranteeFromGuarantor = null;
|
||||
private String isArrearsBasedOnOriginalSchedule = null;
|
||||
private String graceOnPrincipalPayment = "1";
|
||||
private String graceOnInterestPayment = "1";
|
||||
private JsonObject allowAttributeOverrides = null;
|
||||
private Boolean allowPartialPeriodInterestCalcualtion = false;
|
||||
|
||||
private Boolean allowVariableInstallments = Boolean.FALSE;
|
||||
private Integer minimumGap;
|
||||
private Integer maximumGap;
|
||||
|
||||
public String build(final String chargeId) {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
|
||||
if (chargeId != null) {
|
||||
List<HashMap<String, String>> charges = new ArrayList<>();
|
||||
HashMap<String, String> chargeMap = new HashMap<>();
|
||||
chargeMap.put("id", chargeId);
|
||||
charges.add(chargeMap);
|
||||
map.put("charges", charges);
|
||||
}
|
||||
map.put("name", this.nameOfLoanProduct);
|
||||
map.put("shortName", this.shortName);
|
||||
map.put("currencyCode", this.currencyCode);
|
||||
map.put("locale", LOCALE);
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("digitsAfterDecimal", digitsAfterDecimal);
|
||||
map.put("inMultiplesOf", inMultiplesOf);
|
||||
map.put("principal", this.principal);
|
||||
map.put("numberOfRepayments", this.numberOfRepayments);
|
||||
map.put("repaymentEvery", this.repaymentPeriod);
|
||||
map.put("repaymentFrequencyType", this.repaymentFrequency);
|
||||
map.put("interestRatePerPeriod", this.interestRatePerPeriod);
|
||||
map.put("interestRateFrequencyType", this.interestRateFrequencyType);
|
||||
map.put("amortizationType", this.amortizationType);
|
||||
map.put("interestType", this.interestType);
|
||||
map.put("interestCalculationPeriodType", this.interestCalculationPeriodType);
|
||||
map.put("inArrearsTolerance", this.inArrearsTolerance);
|
||||
map.put("transactionProcessingStrategyId", this.transactionProcessingStrategy);
|
||||
map.put("accountingRule", this.accountingRule);
|
||||
map.put("minPrincipal", this.minPrincipal);
|
||||
map.put("maxPrincipal", this.maxPrincipal);
|
||||
map.put("overdueDaysForNPA", this.overdueDaysForNPA);
|
||||
if (this.minimumDaysBetweenDisbursalAndFirstRepayment != null) {
|
||||
map.put("minimumDaysBetweenDisbursalAndFirstRepayment", this.minimumDaysBetweenDisbursalAndFirstRepayment);
|
||||
}
|
||||
if (multiDisburseLoan) {
|
||||
map.put("multiDisburseLoan", this.multiDisburseLoan);
|
||||
map.put("maxTrancheCount", this.maxTrancheCount);
|
||||
map.put("outstandingLoanBalance", this.outstandingLoanBalance);
|
||||
}
|
||||
|
||||
if (this.accountingRule.equals(ACCRUAL_UPFRONT) || this.accountingRule.equals(ACCRUAL_PERIODIC)) {
|
||||
map.putAll(getAccountMappingForAccrualBased());
|
||||
} else if (this.accountingRule.equals(CASH_BASED)) {
|
||||
map.putAll(getAccountMappingForCashBased());
|
||||
}
|
||||
map.put("daysInMonthType", this.daysInMonthType);
|
||||
map.put("daysInYearType", this.daysInYearType);
|
||||
map.put("isInterestRecalculationEnabled", this.isInterestRecalculationEnabled);
|
||||
if (this.isInterestRecalculationEnabled) {
|
||||
map.put("interestRecalculationCompoundingMethod", this.interestRecalculationCompoundingMethod);
|
||||
map.put("rescheduleStrategyMethod", this.rescheduleStrategyMethod);
|
||||
map.put("recalculationRestFrequencyType", recalculationRestFrequencyType);
|
||||
map.put("recalculationRestFrequencyInterval", recalculationRestFrequencyInterval);
|
||||
map.put("recalculationRestFrequencyDate", recalculationRestFrequencyDate);
|
||||
if (!RECALCULATION_COMPOUNDING_METHOD_NONE.equals(this.interestRecalculationCompoundingMethod)) {
|
||||
map.put("recalculationCompoundingFrequencyType", recalculationCompoundingFrequencyType);
|
||||
map.put("recalculationCompoundingFrequencyInterval", recalculationCompoundingFrequencyInterval);
|
||||
map.put("recalculationCompoundingFrequencyDate", recalculationCompoundingFrequencyDate);
|
||||
}
|
||||
map.put("preClosureInterestCalculationStrategy", preCloseInterestCalculationStrategy);
|
||||
if (isArrearsBasedOnOriginalSchedule != null) {
|
||||
map.put("isArrearsBasedOnOriginalSchedule", isArrearsBasedOnOriginalSchedule);
|
||||
}
|
||||
}
|
||||
if (holdGuaranteeFunds != null) {
|
||||
map.put("holdGuaranteeFunds", this.holdGuaranteeFunds);
|
||||
if (this.holdGuaranteeFunds) {
|
||||
map.put("mandatoryGuarantee", this.mandatoryGuarantee);
|
||||
map.put("minimumGuaranteeFromGuarantor", this.minimumGuaranteeFromGuarantor);
|
||||
map.put("minimumGuaranteeFromOwnFunds", this.minimumGuaranteeFromOwnFunds);
|
||||
}
|
||||
}
|
||||
map.put("graceOnPrincipalPayment", graceOnPrincipalPayment);
|
||||
map.put("graceOnInterestPayment", graceOnInterestPayment);
|
||||
if (allowAttributeOverrides != null) {
|
||||
map.put("allowAttributeOverrides", this.allowAttributeOverrides);
|
||||
}
|
||||
map.put("allowPartialPeriodInterestCalcualtion", this.allowPartialPeriodInterestCalcualtion);
|
||||
map.put("allowVariableInstallments", allowVariableInstallments) ;
|
||||
if(allowVariableInstallments) {
|
||||
map.put("minimumGap", minimumGap) ;
|
||||
map.put("maximumGap", maximumGap) ;
|
||||
}
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public LoanProductTestBuilder withMinPrincipal(final String minPrincipal) {
|
||||
this.minPrincipal = minPrincipal;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanProductTestBuilder withMaxPrincipal(final String maxPrincipal) {
|
||||
this.maxPrincipal = maxPrincipal;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanProductTestBuilder withLoanName(final String loanName) {
|
||||
this.nameOfLoanProduct = loanName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanProductTestBuilder withPrincipal(final String principal) {
|
||||
this.principal = principal;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanProductTestBuilder withNumberOfRepayments(final String numberOfRepayment) {
|
||||
this.numberOfRepayments = numberOfRepayment;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanProductTestBuilder withRepaymentTypeAsMonth() {
|
||||
this.repaymentFrequency = MONTHS;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanProductTestBuilder withRepaymentTypeAsWeek() {
|
||||
this.repaymentFrequency = WEEK;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanProductTestBuilder withRepaymentTypeAsDays() {
|
||||
this.repaymentFrequency = DAYS;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanProductTestBuilder withRepaymentAfterEvery(final String repaymentAfterEvery) {
|
||||
this.repaymentPeriod = repaymentAfterEvery;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanProductTestBuilder withInterestRateFrequencyTypeAsMonths() {
|
||||
this.interestRateFrequencyType = MONTHS;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanProductTestBuilder withInterestRateFrequencyTypeAsYear() {
|
||||
this.interestRateFrequencyType = YEARS;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanProductTestBuilder withinterestRatePerPeriod(final String interestRatePerPeriod) {
|
||||
this.interestRatePerPeriod = interestRatePerPeriod;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanProductTestBuilder withAmortizationTypeAsEqualPrincipalPayment() {
|
||||
this.amortizationType = EQUAL_PRINCIPAL_PAYMENTS;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanProductTestBuilder withAmortizationTypeAsEqualInstallments() {
|
||||
this.amortizationType = EQUAL_INSTALLMENTS;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanProductTestBuilder withInterestTypeAsFlat() {
|
||||
this.interestType = FLAT_BALANCE;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanProductTestBuilder withInterestTypeAsDecliningBalance() {
|
||||
this.interestType = DECLINING_BALANCE;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanProductTestBuilder withOverdueDaysForNPA(String days) {
|
||||
this.overdueDaysForNPA = days;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanProductTestBuilder withInterestCalculationPeriodTypeAsDays() {
|
||||
this.interestCalculationPeriodType = DAYS;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanProductTestBuilder withInterestCalculationPeriodTypeAsRepaymentPeriod(final Boolean allowPartialPeriodInterestCalcualtion) {
|
||||
this.interestCalculationPeriodType = CALCULATION_PERIOD_SAME_AS_REPAYMENT_PERIOD;
|
||||
this.allowPartialPeriodInterestCalcualtion = allowPartialPeriodInterestCalcualtion;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanProductTestBuilder withInArrearsTolerance(final String amountCanBeWaved) {
|
||||
this.inArrearsTolerance = amountCanBeWaved;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanProductTestBuilder withAccountingRuleAsNone() {
|
||||
this.accountingRule = NONE;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanProductTestBuilder withAccountingRuleAsCashBased(final Account[] account_list) {
|
||||
this.accountingRule = CASH_BASED;
|
||||
this.accountList = account_list;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanProductTestBuilder withAccountingRuleUpfrontAccrual(final Account[] account_list) {
|
||||
this.accountingRule = ACCRUAL_UPFRONT;
|
||||
this.accountList = account_list;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanProductTestBuilder withAccountingRulePeriodicAccrual(final Account[] account_list) {
|
||||
this.accountingRule = ACCRUAL_PERIODIC;
|
||||
this.accountList = account_list;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanProductTestBuilder withTranches(boolean multiDisburseLoan) {
|
||||
this.multiDisburseLoan = multiDisburseLoan;
|
||||
return this;
|
||||
}
|
||||
|
||||
private Map<String, String> getAccountMappingForCashBased() {
|
||||
final Map<String, String> map = new HashMap<>();
|
||||
for (int i = 0; i < this.accountList.length; i++) {
|
||||
if (this.accountList[i].getAccountType().equals(Account.AccountType.ASSET)) {
|
||||
final String ID = this.accountList[i].getAccountID().toString();
|
||||
map.put("fundSourceAccountId", ID);
|
||||
map.put("loanPortfolioAccountId", ID);
|
||||
map.put("transfersInSuspenseAccountId", ID);
|
||||
}
|
||||
if (this.accountList[i].getAccountType().equals(Account.AccountType.INCOME)) {
|
||||
final String ID = this.accountList[i].getAccountID().toString();
|
||||
map.put("interestOnLoanAccountId", ID);
|
||||
map.put("incomeFromFeeAccountId", ID);
|
||||
map.put("incomeFromPenaltyAccountId", ID);
|
||||
map.put("incomeFromRecoveryAccountId", ID);
|
||||
}
|
||||
if (this.accountList[i].getAccountType().equals(Account.AccountType.EXPENSE)) {
|
||||
final String ID = this.accountList[i].getAccountID().toString();
|
||||
map.put("writeOffAccountId", ID);
|
||||
}
|
||||
if (this.accountList[i].getAccountType().equals(Account.AccountType.LIABILITY)) {
|
||||
final String ID = this.accountList[i].getAccountID().toString();
|
||||
map.put("overpaymentLiabilityAccountId", ID);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private Map<String, String> getAccountMappingForAccrualBased() {
|
||||
final Map<String, String> map = new HashMap<>();
|
||||
for (int i = 0; i < this.accountList.length; i++) {
|
||||
if (this.accountList[i].getAccountType().equals(Account.AccountType.ASSET)) {
|
||||
final String ID = this.accountList[i].getAccountID().toString();
|
||||
map.put("fundSourceAccountId", ID);
|
||||
map.put("loanPortfolioAccountId", ID);
|
||||
map.put("transfersInSuspenseAccountId", ID);
|
||||
map.put("receivableInterestAccountId", ID);
|
||||
map.put("receivableFeeAccountId", ID);
|
||||
map.put("receivablePenaltyAccountId", ID);
|
||||
|
||||
}
|
||||
if (this.accountList[i].getAccountType().equals(Account.AccountType.INCOME)) {
|
||||
final String ID = this.accountList[i].getAccountID().toString();
|
||||
map.put("interestOnLoanAccountId", ID);
|
||||
map.put("incomeFromFeeAccountId", ID);
|
||||
map.put("incomeFromPenaltyAccountId", ID);
|
||||
map.put("incomeFromRecoveryAccountId", ID);
|
||||
}
|
||||
if (this.accountList[i].getAccountType().equals(Account.AccountType.EXPENSE)) {
|
||||
final String ID = this.accountList[i].getAccountID().toString();
|
||||
map.put("writeOffAccountId", ID);
|
||||
}
|
||||
if (this.accountList[i].getAccountType().equals(Account.AccountType.LIABILITY)) {
|
||||
final String ID = this.accountList[i].getAccountID().toString();
|
||||
map.put("overpaymentLiabilityAccountId", ID);
|
||||
}
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
public LoanProductTestBuilder withAccounting(final String accountingRule, final Account[] account_list) {
|
||||
this.accountingRule = accountingRule;
|
||||
this.accountList = account_list;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanProductTestBuilder currencyDetails(final String digitsAfterDecimal, final String inMultiplesOf) {
|
||||
this.digitsAfterDecimal = digitsAfterDecimal;
|
||||
this.inMultiplesOf = inMultiplesOf;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanProductTestBuilder withRepaymentStrategy(final String transactionProcessingStrategy) {
|
||||
this.transactionProcessingStrategy = transactionProcessingStrategy;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanProductTestBuilder withDaysInMonth(final String daysInMonthType) {
|
||||
this.daysInMonthType = daysInMonthType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanProductTestBuilder withDaysInYear(final String daysInYearType) {
|
||||
this.daysInYearType = daysInYearType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanProductTestBuilder withInterestRecalculationDetails(final String interestRecalculationCompoundingMethod,
|
||||
final String rescheduleStrategyMethod, String preCloseInterestCalculationStrategy) {
|
||||
this.isInterestRecalculationEnabled = true;
|
||||
this.interestRecalculationCompoundingMethod = interestRecalculationCompoundingMethod;
|
||||
this.rescheduleStrategyMethod = rescheduleStrategyMethod;
|
||||
this.preCloseInterestCalculationStrategy = preCloseInterestCalculationStrategy;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanProductTestBuilder withInterestRecalculationRestFrequencyDetails(final String recalculationRestFrequencyType,
|
||||
final String recalculationRestFrequencyInterval, final String recalculationRestFrequencyDate) {
|
||||
this.isInterestRecalculationEnabled = true;
|
||||
this.recalculationRestFrequencyType = recalculationRestFrequencyType;
|
||||
this.recalculationRestFrequencyInterval = recalculationRestFrequencyInterval;
|
||||
this.recalculationRestFrequencyDate = recalculationRestFrequencyDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanProductTestBuilder withInterestRecalculationCompoundingFrequencyDetails(final String recalculationCompoundingFrequencyType,
|
||||
final String recalculationCompoundingFrequencyInterval, final String recalculationCompoundingFrequencyDate) {
|
||||
this.isInterestRecalculationEnabled = true;
|
||||
this.recalculationCompoundingFrequencyType = recalculationCompoundingFrequencyType;
|
||||
this.recalculationCompoundingFrequencyInterval = recalculationCompoundingFrequencyInterval;
|
||||
this.recalculationCompoundingFrequencyDate = recalculationCompoundingFrequencyDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanProductTestBuilder withMinimumDaysBetweenDisbursalAndFirstRepayment(final String minimumDaysBetweenDisbursalAndFirstRepayment) {
|
||||
this.minimumDaysBetweenDisbursalAndFirstRepayment = minimumDaysBetweenDisbursalAndFirstRepayment;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanProductTestBuilder withArrearsConfiguration() {
|
||||
this.isArrearsBasedOnOriginalSchedule = "true";
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanProductTestBuilder withOnHoldFundDetails(final String mandatoryGuarantee, final String minimumGuaranteeFromGuarantor,
|
||||
final String minimumGuaranteeFromOwnFunds) {
|
||||
this.holdGuaranteeFunds = true;
|
||||
this.mandatoryGuarantee = mandatoryGuarantee;
|
||||
this.minimumGuaranteeFromGuarantor = minimumGuaranteeFromGuarantor;
|
||||
this.minimumGuaranteeFromOwnFunds = minimumGuaranteeFromOwnFunds;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanProductTestBuilder withMoratorium(String principal, String interest) {
|
||||
this.graceOnPrincipalPayment = principal;
|
||||
this.graceOnInterestPayment = interest;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanProductTestBuilder withLoanProductConfiguration(JsonObject loanProductConfigurableAttributes) {
|
||||
this.allowAttributeOverrides = loanProductConfigurableAttributes;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanProductTestBuilder withVariableInstallmentsConfig(Boolean allowVariableInstallments, Integer minimumGap, Integer maximumGap) {
|
||||
this.allowVariableInstallments = allowVariableInstallments ;
|
||||
this.minimumGap = minimumGap;
|
||||
this.maximumGap = maximumGap;
|
||||
return this ;
|
||||
}
|
||||
}
|
||||
+155
@@ -0,0 +1,155 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common.loans;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
public class LoanRescheduleRequestTestBuilder {
|
||||
|
||||
private String rescheduleFromDate = "04 December 2014";
|
||||
private String graceOnPrincipal = "2";
|
||||
private String graceOnInterest = "2";
|
||||
private String extraTerms = "2";
|
||||
private Boolean recalculateInterest = false;
|
||||
private String newInterestRate = null;
|
||||
private String adjustedDueDate = null;
|
||||
private String rescheduleReasonId = "1";
|
||||
private String rescheduleReasonComment = null;
|
||||
private String submittedOnDate = "04 September 2014";
|
||||
|
||||
public String build(final String loanId) {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("locale", "en_GB");
|
||||
map.put("loanId", loanId);
|
||||
map.put("submittedOnDate", submittedOnDate);
|
||||
map.put("rescheduleFromDate", rescheduleFromDate);
|
||||
|
||||
if (graceOnPrincipal != null) {
|
||||
map.put("graceOnPrincipal", graceOnPrincipal);
|
||||
}
|
||||
|
||||
if (graceOnInterest != null) {
|
||||
map.put("graceOnInterest", graceOnInterest);
|
||||
}
|
||||
|
||||
if (extraTerms != null) {
|
||||
map.put("extraTerms", extraTerms);
|
||||
}
|
||||
|
||||
map.put("recalculateInterest", recalculateInterest);
|
||||
|
||||
if (newInterestRate != null) {
|
||||
map.put("newInterestRate", newInterestRate);
|
||||
}
|
||||
|
||||
if (adjustedDueDate != null) {
|
||||
map.put("adjustedDueDate", adjustedDueDate);
|
||||
}
|
||||
|
||||
map.put("rescheduleReasonId", rescheduleReasonId);
|
||||
|
||||
if (rescheduleReasonComment != null) {
|
||||
map.put("rescheduleReasonComment", rescheduleReasonComment);
|
||||
}
|
||||
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public LoanRescheduleRequestTestBuilder updateRescheduleFromDate(final String rescheduleFromDate) {
|
||||
if (rescheduleFromDate != null) {
|
||||
this.rescheduleFromDate = rescheduleFromDate;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanRescheduleRequestTestBuilder updateGraceOnPrincipal(final String graceOnPrincipal) {
|
||||
this.graceOnPrincipal = graceOnPrincipal;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanRescheduleRequestTestBuilder updateGraceOnInterest(final String graceOnInterest) {
|
||||
this.graceOnInterest = graceOnInterest;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanRescheduleRequestTestBuilder updateExtraTerms(final String extraTerms) {
|
||||
this.extraTerms = extraTerms;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanRescheduleRequestTestBuilder updateRecalculateInterest(final Boolean recalculateInterest) {
|
||||
this.recalculateInterest = recalculateInterest;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanRescheduleRequestTestBuilder updateNewInterestRate(final String newInterestRate) {
|
||||
this.newInterestRate = newInterestRate;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanRescheduleRequestTestBuilder updateAdjustedDueDate(final String adjustedDueDate) {
|
||||
this.adjustedDueDate = adjustedDueDate;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanRescheduleRequestTestBuilder updateRescheduleReasonId(final String rescheduleReasonId) {
|
||||
this.rescheduleReasonId = rescheduleReasonId;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanRescheduleRequestTestBuilder updateRescheduleReasonComment(final String rescheduleReasonComment) {
|
||||
this.rescheduleReasonComment = rescheduleReasonComment;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public LoanRescheduleRequestTestBuilder updateSubmittedOnDate(final String submittedOnDate) {
|
||||
this.submittedOnDate = submittedOnDate;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getRejectLoanRescheduleRequestJSON() {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("locale", "en");
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("rejectedOnDate", submittedOnDate);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public String getApproveLoanRescheduleRequestJSON() {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("locale", "en");
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("approvedOnDate", submittedOnDate);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common.loans;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class LoanStatusChecker {
|
||||
|
||||
public static void verifyLoanIsApproved(final HashMap loanStatusHashMap) {
|
||||
assertFalse(getStatus(loanStatusHashMap, "pendingApproval"));
|
||||
}
|
||||
|
||||
public static void verifyLoanIsWaitingForDisbursal(final HashMap loanStatusHashMap) {
|
||||
assertTrue(getStatus(loanStatusHashMap, "waitingForDisbursal"));
|
||||
}
|
||||
|
||||
public static void verifyLoanIsPending(final HashMap loanStatusHashMap) {
|
||||
assertTrue(getStatus(loanStatusHashMap, "pendingApproval"));
|
||||
}
|
||||
|
||||
public static void verifyLoanIsActive(final HashMap loanStatusHashMap) {
|
||||
assertTrue(getStatus(loanStatusHashMap, "active"));
|
||||
}
|
||||
|
||||
public static void verifyLoanAccountIsClosed(final HashMap loanStatusHashMap) {
|
||||
assertTrue(getStatus(loanStatusHashMap, "closed"));
|
||||
}
|
||||
|
||||
public static void verifyLoanAccountIsNotActive(final HashMap loanStatusHashMap) {
|
||||
assertFalse(getStatus(loanStatusHashMap, "active"));
|
||||
}
|
||||
|
||||
public static void verifyLoanAccountIsOverPaid(final HashMap loanStatusHashMap) {
|
||||
assertTrue(getStatus(loanStatusHashMap, "overpaid"));
|
||||
}
|
||||
|
||||
public static HashMap<String, Object> getStatusOfLoan(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer loanID) {
|
||||
final String url = "/fineract-provider/api/v1/loans/" + loanID + "?" + Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerGet(requestSpec, responseSpec, url, "status");
|
||||
}
|
||||
|
||||
private static boolean getStatus(final HashMap loanStatusMap, final String nameOfLoanStatusString) {
|
||||
return (Boolean) loanStatusMap.get(nameOfLoanStatusString);
|
||||
}
|
||||
|
||||
}
|
||||
+648
@@ -0,0 +1,648 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common.loans;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.joda.time.LocalDate;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public class LoanTransactionHelper {
|
||||
|
||||
private final RequestSpecification requestSpec;
|
||||
private final ResponseSpecification responseSpec;
|
||||
|
||||
private static final String CREATE_LOAN_PRODUCT_URL = "/fineract-provider/api/v1/loanproducts?" + Utils.TENANT_IDENTIFIER;
|
||||
private static final String APPLY_LOAN_URL = "/fineract-provider/api/v1/loans?" + Utils.TENANT_IDENTIFIER;
|
||||
private static final String APPROVE_LOAN_COMMAND = "approve";
|
||||
private static final String UNDO_APPROVAL_LOAN_COMMAND = "undoApproval";
|
||||
private static final String DISBURSE_LOAN_COMMAND = "disburse";
|
||||
private static final String DISBURSE_LOAN_TO_SAVINGS_COMMAND = "disburseToSavings";
|
||||
private static final String UNDO_DISBURSE_LOAN_COMMAND = "undoDisbursal";
|
||||
private static final String UNDO_LAST_DISBURSE_LOAN_COMMAND = "undolastdisbursal";
|
||||
private static final String WRITE_OFF_LOAN_COMMAND = "writeoff";
|
||||
private static final String WAIVE_INTEREST_COMMAND = "waiveinterest";
|
||||
private static final String MAKE_REPAYMENT_COMMAND = "repayment";
|
||||
private static final String WITHDRAW_LOAN_APPLICATION_COMMAND = "withdrawnByApplicant";
|
||||
private static final String RECOVER_FROM_GUARANTORS_COMMAND = "recoverGuarantees";
|
||||
private static final String MAKE_REFUND_BY_CASH_COMMAND = "refundByCash";
|
||||
|
||||
public LoanTransactionHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
this.requestSpec = requestSpec;
|
||||
this.responseSpec = responseSpec;
|
||||
}
|
||||
|
||||
public Integer getLoanProductId(final String loanProductJSON) {
|
||||
return Utils.performServerPost(this.requestSpec, this.responseSpec, CREATE_LOAN_PRODUCT_URL, loanProductJSON, "resourceId");
|
||||
}
|
||||
|
||||
public Integer getLoanId(final String loanApplicationJSON) {
|
||||
return Utils.performServerPost(this.requestSpec, this.responseSpec, APPLY_LOAN_URL, loanApplicationJSON, "loanId");
|
||||
}
|
||||
|
||||
public Integer getLoanOfficerId(final String loanId) {
|
||||
final String GET_LOAN_URL = "/fineract-provider/api/v1/loans/" + loanId + "?" + Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerGet(this.requestSpec, this.responseSpec, GET_LOAN_URL, "loanOfficerId");
|
||||
}
|
||||
|
||||
public Object createLoanAccount(final String loanApplicationJSON, final String responseAttribute) {
|
||||
return Utils.performServerPost(this.requestSpec, this.responseSpec, APPLY_LOAN_URL, loanApplicationJSON, responseAttribute);
|
||||
}
|
||||
|
||||
public Integer updateLoan(final Integer id, final String loanApplicationJSON) {
|
||||
return Utils.performServerPut(this.requestSpec, this.responseSpec, "/fineract-provider/api/v1/loans/" + id + "?"
|
||||
+ Utils.TENANT_IDENTIFIER, loanApplicationJSON, "loanId");
|
||||
}
|
||||
|
||||
public ArrayList getLoanRepaymentSchedule(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer loanID) {
|
||||
final String URL = "/fineract-provider/api/v1/loans/" + loanID + "?associations=repaymentSchedule&" + Utils.TENANT_IDENTIFIER;
|
||||
final HashMap response = Utils.performServerGet(requestSpec, responseSpec, URL, "repaymentSchedule");
|
||||
return (ArrayList) response.get("periods");
|
||||
}
|
||||
|
||||
public ArrayList getLoanFutureRepaymentSchedule(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer loanID) {
|
||||
final String URL = "/fineract-provider/api/v1/loans/" + loanID + "?associations=repaymentSchedule,futureSchedule&"
|
||||
+ Utils.TENANT_IDENTIFIER;
|
||||
final HashMap response = Utils.performServerGet(requestSpec, responseSpec, URL, "repaymentSchedule");
|
||||
return (ArrayList) response.get("futurePeriods");
|
||||
}
|
||||
|
||||
public HashMap getLoanSummary(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, final Integer loanID) {
|
||||
final String URL = "/fineract-provider/api/v1/loans/" + loanID + "?associations=all&" + Utils.TENANT_IDENTIFIER;
|
||||
final HashMap response = Utils.performServerGet(requestSpec, responseSpec, URL, "summary");
|
||||
return response;
|
||||
}
|
||||
|
||||
public Object getLoanDetail(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, final Integer loanID,
|
||||
final String param) {
|
||||
final String URL = "/fineract-provider/api/v1/loans/" + loanID + "?associations=all&" + Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerGet(requestSpec, responseSpec, URL, param);
|
||||
}
|
||||
|
||||
public String getLoanDetails(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, final Integer loanID) {
|
||||
final String URL = "/fineract-provider/api/v1/loans/" + loanID + "?associations=all&" + Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerGet(requestSpec, responseSpec, URL, null);
|
||||
}
|
||||
|
||||
public Object getLoanProductDetail(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer loanProductId, final String jsonAttributeToGetBack) {
|
||||
final String URL = "/fineract-provider/api/v1/loanproducts/" + loanProductId + "?associations=all&" + Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerGet(requestSpec, responseSpec, URL, jsonAttributeToGetBack);
|
||||
}
|
||||
|
||||
public String getLoanProductDetails(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer loanProductId) {
|
||||
final String URL = "/fineract-provider/api/v1/loanproducts/" + loanProductId + "?associations=all&" + Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerGet(requestSpec, responseSpec, URL, null);
|
||||
}
|
||||
|
||||
public ArrayList getLoanCharges(final Integer loanId) {
|
||||
final String GET_LOAN_CHARGES_URL = "/fineract-provider/api/v1/loans/" + loanId + "/charges?" + Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerGet(requestSpec, responseSpec, GET_LOAN_CHARGES_URL, "");
|
||||
}
|
||||
|
||||
public HashMap approveLoan(final String approvalDate, final Integer loanID) {
|
||||
String loanApprovalCommand = createLoanOperationURL(APPROVE_LOAN_COMMAND, loanID);
|
||||
String loanApprovalRequest = getApproveLoanAsJSON(approvalDate);
|
||||
System.out.println("Loan approval command:" + loanApprovalCommand);
|
||||
System.out.println("Loan approval request:" + loanApprovalRequest);
|
||||
return performLoanTransaction(loanApprovalCommand, loanApprovalRequest);
|
||||
}
|
||||
|
||||
public HashMap approveLoanWithApproveAmount(final String approvalDate, final String expectedDisbursementDate,
|
||||
final String approvalAmount, final Integer loanID, List<HashMap> tranches) {
|
||||
return performLoanTransaction(createLoanOperationURL(APPROVE_LOAN_COMMAND, loanID),
|
||||
getApproveLoanAsJSON(approvalDate, expectedDisbursementDate, approvalAmount, tranches));
|
||||
}
|
||||
|
||||
public List<HashMap<String, Object>> approveLoanForTranches(final String approvalDate, final String expectedDisbursementDate,
|
||||
final String approvalAmount, final Integer loanID, List<HashMap> tranches, final String responseAttribute) {
|
||||
return (List<HashMap<String, Object>>) performLoanTransaction(createLoanOperationURL(APPROVE_LOAN_COMMAND, loanID),
|
||||
getApproveLoanAsJSON(approvalDate, expectedDisbursementDate, approvalAmount, tranches), responseAttribute);
|
||||
}
|
||||
|
||||
public Object approveLoan(final String approvalDate, final String approvalAmount, final Integer loanID, final String responseAttribute) {
|
||||
|
||||
final String approvalURL = createLoanOperationURL(APPROVE_LOAN_COMMAND, loanID);
|
||||
final String approvalJSONData = getApproveLoanAsJSON(approvalDate, null, approvalAmount, null);
|
||||
|
||||
return performLoanTransaction(approvalURL, approvalJSONData, responseAttribute);
|
||||
}
|
||||
|
||||
public HashMap undoApproval(final Integer loanID) {
|
||||
final String undoBodyJson = "{'note':'UNDO APPROVAL'}";
|
||||
return performLoanTransaction(createLoanOperationURL(UNDO_APPROVAL_LOAN_COMMAND, loanID), undoBodyJson);
|
||||
}
|
||||
|
||||
public HashMap disburseLoan(final String date, final Integer loanID) {
|
||||
return performLoanTransaction(createLoanOperationURL(DISBURSE_LOAN_COMMAND, loanID), getDisburseLoanAsJSON(date, null));
|
||||
}
|
||||
|
||||
public HashMap disburseLoanWithRepaymentReschedule(final String date, final Integer loanID, String adjustRepaymentDate) {
|
||||
return performLoanTransaction(createLoanOperationURL(DISBURSE_LOAN_COMMAND, loanID), getDisburseLoanWithRepaymentRescheduleAsJSON(date,
|
||||
null, adjustRepaymentDate));
|
||||
}
|
||||
|
||||
public HashMap disburseLoan(final String date, final Integer loanID, final String disburseAmt) {
|
||||
return performLoanTransaction(createLoanOperationURL(DISBURSE_LOAN_COMMAND, loanID), getDisburseLoanAsJSON(date, disburseAmt));
|
||||
}
|
||||
|
||||
public HashMap disburseLoanToSavings(final String date, final Integer loanID) {
|
||||
return performLoanTransaction(createLoanOperationURL(DISBURSE_LOAN_TO_SAVINGS_COMMAND, loanID), getDisburseLoanAsJSON(date, null));
|
||||
}
|
||||
|
||||
public HashMap undoDisbursal(final Integer loanID) {
|
||||
final String undoDisburseJson = "{'note' : 'UNDO DISBURSAL'}";
|
||||
System.out.println("IN DISBURSE LOAN");
|
||||
final String url = createLoanOperationURL(UNDO_DISBURSE_LOAN_COMMAND, loanID);
|
||||
System.out.println("IN DISBURSE LOAN URL " + url);
|
||||
return performLoanTransaction(createLoanOperationURL(UNDO_DISBURSE_LOAN_COMMAND, loanID), undoDisburseJson);
|
||||
}
|
||||
|
||||
public Float undoLastDisbursal(final Integer loanID) {
|
||||
final String undoLastDisburseJson = "{'note' : 'UNDO LAST DISBURSAL'}";
|
||||
final String url = createLoanOperationURL(UNDO_LAST_DISBURSE_LOAN_COMMAND, loanID);
|
||||
System.out.println("IN UNDO LAST DISBURSE LOAN URL " + url);
|
||||
return performUndoLastLoanDisbursementTransaction(createLoanOperationURL(UNDO_LAST_DISBURSE_LOAN_COMMAND, loanID), undoLastDisburseJson);
|
||||
}
|
||||
|
||||
public void recoverFromGuarantor(final Integer loanID) {
|
||||
performLoanTransaction(createLoanOperationURL(RECOVER_FROM_GUARANTORS_COMMAND, loanID), "", "");
|
||||
}
|
||||
|
||||
public HashMap writeOffLoan(final String date, final Integer loanID) {
|
||||
return performLoanTransaction(createLoanTransactionURL(WRITE_OFF_LOAN_COMMAND, loanID), getWriteOffBodyAsJSON(date));
|
||||
}
|
||||
|
||||
public HashMap waiveInterest(final String date, final String amountToBeWaived, final Integer loanID) {
|
||||
return performLoanTransaction(createLoanTransactionURL(WAIVE_INTEREST_COMMAND, loanID), getWaiveBodyAsJSON(date, amountToBeWaived));
|
||||
}
|
||||
|
||||
public Integer waiveInterestAndReturnTransactionId(final String date, final String amountToBeWaived, final Integer loanID) {
|
||||
Integer resourceId = Utils.performServerPost(this.requestSpec, this.responseSpec,
|
||||
createLoanTransactionURL(WAIVE_INTEREST_COMMAND, loanID), getWaiveBodyAsJSON(date, amountToBeWaived), "resourceId");
|
||||
return resourceId;
|
||||
}
|
||||
|
||||
public HashMap makeRepayment(final String date, final Float amountToBePaid, final Integer loanID) {
|
||||
return (HashMap) performLoanTransaction(createLoanTransactionURL(MAKE_REPAYMENT_COMMAND, loanID),
|
||||
getRepaymentBodyAsJSON(date, amountToBePaid), "");
|
||||
}
|
||||
|
||||
public HashMap withdrawLoanApplicationByClient(final String date, final Integer loanID) {
|
||||
return performLoanTransaction(createLoanOperationURL(WITHDRAW_LOAN_APPLICATION_COMMAND, loanID),
|
||||
getWithdrawLoanApplicationBodyAsJSON(date));
|
||||
}
|
||||
|
||||
public Integer addChargesForLoan(final Integer loanId, final String request) {
|
||||
System.out.println("--------------------------------- ADD CHARGES FOR LOAN --------------------------------");
|
||||
final String ADD_CHARGES_URL = "/fineract-provider/api/v1/loans/" + loanId + "/charges?" + Utils.TENANT_IDENTIFIER;
|
||||
final HashMap response = Utils.performServerPost(requestSpec, responseSpec, ADD_CHARGES_URL, request, "");
|
||||
return (Integer) response.get("resourceId");
|
||||
}
|
||||
|
||||
public Object addChargesForAllreadyDisursedLoan(final Integer loanId, final String request, final ResponseSpecification responseSpecification) {
|
||||
final String ADD_CHARGES_URL = "/fineract-provider/api/v1/loans/" + loanId + "/charges?" + Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerPost(this.requestSpec, responseSpecification, ADD_CHARGES_URL, request, "");
|
||||
}
|
||||
|
||||
public Integer updateChargesForLoan(final Integer loanId, final Integer loanchargeId, final String request) {
|
||||
System.out.println("--------------------------------- ADD CHARGES FOR LOAN --------------------------------");
|
||||
final String UPDATE_CHARGES_URL = "/fineract-provider/api/v1/loans/" + loanId + "/charges/" + loanchargeId + "?"
|
||||
+ Utils.TENANT_IDENTIFIER;
|
||||
final HashMap response = Utils.performServerPut(requestSpec, responseSpec, UPDATE_CHARGES_URL, request, "");
|
||||
return (Integer) response.get("resourceId");
|
||||
}
|
||||
|
||||
public Integer deleteChargesForLoan(final Integer loanId, final Integer loanchargeId) {
|
||||
System.out.println("--------------------------------- DELETE CHARGES FOR LOAN --------------------------------");
|
||||
final String DELETE_CHARGES_URL = "/fineract-provider/api/v1/loans/" + loanId + "/charges/" + loanchargeId + "?"
|
||||
+ Utils.TENANT_IDENTIFIER;
|
||||
final HashMap response = Utils.performServerDelete(requestSpec, responseSpec, DELETE_CHARGES_URL, "");
|
||||
return (Integer) response.get("resourceId");
|
||||
}
|
||||
|
||||
public Integer waiveChargesForLoan(final Integer loanId, final Integer loanchargeId, final String json) {
|
||||
System.out.println("--------------------------------- WAIVE CHARGES FOR LOAN --------------------------------");
|
||||
final String CHARGES_URL = "/fineract-provider/api/v1/loans/" + loanId + "/charges/" + loanchargeId + "?command=waive&"
|
||||
+ Utils.TENANT_IDENTIFIER;
|
||||
final HashMap response = Utils.performServerPost(requestSpec, responseSpec, CHARGES_URL, json, "");
|
||||
return (Integer) response.get("resourceId");
|
||||
}
|
||||
|
||||
public Integer payChargesForLoan(final Integer loanId, final Integer loanchargeId, final String json) {
|
||||
System.out.println("--------------------------------- WAIVE CHARGES FOR LOAN --------------------------------");
|
||||
final String CHARGES_URL = "/fineract-provider/api/v1/loans/" + loanId + "/charges/" + loanchargeId + "?command=pay&"
|
||||
+ Utils.TENANT_IDENTIFIER;
|
||||
final HashMap response = Utils.performServerPost(requestSpec, responseSpec, CHARGES_URL, json, "");
|
||||
return (Integer) response.get("resourceId");
|
||||
}
|
||||
|
||||
private String getDisburseLoanAsJSON(final String actualDisbursementDate, final String transactionAmount) {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("locale", "en");
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("actualDisbursementDate", actualDisbursementDate);
|
||||
map.put("note", "DISBURSE NOTE");
|
||||
if (transactionAmount != null) {
|
||||
map.put("transactionAmount", transactionAmount);
|
||||
}
|
||||
System.out.println("Loan Application disburse request : " + map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
private String getDisburseLoanWithRepaymentRescheduleAsJSON(final String actualDisbursementDate, final String transactionAmount, final String adjustRepaymentDate) {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("locale", "en");
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("actualDisbursementDate", actualDisbursementDate);
|
||||
map.put("adjustRepaymentDate", adjustRepaymentDate);
|
||||
map.put("note", "DISBURSE NOTE");
|
||||
if (transactionAmount != null) {
|
||||
map.put("transactionAmount", transactionAmount);
|
||||
}
|
||||
System.out.println("Loan Application disburse request : " + map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
private String getApproveLoanAsJSON(final String approvalDate) {
|
||||
return getApproveLoanAsJSON(approvalDate, null, null, null);
|
||||
}
|
||||
|
||||
private String getApproveLoanAsJSON(final String approvalDate, final String expectedDisbursementDate, final String approvalAmount,
|
||||
List<HashMap> tranches) {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("locale", "en");
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
if (approvalAmount != null) {
|
||||
map.put("approvedLoanAmount", approvalAmount);
|
||||
}
|
||||
map.put("approvedOnDate", approvalDate);
|
||||
if (expectedDisbursementDate != null) {
|
||||
map.put("expectedDisbursementDate", expectedDisbursementDate);
|
||||
}
|
||||
if (tranches != null && tranches.size() > 0) {
|
||||
map.put("disbursementData", tranches);
|
||||
}
|
||||
map.put("note", "Approval NOTE");
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
private String getRepaymentBodyAsJSON(final String transactionDate, final Float transactionAmount) {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("locale", "en");
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("transactionDate", transactionDate);
|
||||
map.put("transactionAmount", transactionAmount.toString());
|
||||
map.put("note", "Repayment Made!!!");
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
private String getWriteOffBodyAsJSON(final String transactionDate) {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("locale", "en");
|
||||
map.put("note", " LOAN WRITE OFF!!!");
|
||||
map.put("transactionDate", transactionDate);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
private String getWaiveBodyAsJSON(final String transactionDate, final String amountToBeWaived) {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("locale", "en");
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("transactionDate", transactionDate);
|
||||
map.put("transactionAmount", amountToBeWaived);
|
||||
map.put("note", " Interest Waived!!!");
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
private String getWithdrawLoanApplicationBodyAsJSON(final String withdrawDate) {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("locale", "en");
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("withdrawnOnDate", withdrawDate);
|
||||
map.put("note", " Loan Withdrawn By Client!!!");
|
||||
return new Gson().toJson(map);
|
||||
|
||||
}
|
||||
|
||||
public static String getSpecifiedDueDateChargesForLoanAsJSON(final String chargeId) {
|
||||
return getSpecifiedDueDateChargesForLoanAsJSON(chargeId, "12 January 2013", "100");
|
||||
}
|
||||
|
||||
public static String getSpecifiedDueDateChargesForLoanAsJSON(final String chargeId, final String dueDate, final String amount) {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("locale", "en_GB");
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("amount", amount);
|
||||
map.put("dueDate", dueDate);
|
||||
map.put("chargeId", chargeId);
|
||||
String json = new Gson().toJson(map);
|
||||
System.out.println(json);
|
||||
return json;
|
||||
}
|
||||
|
||||
public static String getDisbursementChargesForLoanAsJSON(final String chargeId) {
|
||||
return getDisbursementChargesForLoanAsJSON(chargeId, "100");
|
||||
}
|
||||
|
||||
public static String getDisbursementChargesForLoanAsJSON(final String chargeId, String amount) {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("locale", "en_GB");
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("amount", amount);
|
||||
map.put("chargeId", chargeId);
|
||||
String json = new Gson().toJson(map);
|
||||
System.out.println(json);
|
||||
return json;
|
||||
}
|
||||
|
||||
public static String getInstallmentChargesForLoanAsJSON(final String chargeId, final String amount) {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("locale", "en_GB");
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("amount", amount);
|
||||
map.put("chargeId", chargeId);
|
||||
String json = new Gson().toJson(map);
|
||||
System.out.println(json);
|
||||
return json;
|
||||
}
|
||||
|
||||
public static String getUpdateChargesForLoanAsJSON(String amount) {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("locale", "en_GB");
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("amount", amount);
|
||||
String json = new Gson().toJson(map);
|
||||
System.out.println(json);
|
||||
return json;
|
||||
}
|
||||
|
||||
public static String getPayChargeJSON(final String date, final String installmentNumber) {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("locale", "en_GB");
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("transactionDate", date);
|
||||
if (installmentNumber != null) {
|
||||
map.put("installmentNumber", installmentNumber);
|
||||
}
|
||||
String json = new Gson().toJson(map);
|
||||
System.out.println(json);
|
||||
return json;
|
||||
}
|
||||
|
||||
public static String getWaiveChargeJSON(final String installmentNumber) {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("locale", "en_GB");
|
||||
map.put("installmentNumber", installmentNumber);
|
||||
String json = new Gson().toJson(map);
|
||||
System.out.println(json);
|
||||
return json;
|
||||
}
|
||||
|
||||
public String getLoanCalculationBodyAsJSON(final String productID) {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("locale", "en_GB");
|
||||
map.put("productId", productID);
|
||||
map.put("principal", "4,500.00");
|
||||
map.put("loanTermFrequency", "4");
|
||||
map.put("loanTermFrequencyType", "2");
|
||||
map.put("numberOfRepayments", "4");
|
||||
map.put("repaymentEvery", "1");
|
||||
map.put("repaymentFrequencyType", "2");
|
||||
map.put("interestRateFrequencyType", "2");
|
||||
map.put("interestRatePerPeriod", "2");
|
||||
map.put("amortizationType", "1");
|
||||
map.put("interestType", "0");
|
||||
map.put("interestCalculationPeriodType", "1");
|
||||
map.put("expectedDisbursementDate", "20 September 2011");
|
||||
map.put("transactionProcessingStrategyId", "1");
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
private String createLoanOperationURL(final String command, final Integer loanID) {
|
||||
return "/fineract-provider/api/v1/loans/" + loanID + "?command=" + command + "&" + Utils.TENANT_IDENTIFIER;
|
||||
}
|
||||
|
||||
private String createLoanTransactionURL(final String command, final Integer loanID) {
|
||||
return "/fineract-provider/api/v1/loans/" + loanID + "/transactions?command=" + command + "&" + Utils.TENANT_IDENTIFIER;
|
||||
}
|
||||
|
||||
private HashMap performLoanTransaction(final String postURLForLoanTransaction, final String jsonToBeSent) {
|
||||
|
||||
final HashMap response = Utils.performServerPost(this.requestSpec, this.responseSpec, postURLForLoanTransaction, jsonToBeSent,
|
||||
"changes");
|
||||
return (HashMap) response.get("status");
|
||||
}
|
||||
|
||||
private Float performUndoLastLoanDisbursementTransaction(final String postURLForLoanTransaction, final String jsonToBeSent) {
|
||||
|
||||
final HashMap response = Utils.performServerPost(this.requestSpec, this.responseSpec, postURLForLoanTransaction, jsonToBeSent,
|
||||
"changes");
|
||||
return (Float) response.get("disbursedAmount");
|
||||
}
|
||||
|
||||
private Object performLoanTransaction(final String postURLForLoanTransaction, final String jsonToBeSent, final String responseAttribute) {
|
||||
return Utils.performServerPost(this.requestSpec, this.responseSpec, postURLForLoanTransaction, jsonToBeSent, responseAttribute);
|
||||
}
|
||||
|
||||
public Object adjustLoanTransaction(final Integer loanId, final Integer transactionId, final String date,
|
||||
final String transactionAmount, final String responseAttribute) {
|
||||
return adjustLoanTransaction(loanId, transactionId, getAdjustTransactionJSON(date, transactionAmount), responseAttribute);
|
||||
}
|
||||
|
||||
private Object adjustLoanTransaction(final Integer loanId, final Integer tansactionId, final String jsonToBeSent,
|
||||
final String responseAttribute) {
|
||||
final String URL = "/fineract-provider/api/v1/loans/" + loanId + "/transactions/" + tansactionId + "?" + Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerPost(this.requestSpec, this.responseSpec, URL, jsonToBeSent, responseAttribute);
|
||||
}
|
||||
|
||||
private String getAdjustTransactionJSON(final String date, final String transactionAmount) {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("locale", "en_GB");
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("transactionDate", date);
|
||||
map.put("transactionAmount", transactionAmount);
|
||||
String json = new Gson().toJson(map);
|
||||
System.out.println(json);
|
||||
return json;
|
||||
}
|
||||
|
||||
public HashMap getPrepayAmount(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, final Integer loanID) {
|
||||
final String URL = "/fineract-provider/api/v1/loans/" + loanID + "/transactions/template?command=prepayLoan&"
|
||||
+ Utils.TENANT_IDENTIFIER;
|
||||
final HashMap response = Utils.performServerGet(requestSpec, responseSpec, URL, "");
|
||||
return response;
|
||||
}
|
||||
|
||||
private String createLoanRefundTransferURL() {
|
||||
return "/fineract-provider/api/v1/accounttransfers/refundByTransfer?tenantIdentifier=default";
|
||||
}
|
||||
|
||||
public void verifyRepaymentScheduleEntryFor(final int repaymentNumber, final float expectedPrincipalOutstanding, final Integer loanID) {
|
||||
System.out.println("---------------------------GETTING LOAN REPAYMENT SCHEDULE--------------------------------");
|
||||
final ArrayList<HashMap> repaymentPeriods = getLoanRepaymentSchedule(this.requestSpec, this.responseSpec, loanID);
|
||||
assertEquals("Mismatch in Principal Loan Balance Outstanding ", expectedPrincipalOutstanding, repaymentPeriods.get(repaymentNumber)
|
||||
.get("principalLoanBalanceOutstanding"));
|
||||
}
|
||||
|
||||
public void checkAccrualTransactionForRepayment(final LocalDate transactionDate, final Float interestPortion, final Float feePortion,
|
||||
final Float penaltyPortion, final Integer loanID) {
|
||||
|
||||
ArrayList<HashMap> transactions = (ArrayList<HashMap>) getLoanDetail(this.requestSpec, this.responseSpec, loanID, "transactions");
|
||||
boolean isTransactionFound = false;
|
||||
for (int i = 0; i < transactions.size(); i++) {
|
||||
HashMap transactionType = (HashMap) transactions.get(i).get("type");
|
||||
boolean isAccrualTransaction = (Boolean) transactionType.get("accrual");
|
||||
|
||||
if (isAccrualTransaction) {
|
||||
ArrayList<Integer> accrualEntryDateAsArray = (ArrayList<Integer>) transactions.get(i).get("date");
|
||||
LocalDate accrualEntryDate = new LocalDate(accrualEntryDateAsArray.get(0), accrualEntryDateAsArray.get(1),
|
||||
accrualEntryDateAsArray.get(2));
|
||||
|
||||
if (transactionDate.equals(accrualEntryDate)) {
|
||||
isTransactionFound = true;
|
||||
assertEquals("Mismatch in transaction amounts", interestPortion,
|
||||
Float.valueOf(String.valueOf(transactions.get(i).get("interestPortion"))));
|
||||
assertEquals("Mismatch in transaction amounts", feePortion,
|
||||
Float.valueOf(String.valueOf(transactions.get(i).get("feeChargesPortion"))));
|
||||
assertEquals("Mismatch in transaction amounts", penaltyPortion,
|
||||
Float.valueOf(String.valueOf(transactions.get(i).get("penaltyChargesPortion"))));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
assertTrue("No Accrual entries are posted", isTransactionFound);
|
||||
|
||||
}
|
||||
|
||||
public HashMap makeRefundByCash(final String date, final Float amountToBeRefunded, final Integer loanID) {
|
||||
return performLoanTransaction(createLoanTransactionURL(MAKE_REFUND_BY_CASH_COMMAND, loanID),
|
||||
getRefundByCashBodyAsJSON(date, amountToBeRefunded));
|
||||
}
|
||||
|
||||
public HashMap makeRefundByTransfer(final Integer fromAccountId, final Integer toClientId, final Integer toAccountId,
|
||||
final Integer fromClientId, final String date, final Float amountToBeRefunded) {
|
||||
return performLoanTransaction(createLoanRefundTransferURL(),
|
||||
getRefundByTransferBodyAsJSON(fromAccountId, toClientId, toAccountId, fromClientId, date, amountToBeRefunded));
|
||||
}
|
||||
|
||||
private String getRefundByCashBodyAsJSON(final String transactionDate, final Float transactionAmount) {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("locale", "en");
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("transactionDate", transactionDate);
|
||||
map.put("transactionAmount", transactionAmount.toString());
|
||||
map.put("note", "Refund Made!!!");
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
private String getRefundByTransferBodyAsJSON(final Integer fromAccountId, final Integer toClientId, final Integer toAccountId,
|
||||
final Integer fromClientId, final String transactionDate, final Float transactionAmount) {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("fromAccountId", fromAccountId.toString());
|
||||
map.put("fromAccountType", "1");
|
||||
map.put("toOfficeId", "1");
|
||||
map.put("toClientId", toClientId.toString());
|
||||
map.put("toAccountType", "2");
|
||||
map.put("toAccountId", toAccountId.toString());
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("transferDate", transactionDate);
|
||||
map.put("transferAmount", transactionAmount.toString());
|
||||
map.put("transferDescription", "Refund Made!!!");
|
||||
map.put("fromClientId", fromClientId.toString());
|
||||
map.put("fromOfficeId", "1");
|
||||
map.put("locale", "en");
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public HashMap createTrancheDetail(final String id, final String date, final String amount) {
|
||||
HashMap<String, Object> detail = new HashMap<>();
|
||||
if(id != null){
|
||||
detail.put("id", id);
|
||||
}
|
||||
detail.put("expectedDisbursementDate", date);
|
||||
detail.put("principal", amount);
|
||||
|
||||
return detail;
|
||||
}
|
||||
|
||||
public Object editDisbursementDetail(final Integer loanID, final Integer disbursementId, final String approvalAmount, final String expectedDisbursementDate,
|
||||
final String updatedExpectedDisbursementDate, final String updatedPrincipal, final String jsonAttributeToGetBack) {
|
||||
|
||||
return Utils.performServerPut(this.requestSpec, this.responseSpec, createEditDisbursementURL(loanID, disbursementId), getEditDisbursementsAsJSON(approvalAmount, expectedDisbursementDate,
|
||||
updatedExpectedDisbursementDate, updatedPrincipal), jsonAttributeToGetBack);
|
||||
}
|
||||
|
||||
public Object addAndDeleteDisbursementDetail(final Integer loanID, final String approvalAmount, final String expectedDisbursementDate
|
||||
, List<HashMap> disbursementData, final String jsonAttributeToGetBack) {
|
||||
|
||||
return Utils.performServerPut(this.requestSpec, this.responseSpec, createAddAndDeleteDisbursementURL(loanID),
|
||||
getAddAndDeleteDisbursementsAsJSON(approvalAmount, expectedDisbursementDate, disbursementData), jsonAttributeToGetBack);
|
||||
}
|
||||
|
||||
private String createEditDisbursementURL(Integer loanID, Integer disbursementId) {
|
||||
return "/fineract-provider/api/v1/loans/" + loanID + "/disbursements/" + disbursementId + "?" + Utils.TENANT_IDENTIFIER;
|
||||
}
|
||||
|
||||
private String createAddAndDeleteDisbursementURL(Integer loanID) {
|
||||
return "/fineract-provider/api/v1/loans/" + loanID + "/disbursements/editDisbursements?" + Utils.TENANT_IDENTIFIER;
|
||||
}
|
||||
|
||||
public static String getEditDisbursementsAsJSON(final String approvalAmount, final String expectedDisbursementDate,
|
||||
final String updatedExpectedDisbursementDate, final String updatedPrincipal) {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("locale", "en");
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("approvedLoanAmount", approvalAmount);
|
||||
map.put("expectedDisbursementDate", expectedDisbursementDate);
|
||||
map.put("updatedExpectedDisbursementDate", updatedExpectedDisbursementDate);
|
||||
map.put("updatedPrincipal", updatedPrincipal);
|
||||
String json = new Gson().toJson(map);
|
||||
System.out.println(json);
|
||||
return json;
|
||||
}
|
||||
|
||||
public static String getAddAndDeleteDisbursementsAsJSON(final String approvalAmount, final String expectedDisbursementDate,
|
||||
final List<HashMap> disbursementData) {
|
||||
final HashMap map = new HashMap<>();
|
||||
map.put("locale", "en");
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("approvedLoanAmount", approvalAmount);
|
||||
map.put("expectedDisbursementDate", expectedDisbursementDate);
|
||||
map.put("disbursementData", disbursementData);
|
||||
String json = new Gson().toJson(map);
|
||||
System.out.println(json);
|
||||
return json;
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common.organisation;
|
||||
|
||||
public class Currency {
|
||||
|
||||
String code;
|
||||
String name;
|
||||
Integer decimalPlaces;
|
||||
String displaySymbol;
|
||||
String nameCode;
|
||||
String displayLabel;
|
||||
|
||||
public Currency(String code, String name, Integer decimalPlaces, String displaySymbol,
|
||||
String nameCode, String displayLabel) {
|
||||
this.code = code;
|
||||
this.name = name;
|
||||
this.decimalPlaces = decimalPlaces;
|
||||
this.displaySymbol = displaySymbol;
|
||||
this.nameCode = nameCode;
|
||||
this.displayLabel = displayLabel;
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return (this.code != null && this.code.length() == 3) &&
|
||||
(this.name != null && this.name.length() > 0) &&
|
||||
(this.decimalPlaces != null && this.decimalPlaces >= 0) &&
|
||||
(this.nameCode != null && this.nameCode.startsWith("currency.")) &&
|
||||
(this.displayLabel != null && this.displayLabel.length() > 0);
|
||||
|
||||
}
|
||||
}
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common.organisation;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
import static com.jayway.restassured.RestAssured.given;
|
||||
|
||||
public class CurrencyHelper {
|
||||
|
||||
private static final String CURRENCY_URL = "/fineract-provider/api/v1/currencies?" + Utils.TENANT_IDENTIFIER;
|
||||
private static final String CURRENCY_URL_SELECTED = CURRENCY_URL + "&fields=selectedCurrencyOptions";
|
||||
|
||||
private static final List<String> permittedCurrencyArray = Arrays.asList("currencyOptions",
|
||||
"selectedCurrencyOptions");
|
||||
|
||||
private static final List<String> permittedCurrencyArraySelected = Arrays.asList("selectedCurrencyOptions");
|
||||
|
||||
private final RequestSpecification requestSpec;
|
||||
private final ResponseSpecification responseSpec;
|
||||
|
||||
public CurrencyHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
this.requestSpec = requestSpec;
|
||||
this.responseSpec = responseSpec;
|
||||
}
|
||||
|
||||
public ArrayList<Currency> getPermittedCurrencies() {
|
||||
return getCurrencies(CURRENCY_URL, permittedCurrencyArray);
|
||||
}
|
||||
|
||||
public ArrayList<Currency> getSelectedCurrencies() {
|
||||
return getCurrencies(CURRENCY_URL_SELECTED, permittedCurrencyArraySelected);
|
||||
}
|
||||
|
||||
|
||||
private ArrayList<Currency> getCurrencies(final String getUrl, final List<String> permittedCurrencyArrays) {
|
||||
System.out.println("--------------------------------- GET CURRENCY OPTIONS -------------------------------");
|
||||
final String json = given().spec(requestSpec).expect().spec(responseSpec).log().ifError().when()
|
||||
.get(getUrl).andReturn().asString();
|
||||
final Gson gson = new Gson();
|
||||
Assert.notNull(json);
|
||||
final ArrayList<Currency> currencyList = new ArrayList<Currency>();
|
||||
final Type typeOfHashMap = new TypeToken<Map<String, List<Currency>>>() { }.getType();
|
||||
final Map<String, List<Currency>> responseMap = gson.fromJson(json, typeOfHashMap);
|
||||
for(Map.Entry<String, List<Currency>> entry : responseMap.entrySet()) {
|
||||
Assert.isTrue(permittedCurrencyArrays.contains(entry.getKey()));
|
||||
for(Currency currency : entry.getValue()) {
|
||||
currencyList.add(currency);
|
||||
}
|
||||
}
|
||||
return currencyList;
|
||||
}
|
||||
|
||||
public List<String> updateCurrencies(final List<String> currencies) {
|
||||
System.out.println("--------------------------------- UPDATE CURRENCY OPTIONS -------------------------------");
|
||||
final String json = given().spec(requestSpec).body(getUpdateJSON(currencies)).expect().spec(responseSpec).log().ifError().when()
|
||||
.put(CURRENCY_URL).andReturn().asString();
|
||||
final Gson gson = new Gson();
|
||||
Assert.notNull(json);
|
||||
final Type typeOfHashMap = new TypeToken<Map<String,Map<String, List<String>>>>() { }.getType();
|
||||
final Map<String,Map<String, List<String>>> responseMap = gson.fromJson(json, typeOfHashMap);
|
||||
return responseMap.get("changes").get("currencies");
|
||||
}
|
||||
|
||||
private String getUpdateJSON(final List<String> currencies) {
|
||||
final HashMap<String, List<String>> map = new HashMap<>();
|
||||
map.put("currencies", currencies);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
}
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common.organisation;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
public class StaffHelper {
|
||||
|
||||
private static final String TRANSFER_STAFF_URL = "/fineract-provider/api/v1/groups";
|
||||
|
||||
private static final String CREATE_STAFF_URL = "/fineract-provider/api/v1/staff";
|
||||
|
||||
private static final String RESOURCE_ID = "resourceId";
|
||||
|
||||
public static final String GROUP_ID = "groupId";
|
||||
|
||||
|
||||
public static Integer transferStaffToGroup(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer groupId,final Integer staffToTransfer ,final String note){
|
||||
final String url = TRANSFER_STAFF_URL + "/" + groupId + "?command=transferStaff&"+ Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerPost(requestSpec, responseSpec, url, transferStaffToGroupAsJSON(staffToTransfer, note), GROUP_ID);
|
||||
}
|
||||
|
||||
public static String transferStaffToGroupAsJSON(final Integer staffToTransferId,final String note) {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("staffId", staffToTransferId);
|
||||
map.put("note", note);
|
||||
System.out.println("map : " + map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static Integer createStaff(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
return (Integer) createStaffWithJson(requestSpec, responseSpec, createStaffAsJSON()).get("resourceId");
|
||||
}
|
||||
|
||||
public static HashMap createStaffMap(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
return createStaffWithJson(requestSpec, responseSpec, createStaffAsJSON());
|
||||
}
|
||||
|
||||
public static HashMap createStaffWithJson(final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec, final String json) {
|
||||
final String url = CREATE_STAFF_URL + "?" + Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerPost(requestSpec, responseSpec, url, json, "");
|
||||
}
|
||||
|
||||
public static HashMap getStaff(final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec, final Integer staffId) {
|
||||
final String url = CREATE_STAFF_URL + "/" + staffId + "?" + Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerGet(requestSpec, responseSpec, url, "");
|
||||
}
|
||||
|
||||
public static List<HashMap> getStaffList(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
final String url = CREATE_STAFF_URL + "?" + Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerGet(requestSpec, responseSpec, url, "");
|
||||
}
|
||||
|
||||
public static Object getStaffListWithState(final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec, final String status) {
|
||||
final String url = CREATE_STAFF_URL + "?" + Utils.TENANT_IDENTIFIER + "&status=" + status;
|
||||
return Utils.performServerGet(requestSpec, responseSpec, url, "");
|
||||
}
|
||||
|
||||
public static Object updateStaff(final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec, final Integer staffId, final HashMap<String, Object> changes) {
|
||||
final String url = CREATE_STAFF_URL + "/" + staffId + "?" + Utils.TENANT_IDENTIFIER;
|
||||
final String json = new Gson().toJson(changes);
|
||||
return Utils.performServerPut(requestSpec, responseSpec, url, json, "");
|
||||
}
|
||||
|
||||
public static String createStaffAsJSON(){
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("officeId", 1);
|
||||
map.put("firstname", Utils.randomNameGenerator("michael_", 5));
|
||||
map.put("lastname", Utils.randomNameGenerator("Doe_", 4));
|
||||
map.put("isLoanOfficer", true);
|
||||
System.out.println("map : " + map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static String createStaffWithJSONFields(String... fields) {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
final List<String> fieldList = Arrays.asList(fields);
|
||||
if(fieldList.contains("officeId")) {
|
||||
map.put("officeId", 1);
|
||||
}
|
||||
if(fieldList.contains("firstname")) {
|
||||
map.put("firstname", Utils.randomNameGenerator("michael_", 5));
|
||||
}
|
||||
if(fieldList.contains("lastname")) {
|
||||
map.put("lastname", Utils.randomNameGenerator("Doe_", 4));
|
||||
}
|
||||
if(fieldList.contains("isLoanOfficer")) {
|
||||
map.put("isLoanOfficer", true);
|
||||
}
|
||||
if(fieldList.contains("mobileNo")) {
|
||||
map.put("mobileNo", "+123515198");
|
||||
}
|
||||
System.out.println("map : " + map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
}
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common.provisioning;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.accounting.Account;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
public class ProvisioningHelper {
|
||||
|
||||
public final static Map createProvisioingCriteriaJson(ArrayList<Integer> loanProducts, ArrayList categories, Account liability,
|
||||
Account expense) {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("loanProducts", addLoanProducts(loanProducts));
|
||||
map.put("definitions", addProvisioningCategories(categories, liability, expense));
|
||||
DateFormat simple = new SimpleDateFormat("dd MMMM yyyy");
|
||||
String formattedString = simple.format(Utils.getLocalDateOfTenant().toDate());
|
||||
Random rand = new Random() ;
|
||||
String criteriaName = "General Provisioning Criteria" + formattedString+rand.nextLong();
|
||||
map.put("criteriaName", criteriaName);
|
||||
map.put("locale", "en");
|
||||
return map ;
|
||||
}
|
||||
|
||||
public final static String createProvisioningEntryJson() {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("createjournalentries", Boolean.FALSE);
|
||||
map.put("locale", "en");
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
DateFormat simple = new SimpleDateFormat("dd MMMM yyyy");
|
||||
map.put("date", simple.format(Utils.getLocalDateOfTenant().toDate()));
|
||||
String provisioningEntryCreateJson = new Gson().toJson(map);
|
||||
return provisioningEntryCreateJson;
|
||||
}
|
||||
|
||||
public final static String createProvisioningEntryJsonWithJournalsEnabled() {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("createjournalentries", Boolean.TRUE);
|
||||
map.put("locale", "en");
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
DateFormat simple = new SimpleDateFormat("dd MMMM yyyy");
|
||||
map.put("date", simple.format(Utils.getLocalDateOfTenant().toDate()));
|
||||
String provisioningEntryCreateJson = new Gson().toJson(map);
|
||||
return provisioningEntryCreateJson;
|
||||
}
|
||||
|
||||
private static ArrayList addLoanProducts(ArrayList<Integer> loanProducts) {
|
||||
ArrayList list = new ArrayList<>();
|
||||
for (int i = 0; i < loanProducts.size(); i++) {
|
||||
HashMap map = new HashMap();
|
||||
map.put("id", loanProducts.get(i));
|
||||
list.add(map);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static ArrayList addProvisioningCategories(ArrayList categories, Account liability, Account expense) {
|
||||
ArrayList list = new ArrayList();
|
||||
int minStart = 0;
|
||||
int maxStart = 30;
|
||||
|
||||
for (int i = 0; i < categories.size(); i++) {
|
||||
HashMap map = new HashMap();
|
||||
HashMap category = (HashMap) categories.get(i);
|
||||
map.put("categoryId", category.get("id"));
|
||||
map.put("categoryName", category.get("categoryName"));
|
||||
map.put("minAge", (i * 30) + 1);
|
||||
if (i == categories.size() - 1) {
|
||||
map.put("maxAge", 90000);
|
||||
} else {
|
||||
map.put("maxAge", (i+1) * 30);
|
||||
}
|
||||
map.put("provisioningPercentage", new Float((i + 1) * 5.5));
|
||||
map.put("liabilityAccount", liability.getAccountID());
|
||||
map.put("expenseAccount", expense.getAccountID());
|
||||
list.add(map);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common.provisioning;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
|
||||
public class ProvisioningTransactionHelper {
|
||||
|
||||
private static final String PROVISIONING_CATEGORY_URL = "/fineract-provider/api/v1/provisioningcategory?" + Utils.TENANT_IDENTIFIER ;
|
||||
|
||||
private static final String CREATE_PROVISIONING_CRITERIA_URL = "/fineract-provider/api/v1/provisioningcriteria?" + Utils.TENANT_IDENTIFIER;
|
||||
private static final String CREATE_PROVISIONING_ENTRY_URL = "/fineract-provider/api/v1/provisioningentries?" + Utils.TENANT_IDENTIFIER;
|
||||
|
||||
private final RequestSpecification requestSpec;
|
||||
private final ResponseSpecification responseSpec;
|
||||
|
||||
public ProvisioningTransactionHelper(RequestSpecification requestSpec, ResponseSpecification responeSpec) {
|
||||
this.requestSpec = requestSpec ;
|
||||
this.responseSpec = responeSpec ;
|
||||
}
|
||||
|
||||
public ArrayList retrieveAllProvisioningCategories() {
|
||||
return Utils.performServerGet(requestSpec, responseSpec, PROVISIONING_CATEGORY_URL, "");
|
||||
}
|
||||
|
||||
public Integer createProvisioningCriteria(final String provsioningCriteriaJson) {
|
||||
return Utils.performServerPost(this.requestSpec, this.responseSpec, CREATE_PROVISIONING_CRITERIA_URL, provsioningCriteriaJson, "resourceId");
|
||||
}
|
||||
|
||||
public Map retrieveProvisioningCriteria(final Integer criteriaId) {
|
||||
String url = "/fineract-provider/api/v1/provisioningcriteria/"+criteriaId+"?"+Utils.TENANT_IDENTIFIER ;
|
||||
return Utils.performServerGet(requestSpec, responseSpec, url, "");
|
||||
}
|
||||
|
||||
public Integer updateProvisioningCriteria(final Integer criteriaId, final String provsioningCriteriaJson) {
|
||||
String url = "/fineract-provider/api/v1/provisioningcriteria/"+criteriaId+"?"+Utils.TENANT_IDENTIFIER ;
|
||||
return Utils.performServerPut(this.requestSpec, this.responseSpec, url, provsioningCriteriaJson, "resourceId");
|
||||
}
|
||||
|
||||
public Integer deleteProvisioningCriteria(final Integer criteriaId) {
|
||||
String url = "/fineract-provider/api/v1/provisioningcriteria/"+criteriaId+"?"+Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerDelete(this.requestSpec, this.responseSpec, url, "resourceId");
|
||||
}
|
||||
|
||||
public Integer createProvisioningEntries(final String provsioningCriteriaJson) {
|
||||
return Utils.performServerPost(this.requestSpec, this.responseSpec, CREATE_PROVISIONING_ENTRY_URL, provsioningCriteriaJson, "resourceId");
|
||||
}
|
||||
|
||||
public Integer updateProvisioningEntry(final String command, final Integer entryId, String jsonBody) {
|
||||
String url = "/fineract-provider/api/v1/provisioningentries/" + entryId + "?command=" + command + "&" + Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerPost(requestSpec, responseSpec, url, jsonBody, "resourceId") ;
|
||||
}
|
||||
|
||||
public Map retrieveProvisioningEntry(final Integer provisioningEntry) {
|
||||
String url = "/fineract-provider/api/v1/provisioningentries/"+provisioningEntry+"?"+Utils.TENANT_IDENTIFIER; ;
|
||||
return Utils.performServerGet(requestSpec, responseSpec, url, "") ;
|
||||
}
|
||||
|
||||
public Map retrieveProvisioningEntries(final Integer provisioningEntry) {
|
||||
String url = "/fineract-provider/api/v1/provisioningentries/entries?entryId="+provisioningEntry+"&"+Utils.TENANT_IDENTIFIER; ;
|
||||
return Utils.performServerGet(requestSpec, responseSpec, url, "") ;
|
||||
}
|
||||
|
||||
public Map retrieveAllProvisioningEntries() {
|
||||
String url = "/fineract-provider/api/v1/provisioningentries?dateFormat=dd MMMM yyyy"+"&"+"locale=en"+"&"+Utils.TENANT_IDENTIFIER; ;
|
||||
return Utils.performServerGet(requestSpec, responseSpec, url, "") ;
|
||||
}
|
||||
|
||||
}
|
||||
+556
@@ -0,0 +1,556 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests.common.recurringdeposit;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.fineract.integrationtests.common.CommonConstants;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import com.jayway.restassured.specification.ResponseSpecification;
|
||||
|
||||
@SuppressWarnings({ "unused", "rawtypes" })
|
||||
public class RecurringDepositAccountHelper {
|
||||
|
||||
private final RequestSpecification requestSpec;
|
||||
private final ResponseSpecification responseSpec;
|
||||
|
||||
public RecurringDepositAccountHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
this.requestSpec = requestSpec;
|
||||
this.responseSpec = responseSpec;
|
||||
}
|
||||
|
||||
private static final String RECURRING_DEPOSIT_ACCOUNT_URL = "/fineract-provider/api/v1/recurringdepositaccounts";
|
||||
private static final String APPLY_RECURRING_DEPOSIT_ACCOUNT_URL = RECURRING_DEPOSIT_ACCOUNT_URL + "?" + Utils.TENANT_IDENTIFIER;
|
||||
private static final String APPROVE_RECURRING_DEPOSIT_COMMAND = "approve";
|
||||
private static final String UNDO_APPROVAL_RECURRING_DEPOSIT_COMMAND = "undoapproval";
|
||||
private static final String REJECT_RECURRING_DEPOSIT_COMMAND = "reject";
|
||||
private static final String WITHDRAWN_BY_CLIENT_RECURRING_DEPOSIT_COMMAND = "withdrawnByApplicant";
|
||||
private static final String ACTIVATE_RECURRING_DEPOSIT_COMMAND = "activate";
|
||||
private static final String CLOSE_RECURRING_DEPOSIT_COMMAND = "close";
|
||||
private static final String POST_INTEREST_RECURRING_DEPOSIT_COMMAND = "postInterest";
|
||||
private static final String CALCULATE_INTEREST_RECURRING_DEPOSIT_COMMAND = "calculateInterest";
|
||||
private static final String CALCULATE_PREMATURE_AMOUNT_COMMAND = "calculatePrematureAmount";
|
||||
private static final String PREMATURE_CLOSE_COMMAND = "prematureClose";
|
||||
private static final String DEPOSIT_INTO_RECURRING_DEPOSIT_COMMAND = "deposit";
|
||||
private static final String MODIFY_TRANSACTION_COMMAND = "modify";
|
||||
private static final String UNDO_TRANSACTION_COMMAND = "undo";
|
||||
|
||||
private static final String LOCALE = "en_GB";
|
||||
private static final String DIGITS_AFTER_DECIMAL = "4";
|
||||
private static final String IN_MULTIPLES_OF = "100";
|
||||
private static final String USD = "USD";
|
||||
private static final String DAYS = "0";
|
||||
private static final String WEEKS = "1";
|
||||
private static final String MONTHS = "2";
|
||||
private static final String YEARS = "3";
|
||||
private static final String DAILY = "1";
|
||||
private static final String MONTHLY = "4";
|
||||
private static final String QUARTERLY = "5";
|
||||
private static final String BI_ANNUALLY = "6";
|
||||
private static final String ANNUALLY = "7";
|
||||
private static final String INTEREST_CALCULATION_USING_DAILY_BALANCE = "1";
|
||||
private static final String INTEREST_CALCULATION_USING_AVERAGE_DAILY_BALANCE = "2";
|
||||
private static final String DAYS_360 = "360";
|
||||
private static final String DAYS_365 = "365";
|
||||
private static final String NONE = "1";
|
||||
private static final String CASH_BASED = "2";
|
||||
private static final String ACCRUAL_PERIODIC = "3";
|
||||
private static final String ACCRUAL_UPFRONT = "4";
|
||||
|
||||
private String interestCompoundingPeriodType = MONTHLY;
|
||||
private String interestPostingPeriodType = MONTHLY;
|
||||
private String interestCalculationType = INTEREST_CALCULATION_USING_DAILY_BALANCE;
|
||||
private final String lockinPeriodFrequency = "1";
|
||||
private final String lockingPeriodFrequencyType = MONTHS;
|
||||
private final String minDepositTerm = "6";
|
||||
private final String minDepositTermTypeId = MONTHS;
|
||||
private final String maxDepositTerm = "10";
|
||||
private final String maxDepositTermTypeId = YEARS;
|
||||
private final String inMultiplesOfDepositTerm = "2";
|
||||
private final String inMultiplesOfDepositTermTypeId = MONTHS;
|
||||
private final String preClosurePenalInterest = "2";
|
||||
private final boolean preClosurePenalApplicable = true;
|
||||
private final boolean isActiveChart = true;
|
||||
private final String currencyCode = USD;
|
||||
private String interestCalculationDaysInYearType = DAYS_365;
|
||||
private final String depositAmount = "2000";
|
||||
private final String depositPeriod = "14";
|
||||
private final String depositPeriodFrequencyId = MONTHS;
|
||||
private final String recurringFrequency = "1";
|
||||
private final String recurringFrequencyType = MONTHS;
|
||||
private final String mandatoryRecommendedDepositAmount = "2000";
|
||||
private String submittedOnDate = "";
|
||||
private String expectedFirstDepositOnDate = "";
|
||||
private boolean isCalendarInherited = false;
|
||||
|
||||
public String build(final String clientId, final String productId, final String validFrom, final String validTo,
|
||||
final String penalInterestType) {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
|
||||
List<HashMap<String, String>> chartSlabs = new ArrayList<HashMap<String, String>>();
|
||||
HashMap<String, String> chartSlabsMap1 = new HashMap<>();
|
||||
chartSlabsMap1.put("description", "First");
|
||||
chartSlabsMap1.put("periodType", MONTHS);
|
||||
chartSlabsMap1.put("fromPeriod", "1");
|
||||
chartSlabsMap1.put("toPeriod", "6");
|
||||
chartSlabsMap1.put("annualInterestRate", "5");
|
||||
chartSlabsMap1.put("locale", LOCALE);
|
||||
chartSlabs.add(0, chartSlabsMap1);
|
||||
|
||||
HashMap<String, String> chartSlabsMap2 = new HashMap<>();
|
||||
chartSlabsMap2.put("description", "Second");
|
||||
chartSlabsMap2.put("periodType", MONTHS);
|
||||
chartSlabsMap2.put("fromPeriod", "7");
|
||||
chartSlabsMap2.put("toPeriod", "12");
|
||||
chartSlabsMap2.put("annualInterestRate", "6");
|
||||
chartSlabsMap2.put("locale", LOCALE);
|
||||
chartSlabs.add(1, chartSlabsMap2);
|
||||
|
||||
HashMap<String, String> chartSlabsMap3 = new HashMap<>();
|
||||
chartSlabsMap3.put("description", "Third");
|
||||
chartSlabsMap3.put("periodType", MONTHS);
|
||||
chartSlabsMap3.put("fromPeriod", "13");
|
||||
chartSlabsMap3.put("toPeriod", "18");
|
||||
chartSlabsMap3.put("annualInterestRate", "7");
|
||||
chartSlabsMap3.put("locale", LOCALE);
|
||||
chartSlabs.add(2, chartSlabsMap3);
|
||||
|
||||
HashMap<String, String> chartSlabsMap4 = new HashMap<>();
|
||||
chartSlabsMap4.put("description", "Fourth");
|
||||
chartSlabsMap4.put("periodType", MONTHS);
|
||||
chartSlabsMap4.put("fromPeriod", "19");
|
||||
chartSlabsMap4.put("toPeriod", "24");
|
||||
chartSlabsMap4.put("annualInterestRate", "8");
|
||||
chartSlabsMap4.put("locale", LOCALE);
|
||||
chartSlabs.add(3, chartSlabsMap4);
|
||||
|
||||
List<HashMap<String, Object>> charts = new ArrayList<HashMap<String, Object>>();
|
||||
HashMap<String, Object> chartsMap = new HashMap<>();
|
||||
chartsMap.put("fromDate", validFrom);
|
||||
chartsMap.put("endDate", validTo);
|
||||
chartsMap.put("dateFormat", "dd MMMM yyyy");
|
||||
chartsMap.put("locale", LOCALE);
|
||||
chartsMap.put("isActiveChart", this.isActiveChart);
|
||||
chartsMap.put("chartSlabs", chartSlabs);
|
||||
charts.add(chartsMap);
|
||||
|
||||
map.put("charts", charts);
|
||||
map.put("productId", productId);
|
||||
map.put("clientId", clientId);
|
||||
map.put("interestCalculationDaysInYearType", this.interestCalculationDaysInYearType);
|
||||
map.put("locale", LOCALE);
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("monthDayFormat", "dd MMM");
|
||||
map.put("interestCalculationType", this.interestCalculationType);
|
||||
map.put("interestCompoundingPeriodType", this.interestCompoundingPeriodType);
|
||||
map.put("interestPostingPeriodType", this.interestPostingPeriodType);
|
||||
map.put("lockinPeriodFrequency", this.lockinPeriodFrequency);
|
||||
map.put("lockinPeriodFrequencyType", this.lockingPeriodFrequencyType);
|
||||
map.put("preClosurePenalApplicable", "true");
|
||||
map.put("minDepositTermTypeId", this.minDepositTermTypeId);
|
||||
map.put("minDepositTerm", this.minDepositTerm);
|
||||
map.put("maxDepositTermTypeId", this.maxDepositTermTypeId);
|
||||
map.put("maxDepositTerm", this.maxDepositTerm);
|
||||
map.put("preClosurePenalApplicable", this.preClosurePenalApplicable);
|
||||
map.put("inMultiplesOfDepositTerm", this.inMultiplesOfDepositTerm);
|
||||
map.put("inMultiplesOfDepositTermTypeId", this.inMultiplesOfDepositTermTypeId);
|
||||
map.put("preClosurePenalInterest", this.preClosurePenalInterest);
|
||||
map.put("preClosurePenalInterestOnTypeId", penalInterestType);
|
||||
map.put("depositAmount", this.depositAmount);
|
||||
map.put("depositPeriod", this.depositPeriod);
|
||||
map.put("depositPeriodFrequencyId", this.depositPeriodFrequencyId);
|
||||
map.put("submittedOnDate", this.submittedOnDate);
|
||||
map.put("recurringFrequency", this.recurringFrequency);
|
||||
map.put("recurringFrequencyType", this.recurringFrequencyType);
|
||||
map.put("mandatoryRecommendedDepositAmount", this.mandatoryRecommendedDepositAmount);
|
||||
map.put("expectedFirstDepositOnDate", this.expectedFirstDepositOnDate);
|
||||
map.put("isCalendarInherited", this.isCalendarInherited);
|
||||
|
||||
String recurringDepositAccountJson = new Gson().toJson(map);
|
||||
System.out.println(recurringDepositAccountJson);
|
||||
return recurringDepositAccountJson;
|
||||
}
|
||||
|
||||
public static Integer applyRecurringDepositApplication(final String recurringDepositAccountAsJson,
|
||||
final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
System.out.println("--------------------- APPLYING FOR RECURRING DEPOSIT ACCOUNT ------------------------");
|
||||
return Utils.performServerPost(requestSpec, responseSpec, APPLY_RECURRING_DEPOSIT_ACCOUNT_URL, recurringDepositAccountAsJson,
|
||||
CommonConstants.RESPONSE_RESOURCE_ID);
|
||||
}
|
||||
|
||||
public static HashMap getRecurringDepositAccountById(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer accountID) {
|
||||
final String GET_RECURRING_DEPOSIT_BY_ID_URL = RECURRING_DEPOSIT_ACCOUNT_URL + "/" + accountID + "?" + Utils.TENANT_IDENTIFIER;
|
||||
System.out.println("------------------------ RETRIEVING RECURRING DEPOSIT ACCOUNT BY ID -------------------------");
|
||||
return Utils.performServerGet(requestSpec, responseSpec, GET_RECURRING_DEPOSIT_BY_ID_URL, "");
|
||||
}
|
||||
|
||||
public HashMap getRecurringDepositSummary(final Integer accountID) {
|
||||
final String URL = RECURRING_DEPOSIT_ACCOUNT_URL + "/" + accountID + "?" + Utils.TENANT_IDENTIFIER;
|
||||
final HashMap response = Utils.performServerGet(requestSpec, responseSpec, URL, "summary");
|
||||
return response;
|
||||
}
|
||||
|
||||
public static Float getInterestRate(ArrayList<ArrayList<HashMap>> interestSlabData, Integer depositPeriod) {
|
||||
|
||||
Float annualInterestRate = 0.0f;
|
||||
for (Integer slabIndex = 0; slabIndex < interestSlabData.get(0).size(); slabIndex++) {
|
||||
Integer fromPeriod = (Integer) interestSlabData.get(0).get(slabIndex).get("fromPeriod");
|
||||
Integer toPeriod = (Integer) interestSlabData.get(0).get(slabIndex).get("toPeriod");
|
||||
if (depositPeriod >= fromPeriod && depositPeriod <= toPeriod) {
|
||||
annualInterestRate = (Float) interestSlabData.get(0).get(slabIndex).get("annualInterestRate");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return annualInterestRate;
|
||||
}
|
||||
|
||||
public static Float getPrincipalAfterCompoundingInterest(Calendar currentDate, Float principal, Float depositAmount, Integer depositPeriod,
|
||||
double interestPerDay, Integer compoundingInterval, Integer postingInterval) {
|
||||
|
||||
Float totalInterest = 0.0f;
|
||||
Float interestEarned = 0.0f;
|
||||
|
||||
for (int i = 1; i <= depositPeriod; i++) {
|
||||
Integer daysInMonth = currentDate.getActualMaximum(Calendar.DATE);
|
||||
principal += depositAmount;
|
||||
for (int j = 0; j < daysInMonth; j++) {
|
||||
|
||||
interestEarned = (float) (principal * interestPerDay);
|
||||
totalInterest += interestEarned;
|
||||
if (compoundingInterval == 0) {
|
||||
principal += interestEarned;
|
||||
}
|
||||
|
||||
}
|
||||
if ((i % postingInterval) == 0 || i == depositPeriod) {
|
||||
if (compoundingInterval != 0) {
|
||||
principal += totalInterest;
|
||||
}
|
||||
totalInterest = 0.0f;
|
||||
System.out.println(principal);
|
||||
|
||||
}
|
||||
currentDate.add(Calendar.MONTH, 1);
|
||||
interestEarned = 0.0f;
|
||||
}
|
||||
return principal;
|
||||
}
|
||||
|
||||
public HashMap updateRecurringDepositAccount(final String clientID, final String productID, final String accountID,
|
||||
final String validFrom, final String validTo, final String penalInterestType, final String submittedOnDate) {
|
||||
|
||||
DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy", Locale.US);
|
||||
Calendar todaysDate = Calendar.getInstance();
|
||||
todaysDate.add(Calendar.MONTH, -1);
|
||||
todaysDate.add(Calendar.DATE, -1);
|
||||
final String SUBMITTED_ON_DATE = dateFormat.format(todaysDate.getTime());
|
||||
final String EXPECTED_FIRST_DEPOSIT_ON_ON_DATE = SUBMITTED_ON_DATE;
|
||||
final String recurringDepositApplicationJSON = new RecurringDepositAccountHelper(this.requestSpec, this.responseSpec)
|
||||
.withSubmittedOnDate(SUBMITTED_ON_DATE).withExpectedFirstDepositOnDate(EXPECTED_FIRST_DEPOSIT_ON_ON_DATE)
|
||||
.build(clientID, productID, validFrom, validTo, penalInterestType);
|
||||
|
||||
return Utils.performServerPut(this.requestSpec, this.responseSpec, RECURRING_DEPOSIT_ACCOUNT_URL + "/" + accountID + "?"
|
||||
+ Utils.TENANT_IDENTIFIER, recurringDepositApplicationJSON, CommonConstants.RESPONSE_CHANGES);
|
||||
}
|
||||
|
||||
public HashMap updateInterestCalculationConfigForRecurringDeposit(final String clientID, final String productID,
|
||||
final String accountID, final String submittedOnDate, final String validFrom, final String validTo,
|
||||
final String numberOfDaysPerYear, final String penalInterestType, final String interestCalculationType,
|
||||
final String interestCompoundingPeriodType, final String interestPostingPeriodType, final String expectedFirstDepositOnDate) {
|
||||
|
||||
final String recurringDepositApplicationJSON = new RecurringDepositAccountHelper(this.requestSpec, this.responseSpec) //
|
||||
.withSubmittedOnDate(submittedOnDate) //
|
||||
.withNumberOfDaysPerYear(numberOfDaysPerYear) //
|
||||
.withInterestCalculationPeriodType(interestCalculationType) //
|
||||
.withInterestCompoundingPeriodType(interestCompoundingPeriodType) //
|
||||
.withInterestPostingPeriodType(interestPostingPeriodType) //
|
||||
.withExpectedFirstDepositOnDate(expectedFirstDepositOnDate) //
|
||||
.build(clientID, productID, validFrom, validTo, penalInterestType);
|
||||
|
||||
return Utils.performServerPut(this.requestSpec, this.responseSpec, RECURRING_DEPOSIT_ACCOUNT_URL + "/" + accountID + "?"
|
||||
+ Utils.TENANT_IDENTIFIER, recurringDepositApplicationJSON, CommonConstants.RESPONSE_CHANGES);
|
||||
}
|
||||
|
||||
public Integer updateTransactionForRecurringDeposit(final Integer accountID, final Integer transactionId, final String transactionDate,
|
||||
final Float transactionAmount) {
|
||||
System.out.println("--------------------------------- UPDATE RECURRING DEPOSIT TRANSACTION ------------------------------------");
|
||||
return Utils.performServerPost(this.requestSpec, this.responseSpec, RECURRING_DEPOSIT_ACCOUNT_URL + "/" + accountID
|
||||
+ "/transactions/" + transactionId + "?command=" + MODIFY_TRANSACTION_COMMAND,
|
||||
getUpdateTransactionAsJSON(transactionDate, transactionAmount), CommonConstants.RESPONSE_RESOURCE_ID);
|
||||
}
|
||||
|
||||
public Integer undoTransactionForRecurringDeposit(final Integer accountID, final Integer transactionId, final String transactionDate,
|
||||
final Float transactionAmount) {
|
||||
System.out.println("--------------------------------- UNDO RECURRING DEPOSIT TRANSACTION ------------------------------------");
|
||||
return Utils.performServerPost(this.requestSpec, this.responseSpec, RECURRING_DEPOSIT_ACCOUNT_URL + "/" + accountID
|
||||
+ "/transactions/" + transactionId + "?command=" + UNDO_TRANSACTION_COMMAND,
|
||||
getUpdateTransactionAsJSON(transactionDate, transactionAmount), CommonConstants.RESPONSE_RESOURCE_ID);
|
||||
}
|
||||
|
||||
public HashMap approveRecurringDeposit(final Integer recurringDepositAccountID, final String approvedOnDate) {
|
||||
System.out
|
||||
.println("--------------------------------- APPROVING RECURRING DEPOSIT APPLICATION ------------------------------------");
|
||||
return performRecurringDepositApplicationActions(
|
||||
createRecurringDepositOperationURL(APPROVE_RECURRING_DEPOSIT_COMMAND, recurringDepositAccountID),
|
||||
getApproveRecurringDepositAccountAsJSON(approvedOnDate));
|
||||
}
|
||||
|
||||
public HashMap undoApproval(final Integer recurringDepositAccountID) {
|
||||
System.out
|
||||
.println("--------------------------------- UNDO APPROVING RECURRING DEPOSIT APPLICATION -------------------------------");
|
||||
final String undoBodyJson = "{'note':'UNDO APPROVAL'}";
|
||||
return performRecurringDepositApplicationActions(
|
||||
createRecurringDepositOperationURL(UNDO_APPROVAL_RECURRING_DEPOSIT_COMMAND, recurringDepositAccountID), undoBodyJson);
|
||||
}
|
||||
|
||||
public HashMap rejectApplication(final Integer recurringDepositAccountID, final String rejectedOnDate) {
|
||||
System.out.println("--------------------------------- REJECT RECURRING DEPOSIT APPLICATION -------------------------------");
|
||||
return performRecurringDepositApplicationActions(
|
||||
createRecurringDepositOperationURL(REJECT_RECURRING_DEPOSIT_COMMAND, recurringDepositAccountID),
|
||||
getRejectedRecurringDepositAsJSON(rejectedOnDate));
|
||||
}
|
||||
|
||||
public HashMap withdrawApplication(final Integer recurringDepositAccountID, final String withdrawApplicationOnDate) {
|
||||
System.out.println("--------------------------------- WITHDRAW RECURRING DEPOSIT APPLICATION -------------------------------");
|
||||
return performRecurringDepositApplicationActions(
|
||||
createRecurringDepositOperationURL(WITHDRAWN_BY_CLIENT_RECURRING_DEPOSIT_COMMAND, recurringDepositAccountID),
|
||||
getWithdrawnRecurringDepositAccountAsJSON(withdrawApplicationOnDate));
|
||||
}
|
||||
|
||||
public HashMap activateRecurringDeposit(final Integer recurringDepositAccountID, final String activationDate) {
|
||||
System.out
|
||||
.println("---------------------------------- ACTIVATING RECURRING DEPOSIT APPLICATION ----------------------------------");
|
||||
return performRecurringDepositApplicationActions(
|
||||
createRecurringDepositOperationURL(ACTIVATE_RECURRING_DEPOSIT_COMMAND, recurringDepositAccountID),
|
||||
getActivatedRecurringDepositAccountAsJSON(activationDate));
|
||||
}
|
||||
|
||||
public Object deleteRecurringDepositApplication(final Integer recurringDepositAccountID, final String jsonAttributeToGetBack) {
|
||||
System.out.println("---------------------------------- DELETE RECURRING DEPOSIT APPLICATION ----------------------------------");
|
||||
return Utils.performServerDelete(this.requestSpec, this.responseSpec, RECURRING_DEPOSIT_ACCOUNT_URL + "/"
|
||||
+ recurringDepositAccountID + "?" + Utils.TENANT_IDENTIFIER, jsonAttributeToGetBack);
|
||||
|
||||
}
|
||||
|
||||
public Integer calculateInterestForRecurringDeposit(final Integer recurringDepositAccountId) {
|
||||
System.out.println("--------------------------------- CALCULATING INTEREST FOR RECURRING DEPOSIT --------------------------------");
|
||||
return (Integer) performRecurringDepositActions(
|
||||
createRecurringDepositCalculateInterestURL(CALCULATE_INTEREST_RECURRING_DEPOSIT_COMMAND, recurringDepositAccountId),
|
||||
getCalculatedInterestForRecurringDepositApplicationAsJSON(), CommonConstants.RESPONSE_RESOURCE_ID);
|
||||
}
|
||||
|
||||
public Integer postInterestForRecurringDeposit(final Integer recurringDepositAccountId) {
|
||||
System.out.println("--------------------------------- POST INTEREST FOR RECURRING DEPOSIT --------------------------------");
|
||||
return (Integer) performRecurringDepositActions(
|
||||
createRecurringDepositCalculateInterestURL(POST_INTEREST_RECURRING_DEPOSIT_COMMAND, recurringDepositAccountId),
|
||||
getCalculatedInterestForRecurringDepositApplicationAsJSON(), CommonConstants.RESPONSE_RESOURCE_ID);
|
||||
}
|
||||
|
||||
public Integer depositToRecurringDepositAccount(final Integer recurringDepositAccountId, final Float depositAmount,
|
||||
final String depositedOnDate) {
|
||||
System.out.println("--------------------------------- DEPOSIT TO RECURRING DEPOSIT ACCOUNT --------------------------------");
|
||||
return (Integer) performRecurringDepositActions(
|
||||
createDepositToRecurringDepositURL(DEPOSIT_INTO_RECURRING_DEPOSIT_COMMAND, recurringDepositAccountId),
|
||||
getDepositToRecurringDepositAccountAsJSON(depositAmount, depositedOnDate), CommonConstants.RESPONSE_RESOURCE_ID);
|
||||
}
|
||||
|
||||
public HashMap calculatePrematureAmountForRecurringDeposit(final Integer recurringDepositAccountId, final String closedOnDate) {
|
||||
System.out.println("--------------------- CALCULATING PREMATURE AMOUNT FOR RECURRING DEPOSIT ----------------------------");
|
||||
return (HashMap) performRecurringDepositActions(
|
||||
createRecurringDepositCalculateInterestURL(CALCULATE_PREMATURE_AMOUNT_COMMAND, recurringDepositAccountId),
|
||||
getCalculatedPrematureAmountForRecurringDepositAccountAsJSON(closedOnDate), "");
|
||||
}
|
||||
|
||||
public Object prematureCloseForRecurringDeposit(final Integer recurringDepositAccountId, final String closedOnDate,
|
||||
final String closureType, final Integer toSavingsId, final String jsonAttributeToGetBack) {
|
||||
System.out.println("--------------------- PREMATURE CLOSE FOR RECURRING DEPOSIT ----------------------------");
|
||||
return performRecurringDepositActions(
|
||||
createRecurringDepositCalculateInterestURL(PREMATURE_CLOSE_COMMAND, recurringDepositAccountId),
|
||||
getPrematureCloseForRecurringDepositAccountAsJSON(closedOnDate, closureType, toSavingsId), jsonAttributeToGetBack);
|
||||
}
|
||||
|
||||
private String getApproveRecurringDepositAccountAsJSON(final String approvedOnDate) {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("locale", CommonConstants.locale);
|
||||
map.put("dateFormat", CommonConstants.dateFormat);
|
||||
map.put("approvedOnDate", approvedOnDate);
|
||||
map.put("note", "Approval NOTE");
|
||||
String recurringDepositAccountApproveJson = new Gson().toJson(map);
|
||||
System.out.println(recurringDepositAccountApproveJson);
|
||||
return recurringDepositAccountApproveJson;
|
||||
}
|
||||
|
||||
private String getUpdateTransactionAsJSON(final String transactionDate, final Float transactionAmount) {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("locale", CommonConstants.locale);
|
||||
map.put("dateFormat", CommonConstants.dateFormat);
|
||||
map.put("transactionDate", transactionDate);
|
||||
map.put("transactionAmount", transactionAmount);
|
||||
String updateTransactionJson = new Gson().toJson(map);
|
||||
System.out.println(updateTransactionJson);
|
||||
return updateTransactionJson;
|
||||
}
|
||||
|
||||
private String getRejectedRecurringDepositAsJSON(final String rejectedOnDate) {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("locale", CommonConstants.locale);
|
||||
map.put("dateFormat", CommonConstants.dateFormat);
|
||||
map.put("rejectedOnDate", rejectedOnDate);
|
||||
map.put("note", "Rejected NOTE");
|
||||
String recurringDepositAccountJson = new Gson().toJson(map);
|
||||
System.out.println(recurringDepositAccountJson);
|
||||
return recurringDepositAccountJson;
|
||||
}
|
||||
|
||||
private String getWithdrawnRecurringDepositAccountAsJSON(final String withdrawnApplicationOnDate) {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("locale", CommonConstants.locale);
|
||||
map.put("dateFormat", CommonConstants.dateFormat);
|
||||
map.put("withdrawnOnDate", withdrawnApplicationOnDate);
|
||||
map.put("note", "Withdraw NOTE");
|
||||
String recurringDepositAccountJson = new Gson().toJson(map);
|
||||
System.out.println(recurringDepositAccountJson);
|
||||
return recurringDepositAccountJson;
|
||||
}
|
||||
|
||||
private String getActivatedRecurringDepositAccountAsJSON(final String activationDate) {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("locale", CommonConstants.locale);
|
||||
map.put("dateFormat", CommonConstants.dateFormat);
|
||||
map.put("activatedOnDate", activationDate);
|
||||
String recurringDepositAccountActivateJson = new Gson().toJson(map);
|
||||
System.out.println(recurringDepositAccountActivateJson);
|
||||
return recurringDepositAccountActivateJson;
|
||||
}
|
||||
|
||||
private String getCalculatedInterestForRecurringDepositApplicationAsJSON() {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
String recurringDepositAccountCalculatedInterestJson = new Gson().toJson(map);
|
||||
System.out.println(recurringDepositAccountCalculatedInterestJson);
|
||||
return recurringDepositAccountCalculatedInterestJson;
|
||||
}
|
||||
|
||||
private String getCalculatedPrematureAmountForRecurringDepositAccountAsJSON(final String closedOnDate) {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("locale", CommonConstants.locale);
|
||||
map.put("dateFormat", CommonConstants.dateFormat);
|
||||
map.put("closedOnDate", closedOnDate);
|
||||
String recurringDepositAccountPrematureClosureJson = new Gson().toJson(map);
|
||||
System.out.println(recurringDepositAccountPrematureClosureJson);
|
||||
return recurringDepositAccountPrematureClosureJson;
|
||||
}
|
||||
|
||||
private String getDepositToRecurringDepositAccountAsJSON(final Float depositAmount, final String depositedOnDate) {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("locale", CommonConstants.locale);
|
||||
map.put("dateFormat", CommonConstants.dateFormat);
|
||||
map.put("transactionAmount", depositAmount);
|
||||
map.put("transactionDate", depositedOnDate);
|
||||
String recurringDepositAccountPrematureClosureJson = new Gson().toJson(map);
|
||||
System.out.println(recurringDepositAccountPrematureClosureJson);
|
||||
return recurringDepositAccountPrematureClosureJson;
|
||||
}
|
||||
|
||||
private String getPrematureCloseForRecurringDepositAccountAsJSON(final String closedOnDate, final String closureType,
|
||||
final Integer toSavingsId) {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("locale", CommonConstants.locale);
|
||||
map.put("dateFormat", CommonConstants.dateFormat);
|
||||
map.put("closedOnDate", closedOnDate);
|
||||
map.put("onAccountClosureId", closureType);
|
||||
if (toSavingsId != null) {
|
||||
map.put("toSavingsAccountId", toSavingsId);
|
||||
map.put("transferDescription", "Transferring To Savings Account");
|
||||
}
|
||||
String recurringDepositAccountPrematureCloseJson = new Gson().toJson(map);
|
||||
System.out.println(recurringDepositAccountPrematureCloseJson);
|
||||
return recurringDepositAccountPrematureCloseJson;
|
||||
}
|
||||
|
||||
private String createRecurringDepositOperationURL(final String command, final Integer recurringDepositAccountID) {
|
||||
return RECURRING_DEPOSIT_ACCOUNT_URL + "/" + recurringDepositAccountID + "?command=" + command + "&" + Utils.TENANT_IDENTIFIER;
|
||||
}
|
||||
|
||||
private Object performRecurringDepositActions(final String postURLForRecurringDeposit, final String jsonToBeSent,
|
||||
final String jsonAttributeToGetBack) {
|
||||
return Utils.performServerPost(this.requestSpec, this.responseSpec, postURLForRecurringDeposit, jsonToBeSent,
|
||||
jsonAttributeToGetBack);
|
||||
}
|
||||
|
||||
private HashMap performRecurringDepositApplicationActions(final String postURLForRecurringDepositAction, final String jsonToBeSent) {
|
||||
HashMap status = null;
|
||||
final HashMap response = Utils.performServerPost(this.requestSpec, this.responseSpec, postURLForRecurringDepositAction,
|
||||
jsonToBeSent, CommonConstants.RESPONSE_CHANGES);
|
||||
if (response != null) {
|
||||
status = (HashMap) response.get("status");
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
private String createRecurringDepositCalculateInterestURL(final String command, final Integer recurringDepositAccountID) {
|
||||
return RECURRING_DEPOSIT_ACCOUNT_URL + "/" + recurringDepositAccountID + "?command=" + command + "&" + Utils.TENANT_IDENTIFIER;
|
||||
}
|
||||
|
||||
private String createDepositToRecurringDepositURL(final String command, final Integer recurringDepositAccountID) {
|
||||
return RECURRING_DEPOSIT_ACCOUNT_URL + "/" + recurringDepositAccountID + "/transactions" + "?command=" + command + "&"
|
||||
+ Utils.TENANT_IDENTIFIER;
|
||||
}
|
||||
|
||||
public RecurringDepositAccountHelper withSubmittedOnDate(final String recurringDepositApplicationSubmittedDate) {
|
||||
this.submittedOnDate = recurringDepositApplicationSubmittedDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RecurringDepositAccountHelper withExpectedFirstDepositOnDate(final String recurringDepositApplicationExpectedFirstDepositOnDate) {
|
||||
this.expectedFirstDepositOnDate = recurringDepositApplicationExpectedFirstDepositOnDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RecurringDepositAccountHelper withNumberOfDaysPerYear(final String numberOfDaysPerYearTypeId) {
|
||||
this.interestCalculationDaysInYearType = numberOfDaysPerYearTypeId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RecurringDepositAccountHelper withInterestCalculationPeriodType(final String interestCalculationTypeId) {
|
||||
this.interestCalculationType = interestCalculationTypeId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RecurringDepositAccountHelper withInterestCompoundingPeriodType(final String interestCompoundingPeriodTypeId) {
|
||||
this.interestCompoundingPeriodType = interestCompoundingPeriodTypeId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RecurringDepositAccountHelper withInterestPostingPeriodType(final String interestPostingPeriodTypeId) {
|
||||
this.interestPostingPeriodType = interestPostingPeriodTypeId;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user