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

OZG-5322 outsource request to smartDocument

parent f563b5d0
No related branches found
No related tags found
No related merge requests found
......@@ -98,7 +98,8 @@ class BescheidEventListener {
void doCreateBescheid(Command command) {
if (isKielEnvironment()) {
doCreateBescheidBiz(command);
var bescheid = doCreateBescheidBiz(command);
nachrichtService.createNachrichtDraft(bescheid);
eventPublisher.publishEvent(new BescheidCreatedEvent(command));
return;
}
......@@ -111,12 +112,6 @@ class BescheidEventListener {
return smartDocumentsProperties.filter(configuredForKiel).isPresent();
}
void doCreateBescheidBiz(@NonNull Command command) {
var bescheid = service.createBescheid(createRequest(command));
bescheid = fileService.uploadBescheidFile(bescheid);
nachrichtService.createNachrichtDraft(bescheid);
}
BescheidRequest createRequest(Command command) {
var eventBody = command.getBodyObject();
var builder = BescheidRequest.builder();
......@@ -160,6 +155,12 @@ class BescheidEventListener {
void doCreateBescheidDocument(Command command) {
}
Bescheid doCreateBescheidBiz(@NonNull Command command) {
var bescheid = service.createBescheid(createRequest(command));
return fileService.uploadBescheidFile(bescheid);
}
void runWithSecurityContext(Command command, Consumer<Command> commandExecutor) {
SecurityContext prevContext = null;
try {
......
......@@ -109,6 +109,16 @@ class BescheidEventListenerTest {
verify(attachedItemService, never()).createBescheidDraft(any());
}
@Test
void shouldCallNachrichtService() {
var bescheid = BescheidTestFactory.create();
doReturn(bescheid).when(listener).doCreateBescheidBiz(any());
listener.doCreateBescheid(COMMAND);
verify(nachrichtService).createNachrichtDraft(bescheid);
}
@Test
void shouldPublishBescheidCreatedEvent() {
listener.doCreateBescheid(COMMAND);
......@@ -197,49 +207,6 @@ class BescheidEventListenerTest {
}
}
@Nested
class TestCreateBescheidBiz {
private Command command = CommandTestFactory.create();
@Test
void shouldCallCreateRequest() {
listener.doCreateBescheidBiz(command);
verify(listener).createRequest(command);
}
@Test
void shouldCallBescheidService() {
var bescheidRequest = BescheidRequestTestFactory.create();
doReturn(bescheidRequest).when(listener).createRequest(any());
listener.doCreateBescheidBiz(command);
verify(service).createBescheid(bescheidRequest);
}
@Test
void shouldCallFileService() {
var bescheid = BescheidTestFactory.create();
when(service.createBescheid(any())).thenReturn(bescheid);
listener.doCreateBescheidBiz(command);
verify(fileService).uploadBescheidFile(bescheid);
}
@Test
void shouldCallNachrichtService() {
var bescheid = BescheidTestFactory.create();
when(fileService.uploadBescheidFile(any())).thenReturn(bescheid);
listener.doCreateBescheidBiz(command);
verify(nachrichtService).createNachrichtDraft(bescheid);
}
}
@Nested
class TestCreateBescheidRequest {
......@@ -417,6 +384,49 @@ class BescheidEventListenerTest {
}
@Nested
class TestCreateBescheidBiz {
private Command command = CommandTestFactory.create();
@Test
void shouldCallCreateRequest() {
listener.doCreateBescheidBiz(command);
verify(listener).createRequest(command);
}
@Test
void shouldCallBescheidService() {
var bescheidRequest = BescheidRequestTestFactory.create();
doReturn(bescheidRequest).when(listener).createRequest(any());
listener.doCreateBescheidBiz(command);
verify(service).createBescheid(bescheidRequest);
}
@Test
void shouldCallFileService() {
var bescheid = BescheidTestFactory.create();
when(service.createBescheid(any())).thenReturn(bescheid);
listener.doCreateBescheidBiz(command);
verify(fileService).uploadBescheidFile(bescheid);
}
@Test
void shouldReturnBescheid() {
var bescheid = BescheidTestFactory.create();
when(fileService.uploadBescheidFile(any())).thenReturn(bescheid);
var result = listener.doCreateBescheidBiz(command);
assertThat(result).isSameAs(bescheid);
}
}
@Nested
class TestRunWithSecurityContext {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment