use of org.alfresco.repo.rendition.executer.AbstractRenderingEngine.RenderingContext 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.repo.rendition.executer.AbstractRenderingEngine.RenderingContext 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.repo.rendition.executer.AbstractRenderingEngine.RenderingContext 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