RED-1186: Return mocked placeholders in unittest
This commit is contained in:
parent
2d5b3fe4fa
commit
951a901702
@ -0,0 +1,13 @@
|
||||
package com.iqser.red.service.redaction.report.v1.server.client;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class Placeholder {
|
||||
|
||||
private String placeholder;
|
||||
private String value;
|
||||
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
package com.iqser.red.service.redaction.report.v1.server.client;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
|
||||
@FeignClient(name = "PlaceholderResource", url = "${configuration-service.url}")
|
||||
public interface PlaceholderClient {
|
||||
|
||||
List<Placeholder> getPlaceholders();
|
||||
}
|
||||
@ -16,6 +16,8 @@ import org.apache.poi.xwpf.usermodel.XWPFTableRow;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.iqser.red.service.redaction.report.v1.api.model.ReportType;
|
||||
import com.iqser.red.service.redaction.report.v1.server.client.Placeholder;
|
||||
import com.iqser.red.service.redaction.report.v1.server.client.PlaceholderClient;
|
||||
import com.iqser.red.service.redaction.report.v1.server.model.ReportRedactionEntry;
|
||||
import com.iqser.red.service.redaction.report.v1.server.utils.ResourceLoader;
|
||||
|
||||
@ -27,6 +29,7 @@ public class WordReportGenerationService {
|
||||
|
||||
private byte[] appendixA1Template;
|
||||
private byte[] appendixA2Template;
|
||||
private PlaceholderClient placeholderClient;
|
||||
|
||||
|
||||
@PostConstruct
|
||||
@ -39,6 +42,10 @@ public class WordReportGenerationService {
|
||||
|
||||
public byte[] generateReport(ReportType reportType, List<ReportRedactionEntry> reportEntries, String filename) {
|
||||
|
||||
|
||||
List<Placeholder> placeholder = placeholderClient.getPlaceholders();
|
||||
|
||||
|
||||
byte[] template;
|
||||
|
||||
if (reportType.equals(ReportType.WORD_SINGLE_FILE_APPENDIX_A1_TEMPLATE)) {
|
||||
@ -52,6 +59,8 @@ public class WordReportGenerationService {
|
||||
try (ByteArrayInputStream is = new ByteArrayInputStream(template)) {
|
||||
XWPFDocument doc = new XWPFDocument(is);
|
||||
|
||||
// Replace placeholders.
|
||||
|
||||
addTableRows(doc, reportEntries, filename);
|
||||
return toByteArray(doc);
|
||||
} catch (IOException e) {
|
||||
|
||||
Binary file not shown.
@ -1,5 +1,6 @@
|
||||
package com.iqser.red.service.redaction.report.v1.server;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
@ -8,6 +9,8 @@ import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
@ -20,6 +23,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.iqser.red.service.configuration.v1.api.model.LegalBasisMapping;
|
||||
import com.iqser.red.service.redaction.report.v1.api.model.ReportType;
|
||||
import com.iqser.red.service.redaction.report.v1.server.client.LegalBasisMappingClient;
|
||||
import com.iqser.red.service.redaction.report.v1.server.client.Placeholder;
|
||||
import com.iqser.red.service.redaction.report.v1.server.client.PlaceholderClient;
|
||||
import com.iqser.red.service.redaction.report.v1.server.configuration.MessagingConfiguration;
|
||||
import com.iqser.red.service.redaction.report.v1.server.model.ReportRedactionEntry;
|
||||
import com.iqser.red.service.redaction.report.v1.server.service.ExcelReportGenerationService;
|
||||
@ -44,7 +49,7 @@ public class RedactionReportIntegrationTest {
|
||||
@MockBean
|
||||
private AmazonS3 s3Client;
|
||||
|
||||
@Autowired
|
||||
@InjectMocks
|
||||
private WordReportGenerationService wordReportGenerationService;
|
||||
|
||||
@Autowired
|
||||
@ -56,10 +61,15 @@ public class RedactionReportIntegrationTest {
|
||||
@Autowired
|
||||
private RedactionLogConverterService redactionLogConverterService;
|
||||
|
||||
@Mock
|
||||
private PlaceholderClient placeholderClient;
|
||||
|
||||
|
||||
@Test
|
||||
public void testWordReportGeneration() throws IOException {
|
||||
|
||||
when(placeholderClient.getPlaceholders()).thenReturn(List.of(Placeholder.builder().placeholder("{{dossier.name}}").value("Dossier 1").build()));
|
||||
|
||||
ClassPathResource redactionLogResource = new ClassPathResource("files/RedactedLog.txt");
|
||||
|
||||
RedactionLog redactionLog = objectMapper.readValue(redactionLogResource.getInputStream(), RedactionLog.class);
|
||||
@ -73,12 +83,14 @@ public class RedactionReportIntegrationTest {
|
||||
|
||||
List<ReportRedactionEntry> reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping);
|
||||
|
||||
byte[] report = wordReportGenerationService.generateReport(ReportType.WORD_SINGLE_FILE_APPENDIX_A2_TEMPLATE, reportEntries, redactionLog
|
||||
wordReportGenerationService.init();
|
||||
byte[] report = wordReportGenerationService.generateReport(ReportType.WORD_SINGLE_FILE_APPENDIX_A1_TEMPLATE, reportEntries, redactionLog
|
||||
.getFilename());
|
||||
|
||||
try (FileOutputStream fileOutputStream = new FileOutputStream("/tmp/efsa_template.docx")) {
|
||||
fileOutputStream.write(report);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user