mirror of
https://github.com/sismics/docs.git
synced 2025-12-17 19:51:39 +00:00
Closes #53: Build thumbnails for DOCX and ODT files
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
package com.sismics.docs.core.util;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.apache.pdfbox.io.IOUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.common.io.Resources;
|
||||
@@ -18,19 +20,25 @@ import com.sismics.util.mime.MimeType;
|
||||
public class TestFileUtil {
|
||||
@Test
|
||||
public void extractContentOpenDocumentTextTest() throws Exception {
|
||||
try (InputStream inputStream = Resources.getResource("file/document.odt").openStream()) {
|
||||
try (InputStream inputStream = Resources.getResource("file/document.odt").openStream();
|
||||
InputStream bytesInputStream = new ByteArrayInputStream(IOUtils.toByteArray(inputStream))) {
|
||||
File file = new File();
|
||||
file.setMimeType(MimeType.OPEN_DOCUMENT_TEXT);
|
||||
Assert.assertEquals("Lorem ipsum dolor sit amen.\r\n", FileUtil.extractContent(null, file, inputStream));
|
||||
try (InputStream pdfInputStream = FileUtil.convertToPdf(bytesInputStream, file)) {
|
||||
Assert.assertEquals("Lorem ipsum dolor sit amen.\r\n", FileUtil.extractContent(null, file, inputStream, pdfInputStream));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractContentOfficeDocumentTest() throws Exception {
|
||||
try (InputStream inputStream = Resources.getResource("file/document.docx").openStream()) {
|
||||
try (InputStream inputStream = Resources.getResource("file/document.docx").openStream();
|
||||
InputStream bytesInputStream = new ByteArrayInputStream(IOUtils.toByteArray(inputStream))) {
|
||||
File file = new File();
|
||||
file.setMimeType(MimeType.OFFICE_DOCUMENT);
|
||||
Assert.assertEquals("Lorem ipsum dolor sit amen.\r\n", FileUtil.extractContent(null, file, inputStream));
|
||||
try (InputStream pdfInputStream = FileUtil.convertToPdf(bytesInputStream, file)) {
|
||||
Assert.assertEquals("Lorem ipsum dolor sit amen.\r\n", FileUtil.extractContent(null, file, inputStream, pdfInputStream));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user