/*
* 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 .
*/
package org.alfresco.repo.rendition.executer;
import static org.mockito.Mockito.*;
import java.io.Serializable;
import java.util.Map;
import junit.framework.TestCase;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.executer.ActionExecuter;
import org.alfresco.repo.rendition.RenditionDefinitionImpl;
import org.alfresco.repo.rendition.executer.AbstractRenderingEngine.RenderingContext;
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.ContentService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
import org.mockito.ArgumentCaptor;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
/**
* @author Nick Smith
*/
public class AbstractRenderingEngineTest extends TestCase
{
private ContentService contentService;
private NodeService nodeService;
private TestRenderingEngine engine;
@Override
protected void setUp() throws Exception
{
super.setUp();
this.contentService = mock(ContentService.class);
NodeService nodeService1 = makeNodeService();
this.nodeService = nodeService1;
engine = new TestRenderingEngine();
engine.setContentService(contentService);
engine.setNodeService(nodeService);
}
/**
* Creates a mock node service which fails with a helpful message by default if createNode is called.
* @return
*/
private NodeService makeNodeService()
{
NodeService nodeService1 = mock(NodeService.class);
return nodeService1;
}
@SuppressWarnings("unchecked")
public void testCreateRenditionNodeAssoc() throws Exception
{
NodeRef source = new NodeRef("http://test/sourceId");
when(nodeService.exists(source)).thenReturn(true);
QName assocType = ContentModel.ASSOC_CONTAINS;
QName assocName = QName.createQName("url", "renditionName");
QName nodeType = ContentModel.TYPE_CONTENT;
ChildAssociationRef renditionAssoc = mock(ChildAssociationRef.class);
// Set up the rendition definition.
String id = "definitionId";
RenditionDefinition definition = new RenditionDefinitionImpl(id, assocName, TestRenderingEngine.NAME);
definition.setRenditionAssociationType(assocType);
definition.setRenditionParent(source);
// Stub the createNode() method to return renditionAssoc.
when(nodeService
.createNode(eq(source), eq(assocType), any(QName.class), any(QName.class), anyMap()))
.thenReturn(renditionAssoc);
engine.execute(definition, source);
// Check the createNode method was called with the correct parameters.
// Check the nodeType defaults to cm:content.
ArgumentCaptor