Skip to content
Snippets Groups Projects
Commit 38b39b44 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-5322 execute create_bescheid_document command

parent d0e5b43b
No related branches found
No related tags found
No related merge requests found
...@@ -44,6 +44,7 @@ import de.ozgcloud.bescheid.vorgang.VorgangId; ...@@ -44,6 +44,7 @@ import de.ozgcloud.bescheid.vorgang.VorgangId;
import de.ozgcloud.command.Command; import de.ozgcloud.command.Command;
import de.ozgcloud.command.CommandCreatedEvent; import de.ozgcloud.command.CommandCreatedEvent;
import de.ozgcloud.command.CommandFailedEvent; import de.ozgcloud.command.CommandFailedEvent;
import de.ozgcloud.document.BescheidDocumentCreatedEvent;
import de.ozgcloud.document.DocumentService; import de.ozgcloud.document.DocumentService;
import lombok.NonNull; import lombok.NonNull;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
...@@ -153,6 +154,9 @@ class BescheidEventListener { ...@@ -153,6 +154,9 @@ class BescheidEventListener {
} }
void doCreateBescheidDocument(Command command) { void doCreateBescheidDocument(Command command) {
var bescheid = doCreateBescheidBiz(command);
var bescheidDocument = documentService.createBescheidDocument(command, bescheid);
eventPublisher.publishEvent(new BescheidDocumentCreatedEvent(command, bescheidDocument));
} }
Bescheid doCreateBescheidBiz(@NonNull Command command) { Bescheid doCreateBescheidBiz(@NonNull Command command) {
......
...@@ -34,6 +34,7 @@ import de.ozgcloud.command.Command; ...@@ -34,6 +34,7 @@ import de.ozgcloud.command.Command;
import de.ozgcloud.command.CommandCreatedEventTestFactory; import de.ozgcloud.command.CommandCreatedEventTestFactory;
import de.ozgcloud.command.CommandFailedEvent; import de.ozgcloud.command.CommandFailedEvent;
import de.ozgcloud.command.CommandTestFactory; import de.ozgcloud.command.CommandTestFactory;
import de.ozgcloud.document.BescheidDocumentCreatedEvent;
import de.ozgcloud.document.DocumentService; import de.ozgcloud.document.DocumentService;
class BescheidEventListenerTest { class BescheidEventListenerTest {
...@@ -380,8 +381,51 @@ class BescheidEventListenerTest { ...@@ -380,8 +381,51 @@ class BescheidEventListenerTest {
@Nested @Nested
class TestDoCreateBescheidDocument { class TestDoCreateBescheidDocument {
private Command command = CommandTestFactory.create(); private static final Command COMMAND = CommandTestFactory.create();
private static final Bescheid BESCHEID = BescheidTestFactory.create();
@Captor
private ArgumentCaptor<BescheidDocumentCreatedEvent> eventCaptor;
@BeforeEach
void init() {
doReturn(BESCHEID).when(listener).doCreateBescheidBiz(any());
}
@Test
void shouldCallCreateBescheidBiz() {
listener.doCreateBescheidDocument(COMMAND);
verify(listener).doCreateBescheidBiz(COMMAND);
}
@Test
void shouldCallCreateBescheidDocument() {
listener.doCreateBescheidDocument(COMMAND);
verify(documentService).createBescheidDocument(COMMAND, BESCHEID);
}
@Test
@DisplayName("should publish BescheidDocumentCreatedEvent with command")
void shouldPublishEventWithCommand() {
listener.doCreateBescheidDocument(COMMAND);
verify(eventPublisher).publishEvent(eventCaptor.capture());
assertThat(eventCaptor.getValue().getCommand()).isEqualTo(COMMAND);
}
@Test
@DisplayName("should publish BescheidDocumentCreatedEvent with createdResource")
void shouldPublishEventWithCreatedResource() {
var bescheidDocument = "document-id";
when(documentService.createBescheidDocument(any(), any(Bescheid.class))).thenReturn(bescheidDocument);
listener.doCreateBescheidDocument(COMMAND);
verify(eventPublisher).publishEvent(eventCaptor.capture());
assertThat(eventCaptor.getValue().getCreatedResource()).isEqualTo(bescheidDocument);
}
} }
@Nested @Nested
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment