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

adamsaghy 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 29dd1e730 [FINERACT-1678] Exception fix if every loan fail during COB
29dd1e730 is described below

commit 29dd1e730c627a32ff4d4cd22b072575fd6e814e
Author: taskain7 <[email protected]>
AuthorDate: Wed Mar 1 23:58:39 2023 +0100

    [FINERACT-1678] Exception fix if every loan fail during COB
---
 .../org/apache/fineract/cob/loan/AbstractLoanItemWriter.java   |  8 +++++---
 .../fineract/cob/loan/LoanItemWriterStepDefinitions.java       | 10 ++--------
 .../test/resources/features/cob/loan/cob.loan.writer.feature   |  4 ++--
 3 files changed, 9 insertions(+), 13 deletions(-)

diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/cob/loan/AbstractLoanItemWriter.java
 
b/fineract-provider/src/main/java/org/apache/fineract/cob/loan/AbstractLoanItemWriter.java
index 95dc8953b..4fa5e9d0f 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/cob/loan/AbstractLoanItemWriter.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/cob/loan/AbstractLoanItemWriter.java
@@ -36,9 +36,11 @@ public abstract class AbstractLoanItemWriter extends 
RepositoryItemWriter<Loan>
 
     @Override
     public void write(@NotNull List<? extends Loan> items) throws Exception {
-        super.write(items);
-        List<Long> loanIds = 
items.stream().map(AbstractPersistableCustom::getId).toList();
-        accountLockRepository.deleteByLoanIdInAndLockOwner(loanIds, 
getLockOwner());
+        if (!items.isEmpty()) {
+            super.write(items);
+            List<Long> loanIds = 
items.stream().map(AbstractPersistableCustom::getId).toList();
+            accountLockRepository.deleteByLoanIdInAndLockOwner(loanIds, 
getLockOwner());
+        }
     }
 
     protected abstract LockOwner getLockOwner();
diff --git 
a/fineract-provider/src/test/java/org/apache/fineract/cob/loan/LoanItemWriterStepDefinitions.java
 
b/fineract-provider/src/test/java/org/apache/fineract/cob/loan/LoanItemWriterStepDefinitions.java
index 9ec051544..36ca22972 100644
--- 
a/fineract-provider/src/test/java/org/apache/fineract/cob/loan/LoanItemWriterStepDefinitions.java
+++ 
b/fineract-provider/src/test/java/org/apache/fineract/cob/loan/LoanItemWriterStepDefinitions.java
@@ -18,7 +18,6 @@
  */
 package org.apache.fineract.cob.loan;
 
-import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.mockito.Mockito.lenient;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
@@ -27,7 +26,6 @@ import io.cucumber.java8.En;
 import java.util.Collections;
 import java.util.List;
 import org.apache.fineract.cob.domain.LoanAccountLockRepository;
-import org.apache.fineract.cob.domain.LockOwner;
 import org.apache.fineract.portfolio.loanaccount.domain.Loan;
 import org.apache.fineract.portfolio.loanaccount.domain.LoanRepository;
 import org.mockito.Mockito;
@@ -48,8 +46,6 @@ public class LoanItemWriterStepDefinitions implements En {
             lenient().when(loan.getId()).thenReturn(1L);
             if (action.equals("error")) {
                 this.items = Collections.emptyList();
-                lenient().doThrow(new 
RuntimeException("fail")).when(this.accountLockRepository)
-                        .deleteByLoanIdInAndLockOwner(Collections.emptyList(), 
LockOwner.LOAN_COB_CHUNK_PROCESSING);
             } else {
                 this.items = Collections.singletonList(loan);
                 
lenient().doNothing().when(this.accountLockRepository).deleteByLoanIdInAndLockOwner(Mockito.anyList(),
 Mockito.any());
@@ -65,10 +61,8 @@ public class LoanItemWriterStepDefinitions implements En {
             verify(this.accountLockRepository, 
Mockito.times(1)).deleteByLoanIdInAndLockOwner(Mockito.any(), Mockito.any());
         });
 
-        Then("throw exception LoanItemWriter.write method", () -> {
-            assertThrows(RuntimeException.class, () -> {
-                this.loanItemWriter.write(items);
-            });
+        Then("LoanItemWriter.write should not call repository", () -> {
+            verify(this.accountLockRepository, 
Mockito.times(0)).deleteByLoanIdInAndLockOwner(Mockito.any(), Mockito.any());
         });
     }
 }
diff --git 
a/fineract-provider/src/test/resources/features/cob/loan/cob.loan.writer.feature
 
b/fineract-provider/src/test/resources/features/cob/loan/cob.loan.writer.feature
index 1ecccaef1..fba14efc5 100644
--- 
a/fineract-provider/src/test/resources/features/cob/loan/cob.loan.writer.feature
+++ 
b/fineract-provider/src/test/resources/features/cob/loan/cob.loan.writer.feature
@@ -32,8 +32,8 @@ Feature: COB Writer
   @cob
   Scenario Outline: LoanItemWriter - run test: exception
     Given The LoanItemWriter.write method with action <action>
-    Then throw exception LoanItemWriter.write method
+    Then LoanItemWriter.write should not call repository
 
     Examples:
       |action|
-      |error|
\ No newline at end of file
+      |error|

Reply via email to