added quick test and validating HTML output
This commit is contained in:
parent
3ed79aebb7
commit
d15b54796d
@ -71,7 +71,7 @@ public class CommonmarkTransformer implements Transformer {
|
|||||||
throws IOException {
|
throws IOException {
|
||||||
if (this.logger.isTraceEnabled())
|
if (this.logger.isTraceEnabled())
|
||||||
this.logger.trace("transform('" + transformName + "', '" + sourceMimetype + "', '" + targetMimetype + "', " + transformOptions.keySet() + ", '" + sourceFile + "', '" + targetFile + "')");
|
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");
|
throw new TransformException(HttpStatus.BAD_REQUEST.value(), "This transformer does not support source data of the '" + sourceMimetype + "' type");
|
||||||
|
|
||||||
List<Extension> extensions = this.gatherExtensions(transformOptions);
|
List<Extension> extensions = this.gatherExtensions(transformOptions);
|
||||||
|
@ -73,7 +73,7 @@ public class FlexmarkTransformer implements Transformer {
|
|||||||
throws IOException {
|
throws IOException {
|
||||||
if (this.logger.isTraceEnabled())
|
if (this.logger.isTraceEnabled())
|
||||||
this.logger.trace("transform('" + transformName + "', '" + sourceMimetype + "', '" + targetMimetype + "', " + transformOptions.keySet() + ", '" + sourceFile + "', '" + targetFile + "')");
|
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");
|
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);
|
String profile = transformOptions.getOrDefault(RequestParamConstants.PROFILE, this.profile);
|
||||||
|
@ -1,11 +1,16 @@
|
|||||||
package com.inteligr8.alfresco.module.alfmarkdown;
|
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.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.alfresco.transform.exceptions.TransformException;
|
import org.alfresco.transform.exceptions.TransformException;
|
||||||
import org.alfresco.transformer.executors.Transformer;
|
import org.alfresco.transformer.executors.Transformer;
|
||||||
|
import org.jsoup.Jsoup;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user