[FINERACT-1678] Loan COB Catch Up

This commit is contained in:
taskain7
2023-01-18 16:09:26 +01:00
committed by Arnold Gálovics
parent 21013749f4
commit 220d9fe1e4
22 changed files with 1028 additions and 11 deletions
@@ -18,16 +18,26 @@
*/
package org.apache.fineract.cob.service;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.HashMap;
import java.util.List;
import org.apache.fineract.cob.data.LoanIdAndLastClosedBusinessDate;
import org.apache.fineract.cob.exceptions.LoanAccountLockCannotBeOverruledException;
import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant;
import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
import org.apache.fineract.portfolio.loanaccount.domain.LoanRepository;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
@@ -45,17 +55,42 @@ class InlineLoanCOBExecutorServiceImplTest {
private InlineLoanCOBExecutorServiceImpl testObj;
@Mock
private TransactionTemplate transactionTemplate;
@Mock
private InlineLoanCOBExecutionDataParser dataParser;
@Mock
private LoanRepository loanRepository;
@Test
void shouldExceptionThrownIfLoanIsAlreadyLocked() {
JsonCommand command = mock(JsonCommand.class);
LoanIdAndLastClosedBusinessDate loan = mock(LoanIdAndLastClosedBusinessDate.class);
ThreadLocalContextUtil.setTenant(new FineractPlatformTenant(1L, "default", "Default", "Asia/Kolkata", null));
HashMap<BusinessDateType, LocalDate> businessDates = new HashMap<>();
LocalDate businessDate = LocalDate.now(ZoneId.systemDefault());
businessDates.put(BusinessDateType.BUSINESS_DATE, businessDate);
businessDates.put(BusinessDateType.COB_DATE, businessDate.minusDays(1));
ThreadLocalContextUtil.setBusinessDates(businessDates);
when(dataParser.parseExecution(any())).thenReturn(List.of(3L));
when(transactionTemplate.execute(any())).thenThrow(new LoanAccountLockCannotBeOverruledException(""));
when(loanRepository.findAllNonClosedLoansBehindByLoanIds(any(), anyList())).thenReturn(List.of(loan));
assertThrows(LoanAccountLockCannotBeOverruledException.class, () -> testObj.executeInlineJob(command, "INLINE_LOAN_COB"));
}
@Test
void shouldOldestCloseBusinessDateReturnWithCorrectDate()
throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
LoanIdAndLastClosedBusinessDate loan1 = mock(LoanIdAndLastClosedBusinessDate.class);
LoanIdAndLastClosedBusinessDate loan2 = mock(LoanIdAndLastClosedBusinessDate.class);
LoanIdAndLastClosedBusinessDate loan3 = mock(LoanIdAndLastClosedBusinessDate.class);
when(loan1.getLastClosedBusinessDate()).thenReturn(null);
when(loan2.getLastClosedBusinessDate()).thenReturn(LocalDate.of(2023, 1, 10));
when(loan3.getLastClosedBusinessDate()).thenReturn(LocalDate.of(2023, 1, 11));
assertEquals(LocalDate.of(2023, 1, 10), getOldestCOBBusinessDate().invoke(testObj, List.of(loan1, loan2, loan3)));
}
private Method getOldestCOBBusinessDate() throws NoSuchMethodException {
Method method = InlineLoanCOBExecutorServiceImpl.class.getDeclaredMethod("getOldestCOBBusinessDate", List.class);
method.setAccessible(true);
return method;
}
}