RED-6603 - add test for iuclid
This commit is contained in:
parent
8bc2f1e654
commit
a02fbf650d
@ -12,7 +12,10 @@ import static com.iqser.red.service.redaction.report.v1.server.service.Placehold
|
||||
import static com.iqser.red.service.redaction.report.v1.server.utils.OsUtils.getTemporaryDirectory;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@ -25,6 +28,9 @@ import org.apache.commons.io.IOUtils;
|
||||
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFRun;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mockito;
|
||||
@ -70,7 +76,7 @@ import lombok.SneakyThrows;
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@EnableAutoConfiguration(exclude = {/*StorageAutoConfiguration.class,*/RabbitAutoConfiguration.class})
|
||||
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@ComponentScan(excludeFilters={@ComponentScan.Filter(type= FilterType.ASSIGNABLE_TYPE, value=StorageAutoConfiguration.class)})
|
||||
@ComponentScan(excludeFilters = {@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = StorageAutoConfiguration.class)})
|
||||
public class RedactionReportIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
@ -134,6 +140,7 @@ public class RedactionReportIntegrationTest {
|
||||
return testDossier;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@SneakyThrows
|
||||
public void testWordJustificationAppendixA1() {
|
||||
@ -149,7 +156,6 @@ public class RedactionReportIntegrationTest {
|
||||
var wordTemplateResource = new ClassPathResource("templates/Justification Appendix A1.docx");
|
||||
var imageResource = new ClassPathResource("files/exampleImage.jpg");
|
||||
|
||||
|
||||
var placeholders = buildPlaceHolderModel(Map.of("{{dossier.attribute.ActiveSubstance}}",
|
||||
"Aktive Substanz \n Test Return",
|
||||
"{{dossier.attribute.RapporteurMemberState}}",
|
||||
@ -213,6 +219,42 @@ public class RedactionReportIntegrationTest {
|
||||
@SneakyThrows
|
||||
public void testWordIUCLIDFile() {
|
||||
|
||||
XWPFDocument doc = getIUCLIDFile();
|
||||
|
||||
List<XWPFParagraph> paragraphs = doc.getParagraphs();
|
||||
|
||||
Assertions.assertEquals(1, paragraphs.size());
|
||||
|
||||
ClassPathResource classPathResource = new ClassPathResource("expected/iuclid.txt");
|
||||
InputStream inputStream = classPathResource.getInputStream();
|
||||
List<String> expectedContent = IOUtils.readLines(inputStream, "UTF-8");
|
||||
|
||||
List<String> contentOfParagraphs = getContentOfParagraphs(paragraphs, true);
|
||||
|
||||
Assertions.assertIterableEquals(contentOfParagraphs, expectedContent);
|
||||
|
||||
try (FileOutputStream fileOutputStream = new FileOutputStream(getTemporaryDirectory() + "/IUCLID_Template_justification.docx")) {
|
||||
fileOutputStream.write(wordReportGenerationService.toByteArray(doc));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private List<String> getContentOfParagraphs(List<XWPFParagraph> paragraphs, boolean deleteCarriageReturns) {
|
||||
|
||||
List<String> res = new ArrayList<>();
|
||||
|
||||
for (XWPFParagraph paragraph : paragraphs) {
|
||||
for (XWPFRun run : paragraph.getRuns()) {
|
||||
String textOfRun = deleteCarriageReturns ? run.text().replaceAll("\\n", "") : run.text();
|
||||
res.add(textOfRun);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
private XWPFDocument getIUCLIDFile() throws IOException {
|
||||
|
||||
Dossier dossier = prepareDossier();
|
||||
FileModel fileStatus = FileModel.builder().filename("filename").build();
|
||||
|
||||
@ -227,11 +269,11 @@ public class RedactionReportIntegrationTest {
|
||||
var placeholders = buildPlaceHolderModel(new HashMap<>(), Map.of("{{file.attribute.Path}}", "Path"), List.of());
|
||||
|
||||
wordReportGenerationService.generateWordReport(reportEntries, placeholders, "test", doc, fileStatus, dossier, true);
|
||||
byte[] report = wordReportGenerationService.toByteArray(doc);
|
||||
|
||||
try (FileOutputStream fileOutputStream = new FileOutputStream(getTemporaryDirectory() + "/IUCLID_Template_justification.docx")) {
|
||||
fileOutputStream.write(report);
|
||||
}
|
||||
byte[] report = wordReportGenerationService.toByteArray(doc);
|
||||
XWPFDocument newDoc = new XWPFDocument(new ByteArrayInputStream(report));
|
||||
|
||||
return newDoc;
|
||||
}
|
||||
|
||||
|
||||
@ -275,7 +317,10 @@ public class RedactionReportIntegrationTest {
|
||||
|
||||
FileModel fileModelSecondFile = FileModel.builder().filename("secondFile").build();
|
||||
RedactionLog redactionLogSecondFile = objectMapper.readValue(new ClassPathResource("files/excelReportRedactionLog.json").getInputStream(), RedactionLog.class);
|
||||
List<ReportRedactionEntry> reportEntriesSecondFile = redactionLogConverterService.convertAndSort(redactionLogSecondFile, legalBasisMapping, new HashMap<>(), dossier.getDossierId());
|
||||
List<ReportRedactionEntry> reportEntriesSecondFile = redactionLogConverterService.convertAndSort(redactionLogSecondFile,
|
||||
legalBasisMapping,
|
||||
new HashMap<>(),
|
||||
dossier.getDossierId());
|
||||
|
||||
ClassPathResource templateResource = new ClassPathResource("templates/Seeds-NewJustificationForm.docx");
|
||||
XWPFDocument doc = new XWPFDocument(templateResource.getInputStream());
|
||||
@ -342,7 +387,6 @@ public class RedactionReportIntegrationTest {
|
||||
Map<String, String> mapOfEntityDisplayName = createEntityDisplayNames(redactionLog);
|
||||
List<ReportRedactionEntry> reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping, mapOfEntityDisplayName, dossier.getDossierId());
|
||||
|
||||
|
||||
ClassPathResource templateResource = new ClassPathResource("templates/Excel Report.xlsx");
|
||||
|
||||
var placeholders = buildPlaceHolderModel(new HashMap<>(), new HashMap<>(), List.of());
|
||||
@ -385,7 +429,10 @@ public class RedactionReportIntegrationTest {
|
||||
excelTemplateReportGenerationService.generateExcelReport(reportEntries, placeholders, "test", writeWorkbook, "dossierName", fileModel, excelModel, false);
|
||||
|
||||
RedactionLog redactionLogSecondFile = objectMapper.readValue(new ClassPathResource("files/excelReportRedactionLog.json").getInputStream(), RedactionLog.class);
|
||||
List<ReportRedactionEntry> reportEntriesSecondFile = redactionLogConverterService.convertAndSort(redactionLogSecondFile, legalBasisMapping, mapOfEntityDisplayName, dossier.getDossierId());
|
||||
List<ReportRedactionEntry> reportEntriesSecondFile = redactionLogConverterService.convertAndSort(redactionLogSecondFile,
|
||||
legalBasisMapping,
|
||||
mapOfEntityDisplayName,
|
||||
dossier.getDossierId());
|
||||
FileModel fileModelSecondFile = FileModel.builder().filename("secondFile").build();
|
||||
excelTemplateReportGenerationService.generateExcelReport(reportEntriesSecondFile,
|
||||
placeholders,
|
||||
|
||||
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user