[FINERACT-1678] Exception fix if every loan fail during COB

This commit is contained in:
taskain7
2023-03-02 15:44:23 +01:00
committed by Adam Saghy
parent 3853111628
commit 29dd1e730c
3 changed files with 9 additions and 13 deletions
@@ -36,9 +36,11 @@ public abstract class AbstractLoanItemWriter extends RepositoryItemWriter<Loan>
@Override @Override
public void write(@NotNull List<? extends Loan> items) throws Exception { public void write(@NotNull List<? extends Loan> items) throws Exception {
super.write(items); if (!items.isEmpty()) {
List<Long> loanIds = items.stream().map(AbstractPersistableCustom::getId).toList(); super.write(items);
accountLockRepository.deleteByLoanIdInAndLockOwner(loanIds, getLockOwner()); List<Long> loanIds = items.stream().map(AbstractPersistableCustom::getId).toList();
accountLockRepository.deleteByLoanIdInAndLockOwner(loanIds, getLockOwner());
}
} }
protected abstract LockOwner getLockOwner(); protected abstract LockOwner getLockOwner();
@@ -18,7 +18,6 @@
*/ */
package org.apache.fineract.cob.loan; 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.lenient;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
@@ -27,7 +26,6 @@ import io.cucumber.java8.En;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import org.apache.fineract.cob.domain.LoanAccountLockRepository; 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.Loan;
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepository; import org.apache.fineract.portfolio.loanaccount.domain.LoanRepository;
import org.mockito.Mockito; import org.mockito.Mockito;
@@ -48,8 +46,6 @@ public class LoanItemWriterStepDefinitions implements En {
lenient().when(loan.getId()).thenReturn(1L); lenient().when(loan.getId()).thenReturn(1L);
if (action.equals("error")) { if (action.equals("error")) {
this.items = Collections.emptyList(); this.items = Collections.emptyList();
lenient().doThrow(new RuntimeException("fail")).when(this.accountLockRepository)
.deleteByLoanIdInAndLockOwner(Collections.emptyList(), LockOwner.LOAN_COB_CHUNK_PROCESSING);
} else { } else {
this.items = Collections.singletonList(loan); this.items = Collections.singletonList(loan);
lenient().doNothing().when(this.accountLockRepository).deleteByLoanIdInAndLockOwner(Mockito.anyList(), Mockito.any()); 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()); verify(this.accountLockRepository, Mockito.times(1)).deleteByLoanIdInAndLockOwner(Mockito.any(), Mockito.any());
}); });
Then("throw exception LoanItemWriter.write method", () -> { Then("LoanItemWriter.write should not call repository", () -> {
assertThrows(RuntimeException.class, () -> { verify(this.accountLockRepository, Mockito.times(0)).deleteByLoanIdInAndLockOwner(Mockito.any(), Mockito.any());
this.loanItemWriter.write(items);
});
}); });
} }
} }
@@ -32,8 +32,8 @@ Feature: COB Writer
@cob @cob
Scenario Outline: LoanItemWriter - run test: exception Scenario Outline: LoanItemWriter - run test: exception
Given The LoanItemWriter.write method with action <action> Given The LoanItemWriter.write method with action <action>
Then throw exception LoanItemWriter.write method Then LoanItemWriter.write should not call repository
Examples: Examples:
|action| |action|
|error| |error|