Revert "FINERACT-1724 - Replayed bulk transaction fix [x] - Remove bulk transaction from ReplayedTransactionBusinessEventService [x] - Create Aspect and custom annotation for CommandHandler and Tasklet bulk events [x] - Add @BulkEventSupport annotation where ReplayedTransactionBusinessEventService was used [x] - Test class for Aspect call failure handling"

This reverts commit 1b2c09ea
This commit is contained in:
Janos Haber
2023-01-25 16:54:12 +01:00
committed by Arnold Gálovics
parent 507556f202
commit 1808e921ba
50 changed files with 48 additions and 431 deletions
+1 -2
View File
@@ -150,10 +150,9 @@ configurations {
driver
}
dependencies {
testImplementation 'org.projectlombok:lombok:1.18.24'
driver 'org.mariadb.jdbc:mariadb-java-client'
driver 'org.postgresql:postgresql'
driver 'mysql:mysql-connector-java:8.0.32'
driver 'mysql:mysql-connector-java:8.0.31'
}
URLClassLoader loader = GroovyObject.class.classLoader
@@ -1,37 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.infrastructure.event.business.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Annotation to be used to collect events into BulkEvent
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE, ElementType.METHOD })
@Documented
@Inherited
public @interface BulkEventSupport {
}
@@ -1,55 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.infrastructure.event.business.aspect;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierService;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
@Component
@RequiredArgsConstructor
@Aspect
public class BulkEventAspect {
private final BusinessEventNotifierService businessEventNotifierService;
@Around("execution(@org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport public * *(..)) || execution(public * (@org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport *).*(..))")
public Object processCommandJoinPoint(ProceedingJoinPoint proceedingJoinPoint) {
return bulkAroundWrapper(proceedingJoinPoint);
}
@SneakyThrows
private Object bulkAroundWrapper(ProceedingJoinPoint proceedingJoinPoint) {
if (businessEventNotifierService.isExternalEventRecordingEnabled()) {
return proceedingJoinPoint.proceed(proceedingJoinPoint.getArgs());
}
try {
businessEventNotifierService.startExternalEventRecording();
Object result = proceedingJoinPoint.proceed(proceedingJoinPoint.getArgs());
businessEventNotifierService.stopExternalEventRecording();
return result;
} finally {
businessEventNotifierService.resetEventRecording();
}
}
}
@@ -23,6 +23,7 @@ import org.apache.fineract.infrastructure.event.business.domain.BusinessEvent;
/**
* Implemented class is responsible for notifying the business event to registered listeners.
*
*/
public interface BusinessEventNotifierService {
@@ -46,12 +47,9 @@ public interface BusinessEventNotifierService {
*/
<T extends BusinessEvent<?>> void addPostBusinessEventListener(Class<T> eventType, BusinessEventListener<T> listener);
boolean isExternalEventRecordingEnabled();
void startExternalEventRecording();
void stopExternalEventRecording();
void resetEventRecording();
}
@@ -110,8 +110,7 @@ public class BusinessEventNotifierServiceImpl implements BusinessEventNotifierSe
businessEventListeners.add(listener);
}
@Override
public boolean isExternalEventRecordingEnabled() {
private boolean isExternalEventRecordingEnabled() {
return eventRecordingEnabled.get();
}
@@ -162,5 +161,4 @@ public class BusinessEventNotifierServiceImpl implements BusinessEventNotifierSe
eventRecordingEnabled.set(false);
recordedEvents.remove();
}
}
@@ -23,7 +23,6 @@ import org.apache.fineract.commands.annotation.CommandType;
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport;
import org.apache.fineract.portfolio.account.service.AccountTransfersWritePlatformService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -31,7 +30,6 @@ import org.springframework.transaction.annotation.Transactional;
@Service
@RequiredArgsConstructor
@CommandType(entity = "ACCOUNTTRANSFER", action = "CREATE")
@BulkEventSupport
public class CreateAccountTransferCommandHandler implements NewCommandSourceHandler {
private final AccountTransfersWritePlatformService writePlatformService;
@@ -30,7 +30,6 @@ import org.apache.fineract.infrastructure.core.exception.AbstractPlatformService
import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.infrastructure.core.service.database.DatabaseSpecificSQLGenerator;
import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport;
import org.apache.fineract.infrastructure.jobs.exception.JobExecutionException;
import org.apache.fineract.portfolio.account.data.AccountTransferDTO;
import org.apache.fineract.portfolio.account.data.StandingInstructionData;
@@ -53,7 +52,6 @@ import org.springframework.jdbc.core.JdbcTemplate;
@Slf4j
@RequiredArgsConstructor
@BulkEventSupport
public class ExecuteStandingInstructionsTasklet implements Tasklet {
private final StandingInstructionReadPlatformService standingInstructionReadPlatformService;
@@ -22,7 +22,6 @@ import org.apache.fineract.commands.annotation.CommandType;
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport;
import org.apache.fineract.portfolio.collectionsheet.service.CollectionSheetWritePlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -30,7 +29,6 @@ import org.springframework.transaction.annotation.Transactional;
@Service
@CommandType(entity = "COLLECTIONSHEET", action = "SAVE")
@BulkEventSupport
public class SaveIndividualCollectionSheetCommandHandler implements NewCommandSourceHandler {
private final CollectionSheetWritePlatformService collectionSheetWritePlatformService;
@@ -22,7 +22,6 @@ import org.apache.fineract.commands.annotation.CommandType;
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport;
import org.apache.fineract.portfolio.collectionsheet.service.CollectionSheetWritePlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -30,7 +29,6 @@ import org.springframework.transaction.annotation.Transactional;
@Service
@CommandType(entity = "COLLECTIONSHEET", action = "UPDATE")
@BulkEventSupport
public class UpdateCollectionSheetCommandHandler implements NewCommandSourceHandler {
private final CollectionSheetWritePlatformService collectionSheetWritePlatformService;
@@ -22,7 +22,6 @@ import org.apache.fineract.commands.annotation.CommandType;
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport;
import org.apache.fineract.portfolio.collectionsheet.service.CollectionSheetWritePlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -30,7 +29,6 @@ import org.springframework.transaction.annotation.Transactional;
@Service
@CommandType(entity = "CENTER", action = "SAVECOLLECTIONSHEET")
@BulkEventSupport
public class SaveCenterCollectionSheetCommandHandler implements NewCommandSourceHandler {
private final CollectionSheetWritePlatformService writePlatformService;
@@ -22,7 +22,6 @@ import org.apache.fineract.commands.annotation.CommandType;
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport;
import org.apache.fineract.portfolio.collectionsheet.service.CollectionSheetWritePlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -30,7 +29,6 @@ import org.springframework.transaction.annotation.Transactional;
@Service
@CommandType(entity = "GROUP", action = "SAVECOLLECTIONSHEET")
@BulkEventSupport
public class SaveGroupCollectionSheetCommandHandler implements NewCommandSourceHandler {
private final CollectionSheetWritePlatformService writePlatformService;
@@ -22,14 +22,12 @@ import lombok.RequiredArgsConstructor;
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport;
import org.apache.fineract.portfolio.loanaccount.service.LoanWritePlatformService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
@RequiredArgsConstructor
@BulkEventSupport
public class AddAndDeleteLoanDisburseDetailsCommandHandler implements NewCommandSourceHandler {
private final LoanWritePlatformService writePlatformService;
@@ -24,7 +24,6 @@ import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.DataIntegrityErrorHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport;
import org.apache.fineract.portfolio.loanaccount.service.LoanChargeWritePlatformService;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.orm.jpa.JpaSystemException;
@@ -34,7 +33,6 @@ import org.springframework.transaction.annotation.Transactional;
@Service
@RequiredArgsConstructor
@CommandType(entity = "LOANCHARGE", action = "CREATE")
@BulkEventSupport
public class AddLoanChargeCommandHandler implements NewCommandSourceHandler {
private final LoanChargeWritePlatformService writePlatformService;
@@ -24,7 +24,6 @@ import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.DataIntegrityErrorHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport;
import org.apache.fineract.portfolio.loanaccount.service.LoanWritePlatformService;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.orm.jpa.JpaSystemException;
@@ -34,7 +33,6 @@ import org.springframework.transaction.annotation.Transactional;
@Service
@RequiredArgsConstructor
@CommandType(entity = "LOAN", action = "DISBURSE")
@BulkEventSupport
public class DisburseLoanCommandHandler implements NewCommandSourceHandler {
private final LoanWritePlatformService writePlatformService;
@@ -23,7 +23,6 @@ import org.apache.fineract.commands.annotation.CommandType;
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport;
import org.apache.fineract.portfolio.loanaccount.service.LoanWritePlatformService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -31,7 +30,6 @@ import org.springframework.transaction.annotation.Transactional;
@Service
@RequiredArgsConstructor
@CommandType(entity = "LOAN", action = "DISBURSETOSAVINGS")
@BulkEventSupport
public class DisburseLoanToSavingsCommandHandler implements NewCommandSourceHandler {
private final LoanWritePlatformService writePlatformService;
@@ -23,14 +23,12 @@ import org.apache.fineract.commands.annotation.CommandType;
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport;
import org.apache.fineract.portfolio.loanaccount.service.LoanWritePlatformService;
import org.springframework.stereotype.Service;
@Service
@RequiredArgsConstructor
@CommandType(entity = "LOAN", action = "FORECLOSURE")
@BulkEventSupport
public class ForeClosureCommandHandler implements NewCommandSourceHandler {
private final LoanWritePlatformService writePlatformService;
@@ -24,7 +24,6 @@ import org.apache.fineract.commands.annotation.CommandType;
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport;
import org.apache.fineract.portfolio.loanaccount.service.LoanWritePlatformService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -32,7 +31,6 @@ import org.springframework.transaction.annotation.Transactional;
@Service
@RequiredArgsConstructor
@CommandType(entity = "GLIMLOAN", action = "DISBURSE")
@BulkEventSupport
public class GlimLoanApplicationDisburseCommandHandler implements NewCommandSourceHandler {
private final LoanWritePlatformService writePlatformService;
@@ -24,7 +24,6 @@ import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.DataIntegrityErrorHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport;
import org.apache.fineract.portfolio.loanaccount.service.LoanChargeWritePlatformService;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.orm.jpa.JpaSystemException;
@@ -34,7 +33,6 @@ import org.springframework.transaction.annotation.Transactional;
@Service
@RequiredArgsConstructor
@CommandType(entity = "LOAN", action = "CHARGEREFUND")
@BulkEventSupport
public class LoanChargeRefundCommandHandler implements NewCommandSourceHandler {
private final LoanChargeWritePlatformService writePlatformService;
@@ -24,7 +24,6 @@ import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.DataIntegrityErrorHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport;
import org.apache.fineract.portfolio.loanaccount.domain.LoanTransactionType;
import org.apache.fineract.portfolio.loanaccount.service.LoanWritePlatformService;
import org.springframework.dao.DataIntegrityViolationException;
@@ -35,7 +34,6 @@ import org.springframework.transaction.annotation.Transactional;
@Service
@RequiredArgsConstructor
@CommandType(entity = "LOAN", action = "GOODWILLCREDIT")
@BulkEventSupport
public class LoanGoodwillCreditCommandHandler implements NewCommandSourceHandler {
private final LoanWritePlatformService writePlatformService;
@@ -24,7 +24,6 @@ import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.DataIntegrityErrorHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport;
import org.apache.fineract.portfolio.loanaccount.domain.LoanTransactionType;
import org.apache.fineract.portfolio.loanaccount.service.LoanWritePlatformService;
import org.springframework.dao.DataIntegrityViolationException;
@@ -35,7 +34,6 @@ import org.springframework.transaction.annotation.Transactional;
@Service
@RequiredArgsConstructor
@CommandType(entity = "LOAN", action = "MERCHANTISSUEDREFUND")
@BulkEventSupport
public class LoanMerchantIssuedRefundCommandHandler implements NewCommandSourceHandler {
private final LoanWritePlatformService writePlatformService;
@@ -24,7 +24,6 @@ import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.DataIntegrityErrorHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport;
import org.apache.fineract.portfolio.loanaccount.domain.LoanTransactionType;
import org.apache.fineract.portfolio.loanaccount.service.LoanWritePlatformService;
import org.springframework.dao.DataIntegrityViolationException;
@@ -35,7 +34,6 @@ import org.springframework.transaction.annotation.Transactional;
@Service
@RequiredArgsConstructor
@CommandType(entity = "LOAN", action = "PAYOUTREFUND")
@BulkEventSupport
public class LoanPayoutRefundCommandHandler implements NewCommandSourceHandler {
private final LoanWritePlatformService writePlatformService;
@@ -23,7 +23,6 @@ import org.apache.fineract.commands.annotation.CommandType;
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport;
import org.apache.fineract.portfolio.loanaccount.domain.LoanTransactionType;
import org.apache.fineract.portfolio.loanaccount.service.LoanWritePlatformService;
import org.springframework.stereotype.Service;
@@ -31,7 +30,6 @@ import org.springframework.stereotype.Service;
@Service
@RequiredArgsConstructor
@CommandType(entity = "LOAN", action = "RECOVERYPAYMENT")
@BulkEventSupport
public class LoanRecoveryPaymentCommandHandler implements NewCommandSourceHandler {
private final LoanWritePlatformService writePlatformService;
@@ -23,7 +23,6 @@ import org.apache.fineract.commands.annotation.CommandType;
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport;
import org.apache.fineract.portfolio.loanaccount.service.LoanWritePlatformService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -31,7 +30,6 @@ import org.springframework.transaction.annotation.Transactional;
@Service
@RequiredArgsConstructor
@CommandType(entity = "LOAN", action = "ADJUST")
@BulkEventSupport
public class LoanRepaymentAdjustmentCommandHandler implements NewCommandSourceHandler {
private final LoanWritePlatformService writePlatformService;
@@ -24,7 +24,6 @@ import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.DataIntegrityErrorHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport;
import org.apache.fineract.portfolio.loanaccount.domain.LoanTransactionType;
import org.apache.fineract.portfolio.loanaccount.service.LoanWritePlatformService;
import org.springframework.dao.DataIntegrityViolationException;
@@ -35,7 +34,6 @@ import org.springframework.transaction.annotation.Transactional;
@Service
@RequiredArgsConstructor
@CommandType(entity = "LOAN", action = "REPAYMENT")
@BulkEventSupport
public class LoanRepaymentCommandHandler implements NewCommandSourceHandler {
private final LoanWritePlatformService writePlatformService;
@@ -23,7 +23,6 @@ import org.apache.fineract.commands.annotation.CommandType;
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport;
import org.apache.fineract.portfolio.loanaccount.service.LoanChargeWritePlatformService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -31,7 +30,6 @@ import org.springframework.transaction.annotation.Transactional;
@Service
@RequiredArgsConstructor
@CommandType(entity = "LOANCHARGE", action = "PAY")
@BulkEventSupport
public class PayLoanChargeCommandHandler implements NewCommandSourceHandler {
private final LoanChargeWritePlatformService writePlatformService;
@@ -23,14 +23,12 @@ import org.apache.fineract.commands.annotation.CommandType;
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport;
import org.apache.fineract.portfolio.loanaccount.service.LoanWritePlatformService;
import org.springframework.stereotype.Service;
@Service
@RequiredArgsConstructor
@CommandType(entity = "LOAN", action = "RECOVERGUARANTEES")
@BulkEventSupport
public class RecoverFromGuarantorCommandHandler implements NewCommandSourceHandler {
private final LoanWritePlatformService writePlatformService;
@@ -23,7 +23,6 @@ import org.apache.fineract.commands.annotation.CommandType;
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport;
import org.apache.fineract.portfolio.loanaccount.service.LoanWritePlatformService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -31,7 +30,6 @@ import org.springframework.transaction.annotation.Transactional;
@Service
@RequiredArgsConstructor
@CommandType(entity = "LOAN", action = "UNDOWRITEOFF")
@BulkEventSupport
public class UndoWriteOffLoanCommandHandler implements NewCommandSourceHandler {
private final LoanWritePlatformService writePlatformService;
@@ -22,14 +22,12 @@ import lombok.RequiredArgsConstructor;
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport;
import org.apache.fineract.portfolio.loanaccount.service.LoanWritePlatformService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
@RequiredArgsConstructor
@BulkEventSupport
public class UpdateLoanDisburseDateCommandHandler implements NewCommandSourceHandler {
private final LoanWritePlatformService writePlatformService;
@@ -23,7 +23,6 @@ import org.apache.fineract.commands.annotation.CommandType;
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport;
import org.apache.fineract.portfolio.loanaccount.service.LoanWritePlatformService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -31,7 +30,6 @@ import org.springframework.transaction.annotation.Transactional;
@Service
@RequiredArgsConstructor
@CommandType(entity = "LOAN", action = "WAIVEINTERESTPORTION")
@BulkEventSupport
public class WaiveInterestPortionOnLoanCommandHandler implements NewCommandSourceHandler {
private final LoanWritePlatformService writePlatformService;
@@ -29,7 +29,6 @@ import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDoma
import org.apache.fineract.infrastructure.core.data.ApiParameterError;
import org.apache.fineract.infrastructure.core.exception.AbstractPlatformDomainRuleException;
import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport;
import org.apache.fineract.infrastructure.jobs.exception.JobExecutionException;
import org.apache.fineract.portfolio.loanaccount.loanschedule.data.OverdueLoanScheduleData;
import org.apache.fineract.portfolio.loanaccount.service.LoanChargeWritePlatformService;
@@ -41,7 +40,6 @@ import org.springframework.batch.repeat.RepeatStatus;
@Slf4j
@RequiredArgsConstructor
@BulkEventSupport
public class ApplyChargeToOverdueLoanInstallmentTasklet implements Tasklet {
private final ConfigurationDomainService configurationDomainService;
@@ -31,7 +31,6 @@ import java.util.concurrent.Future;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport;
import org.apache.fineract.infrastructure.jobs.exception.JobExecutionException;
import org.apache.fineract.organisation.office.data.OfficeData;
import org.apache.fineract.organisation.office.exception.OfficeNotFoundException;
@@ -47,7 +46,6 @@ import org.springframework.batch.repeat.RepeatStatus;
@Slf4j
@RequiredArgsConstructor
@BulkEventSupport
public class RecalculateInterestForLoanTasklet implements Tasklet {
private final LoanReadPlatformService loanReadPlatformService;
@@ -25,7 +25,6 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.infrastructure.core.domain.ExternalId;
import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport;
import org.apache.fineract.infrastructure.jobs.exception.JobExecutionException;
import org.apache.fineract.portfolio.account.PortfolioAccountType;
import org.apache.fineract.portfolio.account.data.AccountTransferDTO;
@@ -46,7 +45,6 @@ import org.springframework.batch.repeat.RepeatStatus;
@Slf4j
@RequiredArgsConstructor
@BulkEventSupport
public class TransferFeeChargeForLoansTasklet implements Tasklet {
private final LoanChargeReadPlatformService loanChargeReadPlatformService;
@@ -22,7 +22,6 @@ import org.apache.fineract.commands.annotation.CommandType;
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport;
import org.apache.fineract.portfolio.loanaccount.rescheduleloan.service.LoanRescheduleRequestWritePlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -30,7 +29,6 @@ import org.springframework.transaction.annotation.Transactional;
@Service
@CommandType(entity = "RESCHEDULELOAN", action = "APPROVE")
@BulkEventSupport
public class ApproveLoanRescheduleRequestCommandHandler implements NewCommandSourceHandler {
private final LoanRescheduleRequestWritePlatformService loanRescheduleRequestWritePlatformService;
@@ -41,13 +41,19 @@ public class ReplayedTransactionBusinessEventServiceImpl implements ReplayedTran
return;
}
// Extra safety net to avoid event leaking
for (Map.Entry<Long, LoanTransaction> mapEntry : changedTransactionDetail.getNewTransactionMappings().entrySet()) {
LoanTransaction oldTransaction = loanTransactionRepository.findById(mapEntry.getKey())
.orElseThrow(() -> new LoanTransactionNotFoundException(mapEntry.getKey()));
LoanAdjustTransactionBusinessEvent.Data data = new LoanAdjustTransactionBusinessEvent.Data(oldTransaction);
data.setNewTransactionDetail(mapEntry.getValue());
businessEventNotifierService.notifyPostBusinessEvent(new LoanAdjustTransactionBusinessEvent(data));
try {
businessEventNotifierService.startExternalEventRecording();
for (Map.Entry<Long, LoanTransaction> mapEntry : changedTransactionDetail.getNewTransactionMappings().entrySet()) {
LoanTransaction oldTransaction = loanTransactionRepository.findById(mapEntry.getKey())
.orElseThrow(() -> new LoanTransactionNotFoundException(mapEntry.getKey()));
LoanAdjustTransactionBusinessEvent.Data data = new LoanAdjustTransactionBusinessEvent.Data(oldTransaction);
data.setNewTransactionDetail(mapEntry.getValue());
businessEventNotifierService.notifyPostBusinessEvent(new LoanAdjustTransactionBusinessEvent(data));
}
businessEventNotifierService.stopExternalEventRecording();
} catch (Exception e) {
businessEventNotifierService.resetEventRecording();
throw e;
}
}
}
@@ -22,7 +22,6 @@ import org.apache.fineract.commands.annotation.CommandType;
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport;
import org.apache.fineract.portfolio.savings.service.DepositAccountWritePlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -30,7 +29,6 @@ import org.springframework.transaction.annotation.Transactional;
@Service
@CommandType(entity = "FIXEDDEPOSITACCOUNT", action = "ACTIVATE")
@BulkEventSupport
public class ActivateFixedDepositAccountCommandHandler implements NewCommandSourceHandler {
private final DepositAccountWritePlatformService depositAccountWritePlatformService;
@@ -22,7 +22,6 @@ import org.apache.fineract.commands.annotation.CommandType;
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport;
import org.apache.fineract.portfolio.savings.service.DepositAccountWritePlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -30,7 +29,6 @@ import org.springframework.transaction.annotation.Transactional;
@Service
@CommandType(entity = "RECURRINGDEPOSITACCOUNT", action = "ACTIVATE")
@BulkEventSupport
public class ActivateRecurringDepositAccountCommandHandler implements NewCommandSourceHandler {
private final DepositAccountWritePlatformService depositAccountWritePlatformService;
@@ -22,7 +22,6 @@ import org.apache.fineract.commands.annotation.CommandType;
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport;
import org.apache.fineract.portfolio.savings.service.DepositAccountWritePlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -30,7 +29,6 @@ import org.springframework.transaction.annotation.Transactional;
@Service
@CommandType(entity = "FIXEDDEPOSITACCOUNT", action = "CLOSE")
@BulkEventSupport
public class CloseFixedDepositAccountCommandHandler implements NewCommandSourceHandler {
private final DepositAccountWritePlatformService depositAccountWritePlatformService;
@@ -22,7 +22,6 @@ import org.apache.fineract.commands.annotation.CommandType;
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport;
import org.apache.fineract.portfolio.savings.service.DepositAccountWritePlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -30,7 +29,6 @@ import org.springframework.transaction.annotation.Transactional;
@Service
@CommandType(entity = "RECURRINGDEPOSITACCOUNT", action = "CLOSE")
@BulkEventSupport
public class CloseRecurringDepositAccountCommandHandler implements NewCommandSourceHandler {
private final DepositAccountWritePlatformService depositAccountWritePlatformService;
@@ -22,7 +22,6 @@ import org.apache.fineract.commands.annotation.CommandType;
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport;
import org.apache.fineract.portfolio.savings.service.DepositAccountWritePlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -30,7 +29,6 @@ import org.springframework.transaction.annotation.Transactional;
@Service
@CommandType(entity = "FIXEDDEPOSITACCOUNT", action = "PREMATURECLOSE")
@BulkEventSupport
public class PrematureCloseFixedDepositAccountCommandHandler implements NewCommandSourceHandler {
private final DepositAccountWritePlatformService depositAccountWritePlatformService;
@@ -22,7 +22,6 @@ import org.apache.fineract.commands.annotation.CommandType;
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport;
import org.apache.fineract.portfolio.savings.service.DepositAccountWritePlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -30,7 +29,6 @@ import org.springframework.transaction.annotation.Transactional;
@Service
@CommandType(entity = "RECURRINGDEPOSITACCOUNT", action = "PREMATURECLOSE")
@BulkEventSupport
public class PrematureCloseRecurringDepositAccountCommandHandler implements NewCommandSourceHandler {
private final DepositAccountWritePlatformService depositAccountWritePlatformService;
@@ -24,7 +24,6 @@ import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport;
import org.apache.fineract.infrastructure.jobs.exception.JobExecutionException;
import org.apache.fineract.portfolio.account.data.AccountTransferDTO;
import org.apache.fineract.portfolio.account.service.AccountTransfersWritePlatformService;
@@ -37,7 +36,6 @@ import org.springframework.batch.repeat.RepeatStatus;
@Slf4j
@RequiredArgsConstructor
@BulkEventSupport
public class TransferInterestToSavingsTasklet implements Tasklet {
private final DepositAccountReadPlatformService depositAccountReadPlatformService;
@@ -25,7 +25,6 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.infrastructure.core.data.ApiParameterError;
import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport;
import org.apache.fineract.portfolio.savings.DepositAccountType;
import org.apache.fineract.portfolio.savings.data.DepositAccountData;
import org.apache.fineract.portfolio.savings.service.DepositAccountReadPlatformService;
@@ -37,7 +36,6 @@ import org.springframework.batch.repeat.RepeatStatus;
@Slf4j
@RequiredArgsConstructor
@BulkEventSupport
public class UpdateDepositsAccountMaturityDetailsTasklet implements Tasklet {
private final DepositAccountReadPlatformService depositAccountReadPlatformService;
@@ -1,31 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.context.web.WebAppConfiguration;
@ExtendWith(SpringExtension.class)
@TestPropertySource("classpath:application-test.properties")
@WebAppConfiguration
@ContextConfiguration(classes = TestConfiguration.class)
public class AbstractSpringTest {}
@@ -23,7 +23,6 @@ import static org.mockito.Mockito.mock;
import com.zaxxer.hikari.HikariDataSource;
import javax.sql.DataSource;
import org.apache.fineract.infrastructure.core.config.CacheConfig;
import org.apache.fineract.infrastructure.core.config.FineractProperties;
import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant;
import org.apache.fineract.infrastructure.core.service.database.DatabaseIndependentQueryService;
@@ -55,7 +54,6 @@ import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfigurati
import org.springframework.boot.autoconfigure.liquibase.LiquibaseProperties;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cache.jcache.JCacheCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@@ -78,8 +76,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
@EnableWebSecurity
@EnableConfigurationProperties({ FineractProperties.class, LiquibaseProperties.class })
@ComponentScan(basePackages = "org.apache.fineract", excludeFilters = {
@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = ScheduledJobRunnerConfig.class),
@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = CacheConfig.class) })
@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = ScheduledJobRunnerConfig.class) })
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
public class TestConfiguration {
@@ -199,9 +196,4 @@ public class TestConfiguration {
public JobRepository jobRepository() {
return mock(JobRepository.class, RETURNS_MOCKS);
}
@Bean
public JCacheCacheManager jCacheCacheManager() {
return new JCacheCacheManager();
}
}
@@ -25,12 +25,12 @@ import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.context.web.WebAppConfiguration;
// This configuration class is used for Cucumber tests, it's invoked via Cucumber glue (cucumber.properties)
@CucumberContextConfiguration
@ExtendWith(SpringExtension.class)
@TestPropertySource("classpath:application-test.properties")
@WebAppConfiguration
@ContextConfiguration(classes = TestConfiguration.class)
public class CucumberTestSuite {
// @SpringBootTest(classes = TestConfiguration.class)
public class TestSuite {
}
@@ -1,44 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.bulk;
import org.apache.fineract.AbstractSpringTest;
import org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierService;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.SpyBean;
public class BulkAspectTest extends AbstractSpringTest {
@Autowired
private BulkTestEvent testEvent;
@SpyBean
private BusinessEventNotifierService notifier;
@Test
public void testEventOnFail() {
Assertions.assertThrows(IllegalStateException.class, () -> testEvent.processCommand(null));
Mockito.verify(notifier, Mockito.times(1)).startExternalEventRecording();
Mockito.verify(notifier, Mockito.times(0)).stopExternalEventRecording();
Mockito.verify(notifier, Mockito.times(1)).resetEventRecording();
}
}
@@ -1,42 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.bulk;
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport;
import org.springframework.stereotype.Component;
@Component
@BulkEventSupport
public class BulkTestEvent implements NewCommandSourceHandler {
private final NestedBulkTestEvent nestedBulkTestEvent;
public BulkTestEvent(NestedBulkTestEvent nestedBulkTestEvent) {
this.nestedBulkTestEvent = nestedBulkTestEvent;
}
@Override
public CommandProcessingResult processCommand(JsonCommand command) {
nestedBulkTestEvent.exec();
return new CommandProcessingResult(1L);
}
}
@@ -1,31 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.bulk;
import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport;
import org.springframework.stereotype.Component;
@Component
@BulkEventSupport
public class NestedBulkTestEvent {
public void exec() {
throw new IllegalStateException("Not implemented");
}
}
@@ -1,52 +0,0 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.portfolio.loanaccount.service;
import org.apache.fineract.infrastructure.event.business.annotation.BulkEventSupport;
import org.apache.fineract.portfolio.loanaccount.domain.ChangedTransactionDetail;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class DummyTasklet implements Tasklet {
private ChangedTransactionDetail changedTransactionDetail;
@Autowired
private ReplayedTransactionBusinessEventService replayedTransactionBusinessService;
@Override
@BulkEventSupport
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
replayedTransactionBusinessService.raiseTransactionReplayedEvents(changedTransactionDetail);
return RepeatStatus.FINISHED;
}
public ChangedTransactionDetail getChangedTransactionDetail() {
return changedTransactionDetail;
}
public void setChangedTransactionDetail(ChangedTransactionDetail changedTransactionDetail) {
this.changedTransactionDetail = changedTransactionDetail;
}
}
@@ -24,7 +24,6 @@ import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.verify;
import java.util.Optional;
import org.apache.fineract.AbstractSpringTest;
import org.apache.fineract.infrastructure.event.business.domain.loan.LoanAdjustTransactionBusinessEvent;
import org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierService;
import org.apache.fineract.portfolio.loanaccount.domain.ChangedTransactionDetail;
@@ -32,85 +31,75 @@ import org.apache.fineract.portfolio.loanaccount.domain.LoanTransaction;
import org.apache.fineract.portfolio.loanaccount.domain.LoanTransactionRepository;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.mockito.junit.jupiter.MockitoExtension;
class ReplayedTransactionBusinessEventServiceIntegrationTest extends AbstractSpringTest {
@ExtendWith(MockitoExtension.class)
class ReplayedTransactionBusinessEventServiceIntegrationTest {
@MockBean
@Mock
private BusinessEventNotifierService businessEventNotifierService;
@MockBean
@Mock
private LoanTransactionRepository loanTransactionRepository;
@Autowired
private DummyTasklet dummyTasklet;
@Mock
private StepContribution stepContribution;
@Mock
private ChunkContext chunkContext;
private ReplayedTransactionBusinessEventService underTest;
@BeforeEach
void setUp() {
dummyTasklet.setChangedTransactionDetail(null);
public void setUp() {
underTest = new ReplayedTransactionBusinessEventServiceImpl(businessEventNotifierService, loanTransactionRepository);
}
@Test
public void testWhenParamIsNull() throws Exception {
public void testWhenParamIsNull() {
// given
dummyTasklet.setChangedTransactionDetail(null);
ChangedTransactionDetail changedTransactionDetail = null;
// when
dummyTasklet.execute(stepContribution, chunkContext);
underTest.raiseTransactionReplayedEvents(changedTransactionDetail);
// then
verify(businessEventNotifierService, Mockito.times(1)).startExternalEventRecording();
verify(businessEventNotifierService, Mockito.times(0)).startExternalEventRecording();
verify(businessEventNotifierService, Mockito.times(0))
.notifyPostBusinessEvent(Mockito.any(LoanAdjustTransactionBusinessEvent.class));
verify(businessEventNotifierService, Mockito.times(1)).stopExternalEventRecording();
verify(businessEventNotifierService, Mockito.times(1)).resetEventRecording();
verify(businessEventNotifierService, Mockito.times(0)).stopExternalEventRecording();
verify(businessEventNotifierService, Mockito.times(0)).resetEventRecording();
}
@Test
public void testWhenParamHasNoMapping() throws Exception {
public void testWhenParamHasNoMapping() {
// given
ChangedTransactionDetail changedTransactionDetail = new ChangedTransactionDetail();
dummyTasklet.setChangedTransactionDetail(changedTransactionDetail);
// when
dummyTasklet.execute(stepContribution, chunkContext);
underTest.raiseTransactionReplayedEvents(changedTransactionDetail);
// then
verify(businessEventNotifierService, Mockito.times(1)).startExternalEventRecording();
verify(businessEventNotifierService, Mockito.times(0)).startExternalEventRecording();
verify(businessEventNotifierService, Mockito.times(0))
.notifyPostBusinessEvent(Mockito.any(LoanAdjustTransactionBusinessEvent.class));
verify(businessEventNotifierService, Mockito.times(1)).stopExternalEventRecording();
verify(businessEventNotifierService, Mockito.times(1)).resetEventRecording();
verify(businessEventNotifierService, Mockito.times(0)).stopExternalEventRecording();
verify(businessEventNotifierService, Mockito.times(0)).resetEventRecording();
}
@Test
public void testWhenParamHasOneNewTransaction() throws Exception {
public void testWhenParamHasOneNewTransaction() {
// given
LoanTransaction oldLoanTransaction = Mockito.mock(LoanTransaction.class);
LoanTransaction newLoanTransaction = Mockito.mock(LoanTransaction.class);
lenient().when(loanTransactionRepository.findById(1L)).thenReturn(Optional.of(oldLoanTransaction));
ChangedTransactionDetail changedTransactionDetail = new ChangedTransactionDetail();
changedTransactionDetail.getNewTransactionMappings().put(1L, newLoanTransaction);
dummyTasklet.setChangedTransactionDetail(changedTransactionDetail);
// when
dummyTasklet.execute(stepContribution, chunkContext);
underTest.raiseTransactionReplayedEvents(changedTransactionDetail);
// then
verify(businessEventNotifierService, Mockito.times(1)).startExternalEventRecording();
verify(businessEventNotifierService, Mockito.times(1))
.notifyPostBusinessEvent(Mockito.any(LoanAdjustTransactionBusinessEvent.class));
verify(businessEventNotifierService, Mockito.times(1)).stopExternalEventRecording();
verify(businessEventNotifierService, Mockito.times(1)).resetEventRecording();
verify(businessEventNotifierService, Mockito.times(0)).resetEventRecording();
}
@Test
public void testWhenParamHasTwoNewTransaction() throws Exception {
public void testWhenParamHasTwoNewTransaction() {
// given
LoanTransaction oldLoanTransaction = Mockito.mock(LoanTransaction.class);
LoanTransaction newLoanTransaction = Mockito.mock(LoanTransaction.class);
@@ -119,29 +108,28 @@ class ReplayedTransactionBusinessEventServiceIntegrationTest extends AbstractSpr
ChangedTransactionDetail changedTransactionDetail = new ChangedTransactionDetail();
changedTransactionDetail.getNewTransactionMappings().put(1L, newLoanTransaction);
changedTransactionDetail.getNewTransactionMappings().put(2L, newLoanTransaction);
dummyTasklet.setChangedTransactionDetail(changedTransactionDetail);
// when
dummyTasklet.execute(stepContribution, chunkContext);
underTest.raiseTransactionReplayedEvents(changedTransactionDetail);
// then
verify(businessEventNotifierService, Mockito.times(1)).startExternalEventRecording();
verify(businessEventNotifierService, Mockito.times(2))
.notifyPostBusinessEvent(Mockito.any(LoanAdjustTransactionBusinessEvent.class));
verify(businessEventNotifierService, Mockito.times(1)).stopExternalEventRecording();
verify(businessEventNotifierService, Mockito.times(1)).resetEventRecording();
verify(businessEventNotifierService, Mockito.times(0)).resetEventRecording();
}
@Test
public void testWhenParamHasError() {
// given
doThrow(new RuntimeException()).when(businessEventNotifierService).notifyPostBusinessEvent(Mockito.any());
doThrow(new RuntimeException()).when(businessEventNotifierService)
.notifyPostBusinessEvent(Mockito.any(LoanAdjustTransactionBusinessEvent.class));
LoanTransaction oldLoanTransaction = Mockito.mock(LoanTransaction.class);
LoanTransaction newLoanTransaction = Mockito.mock(LoanTransaction.class);
lenient().when(loanTransactionRepository.findById(1L)).thenReturn(Optional.of(oldLoanTransaction));
ChangedTransactionDetail changedTransactionDetail = new ChangedTransactionDetail();
changedTransactionDetail.getNewTransactionMappings().put(1L, newLoanTransaction);
dummyTasklet.setChangedTransactionDetail(changedTransactionDetail);
// when
assertThrows(RuntimeException.class, () -> dummyTasklet.execute(stepContribution, chunkContext));
assertThrows(RuntimeException.class, () -> underTest.raiseTransactionReplayedEvents(changedTransactionDetail));
// then
verify(businessEventNotifierService, Mockito.times(1)).startExternalEventRecording();
verify(businessEventNotifierService, Mockito.times(1))