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 commit is contained in:
committed by
Arnold Gálovics
parent
6d3cac8c02
commit
1b2c09eae5
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* 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 {}
|
||||
+2
-2
@@ -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)
|
||||
// @SpringBootTest(classes = TestConfiguration.class)
|
||||
public class TestSuite {
|
||||
public class CucumberTestSuite {
|
||||
|
||||
}
|
||||
@@ -23,6 +23,7 @@ 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;
|
||||
@@ -54,6 +55,7 @@ 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;
|
||||
@@ -76,7 +78,8 @@ 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 = ScheduledJobRunnerConfig.class),
|
||||
@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = CacheConfig.class) })
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
public class TestConfiguration {
|
||||
@@ -196,4 +199,9 @@ public class TestConfiguration {
|
||||
public JobRepository jobRepository() {
|
||||
return mock(JobRepository.class, RETURNS_MOCKS);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public JCacheCacheManager jCacheCacheManager() {
|
||||
return new JCacheCacheManager();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* 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");
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
+41
-29
@@ -24,6 +24,7 @@ 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;
|
||||
@@ -31,75 +32,85 @@ 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.mockito.junit.jupiter.MockitoExtension;
|
||||
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;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class ReplayedTransactionBusinessEventServiceIntegrationTest {
|
||||
class ReplayedTransactionBusinessEventServiceIntegrationTest extends AbstractSpringTest {
|
||||
|
||||
@Mock
|
||||
@MockBean
|
||||
private BusinessEventNotifierService businessEventNotifierService;
|
||||
|
||||
@Mock
|
||||
@MockBean
|
||||
private LoanTransactionRepository loanTransactionRepository;
|
||||
|
||||
private ReplayedTransactionBusinessEventService underTest;
|
||||
@Autowired
|
||||
private DummyTasklet dummyTasklet;
|
||||
|
||||
@Mock
|
||||
private StepContribution stepContribution;
|
||||
|
||||
@Mock
|
||||
private ChunkContext chunkContext;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
underTest = new ReplayedTransactionBusinessEventServiceImpl(businessEventNotifierService, loanTransactionRepository);
|
||||
void setUp() {
|
||||
dummyTasklet.setChangedTransactionDetail(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhenParamIsNull() {
|
||||
public void testWhenParamIsNull() throws Exception {
|
||||
// given
|
||||
ChangedTransactionDetail changedTransactionDetail = null;
|
||||
dummyTasklet.setChangedTransactionDetail(null);
|
||||
// when
|
||||
underTest.raiseTransactionReplayedEvents(changedTransactionDetail);
|
||||
dummyTasklet.execute(stepContribution, chunkContext);
|
||||
// then
|
||||
verify(businessEventNotifierService, Mockito.times(0)).startExternalEventRecording();
|
||||
verify(businessEventNotifierService, Mockito.times(1)).startExternalEventRecording();
|
||||
verify(businessEventNotifierService, Mockito.times(0))
|
||||
.notifyPostBusinessEvent(Mockito.any(LoanAdjustTransactionBusinessEvent.class));
|
||||
verify(businessEventNotifierService, Mockito.times(0)).stopExternalEventRecording();
|
||||
verify(businessEventNotifierService, Mockito.times(0)).resetEventRecording();
|
||||
verify(businessEventNotifierService, Mockito.times(1)).stopExternalEventRecording();
|
||||
verify(businessEventNotifierService, Mockito.times(1)).resetEventRecording();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhenParamHasNoMapping() {
|
||||
public void testWhenParamHasNoMapping() throws Exception {
|
||||
// given
|
||||
ChangedTransactionDetail changedTransactionDetail = new ChangedTransactionDetail();
|
||||
dummyTasklet.setChangedTransactionDetail(changedTransactionDetail);
|
||||
// when
|
||||
underTest.raiseTransactionReplayedEvents(changedTransactionDetail);
|
||||
dummyTasklet.execute(stepContribution, chunkContext);
|
||||
// then
|
||||
verify(businessEventNotifierService, Mockito.times(0)).startExternalEventRecording();
|
||||
verify(businessEventNotifierService, Mockito.times(1)).startExternalEventRecording();
|
||||
verify(businessEventNotifierService, Mockito.times(0))
|
||||
.notifyPostBusinessEvent(Mockito.any(LoanAdjustTransactionBusinessEvent.class));
|
||||
verify(businessEventNotifierService, Mockito.times(0)).stopExternalEventRecording();
|
||||
verify(businessEventNotifierService, Mockito.times(0)).resetEventRecording();
|
||||
verify(businessEventNotifierService, Mockito.times(1)).stopExternalEventRecording();
|
||||
verify(businessEventNotifierService, Mockito.times(1)).resetEventRecording();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhenParamHasOneNewTransaction() {
|
||||
public void testWhenParamHasOneNewTransaction() throws Exception {
|
||||
// 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
|
||||
underTest.raiseTransactionReplayedEvents(changedTransactionDetail);
|
||||
dummyTasklet.execute(stepContribution, chunkContext);
|
||||
// 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(0)).resetEventRecording();
|
||||
verify(businessEventNotifierService, Mockito.times(1)).resetEventRecording();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhenParamHasTwoNewTransaction() {
|
||||
public void testWhenParamHasTwoNewTransaction() throws Exception {
|
||||
// given
|
||||
LoanTransaction oldLoanTransaction = Mockito.mock(LoanTransaction.class);
|
||||
LoanTransaction newLoanTransaction = Mockito.mock(LoanTransaction.class);
|
||||
@@ -108,28 +119,29 @@ class ReplayedTransactionBusinessEventServiceIntegrationTest {
|
||||
ChangedTransactionDetail changedTransactionDetail = new ChangedTransactionDetail();
|
||||
changedTransactionDetail.getNewTransactionMappings().put(1L, newLoanTransaction);
|
||||
changedTransactionDetail.getNewTransactionMappings().put(2L, newLoanTransaction);
|
||||
dummyTasklet.setChangedTransactionDetail(changedTransactionDetail);
|
||||
// when
|
||||
underTest.raiseTransactionReplayedEvents(changedTransactionDetail);
|
||||
dummyTasklet.execute(stepContribution, chunkContext);
|
||||
// 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(0)).resetEventRecording();
|
||||
verify(businessEventNotifierService, Mockito.times(1)).resetEventRecording();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhenParamHasError() {
|
||||
// given
|
||||
doThrow(new RuntimeException()).when(businessEventNotifierService)
|
||||
.notifyPostBusinessEvent(Mockito.any(LoanAdjustTransactionBusinessEvent.class));
|
||||
doThrow(new RuntimeException()).when(businessEventNotifierService).notifyPostBusinessEvent(Mockito.any());
|
||||
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, () -> underTest.raiseTransactionReplayedEvents(changedTransactionDetail));
|
||||
assertThrows(RuntimeException.class, () -> dummyTasklet.execute(stepContribution, chunkContext));
|
||||
// then
|
||||
verify(businessEventNotifierService, Mockito.times(1)).startExternalEventRecording();
|
||||
verify(businessEventNotifierService, Mockito.times(1))
|
||||
|
||||
Reference in New Issue
Block a user