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));
}
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());
}
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;
}
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!"));
}
}
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"));
}
}
Aggregations