Setting Fraud flag for a loan account
This commit is contained in:
committed by
Arnold Gálovics
parent
0049a9e3f9
commit
b2482c9226
+157
@@ -0,0 +1,157 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import 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 java.time.LocalDate;
|
||||
import java.util.HashMap;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.fineract.client.models.GetLoanProductsProductIdResponse;
|
||||
import org.apache.fineract.client.models.GetLoansLoanIdResponse;
|
||||
import org.apache.fineract.client.models.PutLoansLoanIdResponse;
|
||||
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.LoanTransactionHelper;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@Slf4j
|
||||
public class LoanAccountFraudTest {
|
||||
|
||||
private ResponseSpecification responseSpec;
|
||||
private ResponseSpecification responseSpecError;
|
||||
private RequestSpecification requestSpec;
|
||||
private LoanTransactionHelper loanTransactionHelper;
|
||||
private final String amountVal = "1000";
|
||||
private LocalDate todaysDate;
|
||||
private String operationDate;
|
||||
|
||||
@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.responseSpecError = new ResponseSpecBuilder().expectStatusCode(503).build();
|
||||
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
|
||||
|
||||
this.todaysDate = Utils.getLocalDateOfTenant();
|
||||
this.operationDate = Utils.dateFormatter.format(this.todaysDate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMarkLoanAsFraud() {
|
||||
final String command = "markAsFraud";
|
||||
// Client and Loan account creation
|
||||
final Integer loanId = createAccounts(15, 1);
|
||||
|
||||
GetLoansLoanIdResponse getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||
assertNotNull(getLoansLoanIdResponse);
|
||||
|
||||
// Default values Not Null and False
|
||||
assertNotNull(getLoansLoanIdResponse.getFraud());
|
||||
assertEquals(Boolean.FALSE, getLoansLoanIdResponse.getFraud());
|
||||
|
||||
String payload = loanTransactionHelper.getLoanFraudPayloadAsJSON("fraud", "true");
|
||||
// Send the request expecting an error because the Loan is not active yet
|
||||
PutLoansLoanIdResponse putLoansLoanIdResponse = loanTransactionHelper.modifyLoanCommand(loanId, command, payload,
|
||||
this.responseSpecError);
|
||||
|
||||
String statusCode = getLoansLoanIdResponse.getStatus().getCode();
|
||||
log.info("Loan with Id {} is with Status {}", getLoansLoanIdResponse.getId(), statusCode);
|
||||
|
||||
// Approve the Loan active
|
||||
approveAndDisburseLoan(loanId, this.operationDate, this.amountVal);
|
||||
|
||||
// Default values Not Null and False
|
||||
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||
assertNotNull(getLoansLoanIdResponse);
|
||||
assertNotNull(getLoansLoanIdResponse.getFraud());
|
||||
assertEquals(Boolean.FALSE, getLoansLoanIdResponse.getFraud());
|
||||
statusCode = getLoansLoanIdResponse.getStatus().getCode();
|
||||
log.info("Loan with Id {} is with Status {}", getLoansLoanIdResponse.getId(), statusCode);
|
||||
|
||||
// Mark On the Fraud
|
||||
putLoansLoanIdResponse = loanTransactionHelper.modifyLoanCommand(loanId, command, payload, this.responseSpec);
|
||||
assertNotNull(putLoansLoanIdResponse);
|
||||
|
||||
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||
assertNotNull(getLoansLoanIdResponse);
|
||||
assertNotNull(getLoansLoanIdResponse.getFraud());
|
||||
assertEquals(Boolean.TRUE, getLoansLoanIdResponse.getFraud());
|
||||
|
||||
// Mark Off the Fraud
|
||||
payload = loanTransactionHelper.getLoanFraudPayloadAsJSON("fraud", "false");
|
||||
putLoansLoanIdResponse = loanTransactionHelper.modifyLoanCommand(loanId, command, payload, this.responseSpec);
|
||||
assertNotNull(putLoansLoanIdResponse);
|
||||
|
||||
getLoansLoanIdResponse = loanTransactionHelper.getLoan(requestSpec, responseSpec, loanId);
|
||||
assertNotNull(getLoansLoanIdResponse);
|
||||
assertNotNull(getLoansLoanIdResponse.getFraud());
|
||||
assertEquals(Boolean.FALSE, getLoansLoanIdResponse.getFraud());
|
||||
}
|
||||
|
||||
private Integer createAccounts(final Integer daysToSubtract, final Integer numberOfRepayments) {
|
||||
// Client and Loan account creation
|
||||
final Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2012");
|
||||
final GetLoanProductsProductIdResponse getLoanProductsProductResponse = createLoanProduct(loanTransactionHelper, null);
|
||||
|
||||
// Older date to have more than one overdue installment
|
||||
final LocalDate transactionDate = this.todaysDate.minusDays(daysToSubtract + (30 * (numberOfRepayments - 1)));
|
||||
String operationDate = Utils.dateFormatter.format(transactionDate);
|
||||
|
||||
return createLoanAccount(loanTransactionHelper, clientId.toString(), getLoanProductsProductResponse.getId().toString(),
|
||||
operationDate, amountVal, numberOfRepayments.toString());
|
||||
}
|
||||
|
||||
private GetLoanProductsProductIdResponse createLoanProduct(final LoanTransactionHelper loanTransactionHelper,
|
||||
final Integer delinquencyBucketId) {
|
||||
final HashMap<String, Object> loanProductMap = new LoanProductTestBuilder().build(null, delinquencyBucketId);
|
||||
final Integer loanProductId = loanTransactionHelper.getLoanProductId(Utils.convertToJson(loanProductMap));
|
||||
return loanTransactionHelper.getLoanProduct(loanProductId);
|
||||
}
|
||||
|
||||
private Integer createLoanAccount(final LoanTransactionHelper loanTransactionHelper, final String clientId, final String loanProductId,
|
||||
final String operationDate, final String principalAmount, final String numberOfRepayments) {
|
||||
final String loanApplicationJSON = new LoanApplicationTestBuilder().withPrincipal(principalAmount)
|
||||
.withLoanTermFrequency(numberOfRepayments).withLoanTermFrequencyAsMonths().withNumberOfRepayments(numberOfRepayments)
|
||||
.withRepaymentEveryAfter("1").withRepaymentFrequencyTypeAsMonths() //
|
||||
.withInterestRatePerPeriod("0") //
|
||||
.withExpectedDisbursementDate(operationDate) //
|
||||
.withInterestTypeAsDecliningBalance() //
|
||||
.withSubmittedOnDate(operationDate) //
|
||||
.build(clientId, loanProductId, null);
|
||||
return loanTransactionHelper.getLoanId(loanApplicationJSON);
|
||||
}
|
||||
|
||||
private void approveAndDisburseLoan(final Integer loanId, final String operationDate, final String principalAmount) {
|
||||
loanTransactionHelper.approveLoan(operationDate, principalAmount, loanId, null);
|
||||
loanTransactionHelper.disburseLoanWithNetDisbursalAmount(operationDate, loanId, principalAmount);
|
||||
}
|
||||
|
||||
}
|
||||
+13
@@ -147,6 +147,13 @@ public class LoanTransactionHelper {
|
||||
return GSON.fromJson(response, PutLoansLoanIdResponse.class);
|
||||
}
|
||||
|
||||
public PutLoansLoanIdResponse modifyLoanCommand(final Integer loanId, final String command, final String payload,
|
||||
ResponseSpecification responseSpec) {
|
||||
final String url = "/fineract-provider/api/v1/loans/" + loanId + "?" + Utils.TENANT_IDENTIFIER + "&command=" + command;
|
||||
final String response = Utils.performServerPut(this.requestSpec, responseSpec, url, payload, null);
|
||||
return GSON.fromJson(response, PutLoansLoanIdResponse.class);
|
||||
}
|
||||
|
||||
public ArrayList getLoanRepaymentSchedule(final RequestSpecification requestSpec, final ResponseSpecification responseSpec,
|
||||
final Integer loanID) {
|
||||
final String URL = "/fineract-provider/api/v1/loans/" + loanID + "?associations=repaymentSchedule&" + Utils.TENANT_IDENTIFIER;
|
||||
@@ -1002,6 +1009,12 @@ public class LoanTransactionHelper {
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public String getLoanFraudPayloadAsJSON(final String attrName, final String attrValue) {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
map.put(attrName, attrValue);
|
||||
return new Gson().toJson(map);
|
||||
}
|
||||
|
||||
public HashMap createTrancheDetail(final String id, final String date, final String amount) {
|
||||
HashMap<String, Object> detail = new HashMap<>();
|
||||
if (id != null) {
|
||||
|
||||
Reference in New Issue
Block a user