FINERACT-2418: Extend disbursal and reage events with changed terms flag
This commit is contained in:
committed by
Adam Saghy
parent
136a966fc3
commit
1feb1d730f
+62
@@ -21,6 +21,8 @@ package org.apache.fineract.infrastructure.event.external.service.serialization.
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -32,7 +34,9 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.apache.fineract.avro.loan.v1.LoanTransactionDataV1;
|
||||
import org.apache.fineract.infrastructure.event.business.domain.loan.transaction.LoanDisbursalTransactionBusinessEvent;
|
||||
import org.apache.fineract.infrastructure.event.business.domain.loan.transaction.LoanTransactionBusinessEvent;
|
||||
import org.apache.fineract.infrastructure.event.business.domain.loan.transaction.LoanTransactionFlagsData;
|
||||
import org.apache.fineract.infrastructure.event.external.service.serialization.mapper.loan.LoanTransactionDataMapper;
|
||||
import org.apache.fineract.infrastructure.event.external.service.serialization.serializer.ExternalEventCustomDataSerializer;
|
||||
import org.apache.fineract.portfolio.loanaccount.data.LoanTransactionData;
|
||||
@@ -133,4 +137,62 @@ class LoanTransactionBusinessEventSerializerTest {
|
||||
assertEquals("test_data_for_loan_transaction_2", new String(customData.get("test_key_2").array(), UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testTransactionFlagsSerializationWithChangedTerms() {
|
||||
final long loanId = 1;
|
||||
final long transactionId = 2;
|
||||
|
||||
final Loan loan = mock(Loan.class);
|
||||
final LoanTransaction loanTransaction = mock(LoanTransaction.class);
|
||||
final LoanTransactionData transactionData = mock(LoanTransactionData.class);
|
||||
|
||||
when(loan.getId()).thenReturn(loanId);
|
||||
when(loanTransaction.getId()).thenReturn(transactionId);
|
||||
when(loanTransaction.getLoan()).thenReturn(loan);
|
||||
|
||||
final LoanTransactionFlagsData flags = new LoanTransactionFlagsData(true);
|
||||
final LoanDisbursalTransactionBusinessEvent event = new LoanDisbursalTransactionBusinessEvent(loanTransaction, flags);
|
||||
|
||||
when(loanReadPlatformService.retrieveLoanTransaction(loanId, transactionId)).thenReturn(transactionData);
|
||||
when(loanChargePaidByReadService.fetchLoanChargesPaidByDataTransactionId(anyLong())).thenReturn(new ArrayList<>());
|
||||
|
||||
final LoanTransactionDataV1 expectedAvroData = LoanTransactionDataV1.newBuilder().setId(transactionId).setLoanId(loanId)
|
||||
.setCustomData(new HashMap<>()).build();
|
||||
when(loanTransactionMapper.map(any(LoanTransactionData.class))).thenReturn(expectedAvroData);
|
||||
|
||||
final LoanTransactionDataV1 result = (LoanTransactionDataV1) serializer.toAvroDTO(event);
|
||||
|
||||
assertNotNull(result);
|
||||
assertNotNull(result.getFlags());
|
||||
assertTrue(result.getFlags().getChangedTerms());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testTransactionWithoutFlagsHasNullFlags() {
|
||||
final long loanId = 1;
|
||||
final long transactionId = 2;
|
||||
|
||||
final Loan loan = mock(Loan.class);
|
||||
final LoanTransaction loanTransaction = mock(LoanTransaction.class);
|
||||
final LoanTransactionData transactionData = mock(LoanTransactionData.class);
|
||||
|
||||
when(loan.getId()).thenReturn(loanId);
|
||||
when(loanTransaction.getId()).thenReturn(transactionId);
|
||||
when(loanTransaction.getLoan()).thenReturn(loan);
|
||||
|
||||
final LoanDisbursalTransactionBusinessEvent event = new LoanDisbursalTransactionBusinessEvent(loanTransaction);
|
||||
|
||||
when(loanReadPlatformService.retrieveLoanTransaction(loanId, transactionId)).thenReturn(transactionData);
|
||||
when(loanChargePaidByReadService.fetchLoanChargesPaidByDataTransactionId(anyLong())).thenReturn(new ArrayList<>());
|
||||
|
||||
final LoanTransactionDataV1 expectedAvroData = LoanTransactionDataV1.newBuilder().setId(transactionId).setLoanId(loanId)
|
||||
.setCustomData(new HashMap<>()).build();
|
||||
when(loanTransactionMapper.map(any(LoanTransactionData.class))).thenReturn(expectedAvroData);
|
||||
|
||||
final LoanTransactionDataV1 result = (LoanTransactionDataV1) serializer.toAvroDTO(event);
|
||||
|
||||
assertNotNull(result);
|
||||
assertNull(result.getFlags());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user