Skip to content
Snippets Groups Projects
Commit 904e2571 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-6991 publish command executed event

parent 3e3f4de4
Branches
Tags
No related merge requests found
...@@ -36,6 +36,7 @@ import de.ozgcloud.command.CommandCreatedEvent; ...@@ -36,6 +36,7 @@ import de.ozgcloud.command.CommandCreatedEvent;
import de.ozgcloud.command.CommandExecutedEvent; import de.ozgcloud.command.CommandExecutedEvent;
import de.ozgcloud.command.CommandFailedEvent; import de.ozgcloud.command.CommandFailedEvent;
import de.ozgcloud.command.CommandRevokeFailedEvent; import de.ozgcloud.command.CommandRevokeFailedEvent;
import de.ozgcloud.command.CommandRevokedEvent;
import de.ozgcloud.command.RevokeCommandEvent; import de.ozgcloud.command.RevokeCommandEvent;
import de.ozgcloud.vorgang.command.CommandService; import de.ozgcloud.vorgang.command.CommandService;
import de.ozgcloud.vorgang.command.Order; import de.ozgcloud.vorgang.command.Order;
...@@ -132,6 +133,7 @@ public class VorgangEventListener { ...@@ -132,6 +133,7 @@ public class VorgangEventListener {
var command = event.getSource(); var command = event.getSource();
try { try {
vorgangService.unlockVorgang(command); vorgangService.unlockVorgang(command);
publisher.publishEvent(new CommandRevokedEvent(command));
} catch (RuntimeException e) { } catch (RuntimeException e) {
LOG.error("Error unlocking vorgang.", e); LOG.error("Error unlocking vorgang.", e);
publisher.publishEvent(new CommandRevokeFailedEvent(command.getId(), e.getMessage())); publisher.publishEvent(new CommandRevokeFailedEvent(command.getId(), e.getMessage()));
......
...@@ -47,6 +47,7 @@ import de.ozgcloud.command.Command; ...@@ -47,6 +47,7 @@ import de.ozgcloud.command.Command;
import de.ozgcloud.command.CommandExecutedEvent; import de.ozgcloud.command.CommandExecutedEvent;
import de.ozgcloud.command.CommandFailedEvent; import de.ozgcloud.command.CommandFailedEvent;
import de.ozgcloud.command.CommandRevokeFailedEvent; import de.ozgcloud.command.CommandRevokeFailedEvent;
import de.ozgcloud.command.CommandRevokedEvent;
import de.ozgcloud.command.RevokeCommandEvent; import de.ozgcloud.command.RevokeCommandEvent;
import de.ozgcloud.common.errorhandling.TechnicalException; import de.ozgcloud.common.errorhandling.TechnicalException;
import de.ozgcloud.vorgang.command.CommandCreatedEventTestFactory; import de.ozgcloud.vorgang.command.CommandCreatedEventTestFactory;
...@@ -268,7 +269,9 @@ class VorgangEventListenerTest { ...@@ -268,7 +269,9 @@ class VorgangEventListenerTest {
class TestRevokeLockVorgang { class TestRevokeLockVorgang {
@Captor @Captor
private ArgumentCaptor<CommandRevokeFailedEvent> eventCaptor; private ArgumentCaptor<CommandRevokedEvent> commandRevokedEventCaptor;
@Captor
private ArgumentCaptor<CommandRevokeFailedEvent> commandRevokeFailedEventCaptor;
@Test @Test
void shouldCallUnlockVorgang() { void shouldCallUnlockVorgang() {
...@@ -279,6 +282,16 @@ class VorgangEventListenerTest { ...@@ -279,6 +282,16 @@ class VorgangEventListenerTest {
verify(service).unlockVorgang(command); verify(service).unlockVorgang(command);
} }
@Test
void shouldPublishCommandRevokedEvent() {
var command = CommandTestFactory.create();
listener.onRevokeLockVorgang(new RevokeCommandEvent(command));
verify(publisher).publishEvent(commandRevokedEventCaptor.capture());
assertThat(commandRevokedEventCaptor.getValue().getSource()).isSameAs(command);
}
@Test @Test
void shouldPublishCommandFailedEvent() { void shouldPublishCommandFailedEvent() {
var command = CommandTestFactory.create(); var command = CommandTestFactory.create();
...@@ -287,8 +300,8 @@ class VorgangEventListenerTest { ...@@ -287,8 +300,8 @@ class VorgangEventListenerTest {
listener.onRevokeLockVorgang(new RevokeCommandEvent(command)); listener.onRevokeLockVorgang(new RevokeCommandEvent(command));
verify(publisher).publishEvent(eventCaptor.capture()); verify(publisher).publishEvent(commandRevokeFailedEventCaptor.capture());
assertThat(eventCaptor.getValue()).satisfies(event -> { assertThat(commandRevokeFailedEventCaptor.getValue()).satisfies(event -> {
assertThat(event.getSource()).isEqualTo(CommandTestFactory.ID); assertThat(event.getSource()).isEqualTo(CommandTestFactory.ID);
assertThat(event.getErrorMessage()).isEqualTo(errorMessage); assertThat(event.getErrorMessage()).isEqualTo(errorMessage);
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment