REPO-3424 Unit tests for docker transformers

This commit is contained in:
Alan Davis
2018-04-16 16:24:09 +01:00
parent af4950d99a
commit 0b1ffe9f29
31 changed files with 1027 additions and 61 deletions

View File

@@ -4,8 +4,6 @@
<name>Alfresco Docker ImageMagick</name>
<packaging>jar</packaging>
<version>0.9-SNAPSHOT</version>
<parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-docker-transformers</artifactId>
@@ -50,6 +48,14 @@
<artifactId>alfresco-core</artifactId>
<version>${dependency.alfresco-core.version}</version>
</dependency>
<dependency>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-transformer-base</artifactId>
<version>${project.version}</version>
<classifier>tests</classifier>
<type>test-jar</type>
<scope>test</scope>
</dependency>
</dependencies>
<build>

View File

@@ -114,6 +114,7 @@ public class ImageMagickController extends AbstractTransformerController
@RequestParam("file") MultipartFile sourceMultipartFile,
@RequestParam("targetExtension") String targetExtension,
@RequestParam(value = "timeout", required = false) Long timeout,
@RequestParam(value = "testDelay", required = false) Long testDelay,
@RequestParam(value = "startPage", required = false) Integer startPage,
@RequestParam(value = "endPage", required = false) Integer endPage,
@@ -138,7 +139,11 @@ public class ImageMagickController extends AbstractTransformerController
if (cropGravity != null)
{
cropGravity = cropGravity.trim();
if (!cropGravity.isEmpty() && !GRAVITY_VALUES.contains(cropGravity))
if (cropGravity.isEmpty())
{
cropGravity = null;
}
else if (!GRAVITY_VALUES.contains(cropGravity))
{
throw new TransformException(400, "Invalid cropGravity value");
}
@@ -258,6 +263,6 @@ public class ImageMagickController extends AbstractTransformerController
executeTransformCommand(properties, targetFile, timeout);
return createAttachment(targetFilename, targetFile);
return createAttachment(targetFilename, targetFile, testDelay);
}
}

View File

@@ -8,6 +8,7 @@
<tr><td><div style="text-align:right">file *</div></td><td><input type="file" name="file" /></td></tr>
<tr><td><div style="text-align:right">targetExtension *</div></td><td><input type="text" name="targetExtension" value="" /></td></tr>
<tr><td><div style="text-align:right">timeout</div></td><td><input type="text" name="timeout" value="" /></td></tr>
<tr><td><div style="text-align:right">testDelay</div></td><td><input type="text" name="testDelay" value="" /></td></tr>
<tr><td><div style="text-align:right">startPage</div></td><td><input type="text" name="startPage" /></td></tr>
<tr><td><div style="text-align:right">endPage</div></td><td><input type="text" name="endPage" /></td></tr>

View File

@@ -0,0 +1,116 @@
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2018 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.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.web.servlet.request.MockMvcRequestBuilders;
import java.io.IOException;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
/**
* Test the ImageMagickController without a server.
* Super class includes tests for the AbstractTransformerController.
*/
@RunWith(SpringRunner.class)
@WebMvcTest(ImageMagickController.class)
public class ImageMagickControllerTest extends AbstractTransformerControllerTest
{
@SpyBean
private ImageMagickController controller;
@Before
public void before() throws IOException
{
super.mockTransformCommand(controller, "jpg", "png", "image/jpg");
}
@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.fileUpload("/transform")
.file(sourceFile)
.param("targetExtension", targetExtension)
.param("cropGravity", value))
.andExpect(status().is(200))
.andExpect(content().bytes(expectedTargetFileBytes))
.andExpect(header().string("Content-Disposition", "attachment; filename*= UTF-8''quick."+targetExtension));
}
}
@Test
public void cropGravityBadTest() throws Exception
{
mockMvc.perform(MockMvcRequestBuilders.fileUpload("/transform")
.file(sourceFile)
.param("targetExtension", targetExtension)
.param("cropGravity", "badValue"))
.andExpect(status().is(400));
}
@Test
public void optionsTest() throws Exception
{
expectedOptions = "-alpha remove -gravity SouthEast -crop 123x456%+90+12 +repage -thumbnail 321x654%!";
expectedSourceSuffix = "[2-3]";
mockMvc.perform(MockMvcRequestBuilders.fileUpload("/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", "true")
)
.andExpect(status().is(200))
.andExpect(content().bytes(expectedTargetFileBytes))
.andExpect(header().string("Content-Disposition", "attachment; filename*= UTF-8''quick."+targetExtension));
}
}

View File

@@ -0,0 +1,51 @@
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2018 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;
/**
* Tests AlfrescoPdfRendererHttpRequestTest with a server test harness.
*/
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class ImageMagickHttpRequestTest extends AbstractHttpRequestTest
{
@Override
protected String getTransformerName()
{
return "ImageMagick";
}
@Override
protected String getSourceExtension()
{
return "jpg";
};
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB