mirror of
https://github.com/Alfresco/alfresco-transform-core.git
synced 2025-09-17 14:21:18 +00:00
ATS-531 : Reformat code
This commit is contained in:
@@ -91,7 +91,7 @@ public class ImageMagickControllerTest extends AbstractTransformerControllerTest
|
||||
|
||||
@SpyBean
|
||||
private ImageMagickCommandExecutor commandExecutor;
|
||||
|
||||
|
||||
@SpyBean
|
||||
private ImageMagickController controller;
|
||||
|
||||
@@ -117,7 +117,8 @@ public class ImageMagickControllerTest extends AbstractTransformerControllerTest
|
||||
expectedSourceSuffix = null;
|
||||
expectedSourceFileBytes = readTestFile(sourceExtension);
|
||||
expectedTargetFileBytes = readTargetFileBytes ? readTestFile(targetExtension) : null;
|
||||
sourceFile = new MockMultipartFile("file", "quick." + sourceExtension, sourceMimetype, expectedSourceFileBytes);
|
||||
sourceFile = new MockMultipartFile("file", "quick." + sourceExtension, sourceMimetype,
|
||||
expectedSourceFileBytes);
|
||||
|
||||
when(mockTransformCommand.execute(any(), anyLong())).thenAnswer(
|
||||
(Answer<RuntimeExec.ExecutionResult>) invocation -> {
|
||||
@@ -133,8 +134,11 @@ public class ImageMagickControllerTest extends AbstractTransformerControllerTest
|
||||
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());
|
||||
assertTrue(
|
||||
"The source file \"" + actualSource + "\" should have ended in \"" + expectedSourceSuffix + "\"",
|
||||
actualSource.endsWith(expectedSourceSuffix));
|
||||
actualSource = actualSource.substring(0,
|
||||
actualSource.length() - expectedSourceSuffix.length());
|
||||
}
|
||||
|
||||
assertNotNull(actualOptions);
|
||||
@@ -154,7 +158,7 @@ public class ImageMagickControllerTest extends AbstractTransformerControllerTest
|
||||
int i = actualTarget.lastIndexOf('_');
|
||||
if (i >= 0)
|
||||
{
|
||||
String testFilename = actualTarget.substring(i+1);
|
||||
String testFilename = actualTarget.substring(i + 1);
|
||||
File testFile = getTestFile(testFilename, false);
|
||||
File targetFile = new File(actualTarget);
|
||||
generateTargetFileFromResourceFile(actualTargetExtension, testFile,
|
||||
@@ -163,7 +167,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("Source file is not the same",
|
||||
Arrays.equals(expectedSourceFileBytes, actualSourceFileBytes));
|
||||
|
||||
return mockExecutionResult;
|
||||
});
|
||||
@@ -173,7 +178,6 @@ public class ImageMagickControllerTest extends AbstractTransformerControllerTest
|
||||
when(mockExecutionResult.getStdOut()).thenReturn("STDOUT");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected AbstractTransformerController getController()
|
||||
{
|
||||
@@ -183,27 +187,32 @@ public class ImageMagickControllerTest extends AbstractTransformerControllerTest
|
||||
@Test
|
||||
public void cropGravityGoodTest() throws Exception
|
||||
{
|
||||
for (String value: new String[] {"North", "NorthEast", "East", "SouthEast", "South", "SouthWest", "West", "NorthWest", "Center"})
|
||||
for (String value : new String[]{"North", "NorthEast", "East", "SouthEast", "South", "SouthWest", "West", "NorthWest", "Center"})
|
||||
{
|
||||
expectedOptions = "-gravity "+value+" +repage";
|
||||
mockMvc.perform(MockMvcRequestBuilders.multipart("/transform")
|
||||
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));
|
||||
.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")
|
||||
mockMvc
|
||||
.perform(MockMvcRequestBuilders
|
||||
.multipart("/transform")
|
||||
.file(sourceFile)
|
||||
.param("targetExtension", targetExtension)
|
||||
.param("cropGravity", "badValue"))
|
||||
.andExpect(status().is(BAD_REQUEST.value()));
|
||||
.andExpect(status().is(BAD_REQUEST.value()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -211,7 +220,9 @@ public class ImageMagickControllerTest extends AbstractTransformerControllerTest
|
||||
{
|
||||
expectedOptions = "-alpha remove -gravity SouthEast -crop 123x456%+90+12 +repage -thumbnail 321x654%!";
|
||||
expectedSourceSuffix = "[2-3]";
|
||||
mockMvc.perform(MockMvcRequestBuilders.multipart("/transform")
|
||||
mockMvc
|
||||
.perform(MockMvcRequestBuilders
|
||||
.multipart("/transform")
|
||||
.file(sourceFile)
|
||||
.param("targetExtension", targetExtension)
|
||||
|
||||
@@ -234,10 +245,10 @@ public class ImageMagickControllerTest extends AbstractTransformerControllerTest
|
||||
.param("resizePercentage", "true")
|
||||
.param("allowEnlargement", "true")
|
||||
.param("maintainAspectRatio", "true"))
|
||||
|
||||
.andExpect(status().is(OK.value()))
|
||||
.andExpect(content().bytes(expectedTargetFileBytes))
|
||||
.andExpect(header().string("Content-Disposition", "attachment; filename*= UTF-8''quick."+targetExtension));
|
||||
.andExpect(status().is(OK.value()))
|
||||
.andExpect(content().bytes(expectedTargetFileBytes))
|
||||
.andExpect(header().string("Content-Disposition",
|
||||
"attachment; filename*= UTF-8''quick." + targetExtension));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -245,7 +256,9 @@ public class ImageMagickControllerTest extends AbstractTransformerControllerTest
|
||||
{
|
||||
expectedOptions = "-auto-orient -gravity SouthEast -crop 123x456+90+12 +repage -resize 321x654>";
|
||||
expectedSourceSuffix = "[2-3]";
|
||||
mockMvc.perform(MockMvcRequestBuilders.multipart("/transform")
|
||||
mockMvc
|
||||
.perform(MockMvcRequestBuilders
|
||||
.multipart("/transform")
|
||||
.file(sourceFile)
|
||||
.param("targetExtension", targetExtension)
|
||||
|
||||
@@ -268,10 +281,10 @@ public class ImageMagickControllerTest extends AbstractTransformerControllerTest
|
||||
.param("resizePercentage", "false")
|
||||
.param("allowEnlargement", "false")
|
||||
.param("maintainAspectRatio", "false"))
|
||||
|
||||
.andExpect(status().is(OK.value()))
|
||||
.andExpect(content().bytes(expectedTargetFileBytes))
|
||||
.andExpect(header().string("Content-Disposition", "attachment; filename*= UTF-8''quick."+targetExtension));
|
||||
.andExpect(status().is(OK.value()))
|
||||
.andExpect(content().bytes(expectedTargetFileBytes))
|
||||
.andExpect(header().string("Content-Disposition",
|
||||
"attachment; filename*= UTF-8''quick." + targetExtension));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -279,16 +292,19 @@ public class ImageMagickControllerTest extends AbstractTransformerControllerTest
|
||||
{
|
||||
// Example of why the commandOptions parameter is a bad idea.
|
||||
expectedOptions = "( horrible command / ); -resize 321x654>";
|
||||
mockMvc.perform(MockMvcRequestBuilders.multipart("/transform")
|
||||
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));
|
||||
.andExpect(status().is(OK.value()))
|
||||
.andExpect(content().bytes(expectedTargetFileBytes))
|
||||
.andExpect(header().string("Content-Disposition",
|
||||
"attachment; filename*= UTF-8''quick." + targetExtension));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -299,7 +315,7 @@ public class ImageMagickControllerTest extends AbstractTransformerControllerTest
|
||||
transformRequest.setSourceMediaType(MediaType.IMAGE_PNG_VALUE);
|
||||
transformRequest.setTargetMediaType(MediaType.IMAGE_PNG_VALUE);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void badExitCodeTest() throws Exception
|
||||
{
|
||||
@@ -307,7 +323,8 @@ public class ImageMagickControllerTest extends AbstractTransformerControllerTest
|
||||
|
||||
mockMvc.perform(mockMvcRequest("/transform", sourceFile, "targetExtension", "xxx"))
|
||||
.andExpect(status().is(BAD_REQUEST.value()))
|
||||
.andExpect(status().reason(containsString("Transformer exit code was not 0: \nSTDERR")));
|
||||
.andExpect(
|
||||
status().reason(containsString("Transformer exit code was not 0: \nSTDERR")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -318,7 +335,6 @@ public class ImageMagickControllerTest extends AbstractTransformerControllerTest
|
||||
File sourceFile = getTestFile("quick." + sourceExtension, true);
|
||||
String targetFileRef = UUID.randomUUID().toString();
|
||||
|
||||
|
||||
// Transformation Request POJO
|
||||
TransformRequest transformRequest = new TransformRequest();
|
||||
transformRequest.setRequestId("1");
|
||||
@@ -332,12 +348,14 @@ public class ImageMagickControllerTest extends AbstractTransformerControllerTest
|
||||
|
||||
// HTTP Request
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=quick." + sourceExtension);
|
||||
headers.set(HttpHeaders.CONTENT_DISPOSITION,
|
||||
"attachment; filename=quick." + sourceExtension);
|
||||
ResponseEntity<Resource> 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(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
|
||||
@@ -345,18 +363,21 @@ public class ImageMagickControllerTest extends AbstractTransformerControllerTest
|
||||
|
||||
// Serialize and call the transformer
|
||||
String tr = objectMapper.writeValueAsString(transformRequest);
|
||||
String transformationReplyAsString = mockMvc.perform(MockMvcRequestBuilders.post("/transform")
|
||||
.header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)
|
||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).content(tr))
|
||||
.andExpect(status().is(HttpStatus.CREATED.value()))
|
||||
.andReturn().getResponse().getContentAsString();
|
||||
String transformationReplyAsString = mockMvc
|
||||
.perform(MockMvcRequestBuilders
|
||||
.post("/transform")
|
||||
.header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)
|
||||
.header(HttpHeaders.CONTENT_TYPE,
|
||||
MediaType.APPLICATION_JSON_VALUE).content(tr))
|
||||
.andExpect(status().is(HttpStatus.CREATED.value()))
|
||||
.andReturn().getResponse().getContentAsString();
|
||||
|
||||
TransformReply transformReply = objectMapper.readValue(transformationReplyAsString, TransformReply.class);
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -48,7 +48,8 @@ public class ImageMagickQueueTransformServiceIT extends AbstractQueueTransformSe
|
||||
@Override
|
||||
protected TransformRequest buildRequest()
|
||||
{
|
||||
return TransformRequest.builder()
|
||||
return TransformRequest
|
||||
.builder()
|
||||
.withRequestId(UUID.randomUUID().toString())
|
||||
.withSourceMediaType(MIMETYPE_IMAGE_PNG)
|
||||
.withTargetMediaType(MIMETYPE_IMAGE_JPEG)
|
||||
|
Reference in New Issue
Block a user