use of org.alfresco.service.cmr.rendition.RenditionServiceException in project alfresco-repository by Alfresco.
the class RenditionServiceIntegrationTest method testRenditionPlacements.
/**
* Using a dummy rendition engine, perform a number of
* renditions, both single and composite, to check that
* the renditions always end up as they should do.
*/
@Test
public void testRenditionPlacements() throws Exception {
QName plainQName = QName.createQName("Plain");
RenditionDefinition rdPlain = renditionService.createRenditionDefinition(plainQName, DummyHelloWorldRenditionEngine.ENGINE_NAME);
QName compositeQName = QName.createQName("Composite");
CompositeRenditionDefinition rdComposite = renditionService.createCompositeRenditionDefinition(compositeQName);
rdComposite.addAction(renditionService.createRenditionDefinition(QName.createQName("CompositePart1"), DummyHelloWorldRenditionEngine.ENGINE_NAME));
rdComposite.addAction(renditionService.createRenditionDefinition(QName.createQName("CompositePart2"), DummyHelloWorldRenditionEngine.ENGINE_NAME));
// ============================================== //
// Anonymous Rendition, no existing one there //
// ============================================== //
assertNotNull(nodeWithDocContent);
assertEquals(0, renditionService.getRenditions(nodeWithDocContent).size());
assertEquals(0, nodeService.getChildAssocs(nodeWithDocContent).size());
// Do a plain rendition, and check we acquired the one node
renditionService.render(nodeWithDocContent, rdPlain);
ChildAssociationRef renditionAssoc = renditionService.getRenditionByName(nodeWithDocContent, plainQName);
assertNotNull(renditionAssoc);
assertEquals(1, nodeService.getChildAssocs(nodeWithDocContent).size());
assertEquals(plainQName, nodeService.getChildAssocs(nodeWithDocContent).get(0).getQName());
// Tidy
nodeService.deleteNode(renditionService.getRenditions(nodeWithDocContent).get(0).getChildRef());
assertNotNull(nodeWithDocContent);
assertEquals(0, renditionService.getRenditions(nodeWithDocContent).size());
assertEquals(0, nodeService.getChildAssocs(nodeWithDocContent).size());
// Now do a composite rendition
// Should once again have one node, despite there having been intermediate
// nodes created during the composite stage
renditionService.render(nodeWithDocContent, rdComposite);
assertEquals(1, renditionService.getRenditions(nodeWithDocContent).size());
assertEquals(1, nodeService.getChildAssocs(nodeWithDocContent).size());
renditionAssoc = renditionService.getRenditionByName(nodeWithDocContent, compositeQName);
assertNotNull(renditionAssoc);
assertEquals(compositeQName, nodeService.getChildAssocs(nodeWithDocContent).get(0).getQName());
// Tidy
nodeService.deleteNode(renditionService.getRenditions(nodeWithDocContent).get(0).getChildRef());
// ================================================ //
// Anonymous Rendition, existing one, same type //
// ================================================ //
// Create one of the right type for a plain rendition
renditionService.render(nodeWithDocContent, rdPlain);
assertEquals(1, renditionService.getRenditions(nodeWithDocContent).size());
assertEquals(1, nodeService.getChildAssocs(nodeWithDocContent).size());
renditionAssoc = renditionService.getRenditionByName(nodeWithDocContent, plainQName);
assertNotNull(renditionAssoc);
// Run again, shouldn't change, should re-use the node
renditionNode = renditionAssoc.getChildRef();
renditionService.render(nodeWithDocContent, rdPlain);
assertEquals(1, renditionService.getRenditions(nodeWithDocContent).size());
assertEquals(1, nodeService.getChildAssocs(nodeWithDocContent).size());
renditionAssoc = renditionService.getRenditionByName(nodeWithDocContent, plainQName);
assertNotNull(renditionAssoc);
assertEquals(renditionNode, renditionAssoc.getChildRef());
assertEquals(plainQName, nodeService.getChildAssocs(nodeWithDocContent).get(0).getQName());
// Tidy, and re-create for composite
nodeService.deleteNode(renditionService.getRenditions(nodeWithDocContent).get(0).getChildRef());
renditionService.render(nodeWithDocContent, rdComposite);
assertEquals(1, renditionService.getRenditions(nodeWithDocContent).size());
assertEquals(1, nodeService.getChildAssocs(nodeWithDocContent).size());
renditionAssoc = renditionService.getRenditionByName(nodeWithDocContent, compositeQName);
assertNotNull(renditionAssoc);
// Run again, shouldn't change, should re-use the node
renditionNode = renditionAssoc.getChildRef();
renditionService.render(nodeWithDocContent, rdComposite);
assertEquals(1, renditionService.getRenditions(nodeWithDocContent).size());
assertEquals(1, nodeService.getChildAssocs(nodeWithDocContent).size());
renditionAssoc = renditionService.getRenditionByName(nodeWithDocContent, compositeQName);
assertNotNull(renditionAssoc);
assertEquals(renditionNode, renditionAssoc.getChildRef());
assertEquals(compositeQName, nodeService.getChildAssocs(nodeWithDocContent).get(0).getQName());
// Tidy
nodeService.deleteNode(renditionService.getRenditions(nodeWithDocContent).get(0).getChildRef());
// ================================================= //
// Anonymous Rendition, existing one, wrong type //
// Note - this situation is not possible! //
// ================================================= //
// ================================================= //
// Switch to being path based //
// ================================================= //
String fileName = "HelloWorld.txt";
String path = "/" + (String) nodeService.getProperty(repositoryHelper.getCompanyHome(), ContentModel.PROP_NAME) + "/" + (String) nodeService.getProperty(testTargetFolder, ContentModel.PROP_NAME) + "/" + fileName;
rdPlain.setParameterValue(RenditionService.PARAM_DESTINATION_PATH_TEMPLATE, path);
rdComposite.setParameterValue(RenditionService.PARAM_DESTINATION_PATH_TEMPLATE, path);
QName expectedName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, fileName);
// ================================================= //
// Path based rendition, no existing one there //
// ================================================= //
assertNotNull(nodeWithDocContent);
assertEquals(0, renditionService.getRenditions(nodeWithDocContent).size());
assertEquals(0, nodeService.getChildAssocs(nodeWithDocContent).size());
List<ChildAssociationRef> children = nodeService.getChildAssocs(testTargetFolder);
assertEquals(0, children.size());
// Do a plain rendition, and check we acquired the one node
renditionService.render(nodeWithDocContent, rdPlain);
assertEquals(1, renditionService.getRenditions(nodeWithDocContent).size());
assertEquals(1, nodeService.getChildAssocs(nodeWithDocContent).size());
renditionAssoc = renditionService.getRenditionByName(nodeWithDocContent, plainQName);
assertNotNull(renditionAssoc);
assertFalse(renditionAssoc.isPrimary());
children = nodeService.getChildAssocs(testTargetFolder);
assertEquals(1, children.size());
ChildAssociationRef childAssoc = children.get(0);
assertEquals(expectedName, childAssoc.getQName());
assertTrue(childAssoc.isPrimary());
nodeService.deleteNode(renditionService.getRenditions(nodeWithDocContent).get(0).getChildRef());
assertNotNull(nodeWithDocContent);
assertEquals(0, renditionService.getRenditions(nodeWithDocContent).size());
// FIXME There is a bug in the NodeService whereby associations to children in the archive store
// i.e. deleted children, are included in the results to the getChildAssocs call.
// Therefore, pending a fix to that, we need to suppress this check and similar checks below.
// assertEquals(0, nodeService.getChildAssocs(nodeWithDocContent).size());
assertEquals(0, nodeService.getChildAssocs(testTargetFolder).size());
// Now do a composite rendition
// Should once again have one node, despite there having been intermediate
// nodes created during the composite stage
renditionService.render(nodeWithDocContent, rdComposite);
assertEquals(1, renditionService.getRenditions(nodeWithDocContent).size());
// assertEquals(1, nodeService.getChildAssocs(nodeWithDocContent).size());
renditionAssoc = renditionService.getRenditionByName(nodeWithDocContent, compositeQName);
assertNotNull(renditionAssoc);
assertFalse(renditionAssoc.isPrimary());
children = nodeService.getChildAssocs(testTargetFolder);
assertEquals(1, children.size());
childAssoc = children.get(0);
assertEquals(expectedName, childAssoc.getQName());
assertTrue(childAssoc.isPrimary());
// Tidy
nodeService.deleteNode(renditionService.getRenditions(nodeWithDocContent).get(0).getChildRef());
// ================================================= //
// Path Based Rendition, existing one, same type //
// ================================================= //
// Create one of the right type for a plain rendition
renditionService.render(nodeWithDocContent, rdPlain);
assertEquals(1, renditionService.getRenditions(nodeWithDocContent).size());
// assertEquals(1, nodeService.getChildAssocs(nodeWithDocContent).size());
assertEquals(1, children.size());
renditionAssoc = renditionService.getRenditionByName(nodeWithDocContent, plainQName);
assertNotNull(renditionAssoc);
// Run again, shouldn't change, should re-use the node
renditionNode = renditionAssoc.getChildRef();
renditionService.render(nodeWithDocContent, rdPlain);
assertEquals(1, renditionService.getRenditions(nodeWithDocContent).size());
// assertEquals(1, nodeService.getChildAssocs(nodeWithDocContent).size());
renditionAssoc = renditionService.getRenditionByName(nodeWithDocContent, plainQName);
assertNotNull(renditionAssoc);
assertFalse(renditionAssoc.isPrimary());
assertEquals(renditionNode, renditionAssoc.getChildRef());
children = nodeService.getChildAssocs(testTargetFolder);
assertEquals(1, children.size());
childAssoc = children.get(0);
assertEquals(expectedName, childAssoc.getQName());
assertTrue(childAssoc.isPrimary());
assertEquals(renditionNode, childAssoc.getChildRef());
// Tidy, and re-create for composite
nodeService.deleteNode(renditionService.getRenditions(nodeWithDocContent).get(0).getChildRef());
renditionService.render(nodeWithDocContent, rdComposite);
assertEquals(1, renditionService.getRenditions(nodeWithDocContent).size());
// assertEquals(1, nodeService.getChildAssocs(nodeWithDocContent).size());
assertEquals(1, children.size());
renditionAssoc = renditionService.getRenditionByName(nodeWithDocContent, compositeQName);
assertNotNull(renditionAssoc);
// Run again, shouldn't change, should re-use the node
renditionNode = renditionAssoc.getChildRef();
renditionService.render(nodeWithDocContent, rdComposite);
assertEquals(1, renditionService.getRenditions(nodeWithDocContent).size());
// assertEquals(1, nodeService.getChildAssocs(nodeWithDocContent).size());
renditionAssoc = renditionService.getRenditionByName(nodeWithDocContent, compositeQName);
assertNotNull(renditionAssoc);
assertFalse(renditionAssoc.isPrimary());
assertEquals(renditionNode, renditionAssoc.getChildRef());
children = nodeService.getChildAssocs(testTargetFolder);
assertEquals(1, children.size());
childAssoc = children.get(0);
assertEquals(expectedName, childAssoc.getQName());
assertTrue(childAssoc.isPrimary());
assertEquals(renditionNode, childAssoc.getChildRef());
// ================================================= //
// Path Based Rendition, existing one, wrong type //
// ================================================= //
// We currently have a composite one
assertEquals(expectedName, children.get(0).getQName());
// Run the plain rendition, the composite one should be replaced
// with the new one
renditionNode = children.get(0).getChildRef();
// linked to its source node by a rn:rendition association of the same name as the new rendition.
try {
renditionService.render(nodeWithDocContent, rdPlain);
fail("Expected RenditionServiceException not thrown");
} catch (RenditionServiceException expected) {
// Do Nothing.
}
}
use of org.alfresco.service.cmr.rendition.RenditionServiceException 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.RenditionServiceException in project alfresco-repository by Alfresco.
the class AbstractRenderingEngineTest method testCheckSourceNodeExists.
public void testCheckSourceNodeExists() {
when(nodeService.exists(any(NodeRef.class))).thenReturn(false);
RenditionDefinitionImpl definition = new RenditionDefinitionImpl("id", null, TestRenderingEngine.NAME);
try {
engine.executeImpl(definition, source);
fail("Should have thrown an exception here!");
} catch (RenditionServiceException e) {
assertTrue(e.getMessage().endsWith("Cannot execute action as node does not exist: http://test/sourceId"));
}
}
use of org.alfresco.service.cmr.rendition.RenditionServiceException 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"));
}
}
use of org.alfresco.service.cmr.rendition.RenditionServiceException in project alfresco-repository by Alfresco.
the class RenditionServiceIntegrationTest method testSuitablyMarkedNodesDoNotGetRenditioned.
/**
* Tests that source nodes with a suitable marker aspect on them are not renditioned.
*
* @since 4.0.1
*/
@Test
public void testSuitablyMarkedNodesDoNotGetRenditioned() throws Exception {
this.renditionNode = transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<NodeRef>() {
public NodeRef execute() throws Throwable {
// Initially the node that provides the content
// should not have the rn:renditioned aspect on it.
assertFalse("Source node has unexpected renditioned aspect.", nodeService.hasAspect(nodeWithImageContent, RenditionModel.ASPECT_RENDITIONED));
// Add the marker aspect to prevent rendition
nodeService.addAspect(nodeWithImageContent, RenditionModel.ASPECT_PREVENT_RENDITIONS, null);
RenditionDefinition action = makeReformatAction(null, MimetypeMap.MIMETYPE_TEXT_PLAIN);
action.setParameterValue(AbstractRenderingEngine.PARAM_MIME_TYPE, MimetypeMap.MIMETYPE_IMAGE_JPEG);
ChildAssociationRef renditionAssoc = null;
boolean expectedExceptionThrown = false;
try {
renditionAssoc = renditionService.render(nodeWithImageContent, action);
} catch (RenditionServiceException expected) {
expectedExceptionThrown = true;
}
assertTrue("Expected exception was not thrown.", expectedExceptionThrown);
return renditionAssoc == null ? null : renditionAssoc.getChildRef();
}
});
}
Aggregations