You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by vi...@apache.org on 2019/02/26 08:55:16 UTC

[fineract] branch develop updated: - Fix issue FINERACT-684 (approve loan on batch mode return null pointer exception) - Add integration test to cover the fix

This is an automated email from the ASF dual-hosted git repository.

vishwasbabu pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract.git


The following commit(s) were added to refs/heads/develop by this push:
     new 3965724  - Fix issue FINERACT-684 (approve loan on batch mode return null pointer exception) - Add integration test to cover the fix
     new 0534f37  Merge pull request #526 from hungnguyen2712/create-and-approve-loan-on-batch-mode
3965724 is described below

commit 39657247c6787fd555f4d6d17a40fe881a60ac9a
Author: Hung Nguyen <hu...@trustingsocial.com>
AuthorDate: Thu Feb 21 11:41:43 2019 +0700

    - Fix issue FINERACT-684 (approve loan on batch mode return null pointer exception)
    - Add integration test to cover the fix
---
 .../fineract/integrationtests/BatchApiTest.java    | 48 ++++++++++++++++++++++
 .../integrationtests/common/BatchHelper.java       | 24 +++++++++++
 .../portfolio/loanaccount/domain/Loan.java         | 22 ++++++----
 .../loanaccount/service/LoanAssembler.java         |  3 +-
 4 files changed, 88 insertions(+), 9 deletions(-)

diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/BatchApiTest.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/BatchApiTest.java
index 25a4644..aae79a0 100644
--- a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/BatchApiTest.java
+++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/BatchApiTest.java
@@ -19,6 +19,7 @@
 package org.apache.fineract.integrationtests;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
 import org.apache.fineract.batch.domain.BatchRequest;
@@ -422,4 +423,51 @@ public class BatchApiTest {
         Assert.assertEquals("Verify Status Code 200 for Approve Loan", 200L, (long) response.get(3).getStatusCode());
         Assert.assertEquals("Verify Status Code 200 for Disburse Loan", 200L, (long) response.get(4).getStatusCode());
     }
+
+    /**
+     * Test for the successful create client, apply loan,approval and disbursal of a loan using
+     * Batch API with enclosingTransaction. A '200' status code is expected on successful activation.
+     *
+     * @see org.apache.fineract.batch.command.internal.ApproveLoanCommandStrategy
+     * @see org.apache.fineract.batch.command.internal.DisburseLoanCommandStrategy
+     */
+    @Test
+    public void shouldReturnOkStatusOnSuccessfulLoanApprovalAndDisburseWithTransaction(){
+        final String loanProductJSON = new LoanProductTestBuilder() //
+                .withPrincipal("10000000.00") //
+                .withNumberOfRepayments("24") //
+                .withRepaymentAfterEvery("1") //
+                .withRepaymentTypeAsMonth() //
+                .withinterestRatePerPeriod("2") //
+                .withInterestRateFrequencyTypeAsMonths() //
+                .withAmortizationTypeAsEqualPrincipalPayment() //
+                .withInterestTypeAsDecliningBalance() //
+                .currencyDetails("0", "100").build(null);
+
+        final Integer productId = new LoanTransactionHelper(this.requestSpec, this.responseSpec).getLoanProductId(loanProductJSON);
+
+        // Create a createClient Request
+        final BatchRequest br1 = BatchHelper.createActiveClientRequest(4740L, "");
+
+        // Create a ApplyLoan Request
+        final BatchRequest br2 = BatchHelper.applyLoanRequest(4742L, 4740L, productId);
+
+        // Create a approveLoan Request
+        final BatchRequest br3 = BatchHelper.approveLoanRequest(4743L, 4742L);
+
+        // Create a disburseLoan Request
+        final BatchRequest br4 = BatchHelper.disburseLoanRequest(4744L, 4743L);
+
+        final List<BatchRequest> batchRequests = Arrays.asList(br1,br2,br3,br4);
+
+        final String jsonifiedRequest = BatchHelper.toJsonString(batchRequests);
+
+        final List<BatchResponse> response = BatchHelper.postBatchRequestsWithEnclosingTransaction(this.requestSpec, this.responseSpec,
+                jsonifiedRequest);
+
+        Assert.assertEquals("Verify Status Code 200 for create client", 200L, (long) response.get(0).getStatusCode());
+        Assert.assertEquals("Verify Status Code 200 for apply Loan", 200L, (long) response.get(1).getStatusCode());
+        Assert.assertEquals("Verify Status Code 200 for approve Loan", 200L, (long) response.get(2).getStatusCode());
+        Assert.assertEquals("Verify Status Code 200 for disburse Loan", 200L, (long) response.get(3).getStatusCode());
+    }
 }
\ No newline at end of file
diff --git a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/BatchHelper.java b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/BatchHelper.java
index c99ebea..ec6ff59 100644
--- a/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/BatchHelper.java
+++ b/fineract-provider/src/integrationTest/java/org/apache/fineract/integrationtests/common/BatchHelper.java
@@ -157,6 +157,30 @@ public class BatchHelper {
 
     /**
      * Creates and returns a
+     * {@link org.apache.fineract.batch.command.internal.CreateClientCommandStrategy}
+     * Request as one of the request in Batch.
+     *
+     * @param reqId
+     * @param externalId
+     * @return BatchRequest
+     */
+    public static BatchRequest createActiveClientRequest(final Long requestId, final String externalId) {
+
+        final BatchRequest br = new BatchRequest();
+        br.setRequestId(requestId);
+        br.setRelativeUrl("clients");
+        br.setMethod("POST");
+
+        final String body = "{ \"officeId\": 1, \"firstname\": \"Petra\", \"lastname\": \"Yton\"," + "\"externalId\": " + externalId
+                + ",  \"dateFormat\": \"dd MMMM yyyy\", \"locale\": \"en\"," + "\"active\": true, \"activationDate\": \"04 March 2010\", \"submittedOnDate\": \"04 March 2010\"}";
+
+        br.setBody(body);
+
+        return br;
+    }
+
+    /**
+     * Creates and returns a
      * {@link org.apache.fineract.batch.command.internal.UpdateClientCommandStrategy}
      * Request with given requestId and reference.
      * 
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java
index 193810d..4f4b264 100755
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java
@@ -6497,14 +6497,20 @@ public class Loan extends AbstractPersistableCustom<Long> {
         return this.charges;
     }
     public void initializeLazyCollections() {
-        this.charges.size() ;
-        this.trancheCharges.size() ;
-        this.repaymentScheduleInstallments.size() ;
-        this.loanTransactions.size() ;
-        this.disbursementDetails.size() ;
-        this.loanTermVariations.size() ;
-        this.collateral.size() ;
-        this.loanOfficerHistory.size() ;
+        checkAndFetchLazyCollection(this.charges);
+        checkAndFetchLazyCollection(this.trancheCharges);
+        checkAndFetchLazyCollection(this.repaymentScheduleInstallments);
+        checkAndFetchLazyCollection(this.loanTransactions);
+        checkAndFetchLazyCollection(this.disbursementDetails);
+        checkAndFetchLazyCollection(this.loanTermVariations);
+        checkAndFetchLazyCollection(this.collateral);
+        checkAndFetchLazyCollection(this.loanOfficerHistory);
+    }
+
+    private void checkAndFetchLazyCollection(Collection lazyCollection){
+        if (lazyCollection != null) {
+            lazyCollection.size();
+        }
     }
     
     public void initializeLoanOfficerHistory() {
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanAssembler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanAssembler.java
index 2d124bf..95fc3c0 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanAssembler.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanAssembler.java
@@ -19,6 +19,7 @@
 package org.apache.fineract.portfolio.loanaccount.service;
 
 import java.math.BigDecimal;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Locale;
@@ -181,7 +182,7 @@ public class LoanAssembler {
         if (loanPurposeId != null) {
             loanPurpose = this.codeValueRepository.findOneWithNotFoundDetection(loanPurposeId);
         }
-        List<LoanDisbursementDetails> disbursementDetails = null;
+        List<LoanDisbursementDetails> disbursementDetails = new ArrayList<>();
         BigDecimal fixedEmiAmount = null;
         if (loanProduct.isMultiDisburseLoan() || loanProduct.canDefineInstallmentAmount()) {
             fixedEmiAmount = this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed(LoanApiConstants.emiAmountParameterName, element);