diff --git a/source/java/org/alfresco/repo/thumbnail/ThumbnailServiceImplTest.java b/source/java/org/alfresco/repo/thumbnail/ThumbnailServiceImplTest.java index 85f2fb6d09..bac26799d9 100644 --- a/source/java/org/alfresco/repo/thumbnail/ThumbnailServiceImplTest.java +++ b/source/java/org/alfresco/repo/thumbnail/ThumbnailServiceImplTest.java @@ -34,6 +34,7 @@ import java.util.Map; import org.alfresco.model.ContentModel; import org.alfresco.repo.content.MimetypeMap; import org.alfresco.repo.content.transform.AbstractContentTransformerTest; +import org.alfresco.repo.content.transform.ContentTransformer; import org.alfresco.repo.content.transform.magick.ImageResizeOptions; import org.alfresco.repo.content.transform.magick.ImageTransformationOptions; import org.alfresco.repo.jscript.ClasspathScriptLocation; @@ -85,187 +86,191 @@ public class ThumbnailServiceImplTest extends BaseAlfrescoSpringTest ContentModel.TYPE_FOLDER).getChildRef(); } - - /** - * TODO: Enable test (when build platform fixed) or ignore this change in merge to HEAD - */ - public void testDummy() + private void checkTransformer() { + ContentTransformer transformer = this.contentService.getImageTransformer(); + if (transformer == null) + { + fail("No transformer returned for 'getImageTransformer'"); + } + // Check that it is working + ImageTransformationOptions imageTransformationOptions = new ImageTransformationOptions(); + if (!transformer.isTransformable( + MimetypeMap.MIMETYPE_IMAGE_JPEG, + MimetypeMap.MIMETYPE_IMAGE_JPEG, + imageTransformationOptions)) + { + fail("Image transformer is not working. Please check your image conversion command setup."); + } } - + public void testCreateThumbnailFromImage() throws Exception { - // Check that the image transformations are available - if (this.contentService.getImageTransformer() != null) - { - NodeRef jpgOrig = createOrigionalContent(this.folder, MimetypeMap.MIMETYPE_IMAGE_JPEG); - NodeRef gifOrig = createOrigionalContent(this.folder, MimetypeMap.MIMETYPE_IMAGE_GIF); - - // ===== small: 64x64, marked as thumbnail ==== - - ImageResizeOptions imageResizeOptions = new ImageResizeOptions(); - imageResizeOptions.setWidth(64); - imageResizeOptions.setHeight(64); - imageResizeOptions.setResizeToThumbnail(true); - ImageTransformationOptions imageTransformationOptions = new ImageTransformationOptions(); - imageTransformationOptions.setResizeOptions(imageResizeOptions); - //ThumbnailDetails createOptions = new ThumbnailDetails(); - - NodeRef thumbnail1 = this.thumbnailService.createThumbnail(jpgOrig, ContentModel.PROP_CONTENT, - MimetypeMap.MIMETYPE_IMAGE_JPEG, - imageTransformationOptions, - "small"); - assertNotNull(thumbnail1); - checkThumbnailed(jpgOrig, "small"); - checkThumbnail("small", thumbnail1); - outputThumbnailTempContentLocation(thumbnail1, "jpg", "small - 64x64, marked as thumbnail"); - - // ===== small2: 64x64, aspect not maintained ==== - - ImageResizeOptions imageResizeOptions2 = new ImageResizeOptions(); - imageResizeOptions2.setWidth(64); - imageResizeOptions2.setHeight(64); - imageResizeOptions2.setMaintainAspectRatio(false); - ImageTransformationOptions imageTransformationOptions2 = new ImageTransformationOptions(); - imageTransformationOptions2.setResizeOptions(imageResizeOptions2); - //ThumbnailDetails createOptions2 = new ThumbnailDetails(); - NodeRef thumbnail2 = this.thumbnailService.createThumbnail(jpgOrig, ContentModel.PROP_CONTENT, - MimetypeMap.MIMETYPE_IMAGE_JPEG, - imageTransformationOptions2, - "small2"); - checkThumbnailed(jpgOrig, "small2"); - checkThumbnail("small2", thumbnail2); - outputThumbnailTempContentLocation(thumbnail2, "jpg", "small2 - 64x64, aspect not maintained"); - - // ===== half: 50%x50 ===== - - ImageResizeOptions imageResizeOptions3 = new ImageResizeOptions(); - imageResizeOptions3.setWidth(50); - imageResizeOptions3.setHeight(50); - imageResizeOptions3.setPercentResize(true); - ImageTransformationOptions imageTransformationOptions3 = new ImageTransformationOptions(); - imageTransformationOptions3.setResizeOptions(imageResizeOptions3); - // ThumbnailDetails createOptions3 = new ThumbnailDetails(); - NodeRef thumbnail3 = this.thumbnailService.createThumbnail(jpgOrig, ContentModel.PROP_CONTENT, - MimetypeMap.MIMETYPE_IMAGE_JPEG, - imageTransformationOptions3, - "half"); - checkThumbnailed(jpgOrig, "half"); - checkThumbnail("half", thumbnail3); - outputThumbnailTempContentLocation(thumbnail3, "jpg", "half - 50%x50%"); - - - // ===== half2: 50%x50 from gif ===== - - ImageResizeOptions imageResizeOptions4 = new ImageResizeOptions(); - imageResizeOptions4.setWidth(50); - imageResizeOptions4.setHeight(50); - imageResizeOptions4.setPercentResize(true); - ImageTransformationOptions imageTransformationOptions4 = new ImageTransformationOptions(); - imageTransformationOptions4.setResizeOptions(imageResizeOptions4); - // ThumbnailDetails createOptions4 = new ThumbnailDetails(); - NodeRef thumbnail4 = this.thumbnailService.createThumbnail(gifOrig, ContentModel.PROP_CONTENT, - MimetypeMap.MIMETYPE_IMAGE_JPEG, - imageTransformationOptions4, - "half2"); - checkThumbnailed(gifOrig, "half2"); - checkThumbnail("half2", thumbnail4); - outputThumbnailTempContentLocation(thumbnail4, "jpg", "half2 - 50%x50%, from gif"); - } + checkTransformer(); + + NodeRef jpgOrig = createOrigionalContent(this.folder, MimetypeMap.MIMETYPE_IMAGE_JPEG); + NodeRef gifOrig = createOrigionalContent(this.folder, MimetypeMap.MIMETYPE_IMAGE_GIF); + + // ===== small: 64x64, marked as thumbnail ==== + + ImageResizeOptions imageResizeOptions = new ImageResizeOptions(); + imageResizeOptions.setWidth(64); + imageResizeOptions.setHeight(64); + imageResizeOptions.setResizeToThumbnail(true); + ImageTransformationOptions imageTransformationOptions = new ImageTransformationOptions(); + imageTransformationOptions.setResizeOptions(imageResizeOptions); + //ThumbnailDetails createOptions = new ThumbnailDetails(); + + NodeRef thumbnail1 = this.thumbnailService.createThumbnail(jpgOrig, ContentModel.PROP_CONTENT, + MimetypeMap.MIMETYPE_IMAGE_JPEG, + imageTransformationOptions, + "small"); + assertNotNull(thumbnail1); + checkThumbnailed(jpgOrig, "small"); + checkThumbnail("small", thumbnail1); + outputThumbnailTempContentLocation(thumbnail1, "jpg", "small - 64x64, marked as thumbnail"); + + // ===== small2: 64x64, aspect not maintained ==== + + ImageResizeOptions imageResizeOptions2 = new ImageResizeOptions(); + imageResizeOptions2.setWidth(64); + imageResizeOptions2.setHeight(64); + imageResizeOptions2.setMaintainAspectRatio(false); + ImageTransformationOptions imageTransformationOptions2 = new ImageTransformationOptions(); + imageTransformationOptions2.setResizeOptions(imageResizeOptions2); + //ThumbnailDetails createOptions2 = new ThumbnailDetails(); + NodeRef thumbnail2 = this.thumbnailService.createThumbnail(jpgOrig, ContentModel.PROP_CONTENT, + MimetypeMap.MIMETYPE_IMAGE_JPEG, + imageTransformationOptions2, + "small2"); + checkThumbnailed(jpgOrig, "small2"); + checkThumbnail("small2", thumbnail2); + outputThumbnailTempContentLocation(thumbnail2, "jpg", "small2 - 64x64, aspect not maintained"); + + // ===== half: 50%x50 ===== + + ImageResizeOptions imageResizeOptions3 = new ImageResizeOptions(); + imageResizeOptions3.setWidth(50); + imageResizeOptions3.setHeight(50); + imageResizeOptions3.setPercentResize(true); + ImageTransformationOptions imageTransformationOptions3 = new ImageTransformationOptions(); + imageTransformationOptions3.setResizeOptions(imageResizeOptions3); + // ThumbnailDetails createOptions3 = new ThumbnailDetails(); + NodeRef thumbnail3 = this.thumbnailService.createThumbnail(jpgOrig, ContentModel.PROP_CONTENT, + MimetypeMap.MIMETYPE_IMAGE_JPEG, + imageTransformationOptions3, + "half"); + checkThumbnailed(jpgOrig, "half"); + checkThumbnail("half", thumbnail3); + outputThumbnailTempContentLocation(thumbnail3, "jpg", "half - 50%x50%"); + + + // ===== half2: 50%x50 from gif ===== + + ImageResizeOptions imageResizeOptions4 = new ImageResizeOptions(); + imageResizeOptions4.setWidth(50); + imageResizeOptions4.setHeight(50); + imageResizeOptions4.setPercentResize(true); + ImageTransformationOptions imageTransformationOptions4 = new ImageTransformationOptions(); + imageTransformationOptions4.setResizeOptions(imageResizeOptions4); + // ThumbnailDetails createOptions4 = new ThumbnailDetails(); + NodeRef thumbnail4 = this.thumbnailService.createThumbnail(gifOrig, ContentModel.PROP_CONTENT, + MimetypeMap.MIMETYPE_IMAGE_JPEG, + imageTransformationOptions4, + "half2"); + checkThumbnailed(gifOrig, "half2"); + checkThumbnail("half2", thumbnail4); + outputThumbnailTempContentLocation(thumbnail4, "jpg", "half2 - 50%x50%, from gif"); } public void testDuplicationNames() throws Exception { - if (contentService.getImageTransformer() != null) + checkTransformer(); + + NodeRef jpgOrig = createOrigionalContent(this.folder, MimetypeMap.MIMETYPE_IMAGE_JPEG); + ImageResizeOptions imageResizeOptions = new ImageResizeOptions(); + imageResizeOptions.setWidth(64); + imageResizeOptions.setHeight(64); + imageResizeOptions.setResizeToThumbnail(true); + ImageTransformationOptions imageTransformationOptions = new ImageTransformationOptions(); + imageTransformationOptions.setResizeOptions(imageResizeOptions); + //ThumbnailDetails createOptions = new ThumbnailDetails(); + NodeRef thumbnail1 = this.thumbnailService.createThumbnail(jpgOrig, ContentModel.PROP_CONTENT, + MimetypeMap.MIMETYPE_IMAGE_JPEG, + imageTransformationOptions, + "small"); + assertNotNull(thumbnail1); + checkThumbnailed(jpgOrig, "small"); + checkThumbnail("small", thumbnail1); + + try { - NodeRef jpgOrig = createOrigionalContent(this.folder, MimetypeMap.MIMETYPE_IMAGE_JPEG); - ImageResizeOptions imageResizeOptions = new ImageResizeOptions(); - imageResizeOptions.setWidth(64); - imageResizeOptions.setHeight(64); - imageResizeOptions.setResizeToThumbnail(true); - ImageTransformationOptions imageTransformationOptions = new ImageTransformationOptions(); - imageTransformationOptions.setResizeOptions(imageResizeOptions); - //ThumbnailDetails createOptions = new ThumbnailDetails(); - NodeRef thumbnail1 = this.thumbnailService.createThumbnail(jpgOrig, ContentModel.PROP_CONTENT, + this.thumbnailService.createThumbnail(jpgOrig, ContentModel.PROP_CONTENT, MimetypeMap.MIMETYPE_IMAGE_JPEG, imageTransformationOptions, - "small"); - assertNotNull(thumbnail1); - checkThumbnailed(jpgOrig, "small"); - checkThumbnail("small", thumbnail1); - - try - { - this.thumbnailService.createThumbnail(jpgOrig, ContentModel.PROP_CONTENT, - MimetypeMap.MIMETYPE_IMAGE_JPEG, - imageTransformationOptions, - "small"); - fail("A duplicate exception should have been raised"); - } - catch (ThumbnailException exception) - { - // OK since this should have been thrown - } + "small"); + fail("A duplicate exception should have been raised"); + } + catch (ThumbnailException exception) + { + // OK since this should have been thrown } } public void testThumbnailUpdate() throws Exception { - if (contentService.getImageTransformer() != null) - { - // First create a thumbnail - NodeRef jpgOrig = createOrigionalContent(this.folder, MimetypeMap.MIMETYPE_IMAGE_JPEG); - ImageResizeOptions imageResizeOptions = new ImageResizeOptions(); - imageResizeOptions.setWidth(64); - imageResizeOptions.setHeight(64); - imageResizeOptions.setResizeToThumbnail(true); - ImageTransformationOptions imageTransformationOptions = new ImageTransformationOptions(); - imageTransformationOptions.setResizeOptions(imageResizeOptions); - NodeRef thumbnail1 = this.thumbnailService.createThumbnail(jpgOrig, ContentModel.PROP_CONTENT, - MimetypeMap.MIMETYPE_IMAGE_JPEG, - imageTransformationOptions, - "small"); - - // Update the thumbnail - this.thumbnailService.updateThumbnail(thumbnail1, imageTransformationOptions); - } + checkTransformer(); + // First create a thumbnail + NodeRef jpgOrig = createOrigionalContent(this.folder, MimetypeMap.MIMETYPE_IMAGE_JPEG); + ImageResizeOptions imageResizeOptions = new ImageResizeOptions(); + imageResizeOptions.setWidth(64); + imageResizeOptions.setHeight(64); + imageResizeOptions.setResizeToThumbnail(true); + ImageTransformationOptions imageTransformationOptions = new ImageTransformationOptions(); + imageTransformationOptions.setResizeOptions(imageResizeOptions); + NodeRef thumbnail1 = this.thumbnailService.createThumbnail(jpgOrig, ContentModel.PROP_CONTENT, + MimetypeMap.MIMETYPE_IMAGE_JPEG, + imageTransformationOptions, + "small"); + + // Update the thumbnail + this.thumbnailService.updateThumbnail(thumbnail1, imageTransformationOptions); } public void testGetThumbnailByName() throws Exception { - if (contentService.getImageTransformer() != null) - { - NodeRef jpgOrig = createOrigionalContent(this.folder, MimetypeMap.MIMETYPE_IMAGE_JPEG); - - // Check for missing thumbnail - NodeRef result1 = this.thumbnailService.getThumbnailByName(jpgOrig, ContentModel.PROP_CONTENT, "small"); - assertNull("The thumbnail 'small' should have been missing", result1); - - // Create the thumbnail - ImageResizeOptions imageResizeOptions = new ImageResizeOptions(); - imageResizeOptions.setWidth(64); - imageResizeOptions.setHeight(64); - imageResizeOptions.setResizeToThumbnail(true); - ImageTransformationOptions imageTransformationOptions = new ImageTransformationOptions(); - imageTransformationOptions.setResizeOptions(imageResizeOptions); - this.thumbnailService.createThumbnail(jpgOrig, ContentModel.PROP_CONTENT, - MimetypeMap.MIMETYPE_IMAGE_JPEG, - imageTransformationOptions, - "small"); - - // Try and retrieve the thumbnail - NodeRef result2 = this.thumbnailService.getThumbnailByName(jpgOrig, ContentModel.PROP_CONTENT, "small"); - assertNotNull(result2); - checkThumbnail("small", result2); - - // Check for an other thumbnail that doesn't exist - NodeRef result3 = this.thumbnailService.getThumbnailByName(jpgOrig, ContentModel.PROP_CONTENT, "anotherone"); - assertNull("The thumbnail 'anotherone' should have been missing", result3); - } + checkTransformer(); + + NodeRef jpgOrig = createOrigionalContent(this.folder, MimetypeMap.MIMETYPE_IMAGE_JPEG); + + // Check for missing thumbnail + NodeRef result1 = this.thumbnailService.getThumbnailByName(jpgOrig, ContentModel.PROP_CONTENT, "small"); + assertNull("The thumbnail 'small' should have been missing", result1); + + // Create the thumbnail + ImageResizeOptions imageResizeOptions = new ImageResizeOptions(); + imageResizeOptions.setWidth(64); + imageResizeOptions.setHeight(64); + imageResizeOptions.setResizeToThumbnail(true); + ImageTransformationOptions imageTransformationOptions = new ImageTransformationOptions(); + imageTransformationOptions.setResizeOptions(imageResizeOptions); + this.thumbnailService.createThumbnail(jpgOrig, ContentModel.PROP_CONTENT, + MimetypeMap.MIMETYPE_IMAGE_JPEG, + imageTransformationOptions, + "small"); + + // Try and retrieve the thumbnail + NodeRef result2 = this.thumbnailService.getThumbnailByName(jpgOrig, ContentModel.PROP_CONTENT, "small"); + assertNotNull(result2); + checkThumbnail("small", result2); + + // Check for an other thumbnail that doesn't exist + NodeRef result3 = this.thumbnailService.getThumbnailByName(jpgOrig, ContentModel.PROP_CONTENT, "anotherone"); + assertNull("The thumbnail 'anotherone' should have been missing", result3); } // TODO test getThumbnails @@ -325,35 +330,35 @@ public class ThumbnailServiceImplTest extends BaseAlfrescoSpringTest public void testAutoUpdate() throws Exception { - if (contentService.getImageTransformer() != null) + checkTransformer(); + + final NodeRef jpgOrig = createOrigionalContent(this.folder, MimetypeMap.MIMETYPE_IMAGE_JPEG); + + ThumbnailDefinition details = this.thumbnailService.getThumbnailRegistry().getThumbnailDefinition("medium"); + @SuppressWarnings("unused") + final NodeRef thumbnail = this.thumbnailService.createThumbnail(jpgOrig, ContentModel.PROP_CONTENT, details.getMimetype(), details.getTransformationOptions(), details.getName()); + + setComplete(); + endTransaction(); + + transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback() { - final NodeRef jpgOrig = createOrigionalContent(this.folder, MimetypeMap.MIMETYPE_IMAGE_JPEG); - - ThumbnailDefinition details = this.thumbnailService.getThumbnailRegistry().getThumbnailDefinition("medium"); - final NodeRef thumbnail = this.thumbnailService.createThumbnail(jpgOrig, ContentModel.PROP_CONTENT, details.getMimetype(), details.getTransformationOptions(), details.getName()); - - setComplete(); - endTransaction(); - - transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback() - { - public Object execute() throws Exception - { - String ext = ThumbnailServiceImplTest.this.mimetypeMap.getExtension(MimetypeMap.MIMETYPE_IMAGE_JPEG); - File origFile = AbstractContentTransformerTest.loadQuickTestFile(ext); - - ContentWriter writer = ThumbnailServiceImplTest.this.contentService.getWriter(jpgOrig, ContentModel.PROP_CONTENT, true); - writer.putContent(origFile); - - return null; - } - }); - - // TODO - // this test should wait for the async action to run .. will need to commit transaction for that thou! - - //Thread.sleep(1000); - } + public Object execute() throws Exception + { + String ext = ThumbnailServiceImplTest.this.mimetypeMap.getExtension(MimetypeMap.MIMETYPE_IMAGE_JPEG); + File origFile = AbstractContentTransformerTest.loadQuickTestFile(ext); + + ContentWriter writer = ThumbnailServiceImplTest.this.contentService.getWriter(jpgOrig, ContentModel.PROP_CONTENT, true); + writer.putContent(origFile); + + return null; + } + }); + + // TODO + // this test should wait for the async action to run .. will need to commit transaction for that thou! + + //Thread.sleep(1000); } public void testHTMLToImageAndSWF() throws Exception