mirror of
https://github.com/Alfresco/alfresco-transform-core.git
synced 2025-08-07 17:48:35 +00:00
ATS-702 Add AIOControllerTest for Imagemagick transforms (#208)
Runs the tests inherited from the imagemagick-boot-test-jar through the All in One Transformer Co-authored-by: Erik Knizat <erik.knizat@alfresco.com> Co-authored-by: kristian <kristian.dimitrov@alfresco.com> Co-authored-by: eknizat <26163420+eknizat@users.noreply.github.com>
This commit is contained in:
@@ -38,6 +38,14 @@
|
||||
<type>test-jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-transform-imagemagick-boot</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<classifier>tests</classifier>
|
||||
<type>test-jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
@@ -126,9 +126,9 @@ public class AIOController extends AbstractTransformerController
|
||||
@PostMapping(value = "/transform", consumes = MULTIPART_FORM_DATA_VALUE)
|
||||
public ResponseEntity<Resource> transform(HttpServletRequest request,
|
||||
@RequestParam("file") MultipartFile sourceMultipartFile,
|
||||
@RequestParam(TARGET_EXTENSION) String targetExtension,
|
||||
@RequestParam(SOURCE_MIMETYPE) String sourceMimetype,
|
||||
@RequestParam(TARGET_MIMETYPE) String targetMimetype,
|
||||
@RequestParam(TARGET_EXTENSION) String targetExtension,
|
||||
@RequestParam Map<String, String> requestParameters,
|
||||
@RequestParam (value = TEST_DELAY, required = false) Long testDelay,
|
||||
|
||||
|
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* #%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.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
|
||||
public class AIOControllerHttpRequestTest extends AbstractHttpRequestTest
|
||||
{
|
||||
|
||||
@Override
|
||||
protected String getTransformerName()
|
||||
{
|
||||
return "All in One Transformer";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getSourceExtension()
|
||||
{
|
||||
// Currently using same extension as ImageMagick tests
|
||||
return "jpg";
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* #%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 java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.alfresco.transformer.transformers.ImageMagickAdapter;
|
||||
import org.alfresco.transformer.transformers.Transformer;
|
||||
import org.junit.Before;
|
||||
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 ImageMagick transforms without a server.
|
||||
* Super class includes tests for the AbstractTransformerController.
|
||||
*/
|
||||
public class AIOControllerImageMagickTest extends ImageMagickControllerTest
|
||||
{
|
||||
// All tests contained in ImageMagickControllerTest
|
||||
|
||||
ImageMagickAdapter adapter;
|
||||
|
||||
@Autowired
|
||||
AIOTransformRegistry transformRegistry;
|
||||
|
||||
@PostConstruct
|
||||
private void init() throws Exception
|
||||
{
|
||||
adapter = new ImageMagickAdapter(EXE, DYN, ROOT);
|
||||
}
|
||||
|
||||
@Before @Override
|
||||
public void before() throws IOException
|
||||
{
|
||||
ReflectionTestUtils.setField(commandExecutor, "transformCommand", mockTransformCommand);
|
||||
ReflectionTestUtils.setField(commandExecutor, "checkCommand", mockCheckCommand);
|
||||
ReflectionTestUtils.setField(adapter, "commandExecutor", commandExecutor);
|
||||
//Need to wire in the mocked adapter into the controller...
|
||||
if (ReflectionTestUtils.getField(transformRegistry,"transformerTransformMapping") instanceof Map)
|
||||
{
|
||||
Map<String,Transformer> transformers = transformRegistry.getTransformerTransformMapping();
|
||||
transformers.replace("imagemagick", adapter);
|
||||
ReflectionTestUtils.setField(transformRegistry, "transformerTransformMapping", transformers);
|
||||
}
|
||||
|
||||
mockTransformCommand("jpg", "png", "image/jpeg", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractTransformerController getController()
|
||||
{
|
||||
return controller;
|
||||
}
|
||||
|
||||
@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
|
||||
@Override
|
||||
public void noTargetFileTest()
|
||||
{
|
||||
// Ignore the test in super class as the AIO transforms will not be selected .
|
||||
// It is the mock that returns a zero length file for other transformers, when we supply an invalid targetExtension.
|
||||
}
|
||||
|
||||
@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,41 @@
|
||||
/*
|
||||
* #%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.apache.commons.lang3.tuple.Pair;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class AIOImageMagickIT extends ImageMagickTransformationIT
|
||||
{
|
||||
//Tests are in ImageMagickTransformationIT
|
||||
public AIOImageMagickIT(final Pair<TestFileInfo, Pair<String,String>> entry)
|
||||
{
|
||||
super(entry);
|
||||
}
|
||||
}
|
@@ -81,19 +81,23 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<systemPropertyVariables>
|
||||
<IMAGEMAGICK_EXE>/usr/bin/convert</IMAGEMAGICK_EXE>
|
||||
<IMAGEMAGICK_DYN>/usr/lib64/ImageMagick-7.0.7/lib</IMAGEMAGICK_DYN>
|
||||
<IMAGEMAGICK_ROOT>/usr/lib64/ImageMagick-7.0.7</IMAGEMAGICK_ROOT>
|
||||
<buildDirectory>${project.build.directory}</buildDirectory>
|
||||
</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>
|
||||
|
||||
|
@@ -27,6 +27,7 @@
|
||||
package org.alfresco.transformer;
|
||||
|
||||
import static org.alfresco.transformer.executors.RuntimeExec.ExecutionResult;
|
||||
import static org.alfresco.transformer.util.MimetypeMap.PREFIX_IMAGE;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
@@ -66,9 +67,9 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
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;
|
||||
@@ -91,22 +92,22 @@ public class ImageMagickControllerTest extends AbstractTransformerControllerTest
|
||||
private static final String ENGINE_CONFIG_NAME = "imagemagick_engine_config.json";
|
||||
|
||||
@Mock
|
||||
private ExecutionResult mockExecutionResult;
|
||||
protected ExecutionResult mockExecutionResult;
|
||||
|
||||
@Mock
|
||||
private RuntimeExec mockTransformCommand;
|
||||
protected RuntimeExec mockTransformCommand;
|
||||
|
||||
@Mock
|
||||
private RuntimeExec mockCheckCommand;
|
||||
protected RuntimeExec mockCheckCommand;
|
||||
|
||||
@Value("${transform.core.imagemagick.exe}")
|
||||
private String EXE;
|
||||
protected String EXE;
|
||||
|
||||
@Value("${transform.core.imagemagick.dyn}")
|
||||
private String DYN;
|
||||
protected String DYN;
|
||||
|
||||
@Value("${transform.core.imagemagick.root}")
|
||||
private String ROOT;
|
||||
protected String ROOT;
|
||||
|
||||
ImageMagickCommandExecutor commandExecutor;
|
||||
|
||||
@@ -116,8 +117,8 @@ public class ImageMagickControllerTest extends AbstractTransformerControllerTest
|
||||
commandExecutor = new ImageMagickCommandExecutor(EXE, DYN, ROOT);
|
||||
}
|
||||
|
||||
@SpyBean
|
||||
private ImageMagickController controller;
|
||||
@Autowired
|
||||
protected AbstractTransformerController controller;
|
||||
|
||||
@Before
|
||||
public void before() throws IOException
|
||||
@@ -143,6 +144,7 @@ public class ImageMagickControllerTest extends AbstractTransformerControllerTest
|
||||
this.sourceExtension = sourceExtension;
|
||||
this.targetExtension = targetExtension;
|
||||
this.sourceMimetype = sourceMimetype;
|
||||
this.targetMimetype = PREFIX_IMAGE + targetExtension;
|
||||
|
||||
expectedOptions = null;
|
||||
expectedSourceSuffix = null;
|
||||
@@ -226,6 +228,8 @@ public class ImageMagickControllerTest extends AbstractTransformerControllerTest
|
||||
.multipart("/transform")
|
||||
.file(sourceFile)
|
||||
.param("targetExtension", targetExtension)
|
||||
.param("targetMimetype", targetMimetype)
|
||||
.param("sourceMimetype", sourceMimetype)
|
||||
.param("cropGravity", value))
|
||||
.andExpect(status().is(OK.value()))
|
||||
.andExpect(content().bytes(expectedTargetFileBytes))
|
||||
@@ -242,6 +246,8 @@ public class ImageMagickControllerTest extends AbstractTransformerControllerTest
|
||||
.multipart("/transform")
|
||||
.file(sourceFile)
|
||||
.param("targetExtension", targetExtension)
|
||||
.param("targetMimetype", targetMimetype)
|
||||
.param("sourceMimetype", sourceMimetype)
|
||||
.param("cropGravity", "badValue"))
|
||||
.andExpect(status().is(BAD_REQUEST.value()));
|
||||
}
|
||||
@@ -256,6 +262,8 @@ public class ImageMagickControllerTest extends AbstractTransformerControllerTest
|
||||
.multipart("/transform")
|
||||
.file(sourceFile)
|
||||
.param("targetExtension", targetExtension)
|
||||
.param("targetMimetype", targetMimetype)
|
||||
.param("sourceMimetype", sourceMimetype)
|
||||
|
||||
.param("startPage", "2")
|
||||
.param("endPage", "3")
|
||||
@@ -292,6 +300,8 @@ public class ImageMagickControllerTest extends AbstractTransformerControllerTest
|
||||
.multipart("/transform")
|
||||
.file(sourceFile)
|
||||
.param("targetExtension", targetExtension)
|
||||
.param("targetMimetype", targetMimetype)
|
||||
.param("sourceMimetype", sourceMimetype)
|
||||
|
||||
.param("startPage", "2")
|
||||
.param("endPage", "3")
|
||||
@@ -328,6 +338,8 @@ public class ImageMagickControllerTest extends AbstractTransformerControllerTest
|
||||
.multipart("/transform")
|
||||
.file(sourceFile)
|
||||
.param("targetExtension", targetExtension)
|
||||
.param("targetMimetype", targetMimetype)
|
||||
.param("sourceMimetype", sourceMimetype)
|
||||
.param("thumbnail", "false")
|
||||
.param("resizeWidth", "321")
|
||||
.param("resizeHeight", "654")
|
||||
@@ -374,8 +386,10 @@ public class ImageMagickControllerTest extends AbstractTransformerControllerTest
|
||||
transformRequest.setTransformRequestOptions(new HashMap<>());
|
||||
transformRequest.setSourceReference(sourceFileRef);
|
||||
transformRequest.setSourceExtension(sourceExtension);
|
||||
transformRequest.setSourceMediaType(sourceMimetype);
|
||||
transformRequest.setSourceSize(sourceFile.length());
|
||||
transformRequest.setTargetExtension(targetExtension);
|
||||
transformRequest.setTargetMediaType(targetMimetype);
|
||||
|
||||
// HTTP Request
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
|
@@ -28,13 +28,49 @@ 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_IMAGE_RAW_3FR;
|
||||
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_ARW;
|
||||
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_BMP;
|
||||
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_CGM;
|
||||
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_CR2;
|
||||
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_DNG;
|
||||
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_APPLICATION_EPS;
|
||||
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_GIF;
|
||||
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_IEF;
|
||||
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_JP2;
|
||||
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_JPEG;
|
||||
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_K25;
|
||||
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_MRW;
|
||||
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_NEF;
|
||||
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_ORF;
|
||||
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_PBM;
|
||||
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_PEF;
|
||||
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_PGM;
|
||||
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_PNG;
|
||||
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_PNM;
|
||||
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_PPJ;
|
||||
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_PPM;
|
||||
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_PSD;
|
||||
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_R3D;
|
||||
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_RAF;
|
||||
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAS;
|
||||
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_RW2;
|
||||
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_RWL;
|
||||
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_TIFF;
|
||||
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_X3F;
|
||||
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_XBM;
|
||||
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_XPM;
|
||||
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_XWD;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.springframework.http.HttpStatus.OK;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@@ -57,23 +93,72 @@ public class ImageMagickTransformationIT
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(ImageMagickTransformationIT.class);
|
||||
private static final String ENGINE_URL = "http://localhost:8090";
|
||||
private static final List<String> targetMimetypes = ImmutableList.of(
|
||||
"3fr", "arw", "bmp", "cgm",
|
||||
"cr2", "dng", "eps", "gif", "ief", "jp2", "jpg",
|
||||
"k25", "mrw", "nef", "orf", "pbm", "pef", "pgm", "png", "pnm", "ppj", "ppm",
|
||||
"psd", "r3d", "raf", "ras", "rw2", "rwl", "tiff", "x3f", "xbm", "xpm", "xwd");
|
||||
private static final List<Pair<String,String>> targetExtensions = new ImmutableList.Builder<Pair<String,String>>()
|
||||
.add(Pair.of("3fr",MIMETYPE_IMAGE_RAW_3FR))
|
||||
.add(Pair.of("arw",MIMETYPE_IMAGE_RAW_ARW))
|
||||
.add(Pair.of("bmp",MIMETYPE_IMAGE_BMP))
|
||||
.add(Pair.of("cgm",MIMETYPE_IMAGE_CGM))
|
||||
.add(Pair.of("cr2",MIMETYPE_IMAGE_RAW_CR2))
|
||||
.add(Pair.of("dng",MIMETYPE_IMAGE_RAW_DNG))
|
||||
.add(Pair.of("eps",MIMETYPE_APPLICATION_EPS))
|
||||
.add(Pair.of("gif",MIMETYPE_IMAGE_GIF))
|
||||
.add(Pair.of("ief",MIMETYPE_IMAGE_IEF))
|
||||
.add(Pair.of("jp2",MIMETYPE_IMAGE_JP2))
|
||||
.add(Pair.of("jpg",MIMETYPE_IMAGE_JPEG))
|
||||
.add(Pair.of("k25",MIMETYPE_IMAGE_RAW_K25))
|
||||
.add(Pair.of("mrw",MIMETYPE_IMAGE_RAW_MRW))
|
||||
.add(Pair.of("nef",MIMETYPE_IMAGE_RAW_NEF))
|
||||
.add(Pair.of("orf",MIMETYPE_IMAGE_RAW_ORF))
|
||||
.add(Pair.of("pbm",MIMETYPE_IMAGE_PBM))
|
||||
.add(Pair.of("pef",MIMETYPE_IMAGE_RAW_PEF))
|
||||
.add(Pair.of("pgm",MIMETYPE_IMAGE_PGM))
|
||||
.add(Pair.of("png",MIMETYPE_IMAGE_PNG))
|
||||
.add(Pair.of("pnm",MIMETYPE_IMAGE_PNM))
|
||||
.add(Pair.of("ppj",MIMETYPE_IMAGE_PPJ))
|
||||
.add(Pair.of("ppm",MIMETYPE_IMAGE_PPM))
|
||||
.add(Pair.of("psd",MIMETYPE_IMAGE_PSD))
|
||||
.add(Pair.of("r3d",MIMETYPE_IMAGE_RAW_R3D))
|
||||
.add(Pair.of("raf",MIMETYPE_IMAGE_RAW_RAF))
|
||||
.add(Pair.of("ras",MIMETYPE_IMAGE_RAS))
|
||||
.add(Pair.of("rw2",MIMETYPE_IMAGE_RAW_RW2))
|
||||
.add(Pair.of("rwl",MIMETYPE_IMAGE_RAW_RWL))
|
||||
.add(Pair.of("tiff",MIMETYPE_IMAGE_TIFF))
|
||||
.add(Pair.of("x3f",MIMETYPE_IMAGE_RAW_X3F))
|
||||
.add(Pair.of("xbm",MIMETYPE_IMAGE_XBM))
|
||||
.add(Pair.of("xpm",MIMETYPE_IMAGE_XPM))
|
||||
.add(Pair.of("xwd",MIMETYPE_IMAGE_XWD))
|
||||
.build();
|
||||
|
||||
private static final Map<String, TestFileInfo> TEST_FILES = Stream.of(
|
||||
testFile(MIMETYPE_IMAGE_BMP,"bmp","quick.bmp"),
|
||||
testFile(MIMETYPE_APPLICATION_EPS,"eps","quick.eps"),
|
||||
testFile(MIMETYPE_IMAGE_GIF,"gif","quick.gif"),
|
||||
testFile(MIMETYPE_IMAGE_JPEG,"jpg","quick.jpg"),
|
||||
testFile(MIMETYPE_IMAGE_PBM,"pbm","quick.pbm"),
|
||||
testFile(MIMETYPE_IMAGE_PGM,"pgm","quick.pgm"),
|
||||
testFile(MIMETYPE_IMAGE_PNG,"png","quick.png"),
|
||||
testFile(MIMETYPE_IMAGE_PNM,"pnm","quick.pnm"),
|
||||
testFile(MIMETYPE_IMAGE_PPM,"ppm","quick.ppm"),
|
||||
testFile(MIMETYPE_IMAGE_XBM,"xbm","quick.xbm"),
|
||||
testFile(MIMETYPE_IMAGE_XPM,"xpm","quick.xpm"),
|
||||
testFile(MIMETYPE_IMAGE_XWD,"xwd","quick.xwd")
|
||||
).collect(toMap(TestFileInfo::getPath, identity()));;
|
||||
|
||||
private final String sourceFile;
|
||||
private final String targetExtension;
|
||||
private final String sourceMimetype;
|
||||
private final String targetMimetype;
|
||||
|
||||
public ImageMagickTransformationIT(final Pair<String, String> entry)
|
||||
public ImageMagickTransformationIT(final Pair<TestFileInfo, Pair<String,String>> entry)
|
||||
{
|
||||
sourceFile = entry.getLeft();
|
||||
targetExtension = entry.getLeft();
|
||||
sourceFile = entry.getLeft().getPath();
|
||||
targetExtension = entry.getRight().getLeft();
|
||||
sourceMimetype = entry.getLeft().getMimeType();
|
||||
targetMimetype = entry.getRight().getRight();
|
||||
}
|
||||
|
||||
@Parameterized.Parameters
|
||||
public static Set<Pair<String, String>> engineTransformations()
|
||||
public static Set<Pair<TestFileInfo, Pair<String,String>>> engineTransformations()
|
||||
{
|
||||
return Stream
|
||||
.of(
|
||||
@@ -99,12 +184,12 @@ public class ImageMagickTransformationIT
|
||||
@Test
|
||||
public void testTransformation()
|
||||
{
|
||||
final String descriptor = format("Transform ({0} -> {1})", sourceFile, null,
|
||||
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)
|
||||
@@ -113,10 +198,10 @@ public class ImageMagickTransformationIT
|
||||
}
|
||||
}
|
||||
|
||||
private static Stream<Pair<String, String>> allTargets(final String sourceFile)
|
||||
private static Stream<Pair<TestFileInfo, Pair<String,String>>> allTargets(final String sourceFile)
|
||||
{
|
||||
return targetMimetypes
|
||||
return targetExtensions
|
||||
.stream()
|
||||
.map(k -> Pair.of(sourceFile, k));
|
||||
.map(k -> Pair.of(TEST_FILES.get(sourceFile), k));
|
||||
}
|
||||
}
|
||||
|
@@ -69,11 +69,22 @@ public interface MimetypeMap
|
||||
String MIMETYPE_APPLICATION_FLA = "application/x-fla";
|
||||
String MIMETYPE_VIDEO_MPG = "video/mpeg";
|
||||
String MIMETYPE_VIDEO_MP4 = "video/mp4";
|
||||
String MIMETYPE_IMAGE_BMP = "image/bmp";
|
||||
String MIMETYPE_IMAGE_CGM = "image/cgm";
|
||||
String MIMETYPE_IMAGE_GIF = "image/gif";
|
||||
String MIMETYPE_IMAGE_IEF = "image/ief";
|
||||
String MIMETYPE_IMAGE_JPEG = "image/jpeg";
|
||||
String MIMETYPE_IMAGE_JP2 = "image/jp2";
|
||||
String MIMETYPE_IMAGE_RGB = "image/x-rgb";
|
||||
String MIMETYPE_IMAGE_SVG = "image/svg+xml";
|
||||
String MIMETYPE_IMAGE_PBM = "image/x-portable-bitmap";
|
||||
String MIMETYPE_IMAGE_PGM = "image/x-portable-graymap";
|
||||
String MIMETYPE_IMAGE_PNM = "image/x-portable-anymap";
|
||||
String MIMETYPE_IMAGE_PNG = "image/png";
|
||||
String MIMETYPE_IMAGE_PPM = "image/x-portable-pixmap";
|
||||
String MIMETYPE_IMAGE_PPJ = "image/vnd.adobe.premiere";
|
||||
String MIMETYPE_IMAGE_PSD = "image/vnd.adobe.photoshop";
|
||||
String MIMETYPE_IMAGE_RAS = "image/x-cmu-raster";
|
||||
String MIMETYPE_IMAGE_TIFF = "image/tiff";
|
||||
String MIMETYPE_IMAGE_RAW_DNG = "image/x-raw-adobe";
|
||||
String MIMETYPE_IMAGE_RAW_3FR = "image/x-raw-hasselblad";
|
||||
@@ -90,6 +101,9 @@ public interface MimetypeMap
|
||||
String MIMETYPE_IMAGE_RAW_RWL = "image/x-raw-leica";
|
||||
String MIMETYPE_IMAGE_RAW_R3D = "image/x-raw-red";
|
||||
String MIMETYPE_IMAGE_DWT = "image/x-dwt";
|
||||
String MIMETYPE_IMAGE_XBM = "image/x-xbitmap";
|
||||
String MIMETYPE_IMAGE_XPM = "image/x-xpixmap";
|
||||
String MIMETYPE_IMAGE_XWD = "image/x-xwindowdump";
|
||||
String MIMETYPE_APPLICATION_EPS = "application/eps";
|
||||
String MIMETYPE_APPLICATION_PS = "application/postscript";
|
||||
String MIMETYPE_JAVASCRIPT = "application/x-javascript";
|
||||
|
@@ -26,6 +26,7 @@
|
||||
*/
|
||||
package org.alfresco.transformer;
|
||||
|
||||
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
@@ -63,7 +64,9 @@ import org.alfresco.transform.client.model.config.Transformer;
|
||||
import org.alfresco.transform.client.registry.TransformServiceRegistry;
|
||||
import org.alfresco.transformer.clients.AlfrescoSharedFileStoreClient;
|
||||
import org.alfresco.transformer.probes.ProbeTestTransform;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.boot.test.mock.mockito.SpyBean;
|
||||
@@ -84,6 +87,9 @@ import com.google.common.collect.ImmutableSet;
|
||||
*/
|
||||
public abstract class AbstractTransformerControllerTest
|
||||
{
|
||||
@Rule // added as part of ATS-702 to allow test resources to be read from the imported jar files to prevent test resource duplication
|
||||
public TemporaryFolder folder= new TemporaryFolder();
|
||||
|
||||
@Autowired
|
||||
protected MockMvc mockMvc;
|
||||
|
||||
@@ -99,6 +105,7 @@ public abstract class AbstractTransformerControllerTest
|
||||
protected String sourceExtension;
|
||||
protected String targetExtension;
|
||||
protected String sourceMimetype;
|
||||
protected String targetMimetype;
|
||||
|
||||
protected MockMultipartFile sourceFile;
|
||||
protected String expectedOptions;
|
||||
@@ -162,6 +169,7 @@ public abstract class AbstractTransformerControllerTest
|
||||
|
||||
protected File getTestFile(String testFilename, boolean required) throws IOException
|
||||
{
|
||||
File testFile = null;
|
||||
ClassLoader classLoader = getClass().getClassLoader();
|
||||
URL testFileUrl = classLoader.getResource(testFilename);
|
||||
if (required && testFileUrl == null)
|
||||
@@ -169,7 +177,28 @@ public abstract class AbstractTransformerControllerTest
|
||||
throw new IOException("The test file " + testFilename +
|
||||
" does not exist in the resources directory");
|
||||
}
|
||||
return testFileUrl == null ? null : new File(URLDecoder.decode(testFileUrl.getPath(), "UTF-8"));
|
||||
// added as part of ATS-702 to allow test resources to be read from the imported jar files to prevent test resource duplication
|
||||
if(testFileUrl!=null)
|
||||
{
|
||||
try
|
||||
{
|
||||
testFile = folder.newFile(testFilename);
|
||||
Files.copy(classLoader.getResourceAsStream(testFilename), testFile.toPath(),REPLACE_EXISTING);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
if(e.getMessage().contains("a file with the name \'" + testFilename + "\' already exists in the test folder"))
|
||||
{
|
||||
testFile = new File(URLDecoder.decode(folder.getRoot().getPath()+ File.separator + testFilename, "UTF-8"));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return testFileUrl == null ? null : testFile;
|
||||
}
|
||||
|
||||
protected MockHttpServletRequestBuilder mockMvcRequest(String url, MockMultipartFile sourceFile,
|
||||
|
6
pom.xml
6
pom.xml
@@ -342,6 +342,12 @@
|
||||
<configuration>
|
||||
<forkCount>1</forkCount>
|
||||
<reuseForks>true</reuseForks>
|
||||
<systemPropertyVariables>
|
||||
<IMAGEMAGICK_EXE>/usr/bin/convert</IMAGEMAGICK_EXE>
|
||||
<IMAGEMAGICK_DYN>/usr/lib64/ImageMagick-7.0.7/lib</IMAGEMAGICK_DYN>
|
||||
<IMAGEMAGICK_ROOT>/usr/lib64/ImageMagick-7.0.7</IMAGEMAGICK_ROOT>
|
||||
<buildDirectory>${project.build.directory}</buildDirectory>
|
||||
</systemPropertyVariables>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
|
Reference in New Issue
Block a user