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 198c8a1839d3df37b8e2df80a826f23b01001618..b4a05600b45ab52eeb402efc62a70856490e5d49 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 1ad55c9cf3f692ecf3f69943886e3509d1ef795f..db7b191919a5658a4b2558d4336b00871cd7fda9 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 93dadb6cc66b19d0ef41318fb960a171e1152ba9..eca9c0c669d6d5dd651d82d1297803a926a681d3 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 53bca991fa716be939afeeaf17b24f3ad3d0b83e..1cc686bd0f92030621737879206e2dec1a6a4730 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 4e14e58beb7119298c477c241417a81cf375a985..54198f4649c50df4264c9e03967a3663c99e4977 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