package org.bib.jeffrey; import static org.junit.Assert.*; import java.awt.image.BufferedImage; import java.io.File; import java.util.List; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; public class TiffServiceTest extends BaseTest { // Constructors // Public Methods public TiffServiceTest() { } // Main Method to Test @Test public void testToMultiPageTiff() { /* * None, CCITT RLE, CCITT T.4, CCITT T.6, LZW, JPEG, ZLib, PackBits, Deflate */ final String compressionType = "LZW"; /* * Where to write the multipage tiff - change outputDir to path of your choosing if you don't want to use user.home */ String outputDir = env.getProperty("user.home"); assertFalse(StringUtils.isBlank(outputDir)); String fileName = "bib-multipage-" + compressionType + ".tif"; final File outputFile = new File(outputDir, fileName); /* * Execute the main logic to combine tiffs to a single multi page tiff, then write the result to the target file */ tiffService.toMultiPageTiff(IMAGE_PATH, outputFile, compressionType); } // Component Methods @Test public void testLoadImages() { List imageList = tiffService.loadImages(IMAGE_PATH); assertFalse(CollectionUtils.isEmpty(imageList)); } @Test public void testCreateMultiPageTiff() { List imageList = tiffService.loadImages(IMAGE_PATH); byte[] tiffBytes = tiffService.createMultiPageTiff(imageList, "None"); assertNotNull(tiffBytes); assertTrue(tiffBytes.length > 0); } // Getters & Setters // Attributes /** * Logger */ private static final Logger logger = LogManager.getLogger(TiffServiceTest.class); /** * Environment */ @Autowired private Environment env; /** * Tiff service under test */ @Autowired private TiffService tiffService; /** * Image pattern path */ private static final String IMAGE_PATH = "classpath:/img/*.tif"; }