ATS-702: Add AIO tests from LibreOffice (#231)

Created test-jar for libreoffice-boot
Updated LibreOfficeControllerTest.java so it can provide inheritance
Updated LibreOfficeControllerTest#testPojoTransform to uses a viable targetMimetype
Fixed inconsitent naming for @Value annotation
Moved surefire config to super pom
Implement LibreOfficeIT on AIO Controller
This commit is contained in:
David Edwards
2020-04-22 19:17:01 +01:00
committed by GitHub
parent 6320e04b64
commit 410997689f
12 changed files with 337 additions and 68 deletions

View File

@@ -91,16 +91,23 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<LIBREOFFICE_HOME>/opt/libreoffice6.3</LIBREOFFICE_HOME>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

View File

@@ -79,7 +79,7 @@ public class LibreOfficeController extends AbstractTransformerController
{
private static final Logger logger = LoggerFactory.getLogger(LibreOfficeController.class);
@Value("${transform.core.libreoffice.home}")
@Value("${transform.core.libreoffice.path}")
private String execPath;
LibreOfficeJavaExecutor javaExecutor;

View File

@@ -5,4 +5,4 @@ transform:
config:
location: classpath:libreoffice_engine_config.json
libreoffice:
home: ${LIBREOFFICE_HOME:/opt/libreoffice6.3}
path: ${LIBREOFFICE_HOME:/opt/libreoffice6.3}

View File

@@ -26,6 +26,10 @@
*/
package org.alfresco.transformer;
import static org.alfresco.transformer.util.RequestParamMap.SOURCE_MIMETYPE;
import static org.alfresco.transformer.util.RequestParamMap.TARGET_EXTENSION;
import static org.alfresco.transformer.util.RequestParamMap.TARGET_MIMETYPE;
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_PDF;
import static org.alfresco.transformer.executors.RuntimeExec.ExecutionResult;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals;
@@ -63,9 +67,9 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpHeaders;
@@ -82,19 +86,20 @@ import javax.annotation.PostConstruct;
* Super class includes tests for the AbstractTransformerController.
*/
@RunWith(SpringRunner.class)
@WebMvcTest(LibreOfficeControllerTest.class)
@WebMvcTest(LibreOfficeController.class)
public class LibreOfficeControllerTest extends AbstractTransformerControllerTest
{
private static final String ENGINE_CONFIG_NAME = "libreoffice_engine_config.json";
protected static final String ENGINE_CONFIG_NAME = "libreoffice_engine_config.json";
protected String targetMimetype = MIMETYPE_PDF;
@Mock
private ExecutionResult mockExecutionResult;
protected ExecutionResult mockExecutionResult;
@Value("${transform.core.libreoffice.home}")
private String execPath;
@Value("${transform.core.libreoffice.path}")
protected String execPath;
LibreOfficeJavaExecutor javaExecutor;
protected LibreOfficeJavaExecutor javaExecutor;
@PostConstruct
private void init()
@@ -102,8 +107,8 @@ public class LibreOfficeControllerTest extends AbstractTransformerControllerTest
javaExecutor = Mockito.spy(new LibreOfficeJavaExecutor(execPath));
}
@SpyBean
private LibreOfficeController controller;
@Autowired
protected AbstractTransformerController controller;
@Before
public void before() throws IOException
@@ -112,7 +117,7 @@ public class LibreOfficeControllerTest extends AbstractTransformerControllerTest
targetExtension = "pdf";
sourceMimetype = "application/msword";
ReflectionTestUtils.setField(controller, "javaExecutor", javaExecutor);
setJavaExecutor(controller,javaExecutor);
// The following is based on super.mockTransformCommand(...)
// This is because LibreOffice used JodConverter rather than a RuntimeExec
@@ -152,6 +157,12 @@ public class LibreOfficeControllerTest extends AbstractTransformerControllerTest
}).when(javaExecutor).convert(any(), any());
}
protected void setJavaExecutor(AbstractTransformerController controller, LibreOfficeJavaExecutor javaExecutor)
{
ReflectionTestUtils.setField(controller, "javaExecutor", javaExecutor);
}
@Override
public String getEngineConfigName()
{
@@ -180,10 +191,12 @@ public class LibreOfficeControllerTest extends AbstractTransformerControllerTest
.perform(MockMvcRequestBuilders
.multipart("/transform")
.file(sourceFile)
.param("targetExtension", "xxx"))
.param(TARGET_EXTENSION, "xxx")
.param(SOURCE_MIMETYPE,sourceMimetype)
.param(TARGET_MIMETYPE,targetMimetype))
.andExpect(status().is(400))
.andExpect(status().reason(
containsString("LibreOffice - LibreOffice server conversion failed:")));
containsString("LibreOffice server conversion failed:")));
}
@Override
@@ -192,7 +205,7 @@ public class LibreOfficeControllerTest extends AbstractTransformerControllerTest
transformRequest.setSourceExtension("doc");
transformRequest.setTargetExtension("pdf");
transformRequest.setSourceMediaType("application/msword");
transformRequest.setTargetMediaType(IMAGE_PNG_VALUE);
transformRequest.setTargetMediaType(targetMimetype);
}
@Test

View File

@@ -2,7 +2,7 @@
* #%L
* Alfresco Transform Core
* %%
* Copyright (C) 2005 - 2019 Alfresco Software Limited
* Copyright (C) 2005 - 2020 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
@@ -28,15 +28,39 @@ package org.alfresco.transformer;
import static java.text.MessageFormat.format;
import static java.util.function.Function.identity;
import static java.util.stream.Collectors.toMap;
import static java.util.stream.Collectors.toSet;
import static org.alfresco.transformer.EngineClient.sendTRequest;
import static org.alfresco.transformer.TestFileInfo.testFile;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_EXCEL;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_HTML;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_SVG;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_OPENDOCUMENT_GRAPHICS;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_OPENDOCUMENT_PRESENTATION;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_OPENDOCUMENT_SPREADSHEET;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_OPENDOCUMENT_TEXT;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_OPENXML_PRESENTATION;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_OPENXML_SPREADSHEET;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_OPENXML_WORDPROCESSING;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_PDF;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_PPT;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_RTF;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_TEXT_CSV;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_TSV;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_VISIO;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_VISIO_2013;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_WORD;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_WORDPERFECT;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.springframework.http.HttpStatus.OK;
import java.util.Map;
import java.util.Set;
import java.util.stream.Stream;
import com.google.common.collect.ImmutableSet;
import org.apache.commons.lang3.tuple.Pair;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -46,8 +70,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.core.io.Resource;
import org.springframework.http.ResponseEntity;
import com.google.common.collect.ImmutableSet;
/**
* @author Cezar Leahu
*/
@@ -56,47 +78,93 @@ public class LibreOfficeTransformationIT
{
private static final Logger logger = LoggerFactory.getLogger(LibreOfficeTransformationIT.class);
private static final String ENGINE_URL = "http://localhost:8090";
private static final Set<String> spreadsheetTargetMimetypes = ImmutableSet.of(
"csv", "html", "ods", "pdf", "tsv", "xls");
private static final Set<String> documentsTargetMimetypes = ImmutableSet.of(
"doc", "html", "odt", "pdf", "rtf");
private static final Set<String> graphicTargetMimetypes = ImmutableSet.of(
"pdf", "svg");
private static final Set<String> presentationTargetMimetypes = ImmutableSet.of(
"html", "odp", "ppt", "pdf");
private static final Set<TestFileInfo> spreadsheetTargets = ImmutableSet.of(
testFile(MIMETYPE_TEXT_CSV, "csv",null),
testFile(MIMETYPE_HTML,"html",null),
testFile(MIMETYPE_OPENDOCUMENT_SPREADSHEET,"ods",null),
testFile(MIMETYPE_PDF,"pdf",null),
testFile(MIMETYPE_TSV,"tsv",null),
testFile(MIMETYPE_EXCEL,"xls",null)
);
private static final Set<TestFileInfo> documentsTargets = ImmutableSet.of(
testFile(MIMETYPE_WORD,"doc",null),
testFile(MIMETYPE_HTML,"html",null),
testFile(MIMETYPE_OPENDOCUMENT_TEXT,"odt",null),
testFile(MIMETYPE_PDF,"pdf",null),
testFile(MIMETYPE_RTF,"rtf",null)
);
private static final Set<TestFileInfo> graphicTargets = ImmutableSet.of(
testFile(MIMETYPE_PDF,"pdf",null),
testFile(MIMETYPE_IMAGE_SVG,"svg",null)
);
private static final Set<TestFileInfo> presentationTargets = ImmutableSet.of(
testFile(MIMETYPE_HTML,"html",null),
testFile(MIMETYPE_OPENDOCUMENT_PRESENTATION,"odp",null),
testFile(MIMETYPE_PPT,"ppt",null),
testFile(MIMETYPE_PDF,"pdf",null)
);
private final String sourceFile;
private final String targetExtension;
private final String sourceMimetype;
private final String targetMimetype;
public LibreOfficeTransformationIT(final Pair<String, String> entry)
private static final Map<String,TestFileInfo> TEST_FILES = Stream.of(
testFile(MIMETYPE_WORD ,"doc" ,"quick.doc"),
testFile(MIMETYPE_OPENXML_WORDPROCESSING ,"docx" ,"quick.docx"),
testFile(MIMETYPE_OPENDOCUMENT_GRAPHICS ,"odg" ,"quick.odg"),
testFile(MIMETYPE_OPENDOCUMENT_PRESENTATION ,"odp" ,"quick.odp"),
testFile(MIMETYPE_OPENDOCUMENT_SPREADSHEET ,"ods" ,"quick.ods"),
testFile(MIMETYPE_OPENDOCUMENT_TEXT ,"odt" ,"quick.odt"),
testFile(MIMETYPE_PPT ,"ppt" ,"quick.ppt"),
testFile(MIMETYPE_OPENXML_PRESENTATION ,"pptx" ,"quick.pptx"),
testFile(MIMETYPE_VISIO ,"vdx" ,"quick.vdx"),
testFile(MIMETYPE_VISIO_2013 ,"vsd" ,"quick.vsd"),
testFile(MIMETYPE_WORDPERFECT ,"wpd" ,"quick.wpd"),
testFile(MIMETYPE_EXCEL ,"xls" ,"quick.xls" ),
testFile(MIMETYPE_OPENXML_SPREADSHEET ,"xlsx" ,"quick.xlsx"),
testFile(MIMETYPE_TEXT_CSV ,"csv" ,"people.csv"),
testFile(MIMETYPE_RTF ,"rtf" ,"sample.rtf"),
testFile(MIMETYPE_HTML ,"html" ,"quick.html"),
testFile(MIMETYPE_TSV ,"tsv" ,"sample.tsv")
).collect(toMap(TestFileInfo::getPath, identity()));
public LibreOfficeTransformationIT(final Pair<TestFileInfo, TestFileInfo> entry)
{
sourceFile = entry.getKey();
targetExtension = entry.getRight();
sourceFile = entry.getLeft().getPath();
targetExtension = entry.getRight().getExtension();
sourceMimetype = entry.getLeft().getMimeType();
targetMimetype = entry.getRight().getMimeType();
}
@Parameterized.Parameters
public static Set<Pair<String, String>> engineTransformations()
public static Set<Pair<TestFileInfo, TestFileInfo>> engineTransformations()
{
return Stream
.of(
allTargets("quick.doc", documentsTargetMimetypes),
allTargets("quick.docx", documentsTargetMimetypes),
allTargets("quick.odg", graphicTargetMimetypes),
allTargets("quick.odp", presentationTargetMimetypes),
allTargets("quick.ods", spreadsheetTargetMimetypes),
allTargets("quick.odt", documentsTargetMimetypes),
allTargets("quick.ppt", presentationTargetMimetypes),
allTargets("quick.pptx", presentationTargetMimetypes),
allTargets("quick.vdx", graphicTargetMimetypes),
allTargets("quick.vsd", graphicTargetMimetypes),
allTargets("quick.wpd", documentsTargetMimetypes),
allTargets("quick.xls", spreadsheetTargetMimetypes),
allTargets("quick.xlsx", spreadsheetTargetMimetypes),
allTargets("quick.doc", documentsTargets),
allTargets("quick.docx", documentsTargets),
allTargets("quick.html", documentsTargets),
allTargets("quick.odt", documentsTargets),
allTargets("quick.wpd", documentsTargets),
allTargets("sample.rtf", documentsTargets),
allTargets("people.csv", spreadsheetTargetMimetypes),
allTargets("sample.rtf", documentsTargetMimetypes),
allTargets("quick.html", documentsTargetMimetypes),
allTargets("sample.tsv", spreadsheetTargetMimetypes)
allTargets("quick.odp", presentationTargets),
allTargets("quick.ppt", presentationTargets),
allTargets("quick.pptx", presentationTargets),
allTargets("quick.odg", graphicTargets),
allTargets("quick.vdx", graphicTargets),
allTargets("quick.vsd", graphicTargets),
allTargets("quick.ods", spreadsheetTargets),
allTargets("quick.xls", spreadsheetTargets),
allTargets("quick.xlsx", spreadsheetTargets),
allTargets("people.csv", spreadsheetTargets),
allTargets("sample.tsv", spreadsheetTargets)
)
.flatMap(identity())
.collect(toSet());
@@ -105,12 +173,12 @@ public class LibreOfficeTransformationIT
@Test
public void testTransformation()
{
final String descriptor = format("Transform ({0} -> {1})", sourceFile, targetExtension);
final String descriptor = format("Transform ({0}, {1} -> {2}, {3})",
sourceFile, sourceMimetype, targetMimetype, targetExtension);
try
{
final ResponseEntity<Resource> response = sendTRequest(ENGINE_URL, sourceFile, null,
null, targetExtension);
final ResponseEntity<Resource> response = sendTRequest(ENGINE_URL, sourceFile, sourceMimetype,
targetMimetype, targetExtension);
assertEquals(descriptor, OK, response.getStatusCode());
}
catch (Exception e)
@@ -119,11 +187,15 @@ public class LibreOfficeTransformationIT
}
}
private static Stream<Pair<String, String>> allTargets(final String sourceFile,
final Set<String> mimetypes)
private static Stream<Pair<TestFileInfo, TestFileInfo>> allTargets(final String sourceFile,
final Set<TestFileInfo> mimetypes)
{
return mimetypes
.stream()
.map(k -> Pair.of(sourceFile, k));
//Filter out duplicate mimetypes. eg. We do not want "Transform (quick.doc, application/msword -> application/msword, doc)" as these are not contained in the engine_config
.filter(type -> !type.getMimeType().equals(TEST_FILES.get(sourceFile).getMimeType()))
// Edge case: Transform (quick.ods, application/vnd.oasis.opendocument.spreadsheet -> text/csv, csv) not in engine_config
.filter(type -> !(TEST_FILES.get(sourceFile).getMimeType().equals(MIMETYPE_OPENDOCUMENT_SPREADSHEET) && type.getMimeType().equals(MIMETYPE_TEXT_CSV)))
.map(k -> Pair.of(TEST_FILES.get(sourceFile), k));
}
}