FINERACT-1209: Integration Tests using new Swagger Client API
This commit is contained in:
committed by
Michael Vorburger ⛑️
parent
1e7f1f5847
commit
578e098670
+484
@@ -0,0 +1,484 @@
|
||||
/**
|
||||
* 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 io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
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.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class AccountNumberPreferencesTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AccountNumberPreferencesTest.class);
|
||||
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 = "04 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 static final String MINIMUM_OPENING_BALANCE = "1000.0";
|
||||
private static 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;
|
||||
|
||||
@BeforeEach
|
||||
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,
|
||||
"");
|
||||
LOG.info("Successfully deleted account number preference (ID: {} )", delResponse.get("resourceId"));
|
||||
}
|
||||
/* Deletion of invalid account preference ID should fail */
|
||||
LOG.info(
|
||||
"---------------------------------DELETING ACCOUNT NUMBER PREFERENCE WITH INVALID ID------------------------------------------");
|
||||
|
||||
HashMap<String, Object> deletionError = this.accountNumberPreferencesHelper.deleteAccountNumberPreference(10,
|
||||
this.responseNotFoundError, "");
|
||||
Assertions.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");
|
||||
LOG.info("Successfully created account number preferences for Client (ID: {})", this.clientAccountNumberPreferenceId);
|
||||
|
||||
this.loanAccountNumberPreferenceId = (Integer) this.accountNumberPreferencesHelper
|
||||
.createLoanAccountNumberPreference(this.responseSpec, "resourceId");
|
||||
LOG.info("Successfully created account number preferences for Loan (ID: {} )", this.loanAccountNumberPreferenceId);
|
||||
|
||||
this.savingsAccountNumberPreferenceId = (Integer) this.accountNumberPreferencesHelper
|
||||
.createSavingsAccountNumberPreference(this.responseSpec, "resourceId");
|
||||
LOG.info("Successfully created account number preferences for Savings (ID: {})", this.savingsAccountNumberPreferenceId);
|
||||
|
||||
this.groupsAccountNumberPreferenceId = (Integer) this.accountNumberPreferencesHelper
|
||||
.createGroupsAccountNumberPreference(this.responseSpec, "resourceId");
|
||||
LOG.info("Successfully created account number preferences for Groups (ID: {})", this.groupsAccountNumberPreferenceId);
|
||||
|
||||
this.centerAccountNumberPreferenceId = (Integer) this.accountNumberPreferencesHelper
|
||||
.createCenterAccountNumberPreference(this.responseSpec, "resourceId");
|
||||
LOG.info("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 */
|
||||
LOG.info(
|
||||
"---------------------------------CREATING ACCOUNT NUMBER PREFERENCE WITH DUPLICATE DATA------------------------------------------");
|
||||
|
||||
HashMap<String, Object> creationError = this.accountNumberPreferencesHelper
|
||||
.createAccountNumberPreferenceWithInvalidData(this.responseForbiddenError, accountType, prefixType, "");
|
||||
|
||||
Assertions.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 */
|
||||
LOG.info(
|
||||
"---------------------------------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")) {
|
||||
Assertions.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")) {
|
||||
Assertions.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, "");
|
||||
|
||||
LOG.info("--------------------------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 */
|
||||
LOG.info(
|
||||
"---------------------------------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")) {
|
||||
Assertions.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, "");
|
||||
|
||||
Assertions.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);
|
||||
Assertions.assertNotNull(center);
|
||||
Assertions.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);
|
||||
Assertions.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");
|
||||
|
||||
Assertions.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);
|
||||
Assertions.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, String prefix) {
|
||||
if (prefix != null) {
|
||||
prefix = prefix.substring(0, Math.min(prefix.length(), 10));
|
||||
Assertions.assertEquals(accountNumber.length(), prefix.length() + 9);
|
||||
Assertions.assertTrue(accountNumber.startsWith(prefix));
|
||||
} else {
|
||||
Assertions.assertEquals(9, accountNumber.length());
|
||||
}
|
||||
}
|
||||
|
||||
private void createLoanProduct() {
|
||||
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||
|
||||
LOG.info("---------------------------------CREATING LOAN PRODUCT------------------------------------------");
|
||||
|
||||
final String loanProductJSON = new LoanProductTestBuilder().withPrincipal(loanPrincipalAmount)
|
||||
.withNumberOfRepayments(numberOfRepayments).withinterestRatePerPeriod(interestRatePerPeriod)
|
||||
.withInterestRateFrequencyTypeAsYear().build(null);
|
||||
|
||||
this.loanProductId = this.loanTransactionHelper.getLoanProductId(loanProductJSON);
|
||||
LOG.info("Successfully created loan product (ID: {} )", this.loanProductId);
|
||||
}
|
||||
|
||||
private void createAndValidateLoanEntity(Boolean isAccountPreferenceSetUp) {
|
||||
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||
|
||||
LOG.info("---------------------------------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);
|
||||
|
||||
LOG.info("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);
|
||||
}
|
||||
LOG.info("SUCCESSFULLY CREATED LOAN APPLICATION BASED ON ACCOUNT PREFERENCES (ID: {} )", this.loanId);
|
||||
} else {
|
||||
this.validateAccountNumberLengthAndStartsWithPrefix(loanAccountNo, null);
|
||||
LOG.info("SUCCESSFULLY CREATED LOAN APPLICATION (ID: {} )", loanId);
|
||||
}
|
||||
}
|
||||
|
||||
private void createSavingsProduct() {
|
||||
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||
|
||||
LOG.info("------------------------------CREATING NEW SAVINGS PRODUCT ---------------------------------------");
|
||||
|
||||
SavingsProductHelper savingsProductHelper = new SavingsProductHelper();
|
||||
|
||||
final String savingsProductJSON = savingsProductHelper
|
||||
//
|
||||
.withInterestCompoundingPeriodTypeAsDaily()
|
||||
//
|
||||
.withInterestPostingPeriodTypeAsMonthly()
|
||||
//
|
||||
.withInterestCalculationPeriodTypeAsDailyBalance()
|
||||
//
|
||||
.withMinBalanceForInterestCalculation(minBalanceForInterestCalculation)
|
||||
//
|
||||
.withMinRequiredBalance(minRequiredBalance).withEnforceMinRequiredBalance(enforceMinRequiredBalance)
|
||||
.withMinimumOpenningBalance(MINIMUM_OPENING_BALANCE).build();
|
||||
this.savingsProductId = SavingsProductHelper.createSavingsProduct(savingsProductJSON, this.requestSpec, this.responseSpec);
|
||||
LOG.info("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);
|
||||
}
|
||||
LOG.info("SUCCESSFULLY CREATED SAVINGS APPLICATION BASED ON ACCOUNT PREFERENCES (ID: {} )", this.loanId);
|
||||
} else {
|
||||
this.validateAccountNumberLengthAndStartsWithPrefix(savingsAccountNo, null);
|
||||
LOG.info("SUCCESSFULLY CREATED SAVINGS APPLICATION (ID:{} )", this.savingsId);
|
||||
}
|
||||
}
|
||||
}
|
||||
+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;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
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.Account.AccountType;
|
||||
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.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.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* JUnit Test Cases for Account Transfer for.
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unused" })
|
||||
public class AccountTransferTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AccountTransferTest.class);
|
||||
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;
|
||||
|
||||
static Float TRANSFER_AMOUNT = Float.valueOf(ACCOUNT_TRANSFER_AMOUNT);
|
||||
static Float TRANSFER_AMOUNT_ADJUST = Float.valueOf(ACCOUNT_TRANSFER_AMOUNT_ADJUST);
|
||||
|
||||
private FinancialActivityAccountHelper financialActivityAccountHelper;
|
||||
private Integer financialActivityAccountId;
|
||||
private Account liabilityTransferAccount;
|
||||
|
||||
@BeforeEach
|
||||
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();
|
||||
Assertions.assertNotNull(liabilityTransferAccount);
|
||||
|
||||
/*** Create A Financial Activity to Account Mapping **/
|
||||
financialActivityAccountId = (Integer) financialActivityAccountHelper.createFinancialActivityAccount(
|
||||
FinancialActivityAccountsTest.LIABILITY_TRANSFER_FINANCIAL_ACTIVITY_ID, liabilityTransferAccount.getAccountID(),
|
||||
responseSpec, CommonConstants.RESPONSE_RESOURCE_ID);
|
||||
Assertions.assertNotNull(financialActivityAccountId);
|
||||
} else {
|
||||
for (HashMap financialActivity : financialActivities) {
|
||||
HashMap financialActivityData = (HashMap) financialActivity.get("financialActivityData");
|
||||
if (financialActivityData.get("id").equals(FinancialActivityAccountsTest.LIABILITY_TRANSFER_FINANCIAL_ACTIVITY_ID)) {
|
||||
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
|
||||
*/
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
Integer deletedFinancialActivityAccountId = financialActivityAccountHelper
|
||||
.deleteFinancialActivityAccount(financialActivityAccountId, responseSpec, CommonConstants.RESPONSE_RESOURCE_ID);
|
||||
Assertions.assertNotNull(deletedFinancialActivityAccountId);
|
||||
Assertions.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");
|
||||
Assertions.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));
|
||||
Assertions.assertNotNull(toClientID);
|
||||
|
||||
final Integer toSavingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE, assetAccount,
|
||||
incomeAccount, expenseAccount, liabilityAccount);
|
||||
Assertions.assertNotNull(toSavingsProductID);
|
||||
|
||||
final Integer toSavingsID = this.savingsAccountHelper.applyForSavingsApplication(toClientID, toSavingsProductID,
|
||||
ACCOUNT_TYPE_INDIVIDUAL);
|
||||
Assertions.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");
|
||||
Assertions.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));
|
||||
Assertions.assertNotNull(fromClientID);
|
||||
|
||||
final Integer fromSavingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE,
|
||||
assetAccount, incomeAccount, expenseAccount, liabilityAccount);
|
||||
Assertions.assertNotNull(fromSavingsProductID);
|
||||
|
||||
final Integer fromSavingsID = this.savingsAccountHelper.applyForSavingsApplication(fromClientID, fromSavingsProductID,
|
||||
ACCOUNT_TYPE_INDIVIDUAL);
|
||||
Assertions.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 = Float.valueOf(MINIMUM_OPENING_BALANCE);
|
||||
Float toSavingsBalance = Float.valueOf(MINIMUM_OPENING_BALANCE);
|
||||
|
||||
this.accountTransferHelper.accountTransfer(fromClientID, fromSavingsID, fromClientID, toSavingsID, FROM_SAVINGS_ACCOUNT_TYPE,
|
||||
TO_SAVINGS_ACCOUNT_TYPE, ACCOUNT_TRANSFER_AMOUNT);
|
||||
|
||||
fromSavingsBalance -= Float.valueOf(ACCOUNT_TRANSFER_AMOUNT);
|
||||
toSavingsBalance += Float.valueOf(ACCOUNT_TRANSFER_AMOUNT);
|
||||
|
||||
HashMap fromSavingsSummaryAfter = this.savingsAccountHelper.getSavingsSummary(fromSavingsID);
|
||||
assertEquals(fromSavingsBalance, fromSavingsSummaryAfter.get("accountBalance"),
|
||||
"Verifying From Savings Account Balance after Account Transfer");
|
||||
|
||||
HashMap toSavingsSummaryAfter = this.savingsAccountHelper.getSavingsSummary(toSavingsID);
|
||||
assertEquals(toSavingsBalance, toSavingsSummaryAfter.get("accountBalance"),
|
||||
"Verifying To Savings Account Balance after Account Transfer");
|
||||
final JournalEntry[] office1LiabilityEntries = {
|
||||
new JournalEntry(Float.valueOf(ACCOUNT_TRANSFER_AMOUNT), JournalEntry.TransactionType.CREDIT) };
|
||||
final JournalEntry[] office2LiabilityEntries = {
|
||||
new JournalEntry(Float.valueOf(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");
|
||||
Assertions.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));
|
||||
Assertions.assertNotNull(toClientID);
|
||||
|
||||
Account toTransferAccount = accountHelper.createLiabilityAccount();
|
||||
Assertions.assertNotNull(toTransferAccount);
|
||||
|
||||
final Integer toLoanProductID = createLoanProduct(loanAssetAccount, loanIncomeAccount, loanExpenseAccount, overpaymentAccount);
|
||||
Assertions.assertNotNull(toLoanProductID);
|
||||
|
||||
final Integer toLoanID = applyForLoanApplication(toClientID, toLoanProductID);
|
||||
Assertions.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");
|
||||
Assertions.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));
|
||||
Assertions.assertNotNull(fromClientID);
|
||||
|
||||
final Integer fromSavingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE,
|
||||
assetAccount, incomeAccount, expenseAccount, liabilityAccount);
|
||||
Assertions.assertNotNull(fromSavingsProductID);
|
||||
|
||||
final Integer fromSavingsID = this.savingsAccountHelper.applyForSavingsApplication(fromClientID, fromSavingsProductID,
|
||||
ACCOUNT_TYPE_INDIVIDUAL);
|
||||
Assertions.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 = Float.valueOf(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(fromSavingsBalance, fromSavingsSummaryAfter.get("accountBalance"),
|
||||
"Verifying From Savings Account Balance after Account Transfer");
|
||||
|
||||
HashMap toLoanSummaryAfter = this.loanTransactionHelper.getLoanSummary(requestSpec, responseSpec, toLoanID);
|
||||
assertEquals(TRANSFER_AMOUNT_ADJUST, toLoanSummaryAfter.get("totalRepayment"),
|
||||
"Verifying To Loan Repayment Amount after Account Transfer");
|
||||
|
||||
final JournalEntry[] office1LiabilityEntries = {
|
||||
new JournalEntry(Float.valueOf(ACCOUNT_TRANSFER_AMOUNT_ADJUST), JournalEntry.TransactionType.CREDIT) };
|
||||
final JournalEntry[] office2LiabilityEntries = {
|
||||
new JournalEntry(Float.valueOf(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");
|
||||
Assertions.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));
|
||||
Assertions.assertNotNull(toClientID);
|
||||
|
||||
final Integer toSavingsProductID = createSavingsProduct(this.requestSpec, this.responseSpec, MINIMUM_OPENING_BALANCE, assetAccount,
|
||||
incomeAccount, expenseAccount, liabilityAccount);
|
||||
Assertions.assertNotNull(toSavingsProductID);
|
||||
|
||||
final Integer toSavingsID = this.savingsAccountHelper.applyForSavingsApplication(toClientID, toSavingsProductID,
|
||||
ACCOUNT_TYPE_INDIVIDUAL);
|
||||
Assertions.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");
|
||||
Assertions.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));
|
||||
Assertions.assertNotNull(fromClientID);
|
||||
|
||||
final Integer loanProductID = createLoanProduct(loanAssetAccount, loanIncomeAccount, loanExpenseAccount, overpaymentAccount);
|
||||
Assertions.assertNotNull(loanProductID);
|
||||
|
||||
final Integer loanID = applyForLoanApplication(fromClientID, loanProductID);
|
||||
Assertions.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);
|
||||
Assertions.assertNotNull(fromSavingsProductID);
|
||||
|
||||
final Integer fromSavingsID = this.savingsAccountHelper.applyForSavingsApplication(fromClientID, fromSavingsProductID,
|
||||
ACCOUNT_TYPE_INDIVIDUAL);
|
||||
Assertions.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 = Float.valueOf(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(fromSavingsBalance, fromSavingsSummaryAfter.get("accountBalance"),
|
||||
"Verifying From Savings Account Balance after Account Transfer");
|
||||
|
||||
Float toSavingsBalance = Float.valueOf(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(toSavingsBalance, toSavingsSummaryAfter.get("accountBalance"),
|
||||
"Verifying From Savings Account Balance after Account Transfer");
|
||||
|
||||
final JournalEntry[] office1LiabilityEntries = {
|
||||
new JournalEntry(Float.valueOf(ACCOUNT_TRANSFER_AMOUNT_ADJUST), JournalEntry.TransactionType.CREDIT) };
|
||||
final JournalEntry[] office2LiabilityEntries = {
|
||||
new JournalEntry(Float.valueOf(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) {
|
||||
LOG.info("------------------------------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) {
|
||||
LOG.info("------------------------------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) {
|
||||
LOG.info("--------------------------------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);
|
||||
}
|
||||
}
|
||||
+1050
File diff suppressed because it is too large
Load Diff
+46
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* 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.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.response.Response;
|
||||
import java.util.Map;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class ActuatorIntegrationTest {
|
||||
|
||||
private static final String INFO_URL = "/fineract-provider/actuator/info";
|
||||
|
||||
@Test
|
||||
public void testActuatorGitBuildInfo() {
|
||||
Response response = RestAssured.given().headers("Content-Type", ContentType.JSON, "Accept", ContentType.JSON).when().get(INFO_URL)
|
||||
.then().contentType(ContentType.JSON).extract().response();
|
||||
|
||||
Map<String, String> gitBuildInfo = response.jsonPath().getMap("git");
|
||||
|
||||
assertTrue(gitBuildInfo.containsKey("branch"));
|
||||
assertTrue(gitBuildInfo.containsKey("remote"));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* 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 io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class ApiDocsTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
Utils.initializeRESTAssured();
|
||||
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
|
||||
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApiDocsAccess() {
|
||||
Utils.performServerGet(requestSpec, responseSpec, "/fineract-provider/api-docs/apiLive.htm", null);
|
||||
}
|
||||
|
||||
}
|
||||
+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 io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import org.apache.fineract.integrationtests.common.AuditHelper;
|
||||
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||
import org.apache.fineract.integrationtests.common.OfficeHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Manthan Surkar
|
||||
*
|
||||
*/
|
||||
public class AuditIntegrationTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private ClientHelper clientHelper;
|
||||
private AuditHelper auditHelper;
|
||||
|
||||
/**
|
||||
* Sets up the essential settings for the TEST like contentType, expectedStatusCode. It uses the '@BeforeEach'
|
||||
* annotation provided by jUnit.
|
||||
*/
|
||||
@BeforeEach
|
||||
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.auditHelper = new AuditHelper(this.requestSpec, this.responseSpec);
|
||||
this.clientHelper = new ClientHelper(this.requestSpec, this.responseSpec);
|
||||
}
|
||||
|
||||
/**
|
||||
* Here we Create/Update different Entities and verify an audit is generated for each action. This can be further
|
||||
* extened with more entities and actions in similiar way.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void auditShouldbeCreated() {
|
||||
// Audits recieved after all actions are performed.
|
||||
List<HashMap<String, Object>> auditsRecieved;
|
||||
|
||||
// Audits recieved before any action is performed, needed in special
|
||||
// cases eg: reactivate client, close client
|
||||
List<HashMap<String, Object>> auditsRecievedInitial;
|
||||
|
||||
// When Client is created: Count should be "1"
|
||||
final Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
Assertions.assertNotNull(clientId);
|
||||
auditsRecieved = auditHelper.getAuditDetails(clientId, "CREATE", "CLIENT");
|
||||
auditHelper.verifyOneAuditOnly(auditsRecieved, clientId, "CREATE", "CLIENT");
|
||||
|
||||
// Performs multiple close and reactivate on client
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
// Close
|
||||
auditsRecievedInitial = auditHelper.getAuditDetails(clientId, "CLOSE", "CLIENT");
|
||||
this.clientHelper.closeClient(clientId);
|
||||
auditsRecieved = auditHelper.getAuditDetails(clientId, "CLOSE", "CLIENT");
|
||||
auditHelper.verifyMultipleAuditsOnserver(auditsRecievedInitial, auditsRecieved, clientId, "CLOSE", "CLIENT");
|
||||
|
||||
// Activate
|
||||
auditsRecievedInitial = auditHelper.getAuditDetails(clientId, "REACTIVATE", "CLIENT");
|
||||
this.clientHelper.reactivateClient(clientId);
|
||||
auditsRecieved = auditHelper.getAuditDetails(clientId, "REACTIVATE", "CLIENT");
|
||||
auditHelper.verifyMultipleAuditsOnserver(auditsRecievedInitial, auditsRecieved, clientId, "REACTIVATE", "CLIENT");
|
||||
}
|
||||
|
||||
// When Office is created
|
||||
OfficeHelper officeHelper = new OfficeHelper(requestSpec, responseSpec);
|
||||
int officeId = officeHelper.createOffice("22 June 2020");
|
||||
auditsRecieved = auditHelper.getAuditDetails(officeId, "CREATE", "OFFICE");
|
||||
auditHelper.verifyOneAuditOnly(auditsRecieved, officeId, "CREATE", "OFFICE");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkAuditsWithLimitParam() {
|
||||
// Create client
|
||||
final Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
|
||||
// The following loop would ensure database have atleast 8 audits.
|
||||
for (int i = 0; i < 4; i++) {
|
||||
// Close client
|
||||
this.clientHelper.closeClient(clientId);
|
||||
// Activate client
|
||||
this.clientHelper.reactivateClient(clientId);
|
||||
}
|
||||
|
||||
Random rand = new Random();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
// limit contains a number between 1-8
|
||||
int limit = rand.nextInt(7) + 1;
|
||||
auditHelper.verifyLimitParameterfor(limit);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkIfOrderBySupported() {
|
||||
final List<String> shouldBeSupportedFor = Arrays.asList("checkedOnDate", "officeName", "resourceId", "clientId", "processingResult",
|
||||
"clientName", "maker", "subresourceId", "checker", "savingsAccountNo", "loanAccountNo", "groupName", "entityName",
|
||||
"madeOnDate", "id", "loanId", "actionName");
|
||||
|
||||
for (int i = 0; i < shouldBeSupportedFor.size(); i++) {
|
||||
auditHelper.verifyOrderBysupported(shouldBeSupportedFor.get(i));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+517
@@ -0,0 +1,517 @@
|
||||
/**
|
||||
* 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.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
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.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Sets up the essential settings for the TEST like contentType, expectedStatusCode. It uses the '@BeforeEach'
|
||||
* annotation provided by jUnit.
|
||||
*/
|
||||
@BeforeEach
|
||||
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) {
|
||||
Assertions.assertEquals((long) 501, (long) resp.getStatusCode(), "Verify Status code 501");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
Assertions.assertEquals((long) 200, (long) resp.getStatusCode(), "Verify Status code 200");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
Assertions.assertEquals(1, response.size());
|
||||
Assertions.assertEquals((long) 400, (long) response.get(0).getStatusCode(), "Verify Status code 400");
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
Assertions.assertEquals("TestFirstName", changes.get("firstname").getAsString());
|
||||
Assertions.assertEquals("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");
|
||||
|
||||
Assertions.assertEquals(200L, (long) response.get(1).getStatusCode(), "Verify Status Code 200" + clientId.getAsString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
Assertions.assertEquals(200L, (long) response.get(1).getStatusCode(), "Verify Status Code 200");
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
Assertions.assertEquals(200L, (long) response.get(3).getStatusCode(), "Verify Status Code 200 for Create Loan Charge");
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that batch repayment for loans is happening properly. Collected properly 200(OK) status was returned for
|
||||
* successful responses. It first creates a new loan and then makes two repayments for it and then verifies that
|
||||
* 200(OK) is returned for the repayment requests.
|
||||
*
|
||||
* @see org.apache.fineract.batch.command.internal.RepayLoanCommandStrategy
|
||||
*/
|
||||
@Test
|
||||
public void shouldReturnOkStatusForBatchRepayment() {
|
||||
|
||||
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);
|
||||
|
||||
// Create a loanRepay Request
|
||||
final BatchRequest br6 = BatchHelper.repayLoanRequest(4735L, 4734L);
|
||||
|
||||
// Create a loanRepay Request
|
||||
final BatchRequest br7 = BatchHelper.repayLoanRequest(4736L, 4734L);
|
||||
|
||||
final List<BatchRequest> batchRequests = new ArrayList<>();
|
||||
|
||||
batchRequests.add(br1);
|
||||
batchRequests.add(br2);
|
||||
batchRequests.add(br3);
|
||||
batchRequests.add(br4);
|
||||
batchRequests.add(br5);
|
||||
batchRequests.add(br6);
|
||||
batchRequests.add(br7);
|
||||
|
||||
final String jsonifiedRequest = BatchHelper.toJsonString(batchRequests);
|
||||
|
||||
final List<BatchResponse> response = BatchHelper.postBatchRequestsWithoutEnclosingTransaction(this.requestSpec, this.responseSpec,
|
||||
jsonifiedRequest);
|
||||
|
||||
Assertions.assertEquals(200L, (long) response.get(5).getStatusCode(), "Verify Status Code 200 for Repayment");
|
||||
Assertions.assertEquals(200L, (long) response.get(6).getStatusCode(), "Verify Status Code 200 for Repayment");
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
Assertions.assertEquals(200L, (long) response.get(0).getStatusCode(), "Verify Status Code 200 for Create Client");
|
||||
Assertions.assertEquals(200L, (long) response.get(1).getStatusCode(), "Verify Status Code 200 for Activate Client");
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
Assertions.assertEquals(200L, (long) response.get(3).getStatusCode(), "Verify Status Code 200 for Approve Loan");
|
||||
Assertions.assertEquals(200L, (long) response.get(4).getStatusCode(), "Verify Status Code 200 for Disburse Loan");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for the successful create client, apply loan,approval and disbursal of a loan using Batch API with
|
||||
* enclosingTransaction. 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 shouldReturnOkStatusOnSuccessfulLoanApprovalAndDisburseWithTransaction() {
|
||||
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.createActiveClientRequest(4740L, "");
|
||||
|
||||
// Create a ApplyLoan Request
|
||||
final BatchRequest br2 = BatchHelper.applyLoanRequest(4742L, 4740L, productId);
|
||||
|
||||
// Create a approveLoan Request
|
||||
final BatchRequest br3 = BatchHelper.approveLoanRequest(4743L, 4742L);
|
||||
|
||||
// Create a disburseLoan Request
|
||||
final BatchRequest br4 = BatchHelper.disburseLoanRequest(4744L, 4743L);
|
||||
|
||||
final List<BatchRequest> batchRequests = Arrays.asList(br1, br2, br3, br4);
|
||||
|
||||
final String jsonifiedRequest = BatchHelper.toJsonString(batchRequests);
|
||||
|
||||
final List<BatchResponse> response = BatchHelper.postBatchRequestsWithEnclosingTransaction(this.requestSpec, this.responseSpec,
|
||||
jsonifiedRequest);
|
||||
|
||||
Assertions.assertEquals(200L, (long) response.get(0).getStatusCode(), "Verify Status Code 200 for create client");
|
||||
Assertions.assertEquals(200L, (long) response.get(1).getStatusCode(), "Verify Status Code 200 for apply Loan");
|
||||
Assertions.assertEquals(200L, (long) response.get(2).getStatusCode(), "Verify Status Code 200 for approve Loan");
|
||||
Assertions.assertEquals(200L, (long) response.get(3).getStatusCode(), "Verify Status Code 200 for disburse Loan");
|
||||
}
|
||||
}
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
/**
|
||||
* 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 io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
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.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* 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 static final Logger LOG = LoggerFactory.getLogger(BatchRequestsIntegrationTest.class);
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
|
||||
public BatchRequestsIntegrationTest() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the essential settings for the TEST like contentType, expectedStatusCode. It uses the '@BeforeEach'
|
||||
* annotation provided by jUnit.
|
||||
*/
|
||||
@BeforeEach
|
||||
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());
|
||||
LOG.info("client {} has been added to the group {}", clientIDs[i], 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) {
|
||||
Assertions.assertEquals(200L, (long) res.getStatusCode(), "Verify Status Code 200");
|
||||
}
|
||||
}
|
||||
}
|
||||
+262
@@ -0,0 +1,262 @@
|
||||
/**
|
||||
* 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.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
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.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class CenterIntegrationTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(CenterIntegrationTest.class);
|
||||
private RequestSpecification requestSpec;
|
||||
private ResponseSpecification responseSpec;
|
||||
|
||||
@BeforeEach
|
||||
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);
|
||||
|
||||
Assertions.assertNotNull(center);
|
||||
Assertions.assertTrue(center.getName().equals(name));
|
||||
Assertions.assertTrue(center.getOfficeId() == officeId);
|
||||
Assertions.assertTrue(center.isActive() == false);
|
||||
|
||||
// Test retrieval by listing all centers
|
||||
int id = CenterHelper.listCenters(requestSpec, responseSpec).get(0).getId();
|
||||
Assertions.assertTrue(id > 0);
|
||||
|
||||
CenterDomain retrievedCenter = CenterHelper.retrieveByID(id, requestSpec, responseSpec);
|
||||
Assertions.assertNotNull(retrievedCenter);
|
||||
Assertions.assertNotNull(retrievedCenter.getName());
|
||||
Assertions.assertNotNull(retrievedCenter.getHierarchy());
|
||||
Assertions.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);
|
||||
|
||||
Assertions.assertNotNull(center);
|
||||
Assertions.assertTrue(center.getName().equals(name));
|
||||
Assertions.assertTrue(center.getOfficeId() == officeId);
|
||||
Assertions.assertTrue(center.getExternalId().equals(externalId));
|
||||
Assertions.assertTrue(center.getStaffId() == staffId);
|
||||
Assertions.assertTrue(center.isActive() == false);
|
||||
Assertions.assertArrayEquals(center.getGroupMembers(), groupMembers);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListCenters() {
|
||||
ArrayList<CenterDomain> paginatedList = CenterHelper.paginatedListCenters(requestSpec, responseSpec);
|
||||
ArrayList<CenterDomain> list = CenterHelper.listCenters(requestSpec, responseSpec);
|
||||
|
||||
Assertions.assertNotNull(paginatedList);
|
||||
Assertions.assertNotNull(list);
|
||||
Assertions.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);
|
||||
Assertions.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);
|
||||
Assertions.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);
|
||||
Assertions.assertNotNull(response);
|
||||
Assertions.assertEquals(newName, response.get("name"));
|
||||
Assertions.assertEquals(newExternalId, response.get("externalId"));
|
||||
Assertions.assertEquals(Integer.valueOf(newStaffId), Integer.valueOf(response.get("staffId").toString()));
|
||||
|
||||
CenterDomain center = CenterHelper.retrieveByID(resourceId, requestSpec, responseSpec);
|
||||
Assertions.assertNotNull(center);
|
||||
Assertions.assertEquals(newName, center.getName());
|
||||
Assertions.assertEquals(newExternalId, center.getExternalId());
|
||||
Assertions.assertEquals((Integer) newStaffId, center.getStaffId());
|
||||
Assertions.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);
|
||||
Assertions.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() {
|
||||
|
||||
final Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
|
||||
LOG.info("--------------creating first staff with id------------- {}", staffId);
|
||||
Assertions.assertNotNull(staffId);
|
||||
|
||||
final int centerWithStaffId = CenterHelper.createCenterWithStaffId(this.requestSpec, this.responseSpec, staffId);
|
||||
final CenterDomain center = CenterHelper.retrieveByID(centerWithStaffId, requestSpec, responseSpec);
|
||||
Assertions.assertNotNull(center);
|
||||
Assertions.assertTrue(center.getId() == centerWithStaffId);
|
||||
Assertions.assertTrue(center.getStaffId().intValue() == staffId);
|
||||
Assertions.assertTrue(center.isActive() == true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAssignStaffToCenter() {
|
||||
final Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
|
||||
LOG.info("--------------creating first staff with id------------- {}", staffId);
|
||||
Assertions.assertNotNull(staffId);
|
||||
|
||||
final Integer groupID = CenterHelper.createCenter(this.requestSpec, this.responseSpec);
|
||||
CenterHelper.verifyCenterCreatedOnServer(this.requestSpec, this.responseSpec, groupID);
|
||||
|
||||
final HashMap assignStaffToCenterResponseMap = (HashMap) CenterHelper.assignStaff(this.requestSpec, this.responseSpec,
|
||||
groupID.toString(), staffId.longValue());
|
||||
assertEquals(assignStaffToCenterResponseMap.get("staffId"), staffId, "Verify assigned staff id is the same as id sent");
|
||||
|
||||
final CenterDomain center = CenterHelper.retrieveByID(groupID, requestSpec, responseSpec);
|
||||
Assertions.assertNotNull(center);
|
||||
Assertions.assertTrue(center.getId().intValue() == groupID);
|
||||
Assertions.assertTrue(center.getStaffId().intValue() == staffId);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnassignStaffToCenter() {
|
||||
final Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
|
||||
LOG.info("--------------creating first staff with id------------- {}", staffId);
|
||||
Assertions.assertNotNull(staffId);
|
||||
|
||||
final Integer groupID = CenterHelper.createCenter(this.requestSpec, this.responseSpec);
|
||||
CenterHelper.verifyCenterCreatedOnServer(this.requestSpec, this.responseSpec, groupID);
|
||||
|
||||
final HashMap assignStaffToCenterResponseMap = (HashMap) CenterHelper.assignStaff(this.requestSpec, this.responseSpec,
|
||||
groupID.toString(), staffId.longValue());
|
||||
assertEquals(assignStaffToCenterResponseMap.get("staffId"), staffId, "Verify assigned staff id is the same as id sent");
|
||||
final CenterDomain centerWithStaffAssigned = CenterHelper.retrieveByID(groupID, requestSpec, responseSpec);
|
||||
Assertions.assertNotNull(centerWithStaffAssigned);
|
||||
Assertions.assertTrue(centerWithStaffAssigned.getId().intValue() == groupID);
|
||||
Assertions.assertTrue(centerWithStaffAssigned.getStaffId().intValue() == staffId);
|
||||
|
||||
final HashMap unassignStaffToCenterResponseMap = (HashMap) CenterHelper.unassignStaff(this.requestSpec, this.responseSpec,
|
||||
groupID.toString(), staffId.longValue());
|
||||
assertEquals(unassignStaffToCenterResponseMap.get("staffId"), null, "Verify staffId is null after unassigning ");
|
||||
final CenterDomain centerWithStaffUnssigned = CenterHelper.retrieveByID(groupID, requestSpec, responseSpec);
|
||||
Assertions.assertNotNull(centerWithStaffUnssigned);
|
||||
Assertions.assertTrue(centerWithStaffUnssigned.getId().intValue() == groupID);
|
||||
Assertions.assertTrue(centerWithStaffUnssigned.getStaffId() == null);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+324
@@ -0,0 +1,324 @@
|
||||
/**
|
||||
* 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 io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
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.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@SuppressWarnings({ "rawtypes" })
|
||||
public class ChargesTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
|
||||
@BeforeEach
|
||||
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);
|
||||
Assertions.assertNotNull(allChargesData);
|
||||
|
||||
// Testing Creation, Updation and Deletion of Disbursement Charge
|
||||
final Integer disbursementChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
|
||||
ChargesHelper.getLoanDisbursementJSON());
|
||||
Assertions.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);
|
||||
Assertions.assertEquals(chargeDataAfterChanges.get("amount"), changes.get("amount"), "Verifying Charge after Modification");
|
||||
|
||||
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, disbursementChargeId,
|
||||
ChargesHelper.getModifyChargeAsPecentageAmountJSON());
|
||||
|
||||
chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, disbursementChargeId);
|
||||
|
||||
HashMap chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargePaymentMode");
|
||||
Assertions.assertEquals(chargeChangedData.get("id"), changes.get("chargePaymentMode"), "Verifying Charge after Modification");
|
||||
|
||||
chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargeCalculationType");
|
||||
Assertions.assertEquals(chargeChangedData.get("id"), changes.get("chargeCalculationType"), "Verifying Charge after Modification");
|
||||
|
||||
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, disbursementChargeId,
|
||||
ChargesHelper.getModifyChargeAsPecentageLoanAmountWithInterestJSON());
|
||||
|
||||
chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, disbursementChargeId);
|
||||
|
||||
chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargeCalculationType");
|
||||
Assertions.assertEquals(chargeChangedData.get("id"), changes.get("chargeCalculationType"), "Verifying Charge after Modification");
|
||||
|
||||
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, disbursementChargeId,
|
||||
ChargesHelper.getModifyChargeAsPercentageInterestJSON());
|
||||
|
||||
chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, disbursementChargeId);
|
||||
|
||||
chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargeCalculationType");
|
||||
Assertions.assertEquals(chargeChangedData.get("id"), changes.get("chargeCalculationType"), "Verifying Charge after Modification");
|
||||
|
||||
Integer chargeIdAfterDeletion = ChargesHelper.deleteCharge(this.responseSpec, this.requestSpec, disbursementChargeId);
|
||||
Assertions.assertEquals(disbursementChargeId, chargeIdAfterDeletion, "Verifying Charge ID after deletion");
|
||||
|
||||
// Testing Creation, Updation and Deletion of Specified due date Charge
|
||||
final Integer specifiedDueDateChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
|
||||
ChargesHelper.getLoanSpecifiedDueDateJSON());
|
||||
Assertions.assertNotNull(specifiedDueDateChargeId);
|
||||
|
||||
// Updating Charge Amount
|
||||
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, specifiedDueDateChargeId,
|
||||
ChargesHelper.getModifyChargeJSON());
|
||||
|
||||
chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, specifiedDueDateChargeId);
|
||||
Assertions.assertEquals(chargeDataAfterChanges.get("amount"), changes.get("amount"), "Verifying Charge after Modification");
|
||||
|
||||
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, specifiedDueDateChargeId,
|
||||
ChargesHelper.getModifyChargeAsPecentageAmountJSON());
|
||||
|
||||
chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, specifiedDueDateChargeId);
|
||||
|
||||
chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargePaymentMode");
|
||||
Assertions.assertEquals(chargeChangedData.get("id"), changes.get("chargePaymentMode"), "Verifying Charge after Modification");
|
||||
|
||||
chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargeCalculationType");
|
||||
Assertions.assertEquals(chargeChangedData.get("id"), changes.get("chargeCalculationType"), "Verifying Charge after Modification");
|
||||
|
||||
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, specifiedDueDateChargeId,
|
||||
ChargesHelper.getModifyChargeAsPecentageLoanAmountWithInterestJSON());
|
||||
|
||||
chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, specifiedDueDateChargeId);
|
||||
|
||||
chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargeCalculationType");
|
||||
Assertions.assertEquals(chargeChangedData.get("id"), changes.get("chargeCalculationType"), "Verifying Charge after Modification");
|
||||
|
||||
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, specifiedDueDateChargeId,
|
||||
ChargesHelper.getModifyChargeAsPercentageInterestJSON());
|
||||
|
||||
chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, specifiedDueDateChargeId);
|
||||
|
||||
chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargeCalculationType");
|
||||
Assertions.assertEquals(chargeChangedData.get("id"), changes.get("chargeCalculationType"), "Verifying Charge after Modification");
|
||||
|
||||
chargeIdAfterDeletion = ChargesHelper.deleteCharge(this.responseSpec, this.requestSpec, specifiedDueDateChargeId);
|
||||
Assertions.assertEquals(specifiedDueDateChargeId, chargeIdAfterDeletion, "Verifying Charge ID after deletion");
|
||||
|
||||
// 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);
|
||||
Assertions.assertEquals(chargeDataAfterChanges.get("amount"), changes.get("amount"), "Verifying Charge after Modification");
|
||||
|
||||
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, installmentFeeChargeId,
|
||||
ChargesHelper.getModifyChargeAsPecentageAmountJSON());
|
||||
|
||||
chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, installmentFeeChargeId);
|
||||
|
||||
chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargePaymentMode");
|
||||
Assertions.assertEquals(chargeChangedData.get("id"), changes.get("chargePaymentMode"), "Verifying Charge after Modification");
|
||||
|
||||
chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargeCalculationType");
|
||||
Assertions.assertEquals(chargeChangedData.get("id"), changes.get("chargeCalculationType"), "Verifying Charge after Modification");
|
||||
|
||||
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, installmentFeeChargeId,
|
||||
ChargesHelper.getModifyChargeAsPecentageLoanAmountWithInterestJSON());
|
||||
|
||||
chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, installmentFeeChargeId);
|
||||
|
||||
chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargeCalculationType");
|
||||
Assertions.assertEquals(chargeChangedData.get("id"), changes.get("chargeCalculationType"), "Verifying Charge after Modification");
|
||||
|
||||
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, installmentFeeChargeId,
|
||||
ChargesHelper.getModifyChargeAsPercentageInterestJSON());
|
||||
|
||||
chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, installmentFeeChargeId);
|
||||
|
||||
chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargeCalculationType");
|
||||
Assertions.assertEquals(chargeChangedData.get("id"), changes.get("chargeCalculationType"), "Verifying Charge after Modification");
|
||||
|
||||
chargeIdAfterDeletion = ChargesHelper.deleteCharge(this.responseSpec, this.requestSpec, installmentFeeChargeId);
|
||||
Assertions.assertEquals(installmentFeeChargeId, chargeIdAfterDeletion, "Verifying Charge ID after deletion");
|
||||
|
||||
// Testing Creation, Updation and Deletion of Overdue Installment Fee
|
||||
// Charge
|
||||
final Integer overdueFeeChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
|
||||
ChargesHelper.getLoanOverdueFeeJSON());
|
||||
Assertions.assertNotNull(overdueFeeChargeId);
|
||||
|
||||
// Updating Charge Amount
|
||||
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, overdueFeeChargeId, ChargesHelper.getModifyChargeJSON());
|
||||
|
||||
chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, overdueFeeChargeId);
|
||||
Assertions.assertEquals(chargeDataAfterChanges.get("amount"), changes.get("amount"), "Verifying Charge after Modification");
|
||||
|
||||
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, overdueFeeChargeId,
|
||||
ChargesHelper.getModifyChargeAsPecentageAmountJSON());
|
||||
|
||||
chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, overdueFeeChargeId);
|
||||
|
||||
chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargePaymentMode");
|
||||
Assertions.assertEquals(chargeChangedData.get("id"), changes.get("chargePaymentMode"), "Verifying Charge after Modification");
|
||||
|
||||
chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargeCalculationType");
|
||||
Assertions.assertEquals(chargeChangedData.get("id"), changes.get("chargeCalculationType"), "Verifying Charge after Modification");
|
||||
|
||||
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, overdueFeeChargeId,
|
||||
ChargesHelper.getModifyChargeAsPecentageLoanAmountWithInterestJSON());
|
||||
|
||||
chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, overdueFeeChargeId);
|
||||
|
||||
chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargeCalculationType");
|
||||
Assertions.assertEquals(chargeChangedData.get("id"), changes.get("chargeCalculationType"), "Verifying Charge after Modification");
|
||||
|
||||
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, overdueFeeChargeId,
|
||||
ChargesHelper.getModifyChargeAsPercentageInterestJSON());
|
||||
|
||||
chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, overdueFeeChargeId);
|
||||
|
||||
chargeChangedData = (HashMap) chargeDataAfterChanges.get("chargeCalculationType");
|
||||
Assertions.assertEquals(chargeChangedData.get("id"), changes.get("chargeCalculationType"), "Verifying Charge after Modification");
|
||||
|
||||
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, overdueFeeChargeId,
|
||||
ChargesHelper.getModifyChargeFeeFrequencyAsYearsJSON());
|
||||
|
||||
chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, overdueFeeChargeId);
|
||||
|
||||
chargeChangedData = (HashMap) chargeDataAfterChanges.get("feeFrequency");
|
||||
Assertions.assertEquals(chargeChangedData.get("id"), changes.get("feeFrequency"), "Verifying Charge after Modification");
|
||||
|
||||
chargeIdAfterDeletion = ChargesHelper.deleteCharge(this.responseSpec, this.requestSpec, overdueFeeChargeId);
|
||||
Assertions.assertEquals(overdueFeeChargeId, chargeIdAfterDeletion, "Verifying Charge ID after deletion");
|
||||
}
|
||||
|
||||
@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());
|
||||
Assertions.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);
|
||||
Assertions.assertEquals(chargeDataAfterChanges.get("amount"), changes.get("amount"), "Verifying Charge after Modification");
|
||||
|
||||
Integer chargeIdAfterDeletion = ChargesHelper.deleteCharge(this.responseSpec, this.requestSpec, specifiedDueDateChargeId);
|
||||
Assertions.assertEquals(specifiedDueDateChargeId, chargeIdAfterDeletion, "Verifying Charge ID after deletion");
|
||||
|
||||
// Testing Creation, Updation and Deletion of Savings Activation Charge
|
||||
final Integer savingsActivationChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
|
||||
ChargesHelper.getSavingsActivationFeeJSON());
|
||||
Assertions.assertNotNull(savingsActivationChargeId);
|
||||
|
||||
// Updating Charge Amount
|
||||
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, savingsActivationChargeId,
|
||||
ChargesHelper.getModifyChargeJSON());
|
||||
|
||||
chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, savingsActivationChargeId);
|
||||
Assertions.assertEquals(chargeDataAfterChanges.get("amount"), changes.get("amount"), "Verifying Charge after Modification");
|
||||
|
||||
chargeIdAfterDeletion = ChargesHelper.deleteCharge(this.responseSpec, this.requestSpec, savingsActivationChargeId);
|
||||
Assertions.assertEquals(savingsActivationChargeId, chargeIdAfterDeletion, "Verifying Charge ID after deletion");
|
||||
|
||||
// Testing Creation, Updation and Deletion of Charge for Withdrawal Fee
|
||||
final Integer withdrawalFeeChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
|
||||
ChargesHelper.getSavingsWithdrawalFeeJSON());
|
||||
Assertions.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");
|
||||
Assertions.assertEquals(chargeChangedData.get("id"), changes.get("chargeCalculationType"), "Verifying Charge after Modification");
|
||||
|
||||
chargeIdAfterDeletion = ChargesHelper.deleteCharge(this.responseSpec, this.requestSpec, withdrawalFeeChargeId);
|
||||
Assertions.assertEquals(withdrawalFeeChargeId, chargeIdAfterDeletion, "Verifying Charge ID after deletion");
|
||||
|
||||
// Testing Creation, Updation and Deletion of Charge for Annual Fee
|
||||
final Integer annualFeeChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
|
||||
ChargesHelper.getSavingsAnnualFeeJSON());
|
||||
Assertions.assertNotNull(annualFeeChargeId);
|
||||
|
||||
// Updating Charge Amount
|
||||
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, annualFeeChargeId, ChargesHelper.getModifyChargeJSON());
|
||||
|
||||
chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, annualFeeChargeId);
|
||||
Assertions.assertEquals(chargeDataAfterChanges.get("amount"), changes.get("amount"), "Verifying Charge after Modification");
|
||||
|
||||
chargeIdAfterDeletion = ChargesHelper.deleteCharge(this.responseSpec, this.requestSpec, annualFeeChargeId);
|
||||
Assertions.assertEquals(annualFeeChargeId, chargeIdAfterDeletion, "Verifying Charge ID after deletion");
|
||||
|
||||
// Testing Creation, Updation and Deletion of Charge for Monthly Fee
|
||||
final Integer monthlyFeeChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
|
||||
ChargesHelper.getSavingsMonthlyFeeJSON());
|
||||
Assertions.assertNotNull(monthlyFeeChargeId);
|
||||
|
||||
// Updating Charge Amount
|
||||
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, monthlyFeeChargeId, ChargesHelper.getModifyChargeJSON());
|
||||
|
||||
chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, monthlyFeeChargeId);
|
||||
Assertions.assertEquals(chargeDataAfterChanges.get("amount"), changes.get("amount"), "Verifying Charge after Modification");
|
||||
|
||||
chargeIdAfterDeletion = ChargesHelper.deleteCharge(this.responseSpec, this.requestSpec, monthlyFeeChargeId);
|
||||
Assertions.assertEquals(monthlyFeeChargeId, chargeIdAfterDeletion, "Verifying Charge ID after deletion");
|
||||
|
||||
// Testing Creation, Updation and Deletion of Charge for Overdraft Fee
|
||||
final Integer overdraftFeeChargeId = ChargesHelper.createCharges(this.requestSpec, this.responseSpec,
|
||||
ChargesHelper.getSavingsOverdraftFeeJSON());
|
||||
Assertions.assertNotNull(overdraftFeeChargeId);
|
||||
|
||||
// Updating Charge Amount
|
||||
changes = ChargesHelper.updateCharges(this.requestSpec, this.responseSpec, overdraftFeeChargeId,
|
||||
ChargesHelper.getModifyChargeJSON());
|
||||
|
||||
chargeDataAfterChanges = ChargesHelper.getChargeById(this.requestSpec, this.responseSpec, overdraftFeeChargeId);
|
||||
Assertions.assertEquals(chargeDataAfterChanges.get("amount"), changes.get("amount"), "Verifying Charge after Modification");
|
||||
|
||||
chargeIdAfterDeletion = ChargesHelper.deleteCharge(this.responseSpec, this.requestSpec, overdraftFeeChargeId);
|
||||
Assertions.assertEquals(overdraftFeeChargeId, chargeIdAfterDeletion, "Verifying Charge ID after deletion");
|
||||
}
|
||||
}
|
||||
+5114
File diff suppressed because it is too large
Load Diff
+2110
File diff suppressed because it is too large
Load Diff
+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;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.HashMap;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public final class ClientStatusChecker {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ClientStatusChecker.class);
|
||||
|
||||
private ClientStatusChecker() {
|
||||
|
||||
}
|
||||
|
||||
public static void verifyClientIsActive(final HashMap<String, Object> clientStatusHashMap) {
|
||||
assertEquals(300, (int) clientStatusHashMap.get("id"));
|
||||
}
|
||||
|
||||
public static void verifyClientClosed(final HashMap<String, Object> clientStatusHashMap) {
|
||||
LOG.info("\n-------------------------------------- VERIFYING CLIENT IS CLOSED ------------------------------------");
|
||||
assertEquals(600, (int) clientStatusHashMap.get("id"));
|
||||
LOG.info("Client Status: {} \n", clientStatusHashMap);
|
||||
}
|
||||
|
||||
public static void verifyClientPending(final HashMap<String, Object> clientStatusHashMap) {
|
||||
LOG.info("\n-------------------------------------- VERIFYING CLIENT IS PENDING ------------------------------------");
|
||||
assertEquals(100, (int) clientStatusHashMap.get("id"));
|
||||
LOG.info("Client Status: {} \n", clientStatusHashMap);
|
||||
}
|
||||
|
||||
public static void verifyClientRejected(final HashMap<String, Object> clientStatusHashMap) {
|
||||
LOG.info("\n-------------------------------------- VERIFYING CLIENT IS REJECTED ------------------------------------");
|
||||
assertEquals(700, (int) clientStatusHashMap.get("id"));
|
||||
LOG.info("Client Status: {} \n", clientStatusHashMap);
|
||||
}
|
||||
|
||||
public static void verifyClientActiavted(final HashMap<String, Object> clientStatusHashMap) {
|
||||
LOG.info("\n-------------------------------------- VERIFYING CLIENT IS ACTIVATED ------------------------------------");
|
||||
assertEquals(300, (int) clientStatusHashMap.get("id"));
|
||||
LOG.info("Client Status: {} \n", clientStatusHashMap);
|
||||
}
|
||||
|
||||
public static void verifyClientWithdrawn(final HashMap<String, Object> clientStatusHashMap) {
|
||||
LOG.info("\n-------------------------------------- VERIFYING CLIENT IS WITHDRAWN ------------------------------------");
|
||||
assertEquals(800, (int) clientStatusHashMap.get("id"));
|
||||
LOG.info("Client Status: {} \n", clientStatusHashMap);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
/**
|
||||
* 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.jupiter.api.Assertions.assertNotEquals;
|
||||
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class ClientTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private ClientHelper clientHelper;
|
||||
|
||||
@BeforeEach
|
||||
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.clientHelper = new ClientHelper(this.requestSpec, this.responseSpec);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClientStatus() {
|
||||
|
||||
final Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
Assertions.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() {
|
||||
|
||||
final Integer clientId = ClientHelper.createClientAsPerson(this.requestSpec, this.responseSpec);
|
||||
Assertions.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() {
|
||||
|
||||
final Integer clientId = ClientHelper.createClientAsEntity(this.requestSpec, this.responseSpec);
|
||||
Assertions.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);
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testPendingOnlyClientRequest() {
|
||||
|
||||
Random rand = new Random();
|
||||
// Add a few clients to the server and activate a random amount of them
|
||||
for (int i = 0; i < 15; i++) {
|
||||
final Integer clientId = ClientHelper.createClientAsEntity(this.requestSpec, this.responseSpec);
|
||||
if (rand.nextInt(10) % 2 == 0) {
|
||||
// Takes Client to pending status
|
||||
this.clientHelper.closeClient(clientId);
|
||||
this.clientHelper.reactivateClient(clientId);
|
||||
}
|
||||
// Other clients stay in Active status
|
||||
}
|
||||
List<HashMap<String, Object>> clientsRecieved = (List<HashMap<String, Object>>) clientHelper.getClientWithStatus(50, "pending");
|
||||
assertNotEquals(clientsRecieved.size(), 0);
|
||||
for (int i = 0; i < clientsRecieved.size(); i++) {
|
||||
HashMap<String, Object> clientStatus = ClientHelper.getClientStatus(requestSpec, responseSpec,
|
||||
String.valueOf(clientsRecieved.get(i).get("id")));
|
||||
ClientStatusChecker.verifyClientPending(clientStatus);
|
||||
}
|
||||
|
||||
clientsRecieved = (List<HashMap<String, Object>>) clientHelper.getClientWithStatus(50, "active");
|
||||
assertNotEquals(clientsRecieved.size(), 0);
|
||||
for (int i = 0; i < clientsRecieved.size(); i++) {
|
||||
HashMap<String, Object> clientStatus = ClientHelper.getClientStatus(requestSpec, responseSpec,
|
||||
String.valueOf(clientsRecieved.get(i).get("id")));
|
||||
ClientStatusChecker.verifyClientIsActive(clientStatus);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+329
@@ -0,0 +1,329 @@
|
||||
/**
|
||||
* 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.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.ZoneId;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
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.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@SuppressWarnings({ "unused" })
|
||||
public class ClientUndoRejectAndWithdrawalIntegrationTest {
|
||||
|
||||
private static final String CREATE_CLIENT_URL = "/fineract-provider/api/v1/clients?" + Utils.TENANT_IDENTIFIER;
|
||||
public static final String DATE_FORMAT = "dd MMMM yyyy";
|
||||
private final String submittedOnDate = "submittedOnDate";
|
||||
private final String officeId = "officeId";
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private ClientHelper clientHelper;
|
||||
|
||||
@BeforeEach
|
||||
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.clientHelper = new ClientHelper(this.requestSpec, this.responseSpec);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clientUndoRejectIntegrationTest() {
|
||||
|
||||
// CREATE CLIENT
|
||||
this.clientHelper = new ClientHelper(this.requestSpec, this.responseSpec);
|
||||
final Integer clientId = ClientHelper.createClientPending(this.requestSpec, this.responseSpec);
|
||||
Assertions.assertNotNull(clientId);
|
||||
|
||||
// GET CLIENT STATUS
|
||||
HashMap<String, Object> status = ClientHelper.getClientStatus(requestSpec, responseSpec, String.valueOf(clientId));
|
||||
|
||||
ClientStatusChecker.verifyClientPending(status);
|
||||
|
||||
status = this.clientHelper.rejectClient(clientId);
|
||||
ClientStatusChecker.verifyClientRejected(status);
|
||||
|
||||
status = this.clientHelper.undoReject(clientId);
|
||||
ClientStatusChecker.verifyClientPending(status);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClientUndoRejectWithDateBeforeRejectDate() {
|
||||
final ResponseSpecification errorResponse = new ResponseSpecBuilder().expectStatusCode(403).build();
|
||||
final ClientHelper validationErrorHelper = new ClientHelper(this.requestSpec, errorResponse);
|
||||
|
||||
// CREATE CLIENT
|
||||
this.clientHelper = new ClientHelper(this.requestSpec, this.responseSpec);
|
||||
final Integer clientId = ClientHelper.createClientPending(this.requestSpec, this.responseSpec);
|
||||
Assertions.assertNotNull(clientId);
|
||||
|
||||
// GET CLIENT STATUS
|
||||
HashMap<String, Object> status = ClientHelper.getClientStatus(requestSpec, responseSpec, String.valueOf(clientId));
|
||||
|
||||
ClientStatusChecker.verifyClientPending(status);
|
||||
|
||||
status = this.clientHelper.rejectClient(clientId);
|
||||
ClientStatusChecker.verifyClientRejected(status);
|
||||
|
||||
ArrayList<HashMap<String, Object>> clientErrorData = validationErrorHelper.undoRejectedclient(clientId,
|
||||
CommonConstants.RESPONSE_ERROR, ClientHelper.CREATED_DATE);
|
||||
assertEquals("error.msg.client.reopened.date.cannot.before.client.rejected.date",
|
||||
clientErrorData.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
status = this.clientHelper.undoReject(clientId);
|
||||
ClientStatusChecker.verifyClientPending(status);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@Test
|
||||
public void testClientUndoRejectWithoutReject() {
|
||||
final ResponseSpecification errorResponse = new ResponseSpecBuilder().expectStatusCode(403).build();
|
||||
final ClientHelper validationErrorHelper = new ClientHelper(this.requestSpec, errorResponse);
|
||||
|
||||
// CREATE CLIENT
|
||||
this.clientHelper = new ClientHelper(this.requestSpec, this.responseSpec);
|
||||
final Integer clientId = ClientHelper.createClientPending(this.requestSpec, this.responseSpec);
|
||||
Assertions.assertNotNull(clientId);
|
||||
|
||||
// GET CLIENT STATUS
|
||||
HashMap<String, Object> status = ClientHelper.getClientStatus(requestSpec, responseSpec, String.valueOf(clientId));
|
||||
ClientStatusChecker.verifyClientPending(status);
|
||||
|
||||
DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy", Locale.US);
|
||||
Date todaysDate = Date.from(Utils.getLocalDateOfTenant().atStartOfDay(ZoneId.systemDefault()).toInstant());
|
||||
final String undoRejectDate = dateFormat.format(todaysDate);
|
||||
|
||||
ArrayList<HashMap<String, Object>> clientErrorData = validationErrorHelper.undoRejectedclient(clientId,
|
||||
CommonConstants.RESPONSE_ERROR, undoRejectDate);
|
||||
assertEquals("error.msg.client.undorejection.on.nonrejected.account",
|
||||
clientErrorData.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
status = ClientHelper.getClientStatus(requestSpec, responseSpec, String.valueOf(clientId));
|
||||
ClientStatusChecker.verifyClientPending(status);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClientUndoRejectWithFutureDate() {
|
||||
|
||||
final ResponseSpecification errorResponse = new ResponseSpecBuilder().expectStatusCode(400).build();
|
||||
final ClientHelper validationErrorHelper = new ClientHelper(this.requestSpec, errorResponse);
|
||||
|
||||
// CREATE CLIENT
|
||||
this.clientHelper = new ClientHelper(this.requestSpec, this.responseSpec);
|
||||
final Integer clientId = ClientHelper.createClientPending(this.requestSpec, this.responseSpec);
|
||||
Assertions.assertNotNull(clientId);
|
||||
|
||||
// GET CLIENT STATUS
|
||||
HashMap<String, Object> status = ClientHelper.getClientStatus(requestSpec, responseSpec, String.valueOf(clientId));
|
||||
|
||||
ClientStatusChecker.verifyClientPending(status);
|
||||
|
||||
status = this.clientHelper.rejectClient(clientId);
|
||||
ClientStatusChecker.verifyClientRejected(status);
|
||||
DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy", Locale.US);
|
||||
Date tomorrowsDate = Date.from(Utils.getLocalDateOfTenant().plusDays(1).atStartOfDay(ZoneId.systemDefault()).toInstant());
|
||||
final String undoRejectDate = dateFormat.format(tomorrowsDate);
|
||||
ArrayList<HashMap<String, Object>> clientErrorData = validationErrorHelper.undoWithdrawclient(clientId,
|
||||
CommonConstants.RESPONSE_ERROR, undoRejectDate);
|
||||
assertEquals("validation.msg.client.reopenedDate.is.greater.than.date",
|
||||
clientErrorData.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
status = this.clientHelper.undoReject(clientId);
|
||||
ClientStatusChecker.verifyClientPending(status);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clientUndoWithDrawnIntegrationTest() {
|
||||
|
||||
// CREATE CLIENT
|
||||
this.clientHelper = new ClientHelper(this.requestSpec, this.responseSpec);
|
||||
final Integer clientId = ClientHelper.createClientPending(this.requestSpec, this.responseSpec);
|
||||
Assertions.assertNotNull(clientId);
|
||||
|
||||
// GET CLIENT STATUS
|
||||
HashMap<String, Object> status = ClientHelper.getClientStatus(requestSpec, responseSpec, String.valueOf(clientId));
|
||||
|
||||
ClientStatusChecker.verifyClientPending(status);
|
||||
|
||||
status = this.clientHelper.withdrawClient(clientId);
|
||||
ClientStatusChecker.verifyClientWithdrawn(status);
|
||||
|
||||
status = this.clientHelper.undoWithdrawn(clientId);
|
||||
ClientStatusChecker.verifyClientPending(status);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClientUndoWithDrawnWithDateBeforeWithdrawal() {
|
||||
|
||||
final ResponseSpecification errorResponse = new ResponseSpecBuilder().expectStatusCode(403).build();
|
||||
final ClientHelper validationErrorHelper = new ClientHelper(this.requestSpec, errorResponse);
|
||||
|
||||
// CREATE CLIENT
|
||||
this.clientHelper = new ClientHelper(this.requestSpec, this.responseSpec);
|
||||
final Integer clientId = ClientHelper.createClientPending(this.requestSpec, this.responseSpec);
|
||||
Assertions.assertNotNull(clientId);
|
||||
|
||||
// GET CLIENT STATUS
|
||||
HashMap<String, Object> status = ClientHelper.getClientStatus(requestSpec, responseSpec, String.valueOf(clientId));
|
||||
|
||||
ClientStatusChecker.verifyClientPending(status);
|
||||
|
||||
status = this.clientHelper.withdrawClient(clientId);
|
||||
ClientStatusChecker.verifyClientWithdrawn(status);
|
||||
|
||||
ArrayList<HashMap<String, Object>> clientErrorData = validationErrorHelper.undoWithdrawclient(clientId,
|
||||
CommonConstants.RESPONSE_ERROR, ClientHelper.CREATED_DATE);
|
||||
assertEquals("error.msg.client.reopened.date.cannot.before.client.withdrawal.date",
|
||||
clientErrorData.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
status = this.clientHelper.undoWithdrawn(clientId);
|
||||
ClientStatusChecker.verifyClientPending(status);
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@Test
|
||||
public void testClientUndoWithDrawnWithoutWithdrawal() {
|
||||
final ResponseSpecification errorResponse = new ResponseSpecBuilder().expectStatusCode(403).build();
|
||||
final ClientHelper validationErrorHelper = new ClientHelper(this.requestSpec, errorResponse);
|
||||
// CREATE CLIENT
|
||||
this.clientHelper = new ClientHelper(this.requestSpec, this.responseSpec);
|
||||
final Integer clientId = ClientHelper.createClientPending(this.requestSpec, this.responseSpec);
|
||||
Assertions.assertNotNull(clientId);
|
||||
|
||||
// GET CLIENT STATUS
|
||||
HashMap<String, Object> status = ClientHelper.getClientStatus(requestSpec, responseSpec, String.valueOf(clientId));
|
||||
|
||||
DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy", Locale.US);
|
||||
Date todaysDate = Date.from(Utils.getLocalDateOfTenant().atStartOfDay(ZoneId.systemDefault()).toInstant());
|
||||
final String undoWithdrawDate = dateFormat.format(todaysDate);
|
||||
|
||||
ArrayList<HashMap<String, Object>> clientErrorData = validationErrorHelper.undoWithdrawclient(clientId,
|
||||
CommonConstants.RESPONSE_ERROR, undoWithdrawDate);
|
||||
assertEquals("error.msg.client.undoWithdrawal.on.nonwithdrawal.account",
|
||||
clientErrorData.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
status = ClientHelper.getClientStatus(requestSpec, responseSpec, String.valueOf(clientId));
|
||||
ClientStatusChecker.verifyClientPending(status);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClientUndoWithDrawnWithFutureDate() {
|
||||
|
||||
final ResponseSpecification errorResponse = new ResponseSpecBuilder().expectStatusCode(400).build();
|
||||
final ClientHelper validationErrorHelper = new ClientHelper(this.requestSpec, errorResponse);
|
||||
|
||||
// CREATE CLIENT
|
||||
this.clientHelper = new ClientHelper(this.requestSpec, this.responseSpec);
|
||||
final Integer clientId = ClientHelper.createClientPending(this.requestSpec, this.responseSpec);
|
||||
Assertions.assertNotNull(clientId);
|
||||
|
||||
// GET CLIENT STATUS
|
||||
HashMap<String, Object> status = ClientHelper.getClientStatus(requestSpec, responseSpec, String.valueOf(clientId));
|
||||
|
||||
ClientStatusChecker.verifyClientPending(status);
|
||||
|
||||
status = this.clientHelper.withdrawClient(clientId);
|
||||
ClientStatusChecker.verifyClientWithdrawn(status);
|
||||
DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy", Locale.US);
|
||||
Date tomorrowsDate = Date.from(Utils.getLocalDateOfTenant().plusDays(1).atStartOfDay(ZoneId.systemDefault()).toInstant());
|
||||
final String undoWithdrawDate = dateFormat.format(tomorrowsDate);
|
||||
ArrayList<HashMap<String, Object>> clientErrorData = validationErrorHelper.undoWithdrawclient(clientId,
|
||||
CommonConstants.RESPONSE_ERROR, undoWithdrawDate);
|
||||
assertEquals("validation.msg.client.reopenedDate.is.greater.than.date",
|
||||
clientErrorData.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
status = this.clientHelper.undoWithdrawn(clientId);
|
||||
ClientStatusChecker.verifyClientPending(status);
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@Test
|
||||
public void testValidateReopenedDate() {
|
||||
final ResponseSpecification errorResponse = new ResponseSpecBuilder().expectStatusCode(400).build();
|
||||
final ClientHelper validationErrorHelper = new ClientHelper(this.requestSpec, errorResponse);
|
||||
|
||||
// CREATE CLIENT
|
||||
this.clientHelper = new ClientHelper(this.requestSpec, this.responseSpec);
|
||||
final Integer clientId = ClientHelper.createClientPending(this.requestSpec, this.responseSpec);
|
||||
Assertions.assertNotNull(clientId);
|
||||
// GET CLIENT STATUS
|
||||
HashMap<String, Object> status = ClientHelper.getClientStatus(requestSpec, responseSpec, String.valueOf(clientId));
|
||||
ClientStatusChecker.verifyClientPending(status);
|
||||
|
||||
status = this.clientHelper.withdrawClient(clientId);
|
||||
ClientStatusChecker.verifyClientWithdrawn(status);
|
||||
status = this.clientHelper.undoWithdrawn(clientId);
|
||||
ClientStatusChecker.verifyClientPending(status);
|
||||
ArrayList<HashMap<String, Object>> clientErrorData = validationErrorHelper.activateClient(clientId, CommonConstants.RESPONSE_ERROR);
|
||||
assertEquals("error.msg.clients.submittedOnDate.after.reopened.date",
|
||||
clientErrorData.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReopenedDate() {
|
||||
final ResponseSpecification errorResponse = new ResponseSpecBuilder().expectStatusCode(400).build();
|
||||
// final ClientHelper validationErrorHelper = new
|
||||
// ClientHelper(this.requestSpec, errorResponse);
|
||||
|
||||
// CREATE CLIENT
|
||||
this.clientHelper = new ClientHelper(this.requestSpec, this.responseSpec);
|
||||
final Integer clientId = ClientHelper.createClientPending(this.requestSpec, this.responseSpec);
|
||||
Assertions.assertNotNull(clientId);
|
||||
// GET CLIENT STATUS
|
||||
HashMap<String, Object> status = ClientHelper.getClientStatus(requestSpec, responseSpec, String.valueOf(clientId));
|
||||
ClientStatusChecker.verifyClientPending(status);
|
||||
|
||||
status = this.clientHelper.withdrawClient(clientId);
|
||||
ClientStatusChecker.verifyClientWithdrawn(status);
|
||||
status = this.clientHelper.undoWithdrawn(clientId);
|
||||
ClientStatusChecker.verifyClientPending(status);
|
||||
status = this.clientHelper.activateClientWithDiffDateOption(clientId, ClientHelper.CREATED_DATE_PLUS_TWO);
|
||||
|
||||
}
|
||||
|
||||
private static String randomIDGenerator(final String prefix, final int lenOfRandomSuffix) {
|
||||
return Utils.randomStringGenerator(prefix, lenOfRandomSuffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
}
|
||||
|
||||
}
|
||||
+166
@@ -0,0 +1,166 @@
|
||||
/**
|
||||
* 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 io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
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.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ConcurrencyIntegrationTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ConcurrencyIntegrationTest.class);
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private LoanTransactionHelper loanTransactionHelper;
|
||||
|
||||
private static final String NO_ACCOUNTING = "1";
|
||||
|
||||
static final int MYTHREADS = 30;
|
||||
|
||||
@BeforeEach
|
||||
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++) {
|
||||
LOG.info("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()) {
|
||||
|
||||
}
|
||||
LOG.info("\nFinished all threads");
|
||||
|
||||
}
|
||||
|
||||
private Integer createLoanProduct(final boolean multiDisburseLoan, final String accountingRule, final Account... accounts) {
|
||||
LOG.info("------------------------------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) {
|
||||
LOG.info("--------------------------------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) {
|
||||
LOG.info("Found an exception {}", e.getMessage());
|
||||
LOG.info("Details of failed concurrent transaction (date, amount, loanId) are {},{},{}", repaymentDate, repaymentAmount,
|
||||
loanId);
|
||||
throw (e);
|
||||
}
|
||||
LOG.info("Details of passed concurrent transaction, details (date, amount, loanId) are {},{},{}", repaymentDate,
|
||||
repaymentAmount, loanId);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+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;
|
||||
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
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.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@SuppressWarnings({ "unused", "rawtypes" })
|
||||
public class CurrenciesTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
|
||||
@BeforeEach
|
||||
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();
|
||||
|
||||
Assertions.assertTrue(currency.getDecimalPlaces() >= 0);
|
||||
Assertions.assertNotNull(currency.getName());
|
||||
Assertions.assertNotNull(currency.getDisplaySymbol());
|
||||
Assertions.assertNotNull(currency.getDisplayLabel());
|
||||
Assertions.assertNotNull(currency.getNameCode());
|
||||
|
||||
Assertions.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");
|
||||
currenciestoUpdate.add("INR");
|
||||
|
||||
ArrayList<String> currenciesOutput = CurrenciesHelper.updateSelectedCurrencies(this.requestSpec, this.responseSpec,
|
||||
currenciestoUpdate);
|
||||
Assertions.assertNotNull(currenciesOutput);
|
||||
|
||||
Assertions.assertEquals(currenciestoUpdate, currenciesOutput, "Verifying Do Outputed Currencies Match after Updation");
|
||||
|
||||
// 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);
|
||||
Assertions.assertNotNull(currenciesAfterUpdate);
|
||||
|
||||
Assertions.assertEquals(currenciesBeforeUpdate, currenciesAfterUpdate, "Verifying Do Selected Currencies Match after Updation");
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* 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 io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.savings.SavingsAccountHelper;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
||||
public class CurrencyIntegrationTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private SavingsAccountHelper savingsAccountHelper;
|
||||
|
||||
@BeforeEach
|
||||
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();
|
||||
}
|
||||
}
|
||||
+403
@@ -0,0 +1,403 @@
|
||||
/**
|
||||
* 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.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import org.apache.fineract.integrationtests.common.CalendarHelper;
|
||||
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||
import org.apache.fineract.integrationtests.common.GroupHelper;
|
||||
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.LoanStatusChecker;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Tests loan schedule change based on group meeting changes and loan rescheduling
|
||||
**/
|
||||
@SuppressWarnings({ "rawtypes" })
|
||||
@Disabled
|
||||
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");
|
||||
|
||||
@BeforeEach
|
||||
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
|
||||
Assertions.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(3, dueDateCalendar.get(Calendar.DAY_OF_WEEK), "AFTER MEETING CHANGE DATE THE NEXT REPAYMENT SHOULD BE ON TUESDAY");
|
||||
|
||||
// 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(3, dueDateCalendar.get(Calendar.DAY_OF_WEEK),
|
||||
"AFTER MEETING CHANGE DATE THE NEXT REPAYMENT SHOULD BE ON TUESDAY, EVEN AFTER LOAN RESCHEDULE REQUEST WAS SENT");
|
||||
|
||||
// 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(3, dueDateCalendar.get(Calendar.DAY_OF_WEEK),
|
||||
"AFTER MEETING CHANGE DATE THE NEXT REPAYMENT SHOULD BE ON TUESDAY, EVEN AFTER RESCHEDULE");
|
||||
// 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
|
||||
Assertions.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(3, expectedMaturityCalendar.get(Calendar.DAY_OF_WEEK),
|
||||
"AFTER MEETING CHANGE DATE THE EXPECTED MATURITY SHOULD BE ON TUESDAY");
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
/**
|
||||
* 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 io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
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.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ExternalServicesConfigurationTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ExternalServicesConfigurationTest.class);
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private ExternalServicesConfigurationHelper externalServicesConfigurationHelper;
|
||||
private ResponseSpecification httpStatusForidden;
|
||||
|
||||
@BeforeEach
|
||||
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 = ExternalServicesConfigurationHelper
|
||||
.getExternalServicesConfigurationByServiceName(requestSpec, responseSpec, "S3");
|
||||
Assertions.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";
|
||||
LOG.info("{} : {}", name, value);
|
||||
HashMap arrayListValue = ExternalServicesConfigurationHelper.updateValueForExternaServicesConfiguration(requestSpec,
|
||||
responseSpec, "S3", name, newValue);
|
||||
Assertions.assertNotNull(arrayListValue.get("value"));
|
||||
Assertions.assertEquals(arrayListValue.get("value"), newValue);
|
||||
HashMap arrayListValue1 = ExternalServicesConfigurationHelper.updateValueForExternaServicesConfiguration(requestSpec,
|
||||
responseSpec, "S3", name, value);
|
||||
Assertions.assertNotNull(arrayListValue1.get("value"));
|
||||
Assertions.assertEquals(arrayListValue1.get("value"), value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Checking for SMTP:
|
||||
|
||||
configName = "username";
|
||||
externalServicesConfig = ExternalServicesConfigurationHelper.getExternalServicesConfigurationByServiceName(requestSpec,
|
||||
responseSpec, "SMTP");
|
||||
Assertions.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";
|
||||
LOG.info("{} : {}", name, value);
|
||||
HashMap arrayListValue = ExternalServicesConfigurationHelper.updateValueForExternaServicesConfiguration(requestSpec,
|
||||
responseSpec, "SMTP", name, newValue);
|
||||
Assertions.assertNotNull(arrayListValue.get("value"));
|
||||
Assertions.assertEquals(arrayListValue.get("value"), newValue);
|
||||
HashMap arrayListValue1 = ExternalServicesConfigurationHelper.updateValueForExternaServicesConfiguration(requestSpec,
|
||||
responseSpec, "SMTP", name, value);
|
||||
Assertions.assertNotNull(arrayListValue1.get("value"));
|
||||
Assertions.assertEquals(arrayListValue1.get("value"), value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+160
@@ -0,0 +1,160 @@
|
||||
/**
|
||||
* 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.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import org.apache.fineract.accounting.common.AccountingConstants.FinancialActivity;
|
||||
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.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@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 = FinancialActivity.ASSET_TRANSFER.getValue();
|
||||
public static final Integer LIABILITY_TRANSFER_FINANCIAL_ACTIVITY_ID = FinancialActivity.LIABILITY_TRANSFER.getValue();
|
||||
|
||||
@BeforeEach
|
||||
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();
|
||||
Assertions.assertNotNull(assetTransferAccount);
|
||||
Assertions.assertNotNull(liabilityTransferAccount);
|
||||
|
||||
/*** Create A Financial Activity to Account Mapping **/
|
||||
Integer financialActivityAccountId = (Integer) financialActivityAccountHelper.createFinancialActivityAccount(
|
||||
LIABILITY_TRANSFER_FINANCIAL_ACTIVITY_ID, liabilityTransferAccount.getAccountID(), responseSpec,
|
||||
CommonConstants.RESPONSE_RESOURCE_ID);
|
||||
Assertions.assertNotNull(financialActivityAccountId);
|
||||
|
||||
/***
|
||||
* Fetch Created Financial Activity to Account Mapping and validate created values
|
||||
**/
|
||||
assertFinancialActivityAccountCreation(financialActivityAccountId, LIABILITY_TRANSFER_FINANCIAL_ACTIVITY_ID,
|
||||
liabilityTransferAccount);
|
||||
|
||||
/**
|
||||
* Update Existing Financial Activity to Account Mapping and assert changes
|
||||
**/
|
||||
Account newLiabilityTransferAccount = accountHelper.createLiabilityAccount();
|
||||
Assertions.assertNotNull(newLiabilityTransferAccount);
|
||||
|
||||
HashMap changes = (HashMap) financialActivityAccountHelper.updateFinancialActivityAccount(financialActivityAccountId,
|
||||
LIABILITY_TRANSFER_FINANCIAL_ACTIVITY_ID, newLiabilityTransferAccount.getAccountID(), responseSpec,
|
||||
CommonConstants.RESPONSE_CHANGES);
|
||||
Assertions.assertEquals(newLiabilityTransferAccount.getAccountID(), changes.get("glAccountId"));
|
||||
|
||||
/** Validate update works correctly **/
|
||||
assertFinancialActivityAccountCreation(financialActivityAccountId, LIABILITY_TRANSFER_FINANCIAL_ACTIVITY_ID,
|
||||
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(LIABILITY_TRANSFER_FINANCIAL_ACTIVITY_ID, 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);
|
||||
Assertions.assertNotNull(deletedFinancialActivityAccountId);
|
||||
Assertions.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);
|
||||
Assertions.assertEquals(financialActivityId, ((HashMap) mappingDetails.get("financialActivityData")).get("id"));
|
||||
Assertions.assertEquals(glAccount.getAccountID(), ((HashMap) mappingDetails.get("glAccountData")).get("id"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the Financial activities
|
||||
*/
|
||||
@AfterEach
|
||||
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);
|
||||
Assertions.assertNotNull(deletedFinancialActivityAccountId);
|
||||
Assertions.assertEquals(financialActivityAccountId, deletedFinancialActivityAccountId);
|
||||
}
|
||||
}
|
||||
}
|
||||
+2710
File diff suppressed because it is too large
Load Diff
+156
@@ -0,0 +1,156 @@
|
||||
/**
|
||||
* 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.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
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.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unused", "unchecked" })
|
||||
public class FlexibleSavingsInterestPostingIntegrationTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(FlexibleSavingsInterestPostingIntegrationTest.class);
|
||||
public static final String ACCOUNT_TYPE_INDIVIDUAL = "INDIVIDUAL";
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private SavingsProductHelper savingsProductHelper;
|
||||
private SavingsAccountHelper savingsAccountHelper;
|
||||
|
||||
@BeforeEach
|
||||
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);
|
||||
Assertions.assertNotNull(clientID);
|
||||
|
||||
// Configuring global config flags
|
||||
configureInterestPosting(true, 4);
|
||||
|
||||
final Integer savingsId = createSavingsAccount(clientID, startDate);
|
||||
|
||||
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 (Map.Entry<String, Object> entry : interestPostingTransaction.entrySet()) {
|
||||
LOG.info("{} - {}", 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("33.7016", interestPostingTransaction.get("amount").toString(), "Equality check for interest posted amount");
|
||||
assertEquals("[2014, 3, 31]", interestPostingTransaction.get("date").toString(), "Date check for Interest Posting transaction");
|
||||
|
||||
}
|
||||
|
||||
private Integer createSavingsAccount(final Integer clientID, final String startDate) {
|
||||
final Integer savingsProductID = createSavingsProduct();
|
||||
Assertions.assertNotNull(savingsProductID);
|
||||
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplicationOnDate(clientID, savingsProductID,
|
||||
ACCOUNT_TYPE_INDIVIDUAL, startDate);
|
||||
Assertions.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);
|
||||
Assertions.assertNotNull(globalConfig);
|
||||
|
||||
// Updating flag for interest posting at period end
|
||||
Integer periodEndConfigId = (Integer) globalConfig.get(10).get("id");
|
||||
Assertions.assertNotNull(periodEndConfigId);
|
||||
|
||||
HashMap periodEndConfigData = GlobalConfigurationHelper.getGlobalConfigurationById(this.requestSpec, this.responseSpec,
|
||||
periodEndConfigId.toString());
|
||||
Assertions.assertNotNull(periodEndConfigData);
|
||||
|
||||
Boolean enabled = (Boolean) globalConfig.get(10).get("enabled");
|
||||
|
||||
if (!enabled.equals(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");
|
||||
Assertions.assertNotNull(financialYearBeginningConfigId);
|
||||
|
||||
HashMap financialYearBeginningConfigData = GlobalConfigurationHelper.getGlobalConfigurationById(this.requestSpec, this.responseSpec,
|
||||
financialYearBeginningConfigId.toString());
|
||||
Assertions.assertNotNull(financialYearBeginningConfigData);
|
||||
|
||||
financialYearBeginningConfigId = GlobalConfigurationHelper.updateValueForGlobalConfiguration(this.requestSpec, this.responseSpec,
|
||||
financialYearBeginningConfigId.toString(), financialYearBeginningMonth.toString());
|
||||
Assertions.assertNotNull(financialYearBeginningConfigId);
|
||||
}
|
||||
|
||||
private Integer createSavingsProduct() {
|
||||
final String savingsProductJSON = this.savingsProductHelper.withInterestCompoundingPeriodTypeAsDaily()
|
||||
.withInterestPostingPeriodTypeAsAnnual().withInterestCalculationPeriodTypeAsDailyBalance().build();
|
||||
return SavingsProductHelper.createSavingsProduct(savingsProductJSON, requestSpec, responseSpec);
|
||||
}
|
||||
|
||||
// Reset configuration fields
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
GlobalConfigurationHelper.resetAllDefaultGlobalConfigurations(this.requestSpec, this.responseSpec);
|
||||
GlobalConfigurationHelper.verifyAllDefaultGlobalConfigurations(this.requestSpec, this.responseSpec);
|
||||
}
|
||||
|
||||
}
|
||||
+292
@@ -0,0 +1,292 @@
|
||||
/**
|
||||
* 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.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
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.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Funds Integration Test for checking Funds Application.
|
||||
*/
|
||||
public class FundsIntegrationTest {
|
||||
|
||||
private ResponseSpecification statusOkResponseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
|
||||
@BeforeEach
|
||||
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);
|
||||
Assertions.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);
|
||||
Assertions.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);
|
||||
Assertions.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);
|
||||
Assertions.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);
|
||||
Assertions.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);
|
||||
Assertions.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);
|
||||
Assertions.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);
|
||||
Assertions.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);
|
||||
Assertions.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);
|
||||
Assertions.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);
|
||||
Assertions.assertNotNull(fundID);
|
||||
|
||||
List<FundsHelper> fhList = FundsResourceHandler.retrieveAllFunds(this.requestSpec, this.statusOkResponseSpec);
|
||||
|
||||
Assertions.assertNotNull(fhList);
|
||||
assertThat(fhList.size(), greaterThanOrEqualTo(1));
|
||||
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, Object> map = new Gson().fromJson(jsonData, new TypeToken<HashMap<String, Object>>() {}.getType());
|
||||
assertEquals("error.msg.resource.not.found", map.get("userMessageGlobalisationCode"));
|
||||
}
|
||||
|
||||
@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);
|
||||
Assertions.assertNotNull(fundID);
|
||||
|
||||
String newName = Utils.randomNameGenerator("", 10);
|
||||
String newExternalId = Utils.randomNameGenerator("fund-", 5);
|
||||
FundsHelper fh2 = FundsResourceHandler.updateFund(fundID, newName, newExternalId, this.requestSpec, this.statusOkResponseSpec);
|
||||
|
||||
Assertions.assertEquals(newName, fh2.getName());
|
||||
Assertions.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);
|
||||
Assertions.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);
|
||||
Assertions.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);
|
||||
|
||||
Assertions.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);
|
||||
Assertions.assertNotNull(fundID);
|
||||
|
||||
String newExternalId = Utils.randomNameGenerator("fund-", 5);
|
||||
FundsHelper fh2 = FundsResourceHandler.updateFund(fundID, null, newExternalId, this.requestSpec, this.statusOkResponseSpec);
|
||||
|
||||
Assertions.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);
|
||||
Assertions.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);
|
||||
|
||||
Assertions.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);
|
||||
Assertions.assertNotNull(fundID);
|
||||
|
||||
String newName = Utils.randomNameGenerator("", 10);
|
||||
FundsHelper fh2 = FundsResourceHandler.updateFund(fundID, newName, null, this.requestSpec, this.statusOkResponseSpec);
|
||||
|
||||
Assertions.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);
|
||||
Assertions.assertNotNull(fundID);
|
||||
|
||||
FundsHelper fh2 = FundsResourceHandler.updateFund(fundID, null, null, this.requestSpec, this.statusOkResponseSpec);
|
||||
|
||||
Assertions.assertNull(fh2.getName());
|
||||
Assertions.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);
|
||||
|
||||
Assertions.assertEquals(fh.getName(), fh3.getName());
|
||||
Assertions.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 Long.valueOf(fundId);
|
||||
}
|
||||
|
||||
}
|
||||
+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;
|
||||
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import org.apache.fineract.integrationtests.common.GlobalConfigurationHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class GlobalConfigInterestChargedFromDateSameAsDisbursalDateTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private GlobalConfigurationHelper globalConfigurationHelper;
|
||||
|
||||
@BeforeEach
|
||||
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();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
GlobalConfigurationHelper.resetAllDefaultGlobalConfigurations(this.requestSpec, this.responseSpec);
|
||||
GlobalConfigurationHelper.verifyAllDefaultGlobalConfigurations(this.requestSpec, this.responseSpec);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "static-access", "rawtypes", "unchecked" })
|
||||
@Test
|
||||
public void testInterestChargedFromDateSameAsDisbursalDate() {
|
||||
this.globalConfigurationHelper = new GlobalConfigurationHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
// Retrieving All Global Configuration details
|
||||
final ArrayList<HashMap> globalConfig = GlobalConfigurationHelper.getAllGlobalConfigurations(this.requestSpec, this.responseSpec);
|
||||
Assertions.assertNotNull(globalConfig);
|
||||
|
||||
String configName = "interest-charged-from-date-same-as-disbursal-date";
|
||||
boolean newBooleanValue = true;
|
||||
|
||||
for (Integer configIndex = 0; configIndex < globalConfig.size(); configIndex++) {
|
||||
if (globalConfig.get(configIndex).get("name").equals(configName)) {
|
||||
String configId = globalConfig.get(configIndex).get("id").toString();
|
||||
Integer updateConfigId = GlobalConfigurationHelper.updateEnabledFlagForGlobalConfiguration(this.requestSpec,
|
||||
this.responseSpec, configId.toString(), newBooleanValue);
|
||||
Assertions.assertNotNull(updateConfigId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+210
@@ -0,0 +1,210 @@
|
||||
/**
|
||||
* 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 io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
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.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
|
||||
public class GlobalConfigurationTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private GlobalConfigurationHelper globalConfigurationHelper;
|
||||
private ResponseSpecification httpStatusForidden;
|
||||
|
||||
@BeforeEach
|
||||
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();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
GlobalConfigurationHelper.resetAllDefaultGlobalConfigurations(this.requestSpec, this.responseSpec);
|
||||
GlobalConfigurationHelper.verifyAllDefaultGlobalConfigurations(this.requestSpec, this.responseSpec);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGlobalConfigurations() {
|
||||
this.globalConfigurationHelper = new GlobalConfigurationHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
// Retrieving All Global Configuration details
|
||||
final ArrayList<HashMap> globalConfig = GlobalConfigurationHelper.getAllGlobalConfigurations(this.requestSpec, this.responseSpec);
|
||||
Assertions.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");
|
||||
Assertions.assertNotNull(configId);
|
||||
|
||||
HashMap configDataBefore = GlobalConfigurationHelper.getGlobalConfigurationById(this.requestSpec, this.responseSpec,
|
||||
configId.toString());
|
||||
Assertions.assertNotNull(configDataBefore);
|
||||
|
||||
Integer value = (Integer) configDataBefore.get("value") + 1;
|
||||
|
||||
// Updating Value for penalty-wait-period Global Configuration
|
||||
configId = GlobalConfigurationHelper.updateValueForGlobalConfiguration(this.requestSpec, this.responseSpec,
|
||||
configId.toString(), value.toString());
|
||||
Assertions.assertNotNull(configId);
|
||||
|
||||
HashMap configDataAfter = GlobalConfigurationHelper.getGlobalConfigurationById(this.requestSpec, this.responseSpec,
|
||||
configId.toString());
|
||||
|
||||
// Verifying Value for penalty-wait-period after Updation
|
||||
Assertions.assertEquals(value, configDataAfter.get("value"), "Verifying Global Config Value after Updation");
|
||||
|
||||
// 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 = GlobalConfigurationHelper.updateEnabledFlagForGlobalConfiguration(this.requestSpec, this.responseSpec,
|
||||
configId.toString(), enabled);
|
||||
|
||||
configDataAfter = GlobalConfigurationHelper.getGlobalConfigurationById(this.requestSpec, this.responseSpec,
|
||||
configId.toString());
|
||||
|
||||
// Verifying Enabled Flag for penalty-wait-period after Updation
|
||||
Assertions.assertEquals(enabled, configDataAfter.get("enabled"), "Verifying Enabled Flag Global Config after Updation");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGlobalConfigurationIsCacheEnabled() {
|
||||
this.globalConfigurationHelper = new GlobalConfigurationHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
// Retrieving Is Cache Enabled Global Configuration details
|
||||
ArrayList<HashMap> isCacheGlobalConfig = GlobalConfigurationHelper.getGlobalConfigurationIsCacheEnabled(this.requestSpec,
|
||||
this.responseSpec);
|
||||
Assertions.assertNotNull(isCacheGlobalConfig);
|
||||
|
||||
for (Integer cacheType = 0; cacheType <= isCacheGlobalConfig.size() - 1; cacheType++) {
|
||||
|
||||
// Retrieving Is Cache Enabled Global Configuration details
|
||||
isCacheGlobalConfig = GlobalConfigurationHelper.getGlobalConfigurationIsCacheEnabled(this.requestSpec, this.responseSpec);
|
||||
Assertions.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 = GlobalConfigurationHelper.updateIsCacheEnabledForGlobalConfiguration(this.requestSpec, this.responseSpec,
|
||||
cacheTypeId.toString());
|
||||
Assertions.assertEquals(cacheTypeId, changes.get("cacheType"), "Verifying Is Cache Enabled Global Config after Updation");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGlobalConfigForcePasswordResetDays() {
|
||||
|
||||
// Retrieving All Global Configuration details
|
||||
final ArrayList<HashMap> globalConfig = GlobalConfigurationHelper.getAllGlobalConfigurations(this.requestSpec, this.responseSpec);
|
||||
Assertions.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");
|
||||
Assertions.assertNotNull(configId);
|
||||
|
||||
/*
|
||||
* Update force-password-reset-days with value as 0 and Enable as true - failure case
|
||||
*/
|
||||
ArrayList error = (ArrayList) GlobalConfigurationHelper.updatePasswordResetDaysForGlobalConfiguration(this.requestSpec,
|
||||
this.httpStatusForidden, configId, newValue, newBooleanValue, CommonConstants.RESPONSE_ERROR);
|
||||
HashMap hash = (HashMap) error.get(0);
|
||||
|
||||
Assertions.assertEquals("error.msg.password.reset.days.value.must.be.greater.than.zero",
|
||||
hash.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE),
|
||||
"Force Password Reset days value must be greater than zero.");
|
||||
|
||||
/*
|
||||
* Update force-password-reset-days with value as 50 and Enable as true - success case
|
||||
*/
|
||||
final HashMap updateSuccess = (HashMap) GlobalConfigurationHelper.updatePasswordResetDaysForGlobalConfiguration(
|
||||
this.requestSpec, this.responseSpec, configId, "50", newBooleanValue, "changes");
|
||||
Assertions.assertNotNull(updateSuccess);
|
||||
|
||||
/* Update with value as 0 and Enable as false - success case */
|
||||
final HashMap updateSuccess1 = (HashMap) GlobalConfigurationHelper.updatePasswordResetDaysForGlobalConfiguration(
|
||||
this.requestSpec, this.responseSpec, configId, newValue, "false", "changes");
|
||||
Assertions.assertNotNull(updateSuccess1);
|
||||
|
||||
/*
|
||||
* Update without sending value and Enable as true - failure case
|
||||
*/
|
||||
ArrayList failure = (ArrayList) GlobalConfigurationHelper.updatePasswordResetDaysForGlobalConfiguration(this.requestSpec,
|
||||
this.httpStatusForidden, configId, null, newBooleanValue, CommonConstants.RESPONSE_ERROR);
|
||||
HashMap failureHash = (HashMap) failure.get(0);
|
||||
Assertions.assertEquals("error.msg.password.reset.days.value.must.be.greater.than.zero",
|
||||
failureHash.get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE),
|
||||
"Force Password Reset days value must be greater than zero.");
|
||||
|
||||
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 = GlobalConfigurationHelper.updateValueForGlobalConfiguration(this.requestSpec, this.responseSpec,
|
||||
configId, newValue);
|
||||
Assertions.assertNotNull(updateConfigId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+269
@@ -0,0 +1,269 @@
|
||||
/**
|
||||
* 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.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
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.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.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
private static final Logger LOG = LoggerFactory.getLogger(GroupLoanIntegrationTest.class);
|
||||
|
||||
@BeforeEach
|
||||
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);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkGlimAccountCommands() {
|
||||
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();
|
||||
|
||||
HashMap<String, Integer> glim = applyForGlimApplication(clientID, groupID, loanProductID);
|
||||
LOG.info("Glim Loan Application: {} ", glim);
|
||||
|
||||
final Integer glimId = glim.get("glimId");
|
||||
LOG.info("GlimId : {} ", glimId);
|
||||
|
||||
final Integer loanId = glim.get("loanId");
|
||||
LOG.info("LoanId : {} ", loanId);
|
||||
|
||||
List<Map<String, Object>> approvalFormData = new ArrayList<>();
|
||||
approvalFormData.add(approvalFormData(loanId, "22 September 2011"));
|
||||
|
||||
HashMap loanStatusHashMap = this.loanTransactionHelper.approveGlimAccount(this.requestSpec, this.responseSpec, approvalFormData,
|
||||
glimId);
|
||||
LOG.info("glim approval loanSchedule: {} ", loanStatusHashMap);
|
||||
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
|
||||
|
||||
loanStatusHashMap = this.loanTransactionHelper.disburseGlimAccount("25 September 2011", glimId);
|
||||
LOG.info("glim disbursement loanSchedule: {} ", loanStatusHashMap);
|
||||
LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
|
||||
|
||||
loanStatusHashMap = this.loanTransactionHelper.undoDisburseGlimAccount(glimId);
|
||||
LOG.info("glim undodisbursement loanSchedule: {} ", loanStatusHashMap);
|
||||
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
|
||||
|
||||
loanStatusHashMap = this.loanTransactionHelper.undoApprovalGlimAccount(glimId);
|
||||
LOG.info("glim undoApproval loanSchedule: {} ", loanStatusHashMap);
|
||||
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
|
||||
|
||||
loanStatusHashMap = this.loanTransactionHelper.rejectGlimAccount("22 September 2011", glimId);
|
||||
LOG.info("glim reject loanSchedule: {} ", loanStatusHashMap);
|
||||
LoanStatusChecker.verifyLoanAccountRejected(loanStatusHashMap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getGlimAccountByGroupId() {
|
||||
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
Assertions.assertNotNull(clientID);
|
||||
|
||||
Integer groupID = GroupHelper.createGroup(this.requestSpec, this.responseSpec, true);
|
||||
Assertions.assertNotNull(groupID);
|
||||
|
||||
groupID = GroupHelper.associateClient(this.requestSpec, this.responseSpec, groupID.toString(), clientID.toString());
|
||||
Assertions.assertNotNull(groupID);
|
||||
|
||||
final Integer loanProductID = createLoanProduct();
|
||||
Assertions.assertNotNull(loanProductID);
|
||||
|
||||
HashMap<String, Integer> glim = applyForGlimApplication(clientID, groupID, loanProductID);
|
||||
LOG.info("Glim Loan Application: {} ", glim);
|
||||
|
||||
final Integer glimId = glim.get("glimId");
|
||||
LOG.info("GlimId: {} ", glimId);
|
||||
|
||||
final Integer loanId = glim.get("loanId");
|
||||
LOG.info("LoanId: {} ", loanId);
|
||||
|
||||
final List<String> retrievedGlimId = GroupHelper.verifyRetrieveGlimAccountsByGroupId(this.requestSpec, this.responseSpec, groupID);
|
||||
Assertions.assertNotNull(retrievedGlimId.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getGlimAccountByGlimId() {
|
||||
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
Assertions.assertNotNull(clientID);
|
||||
|
||||
Integer groupID = GroupHelper.createGroup(this.requestSpec, this.responseSpec, true);
|
||||
Assertions.assertNotNull(groupID);
|
||||
|
||||
groupID = GroupHelper.associateClient(this.requestSpec, this.responseSpec, groupID.toString(), clientID.toString());
|
||||
Assertions.assertNotNull(groupID);
|
||||
|
||||
final Integer loanProductID = createLoanProduct();
|
||||
Assertions.assertNotNull(loanProductID);
|
||||
|
||||
HashMap<String, Integer> glim = applyForGlimApplication(clientID, groupID, loanProductID);
|
||||
LOG.info("Glim Loan Application: {} ", glim);
|
||||
|
||||
final Integer glimId = glim.get("glimId");
|
||||
LOG.info("GlimId: {} ", glimId);
|
||||
|
||||
final Integer loanId = glim.get("loanId");
|
||||
LOG.info("LoanId: {} ", loanId);
|
||||
|
||||
final List<String> retrievedGlimAccountId = GroupHelper.verifyRetrieveGlimAccountsByGlimId(this.requestSpec, this.responseSpec,
|
||||
glimId);
|
||||
Assertions.assertNotNull(retrievedGlimAccountId);
|
||||
}
|
||||
|
||||
private Map<String, Object> approvalFormData(final Integer loanId, final String approvedOnDate) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("loanId", loanId);
|
||||
map.put("approvedOnDate", approvedOnDate);
|
||||
map.put("dateFormat", CommonConstants.DATE_FORMAT);
|
||||
map.put("locale", "en");
|
||||
return map;
|
||||
}
|
||||
|
||||
private Integer createLoanProduct() {
|
||||
LOG.info("------------------------------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) {
|
||||
LOG.info("--------------------------------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);
|
||||
LOG.info(loanApplicationJSON);
|
||||
return this.loanTransactionHelper.getLoanId(loanApplicationJSON);
|
||||
}
|
||||
|
||||
private HashMap<String, Integer> applyForGlimApplication(final Integer clientID, final Integer groupID, final Integer loanProductID) {
|
||||
LOG.info("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------");
|
||||
final String GlimApplicationJSON = 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("glim").withtotalLoan("10000").withParentAccount("1")
|
||||
.build(clientID.toString(), groupID.toString(), loanProductID.toString(), null);
|
||||
LOG.info(GlimApplicationJSON);
|
||||
return this.loanTransactionHelper.getGlimId(GlimApplicationJSON);
|
||||
}
|
||||
|
||||
private void verifyLoanRepaymentSchedule(final ArrayList<HashMap> loanSchedule) {
|
||||
LOG.info("--------------------VERIFYING THE PRINCIPAL DUES,INTEREST DUE AND DUE DATE--------------------------");
|
||||
|
||||
assertEquals(new ArrayList<>(Arrays.asList(2011, 10, 20)), loanSchedule.get(1).get("dueDate"),
|
||||
"Checking for Due Date for 1st Month");
|
||||
assertEquals(Float.valueOf("2911.49"), loanSchedule.get(1).get("principalOriginalDue"), "Checking for Principal Due for 1st Month");
|
||||
assertEquals(Float.valueOf("240.00"), loanSchedule.get(1).get("interestOriginalDue"), "Checking for Interest Due for 1st Month");
|
||||
|
||||
assertEquals(new ArrayList<>(Arrays.asList(2011, 11, 20)), loanSchedule.get(2).get("dueDate"),
|
||||
"Checking for Due Date for 2nd Month");
|
||||
assertEquals(Float.valueOf("2969.72"), loanSchedule.get(2).get("principalDue"), "Checking for Principal Due for 2nd Month");
|
||||
assertEquals(Float.valueOf("181.77"), loanSchedule.get(2).get("interestOriginalDue"), "Checking for Interest Due for 2nd Month");
|
||||
|
||||
assertEquals(new ArrayList<>(Arrays.asList(2011, 12, 20)), loanSchedule.get(3).get("dueDate"),
|
||||
"Checking for Due Date for 3rd Month");
|
||||
assertEquals(Float.valueOf("3029.11"), loanSchedule.get(3).get("principalDue"), "Checking for Principal Due for 3rd Month");
|
||||
assertEquals(Float.valueOf("122.38"), loanSchedule.get(3).get("interestOriginalDue"), "Checking for Interest Due for 3rd Month");
|
||||
|
||||
assertEquals(new ArrayList<>(Arrays.asList(2012, 1, 20)), loanSchedule.get(4).get("dueDate"),
|
||||
"Checking for Due Date for 4th Month");
|
||||
assertEquals(Float.valueOf("3089.68"), loanSchedule.get(4).get("principalDue"), "Checking for Principal Due for 4th Month");
|
||||
assertEquals(Float.valueOf("61.79"), loanSchedule.get(4).get("interestOriginalDue"), "Checking for Interest Due for 4th Month");
|
||||
}
|
||||
}
|
||||
+811
@@ -0,0 +1,811 @@
|
||||
/**
|
||||
* 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.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
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.PaymentTypeHelper;
|
||||
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.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
private static final Logger LOG = LoggerFactory.getLogger(GroupSavingsIntegrationTest.class);
|
||||
|
||||
@BeforeEach
|
||||
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);
|
||||
Assertions.assertNotNull(clientID);
|
||||
|
||||
Integer groupID = GroupHelper.createGroup(this.requestSpec, this.responseSpec, true);
|
||||
Assertions.assertNotNull(groupID);
|
||||
|
||||
groupID = GroupHelper.associateClient(this.requestSpec, this.responseSpec, groupID.toString(), clientID.toString());
|
||||
Assertions.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);
|
||||
Assertions.assertNotNull(savingsProductID);
|
||||
|
||||
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(groupID, savingsProductID, ACCOUNT_TYPE_GROUP);
|
||||
Assertions.assertNotNull(savingsId);
|
||||
|
||||
HashMap modifications = this.savingsAccountHelper.updateSavingsAccount(groupID, savingsProductID, savingsId, ACCOUNT_TYPE_GROUP);
|
||||
Assertions.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);
|
||||
Assertions.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);
|
||||
Assertions.assertNotNull(clientID);
|
||||
|
||||
Integer groupID = GroupHelper.createGroup(this.requestSpec, this.responseSpec, true);
|
||||
Assertions.assertNotNull(groupID);
|
||||
|
||||
groupID = GroupHelper.associateClient(this.requestSpec, this.responseSpec, groupID.toString(), clientID.toString());
|
||||
Assertions.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);
|
||||
Assertions.assertNotNull(savingsProductID);
|
||||
|
||||
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(groupID, savingsProductID, ACCOUNT_TYPE_GROUP);
|
||||
Assertions.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);
|
||||
Assertions.assertNotNull(clientID);
|
||||
|
||||
Integer groupID = GroupHelper.createGroup(this.requestSpec, this.responseSpec, true);
|
||||
Assertions.assertNotNull(groupID);
|
||||
|
||||
groupID = GroupHelper.associateClient(this.requestSpec, this.responseSpec, groupID.toString(), clientID.toString());
|
||||
Assertions.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);
|
||||
Assertions.assertNotNull(savingsProductID);
|
||||
|
||||
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(groupID, savingsProductID, ACCOUNT_TYPE_GROUP);
|
||||
Assertions.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));
|
||||
|
||||
}
|
||||
|
||||
// gsimcommands testing
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testGsimSavingsAccount_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);
|
||||
Assertions.assertNotNull(clientID);
|
||||
|
||||
Integer groupID = GroupHelper.createGroup(this.requestSpec, this.responseSpec, true);
|
||||
Assertions.assertNotNull(groupID);
|
||||
|
||||
groupID = GroupHelper.associateClient(this.requestSpec, this.responseSpec, groupID.toString(), clientID.toString());
|
||||
Assertions.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);
|
||||
Assertions.assertNotNull(savingsProductID);
|
||||
|
||||
List<Map<String, Object>> clientArray = new ArrayList<>();
|
||||
clientArray.add(clientArray(clientID, groupID, savingsProductID, "08 January 2013"));
|
||||
|
||||
final Integer gsimID = this.savingsAccountHelper.applyForGsimApplication(clientArray);
|
||||
|
||||
HashMap savingsStatusHashMap = this.savingsAccountHelper.approveGsimSavings(gsimID);
|
||||
SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap);
|
||||
|
||||
List<HashMap> error1 = savingsAccountHelperValidationError.rejectGsimApplicationWithErrorCode(gsimID,
|
||||
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.undoApprovalGsimSavings(gsimID);
|
||||
SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap);
|
||||
|
||||
error1 = savingsAccountHelperValidationError.rejectGsimApplicationWithErrorCode(gsimID, SavingsAccountHelper.getFutureDate());
|
||||
assertEquals("validation.msg.savingsaccount.reject.cannot.be.a.future.date",
|
||||
error1.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE));
|
||||
|
||||
error1 = savingsAccountHelperValidationError.rejectGsimApplicationWithErrorCode(gsimID,
|
||||
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.rejectGsimApplication(gsimID);
|
||||
SavingsStatusChecker.verifySavingsIsRejected(savingsStatusHashMap);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGsimSavingsAccount_DEPOSIT_APPLICATION() {
|
||||
|
||||
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
Assertions.assertNotNull(clientID);
|
||||
|
||||
Integer groupID = GroupHelper.createGroup(this.requestSpec, this.responseSpec, true);
|
||||
Assertions.assertNotNull(groupID);
|
||||
|
||||
groupID = GroupHelper.associateClient(this.requestSpec, this.responseSpec, groupID.toString(), clientID.toString());
|
||||
Assertions.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);
|
||||
Assertions.assertNotNull(savingsProductID);
|
||||
|
||||
List<Map<String, Object>> clientArray = new ArrayList<>();
|
||||
clientArray.add(clientArray(clientID, groupID, savingsProductID, "08 January 2013"));
|
||||
LOG.info("client Array : {} ", clientArray);
|
||||
|
||||
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(groupID, savingsProductID, ACCOUNT_TYPE_GROUP);
|
||||
Assertions.assertNotNull(savingsId);
|
||||
|
||||
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);
|
||||
Assertions.assertNotNull(paymentTypeId);
|
||||
|
||||
List<Map<String, Object>> savingsArray = new ArrayList<>();
|
||||
final Integer transactionAmount = 2500;
|
||||
savingsArray.add(savingsArray(paymentTypeId, savingsId, transactionAmount, "10 March 2013"));
|
||||
|
||||
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 depositId = this.savingsAccountHelper.depositGsimApplication(savingsId, savingsArray);
|
||||
Assertions.assertNotNull(depositId);
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testGsimSavingsAccount_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);
|
||||
Assertions.assertNotNull(clientID);
|
||||
|
||||
Integer groupID = GroupHelper.createGroup(this.requestSpec, this.responseSpec, true);
|
||||
Assertions.assertNotNull(groupID);
|
||||
|
||||
groupID = GroupHelper.associateClient(this.requestSpec, this.responseSpec, groupID.toString(), clientID.toString());
|
||||
Assertions.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);
|
||||
Assertions.assertNotNull(savingsProductID);
|
||||
|
||||
List<Map<String, Object>> clientArray = new ArrayList<>();
|
||||
clientArray.add(clientArray(clientID, groupID, savingsProductID, "08 January 2013"));
|
||||
|
||||
final Integer gsimID = this.savingsAccountHelper.applyForGsimApplication(clientArray);
|
||||
|
||||
HashMap savingsStatusHashMap = this.savingsAccountHelper.approveGsimSavings(gsimID);
|
||||
SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap);
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.activateGsimSavings(gsimID);
|
||||
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
|
||||
.closeGsimSavingsAccountAndGetBackRequiredField(gsimID, 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.closeGsimSavingsAccount(gsimID, withdrawBalance);
|
||||
SavingsStatusChecker.verifySavingsAccountIsClosed(savingsStatusHashMap);
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testGsimSavingsAccount_UPDATE_APPLICATION() {
|
||||
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
|
||||
final ResponseSpecification errorResponse = new ResponseSpecBuilder().expectStatusCode(400).build();
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
Assertions.assertNotNull(clientID);
|
||||
|
||||
Integer groupID = GroupHelper.createGroup(this.requestSpec, this.responseSpec, true);
|
||||
Assertions.assertNotNull(groupID);
|
||||
|
||||
groupID = GroupHelper.associateClient(this.requestSpec, this.responseSpec, groupID.toString(), clientID.toString());
|
||||
Assertions.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);
|
||||
Assertions.assertNotNull(savingsProductID);
|
||||
|
||||
List<Map<String, Object>> clientArray = new ArrayList<>();
|
||||
clientArray.add(clientArray(clientID, groupID, savingsProductID, "08 January 2013"));
|
||||
|
||||
final Integer gsimID = this.savingsAccountHelper.applyForGsimApplication(clientArray);
|
||||
|
||||
HashMap savingsStatusHashMap = this.savingsAccountHelper.updateGsimApplication(gsimID, clientID, groupID, savingsProductID);
|
||||
LOG.info("savingsStatusHashMap: {} ", savingsStatusHashMap);
|
||||
Assertions.assertTrue(savingsStatusHashMap.containsKey("savingsId"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getGsimAccount() {
|
||||
|
||||
this.savingsAccountHelper = new SavingsAccountHelper(this.requestSpec, this.responseSpec);
|
||||
final ResponseSpecification errorResponse = new ResponseSpecBuilder().expectStatusCode(400).build();
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
Assertions.assertNotNull(clientID);
|
||||
|
||||
Integer groupID = GroupHelper.createGroup(this.requestSpec, this.responseSpec, true);
|
||||
Assertions.assertNotNull(groupID);
|
||||
|
||||
groupID = GroupHelper.associateClient(this.requestSpec, this.responseSpec, groupID.toString(), clientID.toString());
|
||||
Assertions.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);
|
||||
Assertions.assertNotNull(savingsProductID);
|
||||
|
||||
List<Map<String, Object>> clientArray = new ArrayList<>();
|
||||
clientArray.add(clientArray(clientID, groupID, savingsProductID, "08 January 2013"));
|
||||
final Integer gsimID = this.savingsAccountHelper.applyForGsimApplication(clientArray);
|
||||
|
||||
final List<String> retrievedGsimId = GroupHelper.verifyRetrieveGsimAccounts(this.requestSpec, this.responseSpec, groupID);
|
||||
Assertions.assertNotNull(retrievedGsimId.toString());
|
||||
}
|
||||
|
||||
@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);
|
||||
Assertions.assertNotNull(clientID);
|
||||
|
||||
Integer groupID = GroupHelper.createGroup(this.requestSpec, this.responseSpec, true);
|
||||
Assertions.assertNotNull(groupID);
|
||||
|
||||
groupID = GroupHelper.associateClient(this.requestSpec, this.responseSpec, groupID.toString(), clientID.toString());
|
||||
Assertions.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);
|
||||
Assertions.assertNotNull(savingsProductID);
|
||||
|
||||
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(groupID, savingsProductID, ACCOUNT_TYPE_GROUP);
|
||||
Assertions.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);
|
||||
Assertions.assertNotNull(clientID);
|
||||
|
||||
Integer groupID = GroupHelper.createGroup(this.requestSpec, this.responseSpec, true);
|
||||
Assertions.assertNotNull(groupID);
|
||||
|
||||
groupID = GroupHelper.associateClient(this.requestSpec, this.responseSpec, groupID.toString(), clientID.toString());
|
||||
Assertions.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);
|
||||
Assertions.assertNotNull(savingsProductID);
|
||||
|
||||
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(groupID, savingsProductID, ACCOUNT_TYPE_GROUP);
|
||||
Assertions.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);
|
||||
Assertions.assertNotNull(clientID);
|
||||
|
||||
Integer groupID = GroupHelper.createGroup(this.requestSpec, this.responseSpec, true);
|
||||
Assertions.assertNotNull(groupID);
|
||||
|
||||
groupID = GroupHelper.associateClient(this.requestSpec, this.responseSpec, groupID.toString(), clientID.toString());
|
||||
Assertions.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);
|
||||
Assertions.assertNotNull(savingsProductID);
|
||||
|
||||
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(groupID, savingsProductID, ACCOUNT_TYPE_GROUP);
|
||||
Assertions.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 = Float.valueOf(MINIMUM_OPENING_BALANCE);
|
||||
assertEquals(balance, summary.get("accountBalance"), "Verifying opening Balance");
|
||||
|
||||
Integer depositTransactionId = (Integer) this.savingsAccountHelper.depositToSavingsAccount(savingsId, DEPOSIT_AMOUNT,
|
||||
SavingsAccountHelper.TRANSACTION_DATE, CommonConstants.RESPONSE_RESOURCE_ID);
|
||||
HashMap depositTransaction = this.savingsAccountHelper.getSavingsTransaction(savingsId, depositTransactionId);
|
||||
balance += Float.valueOf(DEPOSIT_AMOUNT);
|
||||
assertEquals(Float.valueOf(DEPOSIT_AMOUNT), depositTransaction.get("amount"), "Verifying Deposit Amount");
|
||||
assertEquals(balance, depositTransaction.get("runningBalance"), "Verifying Balance after Deposit");
|
||||
|
||||
Integer withdrawTransactionId = (Integer) this.savingsAccountHelper.withdrawalFromSavingsAccount(savingsId, WITHDRAW_AMOUNT,
|
||||
SavingsAccountHelper.TRANSACTION_DATE, CommonConstants.RESPONSE_RESOURCE_ID);
|
||||
HashMap withdrawTransaction = this.savingsAccountHelper.getSavingsTransaction(savingsId, withdrawTransactionId);
|
||||
balance -= Float.valueOf(WITHDRAW_AMOUNT);
|
||||
assertEquals(Float.valueOf(WITHDRAW_AMOUNT), withdrawTransaction.get("amount"), "Verifying Withdrawal Amount");
|
||||
assertEquals(balance, withdrawTransaction.get("runningBalance"), "Verifying Balance after Withdrawal");
|
||||
|
||||
Integer newWithdrawTransactionId = this.savingsAccountHelper.updateSavingsAccountTransaction(savingsId, withdrawTransactionId,
|
||||
WITHDRAW_AMOUNT_ADJUSTED);
|
||||
HashMap newWithdrawTransaction = this.savingsAccountHelper.getSavingsTransaction(savingsId, newWithdrawTransactionId);
|
||||
balance = balance + Float.valueOf(WITHDRAW_AMOUNT) - Float.valueOf(WITHDRAW_AMOUNT_ADJUSTED);
|
||||
assertEquals(Float.valueOf(WITHDRAW_AMOUNT_ADJUSTED), newWithdrawTransaction.get("amount"), "Verifying adjusted Amount");
|
||||
assertEquals(balance, newWithdrawTransaction.get("runningBalance"), "Verifying Balance after adjust");
|
||||
summary = this.savingsAccountHelper.getSavingsSummary(savingsId);
|
||||
assertEquals(balance, summary.get("accountBalance"), "Verifying Adjusted Balance");
|
||||
withdrawTransaction = this.savingsAccountHelper.getSavingsTransaction(savingsId, withdrawTransactionId);
|
||||
Assertions.assertTrue((Boolean) withdrawTransaction.get("reversed"));
|
||||
|
||||
this.savingsAccountHelper.undoSavingsAccountTransaction(savingsId, newWithdrawTransactionId);
|
||||
newWithdrawTransaction = this.savingsAccountHelper.getSavingsTransaction(savingsId, withdrawTransactionId);
|
||||
Assertions.assertTrue((Boolean) newWithdrawTransaction.get("reversed"));
|
||||
summary = this.savingsAccountHelper.getSavingsSummary(savingsId);
|
||||
balance += Float.valueOf(WITHDRAW_AMOUNT_ADJUSTED);
|
||||
assertEquals(balance, summary.get("accountBalance"), "Verifying Balance After Undo Transaction");
|
||||
|
||||
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);
|
||||
Assertions.assertNotNull(clientID);
|
||||
|
||||
Integer groupID = GroupHelper.createGroup(this.requestSpec, this.responseSpec, true);
|
||||
Assertions.assertNotNull(groupID);
|
||||
|
||||
groupID = GroupHelper.associateClient(this.requestSpec, this.responseSpec, groupID.toString(), clientID.toString());
|
||||
Assertions.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);
|
||||
Assertions.assertNotNull(savingsProductID);
|
||||
|
||||
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(groupID, savingsProductID, ACCOUNT_TYPE_GROUP);
|
||||
Assertions.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());
|
||||
Assertions.assertNotNull(withdrawalChargeId);
|
||||
|
||||
this.savingsAccountHelper.addChargesForSavings(savingsId, withdrawalChargeId, false);
|
||||
ArrayList<HashMap> chargesPendingState = this.savingsAccountHelper.getSavingsCharges(savingsId);
|
||||
Assertions.assertEquals(1, chargesPendingState.size());
|
||||
|
||||
Integer savingsChargeId = (Integer) chargesPendingState.get(0).get("id");
|
||||
HashMap chargeChanges = this.savingsAccountHelper.updateCharges(savingsChargeId, savingsId);
|
||||
Assertions.assertTrue(chargeChanges.containsKey("amount"));
|
||||
|
||||
Integer deletedChargeId = this.savingsAccountHelper.deleteCharge(savingsChargeId, savingsId);
|
||||
assertEquals(savingsChargeId, deletedChargeId);
|
||||
|
||||
chargesPendingState = this.savingsAccountHelper.getSavingsCharges(savingsId);
|
||||
Assertions.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());
|
||||
Assertions.assertNotNull(chargeId);
|
||||
|
||||
ArrayList<HashMap> charges = this.savingsAccountHelper.getSavingsCharges(savingsId);
|
||||
Assertions.assertTrue(charges == null || charges.size() == 0);
|
||||
|
||||
this.savingsAccountHelper.addChargesForSavings(savingsId, chargeId, true);
|
||||
charges = this.savingsAccountHelper.getSavingsCharges(savingsId);
|
||||
Assertions.assertEquals(1, charges.size());
|
||||
|
||||
HashMap savingsChargeForPay = charges.get(0);
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(CommonConstants.DATE_FORMAT, 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());
|
||||
Assertions.assertNotNull(monthlyFeechargeId);
|
||||
|
||||
this.savingsAccountHelper.addChargesForSavings(savingsId, monthlyFeechargeId, true);
|
||||
charges = this.savingsAccountHelper.getSavingsCharges(savingsId);
|
||||
Assertions.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());
|
||||
Assertions.assertNotNull(weeklyFeeId);
|
||||
|
||||
this.savingsAccountHelper.addChargesForSavings(savingsId, weeklyFeeId, true);
|
||||
charges = this.savingsAccountHelper.getSavingsCharges(savingsId);
|
||||
Assertions.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);
|
||||
Assertions.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 = LocalDate.of((Integer) nextDueDates.get(0), (Integer) nextDueDates.get(1), (Integer) nextDueDates.get(2));
|
||||
LocalDate expectedNextDueDate = LocalDate.of((Integer) dates.get(0), (Integer) dates.get(1), (Integer) dates.get(2))
|
||||
.plusWeeks((Integer) paidCharge.get("feeInterval"));
|
||||
assertEquals(expectedNextDueDate, nextDueDate);
|
||||
|
||||
this.savingsAccountHelper.closeSavingsAccountAndGetBackRequiredField(savingsId, "true", null,
|
||||
sdf.format(Date.from(Utils.getLocalDateOfTenant().atStartOfDay(ZoneId.systemDefault()).toInstant())));
|
||||
|
||||
}
|
||||
|
||||
public static Integer createSavingsProduct(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String minOpenningBalance, final String minBalanceForInterestCalculation, final String minRequiredBalance,
|
||||
final String enforceMinRequiredBalance) {
|
||||
LOG.info("------------------------------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);
|
||||
}
|
||||
|
||||
private Map<String, Object> clientArray(final Integer clientId, final Integer groupId, final Integer productId,
|
||||
final String submittedOnDate) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("clientId", clientId);
|
||||
map.put("groupId", groupId);
|
||||
map.put("productId", productId);
|
||||
map.put("submittedOnDate", submittedOnDate);
|
||||
map.put("dateFormat", CommonConstants.DATE_FORMAT);
|
||||
map.put("locale", "en");
|
||||
map.put("isParentAccount", "1");
|
||||
map.put("isGSIM", "true");
|
||||
return map;
|
||||
}
|
||||
|
||||
private Map<String, Object> savingsArray(final Integer paymentId, final Integer savingsId, final Integer transactionAmount,
|
||||
final String transactionDate) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("transactionDate", transactionDate);
|
||||
map.put("dateFormat", CommonConstants.DATE_FORMAT);
|
||||
map.put("locale", "en");
|
||||
map.put("transactionAmount", transactionAmount);
|
||||
map.put("paymentTypeId", paymentId);
|
||||
map.put("childAccountId", savingsId);
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
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.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Group Test for checking Group: Creation, Activation, Client Association, Updating & Deletion
|
||||
*/
|
||||
public class GroupTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(GroupTest.class);
|
||||
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";
|
||||
|
||||
@BeforeEach
|
||||
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);
|
||||
LOG.info("--------------creating first staff with id------------- {}", createStaffId1);
|
||||
Assertions.assertNotNull(createStaffId1);
|
||||
|
||||
Integer createStaffId2 = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
|
||||
LOG.info("--------------creating second staff with id------------- {}", createStaffId2);
|
||||
Assertions.assertNotNull(createStaffId2);
|
||||
|
||||
// assign staff "createStaffId1" to group
|
||||
HashMap assignStaffGroupId = (HashMap) GroupHelper.assignStaff(this.requestSpec, this.responseSpec, groupID.toString(),
|
||||
createStaffId1.longValue());
|
||||
assertEquals(assignStaffGroupId.get("staffId"), createStaffId1, "Verify assigned staff id is the same as id sent");
|
||||
|
||||
// assign staff "createStaffId2" to client
|
||||
final HashMap assignStaffToClientChanges = (HashMap) ClientHelper.assignStaffToClient(this.requestSpec, this.responseSpec,
|
||||
clientID.toString(), createStaffId2.toString());
|
||||
assertEquals(assignStaffToClientChanges.get("staffId"), createStaffId2, "Verify assigned staff id is the same as id sent");
|
||||
|
||||
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(assignStaffAndInheritStaffForClientAccounts.get("staffId"), createStaffId2, "Verify if client stuff has changed");
|
||||
assertEquals(assignStaffAndInheritStaffForClientAccounts.get("staffId"), getClientStaffId,
|
||||
"Verify if client inherited staff assigned above");
|
||||
|
||||
// assert if clients loan officer has changed
|
||||
final Integer loanOfficerId = this.loanTransactionHelper.getLoanOfficerId(loanId.toString());
|
||||
assertEquals(assignStaffAndInheritStaffForClientAccounts.get("staffId"), loanOfficerId, "Verify if client loan inherited staff");
|
||||
|
||||
}
|
||||
|
||||
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) {
|
||||
LOG.info("--------------------------------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);
|
||||
}
|
||||
|
||||
}
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
/**
|
||||
* 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.jupiter.api.Assertions.fail;
|
||||
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.path.json.JsonPath;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.util.UUID;
|
||||
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.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class HookIntegrationTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(HookIntegrationTest.class);
|
||||
private RequestSpecification requestSpec;
|
||||
private ResponseSpecification responseSpec;
|
||||
|
||||
private HookHelper hookHelper;
|
||||
private OfficeHelper officeHelper;
|
||||
|
||||
@BeforeEach
|
||||
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 uniqueId = UUID.randomUUID().toString();
|
||||
final String payloadURL = "http://echo-webhook.herokuapp.com:80/" + uniqueId + "?";
|
||||
final Integer hookId = this.hookHelper.createHook(payloadURL);
|
||||
Assertions.assertNotNull(hookId);
|
||||
final Integer createdOfficeID = this.officeHelper.createOffice("01 January 2012");
|
||||
Assertions.assertNotNull(createdOfficeID);
|
||||
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");
|
||||
Assertions.assertEquals(createdOfficeID, notificationOfficeId,
|
||||
"Equality check for created officeId and hook received payload officeId");
|
||||
LOG.info("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);
|
||||
} finally {
|
||||
this.hookHelper.deleteHook(hookId.longValue());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@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();
|
||||
Assertions.assertNotNull(hookId);
|
||||
this.hookHelper.verifyHookCreatedOnServer(hookId);
|
||||
LOG.info("---------------------SUCCESSFULLY CREATED AND VERIFIED HOOK------------------------- {}", hookId);
|
||||
this.hookHelper.updateHook(updateURL, hookId);
|
||||
this.hookHelper.verifyUpdateHook(updateURL, hookId);
|
||||
LOG.info("---------------------SUCCESSFULLY UPDATED AND VERIFIED HOOK------------------------- {}", hookId);
|
||||
this.hookHelper.deleteHook(hookId);
|
||||
this.hookHelper.verifyDeleteHook(hookId);
|
||||
LOG.info("---------------------SUCCESSFULLY DELETED AND VERIFIED HOOK------------------------- {}", hookId);
|
||||
|
||||
}
|
||||
}
|
||||
+275
@@ -0,0 +1,275 @@
|
||||
/**
|
||||
* 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.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
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.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class LoanApplicationApprovalTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(LoanApplicationApprovalTest.class);
|
||||
private ResponseSpecification responseSpec;
|
||||
private ResponseSpecification responseSpecForStatusCode403;
|
||||
private ResponseSpecification responseSpecForStatusCode400;
|
||||
private RequestSpecification requestSpec;
|
||||
private LoanTransactionHelper loanTransactionHelper;
|
||||
|
||||
@BeforeEach
|
||||
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("01 March 2014", "1000"));
|
||||
createTranches.add(createTrancheDetail("23 March 2014", "4000"));
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2014");
|
||||
LOG.info("---------------------------------CLIENT CREATED WITH ID--------------------------------------------------- {}", clientID);
|
||||
|
||||
final Integer loanProductID = this.loanTransactionHelper
|
||||
.getLoanProductId(new LoanProductTestBuilder().withInterestTypeAsDecliningBalance().withTranches(true)
|
||||
.withInterestCalculationPeriodTypeAsRepaymentPeriod(true).build(null));
|
||||
LOG.info("----------------------------------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 = "01 March 2014";
|
||||
final String expectedDisbursementDate = "01 March 2014";
|
||||
|
||||
List<HashMap> approveTranches = new ArrayList<>();
|
||||
approveTranches.add(createTrancheDetail("01 March 2014", "1000"));
|
||||
approveTranches.add(createTrancheDetail("23 March 2014", "1000"));
|
||||
|
||||
final Integer loanID = applyForLoanApplicationWithTranches(clientID, loanProductID, proposedAmount, createTranches);
|
||||
LOG.info("-----------------------------------LOAN CREATED WITH LOANID------------------------------------------------- {}", loanID);
|
||||
|
||||
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
|
||||
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
|
||||
|
||||
LOG.info("-----------------------------------APPROVE LOAN-----------------------------------------------------------");
|
||||
loanStatusHashMap = this.loanTransactionHelper.approveLoanWithApproveAmount(approveDate, expectedDisbursementDate, approvalAmount,
|
||||
loanID, approveTranches);
|
||||
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
|
||||
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
|
||||
LOG.info("-----------------------------------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 = "01 March 2014";
|
||||
final String expectedDisbursementDate = "01 March 2014";
|
||||
|
||||
List<HashMap> approveTranche1 = new ArrayList<>();
|
||||
approveTranche1.add(createTrancheDetail("01 March 2014", "5000"));
|
||||
approveTranche1.add(createTrancheDetail("23 March 2014", "5000"));
|
||||
|
||||
List<HashMap> approveTranche2 = new ArrayList<>();
|
||||
approveTranche2.add(createTrancheDetail("01 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("01 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("01 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);
|
||||
LOG.info("-----------------------------------LOAN CREATED WITH LOANID------------------------------------------------- {}", loanID);
|
||||
|
||||
HashMap<String, Object> loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
|
||||
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
|
||||
|
||||
LOG.info("-----------------------------------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) {
|
||||
LOG.info("--------------------------------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);
|
||||
}
|
||||
|
||||
}
|
||||
+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;
|
||||
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
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.LoanProductTestBuilder;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanStatusChecker;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class LoanApplicationUndoLastTrancheTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(LoanApplicationUndoLastTrancheTest.class);
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private LoanTransactionHelper loanTransactionHelper;
|
||||
private LoanApplicationApprovalTest loanApplicationApprovalTest;
|
||||
|
||||
@BeforeEach
|
||||
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 = "01 March 2014";
|
||||
final String expectedDisbursementDate = "01 March 2014";
|
||||
final String disbursalDate = "01 March 2014";
|
||||
|
||||
// CREATE CLIENT
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2014");
|
||||
LOG.info("---------------------------------CLIENT CREATED WITH ID--------------------------------------------------- {}", clientID);
|
||||
|
||||
// CREATE LOAN MULTIDISBURSAL PRODUCT
|
||||
final Integer loanProductID = this.loanTransactionHelper
|
||||
.getLoanProductId(new LoanProductTestBuilder().withInterestTypeAsDecliningBalance().withTranches(true)
|
||||
.withInterestCalculationPeriodTypeAsRepaymentPeriod(true).build(null));
|
||||
LOG.info("----------------------------------LOAN PRODUCT CREATED WITH ID------------------------------------------- {}",
|
||||
loanProductID);
|
||||
|
||||
// CREATE TRANCHES
|
||||
List<HashMap> createTranches = new ArrayList<>();
|
||||
createTranches.add(this.loanApplicationApprovalTest.createTrancheDetail("01 March 2014", "1000"));
|
||||
createTranches.add(this.loanApplicationApprovalTest.createTrancheDetail("23 June 2014", "4000"));
|
||||
|
||||
// APPROVE TRANCHES
|
||||
List<HashMap> approveTranches = new ArrayList<>();
|
||||
approveTranches.add(this.loanApplicationApprovalTest.createTrancheDetail("01 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);
|
||||
LOG.info("-----------------------------------LOAN CREATED WITH LOANID------------------------------------------------- {}", loanID);
|
||||
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
|
||||
|
||||
// VALIDATE THE LOAN STATUS
|
||||
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
|
||||
|
||||
LOG.info("-----------------------------------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);
|
||||
|
||||
LOG.info("-------------Make repayment 1-----------");
|
||||
this.loanTransactionHelper.makeRepayment("01 April 2014", Float.valueOf("420"), loanID);
|
||||
LOG.info("-------------Make repayment 2-----------");
|
||||
this.loanTransactionHelper.makeRepayment("01 May 2014", Float.valueOf("412"), loanID);
|
||||
LOG.info("-------------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) {
|
||||
Assertions.assertEquals(Float.valueOf("1000.0"), disbursedAmount);
|
||||
|
||||
}
|
||||
|
||||
public Integer applyForLoanApplicationWithTranches(final Integer clientID, final Integer loanProductID, String principal,
|
||||
List<HashMap> tranches) {
|
||||
LOG.info("--------------------------------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);
|
||||
}
|
||||
|
||||
}
|
||||
+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;
|
||||
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
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.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class LoanDisbursalDateValidationTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(LoanDisbursalDateValidationTest.class);
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private LoanTransactionHelper loanTransactionHelper;
|
||||
private ResponseSpecification responseForbiddenError;
|
||||
|
||||
@BeforeEach
|
||||
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.responseForbiddenError = new ResponseSpecBuilder().expectStatusCode(403).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loanApplicationValidateDisbursalDate() {
|
||||
|
||||
final String proposedAmount = "5000";
|
||||
final String approveDate = "01 March 2014";
|
||||
final String disbursalDate = "02 March 2014";
|
||||
|
||||
// CREATE CLIENT
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2014");
|
||||
LOG.info("---------------------------------CLIENT CREATED WITH ID--------------------------------------------------- {}", clientID);
|
||||
|
||||
// CREATE LOAN PRODUCT
|
||||
final Integer loanProductID = this.loanTransactionHelper
|
||||
.getLoanProductId(new LoanProductTestBuilder().withSyncExpectedWithDisbursementDate(true).build(null));
|
||||
LOG.info("----------------------------------LOAN PRODUCT CREATED WITH ID------------------------------------------- {}",
|
||||
loanProductID);
|
||||
|
||||
// APPLY FOR LOAN
|
||||
final Integer loanID = applyForLoanApplication(clientID, loanProductID, proposedAmount);
|
||||
LOG.info("-----------------------------------LOAN CREATED WITH LOANID------------------------------------------------- {}", loanID);
|
||||
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
|
||||
|
||||
// VALIDATE THE LOAN STATUS
|
||||
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
|
||||
|
||||
LOG.info("-----------------------------------APPROVE LOAN-----------------------------------------------------------");
|
||||
loanStatusHashMap = this.loanTransactionHelper.approveLoan(approveDate, loanID);
|
||||
|
||||
// VALIDATE THE LOAN IS APPROVED
|
||||
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
|
||||
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
|
||||
|
||||
// DISBURSE A LOAN
|
||||
@SuppressWarnings("unchecked")
|
||||
List<HashMap> disbursalError = (List<HashMap>) this.loanTransactionHelper.disburseLoan(disbursalDate, loanID,
|
||||
this.responseForbiddenError);
|
||||
|
||||
Assertions.assertEquals(disbursalError.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE),
|
||||
"error.msg.actual.disbursement.date.does.not.match.with.expected.disbursal.date");
|
||||
|
||||
}
|
||||
|
||||
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("01 March 2014")
|
||||
.withSubmittedOnDate("26 February 2014").build(clientID.toString(), loanProductID.toString(), null);
|
||||
return this.loanTransactionHelper.getLoanId(loanApplication);
|
||||
}
|
||||
|
||||
}
|
||||
+457
@@ -0,0 +1,457 @@
|
||||
/**
|
||||
* 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.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
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.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public class LoanDisbursementDetailsIntegrationTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(LoanDisbursementDetailsIntegrationTest.class);
|
||||
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";
|
||||
|
||||
@BeforeEach
|
||||
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");
|
||||
LOG.info("---------------------------------CLIENT CREATED WITH ID---------------------------------------------------{}", clientID);
|
||||
|
||||
final Integer loanProductID = this.loanTransactionHelper.getLoanProductId(new LoanProductTestBuilder()
|
||||
.withInterestTypeAsDecliningBalance().withMoratorium("", "").withAmortizationTypeAsEqualInstallments().withTranches(true)
|
||||
.withInterestCalculationPeriodTypeAsRepaymentPeriod(true).build(null));
|
||||
LOG.info("----------------------------------LOAN PRODUCT CREATED WITH ID------------------------------------------- {}",
|
||||
loanProductID);
|
||||
|
||||
final Integer loanIDWithEmi = applyForLoanApplicationWithEmiAmount(clientID, loanProductID, proposedAmount, createTranches,
|
||||
installmentAmount);
|
||||
|
||||
LOG.info("-----------------------------------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(15, periods.size());
|
||||
|
||||
this.validateRepaymentScheduleWithEMI(periods);
|
||||
|
||||
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanIDWithEmi);
|
||||
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
|
||||
|
||||
LOG.info("-----------------------------------APPROVE LOAN-----------------------------------------------------------");
|
||||
loanStatusHashMap = this.loanTransactionHelper.approveLoanWithApproveAmount("01 June 2015", "01 June 2015", "10000", loanIDWithEmi,
|
||||
createTranches);
|
||||
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
|
||||
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
|
||||
LOG.info(
|
||||
"-----------------------------------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(15, periods1.size());
|
||||
|
||||
LOG.info("-----------------------------------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);
|
||||
|
||||
LOG.info("-----------------------------------APPROVE LOAN-----------------------------------------------------------");
|
||||
loanStatusHashMap = this.loanTransactionHelper.approveLoanWithApproveAmount("01 June 2015", "01 June 2015", "10000",
|
||||
loanIDWithoutEmi, createTranches);
|
||||
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
|
||||
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
|
||||
LOG.info(
|
||||
"-----------------------------------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());
|
||||
LOG.info("{}", period.get("totalOriginalDueForPeriod").toString());
|
||||
assertEquals(Float.valueOf(period.get("totalOriginalDueForPeriod").toString()),
|
||||
expectedRepaymentSchedule.getTotalOriginalDueForPeriod().floatValue(), 0.0f);
|
||||
|
||||
assertEquals(Float.valueOf(period.get("totalOutstandingForPeriod").toString()).floatValue(),
|
||||
expectedRepaymentSchedule.getTotalOutstandingForPeriod(), 0.0f);
|
||||
|
||||
if (position != 0 && position != 3) {
|
||||
|
||||
assertEquals(Float.valueOf(period.get("interestOutstanding").toString()).floatValue(),
|
||||
expectedRepaymentSchedule.getInterestOutstanding(), 0.0f);
|
||||
assertEquals(Float.valueOf(period.get("principalOutstanding").toString()).floatValue(),
|
||||
expectedRepaymentSchedule.getPrincipalOutstanding(), 0.0f);
|
||||
assertEquals(Float.valueOf(period.get("principalDue").toString()).floatValue(), expectedRepaymentSchedule.getPrincipalDue(),
|
||||
0.0f);
|
||||
assertEquals(Float.valueOf(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) {
|
||||
|
||||
LOG.info("--------------------------------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() throws ParseException {
|
||||
|
||||
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");
|
||||
LOG.info("---------------------------------CLIENT CREATED WITH ID--------------------------------------------------- {}", clientID);
|
||||
|
||||
final Integer loanProductID = this.loanTransactionHelper
|
||||
.getLoanProductId(new LoanProductTestBuilder().withInterestTypeAsDecliningBalance().withTranches(true)
|
||||
.withInterestCalculationPeriodTypeAsRepaymentPeriod(true).build(null));
|
||||
LOG.info("----------------------------------LOAN PRODUCT CREATED WITH ID------------------------------------------- {}",
|
||||
loanProductID);
|
||||
|
||||
this.loanID = applyForLoanApplicationWithTranches(clientID, loanProductID, proposedAmount, createTranches);
|
||||
LOG.info("-----------------------------------LOAN CREATED WITH LOANID------------------------------------------------- {}", loanID);
|
||||
|
||||
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
|
||||
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
|
||||
|
||||
LOG.info("-----------------------------------APPROVE LOAN-----------------------------------------------------------");
|
||||
loanStatusHashMap = this.loanTransactionHelper.approveLoanWithApproveAmount(approveDate, expectedDisbursementDate, approvalAmount,
|
||||
loanID, createTranches);
|
||||
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
|
||||
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
|
||||
LOG.info("-----------------------------------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() throws ParseException {
|
||||
this.editDateAndPrincipalOfExistingTranche();
|
||||
this.addNewDisbursementDetails();
|
||||
this.deleteDisbursmentDetails();
|
||||
}
|
||||
|
||||
private void addNewDisbursementDetails() throws ParseException {
|
||||
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, "03 March 2014", "2000"));
|
||||
addTranches.add(this.loanTransactionHelper.createTrancheDetail(id, "04 March 2014", "500"));
|
||||
|
||||
/* Add disbursement detail */
|
||||
this.loanTransactionHelper.addAndDeleteDisbursementDetail(this.loanID, this.approvalAmount, this.expectedDisbursementDate,
|
||||
addTranches, "");
|
||||
}
|
||||
|
||||
private void deleteDisbursmentDetails() throws ParseException {
|
||||
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() throws ParseException {
|
||||
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) throws ParseException {
|
||||
|
||||
SimpleDateFormat source = new SimpleDateFormat("[yyyy, MM, dd]");
|
||||
SimpleDateFormat target = new SimpleDateFormat("dd MMMM yyyy");
|
||||
String date = target.format(source.parse(expectedDisbursementDate));
|
||||
|
||||
return date;
|
||||
}
|
||||
|
||||
private Integer applyForLoanApplicationWithTranches(final Integer clientID, final Integer loanProductID, String principal,
|
||||
List<HashMap> tranches) {
|
||||
LOG.info("--------------------------------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);
|
||||
}
|
||||
|
||||
}
|
||||
+238
@@ -0,0 +1,238 @@
|
||||
/**
|
||||
* 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.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
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.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class LoanRepaymentRescheduleAtDisbursementTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(LoanRepaymentRescheduleAtDisbursementTest.class);
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private LoanTransactionHelper loanTransactionHelper;
|
||||
private LoanApplicationApprovalTest loanApplicationApprovalTest;
|
||||
private ResponseSpecification generalResponseSpec;
|
||||
|
||||
@BeforeEach
|
||||
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";
|
||||
|
||||
// CREATE CLIENT
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2014");
|
||||
LOG.info("---------------------------------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",
|
||||
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,
|
||||
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);
|
||||
|
||||
LOG.info("-----------------------------------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 preCloseInterestCalculationStrategy, final Account[] accounts) {
|
||||
final String recalculationCompoundingFrequencyType = null;
|
||||
final String recalculationCompoundingFrequencyInterval = null;
|
||||
final Integer recalculationCompoundingFrequencyOnDayType = null;
|
||||
final Integer recalculationCompoundingFrequencyDayOfWeekType = null;
|
||||
final Integer recalculationRestFrequencyOnDayType = null;
|
||||
final Integer recalculationRestFrequencyDayOfWeekType = null;
|
||||
return createLoanProductWithInterestRecalculation(repaymentStrategy, interestRecalculationCompoundingMethod,
|
||||
rescheduleStrategyMethod, recalculationRestFrequencyType, recalculationRestFrequencyInterval,
|
||||
recalculationCompoundingFrequencyType, recalculationCompoundingFrequencyInterval, preCloseInterestCalculationStrategy,
|
||||
accounts, null, false, recalculationCompoundingFrequencyOnDayType, recalculationCompoundingFrequencyDayOfWeekType,
|
||||
recalculationRestFrequencyOnDayType, recalculationRestFrequencyDayOfWeekType);
|
||||
}
|
||||
|
||||
private Integer createLoanProductWithInterestRecalculation(final String repaymentStrategy,
|
||||
final String interestRecalculationCompoundingMethod, final String rescheduleStrategyMethod,
|
||||
final String recalculationRestFrequencyType, final String recalculationRestFrequencyInterval,
|
||||
final String recalculationCompoundingFrequencyType, final String recalculationCompoundingFrequencyInterval,
|
||||
final String preCloseInterestCalculationStrategy, final Account[] accounts, final String chargeId,
|
||||
boolean isArrearsBasedOnOriginalSchedule, final Integer recalculationCompoundingFrequencyOnDayType,
|
||||
final Integer recalculationCompoundingFrequencyDayOfWeekType, final Integer recalculationRestFrequencyOnDayType,
|
||||
final Integer recalculationRestFrequencyDayOfWeekType) {
|
||||
LOG.info("------------------------------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,
|
||||
recalculationRestFrequencyOnDayType, recalculationRestFrequencyDayOfWeekType)
|
||||
.withInterestRecalculationCompoundingFrequencyDetails(recalculationCompoundingFrequencyType,
|
||||
recalculationCompoundingFrequencyInterval, recalculationCompoundingFrequencyOnDayType,
|
||||
recalculationCompoundingFrequencyDayOfWeekType);
|
||||
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 repaymentStrategy, final List<HashMap> charges, List<HashMap> tranches) {
|
||||
final String graceOnInterestPayment = null;
|
||||
final String graceOnPrincipalPayment = null;
|
||||
return applyForLoanApplicationForInterestRecalculation(clientID, loanProductID, disbursementDate, repaymentStrategy, charges,
|
||||
graceOnInterestPayment, graceOnPrincipalPayment, tranches);
|
||||
}
|
||||
|
||||
private Integer applyForLoanApplicationForInterestRecalculation(final Integer clientID, final Integer loanProductID,
|
||||
final String disbursementDate, final String repaymentStrategy, final List<HashMap> charges, final String graceOnInterestPayment,
|
||||
final String graceOnPrincipalPayment, List<HashMap> tranches) {
|
||||
LOG.info("--------------------------------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) //
|
||||
.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)));
|
||||
}
|
||||
}
|
||||
+410
@@ -0,0 +1,410 @@
|
||||
/**
|
||||
* 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.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||
import org.apache.fineract.integrationtests.common.GlobalConfigurationHelper;
|
||||
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.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class LoanRescheduleOnDecliningBalanceLoanTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(LoanRescheduleOnDecliningBalanceLoanTest.class);
|
||||
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 final String loanPrincipalAmount = "100000.00";
|
||||
private final String numberOfRepayments = "12";
|
||||
private final String interestRatePerPeriod = "18";
|
||||
private final String dateString = "4 September 2014";
|
||||
|
||||
@BeforeEach
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
disableConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the client, loan product, and loan entities
|
||||
**/
|
||||
private void createRequiredEntities() {
|
||||
this.createClientEntity();
|
||||
this.createLoanProductEntity();
|
||||
this.createLoanEntity();
|
||||
this.enableConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the client, loan product, and loan entities
|
||||
**/
|
||||
private void createRequiredEntitiesWithRecalculationEnabled() {
|
||||
this.createClientEntity();
|
||||
this.createLoanProductWithInterestRecalculation();
|
||||
this.createLoanEntity();
|
||||
this.enableConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
LOG.info("---------------------------------CREATING LOAN PRODUCT------------------------------------------");
|
||||
|
||||
final String loanProductJSON = new LoanProductTestBuilder().withPrincipal(loanPrincipalAmount)
|
||||
.withNumberOfRepayments(numberOfRepayments).withinterestRatePerPeriod(interestRatePerPeriod)
|
||||
.withInterestRateFrequencyTypeAsYear().withInterestTypeAsDecliningBalance().withInterestCalculationPeriodTypeAsDays()
|
||||
.build(null);
|
||||
|
||||
this.loanProductId = this.loanTransactionHelper.getLoanProductId(loanProductJSON);
|
||||
LOG.info("Successfully created loan product (ID:{}) ", this.loanProductId);
|
||||
}
|
||||
|
||||
private void createLoanProductWithInterestRecalculation() {
|
||||
LOG.info(
|
||||
"---------------------------------CREATING LOAN PRODUCT WITH RECALULATION ENABLED ------------------------------------------");
|
||||
|
||||
final String interestRecalculationCompoundingMethod = LoanProductTestBuilder.RECALCULATION_COMPOUNDING_METHOD_NONE;
|
||||
final String rescheduleStrategyMethod = LoanProductTestBuilder.RECALCULATION_STRATEGY_REDUCE_NUMBER_OF_INSTALLMENTS;
|
||||
final String recalculationRestFrequencyType = LoanProductTestBuilder.RECALCULATION_FREQUENCY_TYPE_DAILY;
|
||||
final String recalculationRestFrequencyInterval = "0";
|
||||
final String preCloseInterestCalculationStrategy = LoanProductTestBuilder.INTEREST_APPLICABLE_STRATEGY_ON_PRE_CLOSE_DATE;
|
||||
final String recalculationCompoundingFrequencyType = null;
|
||||
final String recalculationCompoundingFrequencyInterval = null;
|
||||
final Integer recalculationCompoundingFrequencyOnDayType = null;
|
||||
final Integer recalculationCompoundingFrequencyDayOfWeekType = null;
|
||||
final Integer recalculationRestFrequencyOnDayType = null;
|
||||
final Integer recalculationRestFrequencyDayOfWeekType = null;
|
||||
|
||||
final String loanProductJSON = new LoanProductTestBuilder().withPrincipal(loanPrincipalAmount)
|
||||
.withNumberOfRepayments(numberOfRepayments).withinterestRatePerPeriod(interestRatePerPeriod)
|
||||
.withInterestRateFrequencyTypeAsYear().withInterestTypeAsDecliningBalance().withInterestCalculationPeriodTypeAsDays()
|
||||
.withInterestRecalculationDetails(interestRecalculationCompoundingMethod, rescheduleStrategyMethod,
|
||||
preCloseInterestCalculationStrategy)
|
||||
.withInterestRecalculationRestFrequencyDetails(recalculationRestFrequencyType, recalculationRestFrequencyInterval,
|
||||
recalculationRestFrequencyOnDayType, recalculationRestFrequencyDayOfWeekType)
|
||||
.withInterestRecalculationCompoundingFrequencyDetails(recalculationCompoundingFrequencyType,
|
||||
recalculationCompoundingFrequencyInterval, recalculationCompoundingFrequencyOnDayType,
|
||||
recalculationCompoundingFrequencyDayOfWeekType)
|
||||
.build(null);
|
||||
|
||||
this.loanProductId = this.loanTransactionHelper.getLoanProductId(loanProductJSON);
|
||||
LOG.info("Successfully created loan product (ID:{}) ", this.loanProductId);
|
||||
}
|
||||
|
||||
/**
|
||||
* submit a new loan application, approve and disburse the loan
|
||||
**/
|
||||
private void createLoanEntity() {
|
||||
LOG.info("---------------------------------NEW LOAN APPLICATION------------------------------------------");
|
||||
|
||||
final String loanApplicationJSON = new LoanApplicationTestBuilder().withPrincipal(loanPrincipalAmount)
|
||||
.withLoanTermFrequency(numberOfRepayments).withLoanTermFrequencyAsMonths().withNumberOfRepayments(numberOfRepayments)
|
||||
.withRepaymentEveryAfter("1").withRepaymentFrequencyTypeAsMonths().withAmortizationTypeAsEqualInstallments()
|
||||
.withInterestCalculationPeriodTypeAsDays().withInterestRatePerPeriod(interestRatePerPeriod)
|
||||
.withInterestTypeAsDecliningBalance().withSubmittedOnDate(dateString).withExpectedDisbursementDate(dateString)
|
||||
.withPrincipalGrace("2").withInterestGrace("2").build(this.clientId.toString(), this.loanProductId.toString(), null);
|
||||
|
||||
this.loanId = this.loanTransactionHelper.getLoanId(loanApplicationJSON);
|
||||
|
||||
LOG.info("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);
|
||||
LOG.info("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);
|
||||
LOG.info("Successfully disbursed loan (ID: {} )", this.loanId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* enables the configuration `is-interest-to-be-appropriated-equally-when-greater-than-emi`
|
||||
**/
|
||||
private void enableConfig() {
|
||||
GlobalConfigurationHelper.updateEnabledFlagForGlobalConfiguration(this.requestSpec, this.responseSpec, "34", true);
|
||||
}
|
||||
|
||||
/**
|
||||
* disables the configuration `is-interest-to-be-appropriated-equally-when-greater-than-emi`
|
||||
**/
|
||||
private void disableConfig() {
|
||||
GlobalConfigurationHelper.updateEnabledFlagForGlobalConfiguration(this.requestSpec, this.responseSpec, "34", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateLoanRescheduleRequestWithInterestAppropriation() {
|
||||
// create all required entities
|
||||
this.createRequiredEntities();
|
||||
this.createAndApproveLoanRescheduleRequestForInterestAppropriation();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* create new loan reschedule request
|
||||
**/
|
||||
private void createAndApproveLoanRescheduleRequestForInterestAppropriation() {
|
||||
LOG.info(
|
||||
"---------------------------------CREATING LOAN RESCHEDULE REQUEST FOR INTEREST APPROPRIATTION-------------------------------------");
|
||||
|
||||
final String requestJSON = new LoanRescheduleRequestTestBuilder().updateGraceOnPrincipal(null).updateGraceOnInterest(null)
|
||||
.updateExtraTerms(null).updateRescheduleFromDate("04 January 2015").updateAdjustedDueDate("04 October 2015")
|
||||
.updateRecalculateInterest(true).build(this.loanId.toString());
|
||||
|
||||
this.loanRescheduleRequestId = this.loanRescheduleRequestHelper.createLoanRescheduleRequest(requestJSON);
|
||||
this.loanRescheduleRequestHelper.verifyCreationOfLoanRescheduleRequest(this.loanRescheduleRequestId);
|
||||
|
||||
LOG.info("Successfully created loan reschedule request (ID: {} )", this.loanRescheduleRequestId);
|
||||
|
||||
final String aproveRequestJSON = new LoanRescheduleRequestTestBuilder().getApproveLoanRescheduleRequestJSON();
|
||||
this.loanRescheduleRequestHelper.approveLoanRescheduleRequest(this.loanRescheduleRequestId, aproveRequestJSON);
|
||||
final HashMap response = (HashMap) this.loanRescheduleRequestHelper.getLoanRescheduleRequest(loanRescheduleRequestId, "statusEnum");
|
||||
assertTrue((Boolean) response.get("approved"));
|
||||
|
||||
LOG.info("Successfully approved loan reschedule request (ID: {})", this.loanRescheduleRequestId);
|
||||
|
||||
final Map repaymentSchedule = (Map) this.loanTransactionHelper.getLoanDetail(requestSpec, generalResponseSpec, loanId,
|
||||
"repaymentSchedule");
|
||||
final ArrayList periods = (ArrayList) repaymentSchedule.get("periods");
|
||||
|
||||
HashMap period = (HashMap) periods.get(5);
|
||||
Float totalDueForPeriod = (Float) period.get("totalDueForPeriod");
|
||||
|
||||
final HashMap loanSummary = this.loanTransactionHelper.getLoanSummary(requestSpec, generalResponseSpec, loanId);
|
||||
final Float totalExpectedRepayment = (Float) loanSummary.get("totalExpectedRepayment");
|
||||
|
||||
assertEquals(12186, totalDueForPeriod.intValue(), "EXPECTED REPAYMENT is NOK");
|
||||
assertEquals(123682, totalExpectedRepayment.intValue(), "TOTAL EXPECTED REPAYMENT is NOK");
|
||||
|
||||
LOG.info("Successfully approved loan reschedule request (ID: {})", this.loanRescheduleRequestId);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateLoanRescheduleRequestWithRecalculationEnabled() {
|
||||
// create all required entities
|
||||
this.createRequiredEntitiesWithRecalculationEnabled();
|
||||
this.createAndApproveLoanRescheduleRequestWithRecalculationEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* create new loan reschedule request with recalculation enabled in Loan product
|
||||
**/
|
||||
|
||||
private void createAndApproveLoanRescheduleRequestWithRecalculationEnabled() {
|
||||
LOG.info(
|
||||
"---------------------------------CREATING LOAN RESCHEDULE REQUEST FOR LOAN WITH RECALCULATION------------------------------------");
|
||||
|
||||
final String requestJSON = new LoanRescheduleRequestTestBuilder().updateGraceOnPrincipal(null).updateGraceOnInterest(null)
|
||||
.updateExtraTerms(null).updateRescheduleFromDate("04 January 2015").updateAdjustedDueDate("04 October 2015")
|
||||
.updateRecalculateInterest(true).build(this.loanId.toString());
|
||||
|
||||
this.loanRescheduleRequestId = this.loanRescheduleRequestHelper.createLoanRescheduleRequest(requestJSON);
|
||||
this.loanRescheduleRequestHelper.verifyCreationOfLoanRescheduleRequest(this.loanRescheduleRequestId);
|
||||
|
||||
LOG.info("Successfully created loan reschedule request (ID: {} )", this.loanRescheduleRequestId);
|
||||
|
||||
final String aproveRequestJSON = new LoanRescheduleRequestTestBuilder().getApproveLoanRescheduleRequestJSON();
|
||||
this.loanRescheduleRequestHelper.approveLoanRescheduleRequest(this.loanRescheduleRequestId, aproveRequestJSON);
|
||||
final HashMap response = (HashMap) this.loanRescheduleRequestHelper.getLoanRescheduleRequest(loanRescheduleRequestId, "statusEnum");
|
||||
assertTrue((Boolean) response.get("approved"));
|
||||
|
||||
LOG.info("Successfully approved loan reschedule request (ID: {})", this.loanRescheduleRequestId);
|
||||
|
||||
final Map repaymentSchedule = (Map) this.loanTransactionHelper.getLoanDetail(requestSpec, generalResponseSpec, loanId,
|
||||
"repaymentSchedule");
|
||||
final ArrayList periods = (ArrayList) repaymentSchedule.get("periods");
|
||||
|
||||
HashMap period = (HashMap) periods.get(5);
|
||||
Float totalDueForPeriod = (Float) period.get("totalDueForPeriod");
|
||||
|
||||
final HashMap loanSummary = this.loanTransactionHelper.getLoanSummary(requestSpec, generalResponseSpec, loanId);
|
||||
final Float totalExpectedRepayment = (Float) loanSummary.get("totalExpectedRepayment");
|
||||
|
||||
assertEquals(12326, totalDueForPeriod.intValue(), "EXPECTED REPAYMENT is NOK");
|
||||
assertEquals(131512, totalExpectedRepayment.intValue(), "TOTAL EXPECTED REPAYMENT is NOK");
|
||||
|
||||
LOG.info("Successfully approved loan reschedule request (ID: {})", this.loanRescheduleRequestId);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateLoanRescheduleRequestForInterestAppropriationAndFixedEMI() {
|
||||
// create all required entities
|
||||
this.createRequiredEntities();
|
||||
this.createAndApproveLoanRescheduleRequestForInterestAppropriationAndFixedEMI();
|
||||
}
|
||||
|
||||
/**
|
||||
* create new loan reschedule request with combination of date change, interest appropriation and fixed emi
|
||||
**/
|
||||
private void createAndApproveLoanRescheduleRequestForInterestAppropriationAndFixedEMI() {
|
||||
LOG.info(
|
||||
"---------------------------------CREATING LOAN RESCHEDULE REQUEST FOR INTEREST APPROPRIATTION-------------------------------------");
|
||||
|
||||
final String requestJSON = new LoanRescheduleRequestTestBuilder().updateGraceOnPrincipal(null).updateGraceOnInterest(null)
|
||||
.updateExtraTerms(null).updateRescheduleFromDate("04 January 2015").updateAdjustedDueDate("04 July 2015").updateEMI("5000")
|
||||
.updateEmiChangeEndDate("4 September 2015").updateRecalculateInterest(true).build(this.loanId.toString());
|
||||
|
||||
this.loanRescheduleRequestId = this.loanRescheduleRequestHelper.createLoanRescheduleRequest(requestJSON);
|
||||
this.loanRescheduleRequestHelper.verifyCreationOfLoanRescheduleRequest(this.loanRescheduleRequestId);
|
||||
|
||||
LOG.info("Successfully created loan reschedule request (ID: {} )", this.loanRescheduleRequestId);
|
||||
|
||||
final String aproveRequestJSON = new LoanRescheduleRequestTestBuilder().getApproveLoanRescheduleRequestJSON();
|
||||
this.loanRescheduleRequestHelper.approveLoanRescheduleRequest(this.loanRescheduleRequestId, aproveRequestJSON);
|
||||
final HashMap response = (HashMap) this.loanRescheduleRequestHelper.getLoanRescheduleRequest(loanRescheduleRequestId, "statusEnum");
|
||||
assertTrue((Boolean) response.get("approved"));
|
||||
|
||||
LOG.info("Successfully approved loan reschedule request (ID: {})", this.loanRescheduleRequestId);
|
||||
|
||||
final Map repaymentSchedule = (Map) this.loanTransactionHelper.getLoanDetail(requestSpec, generalResponseSpec, loanId,
|
||||
"repaymentSchedule");
|
||||
final ArrayList periods = (ArrayList) repaymentSchedule.get("periods");
|
||||
|
||||
HashMap period = (HashMap) periods.get(5);
|
||||
Float totalFixedDueForPeriod = (Float) period.get("totalDueForPeriod");
|
||||
|
||||
HashMap period2 = (HashMap) periods.get(8);
|
||||
Float totalDueForPeriod = (Float) period2.get("totalDueForPeriod");
|
||||
|
||||
final HashMap loanSummary = this.loanTransactionHelper.getLoanSummary(requestSpec, generalResponseSpec, loanId);
|
||||
final Float totalExpectedRepayment = (Float) loanSummary.get("totalExpectedRepayment");
|
||||
|
||||
assertEquals(5000, totalFixedDueForPeriod.intValue(), "EXPECTED FIXED REPAYMENT is NOK");
|
||||
|
||||
assertEquals(15316, totalDueForPeriod.intValue(), "EXPECTED REPAYMENT is NOK");
|
||||
assertEquals(120806, totalExpectedRepayment.intValue(), "TOTAL EXPECTED REPAYMENT is NOK");
|
||||
|
||||
LOG.info("Successfully approved loan reschedule request (ID: {})", this.loanRescheduleRequestId);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateLoanRescheduleRequestWithMultpleInterestAppropriation() {
|
||||
// create all required entities
|
||||
this.createRequiredEntities();
|
||||
this.createAndApproveLoanRescheduleRequestForInterestAppropriation();
|
||||
|
||||
this.createAndApproveLoanRescheduleRequestForSecondInterestAppropriation();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* create new loan reschedule request
|
||||
**/
|
||||
private void createAndApproveLoanRescheduleRequestForSecondInterestAppropriation() {
|
||||
LOG.info(
|
||||
"---------------------------------CREATING LOAN RESCHEDULE REQUEST FOR INTEREST APPROPRIATTION-------------------------------------");
|
||||
|
||||
final String requestJSON = new LoanRescheduleRequestTestBuilder().updateGraceOnPrincipal(null).updateGraceOnInterest(null)
|
||||
.updateExtraTerms(null).updateRescheduleFromDate("04 December 2015").updateAdjustedDueDate("04 June 2016")
|
||||
.updateRecalculateInterest(true).build(this.loanId.toString());
|
||||
|
||||
this.loanRescheduleRequestId = this.loanRescheduleRequestHelper.createLoanRescheduleRequest(requestJSON);
|
||||
this.loanRescheduleRequestHelper.verifyCreationOfLoanRescheduleRequest(this.loanRescheduleRequestId);
|
||||
|
||||
LOG.info("Successfully created loan reschedule request (ID: {} )", this.loanRescheduleRequestId);
|
||||
|
||||
final String aproveRequestJSON = new LoanRescheduleRequestTestBuilder().getApproveLoanRescheduleRequestJSON();
|
||||
this.loanRescheduleRequestHelper.approveLoanRescheduleRequest(this.loanRescheduleRequestId, aproveRequestJSON);
|
||||
final HashMap response = (HashMap) this.loanRescheduleRequestHelper.getLoanRescheduleRequest(loanRescheduleRequestId, "statusEnum");
|
||||
assertTrue((Boolean) response.get("approved"));
|
||||
|
||||
LOG.info("Successfully approved loan reschedule request (ID: {})", this.loanRescheduleRequestId);
|
||||
|
||||
final Map repaymentSchedule = (Map) this.loanTransactionHelper.getLoanDetail(requestSpec, generalResponseSpec, loanId,
|
||||
"repaymentSchedule");
|
||||
final ArrayList periods = (ArrayList) repaymentSchedule.get("periods");
|
||||
|
||||
HashMap period = (HashMap) periods.get(7);
|
||||
Float totalDueForPeriod = (Float) period.get("totalDueForPeriod");
|
||||
|
||||
final HashMap loanSummary = this.loanTransactionHelper.getLoanSummary(requestSpec, generalResponseSpec, loanId);
|
||||
final Float totalExpectedRepayment = (Float) loanSummary.get("totalExpectedRepayment");
|
||||
|
||||
assertEquals(12187, totalDueForPeriod.intValue(), "EXPECTED REPAYMENT in Second Reschedule is NOK");
|
||||
assertEquals(130750, totalExpectedRepayment.intValue(), "TOTAL EXPECTED in Second Reschedule REPAYMENT is NOK");
|
||||
|
||||
LOG.info("Successfully approved loan reschedule request (ID: {})", this.loanRescheduleRequestId);
|
||||
}
|
||||
}
|
||||
+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;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
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.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Test the creation, approval and rejection of a loan reschedule request
|
||||
**/
|
||||
@SuppressWarnings({ "rawtypes" })
|
||||
public class LoanRescheduleRequestTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(LoanRescheduleRequestTest.class);
|
||||
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 final String loanPrincipalAmount = "100000.00";
|
||||
private final String numberOfRepayments = "12";
|
||||
private final String interestRatePerPeriod = "18";
|
||||
private final String dateString = "04 September 2014";
|
||||
|
||||
@BeforeEach
|
||||
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() {
|
||||
LOG.info("---------------------------------CREATING LOAN PRODUCT------------------------------------------");
|
||||
|
||||
final String loanProductJSON = new LoanProductTestBuilder().withPrincipal(loanPrincipalAmount)
|
||||
.withNumberOfRepayments(numberOfRepayments).withinterestRatePerPeriod(interestRatePerPeriod)
|
||||
.withInterestRateFrequencyTypeAsYear().build(null);
|
||||
|
||||
this.loanProductId = this.loanTransactionHelper.getLoanProductId(loanProductJSON);
|
||||
LOG.info("Successfully created loan product (ID:{}) ", this.loanProductId);
|
||||
}
|
||||
|
||||
/**
|
||||
* submit a new loan application, approve and disburse the loan
|
||||
**/
|
||||
private void createLoanEntity() {
|
||||
LOG.info("---------------------------------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);
|
||||
|
||||
LOG.info("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);
|
||||
LOG.info("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);
|
||||
LOG.info("Successfully disbursed loan (ID: {} )", this.loanId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* create new loan reschedule request
|
||||
**/
|
||||
private void createLoanRescheduleRequest() {
|
||||
LOG.info("---------------------------------CREATING LOAN RESCHEDULE REQUEST------------------------------------------");
|
||||
|
||||
final String requestJSON = new LoanRescheduleRequestTestBuilder().build(this.loanId.toString());
|
||||
|
||||
this.loanRescheduleRequestId = this.loanRescheduleRequestHelper.createLoanRescheduleRequest(requestJSON);
|
||||
this.loanRescheduleRequestHelper.verifyCreationOfLoanRescheduleRequest(this.loanRescheduleRequestId);
|
||||
|
||||
LOG.info("Successfully created loan reschedule request (ID: {} )", this.loanRescheduleRequestId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateLoanRescheduleRequest() {
|
||||
this.createLoanRescheduleRequest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRejectLoanRescheduleRequest() {
|
||||
this.createLoanRescheduleRequest();
|
||||
|
||||
LOG.info("-----------------------------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"));
|
||||
|
||||
LOG.info("Successfully rejected loan reschedule request (ID: {} )", this.loanRescheduleRequestId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApproveLoanRescheduleRequest() {
|
||||
this.createLoanRescheduleRequest();
|
||||
|
||||
LOG.info("-----------------------------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(12, numberOfRepayments, "NUMBER OF REPAYMENTS is NOK");
|
||||
assertEquals(118000, totalExpectedRepayment, "TOTAL EXPECTED REPAYMENT is NOK");
|
||||
|
||||
LOG.info("Successfully approved loan reschedule request (ID: {})", this.loanRescheduleRequestId);
|
||||
}
|
||||
|
||||
/**
|
||||
* create new loan reschedule request
|
||||
**/
|
||||
private void createLoanRescheduleChangeEMIRequest() {
|
||||
LOG.info("---------------------------------CREATING LOAN RESCHEDULE REQUEST CHANGE EMI------------------------------------------");
|
||||
|
||||
final String requestJSON = new LoanRescheduleRequestTestBuilder().updateGraceOnPrincipal(null).updateGraceOnInterest(null)
|
||||
.updateExtraTerms(null).updateEMI("5000").updateEmiChangeEndDate("4 February 2015")
|
||||
.updateRescheduleFromDate("04 January 2015").updateRecalculateInterest(true).build(this.loanId.toString());
|
||||
|
||||
this.loanRescheduleRequestId = this.loanRescheduleRequestHelper.createLoanRescheduleRequest(requestJSON);
|
||||
this.loanRescheduleRequestHelper.verifyCreationOfLoanRescheduleRequest(this.loanRescheduleRequestId);
|
||||
|
||||
LOG.info("Successfully created loan reschedule request (ID: {} )", this.loanRescheduleRequestId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateLoanRescheduleChangeEMIRequest() {
|
||||
this.createLoanRescheduleChangeEMIRequest();
|
||||
}
|
||||
}
|
||||
+405
@@ -0,0 +1,405 @@
|
||||
/**
|
||||
* 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.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.sql.Timestamp;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import org.apache.fineract.integrationtests.common.CalendarHelper;
|
||||
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.GlobalConfigurationHelper;
|
||||
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.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.apache.fineract.integrationtests.common.organisation.StaffHelper;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class LoanReschedulingWithinCenterTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(LoanReschedulingWithinCenterTest.class);
|
||||
private RequestSpecification requestSpec;
|
||||
private ResponseSpecification responseSpec;
|
||||
private LoanTransactionHelper loanTransactionHelper;
|
||||
private ResponseSpecification generalResponseSpec;
|
||||
private LoanApplicationApprovalTest loanApplicationApprovalTest;
|
||||
|
||||
@BeforeEach
|
||||
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();
|
||||
|
||||
GlobalConfigurationHelper.verifyAllDefaultGlobalConfigurations(this.requestSpec, this.responseSpec);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Test
|
||||
public void testCenterReschedulingLoansWithInterestRecalculationEnabled() {
|
||||
|
||||
Integer 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(1, officeId);
|
||||
final String centerActivationDate = "01 July 2007";
|
||||
Integer centerId = CenterHelper.createCenter(name, officeId, externalId, staffId, groupMembers, centerActivationDate, requestSpec,
|
||||
responseSpec);
|
||||
CenterDomain center = CenterHelper.retrieveByID(centerId, requestSpec, responseSpec);
|
||||
Integer groupId = groupMembers[0];
|
||||
Assertions.assertNotNull(center);
|
||||
Assertions.assertTrue(center.getStaffId() == staffId);
|
||||
Assertions.assertTrue(center.isActive() == true);
|
||||
|
||||
Integer calendarId = createCalendarMeeting(centerId);
|
||||
|
||||
Integer clientId = createClient(officeId);
|
||||
|
||||
associateClientsToGroup(groupId, clientId);
|
||||
|
||||
DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy");
|
||||
dateFormat.setTimeZone(Utils.getTimeZoneOfTenant());
|
||||
Calendar today = Calendar.getInstance(Utils.getTimeZoneOfTenant());
|
||||
today.add(Calendar.DAY_OF_MONTH, -14);
|
||||
// CREATE A LOAN PRODUCT
|
||||
final String disbursalDate = dateFormat.format(today.getTime());
|
||||
final String recalculationRestFrequencyDate = "01 January 2012";
|
||||
final boolean isMultiTrancheLoan = false;
|
||||
|
||||
// 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, isMultiTrancheLoan, null, null);
|
||||
|
||||
// APPLY FOR TRANCHE LOAN WITH INTEREST RECALCULATION
|
||||
final Integer loanId = applyForLoanApplicationForInterestRecalculation(clientId, groupId, calendarId, loanProductID, disbursalDate,
|
||||
recalculationRestFrequencyDate, LoanApplicationTestBuilder.RBI_INDIA_STRATEGY, new ArrayList<HashMap>(0), null);
|
||||
|
||||
// Test for loan account is created
|
||||
Assertions.assertNotNull(loanId);
|
||||
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanId);
|
||||
|
||||
// Test for loan account is created, can be approved
|
||||
this.loanTransactionHelper.approveLoan(disbursalDate, loanId);
|
||||
loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanId);
|
||||
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
|
||||
|
||||
// Test for loan account approved can be disbursed
|
||||
this.loanTransactionHelper.disburseLoan(disbursalDate, loanId);
|
||||
loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanId);
|
||||
LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
|
||||
|
||||
LOG.info("---------------------------------CHANGING GROUP MEETING DATE ------------------------------------------");
|
||||
Calendar todaysdate = Calendar.getInstance(Utils.getTimeZoneOfTenant());
|
||||
todaysdate.add(Calendar.DAY_OF_MONTH, 14);
|
||||
String oldMeetingDate = dateFormat.format(todaysdate.getTime());
|
||||
todaysdate.add(Calendar.DAY_OF_MONTH, 1);
|
||||
final String centerMeetingNewStartDate = dateFormat.format(todaysdate.getTime());
|
||||
CalendarHelper.updateMeetingCalendarForCenter(this.requestSpec, this.responseSpec, centerId, calendarId.toString(), oldMeetingDate,
|
||||
centerMeetingNewStartDate);
|
||||
|
||||
ArrayList loanRepaymnetSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(requestSpec, generalResponseSpec, loanId);
|
||||
// VERIFY RESCHEDULED DATE
|
||||
ArrayList dueDateLoanSchedule = (ArrayList) ((HashMap) loanRepaymnetSchedule.get(2)).get("dueDate");
|
||||
assertEquals(getDateAsArray(todaysdate, 0), dueDateLoanSchedule);
|
||||
|
||||
// VERIFY THE INTEREST
|
||||
Float interestDue = (Float) ((HashMap) loanRepaymnetSchedule.get(2)).get("interestDue");
|
||||
assertEquals("90.82", String.valueOf(interestDue));
|
||||
}
|
||||
|
||||
private void associateClientsToGroup(Integer groupId, Integer clientId) {
|
||||
// Associate client to the group
|
||||
GroupHelper.associateClient(this.requestSpec, this.responseSpec, groupId.toString(), clientId.toString());
|
||||
GroupHelper.verifyGroupMembers(this.requestSpec, this.responseSpec, groupId, clientId);
|
||||
}
|
||||
|
||||
private Integer createClient(Integer officeId) {
|
||||
// CREATE CLIENT
|
||||
final String clientActivationDate = "01 July 2014";
|
||||
Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec, clientActivationDate, officeId.toString());
|
||||
ClientHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, clientId);
|
||||
return clientId;
|
||||
}
|
||||
|
||||
private Integer createCalendarMeeting(Integer centerId) {
|
||||
DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy");
|
||||
dateFormat.setTimeZone(Utils.getTimeZoneOfTenant());
|
||||
Calendar today = Calendar.getInstance(Utils.getTimeZoneOfTenant());
|
||||
final String startDate = dateFormat.format(today.getTime());
|
||||
final String frequency = "2"; // 2:Weekly
|
||||
final String interval = "2"; // Every one week
|
||||
Integer repeatsOnDay = today.get(Calendar.DAY_OF_WEEK) - 1;
|
||||
|
||||
if (repeatsOnDay.intValue() == 0) {
|
||||
repeatsOnDay = 7;
|
||||
}
|
||||
|
||||
Integer calendarId = CalendarHelper.createMeetingForGroup(this.requestSpec, this.responseSpec, centerId, startDate, frequency,
|
||||
interval, repeatsOnDay.toString());
|
||||
LOG.info("calendarId {}", calendarId);
|
||||
return calendarId;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Test
|
||||
public void testCenterReschedulingMultiTrancheLoansWithInterestRecalculationEnabled() {
|
||||
|
||||
Integer 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(1, officeId);
|
||||
final String centerActivationDate = "01 July 2007";
|
||||
Integer centerId = CenterHelper.createCenter(name, officeId, externalId, staffId, groupMembers, centerActivationDate, requestSpec,
|
||||
responseSpec);
|
||||
CenterDomain center = CenterHelper.retrieveByID(centerId, requestSpec, responseSpec);
|
||||
Integer groupId = groupMembers[0];
|
||||
Assertions.assertNotNull(center);
|
||||
Assertions.assertTrue(center.getStaffId() == staffId);
|
||||
Assertions.assertTrue(center.isActive() == true);
|
||||
|
||||
Integer calendarId = createCalendarMeeting(centerId);
|
||||
|
||||
Integer clientId = createClient(officeId);
|
||||
|
||||
associateClientsToGroup(groupId, clientId);
|
||||
|
||||
// CREATE A LOAN PRODUCT
|
||||
DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy");
|
||||
dateFormat.setTimeZone(Utils.getTimeZoneOfTenant());
|
||||
Calendar today = Calendar.getInstance(Utils.getTimeZoneOfTenant());
|
||||
today.add(Calendar.DAY_OF_MONTH, -14);
|
||||
// CREATE A LOAN PRODUCT
|
||||
final String approveDate = dateFormat.format(today.getTime());
|
||||
final String expectedDisbursementDate = dateFormat.format(today.getTime());
|
||||
final String disbursementDate = dateFormat.format(today.getTime());
|
||||
final String approvalAmount = "10000";
|
||||
final String recalculationRestFrequencyDate = "01 January 2012";
|
||||
final boolean isMultiTrancheLoan = true;
|
||||
|
||||
// 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, isMultiTrancheLoan, null, null);
|
||||
|
||||
Calendar seondTrancheDate = Calendar.getInstance(Utils.getTimeZoneOfTenant());
|
||||
seondTrancheDate.add(Calendar.MONTH, 1);
|
||||
String secondDisbursement = dateFormat.format(seondTrancheDate.getTime());
|
||||
|
||||
// CREATE TRANCHES
|
||||
List<HashMap> createTranches = new ArrayList<>();
|
||||
createTranches.add(this.loanApplicationApprovalTest.createTrancheDetail(disbursementDate, "5000"));
|
||||
createTranches.add(this.loanApplicationApprovalTest.createTrancheDetail(secondDisbursement, "5000"));
|
||||
|
||||
// APPROVE TRANCHES
|
||||
List<HashMap> approveTranches = new ArrayList<>();
|
||||
approveTranches.add(this.loanApplicationApprovalTest.createTrancheDetail(disbursementDate, "5000"));
|
||||
approveTranches.add(this.loanApplicationApprovalTest.createTrancheDetail(secondDisbursement, "5000"));
|
||||
|
||||
// APPLY FOR TRANCHE LOAN WITH INTEREST RECALCULATION
|
||||
final Integer loanID = applyForLoanApplicationForInterestRecalculation(clientId, groupId, calendarId, 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);
|
||||
|
||||
LOG.info("-----------------------------------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.disburseLoan(disbursementDate, loanID);
|
||||
loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
|
||||
|
||||
LOG.info("---------------------------------CHANGING GROUP MEETING DATE ------------------------------------------");
|
||||
Calendar todaysdate = Calendar.getInstance(Utils.getTimeZoneOfTenant());
|
||||
todaysdate.add(Calendar.DAY_OF_MONTH, 14);
|
||||
String oldMeetingDate = dateFormat.format(todaysdate.getTime());
|
||||
todaysdate.add(Calendar.DAY_OF_MONTH, 1);
|
||||
final String centerMeetingNewStartDate = dateFormat.format(todaysdate.getTime());
|
||||
CalendarHelper.updateMeetingCalendarForCenter(this.requestSpec, this.responseSpec, centerId, calendarId.toString(), oldMeetingDate,
|
||||
centerMeetingNewStartDate);
|
||||
|
||||
ArrayList loanRepaymnetSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(requestSpec, generalResponseSpec, loanID);
|
||||
// VERIFY RESCHEDULED DATE
|
||||
ArrayList dueDateLoanSchedule = (ArrayList) ((HashMap) loanRepaymnetSchedule.get(2)).get("dueDate");
|
||||
assertEquals(getDateAsArray(todaysdate, 0), dueDateLoanSchedule);
|
||||
|
||||
// VERIFY THE INTEREST
|
||||
Float interestDue = (Float) ((HashMap) loanRepaymnetSchedule.get(2)).get("interestDue");
|
||||
assertEquals("41.05", String.valueOf(interestDue));
|
||||
}
|
||||
|
||||
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 boolean isMultiTrancheLoan, final Integer recalculationRestFrequencyOnDayType,
|
||||
final Integer recalculationRestFrequencyDayOfWeekType) {
|
||||
final String recalculationCompoundingFrequencyType = null;
|
||||
final String recalculationCompoundingFrequencyInterval = null;
|
||||
final String recalculationCompoundingFrequencyDate = null;
|
||||
final Integer recalculationCompoundingFrequencyOnDayType = null;
|
||||
final Integer recalculationCompoundingFrequencyDayOfWeekType = null;
|
||||
return createLoanProductWithInterestRecalculation(repaymentStrategy, interestRecalculationCompoundingMethod,
|
||||
rescheduleStrategyMethod, recalculationRestFrequencyType, recalculationRestFrequencyInterval,
|
||||
recalculationRestFrequencyDate, recalculationCompoundingFrequencyType, recalculationCompoundingFrequencyInterval,
|
||||
recalculationCompoundingFrequencyDate, preCloseInterestCalculationStrategy, accounts, null, false, isMultiTrancheLoan,
|
||||
recalculationCompoundingFrequencyOnDayType, recalculationCompoundingFrequencyDayOfWeekType,
|
||||
recalculationRestFrequencyOnDayType, recalculationRestFrequencyDayOfWeekType);
|
||||
}
|
||||
|
||||
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, final boolean isMultiTrancheLoan,
|
||||
final Integer recalculationCompoundingFrequencyOnDayType, final Integer recalculationCompoundingFrequencyDayOfWeekType,
|
||||
final Integer recalculationRestFrequencyOnDayType, final Integer recalculationRestFrequencyDayOfWeekType) {
|
||||
LOG.info("------------------------------CREATING NEW LOAN PRODUCT ---------------------------------------");
|
||||
LoanProductTestBuilder builder = new LoanProductTestBuilder().withPrincipal("10000.00").withNumberOfRepayments("12")
|
||||
.withRepaymentAfterEvery("2").withRepaymentTypeAsWeek().withinterestRatePerPeriod("2")
|
||||
.withInterestRateFrequencyTypeAsMonths().withTranches(isMultiTrancheLoan)
|
||||
.withInterestCalculationPeriodTypeAsRepaymentPeriod(true).withRepaymentStrategy(repaymentStrategy)
|
||||
.withInterestTypeAsDecliningBalance()
|
||||
.withInterestRecalculationDetails(interestRecalculationCompoundingMethod, rescheduleStrategyMethod,
|
||||
preCloseInterestCalculationStrategy)
|
||||
.withInterestRecalculationRestFrequencyDetails(recalculationRestFrequencyType, recalculationRestFrequencyInterval,
|
||||
recalculationRestFrequencyOnDayType, recalculationRestFrequencyDayOfWeekType)
|
||||
.withInterestRecalculationCompoundingFrequencyDetails(recalculationCompoundingFrequencyType,
|
||||
recalculationCompoundingFrequencyInterval, recalculationCompoundingFrequencyOnDayType,
|
||||
recalculationCompoundingFrequencyDayOfWeekType);
|
||||
if (accounts != null) {
|
||||
builder = builder.withAccountingRulePeriodicAccrual(accounts);
|
||||
}
|
||||
|
||||
if (isArrearsBasedOnOriginalSchedule) {
|
||||
builder = builder.withArrearsConfiguration();
|
||||
}
|
||||
|
||||
final String loanProductJSON = builder.build(chargeId);
|
||||
return this.loanTransactionHelper.getLoanProductId(loanProductJSON);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private Integer applyForLoanApplicationForInterestRecalculation(final Integer clientID, Integer groupId, Integer calendarId,
|
||||
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, groupId, calendarId, loanProductID, disbursementDate,
|
||||
restStartDate, compoundingStartDate, repaymentStrategy, charges, graceOnInterestPayment, graceOnPrincipalPayment, tranches);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unused" })
|
||||
private Integer applyForLoanApplicationForInterestRecalculation(final Integer clientID, Integer groupId, Integer calendarId,
|
||||
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) {
|
||||
LOG.info("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------");
|
||||
final String loanApplicationJSON = new LoanApplicationTestBuilder() //
|
||||
.withPrincipal("10000.00") //
|
||||
.withLoanTermFrequency("24") //
|
||||
.withLoanTermFrequencyAsWeeks() //
|
||||
.withNumberOfRepayments("12") //
|
||||
.withRepaymentEveryAfter("2") //
|
||||
.withRepaymentFrequencyTypeAsWeeks() //
|
||||
.withInterestRatePerPeriod("2").withLoanType("jlg") //
|
||||
.withCalendarID(calendarId.toString()).withAmortizationTypeAsEqualInstallments() //
|
||||
.withFixedEmiAmount("") //
|
||||
.withTranches(tranches).withInterestTypeAsDecliningBalance() //
|
||||
.withInterestCalculationPeriodTypeAsDays() //
|
||||
.withInterestCalculationPeriodTypeAsDays() //
|
||||
.withExpectedDisbursementDate(disbursementDate) //
|
||||
.withSubmittedOnDate(disbursementDate) //
|
||||
.withwithRepaymentStrategy(repaymentStrategy) //
|
||||
.withCharges(charges)//
|
||||
.build(clientID.toString(), groupId.toString(), loanProductID.toString(), null);
|
||||
return this.loanTransactionHelper.getLoanId(loanApplicationJSON);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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)));
|
||||
}
|
||||
|
||||
}
|
||||
+217
@@ -0,0 +1,217 @@
|
||||
/**
|
||||
* 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 io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
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.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Client Loan Integration Test for checking Loan Disbursement with Waive Interest and Write-Off.
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes" })
|
||||
public class LoanWithWaiveInterestAndWriteOffIntegrationTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(LoanWithWaiveInterestAndWriteOffIntegrationTest.class);
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
|
||||
private static final String LP_PRINCIPAL = "12,000.00";
|
||||
private static final String LP_REPAYMENTS = "2";
|
||||
private static final String LP_REPAYMENT_PERIOD = "6";
|
||||
private static final String LP_INTEREST_RATE = "1";
|
||||
private static final String PRINCIPAL = "4,500.00";
|
||||
private static final String LOAN_TERM_FREQUENCY = "18";
|
||||
private static final String NUMBER_OF_REPAYMENTS = "9";
|
||||
private static final String REPAYMENT_PERIOD = "2";
|
||||
private static final String DISBURSEMENT_DATE = "30 October 2010";
|
||||
private static final String LOAN_APPLICATION_SUBMISSION_DATE = "23 September 2010";
|
||||
private static final String EXPECTED_DISBURSAL_DATE = "28 October 2010";
|
||||
private static final String RATE_OF_INTEREST_PER_PERIOD = "2";
|
||||
private static final String DATE_OF_JOINING = "04 March 2009";
|
||||
private static final String INTEREST_VALUE_AMOUNT = "40.00";
|
||||
private LoanTransactionHelper loanTransactionHelper;
|
||||
|
||||
@BeforeEach
|
||||
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, 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);
|
||||
|
||||
LOG.info("-----------------------------------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);
|
||||
|
||||
LOG.info("-----------------------------------RE-APPROVE LOAN-----------------------------------------");
|
||||
loanStatusHashMap = this.loanTransactionHelper.approveLoan("01 October 2010", loanID);
|
||||
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
|
||||
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
|
||||
|
||||
// DISBURSE
|
||||
loanStatusHashMap = this.loanTransactionHelper.disburseLoan(DISBURSEMENT_DATE, loanID);
|
||||
LOG.info("DISBURSE {}", loanStatusHashMap.toString());
|
||||
LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
|
||||
|
||||
// PERFORM REPAYMENTS AND CHECK LOAN STATUS
|
||||
this.loanTransactionHelper.verifyRepaymentScheduleEntryFor(1, 4000.0F, loanID);
|
||||
this.loanTransactionHelper.makeRepayment("01 January 2011", 540.0f, loanID);
|
||||
|
||||
// UNDO DISBURSE LOAN
|
||||
loanStatusHashMap = this.loanTransactionHelper.undoDisbursal(loanID);
|
||||
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
|
||||
|
||||
// DIBURSE AGAIN
|
||||
loanStatusHashMap = this.loanTransactionHelper.disburseLoan(DISBURSEMENT_DATE, loanID);
|
||||
LOG.info("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("01 January 2011", repayment_with_interest, loanID);
|
||||
this.loanTransactionHelper.makeRepayment("01 March 2011", repayment_with_interest, loanID);
|
||||
this.loanTransactionHelper.waiveInterest("01 May 2011", INTEREST_VALUE_AMOUNT, loanID);
|
||||
this.loanTransactionHelper.makeRepayment("01 May 2011", repayment_without_interest, loanID);
|
||||
this.loanTransactionHelper.makeRepayment("01 July 2011", repayment_with_interest, loanID);
|
||||
this.loanTransactionHelper.waiveInterest("01 September 2011", INTEREST_VALUE_AMOUNT, loanID);
|
||||
this.loanTransactionHelper.makeRepayment("01 September 2011", repayment_without_interest, loanID);
|
||||
this.loanTransactionHelper.makeRepayment("01 November 2011", repayment_with_interest, loanID);
|
||||
this.loanTransactionHelper.waiveInterest("01 January 2012", INTEREST_VALUE_AMOUNT, loanID);
|
||||
this.loanTransactionHelper.makeRepayment("01 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("01 March 2012", loanID));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkClientLoan_WRITTEN_OFF() {
|
||||
// CREATE CLIENT
|
||||
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, 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);
|
||||
|
||||
LOG.info("-----------------------------------APPROVE LOAN-----------------------------------------");
|
||||
loanStatusHashMap = this.loanTransactionHelper.approveLoan("28 September 2010", loanID);
|
||||
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
|
||||
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
|
||||
|
||||
// DISBURSE
|
||||
loanStatusHashMap = this.loanTransactionHelper.disburseLoan(DISBURSEMENT_DATE, loanID);
|
||||
LOG.info("DISBURSE {}", loanStatusHashMap);
|
||||
LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
|
||||
|
||||
// MAKE REPAYMENTS
|
||||
final float repayment_with_interest = 680.0f;
|
||||
|
||||
this.loanTransactionHelper.verifyRepaymentScheduleEntryFor(1, 4000.0F, loanID);
|
||||
this.loanTransactionHelper.makeRepayment("01 January 2011", repayment_with_interest, loanID);
|
||||
|
||||
HashMap toLoanSummaryAfter = this.loanTransactionHelper.getLoanSummary(requestSpec, responseSpec, loanID);
|
||||
Assertions.assertTrue(Float.valueOf("500.0").compareTo(Float.valueOf(String.valueOf(toLoanSummaryAfter.get("principalPaid")))) == 0,
|
||||
"Checking for Principal paid ");
|
||||
Assertions.assertTrue(Float.valueOf("180.0").compareTo(Float.valueOf(String.valueOf(toLoanSummaryAfter.get("interestPaid")))) == 0,
|
||||
"Checking for interestPaid paid ");
|
||||
Assertions.assertTrue(
|
||||
Float.valueOf("680.0").compareTo(Float.valueOf(String.valueOf(toLoanSummaryAfter.get("totalRepayment")))) == 0,
|
||||
"Checking for total paid ");
|
||||
|
||||
// WRITE OFF LOAN AND CHECK ACCOUNT IS CLOSED
|
||||
LoanStatusChecker.verifyLoanAccountIsClosed(this.loanTransactionHelper.writeOffLoan("01 January 2011", loanID));
|
||||
toLoanSummaryAfter = this.loanTransactionHelper.getLoanSummary(requestSpec, responseSpec, loanID);
|
||||
Assertions.assertTrue(
|
||||
Float.valueOf("4000.0").compareTo(Float.valueOf(String.valueOf(toLoanSummaryAfter.get("principalWrittenOff")))) == 0,
|
||||
"Checking for Principal written off ");
|
||||
Assertions.assertTrue(
|
||||
Float.valueOf("1440.0").compareTo(Float.valueOf(String.valueOf(toLoanSummaryAfter.get("interestWrittenOff")))) == 0,
|
||||
"Checking for interestPaid written off ");
|
||||
Assertions.assertTrue(
|
||||
Float.valueOf("5440.0").compareTo(Float.valueOf(String.valueOf(toLoanSummaryAfter.get("totalWrittenOff")))) == 0,
|
||||
"Checking for total written off ");
|
||||
|
||||
}
|
||||
|
||||
private Integer createLoanProduct() {
|
||||
LOG.info("------------------------------CREATING NEW LOAN PRODUCT ---------------------------------------");
|
||||
final String loanProductJSON = new LoanProductTestBuilder().withPrincipal(LP_PRINCIPAL).withRepaymentTypeAsMonth()
|
||||
.withRepaymentAfterEvery(LP_REPAYMENT_PERIOD).withNumberOfRepayments(LP_REPAYMENTS).withRepaymentTypeAsMonth()
|
||||
.withinterestRatePerPeriod(LP_INTEREST_RATE).withInterestRateFrequencyTypeAsMonths()
|
||||
.withAmortizationTypeAsEqualPrincipalPayment().withInterestTypeAsFlat().build(null);
|
||||
|
||||
return this.loanTransactionHelper.getLoanProductId(loanProductJSON);
|
||||
}
|
||||
|
||||
private Integer applyForLoanApplication(final Integer clientID, final Integer loanProductID) {
|
||||
LOG.info("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------");
|
||||
final String loanApplicationJSON = new LoanApplicationTestBuilder().withPrincipal(PRINCIPAL)
|
||||
.withLoanTermFrequency(LOAN_TERM_FREQUENCY).withLoanTermFrequencyAsMonths().withNumberOfRepayments(NUMBER_OF_REPAYMENTS)
|
||||
.withRepaymentEveryAfter(REPAYMENT_PERIOD).withRepaymentFrequencyTypeAsMonths()
|
||||
.withInterestRatePerPeriod(RATE_OF_INTEREST_PER_PERIOD).withInterestTypeAsFlatBalance()
|
||||
.withAmortizationTypeAsEqualInstallments().withInterestCalculationPeriodTypeSameAsRepaymentPeriod()
|
||||
.withExpectedDisbursementDate(EXPECTED_DISBURSAL_DATE).withSubmittedOnDate(LOAN_APPLICATION_SUBMISSION_DATE)
|
||||
.build(clientID.toString(), loanProductID.toString(), null);
|
||||
return this.loanTransactionHelper.getLoanId(loanApplicationJSON);
|
||||
}
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* 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 io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
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.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class LoanWithdrawnByApplicantIntegrationTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private LoanTransactionHelper loanTransactionHelper;
|
||||
|
||||
@BeforeEach
|
||||
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);
|
||||
}
|
||||
}
|
||||
+216
@@ -0,0 +1,216 @@
|
||||
/**
|
||||
* 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.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
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.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* 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 = "01 August 2014";
|
||||
|
||||
@BeforeEach
|
||||
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 = "04 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
|
||||
Assertions.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 = "04 September 2014";
|
||||
final String firstRepaymentDate = "05 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,324 @@
|
||||
/**
|
||||
* 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 io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.util.HashMap;
|
||||
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||
import org.apache.fineract.integrationtests.common.GroupHelper;
|
||||
import org.apache.fineract.integrationtests.common.NotesHelper;
|
||||
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.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@SuppressWarnings({ "rawtypes" })
|
||||
public class NotesTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private ResponseSpecification responseSpec404;
|
||||
private LoanTransactionHelper loanTransactionHelper;
|
||||
|
||||
@BeforeEach
|
||||
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.responseSpec404 = new ResponseSpecBuilder().expectStatusCode(404).build();
|
||||
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateClientNote() {
|
||||
String noteText = "this is a test note";
|
||||
|
||||
Integer clientId = ClientHelper.createClient(requestSpec, responseSpec);
|
||||
Assertions.assertNotNull(clientId);
|
||||
|
||||
String request = "{\"note\": \"" + noteText + "\"}";
|
||||
Integer noteId = NotesHelper.createClientNote(requestSpec, responseSpec, clientId, request);
|
||||
Assertions.assertNotNull(noteId);
|
||||
|
||||
String receivedNoteText = NotesHelper.getClientNote(requestSpec, responseSpec, clientId, noteId);
|
||||
Assertions.assertEquals(noteText, receivedNoteText);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateClientNote() {
|
||||
String noteText = "this is a test note";
|
||||
|
||||
Integer clientId = ClientHelper.createClient(requestSpec, responseSpec);
|
||||
Assertions.assertNotNull(clientId);
|
||||
|
||||
String request = "{\"note\": \"" + noteText + "\"}";
|
||||
Integer noteId = NotesHelper.createClientNote(requestSpec, responseSpec, clientId, request);
|
||||
Assertions.assertNotNull(noteId);
|
||||
|
||||
String receivedNoteText = NotesHelper.getClientNote(requestSpec, responseSpec, clientId, noteId);
|
||||
Assertions.assertEquals(noteText, receivedNoteText);
|
||||
|
||||
String updatedNoteText = "this is an updated test note";
|
||||
|
||||
String updateRequest = "{\"note\": \"" + updatedNoteText + "\"}";
|
||||
NotesHelper.updateClientNote(requestSpec, responseSpec, clientId, noteId, updateRequest);
|
||||
|
||||
receivedNoteText = NotesHelper.getClientNote(requestSpec, responseSpec, clientId, noteId);
|
||||
Assertions.assertEquals(updatedNoteText, receivedNoteText);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteClientNote() {
|
||||
String noteText = "this is a test note";
|
||||
|
||||
Integer clientId = ClientHelper.createClient(requestSpec, responseSpec);
|
||||
Assertions.assertNotNull(clientId);
|
||||
|
||||
String request = "{\"note\": \"" + noteText + "\"}";
|
||||
Integer noteId = NotesHelper.createClientNote(requestSpec, responseSpec, clientId, request);
|
||||
Assertions.assertNotNull(noteId);
|
||||
|
||||
String receivedNoteText = NotesHelper.getClientNote(requestSpec, responseSpec, clientId, noteId);
|
||||
Assertions.assertEquals(noteText, receivedNoteText);
|
||||
|
||||
NotesHelper.deleteClientNote(requestSpec, responseSpec, clientId, noteId);
|
||||
|
||||
NotesHelper.getClientNote(requestSpec, responseSpec404, clientId, noteId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateGroupNote() {
|
||||
String noteText = "this is a test group note";
|
||||
|
||||
Integer groupId = GroupHelper.createGroup(requestSpec, responseSpec);
|
||||
Assertions.assertNotNull(groupId);
|
||||
|
||||
String request = "{\"note\": \"" + noteText + "\"}";
|
||||
Integer noteId = NotesHelper.createGroupNote(requestSpec, responseSpec, groupId, request);
|
||||
Assertions.assertNotNull(noteId);
|
||||
|
||||
String receivedNoteText = NotesHelper.getGroupNote(requestSpec, responseSpec, groupId, noteId);
|
||||
Assertions.assertEquals(noteText, receivedNoteText);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateGroupNote() {
|
||||
String noteText = "this is a test group note";
|
||||
|
||||
Integer groupId = GroupHelper.createGroup(requestSpec, responseSpec);
|
||||
Assertions.assertNotNull(groupId);
|
||||
|
||||
String request = "{\"note\": \"" + noteText + "\"}";
|
||||
Integer noteId = NotesHelper.createGroupNote(requestSpec, responseSpec, groupId, request);
|
||||
Assertions.assertNotNull(noteId);
|
||||
|
||||
String receivedNoteText = NotesHelper.getGroupNote(requestSpec, responseSpec, groupId, noteId);
|
||||
Assertions.assertEquals(noteText, receivedNoteText);
|
||||
|
||||
String updatedNoteText = "this is an updated test group note";
|
||||
|
||||
String updateRequest = "{\"note\": \"" + updatedNoteText + "\"}";
|
||||
NotesHelper.updateGroupNote(requestSpec, responseSpec, groupId, noteId, updateRequest);
|
||||
|
||||
receivedNoteText = NotesHelper.getGroupNote(requestSpec, responseSpec, groupId, noteId);
|
||||
Assertions.assertEquals(updatedNoteText, receivedNoteText);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteGroupNote() {
|
||||
String noteText = "this is a test group note";
|
||||
|
||||
Integer groupId = GroupHelper.createGroup(requestSpec, responseSpec);
|
||||
Assertions.assertNotNull(groupId);
|
||||
|
||||
String request = "{\"note\": \"" + noteText + "\"}";
|
||||
Integer noteId = NotesHelper.createGroupNote(requestSpec, responseSpec, groupId, request);
|
||||
Assertions.assertNotNull(noteId);
|
||||
|
||||
String receivedNoteText = NotesHelper.getGroupNote(requestSpec, responseSpec, groupId, noteId);
|
||||
Assertions.assertEquals(noteText, receivedNoteText);
|
||||
|
||||
NotesHelper.deleteGroupNote(requestSpec, responseSpec, groupId, noteId);
|
||||
|
||||
NotesHelper.getGroupNote(requestSpec, responseSpec404, groupId, noteId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateLoanNote() {
|
||||
String noteText = "this is a test loan note";
|
||||
|
||||
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);
|
||||
Assertions.assertNotNull(loanId);
|
||||
|
||||
String request = "{\"note\": \"" + noteText + "\"}";
|
||||
Integer noteId = NotesHelper.createLoanNote(requestSpec, responseSpec, loanId, request);
|
||||
Assertions.assertNotNull(noteId);
|
||||
|
||||
String receivedNoteText = NotesHelper.getLoanNote(requestSpec, responseSpec, loanId, noteId);
|
||||
Assertions.assertEquals(noteText, receivedNoteText);
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateLoanNote() {
|
||||
String noteText = "this is a test loan note";
|
||||
|
||||
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);
|
||||
Assertions.assertNotNull(loanId);
|
||||
|
||||
String request = "{\"note\": \"" + noteText + "\"}";
|
||||
Integer noteId = NotesHelper.createLoanNote(requestSpec, responseSpec, loanId, request);
|
||||
Assertions.assertNotNull(noteId);
|
||||
|
||||
String receivedNoteText = NotesHelper.getLoanNote(requestSpec, responseSpec, loanId, noteId);
|
||||
Assertions.assertEquals(noteText, receivedNoteText);
|
||||
|
||||
String updatedNoteText = "this is an updated test loan note";
|
||||
|
||||
String updateRequest = "{\"note\": \"" + updatedNoteText + "\"}";
|
||||
NotesHelper.updateLoanNote(requestSpec, responseSpec, loanId, noteId, updateRequest);
|
||||
|
||||
receivedNoteText = NotesHelper.getLoanNote(requestSpec, responseSpec, loanId, noteId);
|
||||
Assertions.assertEquals(updatedNoteText, receivedNoteText);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteLoanNote() {
|
||||
String noteText = "this is a test loan note";
|
||||
|
||||
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);
|
||||
Assertions.assertNotNull(loanId);
|
||||
|
||||
String request = "{\"note\": \"" + noteText + "\"}";
|
||||
Integer noteId = NotesHelper.createLoanNote(requestSpec, responseSpec, loanId, request);
|
||||
Assertions.assertNotNull(noteId);
|
||||
|
||||
String receivedNoteText = NotesHelper.getLoanNote(requestSpec, responseSpec, loanId, noteId);
|
||||
Assertions.assertEquals(noteText, receivedNoteText);
|
||||
|
||||
NotesHelper.deleteLoanNote(requestSpec, responseSpec, loanId, noteId);
|
||||
|
||||
NotesHelper.getLoanNote(requestSpec, responseSpec404, loanId, noteId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateLoanTransactionNote() {
|
||||
String noteText = "this is a test loan transaction note";
|
||||
|
||||
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);
|
||||
Assertions.assertNotNull(loanId);
|
||||
|
||||
this.loanTransactionHelper.approveLoan("02 April 2012", loanId);
|
||||
this.loanTransactionHelper.disburseLoan("02 April 2012", loanId);
|
||||
HashMap repayment = this.loanTransactionHelper.makeRepayment("02 April 2012", 100.0f, loanId);
|
||||
Integer loanTransactionId = (Integer) repayment.get("resourceId");
|
||||
Assertions.assertNotNull(loanTransactionId);
|
||||
|
||||
String request = "{\"note\": \"" + noteText + "\"}";
|
||||
Integer noteId = NotesHelper.createLoanTransactionNote(requestSpec, responseSpec, loanTransactionId, request);
|
||||
Assertions.assertNotNull(noteId);
|
||||
|
||||
String receivedNoteText = NotesHelper.getLoanTransactionNote(requestSpec, responseSpec, loanTransactionId, noteId);
|
||||
Assertions.assertEquals(noteText, receivedNoteText);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateLoanTransactionNote() {
|
||||
String noteText = "this is a test loan transaction note";
|
||||
|
||||
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);
|
||||
Assertions.assertNotNull(loanId);
|
||||
|
||||
this.loanTransactionHelper.approveLoan("02 April 2012", loanId);
|
||||
this.loanTransactionHelper.disburseLoan("02 April 2012", loanId);
|
||||
HashMap repayment = this.loanTransactionHelper.makeRepayment("02 April 2012", 100.0f, loanId);
|
||||
Integer loanTransactionId = (Integer) repayment.get("resourceId");
|
||||
Assertions.assertNotNull(loanTransactionId);
|
||||
|
||||
String request = "{\"note\": \"" + noteText + "\"}";
|
||||
Integer noteId = NotesHelper.createLoanTransactionNote(requestSpec, responseSpec, loanTransactionId, request);
|
||||
Assertions.assertNotNull(noteId);
|
||||
|
||||
String receivedNoteText = NotesHelper.getLoanTransactionNote(requestSpec, responseSpec, loanTransactionId, noteId);
|
||||
Assertions.assertEquals(noteText, receivedNoteText);
|
||||
|
||||
String updatedNoteText = "this is an updated test loan transaction note";
|
||||
|
||||
String updateRequest = "{\"note\": \"" + updatedNoteText + "\"}";
|
||||
NotesHelper.updateLoanTransactionNote(requestSpec, responseSpec, loanTransactionId, noteId, updateRequest);
|
||||
|
||||
receivedNoteText = NotesHelper.getLoanTransactionNote(requestSpec, responseSpec, loanTransactionId, noteId);
|
||||
Assertions.assertEquals(updatedNoteText, receivedNoteText);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteLoanTransactionNote() {
|
||||
String noteText = "this is a test loan transaction note";
|
||||
|
||||
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);
|
||||
Assertions.assertNotNull(loanId);
|
||||
|
||||
this.loanTransactionHelper.approveLoan("02 April 2012", loanId);
|
||||
this.loanTransactionHelper.disburseLoan("02 April 2012", loanId);
|
||||
HashMap repayment = this.loanTransactionHelper.makeRepayment("02 April 2012", 100.0f, loanId);
|
||||
Integer loanTransactionId = (Integer) repayment.get("resourceId");
|
||||
Assertions.assertNotNull(loanTransactionId);
|
||||
|
||||
String request = "{\"note\": \"" + noteText + "\"}";
|
||||
Integer noteId = NotesHelper.createLoanTransactionNote(requestSpec, responseSpec, loanTransactionId, request);
|
||||
Assertions.assertNotNull(noteId);
|
||||
|
||||
String receivedNoteText = NotesHelper.getLoanTransactionNote(requestSpec, responseSpec, loanTransactionId, noteId);
|
||||
Assertions.assertEquals(noteText, receivedNoteText);
|
||||
|
||||
NotesHelper.deleteLoanTransactionNote(requestSpec, responseSpec, loanTransactionId, noteId);
|
||||
|
||||
NotesHelper.getLoanTransactionNote(requestSpec, responseSpec404, loanTransactionId, noteId);
|
||||
}
|
||||
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* 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 io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.util.HashMap;
|
||||
import org.apache.fineract.integrationtests.common.NotificationHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class NotificationApiTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(NotificationApiTest.class);
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
|
||||
@BeforeEach
|
||||
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
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testNotificationRetrieval() {
|
||||
HashMap<String, Object> response = (HashMap<String, Object>) NotificationHelper.getNotifications(this.requestSpec,
|
||||
this.responseSpec, "");
|
||||
LOG.info("Response : {}", response.toString());
|
||||
Assertions.assertNotNull(response);
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* 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 io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import org.apache.fineract.integrationtests.common.OfficeDomain;
|
||||
import org.apache.fineract.integrationtests.common.OfficeHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class OfficeIntegrationTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
|
||||
@BeforeEach
|
||||
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);
|
||||
|
||||
Assertions.assertTrue(name.equals(newOffice.getName()));
|
||||
Assertions.assertArrayEquals(dateArr, newOffice.getOpeningDate());
|
||||
}
|
||||
}
|
||||
+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;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
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.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public class PasswordPreferencesIntegrationTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(PasswordPreferencesIntegrationTest.class);
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private ResponseSpecification generalResponseSpec;
|
||||
|
||||
@BeforeEach
|
||||
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());
|
||||
LOG.info("---------------------------------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("error.msg.password.validation.policy.id.invalid", error.get(0).get("userMessageGlobalisationCode"),
|
||||
"Password Validation Policy with identifier 2000 does not exist");
|
||||
}
|
||||
|
||||
}
|
||||
+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;
|
||||
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
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.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class PaymentTypeIntegrationTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
|
||||
@BeforeEach
|
||||
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);
|
||||
Assertions.assertNotNull(paymentTypeId);
|
||||
PaymentTypeHelper.verifyPaymentTypeCreatedOnServer(requestSpec, responseSpec, paymentTypeId);
|
||||
PaymentTypeDomain paymentTypeResponse = PaymentTypeHelper.retrieveById(requestSpec, responseSpec, paymentTypeId);
|
||||
Assertions.assertEquals(name, paymentTypeResponse.getName());
|
||||
Assertions.assertEquals(description, paymentTypeResponse.getDescription());
|
||||
Assertions.assertEquals(isCashPayment, paymentTypeResponse.getIsCashPayment());
|
||||
Assertions.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);
|
||||
Assertions.assertEquals(newName, paymentTypeUpdatedResponse.getName());
|
||||
Assertions.assertEquals(newDescription, paymentTypeUpdatedResponse.getDescription());
|
||||
Assertions.assertEquals(isCashPaymentUpdatedValue, paymentTypeUpdatedResponse.getIsCashPayment());
|
||||
Assertions.assertEquals(newPosition, paymentTypeUpdatedResponse.getPosition());
|
||||
|
||||
// Delete
|
||||
Integer deletedPaymentTypeId = PaymentTypeHelper.deletePaymentType(paymentTypeId, requestSpec, responseSpec);
|
||||
Assertions.assertEquals(paymentTypeId, deletedPaymentTypeId);
|
||||
ResponseSpecification responseSpecification = new ResponseSpecBuilder().expectStatusCode(404).build();
|
||||
PaymentTypeHelper.retrieveById(requestSpec, responseSpecification, paymentTypeId);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* 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 io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.rates.RatesHelper;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@SuppressWarnings({ "rawtypes" })
|
||||
public class RatesTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
|
||||
@BeforeEach
|
||||
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 testRatesForLoans() {
|
||||
|
||||
// Retrieving all Rates
|
||||
ArrayList<HashMap> allRatesData = RatesHelper.getRates(this.requestSpec, this.responseSpec);
|
||||
Assertions.assertNotNull(allRatesData);
|
||||
|
||||
// Testing Creation and Update of Loan Rate
|
||||
final Integer loanRateId = RatesHelper.createRates(this.requestSpec, this.responseSpec, RatesHelper.getLoanRateJSON());
|
||||
Assertions.assertNotNull(loanRateId);
|
||||
|
||||
// Update Rate percentage
|
||||
HashMap changes = RatesHelper.updateRates(this.requestSpec, this.responseSpec, loanRateId, RatesHelper.getModifyRateJSON());
|
||||
|
||||
HashMap rateDataAfterChanges = RatesHelper.getRateById(this.requestSpec, this.responseSpec, loanRateId);
|
||||
Assertions.assertEquals(rateDataAfterChanges.get("percentage"), changes.get("percentage"), "Verifying Rate after modification");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+3163
File diff suppressed because it is too large
Load Diff
@@ -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;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
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.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class RolesTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(RolesTest.class);
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
|
||||
@BeforeEach
|
||||
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() {
|
||||
|
||||
LOG.info("---------------------------------CREATING A ROLE---------------------------------------------");
|
||||
final Integer roleId = RolesHelper.createRole(this.requestSpec, this.responseSpec);
|
||||
Assertions.assertNotNull(roleId);
|
||||
|
||||
LOG.info("--------------------------------- Getting ROLE -------------------------------");
|
||||
HashMap<String, Object> role = RolesHelper.getRoleDetails(requestSpec, responseSpec, roleId);
|
||||
assertEquals((Integer) role.get("id"), roleId);
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("cast")
|
||||
@Test
|
||||
public void testDisableRolesStatus() {
|
||||
|
||||
LOG.info("---------------------------------CREATING A ROLE---------------------------------------------");
|
||||
final Integer roleId = RolesHelper.createRole(this.requestSpec, this.responseSpec);
|
||||
Assertions.assertNotNull(roleId);
|
||||
|
||||
LOG.info("--------------------------------- Getting ROLE -------------------------------");
|
||||
HashMap<String, Object> role = RolesHelper.getRoleDetails(requestSpec, responseSpec, roleId);
|
||||
assertEquals((Integer) role.get("id"), roleId);
|
||||
|
||||
LOG.info("--------------------------------- 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(true, (Boolean) role.get("disabled"));
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("cast")
|
||||
@Test
|
||||
public void testEnableRolesStatus() {
|
||||
|
||||
LOG.info("---------------------------------CREATING A ROLE---------------------------------------------");
|
||||
final Integer roleId = RolesHelper.createRole(this.requestSpec, this.responseSpec);
|
||||
Assertions.assertNotNull(roleId);
|
||||
|
||||
LOG.info("--------------------------------- Getting ROLE -------------------------------");
|
||||
HashMap<String, Object> role = RolesHelper.getRoleDetails(requestSpec, responseSpec, roleId);
|
||||
assertEquals((Integer) role.get("id"), roleId);
|
||||
|
||||
LOG.info("--------------------------------- 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(true, (Boolean) role.get("disabled"));
|
||||
|
||||
LOG.info("--------------------------------- 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(false, (Boolean) role.get("disabled"));
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("cast")
|
||||
@Test
|
||||
public void testDeleteRoleStatus() {
|
||||
|
||||
LOG.info("-------------------------------- CREATING A ROLE---------------------------------------------");
|
||||
final Integer roleId = RolesHelper.createRole(this.requestSpec, this.responseSpec);
|
||||
Assertions.assertNotNull(roleId);
|
||||
|
||||
LOG.info("--------------------------------- Getting ROLE -------------------------------");
|
||||
HashMap<String, Object> role = RolesHelper.getRoleDetails(requestSpec, responseSpec, roleId);
|
||||
assertEquals((Integer) role.get("id"), roleId);
|
||||
|
||||
LOG.info("--------------------------------- 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);
|
||||
Assertions.assertNotNull(roleId);
|
||||
|
||||
final Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
|
||||
Assertions.assertNotNull(staffId);
|
||||
|
||||
final Integer userId = UserHelper.createUser(this.requestSpec, this.responseSpec, roleId, staffId);
|
||||
Assertions.assertNotNull(userId);
|
||||
|
||||
final Integer deletedUserId = UserHelper.deleteUser(this.requestSpec, this.responseSpec, userId);
|
||||
Assertions.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);
|
||||
Assertions.assertNotNull(roleId);
|
||||
|
||||
final Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
|
||||
Assertions.assertNotNull(staffId);
|
||||
|
||||
final Integer userId = UserHelper.createUser(this.requestSpec, this.responseSpec, roleId, staffId);
|
||||
Assertions.assertNotNull(userId);
|
||||
|
||||
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(403).build();
|
||||
final Integer deletedRoleId = RolesHelper.deleteRole(this.requestSpec, this.responseSpec, roleId);
|
||||
assertNotEquals(deletedRoleId, roleId);
|
||||
}
|
||||
|
||||
}
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
/**
|
||||
* 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.awaitility.Awaitility.await;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.apache.fineract.infrastructure.jobs.service.JobName;
|
||||
import org.apache.fineract.integrationtests.common.SchedulerJobHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class SchedulerJobsTest {
|
||||
|
||||
private RequestSpecification requestSpec;
|
||||
private SchedulerJobHelper schedulerJobHelper;
|
||||
private Boolean originalSchedulerStatus;
|
||||
private final Map<Integer, Boolean> originalJobStatus = new HashMap<>();
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
Utils.initializeRESTAssured();
|
||||
requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
|
||||
requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
|
||||
requestSpec.header("Fineract-Platform-TenantId", "default");
|
||||
schedulerJobHelper = new SchedulerJobHelper(requestSpec);
|
||||
originalSchedulerStatus = schedulerJobHelper.getSchedulerStatus();
|
||||
for (Integer jobId : schedulerJobHelper.getAllSchedulerJobIds()) {
|
||||
Map<String, Object> schedulerJob = schedulerJobHelper.getSchedulerJobById(jobId);
|
||||
Boolean active = (Boolean) schedulerJob.get("active");
|
||||
originalJobStatus.put(jobId, active);
|
||||
}
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
schedulerJobHelper.updateSchedulerStatus(originalSchedulerStatus);
|
||||
for (int jobId = 1; jobId < JobName.values().length; jobId++) {
|
||||
schedulerJobHelper.updateSchedulerJob(jobId, originalJobStatus.get(jobId));
|
||||
}
|
||||
}
|
||||
|
||||
@Test // FINERACT-926
|
||||
public void testDateFormat() {
|
||||
// must start scheduler and make job active to have nextRunTime (which
|
||||
// is a
|
||||
// java.util.Date)
|
||||
schedulerJobHelper.updateSchedulerStatus(true);
|
||||
schedulerJobHelper.updateSchedulerJob(1, true);
|
||||
String nextRunTimeText = await().until(() -> (String) schedulerJobHelper.getSchedulerJobById(1).get("nextRunTime"),
|
||||
nextRunTime -> nextRunTime != null);
|
||||
DateTimeFormatter.ISO_INSTANT.parse(nextRunTimeText);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // TODO FINERACT-1167
|
||||
public void testFlippingSchedulerStatus() throws InterruptedException {
|
||||
// Retrieving Status of Scheduler
|
||||
Boolean schedulerStatus = schedulerJobHelper.getSchedulerStatus();
|
||||
if (schedulerStatus == true) {
|
||||
schedulerJobHelper.updateSchedulerStatus(false);
|
||||
schedulerStatus = schedulerJobHelper.getSchedulerStatus();
|
||||
// Verifying Status of the Scheduler after stopping
|
||||
assertEquals(false, schedulerStatus, "Verifying Scheduler Job Status");
|
||||
} else {
|
||||
schedulerJobHelper.updateSchedulerStatus(true);
|
||||
schedulerStatus = schedulerJobHelper.getSchedulerStatus();
|
||||
// Verifying Status of the Scheduler after starting
|
||||
assertEquals(true, schedulerStatus, "Verifying Scheduler Job Status");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNumberOfJobs() {
|
||||
List<Integer> jobIds = schedulerJobHelper.getAllSchedulerJobIds();
|
||||
assertEquals(JobName.values().length, jobIds.size(), "Number of jobs in database and code do not match: " + jobIds);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFlippingJobsActiveStatus() throws InterruptedException {
|
||||
// Stop the Scheduler while we test flapping jobs' active on/off, to
|
||||
// avoid side
|
||||
// effects
|
||||
schedulerJobHelper.updateSchedulerStatus(false);
|
||||
|
||||
// For each retrieved scheduled job (by ID)...
|
||||
for (Integer jobId : schedulerJobHelper.getAllSchedulerJobIds()) {
|
||||
// Retrieving Scheduler Job by ID
|
||||
Map<String, Object> schedulerJob = schedulerJobHelper.getSchedulerJobById(jobId);
|
||||
|
||||
Boolean active = (Boolean) schedulerJob.get("active");
|
||||
active = !active;
|
||||
|
||||
// Updating Scheduler Job
|
||||
Map<String, Object> changes = schedulerJobHelper.updateSchedulerJob(jobId, active);
|
||||
|
||||
// Verifying Scheduler Job updates
|
||||
assertEquals(active, changes.get("active"), "Verifying Scheduler Job Updates");
|
||||
|
||||
schedulerJob = schedulerJobHelper.getSchedulerJobById(jobId);
|
||||
assertEquals(active, schedulerJob.get("active"), "Verifying Get Scheduler Job");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTriggeringManualExecutionOfAllSchedulerJobs() {
|
||||
for (String jobName : schedulerJobHelper.getAllSchedulerJobNames()) {
|
||||
schedulerJobHelper.executeAndAwaitJob(jobName);
|
||||
}
|
||||
}
|
||||
}
|
||||
+997
@@ -0,0 +1,997 @@
|
||||
/**
|
||||
* 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.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.text.DateFormat;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
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.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
|
||||
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 static final String DATE_OF_JOINING = "01 January 2011";
|
||||
|
||||
private static final String TRANSACTION_DATE = "01 March 2013";
|
||||
public static final String ACCOUNT_TYPE_INDIVIDUAL = "INDIVIDUAL";
|
||||
public static final String MINIMUM_OPENING_BALANCE = "1000";
|
||||
|
||||
static Float SP_BALANCE = Float.valueOf(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;
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
Utils.initializeRESTAssured();
|
||||
requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
|
||||
requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
|
||||
requestSpec.header("Fineract-Platform-TenantId", "default");
|
||||
responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||
this.responseSpecForSchedulerJob = new ResponseSpecBuilder().expectStatusCode(202).build();
|
||||
this.accountHelper = new AccountHelper(requestSpec, responseSpec);
|
||||
this.journalEntryHelper = new JournalEntryHelper(requestSpec, responseSpec);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
GlobalConfigurationHelper.resetAllDefaultGlobalConfigurations(requestSpec, responseSpec);
|
||||
GlobalConfigurationHelper.verifyAllDefaultGlobalConfigurations(requestSpec, responseSpec);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApplyAnnualFeeForSavingsJobOutcome() throws InterruptedException {
|
||||
this.savingsAccountHelper = new SavingsAccountHelper(requestSpec, responseSpec);
|
||||
this.schedulerJobHelper = new SchedulerJobHelper(requestSpec);
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(requestSpec, responseSpec);
|
||||
Assertions.assertNotNull(clientID);
|
||||
|
||||
final Integer savingsProductID = createSavingsProduct(requestSpec, responseSpec,
|
||||
ClientSavingsIntegrationTest.MINIMUM_OPENING_BALANCE);
|
||||
Assertions.assertNotNull(savingsProductID);
|
||||
|
||||
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID,
|
||||
ClientSavingsIntegrationTest.ACCOUNT_TYPE_INDIVIDUAL);
|
||||
Assertions.assertNotNull(savingsProductID);
|
||||
|
||||
HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(requestSpec, responseSpec, savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap);
|
||||
|
||||
final Integer annualFeeChargeId = ChargesHelper.createCharges(requestSpec, responseSpec, ChargesHelper.getSavingsAnnualFeeJSON());
|
||||
Assertions.assertNotNull(annualFeeChargeId);
|
||||
|
||||
this.savingsAccountHelper.addChargesForSavings(savingsId, annualFeeChargeId, true);
|
||||
ArrayList<HashMap> chargesPendingState = this.savingsAccountHelper.getSavingsCharges(savingsId);
|
||||
Assertions.assertEquals(1, chargesPendingState.size());
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.approveSavings(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsApproved(savingsStatusHashMap);
|
||||
|
||||
savingsStatusHashMap = this.savingsAccountHelper.activateSavings(savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsActive(savingsStatusHashMap);
|
||||
|
||||
String JobName = "Apply Annual Fee For Savings";
|
||||
|
||||
this.schedulerJobHelper.executeAndAwaitJob(JobName);
|
||||
final HashMap chargeData = ChargesHelper.getChargeById(requestSpec, responseSpec, annualFeeChargeId);
|
||||
|
||||
Float chargeAmount = (Float) chargeData.get("amount");
|
||||
|
||||
final HashMap savingsDetails = this.savingsAccountHelper.getSavingsDetails(savingsId);
|
||||
final HashMap annualFeeDetails = (HashMap) savingsDetails.get("annualFee");
|
||||
ArrayList<Integer> annualFeeDueDateAsArrayList = (ArrayList<Integer>) annualFeeDetails.get("dueDate");
|
||||
LocalDate nextDueDateForAnnualFee = LocalDate.of(annualFeeDueDateAsArrayList.get(0), annualFeeDueDateAsArrayList.get(1),
|
||||
annualFeeDueDateAsArrayList.get(2));
|
||||
LocalDate todaysDate = LocalDate.now(ZoneId.of("Asia/Kolkata"));
|
||||
|
||||
Assertions.assertTrue(nextDueDateForAnnualFee.isAfter(todaysDate), "Verifying that all due Annual Fees have been paid ");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInterestPostingForSavingsJobOutcome() throws InterruptedException {
|
||||
this.savingsAccountHelper = new SavingsAccountHelper(requestSpec, responseSpec);
|
||||
this.schedulerJobHelper = new SchedulerJobHelper(requestSpec);
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(requestSpec, responseSpec);
|
||||
Assertions.assertNotNull(clientID);
|
||||
|
||||
final Integer savingsProductID = createSavingsProduct(requestSpec, responseSpec,
|
||||
ClientSavingsIntegrationTest.MINIMUM_OPENING_BALANCE);
|
||||
Assertions.assertNotNull(savingsProductID);
|
||||
|
||||
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID,
|
||||
ClientSavingsIntegrationTest.ACCOUNT_TYPE_INDIVIDUAL);
|
||||
Assertions.assertNotNull(savingsProductID);
|
||||
|
||||
HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(requestSpec, 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.executeAndAwaitJob(JobName);
|
||||
final HashMap summaryAfter = this.savingsAccountHelper.getSavingsSummary(savingsId);
|
||||
|
||||
Assertions.assertNotSame(summaryBefore.get("accountBalance"), summaryAfter.get("accountBalance"),
|
||||
"Verifying the Balance after running Post Interest for Savings Job");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransferFeeForLoansFromSavingsJobOutcome() throws InterruptedException {
|
||||
this.savingsAccountHelper = new SavingsAccountHelper(requestSpec, responseSpec);
|
||||
this.schedulerJobHelper = new SchedulerJobHelper(requestSpec);
|
||||
this.loanTransactionHelper = new LoanTransactionHelper(requestSpec, responseSpec);
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(requestSpec, responseSpec);
|
||||
Assertions.assertNotNull(clientID);
|
||||
|
||||
final Integer savingsProductID = createSavingsProduct(requestSpec, responseSpec,
|
||||
ClientSavingsIntegrationTest.MINIMUM_OPENING_BALANCE);
|
||||
Assertions.assertNotNull(savingsProductID);
|
||||
|
||||
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID,
|
||||
ClientSavingsIntegrationTest.ACCOUNT_TYPE_INDIVIDUAL);
|
||||
Assertions.assertNotNull(savingsProductID);
|
||||
|
||||
HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(requestSpec, 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);
|
||||
Assertions.assertNotNull(loanProductID);
|
||||
|
||||
final Integer loanID = applyForLoanApplication(clientID.toString(), loanProductID.toString(), savingsId.toString());
|
||||
Assertions.assertNotNull(loanID);
|
||||
|
||||
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(requestSpec, responseSpec, loanID);
|
||||
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
|
||||
|
||||
loanStatusHashMap = this.loanTransactionHelper.approveLoan(AccountTransferTest.LOAN_APPROVAL_DATE, loanID);
|
||||
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
|
||||
|
||||
Integer specifiedDueDateChargeId = ChargesHelper.createCharges(requestSpec, responseSpec,
|
||||
ChargesHelper.getLoanSpecifiedDueDateWithAccountTransferJSON());
|
||||
Assertions.assertNotNull(specifiedDueDateChargeId);
|
||||
|
||||
this.loanTransactionHelper.addChargesForLoan(loanID,
|
||||
LoanTransactionHelper.getSpecifiedDueDateChargesForLoanAsJSON(specifiedDueDateChargeId.toString(), "12 March 2013", "100"));
|
||||
ArrayList<HashMap> chargesPendingState = this.loanTransactionHelper.getLoanCharges(loanID);
|
||||
Assertions.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.executeAndAwaitJob(JobName);
|
||||
final HashMap summaryAfter = this.savingsAccountHelper.getSavingsSummary(savingsId);
|
||||
|
||||
final HashMap chargeData = ChargesHelper.getChargeById(requestSpec, responseSpec, specifiedDueDateChargeId);
|
||||
|
||||
Float chargeAmount = (Float) chargeData.get("amount");
|
||||
|
||||
final Float balance = (Float) summaryBefore.get("accountBalance") - chargeAmount;
|
||||
|
||||
Assertions.assertEquals(balance, (Float) summaryAfter.get("accountBalance"),
|
||||
"Verifying the Balance after running Transfer Fee for Loans from Savings");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApplyHolidaysToLoansJobOutcome() throws InterruptedException {
|
||||
this.schedulerJobHelper = new SchedulerJobHelper(requestSpec);
|
||||
this.loanTransactionHelper = new LoanTransactionHelper(requestSpec, responseSpec);
|
||||
this.holidayHelper = new HolidayHelper(requestSpec, responseSpec);
|
||||
this.globalConfigurationHelper = new GlobalConfigurationHelper(requestSpec, responseSpec);
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(requestSpec, responseSpec);
|
||||
Assertions.assertNotNull(clientID);
|
||||
|
||||
Integer holidayId = HolidayHelper.createHolidays(requestSpec, responseSpec);
|
||||
Assertions.assertNotNull(holidayId);
|
||||
|
||||
final Integer loanProductID = createLoanProduct(null);
|
||||
Assertions.assertNotNull(loanProductID);
|
||||
|
||||
final Integer loanID = applyForLoanApplication(clientID.toString(), loanProductID.toString(), null);
|
||||
Assertions.assertNotNull(loanID);
|
||||
|
||||
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(requestSpec, 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 = GlobalConfigurationHelper.getAllGlobalConfigurations(requestSpec, responseSpec);
|
||||
Assertions.assertNotNull(globalConfig);
|
||||
|
||||
// Updating Value for reschedule-repayments-on-holidays Global
|
||||
// Configuration
|
||||
Integer configId = (Integer) globalConfig.get(3).get("id");
|
||||
Assertions.assertNotNull(configId);
|
||||
|
||||
HashMap configData = GlobalConfigurationHelper.getGlobalConfigurationById(requestSpec, responseSpec, configId.toString());
|
||||
Assertions.assertNotNull(configData);
|
||||
|
||||
Boolean enabled = (Boolean) globalConfig.get(3).get("enabled");
|
||||
|
||||
if (enabled == false) {
|
||||
enabled = true;
|
||||
configId = GlobalConfigurationHelper.updateEnabledFlagForGlobalConfiguration(requestSpec, responseSpec, configId.toString(),
|
||||
enabled);
|
||||
}
|
||||
final ArrayList<HashMap> repaymentScheduleDataBeforeJob = this.loanTransactionHelper.getLoanRepaymentSchedule(requestSpec,
|
||||
responseSpec, loanID);
|
||||
|
||||
holidayId = HolidayHelper.activateHolidays(requestSpec, responseSpec, holidayId.toString());
|
||||
Assertions.assertNotNull(holidayId);
|
||||
|
||||
String JobName = "Apply Holidays To Loans";
|
||||
|
||||
this.schedulerJobHelper.executeAndAwaitJob(JobName);
|
||||
final ArrayList<HashMap> repaymentScheduleDataAfterJob = this.loanTransactionHelper.getLoanRepaymentSchedule(requestSpec,
|
||||
responseSpec, loanID);
|
||||
|
||||
HashMap holidayData = HolidayHelper.getHolidayById(requestSpec, responseSpec, holidayId.toString());
|
||||
ArrayList<Integer> repaymentsRescheduledDate = (ArrayList<Integer>) holidayData.get("repaymentsRescheduledTo");
|
||||
|
||||
ArrayList<Integer> rescheduleDateAfter = (ArrayList<Integer>) repaymentScheduleDataAfterJob.get(2).get("fromDate");
|
||||
|
||||
Assertions.assertEquals(repaymentsRescheduledDate, repaymentsRescheduledDate,
|
||||
"Verifying Repayment Rescheduled Date after Running Apply Holidays to Loans Scheduler Job");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApplyDueFeeChargesForSavingsJobOutcome() throws InterruptedException {
|
||||
this.savingsAccountHelper = new SavingsAccountHelper(requestSpec, responseSpec);
|
||||
this.schedulerJobHelper = new SchedulerJobHelper(requestSpec);
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(requestSpec, responseSpec);
|
||||
Assertions.assertNotNull(clientID);
|
||||
|
||||
final Integer savingsProductID = createSavingsProduct(requestSpec, responseSpec,
|
||||
ClientSavingsIntegrationTest.MINIMUM_OPENING_BALANCE);
|
||||
Assertions.assertNotNull(savingsProductID);
|
||||
|
||||
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID,
|
||||
ClientSavingsIntegrationTest.ACCOUNT_TYPE_INDIVIDUAL);
|
||||
Assertions.assertNotNull(savingsProductID);
|
||||
|
||||
HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(requestSpec, responseSpec, savingsId);
|
||||
SavingsStatusChecker.verifySavingsIsPending(savingsStatusHashMap);
|
||||
|
||||
final Integer specifiedDueDateChargeId = ChargesHelper.createCharges(requestSpec, responseSpec,
|
||||
ChargesHelper.getSavingsSpecifiedDueDateJSON());
|
||||
Assertions.assertNotNull(specifiedDueDateChargeId);
|
||||
|
||||
this.savingsAccountHelper.addChargesForSavings(savingsId, specifiedDueDateChargeId, true);
|
||||
ArrayList<HashMap> chargesPendingState = this.savingsAccountHelper.getSavingsCharges(savingsId);
|
||||
Assertions.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.executeAndAwaitJob(JobName);
|
||||
HashMap summaryAfter = this.savingsAccountHelper.getSavingsSummary(savingsId);
|
||||
|
||||
final HashMap chargeData = ChargesHelper.getChargeById(requestSpec, responseSpec, specifiedDueDateChargeId);
|
||||
|
||||
Float chargeAmount = (Float) chargeData.get("amount");
|
||||
|
||||
final Float balance = (Float) summaryBefore.get("accountBalance") - chargeAmount;
|
||||
|
||||
Assertions.assertEquals(balance, (Float) summaryAfter.get("accountBalance"),
|
||||
"Verifying the Balance after running Pay due Savings Charges");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateAccountingRunningBalancesJobOutcome() throws InterruptedException {
|
||||
this.savingsAccountHelper = new SavingsAccountHelper(requestSpec, responseSpec);
|
||||
this.schedulerJobHelper = new SchedulerJobHelper(requestSpec);
|
||||
|
||||
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(requestSpec, responseSpec, DATE_OF_JOINING);
|
||||
final Integer savingsID = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID, ACCOUNT_TYPE_INDIVIDUAL);
|
||||
|
||||
HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(requestSpec, 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(SP_BALANCE, JournalEntry.TransactionType.DEBIT) };
|
||||
final JournalEntry[] liablilityAccountInitialEntry = { new JournalEntry(SP_BALANCE, JournalEntry.TransactionType.CREDIT) };
|
||||
this.journalEntryHelper.checkJournalEntryForAssetAccount(assetAccount, TRANSACTION_DATE, assetAccountInitialEntry);
|
||||
this.journalEntryHelper.checkJournalEntryForLiabilityAccount(liabilityAccount, TRANSACTION_DATE, liablilityAccountInitialEntry);
|
||||
|
||||
String JobName = "Update Accounting Running Balances";
|
||||
|
||||
this.schedulerJobHelper.executeAndAwaitJob(JobName);
|
||||
final HashMap runningBalanceAfter = this.accountHelper.getAccountingWithRunningBalanceById(accountID.toString());
|
||||
|
||||
final Integer INT_BALANCE = Integer.valueOf(MINIMUM_OPENING_BALANCE);
|
||||
|
||||
Assertions.assertEquals(INT_BALANCE, runningBalanceAfter.get("organizationRunningBalance"),
|
||||
"Verifying Account Running Balance after running Update Accounting Running Balances Scheduler Job");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateLoanArrearsAgingJobOutcome() throws InterruptedException {
|
||||
this.schedulerJobHelper = new SchedulerJobHelper(requestSpec);
|
||||
this.loanTransactionHelper = new LoanTransactionHelper(requestSpec, responseSpec);
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(requestSpec, responseSpec);
|
||||
Assertions.assertNotNull(clientID);
|
||||
|
||||
final Integer loanProductID = createLoanProduct(null);
|
||||
Assertions.assertNotNull(loanProductID);
|
||||
|
||||
final Integer loanID = applyForLoanApplication(clientID.toString(), loanProductID.toString(), null);
|
||||
Assertions.assertNotNull(loanID);
|
||||
|
||||
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(requestSpec, 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.executeAndAwaitJob(JobName);
|
||||
HashMap loanSummaryData = this.loanTransactionHelper.getLoanSummary(requestSpec, responseSpec, loanID);
|
||||
|
||||
Float totalLoanArrearsAging = (Float) loanSummaryData.get("principalOverdue") + (Float) loanSummaryData.get("interestOverdue");
|
||||
|
||||
Assertions.assertEquals(totalLoanArrearsAging, loanSummaryData.get("totalOverdue"),
|
||||
"Verifying Arrears Aging after Running Update Loan Arrears Aging Scheduler Job");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateLoanPaidInAdvanceJobOutcome() throws InterruptedException {
|
||||
this.schedulerJobHelper = new SchedulerJobHelper(requestSpec);
|
||||
this.loanTransactionHelper = new LoanTransactionHelper(requestSpec, 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(requestSpec, responseSpec);
|
||||
Assertions.assertNotNull(clientID);
|
||||
|
||||
final Integer loanProductID = createLoanProduct(null);
|
||||
Assertions.assertNotNull(loanProductID);
|
||||
|
||||
final Integer loanID = applyForLoanApplication(clientID.toString(), loanProductID.toString(), null);
|
||||
Assertions.assertNotNull(loanID);
|
||||
|
||||
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(requestSpec, 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(requestSpec, responseSpec, loanID);
|
||||
|
||||
Float totalDueForCurrentPeriod = (Float) loanScheduleBefore.get(1).get("totalDueForPeriod");
|
||||
|
||||
this.loanTransactionHelper.makeRepayment(LOAN_FIRST_REPAYMENT_DATE, totalDueForCurrentPeriod, loanID);
|
||||
|
||||
HashMap loanSummary = this.loanTransactionHelper.getLoanSummary(requestSpec, responseSpec, loanID);
|
||||
|
||||
String JobName = "Update Loan Paid In Advance";
|
||||
this.schedulerJobHelper.executeAndAwaitJob(JobName);
|
||||
// Retrieving Loan Repayment Schedule after the successful
|
||||
// completion of
|
||||
// Update Loan Paid in Advance Scheduler Job
|
||||
ArrayList<HashMap> loanScheduleAfter = this.loanTransactionHelper.getLoanRepaymentSchedule(requestSpec, responseSpec, loanID);
|
||||
|
||||
loanSummary = this.loanTransactionHelper.getLoanSummary(requestSpec, responseSpec, loanID);
|
||||
|
||||
Float totalPaidInAdvance = (Float) loanScheduleAfter.get(1).get("totalPaidInAdvanceForPeriod");
|
||||
|
||||
Assertions.assertEquals(totalDueForCurrentPeriod, totalPaidInAdvance,
|
||||
"Verifying Loan Repayment in Advance after Running Update Loan Paid in Advance Scheduler Job");
|
||||
|
||||
}
|
||||
|
||||
// Invalid test case as it won't affect summary (Loan summary is properly
|
||||
// updated before running this job)
|
||||
@Disabled
|
||||
@Test
|
||||
public void testUpdateLoanSummaryJobOutcome() throws InterruptedException {
|
||||
this.schedulerJobHelper = new SchedulerJobHelper(requestSpec);
|
||||
this.loanTransactionHelper = new LoanTransactionHelper(requestSpec, 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(requestSpec, responseSpec);
|
||||
Assertions.assertNotNull(clientID);
|
||||
|
||||
final Integer loanProductID = createLoanProduct(null);
|
||||
Assertions.assertNotNull(loanProductID);
|
||||
|
||||
final Integer loanID = applyForLoanApplication(clientID.toString(), loanProductID.toString(), null);
|
||||
Assertions.assertNotNull(loanID);
|
||||
|
||||
Integer disburseChargeId = ChargesHelper.createCharges(requestSpec, responseSpec, ChargesHelper.getLoanDisbursementJSON());
|
||||
Assertions.assertNotNull(disburseChargeId);
|
||||
|
||||
this.loanTransactionHelper.addChargesForLoan(loanID,
|
||||
LoanTransactionHelper.getDisbursementChargesForLoanAsJSON(disburseChargeId.toString()));
|
||||
ArrayList<HashMap> chargesPendingState = this.loanTransactionHelper.getLoanCharges(loanID);
|
||||
Assertions.assertEquals(1, chargesPendingState.size());
|
||||
|
||||
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(requestSpec, 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(requestSpec, responseSpec, loanID);
|
||||
|
||||
String JobName = "Update loan Summary";
|
||||
this.schedulerJobHelper.executeAndAwaitJob(JobName);
|
||||
Float expectedSummaryAfterJob = (Float) loanSummaryBefore.get("totalExpectedRepayment")
|
||||
/* - (Float) loanSummaryBefore.get("feeChargesPaid") */;
|
||||
HashMap loanSummaryAfter = this.loanTransactionHelper.getLoanSummary(requestSpec, responseSpec, loanID);
|
||||
Assertions.assertEquals(expectedSummaryAfterJob, (Float) loanSummaryAfter.get("totalExpectedRepayment"),
|
||||
"Verifying Loan Summary after Running Update Loan Summary Scheduler Job");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteStandingInstructionsJobOutcome() throws InterruptedException {
|
||||
this.schedulerJobHelper = new SchedulerJobHelper(requestSpec);
|
||||
this.savingsAccountHelper = new SavingsAccountHelper(requestSpec, responseSpec);
|
||||
this.standingInstructionsHelper = new StandingInstructionsHelper(requestSpec, 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(requestSpec, responseSpec);
|
||||
Assertions.assertNotNull(clientID);
|
||||
|
||||
final Integer savingsProductID = createSavingsProduct(requestSpec, responseSpec,
|
||||
ClientSavingsIntegrationTest.MINIMUM_OPENING_BALANCE);
|
||||
Assertions.assertNotNull(savingsProductID);
|
||||
|
||||
final Integer fromSavingsId = this.savingsAccountHelper.applyForSavingsApplication(clientID, savingsProductID,
|
||||
ClientSavingsIntegrationTest.ACCOUNT_TYPE_INDIVIDUAL);
|
||||
Assertions.assertNotNull(savingsProductID);
|
||||
|
||||
HashMap fromSavingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(requestSpec, 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);
|
||||
Assertions.assertNotNull(savingsProductID);
|
||||
|
||||
HashMap toSavingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(requestSpec, 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);
|
||||
Assertions.assertNotNull(standingInstructionId);
|
||||
|
||||
String JobName = "Execute Standing Instruction";
|
||||
this.schedulerJobHelper.executeAndAwaitJob(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");
|
||||
|
||||
Assertions.assertEquals(expectedFromSavingsBalance, fromSavingsBalanceAfter,
|
||||
"Verifying From Savings Balance after Successful completion of Scheduler Job");
|
||||
Assertions.assertEquals(expectedToSavingsBalance, toSavingsBalanceAfter,
|
||||
"Verifying To Savings Balance after Successful completion of Scheduler Job");
|
||||
Integer fromAccountType = PortfolioAccountType.SAVINGS.getValue();
|
||||
Integer transferType = AccountTransferType.ACCOUNT_TRANSFER.getValue();
|
||||
List<HashMap> standinInstructionHistoryData = this.standingInstructionsHelper.getStandingInstructionHistory(fromSavingsId,
|
||||
fromAccountType, clientID, transferType);
|
||||
Assertions.assertEquals(1, standinInstructionHistoryData.size(),
|
||||
"Verifying the no of stainding instruction transactions logged for the client");
|
||||
HashMap loggedTransaction = standinInstructionHistoryData.get(0);
|
||||
|
||||
Assertions.assertEquals((Float) standingInstructionData.get("amount"), (Float) loggedTransaction.get("amount"),
|
||||
"Verifying transferred amount and logged transaction amounts");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApplyPenaltyForOverdueLoansJobOutcome() throws InterruptedException {
|
||||
this.savingsAccountHelper = new SavingsAccountHelper(requestSpec, responseSpec);
|
||||
this.schedulerJobHelper = new SchedulerJobHelper(requestSpec);
|
||||
this.loanTransactionHelper = new LoanTransactionHelper(requestSpec, responseSpec);
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(requestSpec, responseSpec);
|
||||
Assertions.assertNotNull(clientID);
|
||||
|
||||
Integer overdueFeeChargeId = ChargesHelper.createCharges(requestSpec, responseSpec, ChargesHelper.getLoanOverdueFeeJSON());
|
||||
Assertions.assertNotNull(overdueFeeChargeId);
|
||||
|
||||
final Integer loanProductID = createLoanProduct(overdueFeeChargeId.toString());
|
||||
Assertions.assertNotNull(loanProductID);
|
||||
|
||||
final Integer loanID = applyForLoanApplication(clientID.toString(), loanProductID.toString(), null);
|
||||
Assertions.assertNotNull(loanID);
|
||||
|
||||
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(requestSpec, 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(requestSpec, responseSpec,
|
||||
loanID);
|
||||
|
||||
String JobName = "Apply penalty to overdue loans";
|
||||
this.schedulerJobHelper.executeAndAwaitJob(JobName);
|
||||
|
||||
final HashMap chargeData = ChargesHelper.getChargeById(requestSpec, responseSpec, overdueFeeChargeId);
|
||||
|
||||
Float chargeAmount = (Float) chargeData.get("amount");
|
||||
|
||||
ArrayList<HashMap> repaymentScheduleDataAfter = this.loanTransactionHelper.getLoanRepaymentSchedule(requestSpec, responseSpec,
|
||||
loanID);
|
||||
|
||||
Assertions.assertEquals(chargeAmount, (Float) repaymentScheduleDataAfter.get(1).get("penaltyChargesDue"),
|
||||
"Verifying From Penalty Charges due fot first Repayment after Successful completion of Scheduler Job");
|
||||
|
||||
loanStatusHashMap = this.loanTransactionHelper.undoDisbursal(loanID);
|
||||
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
|
||||
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAvoidUnncessaryPenaltyWhenAmountZeroForOverdueLoansJobOutcome() throws InterruptedException {
|
||||
this.savingsAccountHelper = new SavingsAccountHelper(requestSpec, responseSpec);
|
||||
this.schedulerJobHelper = new SchedulerJobHelper(requestSpec);
|
||||
this.loanTransactionHelper = new LoanTransactionHelper(requestSpec, responseSpec);
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(requestSpec, responseSpec);
|
||||
Assertions.assertNotNull(clientID);
|
||||
|
||||
Integer overdueFeeChargeId = ChargesHelper.createCharges(requestSpec, responseSpec,
|
||||
ChargesHelper.getLoanOverdueFeeJSONWithCalculattionTypePercentage("0.000001"));
|
||||
Assertions.assertNotNull(overdueFeeChargeId);
|
||||
|
||||
final Integer loanProductID = createLoanProduct(overdueFeeChargeId.toString());
|
||||
Assertions.assertNotNull(loanProductID);
|
||||
|
||||
final Integer loanID = applyForLoanApplication(clientID.toString(), loanProductID.toString(), null);
|
||||
Assertions.assertNotNull(loanID);
|
||||
|
||||
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(requestSpec, 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(requestSpec, responseSpec,
|
||||
loanID);
|
||||
|
||||
String JobName = "Apply penalty to overdue loans";
|
||||
Integer jobId = 12;
|
||||
|
||||
this.schedulerJobHelper.executeAndAwaitJob(JobName);
|
||||
|
||||
Map<String, Object> schedulerJob = this.schedulerJobHelper.getSchedulerJobById(jobId);
|
||||
|
||||
Assertions.assertNotNull(schedulerJob);
|
||||
while ((Boolean) schedulerJob.get("currentlyRunning") == true) {
|
||||
Thread.sleep(15000);
|
||||
schedulerJob = this.schedulerJobHelper.getSchedulerJobById(jobId);
|
||||
Assertions.assertNotNull(schedulerJob);
|
||||
}
|
||||
|
||||
final HashMap chargeData = ChargesHelper.getChargeById(requestSpec, responseSpec, overdueFeeChargeId);
|
||||
|
||||
ArrayList<HashMap> repaymentScheduleDataAfter = this.loanTransactionHelper.getLoanRepaymentSchedule(requestSpec, responseSpec,
|
||||
loanID);
|
||||
|
||||
Assertions.assertEquals(0, repaymentScheduleDataAfter.get(1).get("penaltyChargesDue"),
|
||||
"Verifying From Penalty Charges due fot first Repayment after Successful completion of Scheduler Job");
|
||||
|
||||
final ArrayList loanCharges = this.loanTransactionHelper.getLoanCharges(requestSpec, responseSpec, loanID);
|
||||
|
||||
Assertions.assertNull(loanCharges, "Verifying that charge isn't created when the amount is 0");
|
||||
|
||||
loanStatusHashMap = this.loanTransactionHelper.undoDisbursal(loanID);
|
||||
LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap);
|
||||
LoanStatusChecker.verifyLoanIsWaitingForDisbursal(loanStatusHashMap);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateOverdueDaysForNPA() throws InterruptedException {
|
||||
this.schedulerJobHelper = new SchedulerJobHelper(requestSpec);
|
||||
this.loanTransactionHelper = new LoanTransactionHelper(requestSpec, responseSpec);
|
||||
|
||||
final Integer clientID = ClientHelper.createClient(requestSpec, responseSpec);
|
||||
Assertions.assertNotNull(clientID);
|
||||
|
||||
final Integer loanProductID = createLoanProduct(null);
|
||||
Assertions.assertNotNull(loanProductID);
|
||||
|
||||
final Integer loanID = applyForLoanApplication(clientID.toString(), loanProductID.toString(), null);
|
||||
Assertions.assertNotNull(loanID);
|
||||
|
||||
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(requestSpec, 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");
|
||||
Assertions.assertFalse(isNPABefore);
|
||||
// Integer jobId = (Integer) allSchedulerJobsData.get(1).get("jobId");
|
||||
String JobName = "Update Non Performing Assets";
|
||||
this.schedulerJobHelper.executeAndAwaitJob(JobName);
|
||||
final Boolean isNPAAfter = (Boolean) this.loanTransactionHelper.getLoanDetail(requestSpec, responseSpec, loanID, "isNPA");
|
||||
Assertions.assertTrue(isNPAAfter);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInterestTransferForSavings() throws InterruptedException {
|
||||
this.savingsAccountHelper = new SavingsAccountHelper(requestSpec, responseSpec);
|
||||
this.schedulerJobHelper = new SchedulerJobHelper(requestSpec);
|
||||
// FixedDepositProductHelper fixedDepositProductHelper = new
|
||||
// FixedDepositProductHelper(this.requestSpec,this.responseSpec);
|
||||
// AccountHelper accountHelper = new AccountHelper(this.requestSpec,
|
||||
// this.responseSpec);
|
||||
FixedDepositAccountHelper fixedDepositAccountHelper = new FixedDepositAccountHelper(requestSpec, 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(requestSpec, responseSpec);
|
||||
Assertions.assertNotNull(clientId);
|
||||
Float balance = Float.valueOf(MINIMUM_OPENING_BALANCE) + Float.valueOf(FixedDepositAccountHelper.DEPOSIT_AMOUNT);
|
||||
final Integer savingsProductID = createSavingsProduct(requestSpec, responseSpec, String.valueOf(balance));
|
||||
Assertions.assertNotNull(savingsProductID);
|
||||
|
||||
final Integer savingsId = this.savingsAccountHelper.applyForSavingsApplication(clientId, savingsProductID,
|
||||
ClientSavingsIntegrationTest.ACCOUNT_TYPE_INDIVIDUAL);
|
||||
Assertions.assertNotNull(savingsId);
|
||||
|
||||
HashMap savingsStatusHashMap = SavingsStatusChecker.getStatusOfSavings(requestSpec, 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(balance, summary.get("accountBalance"), "Verifying opening Balance");
|
||||
|
||||
Integer fixedDepositProductId = createFixedDepositProduct(VALID_FROM, VALID_TO);
|
||||
Assertions.assertNotNull(fixedDepositProductId);
|
||||
|
||||
Integer fixedDepositAccountId = applyForFixedDepositApplication(clientId.toString(), fixedDepositProductId.toString(), VALID_FROM,
|
||||
VALID_TO, SUBMITTED_ON_DATE, WHOLE_TERM, savingsId.toString(), true, fixedDepositAccountHelper);
|
||||
Assertions.assertNotNull(fixedDepositAccountId);
|
||||
|
||||
HashMap fixedDepositAccountStatusHashMap = FixedDepositAccountStatusChecker.getStatusOfFixedDepositAccount(requestSpec,
|
||||
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 = Float.valueOf(MINIMUM_OPENING_BALANCE);
|
||||
assertEquals(balance, summary.get("accountBalance"), "Verifying Balance");
|
||||
|
||||
fixedDepositAccountHelper.postInterestForFixedDeposit(fixedDepositAccountId);
|
||||
|
||||
HashMap fixedDepositSummary = savingsAccountHelper.getSavingsSummary(fixedDepositAccountId);
|
||||
Float interestPosted = (Float) fixedDepositSummary.get("accountBalance") - Float.valueOf(FixedDepositAccountHelper.DEPOSIT_AMOUNT);
|
||||
|
||||
String JobName = "Transfer Interest To Savings";
|
||||
this.schedulerJobHelper.executeAndAwaitJob(JobName);
|
||||
fixedDepositSummary = savingsAccountHelper.getSavingsSummary(fixedDepositAccountId);
|
||||
assertEquals(Float.valueOf(FixedDepositAccountHelper.DEPOSIT_AMOUNT), fixedDepositSummary.get("accountBalance"),
|
||||
"Verifying opening Balance");
|
||||
|
||||
summary = savingsAccountHelper.getSavingsSummary(savingsId);
|
||||
balance = Float.valueOf(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(requestSpec, responseSpec);
|
||||
final String fixedDepositProductJSON = fixedDepositProductHelper //
|
||||
// .withAccountingRuleAsCashBased(accounts)
|
||||
.withPeriodRangeChart()//
|
||||
.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(requestSpec, responseSpec)
|
||||
//
|
||||
.withSubmittedOnDate(submittedOnDate).withSavings(savingsId).transferInterest(true)
|
||||
.withLockinPeriodFrequency("1", FixedDepositAccountHelper.DAYS).build(clientID, productID, penalInterestType);
|
||||
return FixedDepositAccountHelper.applyFixedDepositApplication(fixedDepositApplicationJSON, requestSpec, responseSpec);
|
||||
}
|
||||
|
||||
private void validateNumberForEqualExcludePrecission(String val, String val2) {
|
||||
DecimalFormat twoDForm = new DecimalFormat("#", new DecimalFormatSymbols(Locale.US));
|
||||
Assertions.assertTrue(
|
||||
Float.valueOf(twoDForm.format(Float.valueOf(val))).compareTo(Float.valueOf(twoDForm.format(Float.valueOf(val2)))) == 0);
|
||||
}
|
||||
}
|
||||
+170
@@ -0,0 +1,170 @@
|
||||
/**
|
||||
* 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.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import org.apache.fineract.integrationtests.common.CalendarHelper;
|
||||
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||
import org.apache.fineract.integrationtests.common.GlobalConfigurationHelper;
|
||||
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.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
|
||||
public class SkipRepaymentOnMonthFirstTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(SkipRepaymentOnMonthFirstTest.class);
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private GlobalConfigurationHelper globalConfigurationHelper;
|
||||
private LoanTransactionHelper loanTransactionHelper;
|
||||
private CalendarHelper calendarHelper;
|
||||
|
||||
@BeforeEach
|
||||
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();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
GlobalConfigurationHelper.resetAllDefaultGlobalConfigurations(this.requestSpec, this.responseSpec);
|
||||
GlobalConfigurationHelper.verifyAllDefaultGlobalConfigurations(this.requestSpec, this.responseSpec);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSkippingRepaymentOnFirstDayOfMonth() {
|
||||
this.globalConfigurationHelper = new GlobalConfigurationHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
// Retrieving All Global Configuration details
|
||||
final ArrayList<HashMap> globalConfig = GlobalConfigurationHelper.getAllGlobalConfigurations(this.requestSpec, this.responseSpec);
|
||||
Assertions.assertNotNull(globalConfig);
|
||||
|
||||
String configName = "skip-repayment-on-first-day-of-month";
|
||||
boolean newBooleanValue = true;
|
||||
|
||||
for (Integer configIndex = 0; configIndex < globalConfig.size(); configIndex++) {
|
||||
if (globalConfig.get(configIndex).get("name").equals(configName)) {
|
||||
String configId = globalConfig.get(configIndex).get("id").toString();
|
||||
Integer updateConfigId = GlobalConfigurationHelper.updateEnabledFlagForGlobalConfiguration(this.requestSpec,
|
||||
this.responseSpec, configId.toString(), newBooleanValue);
|
||||
Assertions.assertNotNull(updateConfigId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkRepaymentSkipOnFirstDayOfMonth() {
|
||||
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 String startDate = "15 September 2011";
|
||||
final String frequency = "3"; // Monthly
|
||||
final String interval = "1"; // Every One Moth
|
||||
Integer calendarID = CalendarHelper.createMeetingForGroup(requestSpec, responseSpec, groupID, startDate, frequency, interval, null);
|
||||
LOG.info("caladerId -------------------- {}", calendarID);
|
||||
final Integer loanProductID = createLoanProduct();
|
||||
final Integer loanID = applyForLoanApplication(groupID, loanProductID, calendarID, clientID);
|
||||
LOG.info("loanID---- {}", loanID);
|
||||
final ArrayList<HashMap> loanSchedule = this.loanTransactionHelper.getLoanRepaymentSchedule(this.requestSpec, this.responseSpec,
|
||||
loanID);
|
||||
verifyLoanRepaymentSchedule(loanSchedule);
|
||||
|
||||
}
|
||||
|
||||
private Integer createLoanProduct() {
|
||||
LOG.info("------------------------------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, Integer calendarID, Integer clientID) {
|
||||
LOG.info("--------------------------------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("01 October 2011") //
|
||||
.withCalendarID(calendarID.toString()) //
|
||||
.withSubmittedOnDate("01 October 2011") //
|
||||
.withLoanType("jlg").build(clientID.toString(), groupID.toString(), loanProductID.toString(), null);
|
||||
LOG.info(loanApplicationJSON);
|
||||
return this.loanTransactionHelper.getLoanId(loanApplicationJSON);
|
||||
}
|
||||
|
||||
private void verifyLoanRepaymentSchedule(final ArrayList<HashMap> loanSchedule) {
|
||||
LOG.info("--------------------VERIFYING THE REPAYMENT DATE--------------------------");
|
||||
assertEquals(new ArrayList<>(Arrays.asList(2011, 10, 15)), loanSchedule.get(1).get("dueDate"),
|
||||
"Checking for Repayment Date for 1st Month");
|
||||
LOG.info("Repayment Date for 1st Month-- {}", loanSchedule.get(1).get("dueDate"));
|
||||
|
||||
assertEquals(new ArrayList<>(Arrays.asList(2011, 11, 15)), loanSchedule.get(2).get("dueDate"),
|
||||
"Checking for Repayment Date for 2nd Month");
|
||||
LOG.info("Repayment Date for 2nd Month-- {}", loanSchedule.get(2).get("dueDate"));
|
||||
|
||||
assertEquals(new ArrayList<>(Arrays.asList(2011, 12, 15)), loanSchedule.get(3).get("dueDate"),
|
||||
"Checking for Repayment Date for 3rd Month");
|
||||
LOG.info("Repayment Date for 3rd Month-- {}", loanSchedule.get(3).get("dueDate"));
|
||||
|
||||
assertEquals(new ArrayList<>(Arrays.asList(2012, 1, 15)), loanSchedule.get(4).get("dueDate"),
|
||||
"Checking for Repayment Date for 4th Month");
|
||||
LOG.info("Repayment Date for 4th Month-- {}", loanSchedule.get(4).get("dueDate"));
|
||||
}
|
||||
|
||||
}
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
/**
|
||||
* 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.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import org.apache.fineract.integrationtests.common.ImageHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.organisation.StaffHelper;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@Deprecated // replaced by new ImageTest, can be deleted as FINERACT-1209 is fully implemented
|
||||
public class StaffImageApiTest {
|
||||
|
||||
private RequestSpecification requestSpec;
|
||||
private ResponseSpecification responseSpec;
|
||||
private ResponseSpecification responseSpec404;
|
||||
|
||||
@BeforeEach
|
||||
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.responseSpec404 = new ResponseSpecBuilder().expectStatusCode(404).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createStaffImage() {
|
||||
Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
|
||||
Integer imageId = ImageHelper.createImageForStaff(this.requestSpec, this.responseSpec, staffId);
|
||||
assertNotNull(imageId, "Image id should not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getStaffImage() {
|
||||
Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
|
||||
Integer imageId = ImageHelper.createImageForStaff(this.requestSpec, this.responseSpec, staffId);
|
||||
assertNotNull(imageId, "Image id should not be null");
|
||||
|
||||
String imageAsText = ImageHelper.getStaffImageAsText(this.requestSpec, this.responseSpec, staffId);
|
||||
assertNotNull("Image id should not be null", imageAsText);
|
||||
assertEquals(ImageHelper.generateImageAsText(), imageAsText);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getStaffImageAsBinary() {
|
||||
Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
|
||||
Integer imageId = ImageHelper.createImageForStaff(this.requestSpec, this.responseSpec, staffId);
|
||||
assertNotNull(imageId, "Image id should not be null");
|
||||
|
||||
byte[] imageAsBytes = ImageHelper.getStaffImageAsBinary(this.requestSpec, this.responseSpec, staffId);
|
||||
assertNotNull(imageAsBytes, "Image content should not be null");
|
||||
assertEquals(251, imageAsBytes.length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateImage() {
|
||||
Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
|
||||
Integer imageId = ImageHelper.createImageForStaff(this.requestSpec, this.responseSpec, staffId);
|
||||
assertNotNull(imageId, "Image id should not be null");
|
||||
|
||||
imageId = ImageHelper.updateImageForStaff(this.requestSpec, this.responseSpec, staffId);
|
||||
assertNotNull(imageId, "Image id should not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteStaffImage() {
|
||||
Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
|
||||
Integer imageId = ImageHelper.createImageForStaff(this.requestSpec, this.responseSpec, staffId);
|
||||
assertNotNull(imageId, "Image id should not be null");
|
||||
|
||||
imageId = ImageHelper.deleteStaffImage(this.requestSpec, this.responseSpec, staffId);
|
||||
assertNotNull(imageId, "Image id should not be null");
|
||||
|
||||
ImageHelper.getStaffImageAsBinary(this.requestSpec, this.responseSpec404, staffId);
|
||||
// No additional Assertion required, the point is the responseSpec404
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,244 @@
|
||||
/**
|
||||
* 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.google.gson.Gson;
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
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.organisation.StaffHelper;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class StaffTest {
|
||||
|
||||
private RequestSpecification requestSpec;
|
||||
private ResponseSpecification responseSpec;
|
||||
private ResponseSpecification responseSpecForValidationError;
|
||||
private ResponseSpecification responseSpecForNotFoundError;
|
||||
|
||||
@BeforeEach
|
||||
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() {
|
||||
Map<String, Object> response = StaffHelper.createStaffMap(requestSpec, responseSpec);
|
||||
|
||||
Assertions.assertNotNull(response);
|
||||
Assertions.assertEquals(1, response.get("officeId"));
|
||||
Assertions.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 Map<String, Object> map = StaffHelper.getMapWithJoiningDate();
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaffCreateMaxNameLength() {
|
||||
|
||||
final Map<String, Object> map = StaffHelper.getMapWithJoiningDate();
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaffCreateExternalIdValidationError() {
|
||||
final Map<String, Object> map = StaffHelper.getMapWithJoiningDate();
|
||||
|
||||
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() {
|
||||
Map<String, Object> response = StaffHelper.getStaff(requestSpec, responseSpec, 1);
|
||||
Assertions.assertNotNull(response);
|
||||
Assertions.assertNotNull(response.get("id"));
|
||||
Assertions.assertEquals(1, response.get("id"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaffListFetch() {
|
||||
StaffHelper.getStaffList(requestSpec, responseSpec);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaffListStatusAll() {
|
||||
StaffHelper.getStaffListWithState(requestSpec, responseSpec, "all");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaffListStatusActive() {
|
||||
List<Map<String, Object>> responseActive = StaffHelper.getStaffListWithState(requestSpec, responseSpec, "active");
|
||||
for (final Map<String, Object> staff : responseActive) {
|
||||
Assertions.assertNotNull(staff.get("id"));
|
||||
Assertions.assertEquals(true, staff.get("isActive"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaffListStatusInactive() {
|
||||
List<Map<String, Object>> responseInactive = StaffHelper.getStaffListWithState(requestSpec, responseSpec, "inactive");
|
||||
for (final Map<String, Object> staff : responseInactive) {
|
||||
Assertions.assertNotNull(staff.get("id"));
|
||||
Assertions.assertEquals(false, staff.get("isActive"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test // because "xyz" will return an error, not a List
|
||||
public void testStaffListFetchWrongState() throws ClassCastException {
|
||||
Assertions.assertThrows(ClassCastException.class, () -> {
|
||||
StaffHelper.getStaffListWithState(requestSpec, responseSpecForValidationError, "xyz");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaffFetchNotFound() {
|
||||
StaffHelper.getStaff(requestSpec, responseSpecForNotFoundError, Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaffUpdate() {
|
||||
final Map<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);
|
||||
|
||||
Map<String, Object> response = StaffHelper.updateStaff(requestSpec, responseSpec, 1, map);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> changes = (Map<String, Object>) response.get("changes");
|
||||
|
||||
Assertions.assertEquals(1, response.get("resourceId"));
|
||||
Assertions.assertEquals(firstname, changes.get("firstname"));
|
||||
Assertions.assertEquals(lastname, changes.get("lastname"));
|
||||
Assertions.assertEquals(externalId, changes.get("externalId"));
|
||||
Assertions.assertEquals(mobileNo, changes.get("mobileNo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaffUpdateLongExternalIdError() {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("externalId", Utils.randomStringGenerator("EXT", 98));
|
||||
|
||||
StaffHelper.updateStaff(requestSpec, responseSpecForValidationError, 1, map);
|
||||
}
|
||||
|
||||
@Test
|
||||
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);
|
||||
}
|
||||
}
|
||||
+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;
|
||||
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
@BeforeEach
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* 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 io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author Manthan Surkar
|
||||
*/
|
||||
public class SwaggeruiTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
Utils.initializeRESTAssured();
|
||||
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
|
||||
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSwaggeruiAccess() {
|
||||
Utils.performServerGet(requestSpec, responseSpec, "/fineract-provider/swagger-ui", null);
|
||||
Utils.performServerGet(requestSpec, responseSpec, "/fineract-provider/swagger-ui/index.html", null);
|
||||
}
|
||||
|
||||
}
|
||||
+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.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
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.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test for creating, updating, deleting codes and code values
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public class SystemCodeTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private ResponseSpecification generalResponseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
|
||||
@BeforeEach
|
||||
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, "");
|
||||
|
||||
Assertions.assertNotNull(newCodeAttributes);
|
||||
assertEquals(createResponseId, newCodeAttributes.get(CodeHelper.CODE_ID_ATTRIBUTE_NAME), "Verify value of codeId");
|
||||
|
||||
assertEquals(codeName, newCodeAttributes.get(CodeHelper.CODE_NAME_ATTRIBUTE_NAME), "Verify code name");
|
||||
assertEquals(false, newCodeAttributes.get(CodeHelper.CODE_SYSTEM_DEFINED_ATTRIBUTE_NAME), "Verify system defined is false");
|
||||
|
||||
// update code
|
||||
final HashMap updateChangeResponse = (HashMap) CodeHelper.updateCode(this.requestSpec, this.responseSpec, createResponseId,
|
||||
codeName + "(CHANGE)", "changes");
|
||||
|
||||
assertEquals(codeName + "(CHANGE)", updateChangeResponse.get(CodeHelper.CODE_NAME_ATTRIBUTE_NAME), "Verify code name updated");
|
||||
|
||||
// delete code
|
||||
final Integer deleteResponseId = (Integer) CodeHelper.deleteCodeById(this.requestSpec, this.responseSpec, createResponseId,
|
||||
CodeHelper.RESPONSE_ID_ATTRIBUTE_NAME);
|
||||
assertEquals(createResponseId, deleteResponseId, "Verify code deleted");
|
||||
|
||||
// verify code deleted
|
||||
final HashMap deletedCodeValues = (HashMap) CodeHelper.getCodeById(this.requestSpec, this.generalResponseSpec, deleteResponseId,
|
||||
"");
|
||||
|
||||
Assertions.assertNotNull(deletedCodeValues);
|
||||
assertNull(deletedCodeValues.get(CodeHelper.CODE_ID_ATTRIBUTE_NAME), "Verify value of codeId");
|
||||
|
||||
assertNull(deletedCodeValues.get(CodeHelper.CODE_NAME_ATTRIBUTE_NAME), "Verify code name");
|
||||
assertNull(deletedCodeValues.get(CodeHelper.CODE_SYSTEM_DEFINED_ATTRIBUTE_NAME), "Verify system defined is false");
|
||||
}
|
||||
|
||||
// @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, "");
|
||||
|
||||
Assertions.assertNotNull(newCodeAttributes);
|
||||
assertEquals(createResponseId, newCodeAttributes.get(CodeHelper.CODE_ID_ATTRIBUTE_NAME), "Verify value of codeId");
|
||||
|
||||
assertEquals(codeName, newCodeAttributes.get(CodeHelper.CODE_NAME_ATTRIBUTE_NAME), "Verify code name");
|
||||
assertEquals(false, newCodeAttributes.get(CodeHelper.CODE_SYSTEM_DEFINED_ATTRIBUTE_NAME), "Verify system defined is false");
|
||||
|
||||
// try to create duplicate-- should fail
|
||||
final List<HashMap> error = (List) CodeHelper.createCode(this.requestSpec, this.generalResponseSpec, codeName,
|
||||
CommonConstants.RESPONSE_ERROR);
|
||||
|
||||
assertEquals("error.msg.code.duplicate.name", error.get(0).get("userMessageGlobalisationCode"), "Verify duplication error");
|
||||
|
||||
// delete code that was just created
|
||||
|
||||
final Integer deleteResponseId = (Integer) CodeHelper.deleteCodeById(this.requestSpec, this.responseSpec, createResponseId,
|
||||
CodeHelper.RESPONSE_ID_ATTRIBUTE_NAME);
|
||||
assertEquals(createResponseId, deleteResponseId, "Verify code deleted");
|
||||
|
||||
// verify code deleted
|
||||
final HashMap deletedCodeAttributes = (HashMap) CodeHelper.getCodeById(this.requestSpec, this.generalResponseSpec, deleteResponseId,
|
||||
"");
|
||||
|
||||
Assertions.assertNotNull(deletedCodeAttributes);
|
||||
assertNull(deletedCodeAttributes.get(CodeHelper.CODE_ID_ATTRIBUTE_NAME), "Verify value of codeId");
|
||||
|
||||
assertNull(deletedCodeAttributes.get(CodeHelper.CODE_NAME_ATTRIBUTE_NAME), "Verify code name");
|
||||
assertNull(deletedCodeAttributes.get(CodeHelper.CODE_SYSTEM_DEFINED_ATTRIBUTE_NAME), "Verify system defined is false");
|
||||
|
||||
}
|
||||
|
||||
// @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("error.msg.code.systemdefined", error.get(0).get("userMessageGlobalisationCode"), "Cannot delete system-defined code");
|
||||
|
||||
// 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("error.msg.code.systemdefined", updateError.get(0).get("userMessageGlobalisationCode"),
|
||||
"Cannot update system-defined code");
|
||||
|
||||
}
|
||||
|
||||
// @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(2, codeValuesList.size(), "Number of code values returned matches number created");
|
||||
|
||||
// verify values of first code value
|
||||
final HashMap codeValuesAttributes1 = (HashMap) CodeHelper.getCodeValueById(this.requestSpec, this.responseSpec,
|
||||
createCodeResponseId, createCodeValueResponseId1, "");
|
||||
|
||||
Assertions.assertNotNull(codeValuesAttributes1);
|
||||
assertEquals(createCodeValueResponseId1, codeValuesAttributes1.get(CodeHelper.CODE_VALUE_ID_ATTRIBUTE_NAME),
|
||||
"Verify value of codeValueId");
|
||||
|
||||
assertEquals(codeValue1, codeValuesAttributes1.get(CodeHelper.CODE_VALUE_NAME_ATTRIBUTE_NAME), "Verify value of code name");
|
||||
|
||||
assertEquals(codeDescription1, codeValuesAttributes1.get(CodeHelper.CODE_VALUE_DESCRIPTION_ATTRIBUTE_NAME),
|
||||
"Verify value of code description");
|
||||
|
||||
assertEquals(codeValue1Position, codeValuesAttributes1.get(CodeHelper.CODE_VALUE_POSITION_ATTRIBUTE_NAME),
|
||||
"Verify position of code value");
|
||||
|
||||
// verify values of second code value
|
||||
final HashMap codeValuesAttributes2 = (HashMap) CodeHelper.getCodeValueById(this.requestSpec, this.responseSpec,
|
||||
createCodeResponseId, createCodeValueResponseId2, "");
|
||||
|
||||
Assertions.assertNotNull(codeValuesAttributes2);
|
||||
assertEquals(createCodeValueResponseId2, codeValuesAttributes2.get(CodeHelper.CODE_VALUE_ID_ATTRIBUTE_NAME),
|
||||
"Verify value of codeValueId");
|
||||
|
||||
assertEquals(codeValue2, codeValuesAttributes2.get(CodeHelper.CODE_VALUE_NAME_ATTRIBUTE_NAME), "Verify value of code name");
|
||||
|
||||
assertEquals(codeDescription2, codeValuesAttributes2.get(CodeHelper.CODE_VALUE_DESCRIPTION_ATTRIBUTE_NAME),
|
||||
"Verify value of code description");
|
||||
|
||||
assertEquals(codeValue2Position, codeValuesAttributes2.get(CodeHelper.CODE_VALUE_POSITION_ATTRIBUTE_NAME),
|
||||
"Verify position of code value");
|
||||
|
||||
// update code value 1
|
||||
final HashMap codeValueChanges = (HashMap) CodeHelper.updateCodeValue(this.requestSpec, this.responseSpec, createCodeResponseId,
|
||||
createCodeValueResponseId1, codeValue1 + "CHANGE", codeDescription1 + "CHANGE", 4, "changes");
|
||||
|
||||
assertEquals(codeValue1 + "CHANGE", codeValueChanges.get("name"), "Verify changed code value name");
|
||||
|
||||
assertEquals(codeDescription1 + "CHANGE", codeValueChanges.get("description"), "Verify changed code value description");
|
||||
|
||||
// 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(1, deletedCodeValuesList.size(), "Number of code values is 1");
|
||||
|
||||
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(deletedCodeValueAttributes2.get(0).get(CommonConstants.RESPONSE_ERROR_MESSAGE_CODE), "error.msg.codevalue.id.invalid");
|
||||
|
||||
final List<HashMap> deletedCodeValuesList1 = (List) CodeHelper.getCodeValuesForCode(this.requestSpec, this.responseSpec,
|
||||
createCodeResponseId, "");
|
||||
|
||||
assertEquals(0, deletedCodeValuesList1.size(), "Number of code values is 0");
|
||||
|
||||
}
|
||||
|
||||
@Disabled
|
||||
@Test
|
||||
public void testCodeValuesAssignedToTable() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+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;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class TemplateIntegrationTest {
|
||||
|
||||
private static final String GET_TEMPLATES_URL = "/fineract-provider/api/v1/templates?tenantIdentifier=default";
|
||||
|
||||
private static final String RESPONSE_ATTRIBUTE_NAME = "name";
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
|
||||
@BeforeEach
|
||||
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();
|
||||
}
|
||||
|
||||
@Disabled
|
||||
@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, GET_TEMPLATES_URL, "");
|
||||
final int entriesBeforeTest = get.size();
|
||||
|
||||
final Integer id = Utils.performServerPost(this.requestSpec, this.responseSpec, GET_TEMPLATES_URL, new Gson().toJson(map),
|
||||
"resourceId");
|
||||
|
||||
final String templateUrlForId = String.format("/fineract-provider/api/v1/templates/%s?tenantIdentifier=default", id);
|
||||
|
||||
final String getrequest2 = Utils.performServerGet(this.requestSpec, this.responseSpec, templateUrlForId, RESPONSE_ATTRIBUTE_NAME);
|
||||
|
||||
Assertions.assertTrue(getrequest2.equals("foo"));
|
||||
|
||||
Utils.performServerDelete(this.requestSpec, this.responseSpec, templateUrlForId, "");
|
||||
|
||||
get = Utils.performServerGet(this.requestSpec, this.responseSpec, GET_TEMPLATES_URL, "");
|
||||
final int entriesAfterTest = get.size();
|
||||
|
||||
Assertions.assertEquals(entriesBeforeTest, entriesAfterTest);
|
||||
}
|
||||
}
|
||||
+174
@@ -0,0 +1,174 @@
|
||||
/**
|
||||
* 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 io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.util.ArrayList;
|
||||
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.organisation.StaffHelper;
|
||||
import org.apache.fineract.integrationtests.useradministration.roles.RolesHelper;
|
||||
import org.apache.fineract.integrationtests.useradministration.users.UserHelper;
|
||||
import org.apache.fineract.useradministration.service.AppUserConstants;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class UserAdministrationTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(UserAdministrationTest.class);
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private List<Integer> transientUsers = new ArrayList<>();
|
||||
|
||||
private ResponseSpecification expectStatusCode(int code) {
|
||||
return new ResponseSpecBuilder().expectStatusCode(code).build();
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
Utils.initializeRESTAssured();
|
||||
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
|
||||
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
|
||||
this.responseSpec = expectStatusCode(200);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
for (Integer userId : this.transientUsers) {
|
||||
UserHelper.deleteUser(this.requestSpec, this.responseSpec, userId);
|
||||
}
|
||||
this.transientUsers.clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateNewUserBlocksDuplicateUsername() {
|
||||
|
||||
final Integer roleId = RolesHelper.createRole(this.requestSpec, this.responseSpec);
|
||||
Assertions.assertNotNull(roleId);
|
||||
|
||||
final Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
|
||||
Assertions.assertNotNull(staffId);
|
||||
|
||||
final Integer userId = (Integer) UserHelper.createUser(this.requestSpec, this.responseSpec, roleId, staffId, "alphabet",
|
||||
"resourceId");
|
||||
Assertions.assertNotNull(userId);
|
||||
this.transientUsers.add(userId);
|
||||
|
||||
final List errors = (List) UserHelper.createUser(this.requestSpec, expectStatusCode(403), roleId, staffId, "alphabet", "errors");
|
||||
Map reason = (Map) errors.get(0);
|
||||
LOG.info("Reason: {}", reason.get("defaultUserMessage"));
|
||||
LOG.info("Code: {}", reason.get("userMessageGlobalisationCode"));
|
||||
Assertions.assertEquals("User with username alphabet already exists.", reason.get("defaultUserMessage"));
|
||||
Assertions.assertEquals("error.msg.user.duplicate.username", reason.get("userMessageGlobalisationCode"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateUserAcceptsNewOrSameUsername() {
|
||||
final Integer roleId = RolesHelper.createRole(this.requestSpec, this.responseSpec);
|
||||
Assertions.assertNotNull(roleId);
|
||||
|
||||
final Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
|
||||
Assertions.assertNotNull(staffId);
|
||||
|
||||
final Integer userId = (Integer) UserHelper.createUser(this.requestSpec, this.responseSpec, roleId, staffId, "alphabet",
|
||||
"resourceId");
|
||||
Assertions.assertNotNull(userId);
|
||||
this.transientUsers.add(userId);
|
||||
|
||||
final Integer userId2 = (Integer) UserHelper.updateUser(this.requestSpec, this.responseSpec, userId, "renegade", "resourceId");
|
||||
Assertions.assertNotNull(userId2);
|
||||
|
||||
final Integer userId3 = (Integer) UserHelper.updateUser(this.requestSpec, this.responseSpec, userId, "renegade", "resourceId");
|
||||
Assertions.assertNotNull(userId3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateUserBlockDuplicateUsername() {
|
||||
final Integer roleId = RolesHelper.createRole(this.requestSpec, this.responseSpec);
|
||||
Assertions.assertNotNull(roleId);
|
||||
|
||||
final Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
|
||||
Assertions.assertNotNull(staffId);
|
||||
|
||||
final Integer userId = (Integer) UserHelper.createUser(this.requestSpec, this.responseSpec, roleId, staffId, "alphabet",
|
||||
"resourceId");
|
||||
Assertions.assertNotNull(userId);
|
||||
this.transientUsers.add(userId);
|
||||
|
||||
final Integer userId2 = (Integer) UserHelper.createUser(this.requestSpec, this.responseSpec, roleId, staffId, "bilingual",
|
||||
"resourceId");
|
||||
Assertions.assertNotNull(userId2);
|
||||
this.transientUsers.add(userId2);
|
||||
|
||||
final List errors = (List) UserHelper.updateUser(this.requestSpec, expectStatusCode(403), userId2, "alphabet", "errors");
|
||||
Map reason = (Map) errors.get(0);
|
||||
Assertions.assertEquals("User with username alphabet already exists.", reason.get("defaultUserMessage"));
|
||||
Assertions.assertEquals("error.msg.user.duplicate.username", reason.get("userMessageGlobalisationCode"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateNewUserBlocksDuplicateClientId() {
|
||||
final Integer roleId = RolesHelper.createRole(this.requestSpec, this.responseSpec);
|
||||
Assertions.assertNotNull(roleId);
|
||||
|
||||
final Integer staffId = StaffHelper.createStaff(this.requestSpec, this.responseSpec);
|
||||
Assertions.assertNotNull(staffId);
|
||||
|
||||
final Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
Assertions.assertNotNull(clientId);
|
||||
|
||||
final Integer userId = (Integer) UserHelper.createUserForSelfService(this.requestSpec, this.responseSpec, roleId, staffId, clientId,
|
||||
"resourceId");
|
||||
Assertions.assertNotNull(userId);
|
||||
this.transientUsers.add(userId);
|
||||
|
||||
final List errors = (List) UserHelper.createUserForSelfService(this.requestSpec, expectStatusCode(403), roleId, staffId, clientId,
|
||||
"errors");
|
||||
Map reason = (Map) errors.get(0);
|
||||
Assertions.assertEquals("Self Service User Id is already created. Go to Admin->Users to edit or delete the self-service user.",
|
||||
reason.get("defaultUserMessage"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteSystemUser() {
|
||||
final Integer userId = UserHelper.getUserId(requestSpec, responseSpec, AppUserConstants.SYSTEM_USER_NAME);
|
||||
Assertions.assertNotNull(userId);
|
||||
|
||||
UserHelper.deleteUser(requestSpec, expectStatusCode(403), userId.intValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testModifySystemUser() {
|
||||
final Integer userId = UserHelper.getUserId(requestSpec, responseSpec, AppUserConstants.SYSTEM_USER_NAME);
|
||||
Assertions.assertNotNull(userId);
|
||||
|
||||
final List errors = (List) UserHelper.updateUser(this.requestSpec, expectStatusCode(403), userId, "systemtest", "errors");
|
||||
}
|
||||
}
|
||||
Executable
+68
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* 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.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
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.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public class WorkingDaysTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
private ResponseSpecification generalResponseSpec;
|
||||
|
||||
@BeforeEach
|
||||
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);
|
||||
Assertions.assertNotNull(response.get("resourceId"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateWorkingDaysWithWrongRecurrencePattern() {
|
||||
final List<HashMap> error = (List) WorkingDaysHelper.updateWorkingDaysWithWrongRecurrence(requestSpec, generalResponseSpec,
|
||||
CommonConstants.RESPONSE_ERROR);
|
||||
assertEquals("error.msg.recurring.rule.parsing.error", error.get(0).get("userMessageGlobalisationCode"),
|
||||
"Verify wrong recurrence pattern error");
|
||||
}
|
||||
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* 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.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
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.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public class XBRLIntegrationTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(XBRLIntegrationTest.class);
|
||||
private RequestSpecification requestSpec;
|
||||
private ResponseSpecification responseSpec;
|
||||
|
||||
private XBRLIntegrationTestHelper xbrlHelper;
|
||||
|
||||
@BeforeEach
|
||||
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) {
|
||||
LOG.info("--------------------VERIFYING TAXONOMY LIST--------------------------");
|
||||
assertEquals("AdministrativeExpense", taxonomyList.get(0).get("name"), "Checking for the 1st taxonomy");
|
||||
}
|
||||
|
||||
}
|
||||
+158
@@ -0,0 +1,158 @@
|
||||
/**
|
||||
* 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.bulkimport.importhandler.client;
|
||||
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import org.apache.fineract.infrastructure.bulkimport.constants.ClientEntityConstants;
|
||||
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
|
||||
import org.apache.fineract.infrastructure.bulkimport.data.GlobalEntityType;
|
||||
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||
import org.apache.fineract.integrationtests.common.OfficeHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.organisation.StaffHelper;
|
||||
import org.apache.fineract.integrationtests.common.system.CodeHelper;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ClientEntityImportHandlerTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ClientEntityImportHandlerTest.class);
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
|
||||
@BeforeEach
|
||||
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 testClientImport() throws InterruptedException, IOException, ParseException {
|
||||
|
||||
// in order to populate helper sheets
|
||||
requestSpec.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
|
||||
Integer outcome_staff_creation = StaffHelper.createStaff(requestSpec, responseSpec);
|
||||
Assertions.assertNotNull(outcome_staff_creation, "Could not create staff");
|
||||
|
||||
// in order to populate helper sheets
|
||||
OfficeHelper officeHelper = new OfficeHelper(requestSpec, responseSpec);
|
||||
Integer outcome_office_creation = officeHelper.createOffice("02 May 2000");
|
||||
Assertions.assertNotNull(outcome_office_creation, "Could not create office");
|
||||
|
||||
// in order to populate helper columns in client entity sheet
|
||||
// create constitution
|
||||
CodeHelper.retrieveOrCreateCodeValue(24, requestSpec, responseSpec);
|
||||
// create client classification
|
||||
CodeHelper.retrieveOrCreateCodeValue(17, requestSpec, responseSpec);
|
||||
// create client types
|
||||
CodeHelper.retrieveOrCreateCodeValue(16, requestSpec, responseSpec);
|
||||
// create Address types
|
||||
CodeHelper.retrieveOrCreateCodeValue(29, requestSpec, responseSpec);
|
||||
// create State
|
||||
CodeHelper.retrieveOrCreateCodeValue(27, requestSpec, responseSpec);
|
||||
// create Country
|
||||
CodeHelper.retrieveOrCreateCodeValue(28, requestSpec, responseSpec);
|
||||
// create Main business line
|
||||
CodeHelper.retrieveOrCreateCodeValue(25, requestSpec, responseSpec);
|
||||
|
||||
ClientHelper clientHelper = new ClientHelper(requestSpec, responseSpec);
|
||||
Workbook workbook = clientHelper.getClientEntityWorkbook(GlobalEntityType.CLIENTS_ENTTTY, "dd MMMM yyyy");
|
||||
|
||||
// insert dummy data into client entity sheet
|
||||
Sheet clientEntitySheet = workbook.getSheet(TemplatePopulateImportConstants.CLIENT_ENTITY_SHEET_NAME);
|
||||
Row firstClientRow = clientEntitySheet.getRow(1);
|
||||
firstClientRow.createCell(ClientEntityConstants.NAME_COL).setCellValue(Utils.randomNameGenerator("C_E_", 6));
|
||||
Sheet staffSheet = workbook.getSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME);
|
||||
firstClientRow.createCell(ClientEntityConstants.OFFICE_NAME_COL).setCellValue(staffSheet.getRow(1).getCell(0).getStringCellValue());
|
||||
firstClientRow.createCell(ClientEntityConstants.STAFF_NAME_COL).setCellValue(staffSheet.getRow(1).getCell(1).getStringCellValue());
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd MMMM yyyy");
|
||||
Date incoporationDate = simpleDateFormat.parse("14 May 2001");
|
||||
firstClientRow.createCell(ClientEntityConstants.INCOPORATION_DATE_COL).setCellValue(incoporationDate);
|
||||
Date validTill = simpleDateFormat.parse("14 May 2019");
|
||||
firstClientRow.createCell(ClientEntityConstants.INCOPORATION_VALID_TILL_COL).setCellValue(validTill);
|
||||
firstClientRow.createCell(ClientEntityConstants.MOBILE_NO_COL).setCellValue(Utils.randomNumberGenerator(7));
|
||||
firstClientRow.createCell(ClientEntityConstants.CLIENT_TYPE_COL)
|
||||
.setCellValue(clientEntitySheet.getRow(1).getCell(ClientEntityConstants.LOOKUP_CLIENT_TYPES).getStringCellValue());
|
||||
firstClientRow.createCell(ClientEntityConstants.CLIENT_CLASSIFICATION_COL)
|
||||
.setCellValue(clientEntitySheet.getRow(1).getCell(ClientEntityConstants.LOOKUP_CLIENT_CLASSIFICATION).getStringCellValue());
|
||||
firstClientRow.createCell(ClientEntityConstants.INCOPORATION_NUMBER_COL).setCellValue(Utils.randomNumberGenerator(6));
|
||||
firstClientRow.createCell(ClientEntityConstants.MAIN_BUSINESS_LINE)
|
||||
.setCellValue(clientEntitySheet.getRow(1).getCell(ClientEntityConstants.LOOKUP_MAIN_BUSINESS_LINE).getStringCellValue());
|
||||
firstClientRow.createCell(ClientEntityConstants.CONSTITUTION_COL)
|
||||
.setCellValue(clientEntitySheet.getRow(1).getCell(ClientEntityConstants.LOOKUP_CONSTITUTION_COL).getStringCellValue());
|
||||
firstClientRow.createCell(ClientEntityConstants.ACTIVE_COL).setCellValue("False");
|
||||
Date submittedDate = simpleDateFormat.parse("28 September 2017");
|
||||
firstClientRow.createCell(ClientEntityConstants.SUBMITTED_ON_COL).setCellValue(submittedDate);
|
||||
firstClientRow.createCell(ClientEntityConstants.ADDRESS_ENABLED).setCellValue("False");
|
||||
|
||||
File directory = new File(System.getProperty("user.home") + File.separator + "Fineract" + File.separator + "bulkimport"
|
||||
+ File.separator + "integration_tests" + File.separator + "importhandler" + File.separator + "client");
|
||||
if (!directory.exists()) {
|
||||
directory.mkdirs();
|
||||
}
|
||||
File file = new File(directory + File.separator + "ClientEntity.xls");
|
||||
OutputStream outputStream = new FileOutputStream(file);
|
||||
workbook.write(outputStream);
|
||||
outputStream.close();
|
||||
|
||||
String importDocumentId = clientHelper.importClientEntityTemplate(file);
|
||||
file.delete();
|
||||
Assertions.assertNotNull(importDocumentId);
|
||||
|
||||
// Wait for the creation of output excel
|
||||
Thread.sleep(10000);
|
||||
|
||||
// check status column of output excel
|
||||
String location = clientHelper.getOutputTemplateLocation(importDocumentId);
|
||||
FileInputStream fileInputStream = new FileInputStream(location);
|
||||
Workbook outputWorkbook = new HSSFWorkbook(fileInputStream);
|
||||
Sheet outputClientEntitySheet = outputWorkbook.getSheet(TemplatePopulateImportConstants.CLIENT_ENTITY_SHEET_NAME);
|
||||
Row row = outputClientEntitySheet.getRow(1);
|
||||
|
||||
LOG.info("Output location: {}", location);
|
||||
LOG.info("Failure reason column: {}", row.getCell(ClientEntityConstants.STATUS_COL).getStringCellValue());
|
||||
|
||||
Assertions.assertEquals("Imported", row.getCell(ClientEntityConstants.STATUS_COL).getStringCellValue());
|
||||
outputWorkbook.close();
|
||||
}
|
||||
}
|
||||
+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.bulkimport.importhandler.loan;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.path.json.JsonPath;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import org.apache.fineract.infrastructure.bulkimport.constants.LoanConstants;
|
||||
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
|
||||
import org.apache.fineract.integrationtests.common.GroupHelper;
|
||||
import org.apache.fineract.integrationtests.common.OfficeDomain;
|
||||
import org.apache.fineract.integrationtests.common.OfficeHelper;
|
||||
import org.apache.fineract.integrationtests.common.PaymentTypeHelper;
|
||||
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.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
|
||||
import org.apache.fineract.integrationtests.common.organisation.StaffHelper;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class LoanImportHandlerTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(LoanImportHandlerTest.class);
|
||||
private static final String CREATE_CLIENT_URL = "/fineract-provider/api/v1/clients?" + Utils.TENANT_IDENTIFIER;
|
||||
public static final String DATE_FORMAT = "dd MMMM yyyy";
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
|
||||
@BeforeEach
|
||||
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 testLoanImport() throws InterruptedException, IOException, ParseException {
|
||||
requestSpec.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
|
||||
|
||||
// in order to populate helper sheets
|
||||
OfficeHelper officeHelper = new OfficeHelper(requestSpec, responseSpec);
|
||||
Integer outcome_office_creation = officeHelper.createOffice("02 May 2000");
|
||||
Assertions.assertNotNull(outcome_office_creation, "Could not create office");
|
||||
|
||||
OfficeDomain office = officeHelper.retrieveOfficeByID(outcome_office_creation);
|
||||
Assertions.assertNotNull(office, "Could not retrieve created office");
|
||||
|
||||
String firstName = Utils.randomNameGenerator("Client_FirstName_", 5);
|
||||
String lastName = Utils.randomNameGenerator("Client_LastName_", 4);
|
||||
String externalId = Utils.randomStringGenerator("ID_", 7, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
|
||||
final HashMap<String, String> clientMap = new HashMap<>();
|
||||
clientMap.put("officeId", outcome_office_creation.toString());
|
||||
clientMap.put("firstname", firstName);
|
||||
clientMap.put("lastname", lastName);
|
||||
clientMap.put("externalId", externalId);
|
||||
clientMap.put("dateFormat", DATE_FORMAT);
|
||||
clientMap.put("locale", "en");
|
||||
clientMap.put("active", "true");
|
||||
clientMap.put("activationDate", "04 March 2011");
|
||||
|
||||
Integer outcome_client_creation = Utils.performServerPost(requestSpec, responseSpec, CREATE_CLIENT_URL,
|
||||
new Gson().toJson(clientMap), "clientId");
|
||||
Assertions.assertNotNull(outcome_client_creation, "Could not create client");
|
||||
|
||||
// in order to populate helper sheets
|
||||
Integer outcome_group_creation = GroupHelper.createGroup(requestSpec, responseSpec, true);
|
||||
Assertions.assertNotNull(outcome_group_creation, "Could not create group");
|
||||
|
||||
// in order to populate helper sheets
|
||||
Integer outcome_staff_creation = StaffHelper.createStaff(requestSpec, responseSpec);
|
||||
Assertions.assertNotNull(outcome_staff_creation, "Could not create staff");
|
||||
|
||||
Map<String, Object> staffMap = StaffHelper.getStaff(requestSpec, responseSpec, outcome_staff_creation);
|
||||
Assertions.assertNotNull(staffMap, "Could not retrieve created staff");
|
||||
|
||||
LoanTransactionHelper ltHelper = new LoanTransactionHelper(requestSpec, responseSpec);
|
||||
LoanProductTestBuilder loanProductTestBuilder = new LoanProductTestBuilder();
|
||||
String jsonLoanProduct = loanProductTestBuilder.build(null);
|
||||
Integer outcome_lp_creation = ltHelper.getLoanProductId(jsonLoanProduct);
|
||||
Assertions.assertNotNull(outcome_lp_creation, "Could not create Loan Product");
|
||||
|
||||
String loanProductStr = ltHelper.getLoanProductDetails(requestSpec, responseSpec, outcome_lp_creation);
|
||||
Assertions.assertNotNull("Could not get created Loan Product", loanProductStr);
|
||||
JsonPath loanProductJson = JsonPath.from(loanProductStr);
|
||||
|
||||
String fundName = Utils.randomNameGenerator("", 9);
|
||||
FundsHelper fh = FundsHelper.create(fundName).externalId("fund-" + fundName).build();
|
||||
Integer outcome_fund_creation = FundsResourceHandler.createFund(new Gson().toJson(fh), requestSpec, responseSpec);
|
||||
Assertions.assertNotNull(outcome_fund_creation, "Could not create Fund");
|
||||
|
||||
String paymentTypeName = PaymentTypeHelper.randomNameGenerator("P_T", 5);
|
||||
String paymentTypeDescription = PaymentTypeHelper.randomNameGenerator("PT_Desc", 15);
|
||||
Integer outcome_payment_creation = PaymentTypeHelper.createPaymentType(requestSpec, responseSpec, paymentTypeName,
|
||||
paymentTypeDescription, true, 1);
|
||||
Assertions.assertNotNull(outcome_payment_creation, "Could not create payment type");
|
||||
|
||||
LoanTransactionHelper loanTransactionHelper = new LoanTransactionHelper(requestSpec, responseSpec);
|
||||
Workbook workbook = loanTransactionHelper.getLoanWorkbook("dd MMMM yyyy");
|
||||
|
||||
// insert dummy data into loan Sheet
|
||||
Sheet loanSheet = workbook.getSheet(TemplatePopulateImportConstants.LOANS_SHEET_NAME);
|
||||
Row firstLoanRow = loanSheet.getRow(1);
|
||||
firstLoanRow.createCell(LoanConstants.OFFICE_NAME_COL).setCellValue(office.getName());
|
||||
firstLoanRow.createCell(LoanConstants.LOAN_TYPE_COL).setCellValue("Individual");
|
||||
firstLoanRow.createCell(LoanConstants.CLIENT_NAME_COL)
|
||||
.setCellValue(firstName + " " + lastName + "(" + outcome_client_creation + ")");
|
||||
firstLoanRow.createCell(LoanConstants.CLIENT_EXTERNAL_ID).setCellValue(externalId);
|
||||
firstLoanRow.createCell(LoanConstants.PRODUCT_COL).setCellValue(loanProductJson.getString("name"));
|
||||
firstLoanRow.createCell(LoanConstants.LOAN_OFFICER_NAME_COL).setCellValue((String) staffMap.get("displayName"));
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd MMMM yyyy");
|
||||
Date date = simpleDateFormat.parse("13 May 2017");
|
||||
firstLoanRow.createCell(LoanConstants.SUBMITTED_ON_DATE_COL).setCellValue(date);
|
||||
firstLoanRow.createCell(LoanConstants.APPROVED_DATE_COL).setCellValue(date);
|
||||
firstLoanRow.createCell(LoanConstants.DISBURSED_DATE_COL).setCellValue(date);
|
||||
firstLoanRow.createCell(LoanConstants.DISBURSED_PAYMENT_TYPE_COL).setCellValue(paymentTypeName);
|
||||
firstLoanRow.createCell(LoanConstants.FUND_NAME_COL).setCellValue(fundName);
|
||||
firstLoanRow.createCell(LoanConstants.PRINCIPAL_COL).setCellValue(loanProductJson.getFloat("principal"));
|
||||
firstLoanRow.createCell(LoanConstants.NO_OF_REPAYMENTS_COL).setCellValue(loanProductJson.getInt("numberOfRepayments"));
|
||||
firstLoanRow.createCell(LoanConstants.REPAID_EVERY_COL).setCellValue(loanProductJson.getInt("repaymentEvery"));
|
||||
firstLoanRow.createCell(LoanConstants.REPAID_EVERY_FREQUENCY_COL)
|
||||
.setCellValue(loanProductJson.getString("repaymentFrequencyType.value"));
|
||||
firstLoanRow.createCell(LoanConstants.LOAN_TERM_COL)
|
||||
.setCellValue(loanProductJson.getInt("repaymentEvery") * loanProductJson.getInt("numberOfRepayments"));
|
||||
firstLoanRow.createCell(LoanConstants.LOAN_TERM_FREQUENCY_COL)
|
||||
.setCellValue(loanProductJson.getString("repaymentFrequencyType.value"));
|
||||
firstLoanRow.createCell(LoanConstants.NOMINAL_INTEREST_RATE_COL).setCellValue(loanProductJson.getDouble("interestRatePerPeriod"));
|
||||
firstLoanRow.createCell(LoanConstants.NOMINAL_INTEREST_RATE_FREQUENCY_COL)
|
||||
.setCellValue(loanProductJson.getString("interestRateFrequencyType.value"));
|
||||
firstLoanRow.createCell(LoanConstants.AMORTIZATION_COL).setCellValue(loanProductJson.getString("amortizationType.value"));
|
||||
firstLoanRow.createCell(LoanConstants.INTEREST_METHOD_COL).setCellValue(loanProductJson.getString("interestType.value"));
|
||||
firstLoanRow.createCell(LoanConstants.INTEREST_CALCULATION_PERIOD_COL)
|
||||
.setCellValue(loanProductJson.getString("interestCalculationPeriodType.value"));
|
||||
firstLoanRow.createCell(LoanConstants.ARREARS_TOLERANCE_COL).setCellValue(0);
|
||||
firstLoanRow.createCell(LoanConstants.REPAYMENT_STRATEGY_COL)
|
||||
.setCellValue(loanProductJson.getString("transactionProcessingStrategyName"));
|
||||
firstLoanRow.createCell(LoanConstants.GRACE_ON_PRINCIPAL_PAYMENT_COL).setCellValue(0);
|
||||
firstLoanRow.createCell(LoanConstants.GRACE_ON_INTEREST_PAYMENT_COL).setCellValue(0);
|
||||
firstLoanRow.createCell(LoanConstants.GRACE_ON_INTEREST_CHARGED_COL).setCellValue(0);
|
||||
firstLoanRow.createCell(LoanConstants.FIRST_REPAYMENT_COL).setCellValue(date);
|
||||
firstLoanRow.createCell(LoanConstants.TOTAL_AMOUNT_REPAID_COL).setCellValue(6000);
|
||||
firstLoanRow.createCell(LoanConstants.LAST_REPAYMENT_DATE_COL).setCellValue(date);
|
||||
firstLoanRow.createCell(LoanConstants.REPAYMENT_TYPE_COL).setCellValue(paymentTypeName);
|
||||
|
||||
String currentdirectory = new File("").getAbsolutePath();
|
||||
File directory = new File(currentdirectory + File.separator + "src" + File.separator + "integrationTest" + File.separator
|
||||
+ "resources" + File.separator + "bulkimport" + File.separator + "importhandler" + File.separator + "loan");
|
||||
if (!directory.exists()) {
|
||||
directory.mkdirs();
|
||||
}
|
||||
File file = new File(directory + File.separator + "Loan.xls");
|
||||
OutputStream outputStream = new FileOutputStream(file);
|
||||
workbook.write(outputStream);
|
||||
outputStream.close();
|
||||
|
||||
String importDocumentId = loanTransactionHelper.importLoanTemplate(file);
|
||||
file.delete();
|
||||
Assertions.assertNotNull(importDocumentId);
|
||||
|
||||
// Wait for the creation of output excel
|
||||
Thread.sleep(10000);
|
||||
|
||||
// check status column of output excel
|
||||
String location = loanTransactionHelper.getOutputTemplateLocation(importDocumentId);
|
||||
FileInputStream fileInputStream = new FileInputStream(location);
|
||||
Workbook outputworkbook = new HSSFWorkbook(fileInputStream);
|
||||
Sheet outputLoanSheet = outputworkbook.getSheet(TemplatePopulateImportConstants.LOANS_SHEET_NAME);
|
||||
Row row = outputLoanSheet.getRow(1);
|
||||
|
||||
LOG.info("Output location: {}", location);
|
||||
LOG.info("Failure reason column: {}", row.getCell(LoanConstants.FAILURE_REPORT_COL).getStringCellValue());
|
||||
|
||||
Assertions.assertEquals("Imported", row.getCell(LoanConstants.STATUS_COL).getStringCellValue());
|
||||
outputworkbook.close();
|
||||
}
|
||||
}
|
||||
+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.bulkimport.importhandler.office;
|
||||
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import org.apache.fineract.infrastructure.bulkimport.constants.OfficeConstants;
|
||||
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
|
||||
import org.apache.fineract.integrationtests.common.OfficeHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class OfficeImportHandlerTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(OfficeImportHandlerTest.class);
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
Utils.initializeRESTAssured();
|
||||
this.requestSpec = new RequestSpecBuilder().build();
|
||||
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
|
||||
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOfficeImport() throws IOException, InterruptedException, NoSuchFieldException, ParseException {
|
||||
OfficeHelper officeHelper = new OfficeHelper(requestSpec, responseSpec);
|
||||
Workbook workbook = officeHelper.getOfficeWorkBook("dd MMMM yyyy");
|
||||
|
||||
// insert dummy data into excel
|
||||
Sheet sheet = workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME);
|
||||
Row firstOfficeRow = sheet.getRow(1);
|
||||
firstOfficeRow.createCell(OfficeConstants.OFFICE_NAME_COL).setCellValue(Utils.randomNameGenerator("Test_Off_", 6));
|
||||
firstOfficeRow.createCell(OfficeConstants.PARENT_OFFICE_NAME_COL)
|
||||
.setCellValue(firstOfficeRow.getCell(OfficeConstants.LOOKUP_OFFICE_COL).getStringCellValue());
|
||||
firstOfficeRow.createCell(OfficeConstants.PARENT_OFFICE_ID_COL)
|
||||
.setCellValue(firstOfficeRow.getCell(OfficeConstants.LOOKUP_OFFICE_ID_COL).getNumericCellValue());
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd MMMM yyyy");
|
||||
Date date = simpleDateFormat.parse("14 May 2001");
|
||||
firstOfficeRow.createCell(OfficeConstants.OPENED_ON_COL).setCellValue(date);
|
||||
|
||||
String currentdirectory = new File("").getAbsolutePath();
|
||||
File directory = new File(currentdirectory + File.separator + "src" + File.separator + "integrationTest" + File.separator
|
||||
+ "resources" + File.separator + "bulkimport" + File.separator + "importhandler" + File.separator + "office");
|
||||
if (!directory.exists()) {
|
||||
directory.mkdirs();
|
||||
}
|
||||
File file = new File(directory + File.separator + "Office.xls");
|
||||
OutputStream outputStream = new FileOutputStream(file);
|
||||
workbook.write(outputStream);
|
||||
outputStream.close();
|
||||
|
||||
String importDocumentId = officeHelper.importOfficeTemplate(file);
|
||||
file.delete();
|
||||
Assertions.assertNotNull(importDocumentId);
|
||||
|
||||
// Wait for the creation of output excel
|
||||
Thread.sleep(10000);
|
||||
|
||||
// check status column of output excel
|
||||
String location = officeHelper.getOutputTemplateLocation(importDocumentId);
|
||||
FileInputStream fileInputStream = new FileInputStream(location);
|
||||
Workbook outputWorkbook = new HSSFWorkbook(fileInputStream);
|
||||
Sheet officeSheet = outputWorkbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME);
|
||||
Row row = officeSheet.getRow(1);
|
||||
|
||||
LOG.info("Output location: {}", location);
|
||||
LOG.info("Failure reason column: {}", row.getCell(OfficeConstants.STATUS_COL).getStringCellValue());
|
||||
|
||||
Assertions.assertEquals("Imported", row.getCell(OfficeConstants.STATUS_COL).getStringCellValue());
|
||||
outputWorkbook.close();
|
||||
}
|
||||
}
|
||||
+196
@@ -0,0 +1,196 @@
|
||||
/**
|
||||
* 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.bulkimport.importhandler.savings;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import org.apache.fineract.infrastructure.bulkimport.constants.SavingsConstants;
|
||||
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
|
||||
import org.apache.fineract.integrationtests.common.GroupHelper;
|
||||
import org.apache.fineract.integrationtests.common.OfficeDomain;
|
||||
import org.apache.fineract.integrationtests.common.OfficeHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.organisation.StaffHelper;
|
||||
import org.apache.fineract.integrationtests.common.savings.SavingsAccountHelper;
|
||||
import org.apache.fineract.integrationtests.common.savings.SavingsProductHelper;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class SavingsImportHandlerTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(SavingsImportHandlerTest.class);
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
|
||||
private static final String CREATE_CLIENT_URL = "/fineract-provider/api/v1/clients?" + Utils.TENANT_IDENTIFIER;
|
||||
public static final String DATE_FORMAT = "dd MMMM yyyy";
|
||||
|
||||
@BeforeEach
|
||||
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 testSavingsImport() throws InterruptedException, IOException, ParseException {
|
||||
|
||||
requestSpec.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
|
||||
// in order to populate helper sheets
|
||||
OfficeHelper officeHelper = new OfficeHelper(requestSpec, responseSpec);
|
||||
Integer outcome_office_creation = officeHelper.createOffice("02 May 2000");
|
||||
Assertions.assertNotNull(outcome_office_creation, "Could not create office");
|
||||
|
||||
OfficeDomain office = officeHelper.retrieveOfficeByID(outcome_office_creation);
|
||||
Assertions.assertNotNull(office, "Could not retrieve created office");
|
||||
|
||||
String firstName = Utils.randomNameGenerator("Client_FirstName_", 5);
|
||||
String lastName = Utils.randomNameGenerator("Client_LastName_", 4);
|
||||
String externalId = Utils.randomStringGenerator("ID_", 7, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
|
||||
final HashMap<String, String> clientMap = new HashMap<>();
|
||||
clientMap.put("officeId", outcome_office_creation.toString());
|
||||
clientMap.put("firstname", firstName);
|
||||
clientMap.put("lastname", lastName);
|
||||
clientMap.put("externalId", externalId);
|
||||
clientMap.put("dateFormat", DATE_FORMAT);
|
||||
clientMap.put("locale", "en");
|
||||
clientMap.put("active", "true");
|
||||
clientMap.put("activationDate", "04 March 2011");
|
||||
|
||||
Integer outcome_client_creation = Utils.performServerPost(requestSpec, responseSpec, CREATE_CLIENT_URL,
|
||||
new Gson().toJson(clientMap), "clientId");
|
||||
Assertions.assertNotNull(outcome_client_creation, "Could not create client");
|
||||
|
||||
// in order to populate helper sheets
|
||||
Integer outcome_group_creation = GroupHelper.createGroup(requestSpec, responseSpec, true);
|
||||
Assertions.assertNotNull(outcome_group_creation, "Could not create group");
|
||||
|
||||
// in order to populate helper sheets
|
||||
Integer outcome_staff_creation = StaffHelper.createStaff(requestSpec, responseSpec);
|
||||
Assertions.assertNotNull(outcome_staff_creation, "Could not create staff");
|
||||
|
||||
Map<String, Object> staffMap = StaffHelper.getStaff(requestSpec, responseSpec, outcome_staff_creation);
|
||||
Assertions.assertNotNull(staffMap, "Could not retrieve created staff");
|
||||
|
||||
SavingsProductHelper savingsProductHelper = new SavingsProductHelper();
|
||||
String jsonSavingsProduct = savingsProductHelper.build();
|
||||
Integer outcome_sp_creaction = SavingsProductHelper.createSavingsProduct(jsonSavingsProduct, requestSpec, responseSpec);
|
||||
Assertions.assertNotNull(outcome_sp_creaction, "Could not create Savings product");
|
||||
|
||||
SavingsAccountHelper savingsAccountHelper = new SavingsAccountHelper(requestSpec, responseSpec);
|
||||
Workbook workbook = savingsAccountHelper.getSavingsWorkbook("dd MMMM yyyy");
|
||||
|
||||
// insert dummy data into Savings sheet
|
||||
Sheet savingsSheet = workbook.getSheet(TemplatePopulateImportConstants.SAVINGS_ACCOUNTS_SHEET_NAME);
|
||||
Row firstSavingsRow = savingsSheet.getRow(1);
|
||||
firstSavingsRow.createCell(SavingsConstants.OFFICE_NAME_COL).setCellValue(office.getName());
|
||||
firstSavingsRow.createCell(SavingsConstants.SAVINGS_TYPE_COL).setCellValue("Individual");
|
||||
firstSavingsRow.createCell(SavingsConstants.CLIENT_NAME_COL)
|
||||
.setCellValue(firstName + " " + lastName + "(" + outcome_client_creation + ")");
|
||||
Sheet savingsProductSheet = workbook.getSheet(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME);
|
||||
firstSavingsRow.createCell(SavingsConstants.PRODUCT_COL)
|
||||
.setCellValue(savingsProductSheet.getRow(1).getCell(1).getStringCellValue());
|
||||
firstSavingsRow.createCell(SavingsConstants.FIELD_OFFICER_NAME_COL).setCellValue((String) staffMap.get("displayName"));
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd MMMM yyyy");
|
||||
Date date = simpleDateFormat.parse("13 May 2017");
|
||||
firstSavingsRow.createCell(SavingsConstants.SUBMITTED_ON_DATE_COL).setCellValue(date);
|
||||
firstSavingsRow.createCell(SavingsConstants.APPROVED_DATE_COL).setCellValue(date);
|
||||
firstSavingsRow.createCell(SavingsConstants.ACTIVATION_DATE_COL).setCellValue(date);
|
||||
firstSavingsRow.createCell(SavingsConstants.CURRENCY_COL)
|
||||
.setCellValue(savingsProductSheet.getRow(1).getCell(10).getStringCellValue());
|
||||
firstSavingsRow.createCell(SavingsConstants.DECIMAL_PLACES_COL)
|
||||
.setCellValue(savingsProductSheet.getRow(1).getCell(11).getNumericCellValue());
|
||||
firstSavingsRow.createCell(SavingsConstants.IN_MULTIPLES_OF_COL)
|
||||
.setCellValue(savingsProductSheet.getRow(1).getCell(12).getNumericCellValue());
|
||||
firstSavingsRow.createCell(SavingsConstants.NOMINAL_ANNUAL_INTEREST_RATE_COL)
|
||||
.setCellValue(savingsProductSheet.getRow(1).getCell(2).getNumericCellValue());
|
||||
firstSavingsRow.createCell(SavingsConstants.INTEREST_COMPOUNDING_PERIOD_COL)
|
||||
.setCellValue(savingsProductSheet.getRow(1).getCell(3).getStringCellValue());
|
||||
firstSavingsRow.createCell(SavingsConstants.INTEREST_POSTING_PERIOD_COL)
|
||||
.setCellValue(savingsProductSheet.getRow(1).getCell(4).getStringCellValue());
|
||||
firstSavingsRow.createCell(SavingsConstants.INTEREST_CALCULATION_COL)
|
||||
.setCellValue(savingsProductSheet.getRow(1).getCell(5).getStringCellValue());
|
||||
firstSavingsRow.createCell(SavingsConstants.INTEREST_CALCULATION_DAYS_IN_YEAR_COL)
|
||||
.setCellValue(savingsProductSheet.getRow(1).getCell(6).getStringCellValue());
|
||||
firstSavingsRow.createCell(SavingsConstants.MIN_OPENING_BALANCE_COL).setCellValue(1000.0);
|
||||
firstSavingsRow.createCell(SavingsConstants.LOCKIN_PERIOD_COL).setCellValue(1);
|
||||
firstSavingsRow.createCell(SavingsConstants.LOCKIN_PERIOD_FREQUENCY_COL).setCellValue("Weeks");
|
||||
firstSavingsRow.createCell(SavingsConstants.APPLY_WITHDRAWAL_FEE_FOR_TRANSFERS).setCellValue("False");
|
||||
firstSavingsRow.createCell(SavingsConstants.ALLOW_OVER_DRAFT_COL).setCellValue("False");
|
||||
firstSavingsRow.createCell(SavingsConstants.OVER_DRAFT_LIMIT_COL)
|
||||
.setCellValue(savingsProductSheet.getRow(1).getCell(15).getNumericCellValue());
|
||||
|
||||
String currentdirectory = new File("").getAbsolutePath();
|
||||
File directory = new File(currentdirectory + File.separator + "src" + File.separator + "integrationTest" + File.separator
|
||||
+ "resources" + File.separator + "bulkimport" + File.separator + "importhandler" + File.separator + "savings");
|
||||
if (!directory.exists()) {
|
||||
directory.mkdirs();
|
||||
}
|
||||
File file = new File(directory + File.separator + "Savings.xls");
|
||||
OutputStream outputStream = new FileOutputStream(file);
|
||||
workbook.write(outputStream);
|
||||
outputStream.close();
|
||||
|
||||
String importDocumentId = savingsAccountHelper.importSavingsTemplate(file);
|
||||
file.delete();
|
||||
Assertions.assertNotNull(importDocumentId);
|
||||
|
||||
// Wait for the creation of output excel
|
||||
Thread.sleep(10000);
|
||||
|
||||
// check status column of output excel
|
||||
String location = savingsAccountHelper.getOutputTemplateLocation(importDocumentId);
|
||||
FileInputStream fileInputStream = new FileInputStream(location);
|
||||
Workbook Outputworkbook = new HSSFWorkbook(fileInputStream);
|
||||
Sheet OutputSavingsSheet = Outputworkbook.getSheet(TemplatePopulateImportConstants.SAVINGS_ACCOUNTS_SHEET_NAME);
|
||||
Row row = OutputSavingsSheet.getRow(1);
|
||||
|
||||
LOG.info("Output location: {}", location);
|
||||
LOG.info("Failure reason column: {}", row.getCell(SavingsConstants.STATUS_COL).getStringCellValue());
|
||||
|
||||
Assertions.assertEquals("Imported", row.getCell(SavingsConstants.STATUS_COL).getStringCellValue());
|
||||
Outputworkbook.close();
|
||||
}
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* 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.bulkimport.populator.client;
|
||||
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.io.IOException;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
|
||||
import org.apache.fineract.infrastructure.bulkimport.data.GlobalEntityType;
|
||||
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||
import org.apache.fineract.integrationtests.common.OfficeHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.organisation.StaffHelper;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class ClientEntityWorkbookPopulatorTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
Utils.initializeRESTAssured();
|
||||
this.requestSpec = new RequestSpecBuilder().build();
|
||||
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
|
||||
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClientEntityWorkbookPopulate() throws IOException {
|
||||
// in order to populate helper sheets
|
||||
requestSpec.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
|
||||
Integer outcome_staff_creation = StaffHelper.createStaff(requestSpec, responseSpec);
|
||||
Assertions.assertNotNull(outcome_staff_creation, "Could not create staff");
|
||||
|
||||
// in order to populate helper sheets
|
||||
OfficeHelper officeHelper = new OfficeHelper(requestSpec, responseSpec);
|
||||
Integer outcome_office_creation = officeHelper.createOffice("02 May 2000");
|
||||
Assertions.assertNotNull(outcome_office_creation, "Could not create office");
|
||||
|
||||
ClientHelper clientHelper = new ClientHelper(requestSpec, responseSpec);
|
||||
Workbook workbook = clientHelper.getClientEntityWorkbook(GlobalEntityType.CLIENTS_ENTTTY, "dd MMMM yyyy");
|
||||
Sheet officeSheet = workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME);
|
||||
Row firstOfficeRow = officeSheet.getRow(1);
|
||||
Assertions.assertNotNull(firstOfficeRow.getCell(1), "No offices found for given OfficeId ");
|
||||
Sheet staffSheet = workbook.getSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME);
|
||||
Row firstStaffRow = staffSheet.getRow(1);
|
||||
Assertions.assertNotNull(firstStaffRow.getCell(1), "No staff found for given staffId");
|
||||
}
|
||||
}
|
||||
+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.bulkimport.populator.loan;
|
||||
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.io.IOException;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
|
||||
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||
import org.apache.fineract.integrationtests.common.GroupHelper;
|
||||
import org.apache.fineract.integrationtests.common.OfficeHelper;
|
||||
import org.apache.fineract.integrationtests.common.PaymentTypeHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.funds.FundsResourceHandler;
|
||||
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.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class LoanWorkbookPopulatorTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
|
||||
@BeforeEach
|
||||
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 testLoanWorkbookPopulate() throws IOException {
|
||||
requestSpec.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
|
||||
// in order to populate helper sheets
|
||||
OfficeHelper officeHelper = new OfficeHelper(requestSpec, responseSpec);
|
||||
Integer outcome_office_creation = officeHelper.createOffice("02 May 2000");
|
||||
Assertions.assertNotNull(outcome_office_creation, "Could not create office");
|
||||
|
||||
// in order to populate helper sheets
|
||||
Integer outcome_client_creation = ClientHelper.createClient(requestSpec, responseSpec);
|
||||
Assertions.assertNotNull(outcome_client_creation, "Could not create client");
|
||||
|
||||
// in order to populate helper sheets
|
||||
Integer outcome_group_creation = GroupHelper.createGroup(requestSpec, responseSpec, true);
|
||||
Assertions.assertNotNull(outcome_group_creation, "Could not create group");
|
||||
|
||||
// in order to populate helper sheets
|
||||
Integer outcome_staff_creation = StaffHelper.createStaff(requestSpec, responseSpec);
|
||||
Assertions.assertNotNull(outcome_staff_creation, "Could not create staff");
|
||||
|
||||
LoanTransactionHelper loanTransactionHelper = new LoanTransactionHelper(requestSpec, responseSpec);
|
||||
LoanProductTestBuilder loanProductTestBuilder = new LoanProductTestBuilder();
|
||||
String jsonLoanProduct = loanProductTestBuilder.build(null);
|
||||
Integer outcome_lp_creaion = loanTransactionHelper.getLoanProductId(jsonLoanProduct);
|
||||
Assertions.assertNotNull(outcome_lp_creaion, "Could not create Loan Product");
|
||||
|
||||
String jsonFund = "{\n" + "\t\"name\": \"" + Utils.randomNameGenerator("Fund_Name", 9) + "\"\n" + "}";
|
||||
Integer outcome_fund_creation = FundsResourceHandler.createFund(jsonFund, requestSpec, responseSpec);
|
||||
Assertions.assertNotNull(outcome_fund_creation, "Could not create Fund");
|
||||
|
||||
String name = PaymentTypeHelper.randomNameGenerator("P_T", 5);
|
||||
String description = PaymentTypeHelper.randomNameGenerator("PT_Desc", 15);
|
||||
Boolean isCashPayment = true;
|
||||
Integer position = 1;
|
||||
Integer outcome_payment_creation = PaymentTypeHelper.createPaymentType(requestSpec, responseSpec, name, description, isCashPayment,
|
||||
position);
|
||||
Assertions.assertNotNull(outcome_payment_creation, "Could not create payment type");
|
||||
|
||||
Workbook workbook = loanTransactionHelper.getLoanWorkbook("dd MMMM yyyy");
|
||||
|
||||
Sheet officeSheet = workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME);
|
||||
Row firstOfficeRow = officeSheet.getRow(1);
|
||||
Assertions.assertNotNull(firstOfficeRow.getCell(1), "No offices found ");
|
||||
|
||||
Sheet clientSheet = workbook.getSheet(TemplatePopulateImportConstants.CLIENT_SHEET_NAME);
|
||||
Row firstClientRow = clientSheet.getRow(1);
|
||||
Assertions.assertNotNull(firstClientRow.getCell(1), "No clients found ");
|
||||
|
||||
Sheet groupSheet = workbook.getSheet(TemplatePopulateImportConstants.GROUP_SHEET_NAME);
|
||||
Row firstGroupRow = groupSheet.getRow(1);
|
||||
Assertions.assertNotNull(firstGroupRow.getCell(1), "No groups found ");
|
||||
|
||||
Sheet staffSheet = workbook.getSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME);
|
||||
Row firstStaffRow = staffSheet.getRow(1);
|
||||
Assertions.assertNotNull(firstStaffRow.getCell(1), "No staff found ");
|
||||
|
||||
Sheet productSheet = workbook.getSheet(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME);
|
||||
Row firstProductRow = productSheet.getRow(1);
|
||||
Assertions.assertNotNull(firstProductRow.getCell(1), "No products found ");
|
||||
|
||||
Sheet extrasSheet = workbook.getSheet(TemplatePopulateImportConstants.EXTRAS_SHEET_NAME);
|
||||
Row firstExtrasRow = extrasSheet.getRow(1);
|
||||
Assertions.assertNotNull(firstExtrasRow.getCell(1), "No Extras found ");
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* 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.bulkimport.populator.office;
|
||||
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.io.IOException;
|
||||
import org.apache.fineract.infrastructure.bulkimport.constants.OfficeConstants;
|
||||
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
|
||||
import org.apache.fineract.integrationtests.common.OfficeHelper;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class OfficeWorkBookPopulatorTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
Utils.initializeRESTAssured();
|
||||
this.requestSpec = new RequestSpecBuilder().build();
|
||||
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
|
||||
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOfficeWorkbookPopulate() throws IOException {
|
||||
OfficeHelper officeHelper = new OfficeHelper(requestSpec, responseSpec);
|
||||
Workbook workbook = officeHelper.getOfficeWorkBook("dd MMMM yyyy");
|
||||
Sheet sheet = workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME);
|
||||
Row firstRow = sheet.getRow(1);
|
||||
Assertions.assertNotNull("No parent offices found", firstRow.getCell(OfficeConstants.LOOKUP_OFFICE_COL).getStringCellValue());
|
||||
Assertions.assertEquals(1, firstRow.getCell(OfficeConstants.LOOKUP_OFFICE_ID_COL).getNumericCellValue(), 0.0);
|
||||
|
||||
}
|
||||
}
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
/**
|
||||
* 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.bulkimport.populator.savings;
|
||||
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.io.IOException;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import org.apache.fineract.infrastructure.bulkimport.constants.TemplatePopulateImportConstants;
|
||||
import org.apache.fineract.integrationtests.common.ClientHelper;
|
||||
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.organisation.StaffHelper;
|
||||
import org.apache.fineract.integrationtests.common.savings.SavingsAccountHelper;
|
||||
import org.apache.fineract.integrationtests.common.savings.SavingsProductHelper;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class SavingsWorkbookPopulateTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
|
||||
@BeforeEach
|
||||
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 testSavingsWorkbookPopulate() throws IOException {
|
||||
requestSpec.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
|
||||
// in order to populate helper sheets
|
||||
OfficeHelper officeHelper = new OfficeHelper(requestSpec, responseSpec);
|
||||
Integer outcome_office_creation = officeHelper.createOffice("02 May 2000");
|
||||
Assertions.assertNotNull(outcome_office_creation, "Could not create office");
|
||||
|
||||
// in order to populate helper sheets
|
||||
Integer outcome_client_creation = ClientHelper.createClient(requestSpec, responseSpec);
|
||||
Assertions.assertNotNull(outcome_client_creation, "Could not create client");
|
||||
|
||||
// in order to populate helper sheets
|
||||
Integer outcome_group_creation = GroupHelper.createGroup(requestSpec, responseSpec, true);
|
||||
Assertions.assertNotNull(outcome_group_creation, "Could not create group");
|
||||
|
||||
// in order to populate helper sheets
|
||||
Integer outcome_staff_creation = StaffHelper.createStaff(requestSpec, responseSpec);
|
||||
Assertions.assertNotNull(outcome_staff_creation, "Could not create staff");
|
||||
|
||||
SavingsProductHelper savingsProductHelper = new SavingsProductHelper();
|
||||
String jsonSavingsProduct = savingsProductHelper.build();
|
||||
Integer outcome_sp_creaction = SavingsProductHelper.createSavingsProduct(jsonSavingsProduct, requestSpec, responseSpec);
|
||||
Assertions.assertNotNull(outcome_sp_creaction, "Could not create Savings product");
|
||||
|
||||
SavingsAccountHelper savingsAccountHelper = new SavingsAccountHelper(requestSpec, responseSpec);
|
||||
Workbook workbook = savingsAccountHelper.getSavingsWorkbook("dd MMMM yyyy");
|
||||
|
||||
Sheet officeSheet = workbook.getSheet(TemplatePopulateImportConstants.OFFICE_SHEET_NAME);
|
||||
Row firstOfficeRow = officeSheet.getRow(1);
|
||||
Assertions.assertNotNull(firstOfficeRow.getCell(1), "No offices found ");
|
||||
|
||||
Sheet clientSheet = workbook.getSheet(TemplatePopulateImportConstants.CLIENT_SHEET_NAME);
|
||||
Row firstClientRow = clientSheet.getRow(1);
|
||||
Assertions.assertNotNull(firstClientRow.getCell(1), "No clients found ");
|
||||
|
||||
Sheet groupSheet = workbook.getSheet(TemplatePopulateImportConstants.GROUP_SHEET_NAME);
|
||||
Row firstGroupRow = groupSheet.getRow(1);
|
||||
Assertions.assertNotNull(firstGroupRow.getCell(1), "No groups found ");
|
||||
|
||||
Sheet staffSheet = workbook.getSheet(TemplatePopulateImportConstants.STAFF_SHEET_NAME);
|
||||
Row firstStaffRow = staffSheet.getRow(1);
|
||||
Assertions.assertNotNull(firstStaffRow.getCell(1), "No staff found ");
|
||||
|
||||
Sheet productSheet = workbook.getSheet(TemplatePopulateImportConstants.PRODUCT_SHEET_NAME);
|
||||
Row firstProductRow = productSheet.getRow(1);
|
||||
Assertions.assertNotNull(firstProductRow.getCell(1), "No products found ");
|
||||
|
||||
}
|
||||
}
|
||||
+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;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Manthan Surkar
|
||||
*
|
||||
*/
|
||||
|
||||
public class AuditHelper {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AuditHelper.class);
|
||||
private static final String AUDIT_BASE_URL = "/fineract-provider/api/v1/audits?" + Utils.TENANT_IDENTIFIER;
|
||||
|
||||
public AuditHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
this.requestSpec = requestSpec;
|
||||
this.responseSpec = responseSpec;
|
||||
}
|
||||
|
||||
public List getAuditDetails(final Integer resourceId, final String actionName, final String entityName) {
|
||||
final String AUDIT_URL = "/fineract-provider/api/v1/audits/?" + "entityName=" + entityName + "&resourceId=" + resourceId
|
||||
+ "&actionName=" + actionName + "&orderBy=id&sortBy=DSC&" + Utils.TENANT_IDENTIFIER;
|
||||
List<HashMap<String, Object>> responseAudits = Utils.performServerGet(requestSpec, responseSpec, AUDIT_URL, "");
|
||||
return responseAudits;
|
||||
}
|
||||
|
||||
public List getAuditDetails(final int limit) {
|
||||
|
||||
final String AUDIT_URL = "/fineract-provider/api/v1/audits?paged=true&limit=" + Integer.toString(limit) + "&"
|
||||
+ Utils.TENANT_IDENTIFIER;
|
||||
LinkedHashMap responseAudits = Utils.performServerGet(requestSpec, responseSpec, AUDIT_URL, "");
|
||||
return (List) responseAudits.get("pageItems");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Some audit actions can only be done once Eg: Creation of a client with id 123, hence we verify number of audits
|
||||
* For such operations is "equal" to 1 always
|
||||
*/
|
||||
public void verifyOneAuditOnly(List<HashMap<String, Object>> auditsToCheck, Integer id, String actionName, String entityType) {
|
||||
LOG.info("------------------------------CHECK IF AUDIT CREATED------------------------------------\n");
|
||||
assertEquals(1, auditsToCheck.size(), "More than one audit created");
|
||||
HashMap<String, Object> auditToCheck = auditsToCheck.get(0);
|
||||
String actual = auditToCheck.get("actionName").toString() + " is done on " + auditToCheck.get("entityName").toString() + " with id "
|
||||
+ auditToCheck.get("resourceId").toString();
|
||||
String expected = actionName + " is done on " + entityType + " with id " + id;
|
||||
assertEquals(expected, actual, "Error in creating audit!");
|
||||
}
|
||||
|
||||
public void verifyMultipleAuditsOnserver(List<HashMap<String, Object>> auditsRecievedInitial,
|
||||
List<HashMap<String, Object>> auditsRecieved, Integer id, String actionName, String entityType) {
|
||||
LOG.info("------------------------------CHECK IF AUDIT CREATED------------------------------------\n");
|
||||
assertEquals(auditsRecievedInitial.size() + 1, auditsRecieved.size(), "Audit is not Created");
|
||||
|
||||
Comparator<HashMap<String, Object>> compareById = (HashMap<String, Object> a, HashMap<String, Object> b) -> a.get("id").toString()
|
||||
.compareTo(b.get("id").toString());
|
||||
Collections.sort(auditsRecieved, compareById.reversed());
|
||||
|
||||
// First element is new audit created(Sorted DESC by Id)
|
||||
HashMap<String, Object> auditToCheck = auditsRecieved.get(0);
|
||||
String actual = auditToCheck.get("actionName").toString() + " is done on " + auditToCheck.get("entityName").toString() + " with id "
|
||||
+ auditToCheck.get("resourceId").toString();
|
||||
String expected = actionName + " is done on " + entityType + " with id " + id;
|
||||
assertEquals(expected, actual, "Error in creating audit!");
|
||||
}
|
||||
|
||||
public void verifyLimitParameterfor(final int limit) {
|
||||
assertEquals(limit, getAuditDetails(limit).size(), "Incorrect number of audits recieved for limit: " + Integer.toString(limit));
|
||||
}
|
||||
|
||||
public void verifyOrderBysupported(final String orderByValue) {
|
||||
final String AUDIT_URL = "/fineract-provider/api/v1/audits/?paged=true&orderBy=" + orderByValue + "&" + Utils.TENANT_IDENTIFIER;
|
||||
Utils.performServerGet(requestSpec, responseSpec, AUDIT_URL, "");
|
||||
}
|
||||
|
||||
}
|
||||
+417
@@ -0,0 +1,417 @@
|
||||
/**
|
||||
* 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.google.gson.reflect.TypeToken;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.apache.fineract.batch.domain.BatchRequest;
|
||||
import org.apache.fineract.batch.domain.BatchResponse;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* 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 final class BatchHelper {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(BatchHelper.class);
|
||||
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() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 a Map from Json String
|
||||
*
|
||||
* @param jsonBody
|
||||
* @return Map
|
||||
*/
|
||||
public static Map generateMapFromJsonString(final String jsonString) {
|
||||
return new Gson().fromJson(jsonString, Map.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the converted string response into JSON.
|
||||
*
|
||||
* @param json
|
||||
* @return {@code 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 {@code 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
|
||||
Assertions.assertNotNull(response);
|
||||
Assertions.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.CreateClientCommandStrategy} Request as
|
||||
* one of the request in Batch.
|
||||
*
|
||||
* @param reqId
|
||||
* @param externalId
|
||||
* @return BatchRequest
|
||||
*/
|
||||
public static BatchRequest createActiveClientRequest(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\": \"" + externalId
|
||||
+ "\", \"dateFormat\": \"dd MMMM yyyy\", \"locale\": \"en\","
|
||||
+ "\"active\": true, \"activationDate\": \"04 March 2010\", \"submittedOnDate\": \"04 March 2010\"}";
|
||||
|
||||
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\": 10,"
|
||||
+ "\"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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a {@link org.apache.fineract.batch.command.internal.RepayLoanCommandStrategy} Request with
|
||||
* given requestId.
|
||||
*
|
||||
*
|
||||
* @param requestId
|
||||
* @param reference
|
||||
* @return BatchRequest
|
||||
*/
|
||||
public static BatchRequest repayLoanRequest(final Long requestId, final Long reference) {
|
||||
final BatchRequest br = new BatchRequest();
|
||||
|
||||
br.setRequestId(requestId);
|
||||
br.setReference(reference);
|
||||
br.setRelativeUrl("loans/$.loanId/transactions?command=repayment");
|
||||
br.setMethod("POST");
|
||||
br.setBody("{\"locale\": \"en\", \"dateFormat\": \"dd MMMM yyyy\", "
|
||||
+ "\"transactionDate\": \"15 September 2013\", \"transactionAmount\": 500}");
|
||||
|
||||
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) {
|
||||
LOG.info("------------------------------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");
|
||||
Assertions.assertEquals((long) 0, (long) responseRecords, "No records found with given externalId");
|
||||
}
|
||||
}
|
||||
+136
@@ -0,0 +1,136 @@
|
||||
/**
|
||||
* 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.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import io.restassured.path.json.JsonPath;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.util.HashMap;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public final class CalendarHelper {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(CalendarHelper.class);
|
||||
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";
|
||||
private static final String CENTER_ENTITY = "centers/";
|
||||
private static final String EDIT_CALENDAR = "editcalendarbasedonmeetingdates/";
|
||||
|
||||
private CalendarHelper() {
|
||||
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
LOG.info("---------------------------------CREATING A MEETING CALENDAR FOR THE GROUP------------------------------");
|
||||
|
||||
final String CALENDAR_RESOURCE_URL = BASE_URL + PARENT_ENTITY_NAME + groupId + ENITY_NAME + "?" + Utils.TENANT_IDENTIFIER;
|
||||
|
||||
LOG.info("{}", 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) {
|
||||
|
||||
LOG.info("---------------------------------UPDATING A MEETING CALENDAR FOR THE GROUP------------------------------");
|
||||
|
||||
final String CALENDAR_RESOURCE_URL = BASE_URL + PARENT_ENTITY_NAME + groupId + ENITY_NAME + "/" + calendarID;
|
||||
|
||||
LOG.info("{}", 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);
|
||||
LOG.info("map : {}", map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static void verifyCalendarCreatedOnServer(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer generatedGroupId, final Integer generatedCalendarId) {
|
||||
LOG.info("------------------------------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 = JsonPath.from(responseCalendarDetailsinJSON).get("id");
|
||||
assertEquals(generatedCalendarId, responseCalendarId, "ERROR IN CREATING THE CALENDAR");
|
||||
}
|
||||
|
||||
public static Integer createMeetingForGroup(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer groupId, final String startDate, final String frequency, final String interval, final String repeatsOnDay) {
|
||||
|
||||
LOG.info("---------------------------------CREATING A MEETING CALENDAR FOR THE GROUP------------------------------");
|
||||
|
||||
final String CALENDAR_RESOURCE_URL = BASE_URL + CENTER_ENTITY + groupId + ENITY_NAME + "?" + Utils.TENANT_IDENTIFIER;
|
||||
|
||||
LOG.info("{}", CALENDAR_RESOURCE_URL);
|
||||
|
||||
return Utils.performServerPost(requestSpec, responseSpec, CALENDAR_RESOURCE_URL,
|
||||
getTestCalendarAsJSON(frequency, interval, repeatsOnDay, startDate), "resourceId");
|
||||
}
|
||||
|
||||
public static Integer updateMeetingCalendarForCenter(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
Integer centerId, String calendarID, String oldDate, String startDate) {
|
||||
|
||||
LOG.info("---------------------------------UPADATING A MEETING CALENDAR FOR THE CENTER------------------------------");
|
||||
|
||||
final String CALENDAR_RESOURCE_URL = BASE_URL + CENTER_ENTITY + centerId + ENITY_NAME + "/" + calendarID + "?"
|
||||
+ Utils.TENANT_IDENTIFIER;
|
||||
|
||||
LOG.info("{}", CALENDAR_RESOURCE_URL);
|
||||
|
||||
return Utils.performServerPut(requestSpec, responseSpec, CALENDAR_RESOURCE_URL, getTestCalendarMeetingAsJSON(oldDate, startDate),
|
||||
"resourceId");
|
||||
|
||||
}
|
||||
|
||||
private static String getTestCalendarMeetingAsJSON(String oldDate, String startDate) {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("locale", "en");
|
||||
map.put("newMeetingDate", startDate);
|
||||
map.put("presentMeetingDate", oldDate);
|
||||
map.put("reschedulebasedOnMeetingDates", "true");
|
||||
LOG.info("map : {}", map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
}
|
||||
+280
@@ -0,0 +1,280 @@
|
||||
/**
|
||||
* 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 java.time.ZoneId;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class CenterDomain implements Comparable<CenterDomain> {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(CenterDomain.class);
|
||||
|
||||
public static final class Builder {
|
||||
|
||||
private final Integer id;
|
||||
private final String accountNo;
|
||||
private final HashMap<String, Object> status;
|
||||
private final boolean active;
|
||||
private final String name;
|
||||
private final String externalId;
|
||||
private final Integer staffId;
|
||||
private final Integer officeId;
|
||||
private final String officeName;
|
||||
private final String hierarchy;
|
||||
private final 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 = null;
|
||||
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<String, Object> 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", Date.from(Utils.getLocalDateOfTenant().atStartOfDay(ZoneId.systemDefault()).toInstant()));
|
||||
} else {
|
||||
map.put("submittedOnDate", submittedDate);
|
||||
}
|
||||
}
|
||||
if (externalId != null) {
|
||||
map.put("externalId", externalId);
|
||||
}
|
||||
if (groupMembers != null) {
|
||||
map.put("groupMembers", groupMembers);
|
||||
}
|
||||
LOG.info("{}", map.toString());
|
||||
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) {
|
||||
hash += this.status.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 this.id.compareTo(cd.getId());
|
||||
}
|
||||
}
|
||||
+282
@@ -0,0 +1,282 @@
|
||||
/**
|
||||
* 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.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.gson.Gson;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public final class CenterHelper {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(CenterHelper.class);
|
||||
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;
|
||||
|
||||
private CenterHelper() {
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
LOG.info("------------------------ RETRIEVING CENTER AT {}-------------------------", id);
|
||||
Object get = Utils.performServerGet(requestSpec, responseSpec, GET_CENTER_BY_ID_URL, "");
|
||||
final String jsonData = new Gson().toJson(get);
|
||||
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;
|
||||
LOG.info("------------------------ RETRIEVING CENTERS-------------------------");
|
||||
Object get = Utils.performServerGet(requestSpec, responseSpec, GET_CENTER, "pageItems");
|
||||
final String jsonData = new Gson().toJson(get);
|
||||
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;
|
||||
LOG.info("------------------------ RETRIEVING CENTERS-------------------------");
|
||||
Object get = Utils.performServerGet(requestSpec, responseSpec, GET_CENTER, "");
|
||||
final String jsonData = new Gson().toJson(get);
|
||||
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);
|
||||
}
|
||||
|
||||
LOG.info("------------------------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;
|
||||
LOG.info("---------------------------------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);
|
||||
LOG.info("---------------------------------ASSOCIATING GROUPS AT {}--------------------------------------------", id);
|
||||
HashMap hash = Utils.performServerPost(requestSpec, responseSpec, ASSOCIATE_GROUP_CENTER_URL, new Gson().toJson(groupMemberHashMap),
|
||||
"changes");
|
||||
LOG.info("{}", hash.toString());
|
||||
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;
|
||||
LOG.info("---------------------------------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) {
|
||||
LOG.info("---------------------------------CREATING A CENTER---------------------------------------------");
|
||||
return createCenter(requestSpec, responseSpec, "CREATED_DATE");
|
||||
}
|
||||
|
||||
public static Integer createCenter(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String activationDate) {
|
||||
LOG.info("---------------------------------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) {
|
||||
LOG.info("---------------------------------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) {
|
||||
LOG.info("---------------------------------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) {
|
||||
LOG.info("------------------------------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(generatedCenterID, responseCenterID, "ERROR IN CREATING THE CENTER");
|
||||
}
|
||||
|
||||
public static void verifyCenterActivatedOnServer(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer generatedCenterID, final boolean generatedCenterStatus) {
|
||||
LOG.info("------------------------------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(generatedCenterStatus, responseCenterStatus, "ERROR IN ACTIVATING THE CENTER");
|
||||
}
|
||||
|
||||
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;
|
||||
LOG.info("---------------------------------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);
|
||||
LOG.info("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);
|
||||
LOG.info("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 (!Strings.isNullOrEmpty(activationDate)) {
|
||||
map.put("activationDate", activationDate);
|
||||
} else {
|
||||
map.put("activationDate", "CREATED_DATE");
|
||||
LOG.info("defaulting to fixed date: CREATED_DATE");
|
||||
}
|
||||
LOG.info("map : {}", map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static String randomNameGenerator(final String prefix, final int lenOfRandomSuffix) {
|
||||
return Utils.randomStringGenerator(prefix, lenOfRandomSuffix);
|
||||
}
|
||||
|
||||
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";
|
||||
LOG.info("---------------------------------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";
|
||||
LOG.info("---------------------------------Unassign Staff---------------------------------------------");
|
||||
return Utils.performServerPost(requestSpec, responseSpec, GROUP_ASSIGN_STAFF_URL, unassignStaffAsJSON(staffId), "changes");
|
||||
}
|
||||
|
||||
}
|
||||
+174
@@ -0,0 +1,174 @@
|
||||
/**
|
||||
* 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 io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import org.apache.fineract.integrationtests.common.charges.ChargesHelper;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
* IntegrationTest for ClientCharges.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* @author lenovo
|
||||
*
|
||||
*/
|
||||
public class ClientChargesTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private RequestSpecification requestSpec;
|
||||
|
||||
@BeforeEach
|
||||
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());
|
||||
Assertions.assertNotNull(chargeId);
|
||||
|
||||
// creates client with activation date
|
||||
final Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 October 2011");
|
||||
Assertions.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());
|
||||
Assertions.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"));
|
||||
Assertions.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"));
|
||||
Assertions.assertNotNull(clientChargeId);
|
||||
final String clientChargePaidTransactionId = ClientHelper.payChargesForClients(this.requestSpec, this.responseSpec, clientId,
|
||||
clientChargeId, ClientHelper.getPayChargeJSON("25 AUGUST 2015", "10"));
|
||||
Assertions.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);
|
||||
Assertions.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();
|
||||
DateFormat dateFormat = new SimpleDateFormat("dd MMMM yyyy");
|
||||
dateFormat.setTimeZone(Utils.getTimeZoneOfTenant());
|
||||
Calendar today = Calendar.getInstance(Utils.getTimeZoneOfTenant());
|
||||
today.add(Calendar.DAY_OF_MONTH, 2);
|
||||
final String responseId_futureDate_failure = ClientHelper.payChargesForClients(this.requestSpec, responseSpecFailure, clientId,
|
||||
clientChargeId, ClientHelper.getPayChargeJSON(dateFormat.format(today.getTime()), "20"));
|
||||
Assertions.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()));
|
||||
Assertions.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);
|
||||
Assertions.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 September 2011", "20"));
|
||||
Assertions.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"));
|
||||
Assertions.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"));
|
||||
Assertions.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);
|
||||
Assertions.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) {
|
||||
Assertions.assertEquals(expectedAmount, (float) outStandingAmount);
|
||||
}
|
||||
|
||||
}
|
||||
+634
@@ -0,0 +1,634 @@
|
||||
/**
|
||||
* 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.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import org.apache.fineract.infrastructure.bulkimport.data.GlobalEntityType;
|
||||
import org.apache.fineract.integrationtests.common.system.CodeHelper;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ClientHelper {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ClientHelper.class);
|
||||
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";
|
||||
private static final String UNDOREJECT_CLIENT_COMMAND = "undoRejection";
|
||||
private static final String UNDOWITHDRAWN_CLIENT_COMMAND = "undoWithdrawal";
|
||||
|
||||
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_PLUS_TWO = "29 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 static final String DATE_TIME_FORMAT = "dd MMMM yyyy HH:mm";
|
||||
|
||||
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) {
|
||||
LOG.info("---------------------------------CREATING A CLIENT---------------------------------------------");
|
||||
return Utils.performServerPost(requestSpec, responseSpec, CREATE_CLIENT_URL, getTestClientAsJSON(activationDate, officeId),
|
||||
"clientId");
|
||||
}
|
||||
|
||||
public static Integer createClientPending(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
return createClientPending(requestSpec, responseSpec, "04 March 2014");
|
||||
}
|
||||
|
||||
public static Integer createClientPending(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String submittedOnDate) {
|
||||
return createClientPending(requestSpec, responseSpec, submittedOnDate, "1");
|
||||
}
|
||||
|
||||
public static Integer createClientPending(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String submittedOnDate, final String officeId) {
|
||||
LOG.info("---------------------------------CREATING A CLIENT IN PENDING---------------------------------------------");
|
||||
return Utils.performServerPost(requestSpec, responseSpec, CREATE_CLIENT_URL, getTestClientAsJSONPending(submittedOnDate, officeId),
|
||||
"clientId");
|
||||
}
|
||||
|
||||
public Object createClientPendingWithError(final String jsonAttributeToGetBack) {
|
||||
LOG.info("---------------------------------CREATING A CLIENT IN PENDING WITH ERROR---------------------------------------------");
|
||||
return Utils.performServerPost(this.requestSpec, this.responseSpec, CREATE_CLIENT_URL,
|
||||
getTestClientAsJSONPending("04 March 2014", "1"), jsonAttributeToGetBack);
|
||||
}
|
||||
|
||||
public static Integer createClientPendingWithDatatable(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String registeredTableName) {
|
||||
LOG.info("-------------------------- CREATING A CLIENT IN PENDING WITH DATATABLES --------------------------------");
|
||||
return Utils.performServerPost(requestSpec, responseSpec, CREATE_CLIENT_URL,
|
||||
getTestPendingClientWithDatatableAsJson(registeredTableName), "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) {
|
||||
|
||||
LOG.info(
|
||||
"---------------------------------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");
|
||||
|
||||
LOG.info(
|
||||
"---------------------------------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";
|
||||
LOG.info(
|
||||
"---------------------------------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";
|
||||
|
||||
LOG.info("---------------------------------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);
|
||||
LOG.info("map : {}", map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static String getTestClientAsJSONPending(final String submittedOnDate, 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", "false");
|
||||
map.put("submittedOnDate", submittedOnDate);
|
||||
LOG.info("map : {}", map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static String getTestPendingClientWithDatatableAsJson(final String registeredTableName) {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("officeId", "1");
|
||||
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", "false");
|
||||
map.put("submittedOnDate", "04 March 2014");
|
||||
String requestJson = getTestDatatableAsJson(map, registeredTableName);
|
||||
LOG.info("map : {}", requestJson);
|
||||
return requestJson;
|
||||
}
|
||||
|
||||
public static String getTestDatatableAsJson(HashMap<String, Object> map, final String registeredTableName) {
|
||||
List<HashMap<String, Object>> datatablesListMap = new ArrayList<>();
|
||||
HashMap<String, Object> datatableMap = new HashMap<>();
|
||||
HashMap<String, Object> dataMap = new HashMap<>();
|
||||
dataMap.put("locale", "en");
|
||||
dataMap.put("Spouse Name", Utils.randomNameGenerator("Spouse_name", 4));
|
||||
dataMap.put("Number of Dependents", 5);
|
||||
dataMap.put("Time of Visit", "01 December 2016 04:03");
|
||||
dataMap.put("dateFormat", DATE_TIME_FORMAT);
|
||||
dataMap.put("Date of Approval", "02 December 2016 00:00");
|
||||
datatableMap.put("registeredTableName", registeredTableName);
|
||||
datatableMap.put("data", dataMap);
|
||||
datatablesListMap.add(datatableMap);
|
||||
map.put("datatables", datatablesListMap);
|
||||
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);
|
||||
|
||||
LOG.info("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);
|
||||
|
||||
LOG.info("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);
|
||||
LOG.info("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);
|
||||
LOG.info("map : {}", map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static void verifyClientCreatedOnServer(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer generatedClientID) {
|
||||
LOG.info("------------------------------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(generatedClientID, responseClientID, "ERROR IN CREATING THE CLIENT");
|
||||
}
|
||||
|
||||
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;
|
||||
LOG.info("---------------------------------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.DATE_FORMAT);
|
||||
map.put("closureDate", CREATED_DATE_PLUS_ONE);
|
||||
|
||||
String clientJson = new Gson().toJson(map);
|
||||
LOG.info(clientJson);
|
||||
return clientJson;
|
||||
|
||||
}
|
||||
|
||||
private String getReactivateClientAsJSON() {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("locale", CommonConstants.LOCALE);
|
||||
map.put("dateFormat", CommonConstants.DATE_FORMAT);
|
||||
map.put("reactivationDate", CREATED_DATE_PLUS_ONE);
|
||||
String clientJson = new Gson().toJson(map);
|
||||
LOG.info(clientJson);
|
||||
return clientJson;
|
||||
|
||||
}
|
||||
|
||||
private String getUndoRejectClientAsJSON(final String date) {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("locale", CommonConstants.LOCALE);
|
||||
map.put("dateFormat", CommonConstants.DATE_FORMAT);
|
||||
map.put("reopenedDate", date);
|
||||
String clientJson = new Gson().toJson(map);
|
||||
LOG.info(clientJson);
|
||||
return clientJson;
|
||||
|
||||
}
|
||||
|
||||
private String getUndoWithdrawnClientAsJSON(final String date) {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("locale", CommonConstants.LOCALE);
|
||||
map.put("dateFormat", CommonConstants.DATE_FORMAT);
|
||||
map.put("reopenedDate", date);
|
||||
String clientJson = new Gson().toJson(map);
|
||||
LOG.info(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.DATE_FORMAT);
|
||||
map.put("rejectionDate", CREATED_DATE_PLUS_ONE);
|
||||
map.put("rejectionReasonId", rejectionReasonId.toString());
|
||||
String clientJson = new Gson().toJson(map);
|
||||
LOG.info(clientJson);
|
||||
return clientJson;
|
||||
|
||||
}
|
||||
|
||||
private String getActivateClientAsJSON(String date) {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("locale", CommonConstants.LOCALE);
|
||||
map.put("dateFormat", CommonConstants.DATE_FORMAT);
|
||||
map.put("activationDate", date);
|
||||
String clientJson = new Gson().toJson(map);
|
||||
LOG.info(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.DATE_FORMAT);
|
||||
map.put("withdrawalDate", CREATED_DATE_PLUS_ONE);
|
||||
map.put("withdrawalReasonId", withdrawalReasonId.toString());
|
||||
String clientJson = new Gson().toJson(map);
|
||||
LOG.info(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);
|
||||
LOG.info("{}", 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);
|
||||
LOG.info("{}", json);
|
||||
return json;
|
||||
}
|
||||
|
||||
public HashMap<String, Object> closeClient(final Integer clientId) {
|
||||
LOG.info("--------------------------------- CLOSE CLIENT -------------------------------");
|
||||
return performClientActions(createClientOperationURL(CLOSE_CLIENT_COMMAND, clientId), getCloseClientAsJSON(), clientId);
|
||||
}
|
||||
|
||||
public HashMap<String, Object> reactivateClient(final Integer clientId) {
|
||||
LOG.info("--------------------------------- REACTIVATE CLIENT -------------------------------");
|
||||
return performClientActions(createClientOperationURL(REACTIVATE_CLIENT_COMMAND, clientId), getReactivateClientAsJSON(), clientId);
|
||||
}
|
||||
|
||||
public HashMap<String, Object> rejectClient(final Integer clientId) {
|
||||
LOG.info("--------------------------------- REJECT CLIENT -------------------------------");
|
||||
return performClientActions(createClientOperationURL(REJECT_CLIENT_COMMAND, clientId), getRejectClientAsJSON(), clientId);
|
||||
}
|
||||
|
||||
public HashMap<String, Object> activateClient(final Integer clientId) {
|
||||
LOG.info("--------------------------------- ACTIVATE CLIENT -------------------------------");
|
||||
return performClientActions(createClientOperationURL(ACTIVATE_CLIENT_COMMAND, clientId),
|
||||
getActivateClientAsJSON(CREATED_DATE_PLUS_ONE), clientId);
|
||||
}
|
||||
|
||||
public HashMap<String, Object> withdrawClient(final Integer clientId) {
|
||||
LOG.info("--------------------------------- 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;
|
||||
}
|
||||
|
||||
public HashMap<String, Object> undoReject(final Integer clientId) {
|
||||
LOG.info("--------------------------------- UNDO REJECT CLIENT -------------------------------");
|
||||
return performClientActions(createClientOperationURL(UNDOREJECT_CLIENT_COMMAND, clientId),
|
||||
getUndoRejectClientAsJSON(CREATED_DATE_PLUS_TWO), clientId);
|
||||
}
|
||||
|
||||
public HashMap<String, Object> undoWithdrawn(final Integer clientId) {
|
||||
LOG.info("--------------------------------- UNDO WITHDRAWN CLIENT -------------------------------");
|
||||
return performClientActions(createClientOperationURL(UNDOWITHDRAWN_CLIENT_COMMAND, clientId),
|
||||
getUndoWithdrawnClientAsJSON(CREATED_DATE_PLUS_TWO), clientId);
|
||||
}
|
||||
|
||||
public ArrayList<HashMap<String, Object>> undoRejectedclient(final Integer clientId, final String jsonAttributeToGetBack,
|
||||
final String rejectedDate) {
|
||||
LOG.info("----------------------------------UNDO REJECT CLIENT ----------------------------------");
|
||||
return performClientActionsWithValidationErrors(createClientOperationURL(UNDOREJECT_CLIENT_COMMAND, clientId),
|
||||
getUndoRejectClientAsJSON(rejectedDate), jsonAttributeToGetBack);
|
||||
}
|
||||
|
||||
public ArrayList<HashMap<String, Object>> undoWithdrawclient(final Integer clientId, final String jsonAttributeToGetBack,
|
||||
final String rejectedDate) {
|
||||
LOG.info("----------------------------------UNDO WITHDRAW CLIENT ----------------------------------");
|
||||
return performClientActionsWithValidationErrors(createClientOperationURL(UNDOWITHDRAWN_CLIENT_COMMAND, clientId),
|
||||
getUndoWithdrawnClientAsJSON(rejectedDate), jsonAttributeToGetBack);
|
||||
}
|
||||
|
||||
public ArrayList<HashMap<String, Object>> activateClient(final Integer clientId, final String jsonAttributeToGetBack) {
|
||||
LOG.info("--------------------------------- ACTIVATE CLIENT -------------------------------");
|
||||
return performClientActionsWithValidationErrors(createClientOperationURL(ACTIVATE_CLIENT_COMMAND, clientId),
|
||||
getActivateClientAsJSON(CREATED_DATE_PLUS_ONE), jsonAttributeToGetBack);
|
||||
}
|
||||
|
||||
public HashMap<String, Object> activateClientWithDiffDateOption(final Integer clientId, final String activationDate) {
|
||||
LOG.info("--------------------------------- ACTIVATE CLIENT -------------------------------");
|
||||
return performClientActions(createClientOperationURL(ACTIVATE_CLIENT_COMMAND, clientId), getActivateClientAsJSON(activationDate),
|
||||
clientId);
|
||||
}
|
||||
|
||||
private ArrayList<HashMap<String, Object>> performClientActionsWithValidationErrors(final String postURLForClient,
|
||||
final String jsonToBeSent, final String jsonAttributeToGetBack) {
|
||||
return Utils.performServerPost(this.requestSpec, this.responseSpec, postURLForClient, jsonToBeSent, jsonAttributeToGetBack);
|
||||
}
|
||||
|
||||
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) {
|
||||
LOG.info("--------------------------------- 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) {
|
||||
LOG.info("--------------------------------- 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) {
|
||||
LOG.info("--------------------------------- 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) {
|
||||
LOG.info("---------------------------------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) {
|
||||
LOG.info("---------------------------------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) {
|
||||
LOG.info("---------------------------------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");
|
||||
}
|
||||
|
||||
public Workbook getClientEntityWorkbook(GlobalEntityType clientsEntity, String dateFormat) throws IOException {
|
||||
requestSpec.header(HttpHeaders.CONTENT_TYPE, "application/vnd.ms-excel");
|
||||
byte[] byteArray = Utils.performGetBinaryResponse(requestSpec, responseSpec, CLIENT_URL + "/downloadtemplate" + "?"
|
||||
+ Utils.TENANT_IDENTIFIER + "&legalFormType=" + clientsEntity + "&dateFormat=" + dateFormat);
|
||||
InputStream inputStream = new ByteArrayInputStream(byteArray);
|
||||
Workbook workbook = new HSSFWorkbook(inputStream);
|
||||
return workbook;
|
||||
}
|
||||
|
||||
public String getOutputTemplateLocation(final String importDocumentId) {
|
||||
requestSpec.header(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN);
|
||||
return Utils.performServerOutputTemplateLocationGet(requestSpec, responseSpec,
|
||||
"/fineract-provider/api/v1/imports/getOutputTemplateLocation" + "?" + Utils.TENANT_IDENTIFIER, importDocumentId);
|
||||
}
|
||||
|
||||
public String importClientEntityTemplate(File file) {
|
||||
String locale = "en";
|
||||
String dateFormat = "dd MMMM yyyy";
|
||||
String legalFormType = GlobalEntityType.CLIENTS_ENTTTY.toString();
|
||||
requestSpec.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA);
|
||||
return Utils.performServerTemplatePost(requestSpec, responseSpec, CLIENT_URL + "/uploadtemplate" + "?" + Utils.TENANT_IDENTIFIER,
|
||||
legalFormType, file, locale, dateFormat);
|
||||
}
|
||||
|
||||
public List getClientWithStatus(final int limit, final String status) {
|
||||
final String URL = "/fineract-provider/api/v1/clients?paged=true&status=" + status + "&limit=" + Integer.toString(limit) + "&"
|
||||
+ Utils.TENANT_IDENTIFIER;
|
||||
LinkedHashMap responseClients = Utils.performServerGet(requestSpec, responseSpec, URL, "");
|
||||
return (List) responseClients.get("pageItems");
|
||||
}
|
||||
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* 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 {
|
||||
|
||||
String LOCALE = "en";
|
||||
String DATE_FORMAT = "dd MMMM yyyy";
|
||||
String RESPONSE_RESOURCE_ID = "resourceId";
|
||||
String RESPONSE_CHANGES = "changes";
|
||||
String RESPONSE_STATUS = "status";
|
||||
String RESPONSE_ERROR = "errors";
|
||||
String RESPONSE_ERROR_MESSAGE_CODE = "userMessageGlobalisationCode";
|
||||
}
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* 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.common.reflect.TypeToken;
|
||||
import com.google.gson.Gson;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@SuppressWarnings({ "unused", "rawtypes", "unchecked" })
|
||||
public final class CurrenciesHelper {
|
||||
|
||||
private CurrenciesHelper() {
|
||||
|
||||
}
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(CurrenciesHelper.class);
|
||||
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;
|
||||
LOG.info("------------------------ 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;
|
||||
LOG.info("------------------------ 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;
|
||||
LOG.info("---------------------------------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);
|
||||
LOG.info("map : {}", map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
}
|
||||
+158
@@ -0,0 +1,158 @@
|
||||
/**
|
||||
* 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 final 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() {
|
||||
|
||||
}
|
||||
|
||||
private CurrencyDomain(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 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());
|
||||
}
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* 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 io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
+440
@@ -0,0 +1,440 @@
|
||||
/**
|
||||
* 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 io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@SuppressWarnings({ "unused", "rawtypes" })
|
||||
public class GlobalConfigurationHelper {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(GlobalConfigurationHelper.class);
|
||||
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<HashMap> getAllGlobalConfigurations(final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec) {
|
||||
final String GET_ALL_GLOBAL_CONFIG_URL = "/fineract-provider/api/v1/configurations?" + Utils.TENANT_IDENTIFIER;
|
||||
LOG.info("------------------------ RETRIEVING ALL GLOBAL CONFIGURATIONS -------------------------");
|
||||
final HashMap<String, ArrayList<HashMap>> response = Utils.performServerGet(requestSpec, responseSpec, GET_ALL_GLOBAL_CONFIG_URL,
|
||||
"");
|
||||
return 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;
|
||||
LOG.info("------------------------ RETRIEVING GLOBAL CONFIGURATION BY ID -------------------------");
|
||||
return Utils.performServerGet(requestSpec, responseSpec, GET_GLOBAL_CONFIG_BY_ID_URL, "");
|
||||
}
|
||||
|
||||
public static void resetAllDefaultGlobalConfigurations(final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec) {
|
||||
|
||||
final ArrayList<HashMap> defaults = getAllDefaultGlobalConfigurations();
|
||||
for (HashMap configDefault : defaults) {
|
||||
|
||||
/**
|
||||
* Cannot update trapDoor global configurations because
|
||||
* {@link org.apache.fineract.infrastructure.configuration.exception.GlobalConfigurationPropertyCannotBeModfied}
|
||||
* will be thrown.
|
||||
*/
|
||||
if ((Boolean) configDefault.get("trapDoor")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Currently only values and enabled flags are modified by the
|
||||
// integration test suite.
|
||||
// If any other column is modified by the integration test suite in
|
||||
// the future, it needs to be reset here.
|
||||
final Integer configDefaultId = (Integer) configDefault.get("id");
|
||||
final Integer configDefaultValue = (Integer) configDefault.get("value");
|
||||
updateValueForGlobalConfiguration(requestSpec, responseSpec, configDefaultId.toString(), configDefaultValue.toString());
|
||||
updateEnabledFlagForGlobalConfiguration(requestSpec, responseSpec, configDefaultId.toString(),
|
||||
(Boolean) configDefault.get("enabled"));
|
||||
}
|
||||
}
|
||||
|
||||
public static void verifyAllDefaultGlobalConfigurations(final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec) {
|
||||
|
||||
ArrayList<HashMap> expectedGlobalConfigurations = getAllDefaultGlobalConfigurations();
|
||||
ArrayList<HashMap> actualGlobalConfigurations = getAllGlobalConfigurations(requestSpec, responseSpec);
|
||||
|
||||
// There are currently 30 global configurations.
|
||||
Assertions.assertEquals(30, expectedGlobalConfigurations.size());
|
||||
Assertions.assertEquals(30, actualGlobalConfigurations.size());
|
||||
|
||||
for (int i = 0; i < expectedGlobalConfigurations.size(); i++) {
|
||||
|
||||
HashMap expectedGlobalConfiguration = expectedGlobalConfigurations.get(i);
|
||||
HashMap actualGlobalConfiguration = actualGlobalConfigurations.get(i);
|
||||
|
||||
Assertions.assertEquals(expectedGlobalConfiguration.get("id"), actualGlobalConfiguration.get("id"));
|
||||
final String assertionFailedMessage = "Assertion failed for configID:<" + expectedGlobalConfiguration.get("id") + ">";
|
||||
Assertions.assertEquals(expectedGlobalConfiguration.get("name"), actualGlobalConfiguration.get("name"), assertionFailedMessage);
|
||||
Assertions.assertEquals(expectedGlobalConfiguration.get("value"), actualGlobalConfiguration.get("value"),
|
||||
assertionFailedMessage);
|
||||
Assertions.assertEquals(expectedGlobalConfiguration.get("enabled"), actualGlobalConfiguration.get("enabled"),
|
||||
assertionFailedMessage);
|
||||
Assertions.assertEquals(expectedGlobalConfiguration.get("trapDoor"), actualGlobalConfiguration.get("trapDoor"),
|
||||
assertionFailedMessage);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to get the current default instance data of the /configurations endpoint. Used to reset and verify
|
||||
* that no global configuration affects state between integration tests.
|
||||
*
|
||||
* @see <a href= "https://issues.apache.org/jira/browse/FINERACT-722">FINERACT-722</a> This is a quick, fail fast
|
||||
* and early implementation to resolve this issue. TODO: A more robust future solution would be isolating all
|
||||
* integration test state using Spring Framework's integration test infrastructure for transaction commits and
|
||||
* rollbacks.
|
||||
*/
|
||||
private static ArrayList<HashMap> getAllDefaultGlobalConfigurations() {
|
||||
|
||||
ArrayList<HashMap> defaults = new ArrayList<>();
|
||||
|
||||
HashMap<String, Object> makerCheckerDefault = new HashMap<>();
|
||||
makerCheckerDefault.put("id", 1);
|
||||
makerCheckerDefault.put("name", "maker-checker");
|
||||
makerCheckerDefault.put("value", 0);
|
||||
makerCheckerDefault.put("enabled", false);
|
||||
makerCheckerDefault.put("trapDoor", false);
|
||||
defaults.add(makerCheckerDefault);
|
||||
|
||||
HashMap<String, Object> amazonS3Default = new HashMap<>();
|
||||
amazonS3Default.put("id", 4);
|
||||
amazonS3Default.put("name", "amazon-S3");
|
||||
amazonS3Default.put("value", 0);
|
||||
amazonS3Default.put("enabled", false);
|
||||
amazonS3Default.put("trapDoor", false);
|
||||
defaults.add(amazonS3Default);
|
||||
|
||||
HashMap<String, Object> rescheduleFuturePaymentsDefault = new HashMap<>();
|
||||
rescheduleFuturePaymentsDefault.put("id", 5);
|
||||
rescheduleFuturePaymentsDefault.put("name", "reschedule-future-repayments");
|
||||
rescheduleFuturePaymentsDefault.put("value", 0);
|
||||
rescheduleFuturePaymentsDefault.put("enabled", true);
|
||||
rescheduleFuturePaymentsDefault.put("trapDoor", false);
|
||||
defaults.add(rescheduleFuturePaymentsDefault);
|
||||
|
||||
HashMap<String, Object> rescheduleRepaymentsOnHolidaysDefault = new HashMap<>();
|
||||
rescheduleRepaymentsOnHolidaysDefault.put("id", 6);
|
||||
rescheduleRepaymentsOnHolidaysDefault.put("name", "reschedule-repayments-on-holidays");
|
||||
rescheduleRepaymentsOnHolidaysDefault.put("value", 0);
|
||||
rescheduleRepaymentsOnHolidaysDefault.put("enabled", false);
|
||||
rescheduleRepaymentsOnHolidaysDefault.put("trapDoor", false);
|
||||
defaults.add(rescheduleRepaymentsOnHolidaysDefault);
|
||||
|
||||
HashMap<String, Object> allowTransactionsOnHolidayDefault = new HashMap<>();
|
||||
allowTransactionsOnHolidayDefault.put("id", 7);
|
||||
allowTransactionsOnHolidayDefault.put("name", "allow-transactions-on-holiday");
|
||||
allowTransactionsOnHolidayDefault.put("value", 0);
|
||||
allowTransactionsOnHolidayDefault.put("enabled", false);
|
||||
allowTransactionsOnHolidayDefault.put("trapDoor", false);
|
||||
defaults.add(allowTransactionsOnHolidayDefault);
|
||||
|
||||
HashMap<String, Object> allowTransactionsOnNonWorkingDayDefault = new HashMap<>();
|
||||
allowTransactionsOnNonWorkingDayDefault.put("id", 8);
|
||||
allowTransactionsOnNonWorkingDayDefault.put("name", "allow-transactions-on-non_workingday");
|
||||
allowTransactionsOnNonWorkingDayDefault.put("value", 0);
|
||||
allowTransactionsOnNonWorkingDayDefault.put("enabled", false);
|
||||
allowTransactionsOnNonWorkingDayDefault.put("trapDoor", false);
|
||||
defaults.add(allowTransactionsOnNonWorkingDayDefault);
|
||||
|
||||
HashMap<String, Object> constraintApproachForDataTablesDefault = new HashMap<>();
|
||||
constraintApproachForDataTablesDefault.put("id", 9);
|
||||
constraintApproachForDataTablesDefault.put("name", "constraint_approach_for_datatables");
|
||||
constraintApproachForDataTablesDefault.put("value", 0);
|
||||
constraintApproachForDataTablesDefault.put("enabled", false);
|
||||
constraintApproachForDataTablesDefault.put("trapDoor", false);
|
||||
defaults.add(constraintApproachForDataTablesDefault);
|
||||
|
||||
HashMap<String, Object> penaltyWaitPeriodDefault = new HashMap<>();
|
||||
penaltyWaitPeriodDefault.put("id", 10);
|
||||
penaltyWaitPeriodDefault.put("name", "penalty-wait-period");
|
||||
penaltyWaitPeriodDefault.put("value", 2);
|
||||
penaltyWaitPeriodDefault.put("enabled", true);
|
||||
penaltyWaitPeriodDefault.put("trapDoor", false);
|
||||
defaults.add(penaltyWaitPeriodDefault);
|
||||
|
||||
HashMap<String, Object> forcePasswordResetDaysDefault = new HashMap<>();
|
||||
forcePasswordResetDaysDefault.put("id", 11);
|
||||
forcePasswordResetDaysDefault.put("name", "force-password-reset-days");
|
||||
forcePasswordResetDaysDefault.put("value", 0);
|
||||
forcePasswordResetDaysDefault.put("enabled", false);
|
||||
forcePasswordResetDaysDefault.put("trapDoor", false);
|
||||
defaults.add(forcePasswordResetDaysDefault);
|
||||
|
||||
HashMap<String, Object> graceOnPenaltyPostingDefault = new HashMap<>();
|
||||
graceOnPenaltyPostingDefault.put("id", 12);
|
||||
graceOnPenaltyPostingDefault.put("name", "grace-on-penalty-posting");
|
||||
graceOnPenaltyPostingDefault.put("value", 0);
|
||||
graceOnPenaltyPostingDefault.put("enabled", true);
|
||||
graceOnPenaltyPostingDefault.put("trapDoor", false);
|
||||
defaults.add(graceOnPenaltyPostingDefault);
|
||||
|
||||
HashMap<String, Object> savingsInterestPostingCurrentPeriodEndDefault = new HashMap<>();
|
||||
savingsInterestPostingCurrentPeriodEndDefault.put("id", 15);
|
||||
savingsInterestPostingCurrentPeriodEndDefault.put("name", "savings-interest-posting-current-period-end");
|
||||
savingsInterestPostingCurrentPeriodEndDefault.put("value", 0);
|
||||
savingsInterestPostingCurrentPeriodEndDefault.put("enabled", false);
|
||||
savingsInterestPostingCurrentPeriodEndDefault.put("trapDoor", false);
|
||||
defaults.add(savingsInterestPostingCurrentPeriodEndDefault);
|
||||
|
||||
HashMap<String, Object> financialYearBeginningMonthDefault = new HashMap<>();
|
||||
financialYearBeginningMonthDefault.put("id", 16);
|
||||
financialYearBeginningMonthDefault.put("name", "financial-year-beginning-month");
|
||||
financialYearBeginningMonthDefault.put("value", 1);
|
||||
financialYearBeginningMonthDefault.put("enabled", true);
|
||||
financialYearBeginningMonthDefault.put("trapDoor", false);
|
||||
defaults.add(financialYearBeginningMonthDefault);
|
||||
|
||||
HashMap<String, Object> minClientsInGroupDefault = new HashMap<>();
|
||||
minClientsInGroupDefault.put("id", 17);
|
||||
minClientsInGroupDefault.put("name", "min-clients-in-group");
|
||||
minClientsInGroupDefault.put("value", 5);
|
||||
minClientsInGroupDefault.put("enabled", false);
|
||||
minClientsInGroupDefault.put("trapDoor", false);
|
||||
defaults.add(minClientsInGroupDefault);
|
||||
|
||||
HashMap<String, Object> maxClientsInGroupDefault = new HashMap<>();
|
||||
maxClientsInGroupDefault.put("id", 18);
|
||||
maxClientsInGroupDefault.put("name", "max-clients-in-group");
|
||||
maxClientsInGroupDefault.put("value", 5);
|
||||
maxClientsInGroupDefault.put("enabled", false);
|
||||
maxClientsInGroupDefault.put("trapDoor", false);
|
||||
defaults.add(maxClientsInGroupDefault);
|
||||
|
||||
HashMap<String, Object> meetingsMandatoryForJlgLoansDefault = new HashMap<>();
|
||||
meetingsMandatoryForJlgLoansDefault.put("id", 19);
|
||||
meetingsMandatoryForJlgLoansDefault.put("name", "meetings-mandatory-for-jlg-loans");
|
||||
meetingsMandatoryForJlgLoansDefault.put("value", 0);
|
||||
meetingsMandatoryForJlgLoansDefault.put("enabled", false);
|
||||
meetingsMandatoryForJlgLoansDefault.put("trapDoor", false);
|
||||
defaults.add(meetingsMandatoryForJlgLoansDefault);
|
||||
|
||||
HashMap<String, Object> officeSpecificProductsEnabledDefault = new HashMap<>();
|
||||
officeSpecificProductsEnabledDefault.put("id", 20);
|
||||
officeSpecificProductsEnabledDefault.put("name", "office-specific-products-enabled");
|
||||
officeSpecificProductsEnabledDefault.put("value", 0);
|
||||
officeSpecificProductsEnabledDefault.put("enabled", false);
|
||||
officeSpecificProductsEnabledDefault.put("trapDoor", false);
|
||||
defaults.add(officeSpecificProductsEnabledDefault);
|
||||
|
||||
HashMap<String, Object> restrictProductsToUserOfficeDefault = new HashMap<>();
|
||||
restrictProductsToUserOfficeDefault.put("id", 21);
|
||||
restrictProductsToUserOfficeDefault.put("name", "restrict-products-to-user-office");
|
||||
restrictProductsToUserOfficeDefault.put("value", 0);
|
||||
restrictProductsToUserOfficeDefault.put("enabled", false);
|
||||
restrictProductsToUserOfficeDefault.put("trapDoor", false);
|
||||
defaults.add(restrictProductsToUserOfficeDefault);
|
||||
|
||||
HashMap<String, Object> officeOpeningBalancesContraAccountDefault = new HashMap<>();
|
||||
officeOpeningBalancesContraAccountDefault.put("id", 22);
|
||||
officeOpeningBalancesContraAccountDefault.put("name", "office-opening-balances-contra-account");
|
||||
officeOpeningBalancesContraAccountDefault.put("value", 0);
|
||||
officeOpeningBalancesContraAccountDefault.put("enabled", true);
|
||||
officeOpeningBalancesContraAccountDefault.put("trapDoor", false);
|
||||
defaults.add(officeOpeningBalancesContraAccountDefault);
|
||||
|
||||
HashMap<String, Object> roundingModeDefault = new HashMap<>();
|
||||
roundingModeDefault.put("id", 23);
|
||||
roundingModeDefault.put("name", "rounding-mode");
|
||||
roundingModeDefault.put("value", 6);
|
||||
roundingModeDefault.put("enabled", true);
|
||||
roundingModeDefault.put("trapDoor", true);
|
||||
defaults.add(roundingModeDefault);
|
||||
|
||||
HashMap<String, Object> backDatePenaltiesEnabledDefault = new HashMap<>();
|
||||
backDatePenaltiesEnabledDefault.put("id", 24);
|
||||
backDatePenaltiesEnabledDefault.put("name", "backdate-penalties-enabled");
|
||||
backDatePenaltiesEnabledDefault.put("value", 0);
|
||||
backDatePenaltiesEnabledDefault.put("enabled", true);
|
||||
backDatePenaltiesEnabledDefault.put("trapDoor", false);
|
||||
defaults.add(backDatePenaltiesEnabledDefault);
|
||||
|
||||
HashMap<String, Object> organisationStartDateDefault = new HashMap<>();
|
||||
organisationStartDateDefault.put("id", 25);
|
||||
organisationStartDateDefault.put("name", "organisation-start-date");
|
||||
organisationStartDateDefault.put("value", 0);
|
||||
organisationStartDateDefault.put("enabled", false);
|
||||
organisationStartDateDefault.put("trapDoor", false);
|
||||
defaults.add(organisationStartDateDefault);
|
||||
|
||||
HashMap<String, Object> paymentTypeApplicableForDisbursementChargesDefault = new HashMap<>();
|
||||
paymentTypeApplicableForDisbursementChargesDefault.put("id", 26);
|
||||
paymentTypeApplicableForDisbursementChargesDefault.put("name", "paymenttype-applicable-for-disbursement-charges");
|
||||
paymentTypeApplicableForDisbursementChargesDefault.put("value", 0);
|
||||
paymentTypeApplicableForDisbursementChargesDefault.put("enabled", false);
|
||||
paymentTypeApplicableForDisbursementChargesDefault.put("trapDoor", false);
|
||||
defaults.add(paymentTypeApplicableForDisbursementChargesDefault);
|
||||
|
||||
HashMap<String, Object> interestChargedFromDateSameAsDisbursalDateDefault = new HashMap<>();
|
||||
interestChargedFromDateSameAsDisbursalDateDefault.put("id", 27);
|
||||
interestChargedFromDateSameAsDisbursalDateDefault.put("name", "interest-charged-from-date-same-as-disbursal-date");
|
||||
interestChargedFromDateSameAsDisbursalDateDefault.put("value", 0);
|
||||
interestChargedFromDateSameAsDisbursalDateDefault.put("enabled", false);
|
||||
interestChargedFromDateSameAsDisbursalDateDefault.put("trapDoor", false);
|
||||
defaults.add(interestChargedFromDateSameAsDisbursalDateDefault);
|
||||
|
||||
HashMap<String, Object> skipRepaymentOnFirstDayOfMonthDefault = new HashMap<>();
|
||||
skipRepaymentOnFirstDayOfMonthDefault.put("id", 28);
|
||||
skipRepaymentOnFirstDayOfMonthDefault.put("name", "skip-repayment-on-first-day-of-month");
|
||||
skipRepaymentOnFirstDayOfMonthDefault.put("value", 14);
|
||||
skipRepaymentOnFirstDayOfMonthDefault.put("enabled", false);
|
||||
skipRepaymentOnFirstDayOfMonthDefault.put("trapDoor", false);
|
||||
defaults.add(skipRepaymentOnFirstDayOfMonthDefault);
|
||||
|
||||
HashMap<String, Object> changeEmiIfRepaymentDateSameAsDisbursementDateDefault = new HashMap<>();
|
||||
changeEmiIfRepaymentDateSameAsDisbursementDateDefault.put("id", 29);
|
||||
changeEmiIfRepaymentDateSameAsDisbursementDateDefault.put("name", "change-emi-if-repaymentdate-same-as-disbursementdate");
|
||||
changeEmiIfRepaymentDateSameAsDisbursementDateDefault.put("value", 0);
|
||||
changeEmiIfRepaymentDateSameAsDisbursementDateDefault.put("enabled", true);
|
||||
changeEmiIfRepaymentDateSameAsDisbursementDateDefault.put("trapDoor", false);
|
||||
defaults.add(changeEmiIfRepaymentDateSameAsDisbursementDateDefault);
|
||||
|
||||
HashMap<String, Object> dailyTptLimitDefault = new HashMap<>();
|
||||
dailyTptLimitDefault.put("id", 30);
|
||||
dailyTptLimitDefault.put("name", "daily-tpt-limit");
|
||||
dailyTptLimitDefault.put("value", 0);
|
||||
dailyTptLimitDefault.put("enabled", false);
|
||||
dailyTptLimitDefault.put("trapDoor", false);
|
||||
defaults.add(dailyTptLimitDefault);
|
||||
|
||||
HashMap<String, Object> enableAddressDefault = new HashMap<>();
|
||||
enableAddressDefault.put("id", 31);
|
||||
enableAddressDefault.put("name", "Enable-Address");
|
||||
enableAddressDefault.put("value", 0);
|
||||
enableAddressDefault.put("enabled", false);
|
||||
enableAddressDefault.put("trapDoor", false);
|
||||
defaults.add(enableAddressDefault);
|
||||
|
||||
HashMap<String, Object> enableSubRatesDefault = new HashMap<>();
|
||||
enableSubRatesDefault.put("id", 32);
|
||||
enableSubRatesDefault.put("name", "sub-rates");
|
||||
enableSubRatesDefault.put("value", 0);
|
||||
enableSubRatesDefault.put("enabled", false);
|
||||
enableSubRatesDefault.put("trapDoor", false);
|
||||
defaults.add(enableSubRatesDefault);
|
||||
|
||||
HashMap<String, Object> isFirstPaydayAllowedOnHoliday = new HashMap<>();
|
||||
isFirstPaydayAllowedOnHoliday.put("id", 33);
|
||||
isFirstPaydayAllowedOnHoliday.put("name", "loan-reschedule-is-first-payday-allowed-on-holiday");
|
||||
isFirstPaydayAllowedOnHoliday.put("value", 0);
|
||||
isFirstPaydayAllowedOnHoliday.put("enabled", false);
|
||||
isFirstPaydayAllowedOnHoliday.put("trapDoor", false);
|
||||
defaults.add(isFirstPaydayAllowedOnHoliday);
|
||||
|
||||
HashMap<String, Object> isInterestAppropriationEnabled = new HashMap<>();
|
||||
isInterestAppropriationEnabled.put("id", 34);
|
||||
isInterestAppropriationEnabled.put("name", "is-interest-to-be-appropriated-equally-when-greater-than-emi");
|
||||
isInterestAppropriationEnabled.put("value", 0);
|
||||
isInterestAppropriationEnabled.put("enabled", false);
|
||||
isInterestAppropriationEnabled.put("trapDoor", false);
|
||||
defaults.add(isInterestAppropriationEnabled);
|
||||
|
||||
return defaults;
|
||||
}
|
||||
|
||||
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;
|
||||
LOG.info("---------------------------------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;
|
||||
LOG.info("---------------------------------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;
|
||||
LOG.info("------------------------ 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;
|
||||
LOG.info("------------------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;
|
||||
LOG.info("------------------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);
|
||||
LOG.info("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);
|
||||
LOG.info("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);
|
||||
LOG.info("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);
|
||||
LOG.info("map : {}", map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
}
|
||||
+322
@@ -0,0 +1,322 @@
|
||||
/**
|
||||
* 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.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.gson.Gson;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class GroupHelper {
|
||||
|
||||
private final RequestSpecification requestSpec;
|
||||
private final ResponseSpecification responseSpec;
|
||||
private static final Logger LOG = LoggerFactory.getLogger(GroupHelper.class);
|
||||
|
||||
private static final String CREATE_GROUP_URL = "/fineract-provider/api/v1/groups?" + Utils.TENANT_IDENTIFIER;
|
||||
public static final String DATE_FORMAT = "dd MMMM yyyy";
|
||||
public static final String DATE_TIME_FORMAT = "dd MMMM yyyy HH:mm";
|
||||
|
||||
public GroupHelper(final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {
|
||||
this.requestSpec = requestSpec;
|
||||
this.responseSpec = responseSpec;
|
||||
}
|
||||
|
||||
public static Integer createGroup(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
@SuppressWarnings("unused") final boolean active) {
|
||||
LOG.info("---------------------------------CREATING A GROUP---------------------------------------------");
|
||||
return createGroup(requestSpec, responseSpec, "04 March 2011");
|
||||
}
|
||||
|
||||
public static Integer createGroup(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String activationDate) {
|
||||
LOG.info("---------------------------------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) {
|
||||
LOG.info("---------------------------------CREATING A GROUP---------------------------------------------");
|
||||
return Utils.performServerPost(requestSpec, responseSpec, CREATE_GROUP_URL, getTestGroupAsJSON(false, ""), "groupId");
|
||||
}
|
||||
|
||||
public Object createGroupWithError(final String jsonAttributeToGetBack) {
|
||||
LOG.info("---------------------------------CREATING A GROUP WITH ERROR---------------------------------------------");
|
||||
return Utils.performServerPost(this.requestSpec, this.responseSpec, CREATE_GROUP_URL, getTestGroupAsJSON(false, ""),
|
||||
jsonAttributeToGetBack);
|
||||
}
|
||||
|
||||
public static Integer createGroupPendingWithDatatable(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String registeredTableName) {
|
||||
LOG.info("-------------------------- CREATING A GROUP WITH DATATABLES --------------------------------");
|
||||
return Utils.performServerPost(requestSpec, responseSpec, CREATE_GROUP_URL, getTestGroupWithDatatableAsJson(registeredTableName),
|
||||
"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;
|
||||
LOG.info("---------------------------------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;
|
||||
LOG.info("---------------------------------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;
|
||||
LOG.info("---------------------------------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;
|
||||
LOG.info("---------------------------------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;
|
||||
LOG.info("---------------------------------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";
|
||||
LOG.info("---------------------------------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";
|
||||
LOG.info("---------------------------------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");
|
||||
LOG.info("defaulting to inactive group: 04 March 2011");
|
||||
}
|
||||
LOG.debug("map : {} ", map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static String associateClientAsJSON(final String clientMember) {
|
||||
final HashMap<String, List<String>> map = new HashMap<>();
|
||||
final List<String> list = new ArrayList<>();
|
||||
list.add(clientMember);
|
||||
map.put("clientMembers", list);
|
||||
LOG.debug("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 (!Strings.isNullOrEmpty(activationDate)) {
|
||||
map.put("activationDate", activationDate);
|
||||
} else {
|
||||
map.put("activationDate", "04 March 2011");
|
||||
LOG.info("defaulting to fixed date: 04 March 2011");
|
||||
}
|
||||
LOG.debug("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);
|
||||
LOG.debug("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);
|
||||
LOG.debug("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");
|
||||
LOG.debug("map : {}", map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static void verifyGroupCreatedOnServer(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer generatedGroupID) {
|
||||
LOG.info("------------------------------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(generatedGroupID, responseGroupID, "ERROR IN CREATING THE GROUP");
|
||||
}
|
||||
|
||||
public static void verifyGroupDetails(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer generatedGroupID, final String field, final String expectedValue) {
|
||||
LOG.info("------------------------------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(expectedValue, responseValue, "ERROR IN CREATING THE GROUP");
|
||||
}
|
||||
|
||||
public static void verifyGroupActivatedOnServer(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer generatedGroupID, final boolean generatedGroupStatus) {
|
||||
LOG.info("------------------------------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(generatedGroupStatus, responseGroupStatus, "ERROR IN ACTIVATING THE GROUP");
|
||||
}
|
||||
|
||||
public static void verifyGroupMembers(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer generatedGroupID, final Integer groupMember) {
|
||||
List<String> list = new ArrayList<>();
|
||||
LOG.info("------------------------------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");
|
||||
LOG.debug("the list of verifyEmptyGroupMembers : {} ", list);
|
||||
assertTrue(list.toString().contains("id=" + groupMember.toString()), "ERROR IN GROUP MEMBER");
|
||||
}
|
||||
|
||||
public static void verifyEmptyGroupMembers(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer generatedGroupID) {
|
||||
List<String> list = new ArrayList<>();
|
||||
LOG.info("------------------------------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");
|
||||
LOG.debug("the list of verifyEmptyGroupMembers : {} ", list);
|
||||
assertEquals(list, null, "GROUP MEMBER LIST NOT EMPTY");
|
||||
}
|
||||
|
||||
public static void verifyGroupDeleted(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer generatedGroupID) {
|
||||
List<String> list = new ArrayList<>();
|
||||
LOG.info("------------------------------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(list.toString().contains("id=" + generatedGroupID.toString()), "GROUP NOT DELETED");
|
||||
}
|
||||
|
||||
// Glim_Gsim_testing
|
||||
public static List<String> verifyRetrieveGlimAccountsByGroupId(final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec, final Integer groupID) {
|
||||
List<String> list = new ArrayList<>();
|
||||
LOG.info("------------------------------CHECK GROUP Retrieve Accounts------------------------------------\n");
|
||||
final String GROUP_URL = "/fineract-provider/api/v1/groups/" + groupID + "/glimaccounts?" + Utils.TENANT_IDENTIFIER;
|
||||
list = Utils.performServerGet(requestSpec, responseSpec, GROUP_URL, "glimId");
|
||||
LOG.debug("GlimId of Retrieved Account : {} ", list);
|
||||
return list;
|
||||
}
|
||||
|
||||
public static List<String> verifyRetrieveGlimAccountsByGlimId(final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec, final Integer glimId) {
|
||||
List<String> list = new ArrayList<>();
|
||||
LOG.info("------------------------------CHECK GROUP Retrieve Accounts------------------------------------\n");
|
||||
final String GROUP_URL = "/fineract-provider/api/v1/loans/glimAccount/" + glimId + "?" + Utils.TENANT_IDENTIFIER;
|
||||
list = Utils.performServerGet(requestSpec, responseSpec, GROUP_URL, "glimId");
|
||||
LOG.debug("GlimId of Retrieved Account: {} ", list);
|
||||
return list;
|
||||
}
|
||||
|
||||
public static List<String> verifyRetrieveGsimAccounts(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer groupID) {
|
||||
List<String> list = new ArrayList<>();
|
||||
LOG.info("------------------------------CHECK GROUP Retrieve Accounts------------------------------------\n");
|
||||
final String GROUP_URL = "/fineract-provider/api/v1/groups/" + groupID + "/gsimaccounts?" + Utils.TENANT_IDENTIFIER;
|
||||
list = Utils.performServerGet(requestSpec, responseSpec, GROUP_URL, "gsimId");
|
||||
LOG.debug("GsimId Retrieved Accounts: {} ", list);
|
||||
return list;
|
||||
}
|
||||
|
||||
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 String getTestGroupWithDatatableAsJson(final String registeredTableName) {
|
||||
final HashMap<String, Object> 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");
|
||||
map.put("active", "false");
|
||||
map.put("submittedOnDate", "04 March 2011");
|
||||
String requestJson = getTestDatatableAsJson(map, registeredTableName);
|
||||
LOG.debug("map : {} ", requestJson);
|
||||
return requestJson;
|
||||
}
|
||||
|
||||
public static String getTestDatatableAsJson(HashMap<String, Object> map, final String registeredTableName) {
|
||||
List<HashMap<String, Object>> datatablesListMap = new ArrayList<>();
|
||||
HashMap<String, Object> datatableMap = new HashMap<>();
|
||||
HashMap<String, Object> dataMap = new HashMap<>();
|
||||
dataMap.put("locale", "en");
|
||||
dataMap.put("Spouse Name", Utils.randomNameGenerator("Spouse_name", 4));
|
||||
dataMap.put("Number of Dependents", 5);
|
||||
dataMap.put("Time of Visit", "01 December 2016 04:03");
|
||||
dataMap.put("dateFormat", DATE_TIME_FORMAT);
|
||||
dataMap.put("Date of Approval", "02 December 2016 00:00");
|
||||
datatableMap.put("registeredTableName", registeredTableName);
|
||||
datatableMap.put("data", dataMap);
|
||||
datatablesListMap.add(datatableMap);
|
||||
map.put("datatables", datatablesListMap);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
}
|
||||
+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 com.google.gson.Gson;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@SuppressWarnings({ "unused", "rawtypes" })
|
||||
public class HolidayHelper {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(HolidayHelper.class);
|
||||
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");
|
||||
map.put("reschedulingType", 2);
|
||||
String HolidayCreateJson = new Gson().toJson(map);
|
||||
LOG.info("{}", HolidayCreateJson);
|
||||
return HolidayCreateJson;
|
||||
}
|
||||
|
||||
public static String getActivateHolidayDataAsJSON() {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
String activateHoliday = new Gson().toJson(map);
|
||||
LOG.info("{}", 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;
|
||||
LOG.info("------------------------ RETRIEVING HOLIDAY BY ID -------------------------");
|
||||
final HashMap response = Utils.performServerGet(requestSpec, responseSpec, GET_HOLIDAY_BY_ID_URL, "");
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
/**
|
||||
* 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.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class HookHelper {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(HookHelper.class);
|
||||
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) {
|
||||
LOG.info("---------------------------------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);
|
||||
LOG.info("map : {}", map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public Integer updateHook(final String payloadURL, final Long hookId) {
|
||||
LOG.info("---------------------------------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) {
|
||||
LOG.info("---------------------------------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) {
|
||||
LOG.info("------------------------------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) {
|
||||
LOG.info("------------------------------CHECK UPDATE HOOK DETAILS------------------------------------\n");
|
||||
final String GET_URL = "/fineract-provider/api/v1/hooks/" + hookId + "?" + Utils.TENANT_IDENTIFIER;
|
||||
ArrayList<HashMap<String, String>> map = Utils.<ArrayList<HashMap<String, String>>>performServerGet(this.requestSpec,
|
||||
this.responseSpec, GET_URL, "config");
|
||||
HashMap<String, String> hash = map.get(1);
|
||||
assertEquals(updateURL, hash.get("fieldValue"));
|
||||
}
|
||||
|
||||
public void verifyDeleteHook(final Long hookId) {
|
||||
LOG.info("------------------------------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<HashMap<String, String>> array = Utils.<ArrayList<HashMap<String, String>>>performServerGet(this.requestSpec,
|
||||
responseSpec404, GET_URL, "errors");
|
||||
HashMap<String, String> map = array.get(0);
|
||||
assertEquals("error.msg.hook.identifier.not.found", map.get("userMessageGlobalisationCode"));
|
||||
}
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* 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 io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import org.apache.http.HttpHeaders;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@Deprecated // replaced by new ImageTest, can be deleted as FINERACT-1209 is fully implemented
|
||||
public final class ImageHelper {
|
||||
|
||||
private ImageHelper() {
|
||||
|
||||
}
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ImageHelper.class);
|
||||
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) {
|
||||
LOG.info("---------------------------------CREATING AN IMAGE FOR STAFF---------------------------------------------");
|
||||
final 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) {
|
||||
LOG.info("---------------------------------UPDATING AN IMAGE FOR STAFF---------------------------------------------");
|
||||
final 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) {
|
||||
LOG.info("---------------------------------RETRIEVING STAFF IMAGE---------------------------------------------");
|
||||
final 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) {
|
||||
LOG.info("---------------------------------RETRIEVING STAFF IMAGE---------------------------------------------");
|
||||
final 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) {
|
||||
LOG.info("---------------------------------RETRIEVING STAFF IMAGE---------------------------------------------");
|
||||
final String URL = STAFF_IMAGE_URL + staffId + IMAGES_URI + "?" + Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerDelete(requestSpec, responseSpec, URL, "resourceId");
|
||||
}
|
||||
|
||||
public static String generateImageAsText() {
|
||||
return "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJ\r\n"
|
||||
+ "bWFnZVJlYWR5ccllPAAAAJ1JREFUeNpi+P//PwMIA4E9EG8E4idQDGLbw+WhiiqA+D8OXAFVAzbp\r\n"
|
||||
+ "DxBvB2JLIGaGYkuoGEjOhhFIHAbij0BdPgxYACMj42ogJQpifwBiXSDeC8JIbt4LxSC5DyxQjTeB\r\n"
|
||||
+ "+BeaYb+Q5EBOAVutCzMJHUNNPADzzDokiYdAfAmJvwLkGeTgWQfyKZICS6hYBTwc0QL8ORSjBDhA\r\n" + "gAEAOg13B6R/SAgAAAAASUVORK5CYII=";
|
||||
}
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* 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.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.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(requestId, id, "ERROR IN CREATING LOAN RESCHEDULE REQUES");
|
||||
}
|
||||
}
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
/**
|
||||
* 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 io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public final class NotesHelper {
|
||||
|
||||
private NotesHelper() {
|
||||
|
||||
}
|
||||
|
||||
private static final String CLIENT_URL = "/fineract-provider/api/v1/clients";
|
||||
|
||||
public static Integer createClientNote(RequestSpecification requestSpec, ResponseSpecification responseSpec, Integer clientId,
|
||||
String request) {
|
||||
String createClientNoteURL = CLIENT_URL + "/" + clientId + "/notes?" + Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerPost(requestSpec, responseSpec, createClientNoteURL, request, "resourceId");
|
||||
}
|
||||
|
||||
public static String getClientNote(RequestSpecification requestSpec, ResponseSpecification responseSpec, Integer clientId,
|
||||
Integer noteId) {
|
||||
String getClientNoteURL = CLIENT_URL + "/" + clientId + "/notes/" + noteId + "?" + Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerGet(requestSpec, responseSpec, getClientNoteURL, "note");
|
||||
}
|
||||
|
||||
public static Integer updateClientNote(RequestSpecification requestSpec, ResponseSpecification responseSpec, Integer clientId,
|
||||
Integer noteId, String request) {
|
||||
String updateClientNoteURL = CLIENT_URL + "/" + clientId + "/notes/" + noteId + "?" + Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerPut(requestSpec, responseSpec, updateClientNoteURL, request, "resourceId");
|
||||
}
|
||||
|
||||
public static void deleteClientNote(RequestSpecification requestSpec, ResponseSpecification responseSpec, Integer clientId,
|
||||
Integer noteId) {
|
||||
String deleteClientNoteURL = CLIENT_URL + "/" + clientId + "/notes/" + noteId + "?" + Utils.TENANT_IDENTIFIER;
|
||||
Utils.performServerDelete(requestSpec, responseSpec, deleteClientNoteURL, "");
|
||||
}
|
||||
|
||||
private static final String GROUP_URL = "/fineract-provider/api/v1/groups";
|
||||
|
||||
public static Integer createGroupNote(RequestSpecification requestSpec, ResponseSpecification responseSpec, Integer groupId,
|
||||
String request) {
|
||||
String createGroupNoteURL = GROUP_URL + "/" + groupId + "/notes?" + Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerPost(requestSpec, responseSpec, createGroupNoteURL, request, "resourceId");
|
||||
}
|
||||
|
||||
public static String getGroupNote(RequestSpecification requestSpec, ResponseSpecification responseSpec, Integer groupId,
|
||||
Integer noteId) {
|
||||
String getGroupNoteURL = GROUP_URL + "/" + groupId + "/notes/" + noteId + "?" + Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerGet(requestSpec, responseSpec, getGroupNoteURL, "note");
|
||||
}
|
||||
|
||||
public static Integer updateGroupNote(RequestSpecification requestSpec, ResponseSpecification responseSpec, Integer groupId,
|
||||
Integer noteId, String request) {
|
||||
String updateGroupNoteURL = GROUP_URL + "/" + groupId + "/notes/" + noteId + "?" + Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerPut(requestSpec, responseSpec, updateGroupNoteURL, request, "resourceId");
|
||||
}
|
||||
|
||||
public static void deleteGroupNote(RequestSpecification requestSpec, ResponseSpecification responseSpec, Integer groupId,
|
||||
Integer noteId) {
|
||||
String deleteGroupNoteURL = GROUP_URL + "/" + groupId + "/notes/" + noteId + "?" + Utils.TENANT_IDENTIFIER;
|
||||
Utils.performServerDelete(requestSpec, responseSpec, deleteGroupNoteURL, "");
|
||||
}
|
||||
|
||||
private static final String LOAN_URL = "/fineract-provider/api/v1/loans";
|
||||
|
||||
public static Integer createLoanNote(RequestSpecification requestSpec, ResponseSpecification responseSpec, Integer loanId,
|
||||
String request) {
|
||||
String createLoanNoteURL = LOAN_URL + "/" + loanId + "/notes?" + Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerPost(requestSpec, responseSpec, createLoanNoteURL, request, "resourceId");
|
||||
}
|
||||
|
||||
public static String getLoanNote(RequestSpecification requestSpec, ResponseSpecification responseSpec, Integer loanId, Integer noteId) {
|
||||
String getLoanNoteURL = LOAN_URL + "/" + loanId + "/notes/" + noteId + "?" + Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerGet(requestSpec, responseSpec, getLoanNoteURL, "note");
|
||||
}
|
||||
|
||||
public static Integer updateLoanNote(RequestSpecification requestSpec, ResponseSpecification responseSpec, Integer loanId,
|
||||
Integer noteId, String updateRequest) {
|
||||
String updateLoanNoteURL = LOAN_URL + "/" + loanId + "/notes/" + noteId + "?" + Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerPut(requestSpec, responseSpec, updateLoanNoteURL, updateRequest, "resourceId");
|
||||
}
|
||||
|
||||
public static void deleteLoanNote(RequestSpecification requestSpec, ResponseSpecification responseSpec, Integer loanId,
|
||||
Integer noteId) {
|
||||
String deleteLoanNoteURL = LOAN_URL + "/" + loanId + "/notes/" + noteId + "?" + Utils.TENANT_IDENTIFIER;
|
||||
Utils.performServerDelete(requestSpec, responseSpec, deleteLoanNoteURL, "");
|
||||
}
|
||||
|
||||
private static final String LOAN_TRANSACTION_URL = "/fineract-provider/api/v1/loanTransactions";
|
||||
|
||||
public static Integer createLoanTransactionNote(RequestSpecification requestSpec, ResponseSpecification responseSpec,
|
||||
Integer loanTransactionId, String request) {
|
||||
String createLoanTransactionNoteURL = LOAN_TRANSACTION_URL + "/" + loanTransactionId + "/notes?" + Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerPost(requestSpec, responseSpec, createLoanTransactionNoteURL, request, "resourceId");
|
||||
}
|
||||
|
||||
public static String getLoanTransactionNote(RequestSpecification requestSpec, ResponseSpecification responseSpec,
|
||||
Integer loanTransactionId, Integer noteId) {
|
||||
String getLoanTransactionNoteURL = LOAN_TRANSACTION_URL + "/" + loanTransactionId + "/notes/" + noteId + "?"
|
||||
+ Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerGet(requestSpec, responseSpec, getLoanTransactionNoteURL, "note");
|
||||
}
|
||||
|
||||
public static Integer updateLoanTransactionNote(RequestSpecification requestSpec, ResponseSpecification responseSpec,
|
||||
Integer loanTransactionId, Integer noteId, String updateRequest) {
|
||||
String updateLoanTransactionNoteURL = LOAN_TRANSACTION_URL + "/" + loanTransactionId + "/notes/" + noteId + "?"
|
||||
+ Utils.TENANT_IDENTIFIER;
|
||||
return Utils.performServerPut(requestSpec, responseSpec, updateLoanTransactionNoteURL, updateRequest, "resourceId");
|
||||
}
|
||||
|
||||
public static void deleteLoanTransactionNote(RequestSpecification requestSpec, ResponseSpecification responseSpec,
|
||||
Integer loanTransactionId, Integer noteId) {
|
||||
String deleteLoanTransactionNoteURL = LOAN_TRANSACTION_URL + "/" + loanTransactionId + "/notes/" + noteId + "?"
|
||||
+ Utils.TENANT_IDENTIFIER;
|
||||
Utils.performServerDelete(requestSpec, responseSpec, deleteLoanTransactionNoteURL, "");
|
||||
}
|
||||
|
||||
}
|
||||
+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.common;
|
||||
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class NotificationHelper {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(NotificationHelper.class);
|
||||
private final RequestSpecification requestSpec;
|
||||
private final ResponseSpecification responseSpec;
|
||||
|
||||
private static final String NOTIFICATION_API_URL = "/fineract-provider/api/v1/notifications?" + Utils.TENANT_IDENTIFIER;
|
||||
|
||||
public NotificationHelper(RequestSpecification requestSpec, ResponseSpecification responseSpec) {
|
||||
this.requestSpec = requestSpec;
|
||||
this.responseSpec = responseSpec;
|
||||
}
|
||||
|
||||
public static Object getNotifications(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String jsonReturn) {
|
||||
final String GET_NOTIFICATIONS_URL = NOTIFICATION_API_URL;
|
||||
LOG.info("-----------------------------GET NOTIFICATIONS-----------------------------------");
|
||||
return Utils.performServerGet(requestSpec, responseSpec, GET_NOTIFICATIONS_URL, "");
|
||||
}
|
||||
}
|
||||
+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;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class OfficeDomain {
|
||||
|
||||
public static final 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() {
|
||||
|
||||
}
|
||||
|
||||
private OfficeDomain(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 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 += Arrays.hashCode(this.openingDate);
|
||||
}
|
||||
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()) && Arrays.equals(this.openingDate, od.getOpeningDate())
|
||||
&& this.hierarchy.equals(od.getHierarchy())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+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;
|
||||
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.gson.Gson;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class OfficeHelper {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(OfficeHelper.class);
|
||||
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) {
|
||||
Object get = Utils.performServerGet(requestSpec, responseSpec, OFFICE_URL + "/" + id + "?" + Utils.TENANT_IDENTIFIER, "");
|
||||
final String json = new Gson().toJson(get);
|
||||
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<String, String> map = new HashMap<String, String>();
|
||||
map.put("name", name);
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("locale", "en");
|
||||
map.put("openingDate", openingDate);
|
||||
|
||||
LOG.info("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);
|
||||
LOG.info("map : {}", map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public String importOfficeTemplate(File file) {
|
||||
String locale = "en";
|
||||
String dateFormat = "dd MMMM yyyy";
|
||||
requestSpec.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA);
|
||||
return Utils.performServerTemplatePost(requestSpec, responseSpec, OFFICE_URL + "/uploadtemplate" + "?" + Utils.TENANT_IDENTIFIER,
|
||||
null, file, locale, dateFormat);
|
||||
|
||||
}
|
||||
|
||||
public String getOutputTemplateLocation(final String importDocumentId) {
|
||||
requestSpec.header(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN);
|
||||
return Utils.performServerOutputTemplateLocationGet(requestSpec, responseSpec,
|
||||
"/fineract-provider/api/v1/imports/getOutputTemplateLocation" + "?" + Utils.TENANT_IDENTIFIER, importDocumentId);
|
||||
}
|
||||
|
||||
public Workbook getOfficeWorkBook(final String dateFormat) throws IOException {
|
||||
requestSpec.header(HttpHeaders.CONTENT_TYPE, "application/vnd.ms-excel");
|
||||
byte[] byteArray = Utils.performGetBinaryResponse(requestSpec, responseSpec,
|
||||
OFFICE_URL + "/downloadtemplate" + "?" + Utils.TENANT_IDENTIFIER + "&dateFormat=" + dateFormat);
|
||||
InputStream inputStream = new ByteArrayInputStream(byteArray);
|
||||
Workbook workbook = new HSSFWorkbook(inputStream);
|
||||
return workbook;
|
||||
}
|
||||
}
|
||||
+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 com.google.gson.Gson;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.util.HashMap;
|
||||
|
||||
public final class PasswordPreferencesHelper {
|
||||
|
||||
private 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 final 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;
|
||||
}
|
||||
|
||||
}
|
||||
+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.common;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.gson.Gson;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.util.HashMap;
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public final class PaymentTypeHelper {
|
||||
|
||||
private 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(generatedPaymentTypeID, responsePaymentTypeID, "ERROR IN CREATING THE PAYMENT TYPE");
|
||||
}
|
||||
|
||||
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---------------------------------------------");
|
||||
Object get = Utils.performServerGet(requestSpec, responseSpec, GET_PAYMENTTYPE_URL, "");
|
||||
final String jsonData = new Gson().toJson(get);
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
+250
@@ -0,0 +1,250 @@
|
||||
/**
|
||||
* 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 io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.ZoneId;
|
||||
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.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Assumptions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public class ProvisioningIntegrationTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ProvisioningIntegrationTest.class);
|
||||
private static final String NONE = "1";
|
||||
private static final int LOANPRODUCTS_SIZE = 10;
|
||||
|
||||
private RequestSpecification requestSpec;
|
||||
private ResponseSpecification responseSpec;
|
||||
private AccountHelper accountHelper;
|
||||
private LoanTransactionHelper loanTransactionHelper;
|
||||
|
||||
@BeforeEach
|
||||
public void setup() throws ParseException {
|
||||
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);
|
||||
Assumptions.assumeTrue(!isAlreadyProvisioningEntriesCreated());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateProvisioningCriteria() {
|
||||
ProvisioningTransactionHelper transactionHelper = new ProvisioningTransactionHelper(requestSpec, responseSpec);
|
||||
ArrayList<Integer> loanProducts = new ArrayList<>(LOANPRODUCTS_SIZE);
|
||||
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);
|
||||
Assertions.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);
|
||||
LOG.info("-------------------------------DISBURSE LOAN-------------------------------------------");
|
||||
loanStatusHashMap = this.loanTransactionHelper.disburseLoan("20 September 2011", loanID);
|
||||
LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap);
|
||||
Assertions.assertNotNull(loanID);
|
||||
}
|
||||
|
||||
ArrayList categories = transactionHelper.retrieveAllProvisioningCategories();
|
||||
Assertions.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);
|
||||
Assertions.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", Float.valueOf((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);
|
||||
Assertions.assertNotNull(criteriaId);
|
||||
|
||||
String provisioningEntryJson = ProvisioningHelper.createProvisioningEntryJson();
|
||||
Integer provisioningEntryId = transactionHelper.createProvisioningEntries(provisioningEntryJson);
|
||||
Assertions.assertNotNull(provisioningEntryId);
|
||||
|
||||
transactionHelper.updateProvisioningEntry("recreateprovisioningentry", provisioningEntryId, "");
|
||||
transactionHelper.updateProvisioningEntry("createjournalentry", provisioningEntryId, "");
|
||||
Map entry = transactionHelper.retrieveProvisioningEntry(provisioningEntryId);
|
||||
Assertions.assertTrue((Boolean) entry.get("journalEntry"));
|
||||
Map provisioningEntry = transactionHelper.retrieveProvisioningEntries(provisioningEntryId);
|
||||
Assertions.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");
|
||||
Assertions.assertEquals(criteriaName, requestCriteriaName);
|
||||
|
||||
// loan products validation
|
||||
ArrayList requestProducts = (ArrayList) requestCriteria.get("loanProducts");
|
||||
ArrayList products = (ArrayList) newCriteria.get("loanProducts");
|
||||
Assertions.assertEquals(products.size(), requestProducts.size());
|
||||
|
||||
ArrayList requestedDefinitions = (ArrayList) requestCriteria.get("definitions");
|
||||
ArrayList newdefintions = (ArrayList) newCriteria.get("definitions");
|
||||
Assertions.assertEquals(newdefintions.size(), requestedDefinitions.size());
|
||||
for (int i = 0; i < newdefintions.size(); i++) {
|
||||
Map requestedMap = (Map) requestedDefinitions.get(i);
|
||||
Object requestedCategoryId = requestedMap.get("categoryId");
|
||||
boolean found = false;
|
||||
for (int j = 0; j < newdefintions.size(); j++) {
|
||||
Map newMap = (Map) newdefintions.get(j);
|
||||
Object newCategoryId = newMap.get("categoryId");
|
||||
if (requestedCategoryId.equals(newCategoryId)) {
|
||||
found = true;
|
||||
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);
|
||||
break; // internal loop
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
Assertions.fail("No Category found with Id:" + requestedCategoryId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkProperty(String propertyName, Map requestMap, Map newMap) {
|
||||
Object requested = requestMap.get(propertyName);
|
||||
Object modified = newMap.get(propertyName);
|
||||
Assertions.assertEquals(requested, modified);
|
||||
}
|
||||
|
||||
private Integer createLoanProduct(final boolean multiDisburseLoan, final String accountingRule, final Account... accounts) {
|
||||
LOG.info("------------------------------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) {
|
||||
LOG.info("--------------------------------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() throws ParseException {
|
||||
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");
|
||||
Date date1 = formatter.parse(date);
|
||||
DateFormat simple = new SimpleDateFormat("dd MMMM yyyy");
|
||||
String formattedString = simple
|
||||
.format(Date.from(Utils.getLocalDateOfTenant().atStartOfDay(ZoneId.systemDefault()).toInstant()));
|
||||
Date currentDate = simple.parse(formattedString);
|
||||
if (date1.getTime() == currentDate.getTime()) {
|
||||
provisioningetryAlreadyCreated = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return provisioningetryAlreadyCreated;
|
||||
}
|
||||
}
|
||||
+212
@@ -0,0 +1,212 @@
|
||||
/**
|
||||
* 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 java.time.Instant.now;
|
||||
import static org.awaitility.Awaitility.await;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class SchedulerJobHelper {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(SchedulerJobHelper.class);
|
||||
private final RequestSpecification requestSpec;
|
||||
private final ResponseSpecification response200Spec;
|
||||
private final ResponseSpecification response202Spec;
|
||||
|
||||
public SchedulerJobHelper(final RequestSpecification requestSpec) {
|
||||
this.requestSpec = requestSpec;
|
||||
this.response200Spec = new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||
this.response202Spec = new ResponseSpecBuilder().expectStatusCode(202).build();
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> getAllSchedulerJobs() {
|
||||
final String GET_ALL_SCHEDULER_JOBS_URL = "/fineract-provider/api/v1/jobs?" + Utils.TENANT_IDENTIFIER;
|
||||
LOG.info("------------------------ RETRIEVING ALL SCHEDULER JOBS -------------------------");
|
||||
List<Map<String, Object>> response = Utils.performServerGet(requestSpec, response200Spec, GET_ALL_SCHEDULER_JOBS_URL, "");
|
||||
assertNotNull(response);
|
||||
return response;
|
||||
}
|
||||
|
||||
private <T> List<T> getAllSchedulerJobDetails(Function<Map<String, Object>, T> mapper) {
|
||||
return getAllSchedulerJobs().stream().map(mapper).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<Integer> getAllSchedulerJobIds() {
|
||||
return getAllSchedulerJobDetails(map -> (Integer) map.get("jobId"));
|
||||
}
|
||||
|
||||
public List<String> getAllSchedulerJobNames() {
|
||||
return getAllSchedulerJobDetails(map -> (String) map.get("displayName"));
|
||||
}
|
||||
|
||||
public Map<String, Object> getSchedulerJobById(int jobId) {
|
||||
final String GET_SCHEDULER_JOB_BY_ID_URL = "/fineract-provider/api/v1/jobs/" + jobId + "?" + Utils.TENANT_IDENTIFIER;
|
||||
LOG.info("------------------------ RETRIEVING SCHEDULER JOB BY ID -------------------------");
|
||||
final Map<String, Object> response = Utils.performServerGet(requestSpec, response200Spec, GET_SCHEDULER_JOB_BY_ID_URL, "");
|
||||
LOG.info("{}", response.toString());
|
||||
assertNotNull(response);
|
||||
return response;
|
||||
}
|
||||
|
||||
public Boolean getSchedulerStatus() {
|
||||
final String GET_SCHEDULER_STATUS_URL = "/fineract-provider/api/v1/scheduler?" + Utils.TENANT_IDENTIFIER;
|
||||
LOG.info("------------------------ RETRIEVING SCHEDULER STATUS -------------------------");
|
||||
final Map<String, Object> response = Utils.performServerGet(requestSpec, response200Spec, GET_SCHEDULER_STATUS_URL, "");
|
||||
return (Boolean) response.get("active");
|
||||
}
|
||||
|
||||
public void updateSchedulerStatus(final boolean on) {
|
||||
String command = on ? "start" : "stop";
|
||||
final String UPDATE_SCHEDULER_STATUS_URL = "/fineract-provider/api/v1/scheduler?command=" + command + "&" + Utils.TENANT_IDENTIFIER;
|
||||
LOG.info("------------------------ UPDATING SCHEDULER STATUS -------------------------");
|
||||
Utils.performServerPost(requestSpec, response202Spec, UPDATE_SCHEDULER_STATUS_URL, runSchedulerJobAsJSON(), null);
|
||||
}
|
||||
|
||||
public Map<String, Object> updateSchedulerJob(int jobId, final boolean active) {
|
||||
final String UPDATE_SCHEDULER_JOB_URL = "/fineract-provider/api/v1/jobs/" + jobId + "?" + Utils.TENANT_IDENTIFIER;
|
||||
LOG.info("------------------------ UPDATING SCHEDULER JOB -------------------------");
|
||||
final Map<String, Object> response = Utils.performServerPut(requestSpec, response200Spec, UPDATE_SCHEDULER_JOB_URL,
|
||||
updateSchedulerJobAsJSON(active), "changes");
|
||||
return response;
|
||||
}
|
||||
|
||||
private static String updateSchedulerJobAsJSON(final boolean active) {
|
||||
final Map<String, String> map = new HashMap<>();
|
||||
map.put("active", Boolean.toString(active));
|
||||
LOG.info("map : {}", map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
private void runSchedulerJob(int 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;
|
||||
LOG.info("------------------------ RUN SCHEDULER JOB -------------------------");
|
||||
Utils.performServerPost(requestSpec, responseSpec, RUN_SCHEDULER_JOB_URL, runSchedulerJobAsJSON(), null);
|
||||
}
|
||||
|
||||
private static String runSchedulerJobAsJSON() {
|
||||
final Map<String, String> map = new HashMap<>();
|
||||
String runSchedulerJob = new Gson().toJson(map);
|
||||
LOG.info(runSchedulerJob);
|
||||
return runSchedulerJob;
|
||||
}
|
||||
|
||||
private int getSchedulerJobIdByName(String jobName) {
|
||||
List<Map<String, Object>> allSchedulerJobsData = getAllSchedulerJobs();
|
||||
for (Integer jobIndex = 0; jobIndex < allSchedulerJobsData.size(); jobIndex++) {
|
||||
if (allSchedulerJobsData.get(jobIndex).get("displayName").equals(jobName)) {
|
||||
return (Integer) allSchedulerJobsData.get(jobIndex).get("jobId");
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException(
|
||||
"No such named Job (see org.apache.fineract.infrastructure.jobs.service.JobName enum):" + jobName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Launches a Job and awaits its completion.
|
||||
*
|
||||
* @param jobName
|
||||
* displayName (see {@link org.apache.fineract.infrastructure.jobs.service.JobName}) of Scheduler Job
|
||||
*
|
||||
* @author Michael Vorburger.ch
|
||||
*/
|
||||
public void executeAndAwaitJob(String jobName) {
|
||||
final Duration timeout = Duration.ofSeconds(30);
|
||||
final Duration pause = Duration.ofMillis(500);
|
||||
DateTimeFormatter df = DateTimeFormatter.ISO_INSTANT; // FINERACT-926
|
||||
Instant beforeExecuteTime = now().truncatedTo(ChronoUnit.SECONDS);
|
||||
|
||||
// Stop the Scheduler while we manually trigger execution of job, to
|
||||
// avoid side effects and simplify debugging when readings logs
|
||||
updateSchedulerStatus(false);
|
||||
|
||||
// Executing Scheduler Job
|
||||
int jobId = getSchedulerJobIdByName(jobName);
|
||||
runSchedulerJob(jobId);
|
||||
|
||||
// Await JobDetailData.lastRunHistory [JobDetailHistoryData]
|
||||
// jobRunStartTime >= beforeExecuteTime (or timeout)
|
||||
await().atMost(timeout).pollInterval(pause).until(jobLastRunHistorySupplier(jobId), lastRunHistory -> {
|
||||
String jobRunStartText = lastRunHistory.get("jobRunStartTime");
|
||||
if (jobRunStartText == null) {
|
||||
return false;
|
||||
}
|
||||
Instant jobRunStartTime = df.parse(jobRunStartText, Instant::from);
|
||||
return jobRunStartTime.equals(beforeExecuteTime) || jobRunStartTime.isAfter(beforeExecuteTime);
|
||||
});
|
||||
|
||||
// Await JobDetailData.lastRunHistory [JobDetailHistoryData]
|
||||
// jobRunEndTime to be both set and >= jobRunStartTime (or timeout)
|
||||
Map<String, String> finalLastRunHistory = await().atMost(timeout).pollInterval(pause).until(jobLastRunHistorySupplier(jobId),
|
||||
lastRunHistory -> {
|
||||
String jobRunEndText = lastRunHistory.get("jobRunEndTime");
|
||||
if (jobRunEndText == null) {
|
||||
return false;
|
||||
}
|
||||
Instant jobRunEndTime = df.parse(jobRunEndText, Instant::from);
|
||||
Instant jobRunStartTime = df.parse(lastRunHistory.get("jobRunStartTime"), Instant::from);
|
||||
return jobRunEndTime.equals(jobRunStartTime) || jobRunEndTime.isAfter(jobRunStartTime);
|
||||
});
|
||||
|
||||
// Verify triggerType
|
||||
assertThat(finalLastRunHistory.get("triggerType"), is("application"));
|
||||
|
||||
// Verify status & propagate jobRunErrorMessage and/or jobRunErrorLog
|
||||
// (if any)
|
||||
String status = finalLastRunHistory.get("status");
|
||||
if (!status.equals("success")) {
|
||||
fail("Job status is not success: " + finalLastRunHistory.toString());
|
||||
}
|
||||
|
||||
// PS: Checking getSchedulerJobHistory() [/runhistory] is pointless,
|
||||
// because the lastRunHistory JobDetailHistoryData is already part of
|
||||
// JobDetailData anyway.
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Callable<Map<String, String>> jobLastRunHistorySupplier(int jobId) {
|
||||
return () -> {
|
||||
Map<String, Object> job = getSchedulerJobById(jobId);
|
||||
if (job == null) {
|
||||
return null;
|
||||
}
|
||||
return (Map<String, String>) job.get("lastRunHistory");
|
||||
};
|
||||
}
|
||||
}
|
||||
+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 com.google.gson.Gson;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@SuppressWarnings({ "unused", "rawtypes", "unchecked" })
|
||||
public class StandingInstructionsHelper {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(StandingInstructionsHelper.class);
|
||||
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);
|
||||
LOG.info("{}", 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) {
|
||||
LOG.info("-------------------------------- 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) {
|
||||
|
||||
LOG.info("----------------------------- 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;
|
||||
LOG.info("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;
|
||||
}
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
* 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.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.util.HashMap;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public final class SurveyHelper {
|
||||
|
||||
private SurveyHelper() {
|
||||
|
||||
}
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(SurveyHelper.class);
|
||||
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) {
|
||||
LOG.info("---------------------------------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");
|
||||
|
||||
LOG.info("map : {}", map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static void verifySurveyCreatedOnServer(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer generatedClientID) {
|
||||
LOG.info("------------------------------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(generatedClientID, responseClientID, "ERROR IN CREATING THE CLIENT");
|
||||
}
|
||||
|
||||
}
|
||||
+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;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.util.HashMap;
|
||||
import org.apache.fineract.integrationtests.common.accounting.Account;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public final class TaxComponentHelper {
|
||||
|
||||
private TaxComponentHelper() {
|
||||
|
||||
}
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(TaxComponentHelper.class);
|
||||
private static final String CREATE_TAX_COMPONENT_URL = "/fineract-provider/api/v1/taxes/component?" + Utils.TENANT_IDENTIFIER;
|
||||
|
||||
public static Integer createTaxComponent(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String percentage, final Integer liabilityAccountId) {
|
||||
LOG.info("---------------------------------CREATING A TAX COMPONENT---------------------------------------------");
|
||||
return Utils.performServerPost(requestSpec, responseSpec, CREATE_TAX_COMPONENT_URL,
|
||||
getTaxComponentAsJSON(percentage, liabilityAccountId), "resourceId");
|
||||
}
|
||||
|
||||
public static String getTaxComponentAsJSON(final String percentage, final Integer creditAccountId) {
|
||||
final HashMap<String, String> map = getBasicTaxComponentMap(percentage);
|
||||
if (creditAccountId != null) {
|
||||
map.put("creditAccountType", Account.AccountType.LIABILITY.toString());
|
||||
map.put("creditAcountId", String.valueOf(creditAccountId));
|
||||
}
|
||||
LOG.info("map : {}", map);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static HashMap<String, String> getBasicTaxComponentMap(final String percentage) {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("name", randomNameGenerator("Tax_component_Name_", 5));
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("locale", "en");
|
||||
map.put("percentage", percentage);
|
||||
map.put("startDate", "01 January 2013");
|
||||
return map;
|
||||
}
|
||||
|
||||
public static String randomNameGenerator(final String prefix, final int lenOfRandomSuffix) {
|
||||
return Utils.randomStringGenerator(prefix, lenOfRandomSuffix);
|
||||
}
|
||||
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* 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 io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public final class TaxGroupHelper {
|
||||
|
||||
private TaxGroupHelper() {
|
||||
|
||||
}
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(TaxGroupHelper.class);
|
||||
private static final String CREATE_TAX_COMPONENT_URL = "/fineract-provider/api/v1/taxes/group?" + Utils.TENANT_IDENTIFIER;
|
||||
|
||||
public static Integer createTaxGroup(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Collection<Integer> taxComponentIds) {
|
||||
LOG.info("---------------------------------CREATING A TAX GROUP---------------------------------------------");
|
||||
return Utils.performServerPost(requestSpec, responseSpec, CREATE_TAX_COMPONENT_URL, getTaxGroupAsJSON(taxComponentIds),
|
||||
"resourceId");
|
||||
}
|
||||
|
||||
public static String getTaxGroupAsJSON(final Collection<Integer> taxComponentIds) {
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("name", randomNameGenerator("Tax_component_Name_", 5));
|
||||
map.put("dateFormat", "dd MMMM yyyy");
|
||||
map.put("locale", "en");
|
||||
map.put("taxComponents", getTaxGroupComponents(taxComponentIds));
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public static List<HashMap<String, String>> getTaxGroupComponents(final Collection<Integer> taxComponentIds) {
|
||||
List<HashMap<String, String>> taxGroupComponents = new ArrayList<>();
|
||||
for (Integer taxComponentId : taxComponentIds) {
|
||||
taxGroupComponents.add(getTaxComponentMap(taxComponentId));
|
||||
}
|
||||
return taxGroupComponents;
|
||||
}
|
||||
|
||||
public static HashMap<String, String> getTaxComponentMap(final Integer taxComponentId) {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put("taxComponentId", String.valueOf(taxComponentId));
|
||||
map.put("startDate", "01 January 2013");
|
||||
return map;
|
||||
}
|
||||
|
||||
public static String randomNameGenerator(final String prefix, final int lenOfRandomSuffix) {
|
||||
return Utils.randomStringGenerator(prefix, lenOfRandomSuffix);
|
||||
}
|
||||
|
||||
}
|
||||
+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.common;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.path.json.JsonPath;
|
||||
import io.restassured.response.Response;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import java.io.File;
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
import java.util.Calendar;
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
import java.util.TimeZone;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.conn.HttpHostConnectException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Util for RestAssured tests. This class here in src/integrationTest is copy/pasted to src/test; please keep them in
|
||||
* sync.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public final class Utils {
|
||||
|
||||
private Utils() {
|
||||
|
||||
}
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Utils.class);
|
||||
|
||||
public static final String TENANT_PARAM_NAME = "tenantIdentifier";
|
||||
public static final String DEFAULT_TENANT = "default";
|
||||
public static final String TENANT_IDENTIFIER = TENANT_PARAM_NAME + '=' + DEFAULT_TENANT;
|
||||
|
||||
public static final String TENANT_TIME_ZONE = "Asia/Kolkata";
|
||||
|
||||
private static final String HEALTH_URL = "/fineract-provider/actuator/health";
|
||||
private static final String LOGIN_URL = "/fineract-provider/api/v1/authentication?" + TENANT_IDENTIFIER;
|
||||
|
||||
public static void initializeRESTAssured() {
|
||||
RestAssured.baseURI = "https://localhost";
|
||||
RestAssured.port = 8443;
|
||||
RestAssured.keyStore("src/main/resources/keystore.jks", "openmf");
|
||||
RestAssured.useRelaxedHTTPSValidation();
|
||||
}
|
||||
|
||||
private static void awaitSpringBootActuatorHealthyUp() {
|
||||
int attempt = 0;
|
||||
final int max_attempts = 10;
|
||||
Response response = null;
|
||||
Exception lastException = null;
|
||||
do {
|
||||
try {
|
||||
response = RestAssured.get(HEALTH_URL);
|
||||
int healthHttpStatus = response.statusCode();
|
||||
if (healthHttpStatus == 200) {
|
||||
LOG.info("{} return HTTP 200, application is now ready for integration testing!", HEALTH_URL);
|
||||
return;
|
||||
} else {
|
||||
LOG.info("{} returned HTTP {}, going to wait and retry (attempt {})", HEALTH_URL, healthHttpStatus, attempt++);
|
||||
sleep(3);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.info("{} caused {}, going to wait and retry (attempt {})", HEALTH_URL, e.getMessage(), attempt++);
|
||||
lastException = e;
|
||||
sleep(3);
|
||||
}
|
||||
} while (attempt < max_attempts);
|
||||
|
||||
if (lastException != null) {
|
||||
LOG.error("{} still not reachable, giving up", HEALTH_URL, lastException);
|
||||
throw new AssertionError(HEALTH_URL + " not reachable", lastException);
|
||||
} else {
|
||||
LOG.error("{} still has not returned HTTP 200, giving up (last) body: {}", HEALTH_URL, response.prettyPrint());
|
||||
fail(HEALTH_URL + " returned " + response.prettyPrint());
|
||||
}
|
||||
}
|
||||
|
||||
private static void sleep(int seconds) {
|
||||
try {
|
||||
Thread.sleep(seconds * 1000);
|
||||
} catch (InterruptedException e) {
|
||||
LOG.warn("Unexpected InterruptedException", e);
|
||||
throw new IllegalStateException("Unexpected InterruptedException", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static String loginIntoServerAndGetBase64EncodedAuthenticationKey() {
|
||||
awaitSpringBootActuatorHealthyUp();
|
||||
try {
|
||||
LOG.info("Logging in, for integration test...");
|
||||
// system.out.println("-----------------------------------LOGIN-----------------------------------------");
|
||||
String json = RestAssured.given().contentType(ContentType.JSON).body("{\"username\":\"mifos\", \"password\":\"password\"}")
|
||||
.expect().log().ifError().when().post(LOGIN_URL).asString();
|
||||
assertThat("Failed to login into fineract platform", StringUtils.isBlank(json), is(false));
|
||||
String key = JsonPath.with(json).get("base64EncodedAuthenticationKey");
|
||||
assertThat("Failed to obtain key: " + json, StringUtils.isBlank(key), is(false));
|
||||
return key;
|
||||
} 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) JsonPath.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) JsonPath.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) JsonPath.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) JsonPath.from(json).get(jsonAttributeToGetBack);
|
||||
}
|
||||
|
||||
public static <T> T performServerDelete(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String deleteURL, final String jsonBodyToSend, final String jsonAttributeToGetBack) {
|
||||
final String json = given().spec(requestSpec).body(jsonBodyToSend).expect().spec(responseSpec).log().ifError().when()
|
||||
.delete(deleteURL).andReturn().asString();
|
||||
return (T) (jsonAttributeToGetBack == null ? json : JsonPath.from(json).get(jsonAttributeToGetBack));
|
||||
}
|
||||
|
||||
public static String convertDateToURLFormat(final String dateToBeConvert) throws ParseException {
|
||||
final SimpleDateFormat oldFormat = new SimpleDateFormat("dd MMMMMM yyyy", Locale.US);
|
||||
final SimpleDateFormat newFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
String reformattedStr = "";
|
||||
|
||||
reformattedStr = newFormat.format(oldFormat.parse(dateToBeConvert));
|
||||
|
||||
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 Long randomNumberGenerator(final int expectedLength) {
|
||||
final String source = "1234567890";
|
||||
final int lengthofSource = source.length();
|
||||
final Random random = new Random();
|
||||
StringBuilder stringBuilder = new StringBuilder(expectedLength);
|
||||
for (int i = 0; i < expectedLength; i++) {
|
||||
stringBuilder.append(source.charAt(random.nextInt(lengthofSource)));
|
||||
}
|
||||
return Long.parseLong(stringBuilder.toString());
|
||||
}
|
||||
|
||||
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 = LocalDate.now(ZoneId.systemDefault());
|
||||
final ZoneId zone = ZoneId.of(TENANT_TIME_ZONE);
|
||||
if (zone != null) {
|
||||
today = LocalDate.now(zone);
|
||||
}
|
||||
return today;
|
||||
}
|
||||
|
||||
public static TimeZone getTimeZoneOfTenant() {
|
||||
return TimeZone.getTimeZone(TENANT_TIME_ZONE);
|
||||
}
|
||||
|
||||
public static String performServerTemplatePost(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final String postURL, final String legalFormType, final File file, final String locale, final String dateFormat) {
|
||||
|
||||
final String importDocumentId = given().spec(requestSpec).queryParam("legalFormType", legalFormType).multiPart("file", file)
|
||||
.formParam("locale", locale).formParam("dateFormat", dateFormat).expect().spec(responseSpec).log().ifError().when()
|
||||
.post(postURL).andReturn().asString();
|
||||
return importDocumentId;
|
||||
}
|
||||
|
||||
public static String performServerOutputTemplateLocationGet(final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec, final String getURL, final String importDocumentId) {
|
||||
final String templateLocation = given().spec(requestSpec).queryParam("importDocumentId", importDocumentId).expect()
|
||||
.spec(responseSpec).log().ifError().when().get(getURL).andReturn().asString();
|
||||
return templateLocation.substring(1, templateLocation.length() - 1);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user