alfresco-community-repo/source/java/org/alfresco/repo/thumbnail/ThumbnailServiceImplParameterTest.java
Dave Ward 840440764b Merged V4.0-BUG-FIX to HEAD
34321: Make CIFS virtual circuit per session limit configurable, return correct status code when virtual circuit limit is reached.
   Required by Terminal Server clients as they can use a single session for all connections. ALF-13156
   34322: Services part of fix for ALF-13057 Nodes marked with rma:ghosted aspect (or other configurable aspects/types) should not be renditioned.
   34323: Added configuration property for CIFS virtual circuits per session, required by Terminal Server clients. ALF-13156.
   34332: Fix for ALF-8405
   34336: Merged BRANCHES/V4.0 to BRANCHES/DEV/V4.0-BUG-FIX:
      34335: Fixing a failing test as part of ALF-13057
   34338: NodeDAO: re-parent "lost & found" orphan child nodes (see ALF-12358 & ALF-13066 / SYS-301)
   - test fix (follow-on to r34279)
   34341: NodeDAO: re-parent "lost & found" orphan child nodes (see ALF-12358 & ALF-13066 / SYS-301)
   - ano test fix (once more with feeling)
   34351: Merged V4.0 to V4.0-BUG-FIX
      34335: (RECORD ONLY) Fixing a failing test as part of ALF-13057
      34350: Merged V3.4 to V4.0
         34327: ALF-13030 ALF-13041 Transformer Server needs filename and to make its transformer preferred over OpenOffice and JOD
            Relates to ALF-10976 and ALF-10412 set of changes
            - TransformerOptions.sourceNodeRef now populated
            - Set average transformer time via global properties
            - TransformerDebug of active transformers added
         34331: ALF-13030 ALF-13041 Transformer Server needs filename and to make its transformer preferred over OpenOffice and JOD
            Relates to ALF-10976 and ALF-10412 set of changes
            - Fix test failures
         34346: ALF-13030 ALF-13041 Transformer Server needs filename and to make its transformer preferred over OpenOffice and JOD
            Relates to ALF-10976 and ALF-10412 set of changes
            - sourceNodeRef was not available to the first child transformer of a ComplexContentTransformer
   34358: Merged V4.0 to V4.0-BUG-FIX (RECORD ONLY)
      34324: Merged BRANCHES/DEV/V4.0-BUG-FIX to BRANCHES/V4.0:
         34322: Services part of fix for ALF-13057 Nodes marked with rma:ghosted aspect (or other configurable aspects/types) should not be renditioned.
   34360: Merged V3.4-BUG-FIX to V4.0-BUG-FIX (RECORD ONLY)
      34349: Merged V3.4 to V3.4-BUG-FIX
         34327: ALF-13030 ALF-13041 Transformer Server needs filename and to make its transformer preferred over OpenOffice and JOD
            Relates to ALF-10976 and ALF-10412 set of changes
            - TransformerOptions.sourceNodeRef now populated
            - Set average transformer time via global properties
            - TransformerDebug of active transformers added
         34331: ALF-13030 ALF-13041 Transformer Server needs filename and to make its transformer preferred over OpenOffice and JOD
            Relates to ALF-10976 and ALF-10412 set of changes
            - Fix test failures
         34346: ALF-13030 ALF-13041 Transformer Server needs filename and to make its transformer preferred over OpenOffice and JOD
            Relates to ALF-10976 and ALF-10412 set of changes
            - sourceNodeRef was not available to the first child transformer of a ComplexContentTransformer
         34348: Merged PATCHES/V3.4.7 to V3.4
            34347: ALF-12949: Merged V4.0-BUG-FIX to PATCHES/V3.4.7
               33959: Merged BRANCHES/DEV/V3.4-BUG-FIX to BRANCHES/DEV/V4.0-BUG-FIX
                  33950: Fix for ALF-12787:
                         - Surf Memory usage optimizations and improvements to ModelObject and derived classes.
                         - Reduced avg memory usage for a ModelObject in the Surf persister cache from 4.0K to 1.5K.
                         - Related refactoring to support removal of in-memory XML DOM previously used to maintain ModelObject state. Now XML DOM only created as needed for set() operations and thrown away.
                         - Improvements to Surf Persister cache strategy to support MRU style concurrent cache, now uses a LinkedConcurrentHashMap to provide a concurrent cache that also has a configurable maximum capacity
                         - Added various improved spring config for persister caches and default sizes.
               Merged BRANCHES/DEV/V3.4-BUG-FIX to BRANCHES/DEV/V4.0-BUG-FIX
                  33956: Latest SpringSurf libs: Fixed issue with overly aggressive caching of missing page View objects.
               34108: Merged BRANCHES/DEV/V3.4-BUG-FIX to BRANCHES/DEV/V4.0-BUG-FIX
                  34107: Added missing jar lib to wcmquickstart and webeditor dependencies
   34363: Merged V4.0 to V4.0-BUG-FIX
      34362: Merged V3.4 to V4.0 (RECORD ONLY)
         34282: ALF-13059: Windows 7 specific: It's impossible to add documents to DWS
         - Fix by Alex Malinovsky
         34348: Merged PATCHES/V3.4.7 to V3.4
            34347: ALF-12949: Merged V4.0-BUG-FIX to PATCHES/V3.4.7
               33959: Merged BRANCHES/DEV/V3.4-BUG-FIX to BRANCHES/DEV/V4.0-BUG-FIX
                  33950: Fix for ALF-12787:
                         - Surf Memory usage optimizations and improvements to ModelObject and derived classes.
                         - Reduced avg memory usage for a ModelObject in the Surf persister cache from 4.0K to 1.5K.
                         - Related refactoring to support removal of in-memory XML DOM previously used to maintain ModelObject state. Now XML DOM only created as needed for set() operations and thrown away.
                         - Improvements to Surf Persister cache strategy to support MRU style concurrent cache, now uses a LinkedConcurrentHashMap to provide a concurrent cache that also has a configurable maximum capacity
                         - Added various improved spring config for persister caches and default sizes.
               Merged BRANCHES/DEV/V3.4-BUG-FIX to BRANCHES/DEV/V4.0-BUG-FIX
                  33956: Latest SpringSurf libs: Fixed issue with overly aggressive caching of missing page View objects.
               34108: Merged BRANCHES/DEV/V3.4-BUG-FIX to BRANCHES/DEV/V4.0-BUG-FIX
                  34107: Added missing jar lib to wcmquickstart and webeditor dependencies


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@34364 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
2012-03-02 15:00:35 +00:00

180 lines
8.2 KiB
Java

/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.thumbnail;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.content.transform.magick.ImageResizeOptions;
import org.alfresco.repo.content.transform.magick.ImageTransformationOptions;
import org.alfresco.repo.rendition.MockedTestServiceRegistry;
import org.alfresco.repo.rendition.RenditionServiceImpl;
import org.alfresco.repo.rendition.executer.AbstractRenderingEngine;
import org.alfresco.repo.rendition.executer.ImageRenderingEngine;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ActionService;
import org.alfresco.service.cmr.rendition.RenditionDefinition;
import org.alfresco.service.cmr.rendition.RenditionService;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.thumbnail.ThumbnailParentAssociationDetails;
import org.alfresco.service.cmr.thumbnail.ThumbnailService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
/**
* Thumbnail service implementation unit test
*
* @author Neil McErlean
*/
public class ThumbnailServiceImplParameterTest
{
// Mocked services.
private ActionService mockActionService = mock(ActionService.class);
// Real services - backed by mocked services.
private RenditionServiceImpl renditionService;
private ThumbnailService thumbnailService;
private final NodeRef dummyNodeRef1 = new NodeRef("workspace", "dummy", "dummyID_1");
private final NodeRef dummyNodeRef2 = new NodeRef("workspace", "dummy", "dummyID_2");
private final NodeRef dummyNodeRef3 = new NodeRef("workspace", "dummy", "dummyID_3");
@Before
public void initMockObjects()
{
renditionService = new RenditionServiceImpl()
{
@Override
public RenditionDefinition loadRenditionDefinition(QName renditionDefinitionName)
{
// We're intentionally returning null for this test.
return null;
}
};
renditionService.setActionService(mockActionService);
renditionService.setServiceRegistry(new MockedTestServiceRegistry());
ThumbnailServiceImpl thumbs = new ThumbnailServiceImpl()
{
@Override
public NodeRef getThumbnailByName(NodeRef node,
QName contentProperty, String thumbnailName)
{
return null;
}
/**
* In this test the thumbnailRef will be null, so we need to ensure
* it is not dereferenced here.
*/
@Override
public NodeRef getThumbnailNode(ChildAssociationRef thumbnailRef)
{
return null;
}
};
thumbs.setRenditionService(renditionService);
thumbs.setThumbnailRegistry(new ThumbnailRegistry() {
@Override
public ThumbnailRenditionConvertor getThumbnailRenditionConvertor()
{
return new ThumbnailRenditionConvertor();
}
});
thumbs.setNodeService(mock(NodeService.class));
thumbnailService = thumbs;
}
/**
* This test method ensures that the parameters on thumbnail-create are
* passed through the RenditionService to the ActionService
*/
@Test
public void createThumbnailPassesParametersToActionService()
{
// As most of the services are mocked out, the actual values used here
// don't matter.
final Map<String, Serializable> parametersUnderTest = new HashMap<String, Serializable>();
parametersUnderTest.put(ImageRenderingEngine.PARAM_RESIZE_WIDTH, new Integer(42));
parametersUnderTest.put(ImageRenderingEngine.PARAM_RESIZE_HEIGHT, new Integer(93));
parametersUnderTest.put(ImageRenderingEngine.PARAM_COMMAND_OPTIONS, "foo");
parametersUnderTest.put(ImageRenderingEngine.PARAM_MAINTAIN_ASPECT_RATIO, Boolean.TRUE);
parametersUnderTest.put(ImageRenderingEngine.PARAM_RESIZE_TO_THUMBNAIL, Boolean.FALSE);
parametersUnderTest.put(ImageRenderingEngine.PARAM_ALLOW_ENLARGEMENT, Boolean.TRUE);
parametersUnderTest.put(AbstractRenderingEngine.PARAM_TARGET_CONTENT_PROPERTY, ContentModel.PROP_CONTENT);
parametersUnderTest.put(RenditionService.PARAM_DESTINATION_NODE, dummyNodeRef2);
ImageTransformationOptions imageTransOpts = new ImageTransformationOptions();
imageTransOpts.setTargetNodeRef(dummyNodeRef2);
imageTransOpts.setTargetContentProperty((QName) parametersUnderTest.get(ImageRenderingEngine.PARAM_TARGET_CONTENT_PROPERTY));
imageTransOpts.setCommandOptions((String) parametersUnderTest.get(ImageRenderingEngine.PARAM_COMMAND_OPTIONS));
ImageResizeOptions resizeOptions = new ImageResizeOptions();
resizeOptions.setHeight((Integer) parametersUnderTest.get(ImageRenderingEngine.PARAM_RESIZE_HEIGHT));
resizeOptions.setWidth((Integer) parametersUnderTest.get(ImageRenderingEngine.PARAM_RESIZE_WIDTH));
resizeOptions.setMaintainAspectRatio((Boolean) parametersUnderTest.get(ImageRenderingEngine.PARAM_MAINTAIN_ASPECT_RATIO));
resizeOptions.setResizeToThumbnail((Boolean) parametersUnderTest.get(ImageRenderingEngine.PARAM_RESIZE_TO_THUMBNAIL));
resizeOptions.setAllowEnlargement((Boolean) parametersUnderTest.get(ImageRenderingEngine.PARAM_ALLOW_ENLARGEMENT));
imageTransOpts.setResizeOptions(resizeOptions);
ThumbnailParentAssociationDetails assocDetails = new ThumbnailParentAssociationDetails(dummyNodeRef3,
ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI,
"homerSimpson"));
// Now request the creation of the the thumbnail.
thumbnailService.createThumbnail(dummyNodeRef1, ContentModel.PROP_CONTENT, MimetypeMap.MIMETYPE_IMAGE_JPEG,
imageTransOpts, "bartSimpson", assocDetails);
ArgumentCaptor<Action> argument = ArgumentCaptor.forClass(Action.class);
verify(mockActionService).executeAction(argument.capture(), any(NodeRef.class), anyBoolean(), anyBoolean());
final Action action = argument.getValue();
final RenditionDefinition renditionDefn = (RenditionDefinition)action;
Map<String, Serializable> parameters = renditionDefn.getParameterValues();
for (String s : parametersUnderTest.keySet())
{
if (parameters.keySet().contains(s) == false || parameters.get(s) == null || parameters.get(s).toString().length() == 0)
{
fail("Missing parameter " + s);
}
assertEquals("Parameter " + s + " had wrong value.",
parametersUnderTest.get(s), parameters.get(s));
}
}
}