added several negative tests
This commit is contained in:
parent
bc6a09f9b9
commit
3ed79aebb7
@ -71,6 +71,8 @@ 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))
|
||||
throw new TransformException(HttpStatus.BAD_REQUEST.value(), "This transformer does not support source data of the '" + sourceMimetype + "' type");
|
||||
|
||||
List<Extension> extensions = this.gatherExtensions(transformOptions);
|
||||
|
||||
@ -140,10 +142,11 @@ public class CommonmarkTransformer implements Transformer {
|
||||
private Class<?> findClass(String className) {
|
||||
Matcher matcher = this.extClassNamePattern.matcher(className);
|
||||
String extName = matcher.find() ? matcher.group(2) : null;
|
||||
String extPackageName = this.camel2package(extName);
|
||||
|
||||
for (String prefix : this.classSearchPrefixes) {
|
||||
String classPrefix = prefix.replaceAll("\\{name\\}", extPackageName);
|
||||
String extPackageName = extName != null ? this.camel2package(extName) : null;
|
||||
|
||||
for (String classPrefix : this.classSearchPrefixes) {
|
||||
if (extPackageName != null)
|
||||
classPrefix = classPrefix.replaceAll("\\{name\\}", extPackageName);
|
||||
|
||||
try {
|
||||
Class<?> extClass = Class.forName(classPrefix + className);
|
||||
|
@ -73,6 +73,8 @@ 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))
|
||||
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);
|
||||
|
||||
@ -147,8 +149,9 @@ public class FlexmarkTransformer implements Transformer {
|
||||
Matcher matcher = this.extClassNamePattern.matcher(className);
|
||||
String extName = matcher.find() ? matcher.group(2).toLowerCase() : null;
|
||||
|
||||
for (String prefix : this.classSearchPrefixes) {
|
||||
String classPrefix = prefix.replaceAll("\\{name\\}", extName);
|
||||
for (String classPrefix : this.classSearchPrefixes) {
|
||||
if (extName != null)
|
||||
classPrefix = classPrefix.replaceAll("\\{name\\}", extName);
|
||||
|
||||
try {
|
||||
Class<?> extClass = Class.forName(classPrefix + className);
|
||||
|
@ -117,7 +117,6 @@ public class TransformerController extends AbstractTransformerController {
|
||||
logger.trace("getProbeTestTransform().executeTransformCommand('" + sourceFile + "', '" + targetFile + "')");
|
||||
Transformer transformer = transformers.get(new Random().nextInt(2));
|
||||
transformer.transform(MediaType.TEXT_MARKDOWN_VALUE, MediaType.TEXT_HTML_VALUE, Collections.emptyMap(), sourceFile, targetFile);
|
||||
System.out.println(targetFile.length());
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -151,9 +150,6 @@ public class TransformerController extends AbstractTransformerController {
|
||||
targetMimetype = matcher.find() ? this.ext2mime(matcher.group(1)) : this.defaultTarget.toString();
|
||||
}
|
||||
|
||||
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 engine = transformOptions.getOrDefault(RequestParamConstants.ENGINE, FlexmarkTransformer.ID);
|
||||
if (!this.engineMap.containsKey(engine))
|
||||
throw new TransformException(HttpStatus.BAD_REQUEST.value(), "This transformer does not support the following engine: " + engine);
|
||||
|
@ -0,0 +1,18 @@
|
||||
package com.inteligr8.alfresco.module.alfmarkdown;
|
||||
|
||||
import org.alfresco.transformer.executors.Transformer;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
|
||||
public class CommonmarkTransformerTest extends TransformerTest {
|
||||
|
||||
@Autowired
|
||||
@Qualifier(FlexmarkTransformer.ID)
|
||||
protected Transformer transformer;
|
||||
|
||||
@Override
|
||||
public Transformer getTransformer() {
|
||||
return this.transformer;
|
||||
}
|
||||
|
||||
}
|
@ -1,12 +1,17 @@
|
||||
package com.inteligr8.alfresco.module.alfmarkdown;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.transform.exceptions.TransformException;
|
||||
import org.alfresco.transformer.executors.Transformer;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.inteligr8.junit4.AssertRegex;
|
||||
@ -27,4 +32,24 @@ public abstract class TransformerTest {
|
||||
this.getTransformer().extractMetadata("does-not-matter", "does-not-matter", "does-not-matter", Collections.emptyMap(), null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tryTransformUnsupportedMedia() throws Exception {
|
||||
List<String[]> mediaTypePairs = Arrays.asList(
|
||||
new String[] {MediaType.TEXT_PLAIN_VALUE, MediaType.TEXT_PLAIN_VALUE},
|
||||
new String[] {MediaType.TEXT_PLAIN_VALUE, MediaType.TEXT_MARKDOWN_VALUE},
|
||||
new String[] {MediaType.TEXT_MARKDOWN_VALUE, MediaType.TEXT_PLAIN_VALUE},
|
||||
new String[] {MediaType.TEXT_HTML_VALUE, MediaType.TEXT_MARKDOWN_VALUE},
|
||||
new String[] {MediaType.TEXT_MARKDOWN_VALUE, MediaType.TEXT_MARKDOWN_VALUE}
|
||||
);
|
||||
|
||||
for (String[] mediaTypePair : mediaTypePairs) {
|
||||
try {
|
||||
this.getTransformer().transform(mediaTypePair[0], mediaTypePair[1], Collections.emptyMap(), null, null);
|
||||
Assert.fail();
|
||||
} catch (TransformException te) {
|
||||
Assert.assertEquals(te.getMessage(), HttpStatus.BAD_REQUEST.value(), te.getStatusCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user