|
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.util.ArrayList; |
27 | | -import java.util.HashMap; |
28 | | -import java.util.List; |
29 | 21 | import org.apache.fineract.client.models.LoanAccountLockResponseDTO; |
| 22 | +import org.apache.fineract.client.models.LockRequest; |
| 23 | +import org.apache.fineract.client.models.PostLoansLoanIdRequest; |
| 24 | +import org.apache.fineract.client.models.PostLoansResponse; |
| 25 | +import org.apache.fineract.client.util.Calls; |
30 | 26 | import org.apache.fineract.integrationtests.common.ClientHelper; |
| 27 | +import org.apache.fineract.integrationtests.common.FineractClientHelper; |
31 | 28 | import org.apache.fineract.integrationtests.common.Utils; |
32 | | -import org.apache.fineract.integrationtests.common.accounting.Account; |
33 | | -import org.apache.fineract.integrationtests.common.loans.LoanAccountLockHelper; |
34 | | -import org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder; |
35 | | -import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder; |
36 | | -import org.apache.fineract.integrationtests.common.loans.LoanStatusChecker; |
37 | | -import org.apache.fineract.integrationtests.common.loans.LoanTestLifecycleExtension; |
38 | | -import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper; |
| 29 | +import org.apache.fineract.portfolio.loanaccount.domain.LoanStatus; |
39 | 30 | import org.junit.jupiter.api.Assertions; |
40 | | -import org.junit.jupiter.api.BeforeEach; |
41 | 31 | import org.junit.jupiter.api.Test; |
42 | | -import org.junit.jupiter.api.extension.ExtendWith; |
43 | | -import org.slf4j.Logger; |
44 | | -import org.slf4j.LoggerFactory; |
45 | 32 |
|
46 | | -@SuppressWarnings({ "rawtypes", "unchecked" }) |
47 | | -@ExtendWith(LoanTestLifecycleExtension.class) |
48 | | -public class ClientLoanAccountLockIntegrationTest { |
49 | | - |
50 | | - private static final Logger LOG = LoggerFactory.getLogger(ClientLoanAccountLockIntegrationTest.class); |
51 | | - |
52 | | - public static final String MINIMUM_OPENING_BALANCE = "1000.0"; |
53 | | - public static final String ACCOUNT_TYPE_INDIVIDUAL = "INDIVIDUAL"; |
54 | | - private static final String NONE = "1"; |
55 | | - |
56 | | - private ResponseSpecification responseSpec; |
57 | | - private RequestSpecification requestSpec; |
58 | | - private ClientHelper clientHelper; |
59 | | - private LoanTransactionHelper loanTransactionHelper; |
60 | | - private LoanAccountLockHelper loanAccountLockHelper; |
61 | | - |
62 | | - @BeforeEach |
63 | | - public void setup() { |
64 | | - Utils.initializeRESTAssured(); |
65 | | - this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build(); |
66 | | - this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); |
67 | | - this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); |
68 | | - this.clientHelper = new ClientHelper(this.requestSpec, this.responseSpec); |
69 | | - this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec); |
70 | | - loanAccountLockHelper = new LoanAccountLockHelper(requestSpec, new ResponseSpecBuilder().expectStatusCode(202).build()); |
71 | | - } |
| 33 | +public class ClientLoanAccountLockIntegrationTest extends BaseLoanIntegrationTest { |
72 | 34 |
|
73 | 35 | @Test |
74 | 36 | public void checkRetrieveLockedLoanAccountsList() { |
75 | | - final Integer clientID = ClientHelper.createClient(this.requestSpec, this.responseSpec); |
76 | | - ClientHelper.verifyClientCreatedOnServer(this.requestSpec, this.responseSpec, clientID); |
| 37 | + final Long clientId = ClientHelper.addClientAsPerson(null, ClientHelper.LEGALFORM_ID_PERSON, null).getResourceId(); |
77 | 38 |
|
78 | | - final Integer loanProductID = createLoanProduct(false, NONE); |
| 39 | + final Long loanProductId = loanTransactionHelper.createLoanProduct(createOnePeriod30DaysLongNoInterestPeriodicAccrualProduct()) // |
| 40 | + .getResourceId(); |
79 | 41 |
|
80 | | - List<HashMap> collaterals = new ArrayList<>(); |
81 | | - final Integer loanID = applyForLoanApplication(clientID, loanProductID, null, null, "12,000.00", collaterals); |
82 | | - HashMap loanStatusHashMap = this.loanTransactionHelper.approveLoan("20 September 2011", loanID); |
83 | | - LoanStatusChecker.verifyLoanIsApproved(loanStatusHashMap); |
84 | | - loanStatusHashMap = this.loanTransactionHelper.disburseLoanWithNetDisbursalAmount("20 September 2011", loanID, "12,000.00"); |
85 | | - LoanStatusChecker.verifyLoanIsActive(loanStatusHashMap); |
| 42 | + final PostLoansResponse loanResponse = loanTransactionHelper |
| 43 | + .applyLoan(applyLoanRequest(clientId, loanProductId, "20 September 2011", 12000.0, 4)); |
| 44 | + final Long loanId = loanResponse.getLoanId(); |
86 | 45 |
|
87 | | - loanAccountLockHelper.placeSoftLockOnLoanAccount(loanID, "LOAN_INLINE_COB_PROCESSING", "Sample error"); |
| 46 | + loanTransactionHelper.approveLoan(loanId, new PostLoansLoanIdRequest() // |
| 47 | + .approvedOnDate("20 September 2011") // |
| 48 | + .dateFormat(Utils.DATE_FORMAT) // |
| 49 | + .locale("en")); |
| 50 | + verifyLoanStatus(loanId, LoanStatus.APPROVED); |
88 | 51 |
|
89 | | - LoanAccountLockResponseDTO getLoanAccountLockResponse = clientHelper.retrieveLockedAccounts(0, 1000); |
90 | | - Assertions.assertTrue(getLoanAccountLockResponse.getContent().size() > 0); |
91 | | - Assertions.assertTrue(getLoanAccountLockResponse.getContent().stream() |
92 | | - .anyMatch(loanAccountLock -> loanAccountLock.getLoanId().equals(Long.valueOf(loanID)))); |
93 | | - } |
| 52 | + loanTransactionHelper.disburseLoan(loanId, "20 September 2011", 12000.0); |
| 53 | + verifyLoanStatus(loanId, LoanStatus.ACTIVE); |
94 | 54 |
|
95 | | - private Integer createLoanProduct(final boolean multiDisburseLoan, final String accountingRule, final Account... accounts) { |
96 | | - LOG.info("------------------------------CREATING NEW LOAN PRODUCT ---------------------------------------"); |
97 | | - LoanProductTestBuilder builder = new LoanProductTestBuilder() // |
98 | | - .withPrincipal("12,000.00") // |
99 | | - .withNumberOfRepayments("4") // |
100 | | - .withRepaymentAfterEvery("1") // |
101 | | - .withRepaymentTypeAsMonth() // |
102 | | - .withinterestRatePerPeriod("1") // |
103 | | - .withInterestRateFrequencyTypeAsMonths() // |
104 | | - .withAmortizationTypeAsEqualInstallments() // |
105 | | - .withInterestTypeAsDecliningBalance() // |
106 | | - .withTranches(multiDisburseLoan) // |
107 | | - .withAccounting(accountingRule, accounts); |
108 | | - if (multiDisburseLoan) { |
109 | | - builder = builder.withInterestCalculationPeriodTypeAsRepaymentPeriod(true); |
110 | | - } |
111 | | - final String loanProductJSON = builder.build(null); |
112 | | - return this.loanTransactionHelper.getLoanProductId(loanProductJSON); |
113 | | - } |
| 55 | + Calls.ok(FineractClientHelper.getFineractClient().legacy // |
| 56 | + .placeLockOnLoanAccount(loanId, "LOAN_INLINE_COB_PROCESSING", new LockRequest().error("Sample error"))); |
114 | 57 |
|
115 | | - private Integer applyForLoanApplication(final Integer clientID, final Integer loanProductID, List<HashMap> charges, |
116 | | - final String savingsId, String principal, List<HashMap> collaterals) { |
117 | | - LOG.info("--------------------------------APPLYING FOR LOAN APPLICATION--------------------------------"); |
118 | | - final String loanApplicationJSON = new LoanApplicationTestBuilder() // |
119 | | - .withPrincipal(principal) // |
120 | | - .withLoanTermFrequency("4") // |
121 | | - .withLoanTermFrequencyAsMonths() // |
122 | | - .withNumberOfRepayments("4") // |
123 | | - .withRepaymentEveryAfter("1") // |
124 | | - .withRepaymentFrequencyTypeAsMonths() // |
125 | | - .withInterestRatePerPeriod("2") // |
126 | | - .withAmortizationTypeAsEqualInstallments() // |
127 | | - .withInterestTypeAsDecliningBalance() // |
128 | | - .withInterestCalculationPeriodTypeSameAsRepaymentPeriod() // |
129 | | - .withExpectedDisbursementDate("20 September 2011") // |
130 | | - .withSubmittedOnDate("20 September 2011") // |
131 | | - .withCollaterals(collaterals).withCharges(charges).build(clientID.toString(), loanProductID.toString(), savingsId); |
132 | | - return this.loanTransactionHelper.getLoanId(loanApplicationJSON); |
| 58 | + LoanAccountLockResponseDTO lockResponse = Calls |
| 59 | + .ok(FineractClientHelper.getFineractClient().loanAccountLockApi.retrieveLockedAccounts(0, 1000)); |
| 60 | + Assertions.assertTrue(lockResponse.getContent().size() > 0); |
| 61 | + Assertions.assertTrue(lockResponse.getContent().stream().anyMatch(lock -> lock.getLoanId().equals(loanId))); |
133 | 62 | } |
134 | 63 | } |
0 commit comments