|
18 | 18 | */ |
19 | 19 | package org.apache.fineract.integrationtests; |
20 | 20 |
|
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; |
30 | 24 | import org.apache.fineract.integrationtests.common.ClientHelper; |
31 | | -import org.apache.fineract.integrationtests.common.CollateralManagementHelper; |
32 | 25 | 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; |
40 | 27 | import org.junit.jupiter.api.Test; |
41 | | -import org.junit.jupiter.api.extension.ExtendWith; |
42 | 28 |
|
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 { |
60 | 30 |
|
61 | 31 | @Test |
62 | 32 | 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); |
101 | 60 | } |
102 | 61 | } |
0 commit comments