FINERACT-1694: Extending MessageV1 and BulkMessageV1 with businessDate + fixing bulk event handling for publication + mapstruct mapper fixes to be more strict

This commit is contained in:
Arnold Galovics
2022-10-21 11:43:27 +02:00
committed by Arnold Gálovics
parent d1f3ffe490
commit 81d9e4a961
20 changed files with 172 additions and 116 deletions
@@ -109,7 +109,7 @@ public class BusinessDateValidatorTest {
}
@Test
public void validateAndParseUpdateWithRighDate() {
public void validateAndParseUpdateWithRightDate() {
String json = "{\"type\":\"COB_DATE\", \"locale\":\"hu\",\"dateFormat\":\"yyyy-MM-dd\",\"date\":\"2022-06-11\"}";
JsonCommand command = JsonCommand.from(json);
BusinessDateData result = businessDateDataParserAndValidator.validateAndParseUpdate(command);
@@ -19,8 +19,10 @@
package org.apache.fineract.infrastructure.event.business.service;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
@@ -93,7 +95,20 @@ class BusinessEventNotifierServiceImplTest {
}
@Test
public void testNotifyPostBusinessEventShouldNotifyPostListenersAndPostAnBulkExternalEventWhenRecordingEnabled() {
public void testNotifyPostBusinessEventShouldNotPostAnythingWhenNoEventWasRaisedExternalEventWhenRecordingEnabled() {
// given
configureExternalEventsProperties(true);
when(externalEventConfigurationRepository.findExternalEventConfigurationByTypeWithNotFoundDetection(Mockito.any()))
.thenReturn(new ExternalEventConfiguration("aType", true));
underTest.startExternalEventRecording();
// when
underTest.stopExternalEventRecording();
// then
verify(externalEventService, never()).postEvent(any());
}
@Test
public void testNotifyPostBusinessEventShouldNotifyPostListenersAndPostARegularExternalEventWhenRecordingEnabled() {
// given
configureExternalEventsProperties(true);
when(externalEventConfigurationRepository.findExternalEventConfigurationByTypeWithNotFoundDetection(Mockito.any()))
@@ -107,12 +122,34 @@ class BusinessEventNotifierServiceImplTest {
underTest.stopExternalEventRecording();
// then
verify(postListener).onBusinessEvent(event);
verify(externalEventService).postEvent(event);
}
@Test
public void testNotifyPostBusinessEventShouldNotifyPostListenersAndPostAnBulkExternalEventWhenRecordingEnabled() {
// given
configureExternalEventsProperties(true);
when(externalEventConfigurationRepository.findExternalEventConfigurationByTypeWithNotFoundDetection(Mockito.any()))
.thenReturn(new ExternalEventConfiguration("aType", true));
MockBusinessEvent event = new MockBusinessEvent();
MockBusinessEvent event2 = new MockBusinessEvent();
BusinessEventListener<MockBusinessEvent> postListener = mockListener();
underTest.addPostBusinessEventListener(MockBusinessEvent.class, postListener);
underTest.startExternalEventRecording();
underTest.notifyPostBusinessEvent(event);
underTest.notifyPostBusinessEvent(event2);
// when
underTest.stopExternalEventRecording();
// then
verify(postListener).onBusinessEvent(event);
verify(postListener).onBusinessEvent(event2);
ArgumentCaptor<BulkBusinessEvent> argumentCaptor = ArgumentCaptor.forClass(BulkBusinessEvent.class);
verify(externalEventService).postEvent(argumentCaptor.capture());
BulkBusinessEvent capturedEvent = argumentCaptor.getValue();
assertThat(capturedEvent.get()).hasSize(1);
assertThat(capturedEvent.get()).hasSize(2);
assertThat(capturedEvent.get().get(0)).isEqualTo(event);
assertThat(capturedEvent.get().get(1)).isEqualTo(event2);
}
@Test
@@ -102,11 +102,11 @@ class SendAsynchronousEventsTaskletTest {
@Test
public void givenBatchSize2WhenTaskExecutionThenSend2Events() throws Exception {
// given
List<ExternalEvent> events = Arrays.asList(new ExternalEvent("aType", "aCategory", "aSchema", new byte[0], "aIdemtpotencyKey"),
new ExternalEvent("aType", "aCategory", "aSchema", new byte[0], "aIdemtpotencyKey"));
List<ExternalEvent> events = Arrays.asList(new ExternalEvent("aType", "aCategory", "aSchema", new byte[0], "aIdempotencyKey"),
new ExternalEvent("aType", "aCategory", "aSchema", new byte[0], "aIdempotencyKey"));
// Dummy Message
MessageV1 dummyMessage = new MessageV1(1, "aSource", "aType", "nocategory", "aCreateDate", "aTennantId", "anidempotencyKey",
"aSchema", Mockito.mock(ByteBuffer.class));
MessageV1 dummyMessage = new MessageV1(1, "aSource", "aType", "nocategory", "aCreateDate", "aBusinessDate", "aTenantId",
"anidempotencyKey", "aSchema", Mockito.mock(ByteBuffer.class));
when(repository.findByStatusOrderById(Mockito.any(), Mockito.any())).thenReturn(events);
when(messageFactory.createMessage(Mockito.any())).thenReturn(dummyMessage);
@@ -123,10 +123,10 @@ class SendAsynchronousEventsTaskletTest {
@Test
public void givenBatchSize2WhenEventSendFailsThenExecutionStops() throws Exception {
// given
List<ExternalEvent> events = Arrays.asList(new ExternalEvent("aType", "aCategory", "aSchema", new byte[0], "aIdemtpotencyKey"),
new ExternalEvent("aType", "aCategory", "aSchema", new byte[0], "aIdemtpotencyKey"));
MessageV1 dummyMessage = new MessageV1(1, "aSource", "aType", "nocategory", "aCreateDate", "aTennantId", "anidempotencyKey",
"aSchema", Mockito.mock(ByteBuffer.class));
List<ExternalEvent> events = Arrays.asList(new ExternalEvent("aType", "aCategory", "aSchema", new byte[0], "aIdempotencyKey"),
new ExternalEvent("aType", "aCategory", "aSchema", new byte[0], "aIdempotencyKey"));
MessageV1 dummyMessage = new MessageV1(1, "aSource", "aType", "nocategory", "aCreateDate", "aBusinessDate", "aTenantId",
"anidempotencyKey", "aSchema", Mockito.mock(ByteBuffer.class));
when(repository.findByStatusOrderById(Mockito.any(), Mockito.any())).thenReturn(events);
when(messageFactory.createMessage(Mockito.any())).thenReturn(dummyMessage);
when(byteBufferConverter.convert(Mockito.any(ByteBuffer.class))).thenReturn(new byte[0]);
@@ -143,9 +143,9 @@ class SendAsynchronousEventsTaskletTest {
public void givenOneEventWhenEventSentThenEventStatusUpdates() throws Exception {
// given
ArgumentCaptor<ExternalEvent> externalEventArgumentCaptor = ArgumentCaptor.forClass(ExternalEvent.class);
List<ExternalEvent> events = Arrays.asList(new ExternalEvent("aType", "aCategory", "aSchema", new byte[0], "aIdemtpotencyKey"));
MessageV1 dummyMessage = new MessageV1(1, "aSource", "aType", "nocategory", "aCreateDate", "aTennantId", "anidempotencyKey",
"aSchema", Mockito.mock(ByteBuffer.class));
List<ExternalEvent> events = Arrays.asList(new ExternalEvent("aType", "aCategory", "aSchema", new byte[0], "aIdempotencyKey"));
MessageV1 dummyMessage = new MessageV1(1, "aSource", "aType", "nocategory", "aCreateDate", "aBusinessDate", "aTenantId",
"anidempotencyKey", "aSchema", Mockito.mock(ByteBuffer.class));
when(repository.findByStatusOrderById(Mockito.any(), Mockito.any())).thenReturn(events);
when(messageFactory.createMessage(Mockito.any())).thenReturn(dummyMessage);
when(byteBufferConverter.convert(Mockito.any(ByteBuffer.class))).thenReturn(new byte[0]);
@@ -153,10 +153,10 @@ class SendAsynchronousEventsTaskletTest {
// when
resultStatus = this.underTest.execute(stepContribution, chunkContext);
// then
verify(messageFactory).createMessage(Mockito.any());
verify(repository).save(externalEventArgumentCaptor.capture());
ExternalEvent externalEvent = externalEventArgumentCaptor.getValue();
assertThat(externalEvent.getStatus()).isEqualTo(ExternalEventStatus.SENT);
assertEquals(RepeatStatus.FINISHED, resultStatus);
}
}