View Javadoc

1   /*
2    * Copyright 2016-2016 Hippo B.V. (http://www.onehippo.com)
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *         http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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 ImageMagickCommandTest extends AbstractImageMagickCommandTest {
28  
29      @Before
30      public void before() throws Exception {
31          Assume.assumeTrue(isImageMagickAvailable());
32      }
33  
34      @Test
35      public void testImageMagickConvert() 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/testImageMagickConvert-120x120-" + targetFileName);
49  
50              ImageMagickCommand cmd = new ImageMagickCommand(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  }