use of com.redhat.service.smartevents.infra.exceptions.BridgeErrorService in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ExecutorServiceTest method test.
@ParameterizedTest
@MethodSource("executorServiceTestArgs")
@SuppressWarnings("unchecked")
void test(ProcessorDTO processor, String inputEvent, VerificationMode wantedNumberOfOnEventInvocations, URI expectedCloudEventSource, String expectedCloudEventType, boolean ack) {
Executor executorMock = mock(Executor.class);
when(executorMock.getProcessor()).thenReturn(processor);
BridgeErrorService bridgeErrorServiceMock = mock(BridgeErrorService.class);
when(bridgeErrorServiceMock.getError(any(Exception.class))).thenReturn(Optional.empty());
ExecutorService executorService = new ExecutorService();
executorService.executor = executorMock;
executorService.mapper = new ObjectMapper();
executorService.bridgeErrorService = bridgeErrorServiceMock;
KafkaRecord<Integer, String> inputMessage = mock(KafkaRecord.class);
when(inputMessage.getPayload()).thenReturn(inputEvent);
when(inputMessage.getHeaders()).thenReturn(new RecordHeaders());
when(inputMessage.getKey()).thenReturn(555);
ArgumentCaptor<CloudEvent> argumentCaptor = ArgumentCaptor.forClass(CloudEvent.class);
assertThatNoException().isThrownBy(() -> executorService.processEvent(inputMessage));
verify(executorMock, wantedNumberOfOnEventInvocations).onEvent(argumentCaptor.capture(), any());
verify(inputMessage, times(ack ? 1 : 0)).ack();
verify(inputMessage, times(ack ? 0 : 1)).nack(any(), any());
if (!argumentCaptor.getAllValues().isEmpty()) {
CloudEvent capturedEvent = argumentCaptor.getValue();
assertThat(capturedEvent.getSource()).isEqualTo(expectedCloudEventSource);
assertThat(capturedEvent.getType()).isEqualTo(expectedCloudEventType);
}
}
Aggregations