Added reschedule loans api resource to Fineract Client and batch; minor swagger polishing
This commit is contained in:
committed by
Arnold Gálovics
parent
b21cdf59b1
commit
87204d5a8a
+83
@@ -27,8 +27,11 @@ 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.time.ZoneId;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import org.apache.fineract.batch.command.internal.CreateTransactionLoanCommandStrategy;
|
||||
import org.apache.fineract.batch.domain.BatchRequest;
|
||||
@@ -41,12 +44,15 @@ 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.apache.fineract.integrationtests.common.system.CodeHelper;
|
||||
import org.apache.fineract.integrationtests.common.system.DatatableHelper;
|
||||
import org.apache.fineract.portfolio.loanaccount.domain.LoanStatus;
|
||||
import org.apache.http.HttpStatus;
|
||||
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 {@link org.apache.fineract.batch.command.CommandStrategyProvider}. This tests the response provided by
|
||||
@@ -59,6 +65,8 @@ import org.junit.jupiter.api.Test;
|
||||
*/
|
||||
public class BatchApiTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(BatchApiTest.class);
|
||||
|
||||
/**
|
||||
* The response specification
|
||||
*/
|
||||
@@ -718,6 +726,81 @@ public class BatchApiTest {
|
||||
Assertions.assertEquals(HttpStatus.SC_OK, responses.get(3).getStatusCode(), "Verify Status Code 200 for Get Transaction By Id");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for the successful new loan reschedule request and approval for the same. A '200' status code is expected on
|
||||
* successful responses.
|
||||
*
|
||||
* @see org.apache.fineract.batch.command.internal.CreateLoanRescheduleRequestCommandStrategy
|
||||
* @see org.apache.fineract.batch.command.internal.ApproveLoanRescheduleCommandStrategy
|
||||
*/
|
||||
@Test
|
||||
public void shouldReturnOkStatusOnSuccessfulDisbursementAndRescheduleLoan() {
|
||||
final String loanProductJSON = new LoanProductTestBuilder() //
|
||||
.withPrincipal("10000000.00") //
|
||||
.withNumberOfRepayments("24") //
|
||||
.withRepaymentAfterEvery("1") //
|
||||
.withRepaymentTypeAsMonth() //
|
||||
.withinterestRatePerPeriod("2") //
|
||||
.withInterestRateFrequencyTypeAsMonths() //
|
||||
.withAmortizationTypeAsEqualPrincipalPayment() //
|
||||
.withInterestTypeAsDecliningBalance() //
|
||||
.currencyDetails("0", "100").build(null);
|
||||
|
||||
final Long createActiveClientRequestId = 8462L;
|
||||
final Long applyLoanRequestId = createActiveClientRequestId + 1;
|
||||
final Long approveLoanRequestId = applyLoanRequestId + 1;
|
||||
final Long disburseLoanRequestId = approveLoanRequestId + 1;
|
||||
final Long rescheduleLoanRequestId = disburseLoanRequestId + 1;
|
||||
final Long approveRescheduleLoanRequestId = rescheduleLoanRequestId + 1;
|
||||
|
||||
// Create product
|
||||
LOG.info("LoanProduct {}", loanProductJSON);
|
||||
final Integer productId = new LoanTransactionHelper(this.requestSpec, this.responseSpec).getLoanProductId(loanProductJSON);
|
||||
|
||||
// Create client
|
||||
final Integer clientId = ClientHelper.createClient(this.requestSpec, this.responseSpec);
|
||||
ClientHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, clientId);
|
||||
|
||||
/* Retrieve/Create Code Values for the Code "LoanRescheduleReason = 23" */
|
||||
final HashMap<String, Object> codeValue = CodeHelper.retrieveOrCreateCodeValue(23, this.requestSpec, this.responseSpec);
|
||||
|
||||
final Integer codeValueId = (Integer) codeValue.get("id");
|
||||
|
||||
// Create an ApplyLoan request
|
||||
final BatchRequest applyLoanRequestWithClientId = BatchHelper.applyLoanRequestWithClientId(applyLoanRequestId, clientId, productId);
|
||||
|
||||
// Create an approveLoan request
|
||||
final BatchRequest approveLoanRequest = BatchHelper.approveLoanRequest(approveLoanRequestId, applyLoanRequestId);
|
||||
|
||||
// Create a disbursement request
|
||||
final LocalDate disburseLoanDate = LocalDate.now(ZoneId.systemDefault()).minusDays(1);
|
||||
final BatchRequest disburseLoanRequest = BatchHelper.disburseLoanRequest(disburseLoanRequestId, approveLoanRequestId,
|
||||
disburseLoanDate);
|
||||
|
||||
// Create a reschedule loan request
|
||||
final BatchRequest rescheduleLoanRequest = BatchHelper.createRescheduleLoanRequest(rescheduleLoanRequestId, disburseLoanRequestId,
|
||||
disburseLoanDate.plusMonths(1), codeValueId);
|
||||
|
||||
// Approve reschedule loan request
|
||||
final BatchRequest approveRescheduleLoanRequest = BatchHelper.approveRescheduleLoanRequest(approveRescheduleLoanRequestId,
|
||||
rescheduleLoanRequestId);
|
||||
|
||||
final List<BatchRequest> batchRequests = Arrays.asList(applyLoanRequestWithClientId, approveLoanRequest, disburseLoanRequest,
|
||||
rescheduleLoanRequest, approveRescheduleLoanRequest);
|
||||
|
||||
LOG.info("shouldReturnOkStatusOnSuccessfulDisbursementAndRescheduleLoan Request - {}", BatchHelper.toJsonString(batchRequests));
|
||||
final List<BatchResponse> responses = BatchHelper.postBatchRequestsWithoutEnclosingTransaction(this.requestSpec, this.responseSpec,
|
||||
BatchHelper.toJsonString(batchRequests));
|
||||
|
||||
Assertions.assertEquals(HttpStatus.SC_OK, responses.get(0).getStatusCode(), "Verify Status Code 200 for Apply Loan");
|
||||
Assertions.assertEquals(HttpStatus.SC_OK, responses.get(1).getStatusCode(), "Verify Status Code 200 for Approve Loan");
|
||||
Assertions.assertEquals(HttpStatus.SC_OK, responses.get(2).getStatusCode(), "Verify Status Code 200 for Disburse Loan");
|
||||
Assertions.assertEquals(HttpStatus.SC_OK, responses.get(3).getStatusCode(),
|
||||
"Verify Status Code 200 for Create Reschedule Loan request");
|
||||
Assertions.assertEquals(HttpStatus.SC_OK, responses.get(4).getStatusCode(),
|
||||
"Verify Status Code 200 for Approve Reschedule Loan request");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for the successful create client, creat, approve and get loan. A '200' status code is expected on successful
|
||||
* responses.
|
||||
|
||||
+64
-2
@@ -98,6 +98,7 @@ public final class BatchHelper {
|
||||
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);
|
||||
LOG.info("BatchHelper Response {}", response);
|
||||
return BatchHelper.fromJsonString(response);
|
||||
}
|
||||
|
||||
@@ -501,8 +502,6 @@ public final class BatchHelper {
|
||||
* the reference ID
|
||||
* @param amount
|
||||
* the amount
|
||||
* @param date
|
||||
* the transaction date
|
||||
* @return BatchRequest the batch request
|
||||
*/
|
||||
public static BatchRequest repayLoanRequest(final Long requestId, final Long reference, final String amount) {
|
||||
@@ -578,6 +577,69 @@ public final class BatchHelper {
|
||||
return br;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a
|
||||
* {@link org.apache.fineract.batch.command.internal.CreateLoanRescheduleRequestCommandStrategy} request with given
|
||||
* request ID.
|
||||
*
|
||||
*
|
||||
* @param requestId
|
||||
* the request ID
|
||||
* @param reference
|
||||
* teh reference
|
||||
* @param rescheduleFromDate
|
||||
* the reschedule from date
|
||||
* @param rescheduleReasonId
|
||||
* the reschedule reason code value id
|
||||
*
|
||||
* @return BatchRequest the created {@link BatchRequest}
|
||||
*/
|
||||
public static BatchRequest createRescheduleLoanRequest(final Long requestId, final Long reference, final LocalDate rescheduleFromDate,
|
||||
final Integer rescheduleReasonId) {
|
||||
final BatchRequest br = new BatchRequest();
|
||||
|
||||
br.setRequestId(requestId);
|
||||
br.setReference(reference);
|
||||
br.setRelativeUrl("rescheduleloans");
|
||||
br.setMethod("POST");
|
||||
final LocalDate today = LocalDate.now(ZoneId.systemDefault());
|
||||
final LocalDate adjustedDueDate = LocalDate.now(ZoneId.systemDefault()).plusDays(40);
|
||||
final String submittedOnDate = today.format(DateTimeFormatter.ofPattern("dd MMMM yyyy"));
|
||||
final String rescheduleFromDateString = rescheduleFromDate.format(DateTimeFormatter.ofPattern("dd MMMM yyyy"));
|
||||
final String adjustedDueDateString = adjustedDueDate.format(DateTimeFormatter.ofPattern("dd MMMM yyyy"));
|
||||
br.setBody(String.format("{\"locale\": \"en\", \"dateFormat\": \"dd MMMM yyyy\", "
|
||||
+ "\"submittedOnDate\": \"%s\", \"rescheduleFromDate\": \"%s\", \"rescheduleReasonId\": %d, \"adjustedDueDate\": \"%s\", \"loanId\": \"$.loanId\"}",
|
||||
submittedOnDate, rescheduleFromDateString, rescheduleReasonId, adjustedDueDateString));
|
||||
|
||||
return br;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a {@link org.apache.fineract.batch.command.internal.ApproveLoanRescheduleCommandStrategy}
|
||||
* request with given request ID.
|
||||
*
|
||||
*
|
||||
* @param requestId
|
||||
* the request ID
|
||||
* @param reference
|
||||
* teh reference
|
||||
* @return BatchRequest the created {@link BatchRequest}
|
||||
*/
|
||||
public static BatchRequest approveRescheduleLoanRequest(final Long requestId, final Long reference) {
|
||||
final BatchRequest br = new BatchRequest();
|
||||
|
||||
br.setRequestId(requestId);
|
||||
br.setReference(reference);
|
||||
br.setRelativeUrl("rescheduleloans/$.resourceId?command=approve");
|
||||
br.setMethod("POST");
|
||||
final LocalDate approvedOnDate = LocalDate.now(ZoneId.systemDefault());
|
||||
final String approvedOnDateString = approvedOnDate.format(DateTimeFormatter.ofPattern("dd MMMM yyyy"));
|
||||
br.setBody(String.format("{\"locale\": \"en\", \"dateFormat\": \"dd MMMM yyyy\", " + "\"approvedOnDate\": \"%s\"}",
|
||||
approvedOnDateString));
|
||||
|
||||
return br;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that the client with given externalId is not created on the server.
|
||||
*
|
||||
|
||||
+3
-2
@@ -207,8 +207,9 @@ public class ClientHelper {
|
||||
map.put("locale", "en");
|
||||
map.put("active", "true");
|
||||
map.put("activationDate", dateOfJoining);
|
||||
log.info("map : {}", map);
|
||||
return GSON.toJson(map);
|
||||
final String testClientAsJson = GSON.toJson(map);
|
||||
log.info("TestClient Request : {}", testClientAsJson);
|
||||
return testClientAsJson;
|
||||
}
|
||||
|
||||
public static String getTestClientAsJSONPending(final String submittedOnDate, final String officeId) {
|
||||
|
||||
Reference in New Issue
Block a user