[FINERACT-1678] Introducing synchronous COB execution for loan account changing APIs

This commit is contained in:
taskain7
2022-11-08 14:46:51 +01:00
committed by Arnold Gálovics
parent 70a0a3e2e9
commit 3951e69ad7
8 changed files with 91 additions and 53 deletions
@@ -30,6 +30,7 @@ import java.math.BigDecimal;
import java.util.Collections;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import org.apache.fineract.cob.service.InlineLoanCOBExecutorServiceImpl;
import org.apache.fineract.cob.service.LoanAccountLockService;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.portfolio.loanaccount.domain.GLIMAccountInfoRepository;
@@ -59,6 +60,8 @@ class LoanCOBApiFilterTest {
private GLIMAccountInfoRepository glimAccountInfoRepository;
@Mock
private PlatformSecurityContext context;
@Mock
private InlineLoanCOBExecutorServiceImpl inlineLoanCOBExecutorService;
@Test
void shouldProceedWhenUrlDoesNotMatch() throws ServletException, IOException {
@@ -99,6 +102,7 @@ class LoanCOBApiFilterTest {
given(request.getPathInfo()).willReturn("/loans/2/charges");
given(request.getMethod()).willReturn(HTTPMethods.POST.value());
given(loanAccountLockService.isLoanHardLocked(2L)).willReturn(false);
given(loanAccountLockService.isLoanSoftLocked(2L)).willReturn(false);
given(context.getAuthenticatedUserIfPresent()).willReturn(appUser);
testObj.doFilterInternal(request, response, filterChain);
@@ -106,7 +110,7 @@ class LoanCOBApiFilterTest {
}
@Test
void shouldProceedWhenLoanIsSoftLocked() throws ServletException, IOException {
void shouldRunInlineCOBAndProceedWhenLoanIsSoftLocked() throws ServletException, IOException {
MockHttpServletRequest request = mock(MockHttpServletRequest.class);
MockHttpServletResponse response = mock(MockHttpServletResponse.class);
FilterChain filterChain = mock(FilterChain.class);
@@ -115,9 +119,11 @@ class LoanCOBApiFilterTest {
given(request.getPathInfo()).willReturn("/loans/2/charges");
given(request.getMethod()).willReturn(HTTPMethods.POST.value());
given(loanAccountLockService.isLoanHardLocked(2L)).willReturn(false);
given(loanAccountLockService.isLoanSoftLocked(2L)).willReturn(true);
given(context.getAuthenticatedUserIfPresent()).willReturn(appUser);
testObj.doFilterInternal(request, response, filterChain);
verify(inlineLoanCOBExecutorService, times(1)).execute(Collections.singletonList(2L), "INLINE_LOAN_COB");
verify(filterChain, times(1)).doFilter(request, response);
}