From 4e9ac48ad55a18d6400b337b07a665b4839fd1cb Mon Sep 17 00:00:00 2001 From: OZGCloud <ozgcloud@mgm-tp.com> Date: Tue, 8 Nov 2022 14:14:51 +0100 Subject: [PATCH] OZG-2966 OZG-3097 move pdfService call from controller to service --- .../postfach/PostfachMailController.java | 5 +-- .../postfach/PostfachMailPdfService.java | 2 +- .../goofy/postfach/PostfachMailService.java | 9 +++++ .../postfach/PostfachMailControllerTest.java | 4 +-- .../postfach/PostfachMailServiceTest.java | 34 ++++++++++++++++--- 5 files changed, 41 insertions(+), 13 deletions(-) diff --git a/goofy-server/src/main/java/de/itvsh/goofy/postfach/PostfachMailController.java b/goofy-server/src/main/java/de/itvsh/goofy/postfach/PostfachMailController.java index 198c8a1839..b4a05600b4 100644 --- a/goofy-server/src/main/java/de/itvsh/goofy/postfach/PostfachMailController.java +++ b/goofy-server/src/main/java/de/itvsh/goofy/postfach/PostfachMailController.java @@ -48,9 +48,6 @@ public class PostfachMailController { @Autowired private PostfachMailModelAssembler assembler; - @Autowired - private PostfachMailPdfService pdfService; - @Autowired private VorgangController vorgangController; @Autowired @@ -71,7 +68,7 @@ public class PostfachMailController { } StreamingResponseBody createDownloadStreamingBody(VorgangWithEingang vorgang) { - return out -> pdfService.getAllAsPdf(vorgang, out); + return out -> service.getAllAsPdf(vorgang, out); } ResponseEntity<StreamingResponseBody> buildResponseEntity(VorgangWithEingang vorgang, StreamingResponseBody responseBody) { diff --git a/goofy-server/src/main/java/de/itvsh/goofy/postfach/PostfachMailPdfService.java b/goofy-server/src/main/java/de/itvsh/goofy/postfach/PostfachMailPdfService.java index 1ad55c9cf3..db7b191919 100644 --- a/goofy-server/src/main/java/de/itvsh/goofy/postfach/PostfachMailPdfService.java +++ b/goofy-server/src/main/java/de/itvsh/goofy/postfach/PostfachMailPdfService.java @@ -24,7 +24,7 @@ class PostfachMailPdfService { @Value(PostfachMailPdfService.PDF_TEMPLATE_PATH) private Resource pdfTemplate; - public Object getAllAsPdf(VorgangWithEingang vorgang, OutputStream out) { + public OutputStream getAllAsPdf(VorgangWithEingang vorgang, OutputStream out) { return pdfService.createPdf(getTemplate(), out, buildModel(vorgang)); } diff --git a/goofy-server/src/main/java/de/itvsh/goofy/postfach/PostfachMailService.java b/goofy-server/src/main/java/de/itvsh/goofy/postfach/PostfachMailService.java index 93dadb6cc6..eca9c0c669 100644 --- a/goofy-server/src/main/java/de/itvsh/goofy/postfach/PostfachMailService.java +++ b/goofy-server/src/main/java/de/itvsh/goofy/postfach/PostfachMailService.java @@ -1,5 +1,6 @@ package de.itvsh.goofy.postfach; +import java.io.OutputStream; import java.util.Objects; import java.util.stream.Stream; @@ -7,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import de.itvsh.goofy.common.errorhandling.ResourceNotFoundException; +import de.itvsh.goofy.vorgang.VorgangWithEingang; import lombok.extern.log4j.Log4j2; @Log4j2 @@ -15,6 +17,9 @@ class PostfachMailService { private Boolean isPostfachConfigured = null; + @Autowired + private PostfachMailPdfService pdfService; + @Autowired private PostfachMailRemoteService remoteService; @@ -45,4 +50,8 @@ class PostfachMailService { } return isPostfachConfigured; } + + public OutputStream getAllAsPdf(VorgangWithEingang vorgang, OutputStream out) { + return pdfService.getAllAsPdf(vorgang, out); + } } \ No newline at end of file diff --git a/goofy-server/src/test/java/de/itvsh/goofy/postfach/PostfachMailControllerTest.java b/goofy-server/src/test/java/de/itvsh/goofy/postfach/PostfachMailControllerTest.java index 53bca991fa..1cc686bd0f 100644 --- a/goofy-server/src/test/java/de/itvsh/goofy/postfach/PostfachMailControllerTest.java +++ b/goofy-server/src/test/java/de/itvsh/goofy/postfach/PostfachMailControllerTest.java @@ -45,8 +45,6 @@ class PostfachMailControllerTest { @Mock private PostfachMailModelAssembler assembler; @Mock - private PostfachMailPdfService pdfService; - @Mock private VorgangController vorgangController; @Mock private BinaryFileController binaryFileController; @@ -119,7 +117,7 @@ class PostfachMailControllerTest { void shouldCallService() throws Exception { doRequest(); - verify(pdfService).getAllAsPdf(eq(vorgang), any(OutputStream.class)); + verify(service).getAllAsPdf(eq(vorgang), any(OutputStream.class)); } @Test diff --git a/goofy-server/src/test/java/de/itvsh/goofy/postfach/PostfachMailServiceTest.java b/goofy-server/src/test/java/de/itvsh/goofy/postfach/PostfachMailServiceTest.java index 4e14e58beb..54198f4649 100644 --- a/goofy-server/src/test/java/de/itvsh/goofy/postfach/PostfachMailServiceTest.java +++ b/goofy-server/src/test/java/de/itvsh/goofy/postfach/PostfachMailServiceTest.java @@ -1,9 +1,11 @@ package de.itvsh.goofy.postfach; +import static org.assertj.core.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; +import java.io.OutputStream; import java.util.Optional; import org.junit.jupiter.api.BeforeEach; @@ -13,19 +15,22 @@ import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import org.mockito.Mock; -import static org.assertj.core.api.Assertions.*; - import de.itvsh.goofy.common.command.CommandTestFactory; import de.itvsh.goofy.common.errorhandling.ResourceNotFoundException; import de.itvsh.goofy.vorgang.VorgangHeaderTestFactory; +import de.itvsh.goofy.vorgang.VorgangWithEingang; +import de.itvsh.goofy.vorgang.VorgangWithEingangTestFactory; class PostfachMailServiceTest { @InjectMocks // NOSONAR private PostfachMailService service; @Mock + private PostfachMailPdfService pdfService; + @Mock private PostfachMailRemoteService remoteService; + @DisplayName("Get all") @Nested class TestGetAll { @@ -37,6 +42,7 @@ class PostfachMailServiceTest { } } + @DisplayName("Find by id") @Nested class TestFindById { @@ -69,6 +75,7 @@ class PostfachMailServiceTest { } } + @DisplayName("Resend postfach mail") @Nested class TestResendPostfachMail { @@ -80,19 +87,19 @@ class PostfachMailServiceTest { } } + @DisplayName("Is postfach configured") @Nested class TestIsPostfachConfigured { @Test - void shouldCallRemoteService() { + void shouldCallRemoteServiceOnMissingProperty() { service.isPostfachConfigured(); verify(remoteService).isPostfachConfigured(); } - @DisplayName("if property is already set, no remoteservice call should be done") @Test - void shouldNotCallRemoteService() throws Exception { + void shouldNotCallRemoteServiceOnExistingProperty() throws Exception { setIsConfigured(); service.isPostfachConfigured(); @@ -106,4 +113,21 @@ class PostfachMailServiceTest { isPostfachConfigured.set(service, true); } } + + @DisplayName("Get all as pdf") + @Nested + class TestGetAllAsPdf { + + @Mock + private OutputStream outputStream; + + private final VorgangWithEingang vorgang = VorgangWithEingangTestFactory.create(); + + @Test + void shouldCallPdfService() { + service.getAllAsPdf(vorgang, outputStream); + + verify(pdfService).getAllAsPdf(vorgang, outputStream); + } + } } \ No newline at end of file -- GitLab