Skip to content

Commit 1934cad

Browse files
committed
FINERACT-2454: Migrate LoanWithdrawnByApplicantIntegrationTest from RestAssured to fineract-client-feign
- Migrates LoanWithdrawnByApplicantIntegrationTest to use fineract-client-feign - Replaces RestAssured based API calls with Feign client - Fixes getObligeeData handling for JSON array response - Applies related test and schema updates # Conflicts: # integration-tests/src/test/java/org/apache/fineract/integrationtests/ClientExternalIdTest.java # integration-tests/src/test/java/org/apache/fineract/integrationtests/common/ClientHelper.java
1 parent 7f3d40d commit 1934cad

3 files changed

Lines changed: 37 additions & 74 deletions

File tree

integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanWithdrawnByApplicantIntegrationTest.java

Lines changed: 32 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -18,85 +18,44 @@
1818
*/
1919
package org.apache.fineract.integrationtests;
2020

21-
import io.restassured.builder.RequestSpecBuilder;
22-
import io.restassured.builder.ResponseSpecBuilder;
23-
import io.restassured.http.ContentType;
24-
import io.restassured.specification.RequestSpecification;
25-
import io.restassured.specification.ResponseSpecification;
26-
import java.math.BigDecimal;
27-
import java.util.ArrayList;
28-
import java.util.HashMap;
29-
import java.util.List;
21+
import org.apache.fineract.client.models.PostClientsRequest;
22+
import org.apache.fineract.client.models.PostLoansLoanIdRequest;
23+
import org.apache.fineract.client.models.PostLoansResponse;
3024
import org.apache.fineract.integrationtests.common.ClientHelper;
31-
import org.apache.fineract.integrationtests.common.CollateralManagementHelper;
3225
import org.apache.fineract.integrationtests.common.Utils;
33-
import org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder;
34-
import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
35-
import org.apache.fineract.integrationtests.common.loans.LoanStatusChecker;
36-
import org.apache.fineract.integrationtests.common.loans.LoanTestLifecycleExtension;
37-
import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
38-
import org.junit.jupiter.api.Assertions;
39-
import org.junit.jupiter.api.BeforeEach;
26+
import org.apache.fineract.portfolio.loanaccount.domain.LoanStatus;
4027
import org.junit.jupiter.api.Test;
41-
import org.junit.jupiter.api.extension.ExtendWith;
4228

43-
@SuppressWarnings("rawtypes")
44-
@ExtendWith(LoanTestLifecycleExtension.class)
45-
public class LoanWithdrawnByApplicantIntegrationTest {
46-
47-
private ResponseSpecification responseSpec;
48-
private RequestSpecification requestSpec;
49-
private LoanTransactionHelper loanTransactionHelper;
50-
51-
@BeforeEach
52-
public void setup() {
53-
Utils.initializeRESTAssured();
54-
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build();
55-
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey());
56-
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
57-
58-
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec);
59-
}
29+
public class LoanWithdrawnByApplicantIntegrationTest extends BaseLoanIntegrationTest {
6030

6131
@Test
6232
public void loanWithdrawnByApplicant() {
63-
final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec, "01 January 2012");
64-
final Integer loanProductID = this.loanTransactionHelper.getLoanProductId(new LoanProductTestBuilder().build(null));
65-
final Integer loanID = applyForLoanApplication(clientID, loanProductID);
66-
67-
HashMap loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
68-
LoanStatusChecker.verifyLoanIsPending(loanStatusHashMap);
69-
70-
this.loanTransactionHelper.withdrawLoanApplicationByClient("03 April 2012", loanID);
71-
loanStatusHashMap = LoanStatusChecker.getStatusOfLoan(this.requestSpec, this.responseSpec, loanID);
72-
LoanStatusChecker.verifyLoanAccountIsNotActive(loanStatusHashMap);
73-
74-
}
75-
76-
private void addCollaterals(List<HashMap> collaterals, Integer collateralId, BigDecimal quantity) {
77-
collaterals.add(collaterals(collateralId, quantity));
78-
}
79-
80-
private HashMap<String, String> collaterals(Integer collateralId, BigDecimal quantity) {
81-
HashMap<String, String> collateral = new HashMap<String, String>(2);
82-
collateral.put("clientCollateralId", collateralId.toString());
83-
collateral.put("quantity", quantity.toString());
84-
return collateral;
85-
}
86-
87-
private Integer applyForLoanApplication(final Integer clientID, final Integer loanProductID) {
88-
List<HashMap> collaterals = new ArrayList<>();
89-
final Integer collateralId = CollateralManagementHelper.createCollateralProduct(this.requestSpec, this.responseSpec);
90-
Assertions.assertNotNull(collateralId);
91-
final Integer clientCollateralId = CollateralManagementHelper.createClientCollateral(this.requestSpec, this.responseSpec,
92-
clientID.toString(), collateralId);
93-
Assertions.assertNotNull(clientCollateralId);
94-
addCollaterals(collaterals, clientCollateralId, BigDecimal.valueOf(1));
95-
final String loanApplication = new LoanApplicationTestBuilder().withPrincipal("5000").withLoanTermFrequency("5")
96-
.withLoanTermFrequencyAsMonths().withNumberOfRepayments("5").withRepaymentEveryAfter("1")
97-
.withRepaymentFrequencyTypeAsMonths().withInterestRatePerPeriod("2").withExpectedDisbursementDate("04 April 2012")
98-
.withCollaterals(collaterals).withSubmittedOnDate("02 April 2012")
99-
.build(clientID.toString(), loanProductID.toString(), null);
100-
return this.loanTransactionHelper.getLoanId(loanApplication);
33+
final Long clientId = ClientHelper.createClient(new PostClientsRequest() //
34+
.officeId(1L) //
35+
.legalFormId(1L) //
36+
.firstname(Utils.randomFirstNameGenerator()) //
37+
.lastname(Utils.randomLastNameGenerator()) //
38+
.active(true) //
39+
.activationDate("01 January 2012") //
40+
.dateFormat(Utils.DATE_FORMAT) //
41+
.locale("en")) //
42+
.getResourceId();
43+
44+
final Long loanProductId = loanTransactionHelper.createLoanProduct(createOnePeriod30DaysLongNoInterestPeriodicAccrualProduct()) //
45+
.getResourceId();
46+
47+
final PostLoansResponse loanResponse = loanTransactionHelper
48+
.applyLoan(applyLoanRequest(clientId, loanProductId, "04 April 2012", 5000.0, 5));
49+
final Long loanId = loanResponse.getLoanId();
50+
51+
verifyLoanStatus(loanId, LoanStatus.SUBMITTED_AND_PENDING_APPROVAL);
52+
53+
loanTransactionHelper.withdrawnByApplicantLoan(loanId, //
54+
new PostLoansLoanIdRequest() //
55+
.withdrawnOnDate("05 April 2012") //
56+
.dateFormat(Utils.DATE_FORMAT) //
57+
.locale("en"));
58+
59+
verifyLoanStatus(loanId, LoanStatus.WITHDRAWN_BY_CLIENT);
10160
}
10261
}

integration-tests/src/test/java/org/apache/fineract/integrationtests/common/ClientHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
import static org.junit.jupiter.api.Assertions.assertEquals;
2222

23-
import com.google.common.reflect.TypeToken;
2423
import com.google.gson.Gson;
24+
import com.google.gson.reflect.TypeToken;
2525
import io.restassured.builder.RequestSpecBuilder;
2626
import io.restassured.builder.ResponseSpecBuilder;
2727
import io.restassured.http.ContentType;

integration-tests/src/test/java/org/apache/fineract/integrationtests/common/loans/LoanTransactionHelper.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2972,6 +2972,10 @@ public PostLoansLoanIdResponse rejectLoan(Long loanId, PostLoansLoanIdRequest re
29722972
return Calls.ok(FineractClientHelper.getFineractClient().loans.stateTransitions(loanId, request, "reject"));
29732973
}
29742974

2975+
public PostLoansLoanIdResponse withdrawnByApplicantLoan(Long loanId, PostLoansLoanIdRequest request) {
2976+
return Calls.ok(FineractClientHelper.getFineractClient().loans.stateTransitions(loanId, request, "withdrawnByApplicant"));
2977+
}
2978+
29752979
public PostLoansLoanIdResponse withdrawnByApplicantLoan(String loanExternalId, PostLoansLoanIdRequest request) {
29762980
return Calls.ok(FineractClientHelper.getFineractClient().loans.stateTransitionsByExternalId(loanExternalId, request,
29772981
"withdrawnByApplicant"));

0 commit comments

Comments
 (0)