diff --git a/src/main/java/de/ozgcloud/processor/processor/ProcessorEventListener.java b/src/main/java/de/ozgcloud/processor/processor/ProcessorEventListener.java index 21b0b117a60d998a3dede794eacc7799d58f6ce7..adaf932520d71d540caf54dc31fcedf655e06778 100644 --- a/src/main/java/de/ozgcloud/processor/processor/ProcessorEventListener.java +++ b/src/main/java/de/ozgcloud/processor/processor/ProcessorEventListener.java @@ -51,11 +51,6 @@ class ProcessorEventListener { handleError(e, event.getSource()); } } - - private void handleError(Throwable cause, String vorgangId) { - LOG.error("Error on procession Vorgang {} externally", vorgangId, cause); - resultService.processError(cause, vorgangId); - } @EventListener(condition = IS_EXECUTE_PROCESSOR) public void onCommandExecuteProcessor(CommandCreatedEvent event) { @@ -88,11 +83,16 @@ class ProcessorEventListener { return result.toBuilder().vorgangId(VorgangId.from(vorgangId)).build(); } - void publishCommandFailedEvent(Throwable e, String commandId) { - publisher.publishEvent(new CommandFailedEvent(commandId, e.getMessage())); + private void handleError(Throwable cause, String vorgangId) { + LOG.error("Error on procession Vorgang {} externally", vorgangId, cause); + resultService.processError(cause, vorgangId); } void publishCommandProcessedEvent(Command command) { publisher.publishEvent(new CommandProcessedEvent(command)); } + + void publishCommandFailedEvent(Throwable e, String commandId) { + publisher.publishEvent(new CommandFailedEvent(commandId, e.getMessage())); + } } \ No newline at end of file diff --git a/src/test/java/de/ozgcloud/processor/processor/ProcessorEventListenerTest.java b/src/test/java/de/ozgcloud/processor/processor/ProcessorEventListenerTest.java index 49ebd9fccf6809860c2967b97b9493786c5c1b09..e50d8ea938a85485743ef4257af25f7b56135c8a 100644 --- a/src/test/java/de/ozgcloud/processor/processor/ProcessorEventListenerTest.java +++ b/src/test/java/de/ozgcloud/processor/processor/ProcessorEventListenerTest.java @@ -5,12 +5,12 @@ import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.stream.Stream; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -210,14 +210,20 @@ class ProcessorEventListenerTest { } } - @Disabled("FIXME: Er geht nicht in den catch block rein") @DisplayName("On ViolationConstraint exception") @Nested class TestOnViolationConstraintException { + private final Mono<ProcessorResult> processorResults = Mono.just(ProcessorResultTestFactory.create()); + private final Stream<Mono<ProcessorResult>> monoStream = Stream.of(processorResults); + private final ConstraintViolationException exception = new ConstraintViolationException("", Collections.emptySet()); + @BeforeEach void init(){ - doThrow(ConstraintViolationException.class).when(resultService).processResult(any()); + when(vorgangService.getVorgang(any())).thenReturn(vorgang); + when(processorService.processVorgang(any(), any())).thenReturn(monoStream); + doThrow(exception).when(vorgangEventListener).processResult(any(), any()); + doNothing().when(vorgangEventListener).publishCommandFailedEvent(any(), any()); } @Test