added quick test and validating HTML output

This commit is contained in:
brian 2021-01-18 17:05:06 -05:00
parent 3ed79aebb7
commit d15b54796d
3 changed files with 34 additions and 2 deletions

View File

@ -71,7 +71,7 @@ public class CommonmarkTransformer implements Transformer {
throws IOException {
if (this.logger.isTraceEnabled())
this.logger.trace("transform('" + transformName + "', '" + sourceMimetype + "', '" + targetMimetype + "', " + transformOptions.keySet() + ", '" + sourceFile + "', '" + targetFile + "')");
if (!MediaType.TEXT_PLAIN_VALUE.equals(sourceMimetype))
if (!MediaType.TEXT_MARKDOWN_VALUE.equals(sourceMimetype))
throw new TransformException(HttpStatus.BAD_REQUEST.value(), "This transformer does not support source data of the '" + sourceMimetype + "' type");
List<Extension> extensions = this.gatherExtensions(transformOptions);

View File

@ -73,7 +73,7 @@ public class FlexmarkTransformer implements Transformer {
throws IOException {
if (this.logger.isTraceEnabled())
this.logger.trace("transform('" + transformName + "', '" + sourceMimetype + "', '" + targetMimetype + "', " + transformOptions.keySet() + ", '" + sourceFile + "', '" + targetFile + "')");
if (!MediaType.TEXT_PLAIN_VALUE.equals(sourceMimetype))
if (!MediaType.TEXT_MARKDOWN_VALUE.equals(sourceMimetype))
throw new TransformException(HttpStatus.BAD_REQUEST.value(), "This transformer does not support source data of the '" + sourceMimetype + "' type");
String profile = transformOptions.getOrDefault(RequestParamConstants.PROFILE, this.profile);

View File

@ -1,11 +1,16 @@
package com.inteligr8.alfresco.module.alfmarkdown;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.alfresco.transform.exceptions.TransformException;
import org.alfresco.transformer.executors.Transformer;
import org.jsoup.Jsoup;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -52,4 +57,31 @@ public abstract class TransformerTest {
}
}
@Test
public void tryTransformQuick() throws IOException, URISyntaxException {
File targetFile = this.transform(Collections.emptyMap(), new File(this.getClass().getResource("/quick.md").toURI()));
try {
Assert.assertEquals(70L, targetFile.length());
// is valid html
Jsoup.parse(targetFile, "utf-8");
} finally {
targetFile.delete();
}
}
private File transform(Map<String, String> transformOptions, File sourceFile) throws IOException, TransformException {
File htmlFile = File.createTempFile("test-", ".html");
try {
this.getTransformer().transform(MediaType.TEXT_MARKDOWN_VALUE, MediaType.TEXT_HTML_VALUE, transformOptions, sourceFile, htmlFile);
return htmlFile;
} catch (RuntimeException re) {
htmlFile.delete();
throw re;
} catch (Error e) {
htmlFile.delete();
throw e;
}
}
}