package com.estate.expert.admin.stat.report.builder;
|
|
import org.apache.poi.util.Units;
|
import org.apache.poi.xwpf.usermodel.Document;
|
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
import org.junit.jupiter.api.Test;
|
|
import java.io.ByteArrayInputStream;
|
import java.util.Base64;
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
class ChengduHengtaiSystemReportBuilderTest {
|
|
private static final int TEMPLATE_PICTURE_ROW_HEIGHT = 3308;
|
|
private static final byte[] ONE_PIXEL_PNG = Base64.getDecoder().decode(
|
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=");
|
|
@Test
|
void shouldCompactPictureRowWhenNoPictureExists() throws Exception {
|
try (var document = createPictureTable()) {
|
ChengduHengtaiSystemReportBuilder.compactEmptyPictureRows(document);
|
|
assertEquals(240, document.getTables().get(0).getRow(1).getHeight());
|
}
|
}
|
|
@Test
|
void shouldKeepTemplateHeightWhenPictureExists() throws Exception {
|
try (var document = createPictureTable()) {
|
var pictureCell = document.getTables().get(0).getRow(1).getCell(0);
|
pictureCell.getParagraphs().get(0).createRun().addPicture(
|
new ByteArrayInputStream(ONE_PIXEL_PNG),
|
Document.PICTURE_TYPE_PNG,
|
"pixel.png",
|
Units.pixelToEMU(1),
|
Units.pixelToEMU(1));
|
|
ChengduHengtaiSystemReportBuilder.compactEmptyPictureRows(document);
|
|
assertEquals(TEMPLATE_PICTURE_ROW_HEIGHT, document.getTables().get(0).getRow(1).getHeight());
|
}
|
}
|
|
private XWPFDocument createPictureTable() {
|
var document = new XWPFDocument();
|
var table = document.createTable(2, 1);
|
table.getRow(0).getCell(0).setText("问题图片");
|
table.getRow(1).setHeight(TEMPLATE_PICTURE_ROW_HEIGHT);
|
return document;
|
}
|
}
|