/*
 * 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.Matchers.any;
import static org.mockito.Matchers.anyMap;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.io.Serializable;
import java.util.Map;
import junit.framework.TestCase;
import org.alfresco.model.ContentModel;
import org.alfresco.model.RenditionModel;
import org.alfresco.repo.action.executer.ActionExecuter;
import org.alfresco.repo.policy.BehaviourFilter;
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.rendition.RenditionServiceException;
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;
/**
 * @author Nick Smith
 */
public class AbstractRenderingEngineTest extends TestCase
{
    private final NodeRef source = new NodeRef("http://test/sourceId");
    private ContentService contentService;
    private NodeService nodeService;
    private TestRenderingEngine engine;
    @Override
    protected void setUp() throws Exception
    {
        super.setUp();
        this.contentService = mock(ContentService.class);
        this.nodeService = mock(NodeService.class);
        engine = new TestRenderingEngine();
        engine.setContentService(contentService);
        engine.setNodeService(nodeService);
        engine.setBehaviourFilter(mock(BehaviourFilter.class));
    }
    @SuppressWarnings({"unchecked" , "rawtypes"})
    public void testCreateRenditionNodeAssoc() throws Exception
    {
        QName assocType = RenditionModel.ASSOC_RENDITION;
        when(nodeService.exists(source)).thenReturn(true);
        QName nodeType = ContentModel.TYPE_CONTENT;
        ChildAssociationRef renditionAssoc = makeRenditionAssoc();
        RenditionDefinition definition = makeRenditionDefinition(renditionAssoc);
        // 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