mirror of
https://github.com/Alfresco/alfresco-transform-core.git
synced 2025-05-12 17:04:48 +00:00
REPO-4331: Update target file size check (#66)
* REPO-4331: Transformers should not throw an exception when source and target files are empty
This commit is contained in:
parent
4da81d99aa
commit
28158ec48b
@ -63,7 +63,7 @@ public class SelectingTransformer
|
||||
transformers.add(new HtmlParserContentTransformer());
|
||||
transformers.add(new StringExtractingContentTransformer());
|
||||
transformers.add(new TextToPdfContentTransformer());
|
||||
// transformers.add(new OOXMLThumbnailContentTransformer()); // Doesn't work with java 11, comment put and disabled test
|
||||
// transformers.add(new OOXMLThumbnailContentTransformer()); // Doesn't work with java 11, transformer and test disabled
|
||||
}
|
||||
|
||||
/**
|
||||
@ -90,10 +90,15 @@ public class SelectingTransformer
|
||||
{
|
||||
throw new TransformException(INTERNAL_SERVER_ERROR.value(), getMessage(e));
|
||||
}
|
||||
if (!targetFile.exists() || targetFile.length() == 0)
|
||||
if (!targetFile.exists())
|
||||
{
|
||||
throw new TransformException(INTERNAL_SERVER_ERROR.value(),
|
||||
"Transformer failed to create an output file");
|
||||
"Transformer failed to create an output file. Target file does not exist.");
|
||||
}
|
||||
if (sourceFile.length() > 0 && targetFile.length() == 0)
|
||||
{
|
||||
throw new TransformException(INTERNAL_SERVER_ERROR.value(),
|
||||
"Transformer failed to create an output file. Target file is empty but source file was not empty.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -104,6 +109,11 @@ public class SelectingTransformer
|
||||
{
|
||||
if (transformer.isTransformable(sourceMimetype, targetMimetype, parameters))
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Using " + transformer.getClass().getName()
|
||||
+ " to transform from " + sourceMimetype + " to " + targetMimetype );
|
||||
}
|
||||
return transformer;
|
||||
}
|
||||
}
|
||||
|
@ -155,7 +155,7 @@ public class MiscControllerTest extends AbstractTransformerControllerTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStringtoString() throws Exception
|
||||
public void testStringToString() throws Exception
|
||||
{
|
||||
String expected = null;
|
||||
byte[] content = null;
|
||||
@ -181,6 +181,23 @@ public class MiscControllerTest extends AbstractTransformerControllerTest
|
||||
assertTrue("The content did not include \""+expected, contentResult.contains(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyTextFileReturnsEmptyFile() throws Exception
|
||||
{
|
||||
// Use empty content to create an empty source file
|
||||
byte[] content = new byte[0];
|
||||
|
||||
MvcResult result = sendText("txt",
|
||||
"UTF-8",
|
||||
MIMETYPE_TEXT_PLAIN,
|
||||
"txt",
|
||||
MIMETYPE_TEXT_PLAIN,
|
||||
"UTF-8",
|
||||
content);
|
||||
|
||||
assertEquals("Returned content should be empty for an empty source file", 0, result.getResponse().getContentLength());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void textToPdf() throws Exception
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user