Search in sources :

Example 46 with RenditionDefinition

use of org.alfresco.service.cmr.rendition.RenditionDefinition in project alfresco-repository by Alfresco.

the class AbstractRenderingEngineTest method testCreateRenditionNodeAssoc.

@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<Map> captor = ArgumentCaptor.forClass(Map.class);
    verify(nodeService).createNode(eq(source), eq(assocType), any(QName.class), eq(nodeType), captor.capture());
    Map<String, Serializable> props = captor.getValue();
    // Check the node name is set to match teh rendition name local name.
    assertEquals(renditionAssoc.getQName().getLocalName(), props.get(ContentModel.PROP_NAME));
    // Check content property name defaults to cm:content
    assertEquals(ContentModel.PROP_CONTENT, props.get(ContentModel.PROP_CONTENT_PROPERTY_NAME));
    // Check the returned result is the association created by the call to
    // nodeServcie.createNode().
    Serializable result = definition.getParameterValue(ActionExecuter.PARAM_RESULT);
    assertEquals("The returned rendition association is not the one created by the node service!", renditionAssoc, result);
    // Check that setting the default content property and default node type
    // on the rendition engine works.
    nodeType = QName.createQName("url", "someNodeType");
    QName contentPropName = QName.createQName("url", "someContentProp");
    engine.setDefaultRenditionContentProp(contentPropName.toString());
    engine.setDefaultRenditionNodeType(nodeType.toString());
    engine.execute(definition, source);
    verify(nodeService).createNode(eq(source), eq(assocType), any(QName.class), eq(nodeType), captor.capture());
    props = captor.getValue();
    assertEquals(contentPropName, props.get(ContentModel.PROP_CONTENT_PROPERTY_NAME));
    // Check that setting the rendition node type param works.
    nodeType = ContentModel.TYPE_THUMBNAIL;
    contentPropName = ContentModel.PROP_CONTENT;
    definition.setParameterValue(RenditionService.PARAM_RENDITION_NODETYPE, nodeType);
    definition.setParameterValue(AbstractRenderingEngine.PARAM_TARGET_CONTENT_PROPERTY, contentPropName);
    engine.execute(definition, source);
    verify(nodeService).createNode(eq(source), eq(assocType), any(QName.class), eq(nodeType), captor.capture());
    props = captor.getValue();
    assertEquals(contentPropName, props.get(ContentModel.PROP_CONTENT_PROPERTY_NAME));
}
Also used : Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) RenditionDefinition(org.alfresco.service.cmr.rendition.RenditionDefinition) ArgumentMatchers.anyMap(org.mockito.ArgumentMatchers.anyMap) Map(java.util.Map)

Example 47 with RenditionDefinition

use of org.alfresco.service.cmr.rendition.RenditionDefinition in project alfresco-repository by Alfresco.

the class AbstractRenderingEngineTest method testRenderingContext.

@SuppressWarnings("unchecked")
public void testRenderingContext() {
    when(nodeService.exists(source)).thenReturn(true);
    ChildAssociationRef renditionAssoc = makeRenditionAssoc();
    RenditionDefinition definition = makeRenditionDefinition(renditionAssoc);
    // Stub the createNode() method to return renditionAssoc.
    when(nodeService.createNode(eq(source), eq(renditionAssoc.getTypeQName()), any(QName.class), any(QName.class), anyMap())).thenReturn(renditionAssoc);
    engine.execute(definition, source);
    RenderingContext context = engine.getContext();
    assertEquals(definition, context.getDefinition());
    assertEquals(renditionAssoc.getChildRef(), context.getDestinationNode());
    assertEquals(source, context.getSourceNode());
}
Also used : RenderingContext(org.alfresco.repo.rendition.executer.AbstractRenderingEngine.RenderingContext) QName(org.alfresco.service.namespace.QName) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) RenditionDefinition(org.alfresco.service.cmr.rendition.RenditionDefinition)

Example 48 with RenditionDefinition

use of org.alfresco.service.cmr.rendition.RenditionDefinition in project alfresco-repository by Alfresco.

the class AbstractRenderingEngineTest method makeRenditionDefinition.

/**
 * Set up the rendition definition.
 * @param renditionAssoc ChildAssociationRef
 * @return RenditionDefinition
 */
private RenditionDefinition makeRenditionDefinition(ChildAssociationRef renditionAssoc) {
    String id = "definitionId";
    RenditionDefinition definition = new RenditionDefinitionImpl(id, renditionAssoc.getQName(), TestRenderingEngine.NAME);
    definition.setRenditionAssociationType(renditionAssoc.getTypeQName());
    definition.setRenditionParent(source);
    return definition;
}
Also used : RenditionDefinition(org.alfresco.service.cmr.rendition.RenditionDefinition) RenditionDefinitionImpl(org.alfresco.repo.rendition.RenditionDefinitionImpl)

Example 49 with RenditionDefinition

use of org.alfresco.service.cmr.rendition.RenditionDefinition in project alfresco-repository by Alfresco.

the class AbstractRenderingEngineTest method testGetCheckedParameter.

@SuppressWarnings("unchecked")
public void testGetCheckedParameter() {
    when(nodeService.exists(source)).thenReturn(true);
    ChildAssociationRef renditionAssoc = makeRenditionAssoc();
    RenditionDefinition definition = makeRenditionDefinition(renditionAssoc);
    // Stub the createNode() method to return renditionAssoc.
    when(nodeService.createNode(eq(source), eq(renditionAssoc.getTypeQName()), any(QName.class), any(QName.class), anyMap())).thenReturn(renditionAssoc);
    engine.executeImpl(definition, source);
    RenderingContext context = engine.getContext();
    String paramName = "Some param";
    // Check returns null by default.
    String result = context.getCheckedParam(paramName, String.class);
    assertNull(result);
    // Check can set a value to return.
    String value = "value";
    definition.setParameterValue(paramName, value);
    engine.executeImpl(definition, source);
    context = engine.getContext();
    result = context.getCheckedParam(paramName, String.class);
    assertEquals(value, result);
    // Check throws an exception if value is of wrong type.
    try {
        context.getCheckedParam(paramName, Boolean.class);
        fail("Should throw an exception if type is wrong!");
    } catch (RenditionServiceException e) {
        assertTrue(e.getMessage().endsWith("The parameter: Some param must be of type: java.lang.Booleanbut was of type: java.lang.String"));
    }
    // Check throws an exception if value is of wrong type.
    try {
        context.getCheckedParam(paramName, null);
        fail("Should throw an exception if type is wrong!");
    } catch (RenditionServiceException e) {
        assertTrue(e.getMessage().endsWith("The class must not be null!"));
    }
}
Also used : RenderingContext(org.alfresco.repo.rendition.executer.AbstractRenderingEngine.RenderingContext) QName(org.alfresco.service.namespace.QName) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) RenditionDefinition(org.alfresco.service.cmr.rendition.RenditionDefinition) RenditionServiceException(org.alfresco.service.cmr.rendition.RenditionServiceException)

Example 50 with RenditionDefinition

use of org.alfresco.service.cmr.rendition.RenditionDefinition in project alfresco-repository by Alfresco.

the class AbstractRenderingEngineTest method testGetParameterWithDefault.

@SuppressWarnings("unchecked")
public void testGetParameterWithDefault() {
    when(nodeService.exists(source)).thenReturn(true);
    ChildAssociationRef renditionAssoc = makeRenditionAssoc();
    RenditionDefinition definition = makeRenditionDefinition(renditionAssoc);
    // Stub the createNode() method to return renditionAssoc.
    when(nodeService.createNode(eq(source), eq(renditionAssoc.getTypeQName()), any(QName.class), any(QName.class), anyMap())).thenReturn(renditionAssoc);
    engine.executeImpl(definition, source);
    RenderingContext context = engine.getContext();
    // Check default value works.
    String paramName = "Some-param";
    String defaultValue = "default";
    Object result = context.getParamWithDefault(paramName, defaultValue);
    assertEquals(defaultValue, result);
    // Check specific value overrides default.
    String value = "value";
    definition.setParameterValue(paramName, value);
    engine.executeImpl(definition, source);
    context = engine.getContext();
    result = context.getParamWithDefault(paramName, defaultValue);
    assertEquals(value, result);
    // Check null default value throws exception.
    try {
        result = context.getParamWithDefault(paramName, null);
        fail("Should throw an Exception if default value is null!");
    } catch (RenditionServiceException e) {
        assertTrue(e.getMessage().endsWith("The defaultValue cannot be null!"));
    }
    // Check wrong type of default value throws exception.
    try {
        result = context.getParamWithDefault(paramName, Boolean.TRUE);
        fail("Should throw an exception if default value is of incoorect type!");
    } catch (RenditionServiceException e) {
        assertTrue(e.getMessage().endsWith("The parameter: Some-param must be of type: java.lang.Booleanbut was of type: java.lang.String"));
    }
}
Also used : RenderingContext(org.alfresco.repo.rendition.executer.AbstractRenderingEngine.RenderingContext) QName(org.alfresco.service.namespace.QName) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) RenditionDefinition(org.alfresco.service.cmr.rendition.RenditionDefinition) RenditionServiceException(org.alfresco.service.cmr.rendition.RenditionServiceException)

Aggregations

RenditionDefinition (org.alfresco.service.cmr.rendition.RenditionDefinition)58 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)32 QName (org.alfresco.service.namespace.QName)28 Test (org.junit.Test)25 CompositeRenditionDefinition (org.alfresco.service.cmr.rendition.CompositeRenditionDefinition)22 BaseAlfrescoSpringTest (org.alfresco.util.BaseAlfrescoSpringTest)21 AbstractContentTransformerTest (org.alfresco.repo.content.transform.AbstractContentTransformerTest)14 NodeRef (org.alfresco.service.cmr.repository.NodeRef)13 Serializable (java.io.Serializable)11 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)11 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)9 RenditionServiceException (org.alfresco.service.cmr.rendition.RenditionServiceException)9 ArrayList (java.util.ArrayList)6 ContentReader (org.alfresco.service.cmr.repository.ContentReader)6 AuthenticationUtil (org.alfresco.repo.security.authentication.AuthenticationUtil)5 FileInfo (org.alfresco.service.cmr.model.FileInfo)5 HashMap (java.util.HashMap)3 RenderingContext (org.alfresco.repo.rendition.executer.AbstractRenderingEngine.RenderingContext)3 List (java.util.List)2 ImageTransformationOptions (org.alfresco.repo.content.transform.magick.ImageTransformationOptions)2