mirror of
https://github.com/Alfresco/alfresco-transform-core.git
synced 2025-05-12 17:04:48 +00:00
ATS-702 Add AIO tests from Pdf Renderer (#233)
* ATS-702 implement AIOControllerTikaTest * ATS-702 Implement PDFIT in AIO
This commit is contained in:
parent
cd16637143
commit
6320e04b64
@ -46,6 +46,14 @@
|
|||||||
<type>test-jar</type>
|
<type>test-jar</type>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.alfresco</groupId>
|
||||||
|
<artifactId>alfresco-transform-pdf-renderer-boot</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<classifier>tests</classifier>
|
||||||
|
<type>test-jar</type>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.alfresco</groupId>
|
<groupId>org.alfresco</groupId>
|
||||||
<artifactId>alfresco-transform-tika-boot</artifactId>
|
<artifactId>alfresco-transform-tika-boot</artifactId>
|
||||||
|
@ -0,0 +1,128 @@
|
|||||||
|
/*
|
||||||
|
* #%L
|
||||||
|
* Alfresco Transform Core
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2005 - 2020 Alfresco Software Limited
|
||||||
|
* %%
|
||||||
|
* This file is part of the Alfresco software.
|
||||||
|
* -
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
* -
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
* -
|
||||||
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
* -
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* #L%
|
||||||
|
*/
|
||||||
|
package org.alfresco.transformer;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
|
||||||
|
import org.alfresco.transformer.transformers.PdfRendererAdapter;
|
||||||
|
import org.alfresco.transformer.transformers.Transformer;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
import org.springframework.mock.web.MockMultipartFile;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
import org.springframework.test.util.ReflectionTestUtils;
|
||||||
|
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
|
||||||
|
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@WebMvcTest(AIOController.class)
|
||||||
|
@Import(AIOCustomConfig.class)
|
||||||
|
/**
|
||||||
|
* Test the AIOController PDF Renderer transforms without a server.
|
||||||
|
* Super class includes tests for the AbstractTransformerController.
|
||||||
|
*/
|
||||||
|
public class AIOControllerPdfRendererTest extends AlfrescoPdfRendererControllerTest
|
||||||
|
{
|
||||||
|
// All tests contained IN AlfrescoPdfRendererControllerTest
|
||||||
|
PdfRendererAdapter adapter;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
AIOTransformRegistry transformRegistry;
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
private void init() throws Exception
|
||||||
|
{
|
||||||
|
adapter = new PdfRendererAdapter(execPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setFields()
|
||||||
|
{
|
||||||
|
ReflectionTestUtils.setField(commandExecutor, "transformCommand", mockTransformCommand);
|
||||||
|
ReflectionTestUtils.setField(commandExecutor, "checkCommand", mockCheckCommand);
|
||||||
|
ReflectionTestUtils.setField(adapter, "pdfExecutor", commandExecutor);
|
||||||
|
//Need to wire in the mocked adapter into the controller...
|
||||||
|
Map<String,Transformer> transformers = transformRegistry.getTransformerTransformMapping();
|
||||||
|
transformers.replace("pdfrenderer", adapter);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected MockHttpServletRequestBuilder mockMvcRequest(String url, MockMultipartFile sourceFile,
|
||||||
|
String... params)
|
||||||
|
{
|
||||||
|
final MockHttpServletRequestBuilder builder = super.mockMvcRequest(url, sourceFile, params)
|
||||||
|
.param("targetMimetype", targetMimetype)
|
||||||
|
.param("sourceMimetype", sourceMimetype);
|
||||||
|
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTestValidity()
|
||||||
|
{
|
||||||
|
// just test that we are actually testing against the AIOController (instead of MiscController)
|
||||||
|
assertTrue("Wrong controller wired for test", controller instanceof AIOController);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Override
|
||||||
|
public void testGetTransformConfigInfo()
|
||||||
|
{
|
||||||
|
// Ignore the test in super class as the way the AIO transformer provides config is fundementally different.
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
@Override
|
||||||
|
public void testGetInfoFromConfigWithDuplicates()
|
||||||
|
{
|
||||||
|
// Ignore the test in super class as the way the AIO transformer provides config is fundementally different.
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Override
|
||||||
|
public void testGetInfoFromConfigWithEmptyTransformOptions()
|
||||||
|
{
|
||||||
|
// Ignore the test in super class as the way the AIO transformer provides config is fundementally different.
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Override
|
||||||
|
public void testGetInfoFromConfigWithNoTransformOptions()
|
||||||
|
{
|
||||||
|
// Ignore the test in super class as the way the AIO transformer provides config is fundementally different.
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* #%L
|
||||||
|
* Alfresco Transform Core
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2005 - 2020 Alfresco Software Limited
|
||||||
|
* %%
|
||||||
|
* This file is part of the Alfresco software.
|
||||||
|
* -
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
* -
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
* -
|
||||||
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
* -
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* #L%
|
||||||
|
*/
|
||||||
|
package org.alfresco.transformer;
|
||||||
|
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.junit.runners.Parameterized;
|
||||||
|
|
||||||
|
@RunWith(Parameterized.class)
|
||||||
|
public class AIOPdfRendererIT extends AlfrescoPdfRendererTransformationIT {
|
||||||
|
// Tests are in AlfrescoPdfRendererTransformationIT
|
||||||
|
public AIOPdfRendererIT(String sourceFile)
|
||||||
|
{
|
||||||
|
super(sourceFile);
|
||||||
|
}
|
||||||
|
}
|
@ -80,16 +80,23 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<configuration>
|
|
||||||
<systemPropertyVariables>
|
|
||||||
<PDF_RENDERER_EXE>/usr/bin/alfresco-pdf-renderer</PDF_RENDERER_EXE>
|
|
||||||
</systemPropertyVariables>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-failsafe-plugin</artifactId>
|
<artifactId>maven-failsafe-plugin</artifactId>
|
||||||
</plugin>
|
</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>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* #%L
|
* #%L
|
||||||
* Alfresco Transform Core
|
* 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.
|
* This file is part of the Alfresco software.
|
||||||
* -
|
* -
|
||||||
@ -67,9 +67,9 @@ import org.junit.Test;
|
|||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.stubbing.Answer;
|
import org.mockito.stubbing.Answer;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
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.FileSystemResource;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
@ -96,15 +96,15 @@ public class AlfrescoPdfRendererControllerTest extends AbstractTransformerContro
|
|||||||
private ExecutionResult mockExecutionResult;
|
private ExecutionResult mockExecutionResult;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private RuntimeExec mockTransformCommand;
|
protected RuntimeExec mockTransformCommand;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private RuntimeExec mockCheckCommand;
|
protected RuntimeExec mockCheckCommand;
|
||||||
|
|
||||||
@Value("${transform.core.pdfrenderer.exe}")
|
@Value("${transform.core.pdfrenderer.exe}")
|
||||||
private String execPath;
|
protected String execPath;
|
||||||
|
|
||||||
PdfRendererCommandExecutor commandExecutor;
|
protected PdfRendererCommandExecutor commandExecutor;
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
private void init()
|
private void init()
|
||||||
@ -112,17 +112,22 @@ public class AlfrescoPdfRendererControllerTest extends AbstractTransformerContro
|
|||||||
commandExecutor = new PdfRendererCommandExecutor(execPath);
|
commandExecutor = new PdfRendererCommandExecutor(execPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SpyBean
|
@Autowired
|
||||||
private AlfrescoPdfRendererController controller;
|
protected AbstractTransformerController controller;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void before() throws IOException
|
public void before() throws IOException
|
||||||
|
{
|
||||||
|
setFields();
|
||||||
|
|
||||||
|
mockTransformCommand("pdf", "png", APPLICATION_PDF_VALUE, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setFields()
|
||||||
{
|
{
|
||||||
ReflectionTestUtils.setField(commandExecutor, "transformCommand", mockTransformCommand);
|
ReflectionTestUtils.setField(commandExecutor, "transformCommand", mockTransformCommand);
|
||||||
ReflectionTestUtils.setField(commandExecutor, "checkCommand", mockCheckCommand);
|
ReflectionTestUtils.setField(commandExecutor, "checkCommand", mockCheckCommand);
|
||||||
ReflectionTestUtils.setField(controller, "commandExecutor", commandExecutor);
|
ReflectionTestUtils.setField(controller, "commandExecutor", commandExecutor);
|
||||||
|
|
||||||
mockTransformCommand("pdf", "png", "application/pdf", true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -139,6 +144,7 @@ public class AlfrescoPdfRendererControllerTest extends AbstractTransformerContro
|
|||||||
this.sourceExtension = sourceExtension;
|
this.sourceExtension = sourceExtension;
|
||||||
this.targetExtension = targetExtension;
|
this.targetExtension = targetExtension;
|
||||||
this.sourceMimetype = sourceMimetype;
|
this.sourceMimetype = sourceMimetype;
|
||||||
|
this.targetMimetype = IMAGE_PNG_VALUE;
|
||||||
|
|
||||||
expectedOptions = null;
|
expectedOptions = null;
|
||||||
expectedSourceSuffix = null;
|
expectedSourceSuffix = null;
|
||||||
@ -220,6 +226,8 @@ public class AlfrescoPdfRendererControllerTest extends AbstractTransformerContro
|
|||||||
.multipart("/transform")
|
.multipart("/transform")
|
||||||
.file(sourceFile)
|
.file(sourceFile)
|
||||||
.param("targetExtension", targetExtension)
|
.param("targetExtension", targetExtension)
|
||||||
|
.param("targetMimetype", targetMimetype)
|
||||||
|
.param("sourceMimetype", sourceMimetype)
|
||||||
|
|
||||||
.param("page", "2")
|
.param("page", "2")
|
||||||
|
|
||||||
@ -242,6 +250,8 @@ public class AlfrescoPdfRendererControllerTest extends AbstractTransformerContro
|
|||||||
.multipart("/transform")
|
.multipart("/transform")
|
||||||
.file(sourceFile)
|
.file(sourceFile)
|
||||||
.param("targetExtension", targetExtension)
|
.param("targetExtension", targetExtension)
|
||||||
|
.param("targetMimetype", targetMimetype)
|
||||||
|
.param("sourceMimetype", sourceMimetype)
|
||||||
|
|
||||||
.param("page", "2")
|
.param("page", "2")
|
||||||
|
|
||||||
|
@ -27,12 +27,17 @@
|
|||||||
package org.alfresco.transformer;
|
package org.alfresco.transformer;
|
||||||
|
|
||||||
import static java.text.MessageFormat.format;
|
import static java.text.MessageFormat.format;
|
||||||
|
import static java.util.function.Function.identity;
|
||||||
|
import static java.util.stream.Collectors.toMap;
|
||||||
import static org.alfresco.transformer.EngineClient.sendTRequest;
|
import static org.alfresco.transformer.EngineClient.sendTRequest;
|
||||||
|
import static org.alfresco.transformer.TestFileInfo.testFile;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
import static org.springframework.http.HttpStatus.OK;
|
import static org.springframework.http.HttpStatus.OK;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@ -54,11 +59,19 @@ public class AlfrescoPdfRendererTransformationIT
|
|||||||
AlfrescoPdfRendererTransformationIT.class);
|
AlfrescoPdfRendererTransformationIT.class);
|
||||||
private static final String ENGINE_URL = "http://localhost:8090";
|
private static final String ENGINE_URL = "http://localhost:8090";
|
||||||
|
|
||||||
|
private static final Map<String, TestFileInfo> TEST_FILES = Stream.of(
|
||||||
|
testFile("application/pdf","pdf","quick.pdf"),
|
||||||
|
testFile("application/illustrator","ai","quickCS3.ai") ,
|
||||||
|
testFile("application/illustrator","ai","quickCS5.ai")
|
||||||
|
).collect(toMap(TestFileInfo::getPath, identity()));
|
||||||
|
|
||||||
private final String sourceFile;
|
private final String sourceFile;
|
||||||
|
private final String sourceMimetype;
|
||||||
|
|
||||||
public AlfrescoPdfRendererTransformationIT(String sourceFile)
|
public AlfrescoPdfRendererTransformationIT(String sourceFile)
|
||||||
{
|
{
|
||||||
this.sourceFile = sourceFile;
|
this.sourceFile = sourceFile;
|
||||||
|
this.sourceMimetype = TEST_FILES.get(sourceFile).getMimeType();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Parameterized.Parameters
|
@Parameterized.Parameters
|
||||||
@ -74,12 +87,13 @@ public class AlfrescoPdfRendererTransformationIT
|
|||||||
@Test
|
@Test
|
||||||
public void testTransformation()
|
public void testTransformation()
|
||||||
{
|
{
|
||||||
final String descriptor = format("Transform ({0} -> png)", sourceFile);
|
final String descriptor = format("Transform ({0}, {1} -> {2}, {3})",
|
||||||
|
sourceFile, sourceMimetype, "image/png", "png");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
final ResponseEntity<Resource> response = sendTRequest(ENGINE_URL, sourceFile, null,
|
final ResponseEntity<Resource> response = sendTRequest(ENGINE_URL, sourceFile, sourceMimetype,
|
||||||
null, "png");
|
"image/png", "png");
|
||||||
assertEquals(descriptor, OK, response.getStatusCode());
|
assertEquals(descriptor, OK, response.getStatusCode());
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
@ -47,6 +47,10 @@
|
|||||||
<groupId>org.quartz-scheduler</groupId>
|
<groupId>org.quartz-scheduler</groupId>
|
||||||
<artifactId>quartz</artifactId>
|
<artifactId>quartz</artifactId>
|
||||||
</exclusion>
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>xml-apis</groupId>
|
||||||
|
<artifactId>xml-apis</artifactId>
|
||||||
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
1
pom.xml
1
pom.xml
@ -346,6 +346,7 @@
|
|||||||
<IMAGEMAGICK_EXE>/usr/bin/convert</IMAGEMAGICK_EXE>
|
<IMAGEMAGICK_EXE>/usr/bin/convert</IMAGEMAGICK_EXE>
|
||||||
<IMAGEMAGICK_DYN>/usr/lib64/ImageMagick-7.0.7/lib</IMAGEMAGICK_DYN>
|
<IMAGEMAGICK_DYN>/usr/lib64/ImageMagick-7.0.7/lib</IMAGEMAGICK_DYN>
|
||||||
<IMAGEMAGICK_ROOT>/usr/lib64/ImageMagick-7.0.7</IMAGEMAGICK_ROOT>
|
<IMAGEMAGICK_ROOT>/usr/lib64/ImageMagick-7.0.7</IMAGEMAGICK_ROOT>
|
||||||
|
<PDF_RENDERER_EXE>/usr/bin/alfresco-pdf-renderer</PDF_RENDERER_EXE>
|
||||||
<buildDirectory>${project.build.directory}</buildDirectory>
|
<buildDirectory>${project.build.directory}</buildDirectory>
|
||||||
</systemPropertyVariables>
|
</systemPropertyVariables>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user