Search in sources :

Example 1 with BridgeErrorService

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);
    }
}
Also used : BridgeErrorService(com.redhat.service.smartevents.infra.exceptions.BridgeErrorService) RecordHeaders(org.apache.kafka.common.header.internals.RecordHeaders) ExecutorTestUtils.createCloudEventString(com.redhat.service.smartevents.executor.ExecutorTestUtils.createCloudEventString) Assertions.assertThatNoException(org.assertj.core.api.Assertions.assertThatNoException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) CloudEvent(io.cloudevents.CloudEvent) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ExecutorTestUtils.createCloudEventString (com.redhat.service.smartevents.executor.ExecutorTestUtils.createCloudEventString)1 BridgeErrorService (com.redhat.service.smartevents.infra.exceptions.BridgeErrorService)1 CloudEvent (io.cloudevents.CloudEvent)1 RecordHeaders (org.apache.kafka.common.header.internals.RecordHeaders)1 Assertions.assertThatNoException (org.assertj.core.api.Assertions.assertThatNoException)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1