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

OZG-2966 OZG-3097 move pdfService call from controller to service

parent a517fbd2
Branches
Tags
No related merge requests found
...@@ -48,9 +48,6 @@ public class PostfachMailController { ...@@ -48,9 +48,6 @@ public class PostfachMailController {
@Autowired @Autowired
private PostfachMailModelAssembler assembler; private PostfachMailModelAssembler assembler;
@Autowired
private PostfachMailPdfService pdfService;
@Autowired @Autowired
private VorgangController vorgangController; private VorgangController vorgangController;
@Autowired @Autowired
...@@ -71,7 +68,7 @@ public class PostfachMailController { ...@@ -71,7 +68,7 @@ public class PostfachMailController {
} }
StreamingResponseBody createDownloadStreamingBody(VorgangWithEingang vorgang) { StreamingResponseBody createDownloadStreamingBody(VorgangWithEingang vorgang) {
return out -> pdfService.getAllAsPdf(vorgang, out); return out -> service.getAllAsPdf(vorgang, out);
} }
ResponseEntity<StreamingResponseBody> buildResponseEntity(VorgangWithEingang vorgang, StreamingResponseBody responseBody) { ResponseEntity<StreamingResponseBody> buildResponseEntity(VorgangWithEingang vorgang, StreamingResponseBody responseBody) {
......
...@@ -24,7 +24,7 @@ class PostfachMailPdfService { ...@@ -24,7 +24,7 @@ class PostfachMailPdfService {
@Value(PostfachMailPdfService.PDF_TEMPLATE_PATH) @Value(PostfachMailPdfService.PDF_TEMPLATE_PATH)
private Resource pdfTemplate; private Resource pdfTemplate;
public Object getAllAsPdf(VorgangWithEingang vorgang, OutputStream out) { public OutputStream getAllAsPdf(VorgangWithEingang vorgang, OutputStream out) {
return pdfService.createPdf(getTemplate(), out, buildModel(vorgang)); return pdfService.createPdf(getTemplate(), out, buildModel(vorgang));
} }
......
package de.itvsh.goofy.postfach; package de.itvsh.goofy.postfach;
import java.io.OutputStream;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Stream; import java.util.stream.Stream;
...@@ -7,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -7,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import de.itvsh.goofy.common.errorhandling.ResourceNotFoundException; import de.itvsh.goofy.common.errorhandling.ResourceNotFoundException;
import de.itvsh.goofy.vorgang.VorgangWithEingang;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
@Log4j2 @Log4j2
...@@ -15,6 +17,9 @@ class PostfachMailService { ...@@ -15,6 +17,9 @@ class PostfachMailService {
private Boolean isPostfachConfigured = null; private Boolean isPostfachConfigured = null;
@Autowired
private PostfachMailPdfService pdfService;
@Autowired @Autowired
private PostfachMailRemoteService remoteService; private PostfachMailRemoteService remoteService;
...@@ -45,4 +50,8 @@ class PostfachMailService { ...@@ -45,4 +50,8 @@ class PostfachMailService {
} }
return isPostfachConfigured; return isPostfachConfigured;
} }
public OutputStream getAllAsPdf(VorgangWithEingang vorgang, OutputStream out) {
return pdfService.getAllAsPdf(vorgang, out);
}
} }
\ No newline at end of file
...@@ -45,8 +45,6 @@ class PostfachMailControllerTest { ...@@ -45,8 +45,6 @@ class PostfachMailControllerTest {
@Mock @Mock
private PostfachMailModelAssembler assembler; private PostfachMailModelAssembler assembler;
@Mock @Mock
private PostfachMailPdfService pdfService;
@Mock
private VorgangController vorgangController; private VorgangController vorgangController;
@Mock @Mock
private BinaryFileController binaryFileController; private BinaryFileController binaryFileController;
...@@ -119,7 +117,7 @@ class PostfachMailControllerTest { ...@@ -119,7 +117,7 @@ class PostfachMailControllerTest {
void shouldCallService() throws Exception { void shouldCallService() throws Exception {
doRequest(); doRequest();
verify(pdfService).getAllAsPdf(eq(vorgang), any(OutputStream.class)); verify(service).getAllAsPdf(eq(vorgang), any(OutputStream.class));
} }
@Test @Test
......
package de.itvsh.goofy.postfach; package de.itvsh.goofy.postfach;
import static org.assertj.core.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*; import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import java.io.OutputStream;
import java.util.Optional; import java.util.Optional;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
...@@ -13,19 +15,22 @@ import org.junit.jupiter.api.Test; ...@@ -13,19 +15,22 @@ import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.Mock; import org.mockito.Mock;
import static org.assertj.core.api.Assertions.*;
import de.itvsh.goofy.common.command.CommandTestFactory; import de.itvsh.goofy.common.command.CommandTestFactory;
import de.itvsh.goofy.common.errorhandling.ResourceNotFoundException; import de.itvsh.goofy.common.errorhandling.ResourceNotFoundException;
import de.itvsh.goofy.vorgang.VorgangHeaderTestFactory; import de.itvsh.goofy.vorgang.VorgangHeaderTestFactory;
import de.itvsh.goofy.vorgang.VorgangWithEingang;
import de.itvsh.goofy.vorgang.VorgangWithEingangTestFactory;
class PostfachMailServiceTest { class PostfachMailServiceTest {
@InjectMocks // NOSONAR @InjectMocks // NOSONAR
private PostfachMailService service; private PostfachMailService service;
@Mock @Mock
private PostfachMailPdfService pdfService;
@Mock
private PostfachMailRemoteService remoteService; private PostfachMailRemoteService remoteService;
@DisplayName("Get all")
@Nested @Nested
class TestGetAll { class TestGetAll {
...@@ -37,6 +42,7 @@ class PostfachMailServiceTest { ...@@ -37,6 +42,7 @@ class PostfachMailServiceTest {
} }
} }
@DisplayName("Find by id")
@Nested @Nested
class TestFindById { class TestFindById {
...@@ -69,6 +75,7 @@ class PostfachMailServiceTest { ...@@ -69,6 +75,7 @@ class PostfachMailServiceTest {
} }
} }
@DisplayName("Resend postfach mail")
@Nested @Nested
class TestResendPostfachMail { class TestResendPostfachMail {
...@@ -80,19 +87,19 @@ class PostfachMailServiceTest { ...@@ -80,19 +87,19 @@ class PostfachMailServiceTest {
} }
} }
@DisplayName("Is postfach configured")
@Nested @Nested
class TestIsPostfachConfigured { class TestIsPostfachConfigured {
@Test @Test
void shouldCallRemoteService() { void shouldCallRemoteServiceOnMissingProperty() {
service.isPostfachConfigured(); service.isPostfachConfigured();
verify(remoteService).isPostfachConfigured(); verify(remoteService).isPostfachConfigured();
} }
@DisplayName("if property is already set, no remoteservice call should be done")
@Test @Test
void shouldNotCallRemoteService() throws Exception { void shouldNotCallRemoteServiceOnExistingProperty() throws Exception {
setIsConfigured(); setIsConfigured();
service.isPostfachConfigured(); service.isPostfachConfigured();
...@@ -106,4 +113,21 @@ class PostfachMailServiceTest { ...@@ -106,4 +113,21 @@ class PostfachMailServiceTest {
isPostfachConfigured.set(service, true); 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment