ACS-930 Security update to spring boot 2.4.1 (#321)

* ACS-930 Upgrade to Junit5
This commit is contained in:
David Edwards
2021-01-15 10:31:25 +00:00
committed by GitHub
parent 0060461695
commit ef21365e00
55 changed files with 647 additions and 836 deletions

View File

@@ -59,11 +59,6 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>

View File

@@ -2,7 +2,7 @@
* #%L
* Alfresco Transform Core
* %%
* Copyright (C) 2005 - 2020 Alfresco Software Limited
* Copyright (C) 2005 - 2021 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
@@ -26,44 +26,11 @@
*/
package org.alfresco.transformer;
import org.alfresco.transform.client.model.TransformReply;
import org.alfresco.transform.client.model.TransformRequest;
import org.alfresco.transformer.executors.ImageMagickCommandExecutor;
import org.alfresco.transformer.executors.RuntimeExec;
import org.alfresco.transformer.model.FileRefEntity;
import org.alfresco.transformer.model.FileRefResponse;
import org.junit.Before;
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.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
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.MockMvcRequestBuilders;
import javax.annotation.PostConstruct;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
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;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.when;
@@ -80,12 +47,47 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.util.StringUtils.getFilenameExtension;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import javax.annotation.PostConstruct;
import org.alfresco.transform.client.model.TransformReply;
import org.alfresco.transform.client.model.TransformRequest;
import org.alfresco.transformer.executors.ImageMagickCommandExecutor;
import org.alfresco.transformer.executors.RuntimeExec;
import org.alfresco.transformer.executors.RuntimeExec.ExecutionResult;
import org.alfresco.transformer.model.FileRefEntity;
import org.alfresco.transformer.model.FileRefResponse;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
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.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
/**
* Test the ImageMagickController without a server.
* Super class includes tests for the AbstractTransformerController.
*/
@RunWith(SpringRunner.class)
@WebMvcTest(ImageMagickController.class)
// Specifying class for @WebMvcTest() will break AIO tests, without specifying it will use all controllers in the application context,
// currently only ImageMagickController.class
@WebMvcTest()
public class ImageMagickControllerTest extends AbstractTransformerControllerTest
{
private static final String ENGINE_CONFIG_NAME = "imagemagick_engine_config.json";
@@ -125,7 +127,7 @@ public class ImageMagickControllerTest extends AbstractTransformerControllerTest
@Autowired
protected AbstractTransformerController controller;
@Before
@BeforeEach
public void before() throws IOException
{
ReflectionTestUtils.setField(commandExecutor, "transformCommand", mockTransformCommand);
@@ -161,7 +163,7 @@ public class ImageMagickControllerTest extends AbstractTransformerControllerTest
when(mockTransformCommand.execute(any(), anyLong())).thenAnswer(
(Answer<RuntimeExec.ExecutionResult>) invocation -> {
Map<String, String> actualProperties = invocation.getArgument(0);
assertEquals("There should be 3 properties", 3, actualProperties.size());
assertEquals(3, actualProperties.size(), "There should be 3 properties");
String actualOptions = actualProperties.get("options");
String actualSource = actualProperties.get("source");
@@ -170,26 +172,23 @@ public class ImageMagickControllerTest extends AbstractTransformerControllerTest
assertNotNull(actualSource);
assertNotNull(actualTarget);
if (expectedSourceSuffix != null)
{
assertTrue(
"The source file \"" + actualSource + "\" should have ended in \"" + expectedSourceSuffix + "\"",
actualSource.endsWith(expectedSourceSuffix));
actualSource = actualSource.substring(0,
actualSource.length() - expectedSourceSuffix.length());
if (expectedSourceSuffix != null) {
assertTrue(actualSource.endsWith(expectedSourceSuffix),
"The source file \"" + actualSource + "\" should have ended in \"" + expectedSourceSuffix + "\"");
actualSource = actualSource.substring(0, actualSource.length() - expectedSourceSuffix.length());
}
assertNotNull(actualOptions);
if (expectedOptions != null)
{
assertEquals("expectedOptions", expectedOptions, actualOptions);
assertEquals(expectedOptions, actualOptions,"expectedOptions");
}
Long actualTimeout = invocation.getArgument(1);
assertNotNull(actualTimeout);
if (expectedTimeout != null)
{
assertEquals("expectedTimeout", expectedTimeout, actualTimeout);
assertEquals(expectedTimeout, actualTimeout,"expectedTimeout");
}
// Copy a test file into the target file location if it exists
@@ -205,8 +204,8 @@ public class ImageMagickControllerTest extends AbstractTransformerControllerTest
// Check the supplied source file has not been changed.
byte[] actualSourceFileBytes = Files.readAllBytes(new File(actualSource).toPath());
assertTrue("Source file is not the same",
Arrays.equals(expectedSourceFileBytes, actualSourceFileBytes));
assertTrue(Arrays.equals(expectedSourceFileBytes, actualSourceFileBytes),
"Source file is not the same");
return mockExecutionResult;
});
@@ -222,25 +221,23 @@ public class ImageMagickControllerTest extends AbstractTransformerControllerTest
return controller;
}
@Test
public void cropGravityGoodTest() throws Exception
@ParameterizedTest
@ValueSource(strings = {"North", "NorthEast", "East", "SouthEast", "South", "SouthWest", "West", "NorthWest", "Center"})
public void cropGravityGoodTest(String value) throws Exception
{
for (String value : new String[]{"North", "NorthEast", "East", "SouthEast", "South", "SouthWest", "West", "NorthWest", "Center"})
{
expectedOptions = "-auto-orient " + "-gravity " + value + " +repage";
mockMvc
.perform(MockMvcRequestBuilders
.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))
.andExpect(header().string("Content-Disposition",
"attachment; filename*= UTF-8''quick." + targetExtension));
}
expectedOptions = "-auto-orient " + "-gravity " + value + " +repage";
mockMvc
.perform(MockMvcRequestBuilders
.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))
.andExpect(header().string("Content-Disposition",
"attachment; filename*= UTF-8''quick." + targetExtension));
}
@Test

View File

@@ -26,16 +26,12 @@
*/
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;
/**
* Tests ImageMagickController with a server test harness.
*/
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class ImageMagickHttpRequestTest extends AbstractHttpRequestTest
{
@Override

View File

@@ -2,7 +2,7 @@
* #%L
* Alfresco Transform Core
* %%
* Copyright (C) 2005 - 2019 Alfresco Software Limited
* Copyright (C) 2005 - 2021 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
@@ -32,15 +32,12 @@ import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_IMAGE_PNG;
import java.util.UUID;
import org.alfresco.transform.client.model.TransformRequest;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
/**
* @author Lucian Tuca
* created on 15/01/2019
*/
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = {"activemq.url=nio://localhost:61616"})
public class ImageMagickQueueTransformServiceIT extends AbstractQueueTransformServiceIT

View File

@@ -30,210 +30,192 @@ import static java.text.MessageFormat.format;
import static java.util.Collections.emptyMap;
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_APPLICATION_EPS;
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_RAS;
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_RAW_CR2;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_IMAGE_RAW_DNG;
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_RAW_PEF;
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_TIFF;
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.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.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;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import org.apache.commons.lang3.tuple.Pair;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.Resource;
import org.springframework.http.ResponseEntity;
import com.google.common.collect.ImmutableList;
/**
* @author Cezar Leahu
*/
@RunWith(Parameterized.class)
public class ImageMagickTransformationIT
{
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<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("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 List<Pair<String,String>> targetExtensionsForPSD = new ImmutableList.Builder<Pair<String,String>>()
.add(Pair.of("x3f",MIMETYPE_IMAGE_RAW_X3F))
.add(Pair.of("tiff",MIMETYPE_IMAGE_TIFF))
.add(Pair.of("rwl",MIMETYPE_IMAGE_RAW_RWL))
.add(Pair.of("rw2",MIMETYPE_IMAGE_RAW_RW2))
.add(Pair.of("ras",MIMETYPE_IMAGE_RAS))
.add(Pair.of("raf",MIMETYPE_IMAGE_RAW_RAF))
.add(Pair.of("r3d",MIMETYPE_IMAGE_RAW_R3D))
.add(Pair.of("psd",MIMETYPE_IMAGE_PSD))
.add(Pair.of("ppm",MIMETYPE_IMAGE_PPM))
.add(Pair.of("ppj",MIMETYPE_IMAGE_PPJ))
.add(Pair.of("pnm",MIMETYPE_IMAGE_PNM))
.add(Pair.of("pgm",MIMETYPE_IMAGE_PGM))
.add(Pair.of("pef",MIMETYPE_IMAGE_RAW_PEF))
.add(Pair.of("pbm",MIMETYPE_IMAGE_PBM))
.add(Pair.of("orf",MIMETYPE_IMAGE_RAW_ORF))
.add(Pair.of("nef",MIMETYPE_IMAGE_RAW_NEF))
.add(Pair.of("mrw",MIMETYPE_IMAGE_RAW_MRW))
.add(Pair.of("k25",MIMETYPE_IMAGE_RAW_K25))
.add(Pair.of("ief",MIMETYPE_IMAGE_IEF))
.add(Pair.of("gif",MIMETYPE_IMAGE_GIF))
.add(Pair.of("dng",MIMETYPE_IMAGE_RAW_DNG))
.add(Pair.of("cr2",MIMETYPE_IMAGE_RAW_CR2))
.add(Pair.of("arw",MIMETYPE_IMAGE_RAW_ARW))
.add(Pair.of("3fr",MIMETYPE_IMAGE_RAW_3FR))
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("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 List<Pair<String,String>> targetExtensionsForTiffFirstPage = new ImmutableList.Builder<Pair<String,String>>()
.add(Pair.of("bmp",MIMETYPE_IMAGE_BMP))
.add(Pair.of("eps",MIMETYPE_APPLICATION_EPS))
.add(Pair.of("jp2",MIMETYPE_IMAGE_JP2))
.add(Pair.of("jpg",MIMETYPE_IMAGE_JPEG))
.add(Pair.of("png",MIMETYPE_IMAGE_PNG))
.add(Pair.of("xbm",MIMETYPE_IMAGE_XBM))
.add(Pair.of("xpm",MIMETYPE_IMAGE_XPM))
.add(Pair.of("xwd",MIMETYPE_IMAGE_XWD))
private static final List<Pair<String, String>> targetExtensionsForPSD = new ImmutableList.Builder<Pair<String, String>>()
.add(Pair.of("x3f", MIMETYPE_IMAGE_RAW_X3F))
.add(Pair.of("tiff", MIMETYPE_IMAGE_TIFF))
.add(Pair.of("rwl", MIMETYPE_IMAGE_RAW_RWL))
.add(Pair.of("rw2", MIMETYPE_IMAGE_RAW_RW2))
.add(Pair.of("ras", MIMETYPE_IMAGE_RAS))
.add(Pair.of("raf", MIMETYPE_IMAGE_RAW_RAF))
.add(Pair.of("r3d", MIMETYPE_IMAGE_RAW_R3D))
.add(Pair.of("psd", MIMETYPE_IMAGE_PSD))
.add(Pair.of("ppm", MIMETYPE_IMAGE_PPM))
.add(Pair.of("ppj", MIMETYPE_IMAGE_PPJ))
.add(Pair.of("pnm", MIMETYPE_IMAGE_PNM))
.add(Pair.of("pgm", MIMETYPE_IMAGE_PGM))
.add(Pair.of("pef", MIMETYPE_IMAGE_RAW_PEF))
.add(Pair.of("pbm", MIMETYPE_IMAGE_PBM))
.add(Pair.of("orf", MIMETYPE_IMAGE_RAW_ORF))
.add(Pair.of("nef", MIMETYPE_IMAGE_RAW_NEF))
.add(Pair.of("mrw", MIMETYPE_IMAGE_RAW_MRW))
.add(Pair.of("k25", MIMETYPE_IMAGE_RAW_K25))
.add(Pair.of("ief", MIMETYPE_IMAGE_IEF))
.add(Pair.of("gif", MIMETYPE_IMAGE_GIF))
.add(Pair.of("dng", MIMETYPE_IMAGE_RAW_DNG))
.add(Pair.of("cr2", MIMETYPE_IMAGE_RAW_CR2))
.add(Pair.of("arw", MIMETYPE_IMAGE_RAW_ARW))
.add(Pair.of("3fr", MIMETYPE_IMAGE_RAW_3FR))
.build();
private static final List<Pair<String, String>> targetExtensionsForTiffFirstPage = new ImmutableList.Builder<Pair<String, String>>()
.add(Pair.of("bmp", MIMETYPE_IMAGE_BMP))
.add(Pair.of("eps", MIMETYPE_APPLICATION_EPS))
.add(Pair.of("jp2", MIMETYPE_IMAGE_JP2))
.add(Pair.of("jpg", MIMETYPE_IMAGE_JPEG))
.add(Pair.of("png", MIMETYPE_IMAGE_PNG))
.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_PSD,"psd","quick.psd"),
testFile(MIMETYPE_IMAGE_TIFF,"tiff","quick.tiff"),
testFile(MIMETYPE_IMAGE_XWD,"xwd","quick.xwd")
).collect(toMap(TestFileInfo::getPath, identity()));
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_PSD, "psd", "quick.psd"),
testFile(MIMETYPE_IMAGE_TIFF, "tiff", "quick.tiff"),
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<TestFileInfo, Pair<String,String>> entry)
{
sourceFile = entry.getLeft().getPath();
targetExtension = entry.getRight().getLeft();
sourceMimetype = entry.getLeft().getMimeType();
targetMimetype = entry.getRight().getRight();
}
@Parameterized.Parameters
public static Set<Pair<TestFileInfo, Pair<String,String>>> engineTransformations()
{
Set<Pair<TestFileInfo, Pair<String,String>>> resolved = null;
resolved = Stream
public static Stream<Pair<TestFileInfo, Pair<String,String>>> engineTransformations() {
return Stream
.of(
allTargets("quick.bmp", targetExtensions),
allTargets("quick.bmp", targetExtensions),
allTargets("quick.eps", targetExtensions),
allTargets("quick.gif", targetExtensions),
allTargets("quick.gif", targetExtensions),
allTargets("quick.jpg", targetExtensions),
allTargets("quick.pbm", targetExtensions),
allTargets("quick.pbm", targetExtensions),
allTargets("quick.pgm", targetExtensions),
allTargets("quick.png", targetExtensions),
allTargets("quick.png", targetExtensions),
allTargets("quick.pnm", targetExtensions),
allTargets("quick.ppm", targetExtensions),
allTargets("quick.ppm", targetExtensions),
allTargets("quick.psd", targetExtensionsForPSD),
allTargets("quick.tiff", targetExtensions),
allTargets("quick.tiff", targetExtensions),
allTargets("quick.xbm", targetExtensions),
allTargets("quick.xpm", targetExtensions),
allTargets("quick.xpm", targetExtensions),
allTargets("quick.xwd", targetExtensions)
)
.flatMap(identity())
.collect(toSet());
return resolved;
).flatMap(identity());
}
@Test
public void testTransformation()
@ParameterizedTest
@MethodSource("engineTransformations")
public void testTransformation(Pair<TestFileInfo, Pair<String, String>> entry)
{
String sourceFile = entry.getLeft().getPath();
String targetExtension = entry.getRight().getLeft();
String sourceMimetype = entry.getLeft().getMimeType();
String targetMimetype = entry.getRight().getRight();
final String descriptor = format("Transform ({0}, {1} -> {2}, {3})",
sourceFile, sourceMimetype, targetMimetype, targetExtension);
try
{
// note: some image/tiff->image/* will return multiple page results (hence error) unless options specified for single page
Map<String, String> tOptions = emptyMap();
Pair targetPair = Pair.of(targetExtension, targetMimetype);
Pair<String,String> targetPair = Pair.of(targetExtension, targetMimetype);
if (MIMETYPE_IMAGE_TIFF.equals(sourceMimetype) && targetExtensionsForTiffFirstPage.contains(targetPair))
{
tOptions = ImmutableMap.of("startPage", "0", "endPage", "0");
@@ -241,7 +223,7 @@ public class ImageMagickTransformationIT
final ResponseEntity<Resource> response = sendTRequest(ENGINE_URL, sourceFile, sourceMimetype,
targetMimetype, targetExtension, tOptions);
assertEquals(descriptor, OK, response.getStatusCode());
assertEquals(OK, response.getStatusCode(), descriptor);
}
catch (Exception e)
{
@@ -256,4 +238,5 @@ public class ImageMagickTransformationIT
.map(k -> Pair.of(TEST_FILES.get(sourceFile), k));
}
}