1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.onehippo.forge.gallerymagick.core.command;
17
18 import java.io.File;
19
20 import org.apache.commons.io.FilenameUtils;
21 import org.junit.Assume;
22 import org.junit.Before;
23 import org.junit.Test;
24
25 import static org.junit.Assert.assertTrue;
26
27 public class GraphicsMagickCommandTest extends AbstractGraphicsMagickCommandTest {
28
29 @Before
30 public void before() throws Exception {
31 Assume.assumeTrue(isGraphicsMagickAvailable());
32 }
33
34 @Test
35 public void testGraphicsMagickConvert() throws Exception {
36 String sourceFileName;
37 String sourceExtension;
38 String targetFileName;
39 long sourceLength;
40 File targetFile;
41
42 for (File sourceFile : getTestImageFiles()) {
43 sourceFileName = sourceFile.getName();
44 sourceExtension = FilenameUtils.getExtension(sourceFileName);
45 targetFileName = FilenameUtils.getBaseName(sourceFileName) + "-thumbnail." + sourceExtension;
46
47 sourceLength = sourceFile.length();
48 targetFile = new File("target/testGraphicsMagickConvert-120x120-" + targetFileName);
49
50 GraphicsMagickCommand cmd = new GraphicsMagickCommand(null, "convert");
51 cmd.setWorkingDirectory(new File("target"));
52 cmd.addArgument(sourceFile.getCanonicalPath());
53 cmd.addArgument("-size");
54 cmd.addArgument("120x120");
55 cmd.addArgument("-resize");
56 cmd.addArgument("120x120");
57 cmd.addArgument("+profile");
58 cmd.addArgument("*");
59 cmd.addArgument(targetFile.getCanonicalPath());
60 cmd.execute();
61
62 assertTrue(targetFile.isFile());
63 assertTrue(targetFile.length() > 0L);
64 assertTrue(targetFile.length() < sourceLength);
65 }
66 }
67
68 }