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

OZG-5665 Added BescheidDocument to fioles in xDomea Bescheid Export

parent e5d71f46
Branches
Tags
No related merge requests found
......@@ -3,6 +3,8 @@ package de.ozgcloud.alfa.bescheid;
import java.util.List;
import de.ozgcloud.alfa.common.file.OzgFile;
import lombok.Builder;
@Builder
record BescheidExportInput(Bescheid bescheid, String organisationseinheitenId, List<OzgFile> files) {
}
package de.ozgcloud.alfa.bescheid;
import java.util.List;
import java.util.stream.Stream;
import org.springframework.stereotype.Service;
......@@ -32,16 +31,18 @@ public class ExportBescheidService {
}
BescheidExportInput createBescheidExportInput(Bescheid bescheid, VorgangWithEingang vorgang) {
return new BescheidExportInput(bescheid, vorgang.getOrganisationseinheitenID(), getAttachments(bescheid));
return BescheidExportInput.builder()
.bescheid(bescheid)
.organisationseinheitenId(vorgang.getOrganisationseinheitenID())
.files(Stream.concat(Stream.of(getDocument(bescheid)), getAttachments(bescheid)).toList()).build();
}
List<OzgFile> getAttachments(Bescheid bescheid) {
return binaryFileService.getFiles(bescheid.getAttachments()).toList();
Stream<OzgFile> getAttachments(Bescheid bescheid) {
return binaryFileService.getFiles(bescheid.getAttachments());
}
void addBescheidExportData(BescheidExportInput input, BescheidExportData.BescheidExportDataBuilder builder) {
builder.dokumentType(buildDokumentType(input))
.file(getDocument(input.bescheid()))
.files(input.files());
}
......
......@@ -10,10 +10,17 @@ public class BescheidExportInputTestFactory {
public final static Bescheid BESCHEID = BescheidTestFactory.create();
public final static String ORGANISATIONSEINHEITEN_ID = ZustaendigeStelleTestFactory.ORGANISATIONSEINHEITEN_ID;
public final static List<OzgFile> ATTACHMENTS = List.of(OzgFileTestFactory.createWithUniqueId());
public final static List<OzgFile> FILES = List.of(OzgFileTestFactory.createWithUniqueId());
public static BescheidExportInput create() {
return new BescheidExportInput(BESCHEID, ORGANISATIONSEINHEITEN_ID, ATTACHMENTS);
return createBuilder().build();
}
public static BescheidExportInput.BescheidExportInputBuilder createBuilder() {
return BescheidExportInput.builder()
.bescheid(BESCHEID)
.organisationseinheitenId(ORGANISATIONSEINHEITEN_ID)
.files(FILES);
}
}
......@@ -154,10 +154,13 @@ class ExportBescheidServiceTest {
class TestCreateBescheidExportInput {
private final VorgangWithEingang vorgang = VorgangWithEingangTestFactory.create();
private final Bescheid bescheid = BescheidTestFactory.create();
private final OzgFile document = OzgFileTestFactory.create();
private final OzgFile attachment = OzgFileTestFactory.create();
@BeforeEach
void setUpMocks() {
doReturn(BescheidExportInputTestFactory.ATTACHMENTS).when(service).getAttachments(bescheid);
doReturn(Stream.of(attachment)).when(service).getAttachments(bescheid);
doReturn(document).when(service).getDocument(bescheid);
}
@Test
......@@ -167,11 +170,19 @@ class ExportBescheidServiceTest {
verify(service).getAttachments(bescheid);
}
@Test
void shouldCallGetDocument() {
callService();
verify(service).getDocument(bescheid);
}
@Test
void shouldReturnInputData() {
var resultInput = callService();
assertThat(resultInput).usingRecursiveComparison().isEqualTo(BescheidExportInputTestFactory.create());
assertThat(resultInput).usingRecursiveComparison()
.isEqualTo(BescheidExportInputTestFactory.createBuilder().files(List.of(document, attachment)).build());
}
private BescheidExportInput callService() {
......@@ -243,7 +254,7 @@ class ExportBescheidServiceTest {
@Nested
class TestAddBescheidExportData {
private final List<OzgFile> attachments = BescheidExportInputTestFactory.ATTACHMENTS;
private final List<OzgFile> files = BescheidExportInputTestFactory.FILES;
private final OzgFile document = OzgFileTestFactory.create();
private final DokumentType dokumentType = DokumentTypeTestFactory.create();
private final BescheidExportInput exportInput = BescheidExportInputTestFactory.create();
......@@ -254,30 +265,14 @@ class ExportBescheidServiceTest {
@BeforeEach
void setUpMocks() {
doReturn(dokumentType).when(service).buildDokumentType(exportInput);
doReturn(document).when(service).getDocument(exportInput.bescheid());
when(exportDataBuilder.dokumentType(dokumentType)).thenReturn(exportDataBuilder);
when(exportDataBuilder.file(document)).thenReturn(exportDataBuilder);
}
@Test
void shouldGetDocument() {
callService();
verify(service).getDocument(exportInput.bescheid());
}
@Test
void shouldAddDocumentToBuilder() {
callService();
verify(exportDataBuilder).file(document);
}
@Test
void shouldAddAttachmentsToBuilder() {
callService();
verify(exportDataBuilder).files(attachments);
verify(exportDataBuilder).files(files);
}
@Test
......@@ -303,7 +298,7 @@ class ExportBescheidServiceTest {
class TestBuildDokumentType {
private final BescheidExportInput exportInput = BescheidExportInputTestFactory.create();
private final Bescheid bescheid = BescheidExportInputTestFactory.BESCHEID;
private final List<OzgFile> attachments = BescheidExportInputTestFactory.ATTACHMENTS;
private final List<OzgFile> attachments = BescheidExportInputTestFactory.FILES;
private final String fullName = UserProfileTestFactory.FULLNAME;
private MockedStatic<DokumentTypeBuilder> dokumentTypeBuilderMockedStatic;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment