From afa4d9e266e578d169e9b67c3e17757afe32d579 Mon Sep 17 00:00:00 2001 From: David Edwards Date: Tue, 7 Apr 2020 15:21:40 +0100 Subject: [PATCH] ATS-702 Update tests, undo renaming --- ...nOneController.java => AIOController.java} | 4 +- ...CustomConfig.java => AIOCustomConfig.java} | 2 +- ...java => AIOControllerHttpRequestTest.java} | 2 +- ...java => AIOControllerImageMagickTest.java} | 57 ++- ...rollerTest.java => AIOControllerTest.java} | 8 +- .../AllInOneControllerImageMagickTest.java | 419 ------------------ .../ImageMagickControllerTest.java | 332 +------------- ...ava => ImageMagickControllerTestBase.java} | 16 +- .../ImageMagickControllerTestPOC.java | 75 ---- .../alfresco-transform-tika/pom.xml | 4 + .../AbstractTransformerControllerTest.java | 1 + 11 files changed, 65 insertions(+), 855 deletions(-) rename alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/main/java/org/alfresco/transformer/{AllInOneController.java => AIOController.java} (96%) rename alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/main/java/org/alfresco/transformer/{AllInOneCustomConfig.java => AIOCustomConfig.java} (95%) rename alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/{AllInOneControllerHttpRequestTest.java => AIOControllerHttpRequestTest.java} (92%) rename alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/{AllInOneControllerImageMagickTestPOC.java => AIOControllerImageMagickTest.java} (56%) rename alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/{AllInOneControllerTest.java => AIOControllerTest.java} (89%) delete mode 100644 alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AllInOneControllerImageMagickTest.java rename alfresco-transform-imagemagick/alfresco-transform-imagemagick-boot/src/test/java/org/alfresco/transformer/{ImageMagickControllerTestBasePOC.java => ImageMagickControllerTestBase.java} (94%) delete mode 100644 alfresco-transform-imagemagick/alfresco-transform-imagemagick-boot/src/test/java/org/alfresco/transformer/ImageMagickControllerTestPOC.java diff --git a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/main/java/org/alfresco/transformer/AllInOneController.java b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/main/java/org/alfresco/transformer/AIOController.java similarity index 96% rename from alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/main/java/org/alfresco/transformer/AllInOneController.java rename to alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/main/java/org/alfresco/transformer/AIOController.java index 1e56a5eb..ea021dc5 100644 --- a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/main/java/org/alfresco/transformer/AllInOneController.java +++ b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/main/java/org/alfresco/transformer/AIOController.java @@ -59,9 +59,9 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.multipart.MultipartFile; @Controller -public class AllInOneController extends AbstractTransformerController +public class AIOController extends AbstractTransformerController { - private static final Logger logger = LoggerFactory.getLogger(AllInOneController.class); + private static final Logger logger = LoggerFactory.getLogger(AIOController.class); //TODO Should these be moved to the AbstractTransformerController or are they present in the transform.client? They are used by most controllers... private static final String SOURCE_ENCODING = "sourceEncoding"; diff --git a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/main/java/org/alfresco/transformer/AllInOneCustomConfig.java b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/main/java/org/alfresco/transformer/AIOCustomConfig.java similarity index 95% rename from alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/main/java/org/alfresco/transformer/AllInOneCustomConfig.java rename to alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/main/java/org/alfresco/transformer/AIOCustomConfig.java index 5ea2af5a..86db8fd1 100644 --- a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/main/java/org/alfresco/transformer/AllInOneCustomConfig.java +++ b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/main/java/org/alfresco/transformer/AIOCustomConfig.java @@ -37,7 +37,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; @Configuration -public class AllInOneCustomConfig +public class AIOCustomConfig { @Bean("AllInOneTransformer") diff --git a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AllInOneControllerHttpRequestTest.java b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerHttpRequestTest.java similarity index 92% rename from alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AllInOneControllerHttpRequestTest.java rename to alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerHttpRequestTest.java index 8570ad4f..92891db0 100644 --- a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AllInOneControllerHttpRequestTest.java +++ b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerHttpRequestTest.java @@ -33,7 +33,7 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -public class AllInOneControllerHttpRequestTest extends AbstractHttpRequestTest +public class AIOControllerHttpRequestTest extends AbstractHttpRequestTest { @Override diff --git a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AllInOneControllerImageMagickTestPOC.java b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerImageMagickTest.java similarity index 56% rename from alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AllInOneControllerImageMagickTestPOC.java rename to alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerImageMagickTest.java index bb6afb7e..697eac1e 100644 --- a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AllInOneControllerImageMagickTestPOC.java +++ b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerImageMagickTest.java @@ -28,6 +28,8 @@ package org.alfresco.transformer; import java.io.IOException; import java.util.Map; +import java.util.Arrays; +import java.util.List; import org.alfresco.transformer.transformers.AllInOneTransformer; import org.alfresco.transformer.transformers.ImageMagickAdapter; @@ -40,13 +42,16 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.SpyBean; 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; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; @RunWith(SpringRunner.class) -@WebMvcTest(AllInOneController.class) -@Import(AllInOneCustomConfig.class) -public class AllInOneControllerImageMagickTestPOC extends ImageMagickControllerTestBasePOC +@WebMvcTest(AIOController.class) +@Import(AIOCustomConfig.class) +public class AIOControllerImageMagickTest extends ImageMagickControllerTestBase { static ImageMagickAdapter adapter; @@ -55,7 +60,7 @@ public class AllInOneControllerImageMagickTestPOC extends ImageMagickControllerT AllInOneTransformer transformer; @SpyBean - AllInOneController controller; + AIOController controller; @BeforeClass public static void beforeClass() throws Exception @@ -63,23 +68,22 @@ public class AllInOneControllerImageMagickTestPOC extends ImageMagickControllerT adapter = new ImageMagickAdapter(); } - @Before @SuppressWarnings("unchecked") - public void before() throws IOException + @Before //@SuppressWarnings("unchecked") + public void before() throws IOException, Exception { + adapter = new ImageMagickAdapter(); ReflectionTestUtils.setField(commandExecutor, "transformCommand", mockTransformCommand); ReflectionTestUtils.setField(commandExecutor, "checkCommand", mockCheckCommand); ReflectionTestUtils.setField(adapter, "commandExecutor", commandExecutor); - //Need to wire in the mocked adpater into the controller... - if (ReflectionTestUtils.getField(transformer,"transformerTransformMapping") instanceof Map) - { - Map transformers = (Map)ReflectionTestUtils.getField(transformer,"transformerTransformMapping"); - transformers.replace("imagemagick", adapter); - ReflectionTestUtils.setField(transformer, "transformerTransformMapping", transformers); - } + // //Need to wire in the mocked adpater into the controller... + // if (ReflectionTestUtils.getField(transformer,"transformerTransformMapping") instanceof Map) + // { + // Map transformers = (Map)ReflectionTestUtils.getField(transformer,"transformerTransformMapping"); + // transformers.replace("imagemagick", adapter); + // ReflectionTestUtils.setField(transformer, "transformerTransformMapping", transformers); + // } - ReflectionTestUtils.setField(controller, "transformer",transformer); - - mockTransformCommand("jpg", "png", "image/jpg", true); + mockTransformCommand("jpg", "png", "image/jpeg", true); } @Override @@ -88,14 +92,23 @@ public class AllInOneControllerImageMagickTestPOC extends ImageMagickControllerT return controller; } - //There is currently a bug in the version of the surefire plugin that junit4 uses - //which means that inherited tests are not detected and run if there are no tests - //present in the super class, the below is a workaround. - @Test - public void emptyTest() + @Override + protected MockHttpServletRequestBuilder mockMvcRequest(String url, MockMultipartFile sourceFile, + String... params) { - controller.info(); + 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 we not be selected . + // It is the mock that returns a zero length file for other transformers, when we supply an invalid targetExtension. + } } \ No newline at end of file diff --git a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AllInOneControllerTest.java b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerTest.java similarity index 89% rename from alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AllInOneControllerTest.java rename to alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerTest.java index 0c56d5f2..30b877c6 100644 --- a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AllInOneControllerTest.java +++ b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerTest.java @@ -38,13 +38,13 @@ import org.springframework.context.annotation.Import; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) -@WebMvcTest(AllInOneController.class) -@Import(AllInOneCustomConfig.class) -public class AllInOneControllerTest //extends AbstractTransformerControllerTest +@WebMvcTest(AIOController.class) +@Import(AIOCustomConfig.class) +public class AIOControllerTest //extends AbstractTransformerControllerTest { @Autowired - AllInOneController aioController; + AIOController aioController; //@Override protected void mockTransformCommand(String sourceExtension, String targetExtension, String sourceMimetype, diff --git a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AllInOneControllerImageMagickTest.java b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AllInOneControllerImageMagickTest.java deleted file mode 100644 index 132082b2..00000000 --- a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AllInOneControllerImageMagickTest.java +++ /dev/null @@ -1,419 +0,0 @@ -/* - * #%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 . - * #L% - */ -package org.alfresco.transformer; - -import static org.alfresco.transformer.executors.RuntimeExec.ExecutionResult; -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.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.Mockito.when; -import static org.springframework.http.HttpHeaders.ACCEPT; -import static org.springframework.http.HttpHeaders.CONTENT_DISPOSITION; -import static org.springframework.http.HttpHeaders.CONTENT_TYPE; -import static org.springframework.http.HttpStatus.BAD_REQUEST; -import static org.springframework.http.HttpStatus.CREATED; -import static org.springframework.http.HttpStatus.OK; -import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; -import static org.springframework.http.MediaType.IMAGE_PNG_VALUE; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; -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 org.alfresco.transformer.transformers.AllInOneTransformer; -import org.alfresco.transformer.transformers.ImageMagickAdapter; -import org.alfresco.transformer.transformers.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.BeforeClass; -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.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.SpyBean; -import org.springframework.context.annotation.Import; -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; - -@RunWith(SpringRunner.class) -@WebMvcTest(AllInOneController.class) -@Import(AllInOneCustomConfig.class) -public class AllInOneControllerImageMagickTest extends AbstractTransformerControllerTest -{ - @Mock - private ExecutionResult mockExecutionResult; - - @Mock - private RuntimeExec mockTransformCommand; - - @Mock - private RuntimeExec mockCheckCommand; - - private ImageMagickCommandExecutor commandExecutor = new ImageMagickCommandExecutor(); - - static ImageMagickAdapter adapter; - - @Autowired - AllInOneTransformer transformer; - - @SpyBean - AllInOneController controller; - - @BeforeClass - public static void beforeClass() throws Exception - { - adapter = new ImageMagickAdapter(); - } - - @Before @SuppressWarnings("unchecked") - 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 adpater into the controller... - if (ReflectionTestUtils.getField(transformer,"transformerTransformMapping") instanceof Map) - { - Map transformers = (Map)ReflectionTestUtils.getField(transformer,"transformerTransformMapping"); - transformers.replace("imagemagick", adapter); - ReflectionTestUtils.setField(transformer, "transformerTransformMapping", transformers); - } - //when(transformer.getTransformer("imagemagick")).thenReturn(adapter); - - ReflectionTestUtils.setField(controller, "transformer",transformer); - - mockTransformCommand("jpg", "png", "image/jpg", true); - } - - @Override - protected AbstractTransformerController getController() - { - return this.controller; - } - - @Override - protected void mockTransformCommand(String sourceExtension, - String targetExtension, String sourceMimetype, - boolean readTargetFileBytes) throws IOException - { - this.sourceExtension = sourceExtension; - this.targetExtension = targetExtension; - this.sourceMimetype = sourceMimetype; - - expectedOptions = null; - expectedSourceSuffix = null; - expectedSourceFileBytes = readTestFile(sourceExtension); - expectedTargetFileBytes = readTargetFileBytes ? readTestFile(targetExtension) : null; - sourceFile = new MockMultipartFile("file", "quick." + sourceExtension, sourceMimetype, - expectedSourceFileBytes); - - when(mockTransformCommand.execute(any(), anyLong())).thenAnswer( - (Answer) invocation -> { - Map actualProperties = invocation.getArgument(0); - assertEquals("There should be 3 properties", 3, actualProperties.size()); - - String actualOptions = actualProperties.get("options"); - String actualSource = actualProperties.get("source"); - String actualTarget = actualProperties.get("target"); - String actualTargetExtension = getFilenameExtension(actualTarget); - - 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()); - } - - assertNotNull(actualOptions); - if (expectedOptions != null) - { - assertEquals("expectedOptions", expectedOptions, actualOptions); - } - - Long actualTimeout = invocation.getArgument(1); - assertNotNull(actualTimeout); - if (expectedTimeout != null) - { - assertEquals("expectedTimeout", expectedTimeout, actualTimeout); - } - - // Copy a test file into the target file location if it exists - int i = actualTarget.lastIndexOf('_'); - if (i >= 0) - { - String testFilename = actualTarget.substring(i + 1); - File testFile = getTestFile(testFilename, false); - File targetFile = new File(actualTarget); - generateTargetFileFromResourceFile(actualTargetExtension, testFile, - targetFile); - } - - // 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)); - - return mockExecutionResult; - }); - - when(mockExecutionResult.getExitValue()).thenReturn(0); - when(mockExecutionResult.getStdErr()).thenReturn("STDERROR"); - when(mockExecutionResult.getStdOut()).thenReturn("STDOUT"); - } - - - @Test - public void cropGravityGoodTest() throws Exception - { - for (String value : new String[]{"North", "NorthEast", "East", "SouthEast", "South", "SouthWest", "West", "NorthWest", "Center"}) - { - expectedOptions = "-gravity " + value + " +repage"; - mockMvc - .perform(MockMvcRequestBuilders - .multipart("/transform") - .file(sourceFile) - .param("targetExtension", targetExtension) - .param("cropGravity", value)) - .andExpect(status().is(OK.value())) - .andExpect(content().bytes(expectedTargetFileBytes)) - .andExpect(header().string("Content-Disposition", - "attachment; filename*= UTF-8''quick." + targetExtension)); - } - } - - @Test - public void cropGravityBadTest() throws Exception - { - mockMvc - .perform(MockMvcRequestBuilders - .multipart("/transform") - .file(sourceFile) - .param("targetExtension", targetExtension) - .param("cropGravity", "badValue")) - .andExpect(status().is(BAD_REQUEST.value())); - } - - @Test - public void optionsTest() throws Exception - { - expectedOptions = "-alpha remove -gravity SouthEast -crop 123x456%+90+12 +repage -thumbnail 321x654%!"; - expectedSourceSuffix = "[2-3]"; - mockMvc - .perform(MockMvcRequestBuilders - .multipart("/transform") - .file(sourceFile) - .param("targetExtension", targetExtension) - - .param("startPage", "2") - .param("endPage", "3") - - .param("alphaRemove", "true") - .param("autoOrient", "false") - - .param("cropGravity", "SouthEast") - .param("cropWidth", "123") - .param("cropHeight", "456") - .param("cropPercentage", "true") - .param("cropXOffset", "90") - .param("cropYOffset", "12") - - .param("thumbnail", "true") - .param("resizeWidth", "321") - .param("resizeHeight", "654") - .param("resizePercentage", "true") - .param("allowEnlargement", "true") - .param("maintainAspectRatio", "false")) - .andExpect(status().is(OK.value())) - .andExpect(content().bytes(expectedTargetFileBytes)) - .andExpect(header().string("Content-Disposition", - "attachment; filename*= UTF-8''quick." + targetExtension)); - } - - @Test - public void optionsNegateBooleansTest() throws Exception - { - expectedOptions = "-auto-orient -gravity SouthEast -crop 123x456+90+12 +repage -resize 321x654>"; - expectedSourceSuffix = "[2-3]"; - mockMvc - .perform(MockMvcRequestBuilders - .multipart("/transform") - .file(sourceFile) - .param("targetExtension", targetExtension) - - .param("startPage", "2") - .param("endPage", "3") - - .param("alphaRemove", "false") - .param("autoOrient", "true") - - .param("cropGravity", "SouthEast") - .param("cropWidth", "123") - .param("cropHeight", "456") - .param("cropPercentage", "false") - .param("cropXOffset", "90") - .param("cropYOffset", "12") - - .param("thumbnail", "false") - .param("resizeWidth", "321") - .param("resizeHeight", "654") - .param("resizePercentage", "false") - .param("allowEnlargement", "false") - .param("maintainAspectRatio", "true")) - .andExpect(status().is(OK.value())) - .andExpect(content().bytes(expectedTargetFileBytes)) - .andExpect(header().string("Content-Disposition", - "attachment; filename*= UTF-8''quick." + targetExtension)); - } - - @Test - public void deprecatedCommandOptionsTest() throws Exception - { - // Example of why the commandOptions parameter is a bad idea. - expectedOptions = "( horrible command / ); -resize 321x654>"; - mockMvc - .perform(MockMvcRequestBuilders - .multipart("/transform") - .file(sourceFile) - .param("targetExtension", targetExtension) - .param("thumbnail", "false") - .param("resizeWidth", "321") - .param("resizeHeight", "654") - .param("commandOptions", "( horrible command / );")) - .andExpect(status().is(OK.value())) - .andExpect(content().bytes(expectedTargetFileBytes)) - .andExpect(header().string("Content-Disposition", - "attachment; filename*= UTF-8''quick." + targetExtension)); - } - - @Override - protected void updateTransformRequestWithSpecificOptions(TransformRequest transformRequest) - { - transformRequest.setSourceExtension("png"); - transformRequest.setTargetExtension("png"); - transformRequest.setSourceMediaType(IMAGE_PNG_VALUE); - transformRequest.setTargetMediaType(IMAGE_PNG_VALUE); - } - - @Test - public void badExitCodeTest() throws Exception - { - when(mockExecutionResult.getExitValue()).thenReturn(1); - - mockMvc.perform(mockMvcRequest("/transform", sourceFile, "targetExtension", "xxx")) - .andExpect(status().is(BAD_REQUEST.value())) - .andExpect( - status().reason(containsString("Transformer exit code was not 0: \nSTDERR"))); - } - - @Test - public void testPojoTransform() throws Exception - { - // Files - String sourceFileRef = UUID.randomUUID().toString(); - File sourceFile = getTestFile("quick." + sourceExtension, true); - String targetFileRef = UUID.randomUUID().toString(); - - // Transformation Request POJO - TransformRequest transformRequest = new TransformRequest(); - transformRequest.setRequestId("1"); - transformRequest.setSchema(1); - transformRequest.setClientData("Alfresco Digital Business Platform"); - transformRequest.setTransformRequestOptions(new HashMap<>()); - transformRequest.setSourceReference(sourceFileRef); - transformRequest.setSourceExtension(sourceExtension); - transformRequest.setSourceSize(sourceFile.length()); - transformRequest.setTargetExtension(targetExtension); - - // HTTP Request - HttpHeaders headers = new HttpHeaders(); - headers.set(CONTENT_DISPOSITION, "attachment; filename=quick." + sourceExtension); - ResponseEntity response = new ResponseEntity<>(new FileSystemResource( - sourceFile), headers, OK); - - when(alfrescoSharedFileStoreClient.retrieveFile(sourceFileRef)).thenReturn(response); - when(alfrescoSharedFileStoreClient.saveFile(any())) - .thenReturn(new FileRefResponse(new FileRefEntity(targetFileRef))); - when(mockExecutionResult.getExitValue()).thenReturn(0); - - // Update the Transformation Request with any specific params before sending it - updateTransformRequestWithSpecificOptions(transformRequest); - - // Serialize and call the transformer - String tr = objectMapper.writeValueAsString(transformRequest); - String transformationReplyAsString = mockMvc - .perform(MockMvcRequestBuilders - .post("/transform") - .header(ACCEPT, APPLICATION_JSON_VALUE) - .header(CONTENT_TYPE, APPLICATION_JSON_VALUE) - .content(tr)) - .andExpect(status().is(CREATED.value())) - .andReturn().getResponse().getContentAsString(); - - TransformReply transformReply = objectMapper.readValue(transformationReplyAsString, - TransformReply.class); - - // Assert the reply - assertEquals(transformRequest.getRequestId(), transformReply.getRequestId()); - assertEquals(transformRequest.getClientData(), transformReply.getClientData()); - assertEquals(transformRequest.getSchema(), transformReply.getSchema()); - } - @Test - public void emptyTest() - { - controller.info(); - } - - -} \ No newline at end of file diff --git a/alfresco-transform-imagemagick/alfresco-transform-imagemagick-boot/src/test/java/org/alfresco/transformer/ImageMagickControllerTest.java b/alfresco-transform-imagemagick/alfresco-transform-imagemagick-boot/src/test/java/org/alfresco/transformer/ImageMagickControllerTest.java index 978980e2..51976fc2 100644 --- a/alfresco-transform-imagemagick/alfresco-transform-imagemagick-boot/src/test/java/org/alfresco/transformer/ImageMagickControllerTest.java +++ b/alfresco-transform-imagemagick/alfresco-transform-imagemagick-boot/src/test/java/org/alfresco/transformer/ImageMagickControllerTest.java @@ -26,56 +26,15 @@ */ package org.alfresco.transformer; -import static org.alfresco.transformer.executors.RuntimeExec.ExecutionResult; -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.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.Mockito.when; -import static org.springframework.http.HttpHeaders.ACCEPT; -import static org.springframework.http.HttpHeaders.CONTENT_DISPOSITION; -import static org.springframework.http.HttpHeaders.CONTENT_TYPE; -import static org.springframework.http.HttpStatus.BAD_REQUEST; -import static org.springframework.http.HttpStatus.CREATED; -import static org.springframework.http.HttpStatus.OK; -import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; -import static org.springframework.http.MediaType.IMAGE_PNG_VALUE; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; -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 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.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; -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; /** * Test the ImageMagickController without a server. @@ -83,20 +42,8 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; */ @RunWith(SpringRunner.class) @WebMvcTest(ImageMagickController.class) -public class ImageMagickControllerTest extends AbstractTransformerControllerTest +public class ImageMagickControllerTest extends ImageMagickControllerTestBase { - private static final String ENGINE_CONFIG_NAME = "imagemagick_engine_config.json"; - - @Mock - private ExecutionResult mockExecutionResult; - - @Mock - private RuntimeExec mockTransformCommand; - - @Mock - private RuntimeExec mockCheckCommand; - - private ImageMagickCommandExecutor commandExecutor = new ImageMagickCommandExecutor(); @SpyBean private ImageMagickController controller; @@ -112,284 +59,9 @@ public class ImageMagickControllerTest extends AbstractTransformerControllerTest } @Override - public String getEngineConfigName() - { - return ENGINE_CONFIG_NAME; - } - - @Override - protected void mockTransformCommand(String sourceExtension, - String targetExtension, String sourceMimetype, - boolean readTargetFileBytes) throws IOException - { - this.sourceExtension = sourceExtension; - this.targetExtension = targetExtension; - this.sourceMimetype = sourceMimetype; - - expectedOptions = null; - expectedSourceSuffix = null; - expectedSourceFileBytes = readTestFile(sourceExtension); - expectedTargetFileBytes = readTargetFileBytes ? readTestFile(targetExtension) : null; - sourceFile = new MockMultipartFile("file", "quick." + sourceExtension, sourceMimetype, - expectedSourceFileBytes); - - when(mockTransformCommand.execute(any(), anyLong())).thenAnswer( - (Answer) invocation -> { - Map actualProperties = invocation.getArgument(0); - assertEquals("There should be 3 properties", 3, actualProperties.size()); - - String actualOptions = actualProperties.get("options"); - String actualSource = actualProperties.get("source"); - String actualTarget = actualProperties.get("target"); - String actualTargetExtension = getFilenameExtension(actualTarget); - - 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()); - } - - assertNotNull(actualOptions); - if (expectedOptions != null) - { - assertEquals("expectedOptions", expectedOptions, actualOptions); - } - - Long actualTimeout = invocation.getArgument(1); - assertNotNull(actualTimeout); - if (expectedTimeout != null) - { - assertEquals("expectedTimeout", expectedTimeout, actualTimeout); - } - - // Copy a test file into the target file location if it exists - int i = actualTarget.lastIndexOf('_'); - if (i >= 0) - { - String testFilename = actualTarget.substring(i + 1); - File testFile = getTestFile(testFilename, false); - File targetFile = new File(actualTarget); - generateTargetFileFromResourceFile(actualTargetExtension, testFile, - targetFile); - } - - // 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)); - - return mockExecutionResult; - }); - - when(mockExecutionResult.getExitValue()).thenReturn(0); - when(mockExecutionResult.getStdErr()).thenReturn("STDERROR"); - when(mockExecutionResult.getStdOut()).thenReturn("STDOUT"); - } - - @Override - protected AbstractTransformerController getController() + protected AbstractTransformerController getController() { return controller; } - @Test - public void cropGravityGoodTest() throws Exception - { - for (String value : new String[]{"North", "NorthEast", "East", "SouthEast", "South", "SouthWest", "West", "NorthWest", "Center"}) - { - expectedOptions = "-gravity " + value + " +repage"; - mockMvc - .perform(MockMvcRequestBuilders - .multipart("/transform") - .file(sourceFile) - .param("targetExtension", targetExtension) - .param("cropGravity", value)) - .andExpect(status().is(OK.value())) - .andExpect(content().bytes(expectedTargetFileBytes)) - .andExpect(header().string("Content-Disposition", - "attachment; filename*= UTF-8''quick." + targetExtension)); - } - } - - @Test - public void cropGravityBadTest() throws Exception - { - mockMvc - .perform(MockMvcRequestBuilders - .multipart("/transform") - .file(sourceFile) - .param("targetExtension", targetExtension) - .param("cropGravity", "badValue")) - .andExpect(status().is(BAD_REQUEST.value())); - } - - @Test - public void optionsTest() throws Exception - { - expectedOptions = "-alpha remove -gravity SouthEast -crop 123x456%+90+12 +repage -thumbnail 321x654%!"; - expectedSourceSuffix = "[2-3]"; - mockMvc - .perform(MockMvcRequestBuilders - .multipart("/transform") - .file(sourceFile) - .param("targetExtension", targetExtension) - - .param("startPage", "2") - .param("endPage", "3") - - .param("alphaRemove", "true") - .param("autoOrient", "false") - - .param("cropGravity", "SouthEast") - .param("cropWidth", "123") - .param("cropHeight", "456") - .param("cropPercentage", "true") - .param("cropXOffset", "90") - .param("cropYOffset", "12") - - .param("thumbnail", "true") - .param("resizeWidth", "321") - .param("resizeHeight", "654") - .param("resizePercentage", "true") - .param("allowEnlargement", "true") - .param("maintainAspectRatio", "false")) - .andExpect(status().is(OK.value())) - .andExpect(content().bytes(expectedTargetFileBytes)) - .andExpect(header().string("Content-Disposition", - "attachment; filename*= UTF-8''quick." + targetExtension)); - } - - @Test - public void optionsNegateBooleansTest() throws Exception - { - expectedOptions = "-auto-orient -gravity SouthEast -crop 123x456+90+12 +repage -resize 321x654>"; - expectedSourceSuffix = "[2-3]"; - mockMvc - .perform(MockMvcRequestBuilders - .multipart("/transform") - .file(sourceFile) - .param("targetExtension", targetExtension) - - .param("startPage", "2") - .param("endPage", "3") - - .param("alphaRemove", "false") - .param("autoOrient", "true") - - .param("cropGravity", "SouthEast") - .param("cropWidth", "123") - .param("cropHeight", "456") - .param("cropPercentage", "false") - .param("cropXOffset", "90") - .param("cropYOffset", "12") - - .param("thumbnail", "false") - .param("resizeWidth", "321") - .param("resizeHeight", "654") - .param("resizePercentage", "false") - .param("allowEnlargement", "false") - .param("maintainAspectRatio", "true")) - .andExpect(status().is(OK.value())) - .andExpect(content().bytes(expectedTargetFileBytes)) - .andExpect(header().string("Content-Disposition", - "attachment; filename*= UTF-8''quick." + targetExtension)); - } - - @Test - public void deprecatedCommandOptionsTest() throws Exception - { - // Example of why the commandOptions parameter is a bad idea. - expectedOptions = "( horrible command / ); -resize 321x654>"; - mockMvc - .perform(MockMvcRequestBuilders - .multipart("/transform") - .file(sourceFile) - .param("targetExtension", targetExtension) - .param("thumbnail", "false") - .param("resizeWidth", "321") - .param("resizeHeight", "654") - .param("commandOptions", "( horrible command / );")) - .andExpect(status().is(OK.value())) - .andExpect(content().bytes(expectedTargetFileBytes)) - .andExpect(header().string("Content-Disposition", - "attachment; filename*= UTF-8''quick." + targetExtension)); - } - - @Override - protected void updateTransformRequestWithSpecificOptions(TransformRequest transformRequest) - { - transformRequest.setSourceExtension("png"); - transformRequest.setTargetExtension("png"); - transformRequest.setSourceMediaType(IMAGE_PNG_VALUE); - transformRequest.setTargetMediaType(IMAGE_PNG_VALUE); - } - - @Test - public void badExitCodeTest() throws Exception - { - when(mockExecutionResult.getExitValue()).thenReturn(1); - - mockMvc.perform(mockMvcRequest("/transform", sourceFile, "targetExtension", "xxx")) - .andExpect(status().is(BAD_REQUEST.value())) - .andExpect( - status().reason(containsString("Transformer exit code was not 0: \nSTDERR"))); - } - - @Test - public void testPojoTransform() throws Exception - { - // Files - String sourceFileRef = UUID.randomUUID().toString(); - File sourceFile = getTestFile("quick." + sourceExtension, true); - String targetFileRef = UUID.randomUUID().toString(); - - // Transformation Request POJO - TransformRequest transformRequest = new TransformRequest(); - transformRequest.setRequestId("1"); - transformRequest.setSchema(1); - transformRequest.setClientData("Alfresco Digital Business Platform"); - transformRequest.setTransformRequestOptions(new HashMap<>()); - transformRequest.setSourceReference(sourceFileRef); - transformRequest.setSourceExtension(sourceExtension); - transformRequest.setSourceSize(sourceFile.length()); - transformRequest.setTargetExtension(targetExtension); - - // HTTP Request - HttpHeaders headers = new HttpHeaders(); - headers.set(CONTENT_DISPOSITION, "attachment; filename=quick." + sourceExtension); - ResponseEntity response = new ResponseEntity<>(new FileSystemResource( - sourceFile), headers, OK); - - when(alfrescoSharedFileStoreClient.retrieveFile(sourceFileRef)).thenReturn(response); - when(alfrescoSharedFileStoreClient.saveFile(any())) - .thenReturn(new FileRefResponse(new FileRefEntity(targetFileRef))); - when(mockExecutionResult.getExitValue()).thenReturn(0); - - // Update the Transformation Request with any specific params before sending it - updateTransformRequestWithSpecificOptions(transformRequest); - - // Serialize and call the transformer - String tr = objectMapper.writeValueAsString(transformRequest); - String transformationReplyAsString = mockMvc - .perform(MockMvcRequestBuilders - .post("/transform") - .header(ACCEPT, APPLICATION_JSON_VALUE) - .header(CONTENT_TYPE, APPLICATION_JSON_VALUE) - .content(tr)) - .andExpect(status().is(CREATED.value())) - .andReturn().getResponse().getContentAsString(); - - TransformReply transformReply = objectMapper.readValue(transformationReplyAsString, - TransformReply.class); - - // Assert the reply - assertEquals(transformRequest.getRequestId(), transformReply.getRequestId()); - assertEquals(transformRequest.getClientData(), transformReply.getClientData()); - assertEquals(transformRequest.getSchema(), transformReply.getSchema()); - } } diff --git a/alfresco-transform-imagemagick/alfresco-transform-imagemagick-boot/src/test/java/org/alfresco/transformer/ImageMagickControllerTestBasePOC.java b/alfresco-transform-imagemagick/alfresco-transform-imagemagick-boot/src/test/java/org/alfresco/transformer/ImageMagickControllerTestBase.java similarity index 94% rename from alfresco-transform-imagemagick/alfresco-transform-imagemagick-boot/src/test/java/org/alfresco/transformer/ImageMagickControllerTestBasePOC.java rename to alfresco-transform-imagemagick/alfresco-transform-imagemagick-boot/src/test/java/org/alfresco/transformer/ImageMagickControllerTestBase.java index 46ba7408..2aab2945 100644 --- a/alfresco-transform-imagemagick/alfresco-transform-imagemagick-boot/src/test/java/org/alfresco/transformer/ImageMagickControllerTestBasePOC.java +++ b/alfresco-transform-imagemagick/alfresco-transform-imagemagick-boot/src/test/java/org/alfresco/transformer/ImageMagickControllerTestBase.java @@ -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; @@ -80,7 +81,7 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; */ @RunWith(SpringRunner.class) @WebMvcTest(ImageMagickController.class) -public abstract class ImageMagickControllerTestBasePOC extends AbstractTransformerControllerTest +public abstract class ImageMagickControllerTestBase extends AbstractTransformerControllerTest { private static final String ENGINE_CONFIG_NAME = "imagemagick_engine_config.json"; @@ -110,6 +111,7 @@ public abstract class ImageMagickControllerTestBasePOC extends AbstractTransform this.sourceExtension = sourceExtension; this.targetExtension = targetExtension; this.sourceMimetype = sourceMimetype; + this.targetMimetype = PREFIX_IMAGE + targetExtension; expectedOptions = null; expectedSourceSuffix = null; @@ -188,6 +190,8 @@ public abstract class ImageMagickControllerTestBasePOC extends AbstractTransform .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)) @@ -204,6 +208,8 @@ public abstract class ImageMagickControllerTestBasePOC extends AbstractTransform .multipart("/transform") .file(sourceFile) .param("targetExtension", targetExtension) + .param("targetMimetype", targetMimetype) + .param("sourceMimetype", sourceMimetype) .param("cropGravity", "badValue")) .andExpect(status().is(BAD_REQUEST.value())); } @@ -218,6 +224,8 @@ public abstract class ImageMagickControllerTestBasePOC extends AbstractTransform .multipart("/transform") .file(sourceFile) .param("targetExtension", targetExtension) + .param("targetMimetype", targetMimetype) + .param("sourceMimetype", sourceMimetype) .param("startPage", "2") .param("endPage", "3") @@ -254,6 +262,8 @@ public abstract class ImageMagickControllerTestBasePOC extends AbstractTransform .multipart("/transform") .file(sourceFile) .param("targetExtension", targetExtension) + .param("targetMimetype", targetMimetype) + .param("sourceMimetype", sourceMimetype) .param("startPage", "2") .param("endPage", "3") @@ -290,6 +300,8 @@ public abstract class ImageMagickControllerTestBasePOC extends AbstractTransform .multipart("/transform") .file(sourceFile) .param("targetExtension", targetExtension) + .param("targetMimetype", targetMimetype) + .param("sourceMimetype", sourceMimetype) .param("thumbnail", "false") .param("resizeWidth", "321") .param("resizeHeight", "654") @@ -336,8 +348,10 @@ public abstract class ImageMagickControllerTestBasePOC extends AbstractTransform 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(); diff --git a/alfresco-transform-imagemagick/alfresco-transform-imagemagick-boot/src/test/java/org/alfresco/transformer/ImageMagickControllerTestPOC.java b/alfresco-transform-imagemagick/alfresco-transform-imagemagick-boot/src/test/java/org/alfresco/transformer/ImageMagickControllerTestPOC.java deleted file mode 100644 index c45195e3..00000000 --- a/alfresco-transform-imagemagick/alfresco-transform-imagemagick-boot/src/test/java/org/alfresco/transformer/ImageMagickControllerTestPOC.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * #%L - * Alfresco Transform Core - * %% - * Copyright (C) 2005 - 2019 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 . - * #L% - */ -package org.alfresco.transformer; - -import java.io.IOException; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.SpyBean; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.util.ReflectionTestUtils; - -/** - * Test the ImageMagickController without a server. - * Super class includes tests for the AbstractTransformerController. - */ -@RunWith(SpringRunner.class) -@WebMvcTest(ImageMagickController.class) -public class ImageMagickControllerTestPOC extends ImageMagickControllerTestBasePOC -{ - - @SpyBean - private ImageMagickController controller; - - @Before - public void before() throws IOException - { - ReflectionTestUtils.setField(commandExecutor, "transformCommand", mockTransformCommand); - ReflectionTestUtils.setField(commandExecutor, "checkCommand", mockCheckCommand); - ReflectionTestUtils.setField(controller, "commandExecutor", commandExecutor); - - mockTransformCommand("jpg", "png", "image/jpg", true); - } - - @Override - protected AbstractTransformerController getController() - { - return controller; - } - - //There is currently a bug in the version of the surefire plugin that junit4 uses - //which means that inherited tests are not detected and run if there are no tests - //present in the super class, the below is a workaround. - @Test - public void emptyTest() - { - controller.info(); - } -} diff --git a/alfresco-transform-tika/alfresco-transform-tika/pom.xml b/alfresco-transform-tika/alfresco-transform-tika/pom.xml index c52116a9..25db09a7 100644 --- a/alfresco-transform-tika/alfresco-transform-tika/pom.xml +++ b/alfresco-transform-tika/alfresco-transform-tika/pom.xml @@ -49,6 +49,10 @@ org.quartz-scheduler quartz + + xml-apis + xml-apis + diff --git a/alfresco-transformer-base/src/test/java/org/alfresco/transformer/AbstractTransformerControllerTest.java b/alfresco-transformer-base/src/test/java/org/alfresco/transformer/AbstractTransformerControllerTest.java index c6ba029f..33744065 100644 --- a/alfresco-transformer-base/src/test/java/org/alfresco/transformer/AbstractTransformerControllerTest.java +++ b/alfresco-transformer-base/src/test/java/org/alfresco/transformer/AbstractTransformerControllerTest.java @@ -100,6 +100,7 @@ public abstract class AbstractTransformerControllerTest protected String sourceExtension; protected String targetExtension; protected String sourceMimetype; + protected String targetMimetype; protected MockMultipartFile sourceFile; protected String expectedOptions;