diff --git a/src/main/java/org/alfresco/repo/content/transform/ContentTransformerRegistry.java b/src/main/java/org/alfresco/repo/content/transform/ContentTransformerRegistry.java index abccf973c5..731cc7f562 100644 --- a/src/main/java/org/alfresco/repo/content/transform/ContentTransformerRegistry.java +++ b/src/main/java/org/alfresco/repo/content/transform/ContentTransformerRegistry.java @@ -77,6 +77,7 @@ public class ContentTransformerRegistry public void setEnabled(boolean enabled) { this.enabled = enabled; + firstTime = true; } public void setTransformerDebug(TransformerDebug transformerDebug) diff --git a/src/main/java/org/alfresco/repo/content/transform/TransformerDebug.java b/src/main/java/org/alfresco/repo/content/transform/TransformerDebug.java index 1aa5959dc9..6ffabb4cc9 100644 --- a/src/main/java/org/alfresco/repo/content/transform/TransformerDebug.java +++ b/src/main/java/org/alfresco/repo/content/transform/TransformerDebug.java @@ -165,7 +165,7 @@ public class TransformerDebug private final String targetMimetype; private final TransformationOptions options; private final boolean origDebugOutput; - private final long start; + private long start; private Call callType; private Frame parent; @@ -564,7 +564,11 @@ public class TransformerDebug (firstLevel && use != null ? "-- "+use+" -- " : "") + message); if (firstLevel) { - log(getNodeRef(frame.options, firstLevel, sourceSize)); + String nodeRef = getNodeRef(frame.options, firstLevel, sourceSize); + if (!nodeRef.isEmpty()) + { + log(nodeRef); + } } } @@ -576,7 +580,7 @@ public class TransformerDebug { if (isEnabled()) { - pop(Call.AVAILABLE, false); + pop(Call.AVAILABLE, false, false); } } @@ -587,7 +591,7 @@ public class TransformerDebug { if (isEnabled()) { - pop(Call.TRANSFORM, false); + pop(Call.TRANSFORM, false, false); } } @@ -599,7 +603,7 @@ public class TransformerDebug { if (isEnabled()) { - pop(Call.AVAILABLE, ThreadInfo.getStack().size() > 1); + pop(Call.AVAILABLE, ThreadInfo.getStack().size() > 1, false); } } @@ -614,12 +618,14 @@ public class TransformerDebug } } - private void pop(Call callType, boolean suppressFinish) + private int pop(Call callType, boolean suppressFinish, boolean suppressChecking) { + int id = -1; Deque ourStack = ThreadInfo.getStack(); if (!ourStack.isEmpty()) { Frame frame = ourStack.peek(); + id = frame.getId(); if ((frame.callType == callType) || (frame.callType == Call.AVAILABLE_AND_TRANSFORM && callType == Call.AVAILABLE)) @@ -633,7 +639,7 @@ public class TransformerDebug if (!suppressFinish && (firstLevel || logger.isTraceEnabled())) { log(FINISHED_IN + ms + - (frame.callType == Call.AVAILABLE ? " Transformer NOT available" : "") + + (frame.callType == Call.AVAILABLE && !suppressChecking? " Just checking if a transformer is available" : "") + (firstLevel ? "\n" : ""), firstLevel); } @@ -642,6 +648,7 @@ public class TransformerDebug ourStack.pop(); } } + return id; } private void logInfo(Frame frame, int size, String ms) @@ -1381,7 +1388,7 @@ public class TransformerDebug /** * Debugs a request to the Transform Service */ - public void debugTransformServiceRequest(String sourceMimetype, long sourceSize, NodeRef sourceNodeRef, + public int debugTransformServiceRequest(String sourceMimetype, long sourceSize, NodeRef sourceNodeRef, int contentHashcode, String fileName, String targetMimetype, String use) { pushMisc(); @@ -1391,18 +1398,32 @@ public class TransformerDebug (use != null ? "-- "+use+" -- " : "") + " RenditionService2"); debug(sourceNodeRef.toString() + ' ' +contentHashcode); debug(" **a) [01] TransformService"); - pop(Call.AVAILABLE, true); + return pop(Call.AVAILABLE, true, false); } /** * Debugs a response to the Transform Service */ - public void debugTransformServiceResponse(NodeRef sourceNodeRef, int contentHashcode, String msg) + public void debugTransformServiceResponse(NodeRef sourceNodeRef, int contentHashcode, + long requested, int seq, String sourceExt, String targetExt, String msg) { pushMisc(); + Frame frame = ThreadInfo.getStack().getLast(); + frame.id = seq; + boolean suppressFinish = seq == -1 || requested == -1; + if (!suppressFinish) + { + frame.start = requested; +// TODO Create a dummy (available == false) transformer for TransformService before we can record the TS's stats +// String sourceMimetype = mimetypeService.getMimetype(sourceExt); +// String targetMimetype = mimetypeService.getMimetype(targetExt); +// long ms = System.currentTimeMillis()-requested; +// AbstractContentTransformer2 transformer = null; +// transformer.recordTime(sourceMimetype, targetMimetype, ms); + } debug(msg); debug(sourceNodeRef.toString() + ' ' +contentHashcode); - pop(Call.AVAILABLE, true); + pop(Call.AVAILABLE, suppressFinish, true); } public String testTransform(String sourceExtension, String targetExtension, String use) diff --git a/src/main/java/org/alfresco/repo/rendition2/LegacyLocalTransformServiceRegistry.java b/src/main/java/org/alfresco/repo/rendition2/LegacyLocalTransformServiceRegistry.java index e79bf4cd01..0ddd2e9993 100644 --- a/src/main/java/org/alfresco/repo/rendition2/LegacyLocalTransformServiceRegistry.java +++ b/src/main/java/org/alfresco/repo/rendition2/LegacyLocalTransformServiceRegistry.java @@ -62,6 +62,7 @@ public class LegacyLocalTransformServiceRegistry extends AbstractTransformServic public void setEnabled(boolean enabled) { this.enabled = enabled; + firstTime = true; } public void setTransformerDebug(TransformerDebug transformerDebug) diff --git a/src/main/java/org/alfresco/repo/rendition2/RenditionDefinitionRegistry2Impl.java b/src/main/java/org/alfresco/repo/rendition2/RenditionDefinitionRegistry2Impl.java index 417dbc5d43..12e9f92f18 100644 --- a/src/main/java/org/alfresco/repo/rendition2/RenditionDefinitionRegistry2Impl.java +++ b/src/main/java/org/alfresco/repo/rendition2/RenditionDefinitionRegistry2Impl.java @@ -109,7 +109,7 @@ public class RenditionDefinitionRegistry2Impl implements RenditionDefinitionRegi for (Pair pair : renditionNamesWithMaxSize) { Long maxSize = pair.getSecond(); - if (maxSize == -1L || maxSize >= size) + if (maxSize != 0 && (maxSize == -1L || maxSize >= size)) { String renditionName = pair.getFirst(); renditionNames.add(renditionName); diff --git a/src/main/java/org/alfresco/repo/rendition2/SwitchingTransformServiceRegistry.java b/src/main/java/org/alfresco/repo/rendition2/SwitchingTransformServiceRegistry.java index 3be3d1f1d3..66569a5d4c 100644 --- a/src/main/java/org/alfresco/repo/rendition2/SwitchingTransformServiceRegistry.java +++ b/src/main/java/org/alfresco/repo/rendition2/SwitchingTransformServiceRegistry.java @@ -50,7 +50,7 @@ public class SwitchingTransformServiceRegistry extends AbstractTransformServiceR { long maxSize; long primaryMaxSize = primary.getMaxSize(sourceMimetype, targetMimetype, options, renditionName); - if (primaryMaxSize != 0 && primaryMaxSize == -1L) + if (primaryMaxSize == -1L) { maxSize = -1L; } diff --git a/src/main/java/org/alfresco/repo/thumbnail/ThumbnailRegistry.java b/src/main/java/org/alfresco/repo/thumbnail/ThumbnailRegistry.java index b0948e7505..7e6f2a610f 100644 --- a/src/main/java/org/alfresco/repo/thumbnail/ThumbnailRegistry.java +++ b/src/main/java/org/alfresco/repo/thumbnail/ThumbnailRegistry.java @@ -25,15 +25,12 @@ */ package org.alfresco.repo.thumbnail; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - import org.alfresco.repo.content.transform.ContentTransformer; import org.alfresco.repo.content.transform.TransformerDebug; import org.alfresco.repo.lock.JobLockService; import org.alfresco.repo.lock.LockAcquisitionException; +import org.alfresco.repo.rendition2.RenditionDefinition2; +import org.alfresco.repo.rendition2.RenditionDefinitionRegistry2; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; import org.alfresco.repo.tenant.Tenant; @@ -48,6 +45,7 @@ import org.alfresco.service.cmr.thumbnail.ThumbnailException; import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; import org.alfresco.service.transaction.TransactionService; +import org.alfresco.transform.client.model.config.TransformServiceRegistry; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.BeansException; @@ -58,6 +56,11 @@ import org.springframework.context.ApplicationListener; import org.springframework.context.event.ApplicationContextEvent; import org.springframework.extensions.surf.util.AbstractLifecycleBean; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + /** * Registry of all the thumbnail details available * @@ -87,7 +90,11 @@ public class ThumbnailRegistry implements ApplicationContextAware, ApplicationLi protected TenantAdminService tenantAdminService; private JobLockService jobLockService; - + + private TransformServiceRegistry transformServiceRegistry; + + private RenditionDefinitionRegistry2 renditionDefinitionRegistry2; + private boolean redeployStaticDefsOnStartup; /** Map of thumbnail definition */ @@ -155,7 +162,17 @@ public class ThumbnailRegistry implements ApplicationContextAware, ApplicationLi { this.jobLockService = jobLockService; } - + + public void setTransformServiceRegistry(TransformServiceRegistry transformServiceRegistry) + { + this.transformServiceRegistry = transformServiceRegistry; + } + + public void setRenditionDefinitionRegistry2(RenditionDefinitionRegistry2 renditionDefinitionRegistry2) + { + this.renditionDefinitionRegistry2 = renditionDefinitionRegistry2; + } + /** * This method is used to inject the thumbnail definitions. */ @@ -377,25 +394,34 @@ public class ThumbnailRegistry implements ApplicationContextAware, ApplicationLi */ public boolean isThumbnailDefinitionAvailable(String sourceUrl, String sourceMimetype, long sourceSize, NodeRef sourceNodeRef, ThumbnailDefinition thumbnailDefinition) { - // Copy the thumbnail's TransformationOptions and set the sourceNodeRef, for use by transformers and debug. - TransformationOptions options = thumbnailDefinition.getTransformationOptions().deepCopy(); - options.setSourceNodeRef(sourceNodeRef); - - // Log the following getTransform() as trace so we can see the wood for the trees - boolean orig = TransformerDebug.setDebugOutput(false); - try + // Use RenditionService2 if it knows about the definition, otherwise use contentService as before. Needed as + // disabling local transforms should not disable thumbnails if they can be done remotely. + boolean supported = false; + String targetMimetype = thumbnailDefinition.getMimetype(); + RenditionDefinition2 renditionDefinition = getEquivalentRenditionDefinition2(thumbnailDefinition); + if (renditionDefinition != null) { - return this.contentService.getTransformer( - sourceUrl, - sourceMimetype, - sourceSize, - thumbnailDefinition.getMimetype(), options - ) != null; + Map options = renditionDefinition.getTransformOptions(); + String renditionName = renditionDefinition.getRenditionName(); + supported = transformServiceRegistry.isSupported(sourceMimetype, sourceSize, targetMimetype, options, renditionName); } - finally + else { - TransformerDebug.setDebugOutput(orig); + boolean orig = TransformerDebug.setDebugOutput(false); + try + { + // Copy the thumbnail's TransformationOptions and set the sourceNodeRef, for use by debug. + TransformationOptions options = thumbnailDefinition.getTransformationOptions().deepCopy(); + options.setSourceNodeRef(sourceNodeRef); + supported = contentService.getTransformer(sourceUrl, sourceMimetype, sourceSize, + targetMimetype, options) != null; + } + finally + { + TransformerDebug.setDebugOutput(orig); + } } + return supported; } /** @@ -409,21 +435,7 @@ public class ThumbnailRegistry implements ApplicationContextAware, ApplicationLi */ public boolean isThumbnailDefinitionAvailable(String sourceUrl, String sourceMimeType, long sourceSize, ThumbnailDefinition thumbnailDefinition) { - // Log the following getTransform() as trace so we can see the wood for the trees - boolean orig = TransformerDebug.setDebugOutput(false); - try - { - return this.contentService.getTransformer( - sourceUrl, - sourceMimeType, - sourceSize, - thumbnailDefinition.getMimetype(), thumbnailDefinition.getTransformationOptions() - ) != null; - } - finally - { - TransformerDebug.setDebugOutput(orig); - } + return isThumbnailDefinitionAvailable(sourceUrl, sourceMimeType, sourceSize, null, thumbnailDefinition); } /** @@ -435,19 +447,49 @@ public class ThumbnailRegistry implements ApplicationContextAware, ApplicationLi */ public long getMaxSourceSizeBytes(String sourceMimetype, ThumbnailDefinition thumbnailDefinition) { - // Log the following getTransform() as trace so we can see the wood for the trees - boolean orig = TransformerDebug.setDebugOutput(false); - try + // Use RenditionService2 if it knows about the definition, otherwise use contentService as before. Needed as + // disabling local transforms should not disable thumbnails if they can be done remotely. + long maxSize = 0; + String targetMimetype = thumbnailDefinition.getMimetype(); + RenditionDefinition2 renditionDefinition = getEquivalentRenditionDefinition2(thumbnailDefinition); + if (renditionDefinition != null) { - return contentService.getMaxSourceSizeBytes(sourceMimetype, - thumbnailDefinition.getMimetype(), thumbnailDefinition.getTransformationOptions()); + Map options = renditionDefinition.getTransformOptions(); + String renditionName = renditionDefinition.getRenditionName(); + maxSize = transformServiceRegistry.getMaxSize(sourceMimetype, targetMimetype, options, renditionName); } - finally + else { - TransformerDebug.setDebugOutput(orig); + boolean orig = TransformerDebug.setDebugOutput(false); + try + { + TransformationOptions options = thumbnailDefinition.getTransformationOptions(); + maxSize = contentService.getMaxSourceSizeBytes(sourceMimetype, targetMimetype, options); + } + finally + { + TransformerDebug.setDebugOutput(orig); + } } + return maxSize; } - + + private RenditionDefinition2 getEquivalentRenditionDefinition2(ThumbnailDefinition thumbnailDefinition) + { + String renditionName = thumbnailDefinition.getName(); + RenditionDefinition2 renditionDefinition = renditionDefinitionRegistry2.getRenditionDefinition(renditionName); + if (renditionDefinition != null) + { + String thumbnailTargetMimetype = thumbnailDefinition.getMimetype(); + String renditionTargetMimetype = renditionDefinition.getTargetMimetype(); + if (!renditionTargetMimetype.equals(thumbnailTargetMimetype)) + { + renditionDefinition = null; + } + } + return renditionDefinition; + } + /** * Add a thumbnail details * diff --git a/src/main/java/org/alfresco/transform/client/model/config/TransformServiceRegistryImpl.java b/src/main/java/org/alfresco/transform/client/model/config/TransformServiceRegistryImpl.java index 88b5ee625a..2eec19eb08 100644 --- a/src/main/java/org/alfresco/transform/client/model/config/TransformServiceRegistryImpl.java +++ b/src/main/java/org/alfresco/transform/client/model/config/TransformServiceRegistryImpl.java @@ -39,6 +39,8 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import static org.alfresco.repo.rendition2.RenditionDefinition2.TIMEOUT; + /** * Used by clients work out if a transformation is supported by the Transform Service. */ @@ -140,6 +142,13 @@ public class TransformServiceRegistryImpl implements TransformServiceRegistry, I return maxSize.longValue(); } + // Remove the "timeout" property from the actualOptions as it is not used to select a transformer. + if (actualOptions.containsKey(TIMEOUT)) + { + actualOptions = new HashMap(actualOptions); + actualOptions.remove(TIMEOUT); + } + long calculatedMaxSize = 0; ConcurrentMap> targetMap = transformers.get(sourceMimetype); if (targetMap != null) diff --git a/src/main/resources/alfresco/thumbnail-service-context.xml b/src/main/resources/alfresco/thumbnail-service-context.xml index f2784e8ec0..baeef132d3 100644 --- a/src/main/resources/alfresco/thumbnail-service-context.xml +++ b/src/main/resources/alfresco/thumbnail-service-context.xml @@ -237,6 +237,8 @@ + + diff --git a/src/test/java/org/alfresco/MiscContextTestSuite.java b/src/test/java/org/alfresco/MiscContextTestSuite.java index 7767fad66b..4587ddac93 100644 --- a/src/test/java/org/alfresco/MiscContextTestSuite.java +++ b/src/test/java/org/alfresco/MiscContextTestSuite.java @@ -148,24 +148,29 @@ import org.springframework.context.ApplicationContext; // Requires running transformers org.alfresco.repo.rendition2.RenditionService2IntegrationTest.class, org.alfresco.repo.rendition2.LegacyLocalTransformClientIntegrationTest.class, - org.alfresco.repo.rendition2.LegacyLocalTransformServiceRegistryTest.class + org.alfresco.repo.rendition2.LegacyLocalTransformServiceRegistryTest.class, + + // Due to problems reloading the context (bits of it remain), NoLocalTransformRenditionTest has been commented out. + // It works on its own. + org.alfresco.repo.rendition2.RenditionTest.class, +// org.alfresco.repo.rendition2.NoLocalTransformRenditionTest.class, }) public class MiscContextTestSuite { - /** - * Asks {@link ApplicationContextHelper} to give us a - * suitable, perhaps cached context for use in our tests - */ - public static ApplicationContext getMinimalContext() { - ApplicationContextHelper.setUseLazyLoading(false); - ApplicationContextHelper.setNoAutoStart(true); - return ApplicationContextHelper.getApplicationContext( - new String[] { "classpath:alfresco/minimal-context.xml" } - ); - } + /** + * Asks {@link ApplicationContextHelper} to give us a + * suitable, perhaps cached context for use in our tests + */ + public static ApplicationContext getMinimalContext() { + ApplicationContextHelper.setUseLazyLoading(false); + ApplicationContextHelper.setNoAutoStart(true); + return ApplicationContextHelper.getApplicationContext( + new String[] { "classpath:alfresco/minimal-context.xml" } + ); + } - static - { - getMinimalContext(); - } + static + { + getMinimalContext(); + } } diff --git a/src/test/java/org/alfresco/repo/content/transform/TransformerDebugTest.java b/src/test/java/org/alfresco/repo/content/transform/TransformerDebugTest.java index 59dfacb509..fc9b7cb7fb 100644 --- a/src/test/java/org/alfresco/repo/content/transform/TransformerDebugTest.java +++ b/src/test/java/org/alfresco/repo/content/transform/TransformerDebugTest.java @@ -166,11 +166,10 @@ public class TransformerDebugTest assertDebugEntriesEquals(new String[] { "0 pdf txt 1.5 MB ContentService.transform(...) NO transformers\n"+ - "0 \n"+ "0 --a) [---] transformer1<> > 50 KB\n"+ "0 --b) [---] transformer3<> > 50 KB\n"+ "0 --c) [---] transformer4<> > 50 KB\n"+ - "0 Finished in NN ms Transformer NOT available"}, unnumbered(untimed(debug.getEntries(10)))); + "0 Finished in NN ms Just checking if a transformer is available"}, unnumbered(untimed(debug.getEntries(10)))); assertArrayEquals(new String[] { "0 pdf txt WARN 1.5 MB NN ms No transformers as file is > 50 KB"}, unnumbered(untimed(stripDateStamp(log.getEntries(10))))); } diff --git a/src/test/java/org/alfresco/repo/rendition2/AbstractRenditionIntegrationTest.java b/src/test/java/org/alfresco/repo/rendition2/AbstractRenditionIntegrationTest.java index ddbded1866..7ce7a723cb 100644 --- a/src/test/java/org/alfresco/repo/rendition2/AbstractRenditionIntegrationTest.java +++ b/src/test/java/org/alfresco/repo/rendition2/AbstractRenditionIntegrationTest.java @@ -25,54 +25,278 @@ */ package org.alfresco.repo.rendition2; -import java.io.File; -import java.io.FileNotFoundException; -import java.util.Collections; +import junit.framework.AssertionFailedError; import org.alfresco.model.ContentModel; +import org.alfresco.repo.content.MimetypeMap; import org.alfresco.repo.security.authentication.AuthenticationUtil; +import org.alfresco.repo.thumbnail.ThumbnailRegistry; import org.alfresco.repo.transaction.RetryingTransactionHelper; +import org.alfresco.service.cmr.rendition.RenditionService; +import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.ContentService; import org.alfresco.service.cmr.repository.ContentWriter; import org.alfresco.service.cmr.repository.MimetypeService; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.StoreRef; -import org.alfresco.service.cmr.security.AuthenticationService; import org.alfresco.service.cmr.security.MutableAuthenticationService; +import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.security.PersonService; import org.alfresco.service.namespace.QName; import org.alfresco.service.transaction.TransactionService; +import org.alfresco.util.ApplicationContextHelper; import org.alfresco.util.BaseSpringTest; import org.alfresco.util.GUID; import org.alfresco.util.PropertyMap; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.ResourceUtils; +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Collections; + +import static java.lang.Thread.sleep; +import static org.alfresco.model.ContentModel.PROP_CONTENT; +import static org.alfresco.repo.content.MimetypeMap.EXTENSION_BINARY; + /** * Class unites common utility methods for {@link org.alfresco.repo.rendition2} package tests. */ public abstract class AbstractRenditionIntegrationTest extends BaseSpringTest { @Autowired - NodeService nodeService; + protected RenditionService2Impl renditionService2; @Autowired - ContentService contentService; + protected RenditionDefinitionRegistry2 renditionDefinitionRegistry2; @Autowired - MimetypeService mimetypeService; + protected TransformClient transformClient; @Autowired - TransactionService transactionService; + protected RenditionService renditionService; @Autowired - PersonService personService; + protected ThumbnailRegistry thumbnailRegistry; @Autowired - MutableAuthenticationService authenticationService; + protected MimetypeMap mimetypeMap; + + @Autowired + protected MimetypeService mimetypeService; + + @Autowired + protected NodeService nodeService; + + @Autowired + protected ContentService contentService; + + @Autowired + protected TransactionService transactionService; + + @Autowired + protected MutableAuthenticationService authenticationService; + + @Autowired + protected PersonService personService; + + @Autowired + protected PermissionService permissionService; static String PASSWORD = "password"; + protected static final String ADMIN = "admin"; + protected static final String DOC_LIB = "doclib"; + + @BeforeClass + public static void before() + { + // Ensure other applications contexts are closed... + // Multiple consumers not supported for same direct vm in different Camel contexts. + ApplicationContextHelper.closeApplicationContext(); + + // Use the docker images for transforms + System.setProperty("alfresco-pdf-renderer.url", "http://localhost:8090/"); + System.setProperty("img.url", "http://localhost:8091"); + System.setProperty("jodconverter.url", "http://localhost:8092/"); + System.setProperty("tika.url", "http://localhost:8093/"); + } + + @Before + public void setUp() throws Exception + { + assertTrue("The RenditionService2 needs to be enabled", renditionService2.isEnabled()); + } + + @After + public void cleanUp() + { + AuthenticationUtil.clearCurrentSecurityContext(); + } + + @AfterClass + public static void after() + { + System.clearProperty("alfresco-pdf-renderer.url"); + System.clearProperty("img.url"); + System.clearProperty("jodconverter.url"); + System.clearProperty("tika.url"); + } + + protected void checkRendition(String testFileName, String renditionName, boolean expectedToPass) + { + try + { + NodeRef sourceNodeRef = createSource(ADMIN, testFileName); + render(ADMIN, sourceNodeRef, renditionName); + waitForRendition(ADMIN, sourceNodeRef, renditionName); + if (!expectedToPass) + { + fail("The " + renditionName + " rendition should NOT be supported for " + testFileName); + } + } + catch(UnsupportedOperationException e) + { + if (expectedToPass) + { + fail("The " + renditionName + " rendition SHOULD be supported for " + testFileName); + } + } + } + + // Creates a new source node as the given user in its own transaction. + protected NodeRef createSource(String user, String testFileName) + { + return AuthenticationUtil.runAs(() -> + transactionService.getRetryingTransactionHelper().doInTransaction(() -> + createSource(testFileName)), user); + } + + // Creates a new source node as the current user in the current transaction. + private NodeRef createSource(String testFileName) throws FileNotFoundException + { + return createContentNodeFromQuickFile(testFileName); + } + + // Changes the content of a source node as the given user in its own transaction. + protected void updateContent(String user, NodeRef sourceNodeRef, String testFileName) + { + AuthenticationUtil.runAs((AuthenticationUtil.RunAsWork) () -> + transactionService.getRetryingTransactionHelper().doInTransaction(() -> + { + updateContent(sourceNodeRef, testFileName); + return null; + }), user); + } + + // Changes the content of a source node as the current user in the current transaction. + private NodeRef updateContent(NodeRef sourceNodeRef, String testFileName) throws FileNotFoundException + { + File file = ResourceUtils.getFile("classpath:quick/" + testFileName); + nodeService.setProperty(sourceNodeRef, ContentModel.PROP_NAME, testFileName); + + ContentWriter contentWriter = contentService.getWriter(sourceNodeRef, ContentModel.PROP_CONTENT, true); + contentWriter.setMimetype(mimetypeService.guessMimetype(testFileName)); + contentWriter.putContent(file); + + return sourceNodeRef; + } + + // Clears the content of a source node as the given user in its own transaction. + protected void clearContent(String user, NodeRef sourceNodeRef) + { + AuthenticationUtil.runAs((AuthenticationUtil.RunAsWork) () -> + transactionService.getRetryingTransactionHelper().doInTransaction(() -> + { + clearContent(sourceNodeRef); + return null; + }), user); + } + + // Clears the content of a source node as the current user in the current transaction. + private void clearContent(NodeRef sourceNodeRef) + { + nodeService.removeProperty(sourceNodeRef, PROP_CONTENT); + } + + // Requests a new rendition as the given user in its own transaction. + protected void render(String user, NodeRef sourceNode, String renditionName) + { + AuthenticationUtil.runAs((AuthenticationUtil.RunAsWork) () -> + transactionService.getRetryingTransactionHelper().doInTransaction(() -> + { + render(sourceNode, renditionName); + return null; + }), user); + } + + // Requests a new rendition as the current user in the current transaction. + private void render(NodeRef sourceNodeRef, String renditionName) + { + renditionService2.render(sourceNodeRef, renditionName); + } + + // As a given user waitForRendition for a rendition to appear. Creates new transactions to do this. + protected NodeRef waitForRendition(String user, NodeRef sourceNodeRef, String renditionName) throws AssertionFailedError + { + try + { + return AuthenticationUtil.runAs(() -> waitForRendition(sourceNodeRef, renditionName), user); + } + catch (RuntimeException e) + { + Throwable cause = e.getCause(); + if (cause instanceof AssertionFailedError) + { + throw (AssertionFailedError)cause; + } + throw e; + } + } + + // As the current user waitForRendition for a rendition to appear. Creates new transactions to do this. + private NodeRef waitForRendition(NodeRef sourceNodeRef, String renditionName) throws InterruptedException + { + long maxMillis = 10000; + ChildAssociationRef assoc = null; + for (int i = (int)(maxMillis / 1000); i >= 0; i--) + { + // Must create a new transaction in order to see changes that take place after this method started. + assoc = transactionService.getRetryingTransactionHelper().doInTransaction(() -> + renditionService2.getRenditionByName(sourceNodeRef, renditionName), true, true); + if (assoc != null) + { + break; + } + logger.debug("RenditionService2.getRenditionByName(...) sleep "+i); + sleep(1000); + } + assertNotNull("Rendition " + renditionName + " failed", assoc); + return assoc.getChildRef(); + } + + protected String getTestFileName(String sourceMimetype) throws FileNotFoundException + { + String extension = mimetypeMap.getExtension(sourceMimetype); + String testFileName = extension.equals(EXTENSION_BINARY) ? null : "quick."+extension; + if (testFileName != null) + { + try + { + ResourceUtils.getFile("classpath:quick/" + testFileName); + } + catch (FileNotFoundException e) + { + testFileName = null; + } + } + return testFileName; + } + NodeRef createContentNodeFromQuickFile(String fileName) throws FileNotFoundException { NodeRef rootNodeRef = nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE); diff --git a/src/test/java/org/alfresco/repo/rendition2/LegacyLocalTransformClientIntegrationTest.java b/src/test/java/org/alfresco/repo/rendition2/LegacyLocalTransformClientIntegrationTest.java index cb98d24847..46dfd671cf 100644 --- a/src/test/java/org/alfresco/repo/rendition2/LegacyLocalTransformClientIntegrationTest.java +++ b/src/test/java/org/alfresco/repo/rendition2/LegacyLocalTransformClientIntegrationTest.java @@ -41,59 +41,49 @@ import static org.alfresco.model.ContentModel.PROP_CONTENT; */ public class LegacyLocalTransformClientIntegrationTest extends AbstractRenditionIntegrationTest { - @Autowired - private TransformClient transformClient; - - @Autowired - private RenditionDefinitionRegistry2 renditionDefinitionRegistry2; - - @Autowired - private RenditionService2 renditionService2; - @Before - public void setUp() + public void setUp() throws Exception { + super.setUp(); AuthenticationUtil.setRunAsUser(AuthenticationUtil.getAdminUserName()); - assertTrue("A wrong type of transform client detected", transformClient instanceof LegacyLocalTransformClient); } - // PDF transformation @Test public void testLocalRenderPdfToJpegMedium() throws Exception { - checkRendition("quick.pdf", "medium", true); + localCheckRendition("quick.pdf", "medium", true); } @Test public void testLocalRenderPdfToDoclib() throws Exception { - checkRendition("quick.pdf", "doclib", true); + localCheckRendition("quick.pdf", "doclib", true); } @Test public void testLocalRenderPdfJpegImgpreview() throws Exception { - checkRendition("quick.pdf", "imgpreview", true); + localCheckRendition("quick.pdf", "imgpreview", true); } @Test public void testLocalRenderPdfPngAvatar() throws Exception { - checkRendition("quick.pdf", "avatar", true); + localCheckRendition("quick.pdf", "avatar", true); } @Test public void testLocalRenderPdfPngAvatar32() throws Exception { - checkRendition("quick.pdf", "avatar32", true); + localCheckRendition("quick.pdf", "avatar32", true); } @Test public void testLocalRenderPdfFlashWebpreview() throws Exception { - checkRendition("quick.pdf", "webpreview", false); + localCheckRendition("quick.pdf", "webpreview", false); } // DOCX transformation @@ -101,46 +91,46 @@ public class LegacyLocalTransformClientIntegrationTest extends AbstractRendition @Test public void testLocalRenderDocxJpegMedium() throws Exception { - checkRendition("quick.docx", "medium", true); + localCheckRendition("quick.docx", "medium", true); } @Test public void testLocalRenderDocxDoclib() throws Exception { - checkRendition("quick.docx", "doclib", true); + localCheckRendition("quick.docx", "doclib", true); } @Test public void testLocalRenderDocxJpegImgpreview() throws Exception { - checkRendition("quick.docx", "imgpreview", true); + localCheckRendition("quick.docx", "imgpreview", true); } @Test public void testLocalRenderDocxPngAvatar() throws Exception { - checkRendition("quick.docx", "avatar", true); + localCheckRendition("quick.docx", "avatar", true); } @Test public void testLocalRenderDocxPngAvatar32() throws Exception { - checkRendition("quick.docx", "avatar32", true); + localCheckRendition("quick.docx", "avatar32", true); } @Test public void testLocalRenderDocxFlashWebpreview() throws Exception { - checkRendition("quick.docx", "webpreview", false); + localCheckRendition("quick.docx", "webpreview", false); } @Test public void testLocalRenderDocxPdf() throws Exception { - checkRendition("quick.docx", "pdf", false); + localCheckRendition("quick.docx", "pdf", false); } - private void checkRendition(String testFileName, String renditionDefinitionName, boolean expectedToPass) throws InterruptedException + private void localCheckRendition(String testFileName, String renditionDefinitionName, boolean expectedToPass) throws InterruptedException { if (expectedToPass) { diff --git a/src/test/java/org/alfresco/repo/rendition2/LegacyLocalTransformServiceRegistryTest.java b/src/test/java/org/alfresco/repo/rendition2/LegacyLocalTransformServiceRegistryTest.java index 38f84d440d..06520134f5 100644 --- a/src/test/java/org/alfresco/repo/rendition2/LegacyLocalTransformServiceRegistryTest.java +++ b/src/test/java/org/alfresco/repo/rendition2/LegacyLocalTransformServiceRegistryTest.java @@ -54,6 +54,7 @@ public class LegacyLocalTransformServiceRegistryTest extends AbstractRenditionIn @Before public void setUp() throws Exception { + super.setUp(); RenditionDefinition2 definition2 = renditionDefinitionRegistry2.getRenditionDefinition(RENDITION_NAME); options = definition2.getTransformOptions(); } diff --git a/src/test/java/org/alfresco/repo/rendition2/NoLocalTransformRenditionTest.java b/src/test/java/org/alfresco/repo/rendition2/NoLocalTransformRenditionTest.java new file mode 100644 index 0000000000..91be66fbb2 --- /dev/null +++ b/src/test/java/org/alfresco/repo/rendition2/NoLocalTransformRenditionTest.java @@ -0,0 +1,77 @@ +/* + * #%L + * Alfresco Repository + * %% + * Copyright (C) 2005 - 2018 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ +package org.alfresco.repo.rendition2; + +import org.alfresco.util.testing.category.DebugTests; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +/** + * Disables local transform and repeats the RenditionTests + * + * @author adavis + */ +public class NoLocalTransformRenditionTest extends RenditionTest +{ + @BeforeClass + public static void before() + { + AbstractRenditionIntegrationTest.before(); + System.setProperty("local.transform.service.enabled", "false"); + } + + @AfterClass + public static void after() + { + AbstractRenditionIntegrationTest.after(); + System.clearProperty("local.transform.service.enabled"); + } + + + @Test + @Override + public void testTasRestApiRenditions() throws Exception + { + internalTestTasRestApiRenditions(0, 0); + } + + @Category(DebugTests.class) + @Test + @Override + public void testAllSourceExtensions() throws Exception + { + internalTestAllSourceExtensions(0, 0); + } + + @Test + @Override + public void testGifRenditions() throws Exception + { + internalTestGifRenditions(0, 0); + } +} diff --git a/src/test/java/org/alfresco/repo/rendition2/RenditionService2IntegrationTest.java b/src/test/java/org/alfresco/repo/rendition2/RenditionService2IntegrationTest.java index 3f4777760f..44570ee624 100644 --- a/src/test/java/org/alfresco/repo/rendition2/RenditionService2IntegrationTest.java +++ b/src/test/java/org/alfresco/repo/rendition2/RenditionService2IntegrationTest.java @@ -26,10 +26,14 @@ package org.alfresco.repo.rendition2; import java.util.List; + +import junit.framework.AssertionFailedError; import org.alfresco.model.ContentModel; import org.alfresco.model.RenditionModel; +import org.alfresco.repo.content.MimetypeMap; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.permissions.AccessDeniedException; +import org.alfresco.repo.thumbnail.ThumbnailRegistry; import org.alfresco.service.cmr.rendition.RenditionService; import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.ContentWriter; @@ -50,161 +54,13 @@ import java.io.FileNotFoundException; import static java.lang.Thread.sleep; import static org.alfresco.model.ContentModel.PROP_CONTENT; +import static org.alfresco.repo.content.MimetypeMap.EXTENSION_BINARY; /** * Integration tests for {@link RenditionService2} */ public class RenditionService2IntegrationTest extends AbstractRenditionIntegrationTest { - @Autowired - private RenditionService2Impl renditionService2; - @Autowired - private TransformClient transformClient; - @Autowired - private PermissionService permissionService; - @Autowired - private RenditionService renditionService; - - private static final String ADMIN = "admin"; - private static final String DOC_LIB = "doclib"; - - @BeforeClass - public static void before() - { - // Ensure other applications contexts are closed... - // Multiple consumers not supported for same direct vm in different Camel contexts. - ApplicationContextHelper.closeApplicationContext(); - } - - @Before - public void setUp() - { - assertTrue("The RenditionService2 needs to be enabled", renditionService2.isEnabled()); - assertTrue("A wrong type of transform client detected", transformClient instanceof LegacyLocalTransformClient); - } - - @After - public void cleanUp() - { - AuthenticationUtil.clearCurrentSecurityContext(); - } - - private void checkRendition(String testFileName, String renditionName, boolean expectedToPass) - { - try - { - NodeRef sourceNodeRef = createSource(ADMIN, testFileName); - render(ADMIN, sourceNodeRef, renditionName); - waitForRendition(ADMIN, sourceNodeRef, renditionName); - } - catch(UnsupportedOperationException uoe) - { - if (expectedToPass) - { - fail("The " + renditionName + " rendition should be supported for " + testFileName); - } - } - } - - // Creates a new source node as the given user in its own transaction. - private NodeRef createSource(String user, String testFileName) - { - return AuthenticationUtil.runAs(() -> - transactionService.getRetryingTransactionHelper().doInTransaction(() -> - createSource(testFileName)), user); - } - - // Creates a new source node as the current user in the current transaction. - private NodeRef createSource(String testFileName) throws FileNotFoundException - { - return createContentNodeFromQuickFile(testFileName); - } - - // Changes the content of a source node as the given user in its own transaction. - private void updateContent(String user, NodeRef sourceNodeRef, String testFileName) - { - AuthenticationUtil.runAs((AuthenticationUtil.RunAsWork) () -> - transactionService.getRetryingTransactionHelper().doInTransaction(() -> - { - updateContent(sourceNodeRef, testFileName); - return null; - }), user); - } - - // Changes the content of a source node as the current user in the current transaction. - private NodeRef updateContent(NodeRef sourceNodeRef, String testFileName) throws FileNotFoundException - { - File file = ResourceUtils.getFile("classpath:quick/" + testFileName); - nodeService.setProperty(sourceNodeRef, ContentModel.PROP_NAME, testFileName); - - ContentWriter contentWriter = contentService.getWriter(sourceNodeRef, ContentModel.PROP_CONTENT, true); - contentWriter.setMimetype(mimetypeService.guessMimetype(testFileName)); - contentWriter.putContent(file); - - return sourceNodeRef; - } - - // Clears the content of a source node as the given user in its own transaction. - private void clearContent(String user, NodeRef sourceNodeRef) - { - AuthenticationUtil.runAs((AuthenticationUtil.RunAsWork) () -> - transactionService.getRetryingTransactionHelper().doInTransaction(() -> - { - clearContent(sourceNodeRef); - return null; - }), user); - } - - // Clears the content of a source node as the current user in the current transaction. - private void clearContent(NodeRef sourceNodeRef) - { - nodeService.removeProperty(sourceNodeRef, PROP_CONTENT); - } - - // Requests a new rendition as the given user in its own transaction. - private void render(String user, NodeRef sourceNode, String renditionName) - { - AuthenticationUtil.runAs((AuthenticationUtil.RunAsWork) () -> - transactionService.getRetryingTransactionHelper().doInTransaction(() -> - { - render(sourceNode, renditionName); - return null; - }), user); - } - - // Requests a new rendition as the current user in the current transaction. - private void render(NodeRef sourceNodeRef, String renditionName) - { - renditionService2.render(sourceNodeRef, renditionName); - } - - // As a given user waitForRendition for a rendition to appear. Creates new transactions to do this. - private NodeRef waitForRendition(String user, NodeRef sourceNodeRef, String renditionName) - { - return AuthenticationUtil.runAs(() -> waitForRendition(sourceNodeRef, renditionName), user); - } - - // As the current user waitForRendition for a rendition to appear. Creates new transactions to do this. - private NodeRef waitForRendition(NodeRef sourceNodeRef, String renditionName) throws InterruptedException - { - long maxMillis = 20000; - ChildAssociationRef assoc = null; - for (int i = (int)(maxMillis / 500); i >= 0; i--) - { - // Must create a new transaction in order to see changes that take place after this method started. - assoc = transactionService.getRetryingTransactionHelper().doInTransaction(() -> - renditionService2.getRenditionByName(sourceNodeRef, renditionName), true, true); - if (assoc != null) - { - break; - } - logger.debug("RenditionService2.getRenditionByName(...) sleep "+i); - sleep(500); - } - assertNotNull("Rendition " + renditionName + " failed", assoc); - return assoc.getChildRef(); - } - // PDF transformation @Test diff --git a/src/test/java/org/alfresco/repo/rendition2/RenditionTest.java b/src/test/java/org/alfresco/repo/rendition2/RenditionTest.java new file mode 100644 index 0000000000..db22a59f23 --- /dev/null +++ b/src/test/java/org/alfresco/repo/rendition2/RenditionTest.java @@ -0,0 +1,231 @@ +/* + * #%L + * Alfresco Repository + * %% + * Copyright (C) 2005 - 2018 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ +package org.alfresco.repo.rendition2; + +import junit.framework.AssertionFailedError; +import org.alfresco.repo.security.authentication.AuthenticationUtil; +import org.alfresco.repo.thumbnail.ThumbnailDefinition; +import org.alfresco.util.testing.category.DebugTests; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.StringJoiner; + +/** + * Test it is possible to create renditions from the quick files. + * + * @author adavis + */ +public class RenditionTest extends AbstractRenditionIntegrationTest +{ + @Before + public void setUp() throws Exception + { + super.setUp(); + AuthenticationUtil.setRunAsUser(AuthenticationUtil.getAdminUserName()); + } + + private Set getThumbnailNames(List thumbnailDefinitions) + { + + Set names = new HashSet<>(); + for (ThumbnailDefinition thumbnailDefinition : thumbnailDefinitions) + { + String name = thumbnailDefinition.getName(); + names.add(name); + } + return names; + } + + private void assertRenditionsOkayFromSourceExtension(List sourceExtensions, List excludeList, List expectedToFail, + int expectedRenditionCount, int expectedFailedCount) throws Exception + { + int expectedSuccessCount = expectedRenditionCount - Math.min(excludeList.size(), expectedRenditionCount) - expectedFailedCount; + int renditionCount = 0; + int failedCount = 0; + int successCount = 0; + RenditionDefinitionRegistry2 renditionDefinitionRegistry2 = renditionService2.getRenditionDefinitionRegistry2(); + StringJoiner failures = new StringJoiner("\n"); + StringJoiner successes = new StringJoiner("\n"); + + for (String sourceExtension : sourceExtensions) + { + String sourceMimetype = mimetypeMap.getMimetype(sourceExtension); + String testFileName = getTestFileName(sourceMimetype); + if (testFileName != null) + { + Set renditionNames = renditionDefinitionRegistry2.getRenditionNamesFrom(sourceMimetype, -1); + List thumbnailDefinitions = thumbnailRegistry.getThumbnailDefinitions(sourceMimetype, -1); + Set thumbnailNames = getThumbnailNames(thumbnailDefinitions); + assertEquals("There should be the same renditions ("+renditionNames+") as deprecated thumbnails ("+thumbnailNames+")", + renditionNames, thumbnailNames); + + renditionCount += renditionNames.size(); + for (String renditionName : renditionNames) + { + RenditionDefinition2 renditionDefinition = renditionDefinitionRegistry2.getRenditionDefinition(renditionName); + String targetMimetype = renditionDefinition.getTargetMimetype(); + String targetExtension = mimetypeMap.getExtension(targetMimetype); + + String sourceTragetRendition = sourceExtension + ' ' + targetExtension + ' ' + renditionName; + if (!excludeList.contains(sourceTragetRendition)) + { + String task = sourceExtension + " " + targetExtension + " " + renditionName; + + try + { + checkRendition(testFileName, renditionName, !expectedToFail.contains(sourceTragetRendition)); + successes.add(task); + successCount++; + } + catch (AssertionFailedError e) + { + failures.add(task + " " + e.getMessage()); + failedCount++; + } + } + } + } + } + System.out.println("FAILURES:\n"+failures+"\n"); + System.out.println("SUCCESSES:\n"+successes+"\n"); + System.out.println("renditionCount: "+renditionCount+" expected "+expectedRenditionCount); + System.out.println(" failedCount: "+failedCount+" expected "+expectedFailedCount); + System.out.println(" successCount: "+successCount+" expected "+expectedSuccessCount); + + assertEquals("Rendition count has changed", expectedRenditionCount, renditionCount); + assertEquals("Failed rendition count has changed", expectedFailedCount, failedCount); + assertEquals("Successful rendition count has changed", expectedSuccessCount, successCount); + if (failures.length() > 0) + { + fail(failures.toString()); + } + } + + @Test + public void testExpectedNumberOfRenditions() throws Exception + { + RenditionDefinitionRegistry2 renditionDefinitionRegistry21 = renditionService2.getRenditionDefinitionRegistry2(); + Set renditionNames = renditionDefinitionRegistry21.getRenditionNames(); + assertEquals("Added or removed a definition (rendition-service2-contex.xml)?", 7, renditionNames.size()); + } + + @Test + public void testTasRestApiRenditions() throws Exception + { + internalTestTasRestApiRenditions(62, 0); + } + + protected void internalTestTasRestApiRenditions(int expectedRenditionCount, int expectedFailedCount) throws Exception + { + assertRenditionsOkayFromSourceExtension(Arrays.asList("doc", "xls", "ppt", "docx", "xlsx", "pptx", "msg", "pdf", "png", "gif", "jpg"), + Arrays.asList(new String[]{ + "docx jpg imgpreview", + "docx jpg medium", + + "xlsx jpg imgpreview", + "xlsx jpg medium", + + }), + Collections.emptyList(), expectedRenditionCount, expectedFailedCount); + } + + @Category(DebugTests.class) + @Test + public void testAllSourceExtensions() throws Exception + { + internalTestAllSourceExtensions(196, 0); + } + + protected void internalTestAllSourceExtensions(int expectedRenditionCount, int expectedFailedCount) throws Exception + { + List sourceExtensions = new ArrayList<>(); + for (String sourceMimetype : mimetypeMap.getMimetypes()) + { + String sourceExtension = mimetypeMap.getExtension(sourceMimetype); + sourceExtensions.add(sourceExtension); + } + assertRenditionsOkayFromSourceExtension(sourceExtensions, + Arrays.asList(new String[]{ + "docx jpg imgpreview", + "docx jpg medium", + + "xlsx jpg imgpreview", + "xlsx jpg medium", + + "key jpg imgpreview", + "key jpg medium", + "key png doclib", + "key png avatar", + "key png avatar32", + + "pages jpg imgpreview", + "pages jpg medium", + "pages png doclib", + "pages png avatar", + "pages png avatar32", + + "numbers jpg imgpreview", + "numbers jpg medium", + "numbers png doclib", + "numbers png avatar", + "numbers png avatar32", + + "tiff jpg imgpreview", + "tiff jpg medium", + "tiff png doclib", + "tiff png avatar", + "tiff png avatar32", + + "wpd pdf pdf", + "wpd jpg medium", + "wpd png doclib", + "wpd png avatar", + "wpd png avatar32", + "wpd jpg imgpreview" + }), + Collections.emptyList(), expectedRenditionCount, expectedFailedCount); + } + + @Test + public void testGifRenditions() throws Exception + { + internalTestGifRenditions(5, 0); + } + + protected void internalTestGifRenditions(int expectedRenditionCount, int expectedFailedCount) throws Exception + { + assertRenditionsOkayFromSourceExtension(Arrays.asList("gif"), + Collections.emptyList(), Collections.emptyList(), expectedRenditionCount, expectedFailedCount); + } +} diff --git a/src/test/java/org/alfresco/repo/thumbnail/ThumbnailServiceImplTest.java b/src/test/java/org/alfresco/repo/thumbnail/ThumbnailServiceImplTest.java index ca2e5634a9..d27aac729b 100644 --- a/src/test/java/org/alfresco/repo/thumbnail/ThumbnailServiceImplTest.java +++ b/src/test/java/org/alfresco/repo/thumbnail/ThumbnailServiceImplTest.java @@ -1235,6 +1235,7 @@ public class ThumbnailServiceImplTest extends BaseAlfrescoSpringTest { ThumbnailRegistry thumbnailRegistry = this.thumbnailService.getThumbnailRegistry(); List defs = thumbnailRegistry.getThumbnailDefinitions(MimetypeMap.MIMETYPE_HTML, -1); + assertFalse("There should be some thumbnails", defs.isEmpty()); System.out.println("Definitions ..."); for (ThumbnailDefinition def : defs) { diff --git a/src/test/resources/alfresco-global.properties b/src/test/resources/alfresco-global.properties index f20e25649d..cb2a0c19f6 100644 --- a/src/test/resources/alfresco-global.properties +++ b/src/test/resources/alfresco-global.properties @@ -43,4 +43,3 @@ identity-service.enable-pkce=true identity-service.ignore-oauth-query-parameter=true identity-service.credentials.secret=11111 identity-service.credentials.provider=secret -