changes to get testing framework ready
This commit is contained in:
parent
41164123a3
commit
bc6a09f9b9
@ -86,6 +86,12 @@
|
|||||||
</exclusion>
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.inteligr8</groupId>
|
||||||
|
<artifactId>junit4-ext</artifactId>
|
||||||
|
<version>[1.0,2.0)</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jsoup</groupId>
|
<groupId>org.jsoup</groupId>
|
||||||
<artifactId>jsoup</artifactId>
|
<artifactId>jsoup</artifactId>
|
||||||
|
@ -32,11 +32,12 @@ import org.springframework.http.HttpStatus;
|
|||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@Component
|
@Component(CommonmarkTransformer.ID)
|
||||||
public class CommonmarkTransformer implements Transformer {
|
public class CommonmarkTransformer implements Transformer {
|
||||||
|
|
||||||
|
public static final String ID = "commonmark";
|
||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(CommonmarkTransformer.class);
|
private final Logger logger = LoggerFactory.getLogger(CommonmarkTransformer.class);
|
||||||
private final String id = "commonmark";
|
|
||||||
private final List<String> classSearchPrefixes = Arrays.asList("", "org.commonmark.ext.{name}.", "org.commonmark.ext.gfm.{name}.");
|
private final List<String> classSearchPrefixes = Arrays.asList("", "org.commonmark.ext.{name}.", "org.commonmark.ext.gfm.{name}.");
|
||||||
private final Pattern extClassNamePattern = Pattern.compile("[\\.]?(([A-Za-z0-9]+)Extension|[A-Za-z0-9]+)$");
|
private final Pattern extClassNamePattern = Pattern.compile("[\\.]?(([A-Za-z0-9]+)Extension|[A-Za-z0-9]+)$");
|
||||||
|
|
||||||
@ -54,7 +55,7 @@ public class CommonmarkTransformer implements Transformer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTransformerId() {
|
public String getTransformerId() {
|
||||||
return this.id;
|
return ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -34,7 +34,7 @@ import com.vladsch.flexmark.util.ast.IRender;
|
|||||||
import com.vladsch.flexmark.util.data.MutableDataSet;
|
import com.vladsch.flexmark.util.data.MutableDataSet;
|
||||||
import com.vladsch.flexmark.util.misc.Extension;
|
import com.vladsch.flexmark.util.misc.Extension;
|
||||||
|
|
||||||
@Component
|
@Component(FlexmarkTransformer.ID)
|
||||||
public class FlexmarkTransformer implements Transformer {
|
public class FlexmarkTransformer implements Transformer {
|
||||||
|
|
||||||
public static final String ID = "flexmark";
|
public static final String ID = "flexmark";
|
||||||
|
@ -29,9 +29,11 @@
|
|||||||
package com.inteligr8.alfresco.module.alfmarkdown;
|
package com.inteligr8.alfresco.module.alfmarkdown;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Random;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@ -96,21 +98,26 @@ public class TransformerController extends AbstractTransformerController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void mapEngines() {
|
public void registerEngines() {
|
||||||
this.engineMap = new HashMap<>();
|
this.engineMap = new HashMap<>();
|
||||||
for (Transformer transformer : this.transformers)
|
for (Transformer transformer : this.transformers) {
|
||||||
|
if (this.logger.isInfoEnabled())
|
||||||
|
this.logger.info("Registered transformer/engine: " + transformer.getTransformerId());
|
||||||
this.engineMap.put(transformer.getTransformerId(), transformer);
|
this.engineMap.put(transformer.getTransformerId(), transformer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void initProbe() {
|
public void initProbe() {
|
||||||
this.probe = new ProbeTestTransform(this, "quick.src", "quick.trgt",
|
this.probe = new ProbeTestTransform(this, "quick.md", "quick.html",
|
||||||
7455L, 1024L, 150, 10240L, 60L * 20L + 1L, 60L * 15L - 15L) {
|
500L, 500L, 150, 16384L, 10L, 300L) {
|
||||||
@Override
|
@Override
|
||||||
protected void executeTransformCommand(File sourceFile, File targetFile) {
|
protected void executeTransformCommand(File sourceFile, File targetFile) {
|
||||||
if (logger.isTraceEnabled())
|
if (logger.isTraceEnabled())
|
||||||
logger.trace("getProbeTestTransform().executeTransformCommand('" + sourceFile + "', '" + targetFile + "')");
|
logger.trace("getProbeTestTransform().executeTransformCommand('" + sourceFile + "', '" + targetFile + "')");
|
||||||
// TODO test a transformation
|
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());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,16 @@
|
|||||||
<?xml version='1.0' encoding='UTF-8'?>
|
<?xml version='1.0' encoding='UTF-8'?>
|
||||||
|
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns:context="http://www.springframework.org/schema/context"
|
||||||
|
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||||
|
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
|
||||||
|
|
||||||
<bean autowire-candidate="true" class="org.alfresco.transformer.clients.AlfrescoSharedFileStoreClient" />
|
<bean autowire-candidate="true" class="org.alfresco.transformer.clients.AlfrescoSharedFileStoreClient" />
|
||||||
<bean autowire-candidate="true" class="org.springframework.web.client.RestTemplate" />
|
<bean autowire-candidate="true" class="org.springframework.web.client.RestTemplate" />
|
||||||
<bean autowire-candidate="true" class="org.alfresco.transform.client.model.TransformRequestValidator" />
|
<bean autowire-candidate="true" class="org.alfresco.transform.client.model.TransformRequestValidator" />
|
||||||
<bean autowire-candidate="true" class="org.alfresco.transformer.TransformRegistryImpl" />
|
<bean autowire-candidate="true" class="org.alfresco.transformer.TransformRegistryImpl" />
|
||||||
|
|
||||||
|
<context:component-scan base-package="com.inteligr8.alfresco.module.alfmarkdown" />
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
|
1
tengine/src/main/resources/quick.md
Executable file
1
tengine/src/main/resources/quick.md
Executable file
@ -0,0 +1 @@
|
|||||||
|
Just a simple markdown file, which is just a simple text file.
|
@ -7,7 +7,10 @@
|
|||||||
<table>
|
<table>
|
||||||
<tr><td><div style="text-align:right">file *</div></td><td><input type="file" name="file" /></td></tr>
|
<tr><td><div style="text-align:right">file *</div></td><td><input type="file" name="file" /></td></tr>
|
||||||
<tr><td><div style="text-align:right">targetExtension *</div></td><td><input type="text" name="targetExtension" value="" /></td></tr>
|
<tr><td><div style="text-align:right">targetExtension *</div></td><td><input type="text" name="targetExtension" value="" /></td></tr>
|
||||||
<tr><td><div style="text-align:right">engine</div></td><td><input type="text" name="engine" value="" /></td></tr>
|
<tr><td><div style="text-align:right">engine</div></td><td><select name="engine">
|
||||||
|
<option value="commonmark">commonmark</option>
|
||||||
|
<option value="flexmark" selected>flexmark</option>
|
||||||
|
</select></td></tr>
|
||||||
<tr><td><div style="text-align:right">profile</div></td><td><input type="text" name="profile" value="" /></td></tr>
|
<tr><td><div style="text-align:right">profile</div></td><td><input type="text" name="profile" value="" /></td></tr>
|
||||||
<tr><td><div style="text-align:right">extensions</div></td><td><textarea name="extensions" rows="5"></textarea></tr>
|
<tr><td><div style="text-align:right">extensions</div></td><td><textarea name="extensions" rows="5"></textarea></tr>
|
||||||
<tr><td></td><td><input type="submit" value="Transform" /></td></tr>
|
<tr><td></td><td><input type="submit" value="Transform" /></td></tr>
|
||||||
|
@ -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 FlexmarkTransformerTest extends TransformerTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
@Qualifier(FlexmarkTransformer.ID)
|
||||||
|
protected Transformer transformer;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Transformer getTransformer() {
|
||||||
|
return this.transformer;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,13 +1,15 @@
|
|||||||
package com.inteligr8.alfresco.module.alfmarkdown;
|
package com.inteligr8.alfresco.module.alfmarkdown;
|
||||||
|
|
||||||
import org.alfresco.transformer.AbstractTransformerController;
|
import org.alfresco.transformer.AbstractTransformerController;
|
||||||
import org.junit.Ignore;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
import com.inteligr8.junit4.AssertRegex;
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@WebMvcTest(controllers = TransformerController.class)
|
@WebMvcTest(controllers = TransformerController.class)
|
||||||
public class TransformerControllerTest {
|
public class TransformerControllerTest {
|
||||||
@ -15,8 +17,14 @@ public class TransformerControllerTest {
|
|||||||
@Autowired
|
@Autowired
|
||||||
protected AbstractTransformerController controller;
|
protected AbstractTransformerController controller;
|
||||||
|
|
||||||
@Test @Ignore
|
@Test
|
||||||
public void test() {
|
public void tryTransformerName() {
|
||||||
|
Assert.assertEquals("alfmarkdown", this.controller.getTransformerName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void tryVersion() {
|
||||||
|
AssertRegex.assertMatches("[0-9]+\\.[0-9]+(\\.[0-9]+|-SNAPSHOT)", this.controller.version());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,30 @@
|
|||||||
|
package com.inteligr8.alfresco.module.alfmarkdown;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import org.alfresco.transform.exceptions.TransformException;
|
||||||
|
import org.alfresco.transformer.executors.Transformer;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
import com.inteligr8.junit4.AssertRegex;
|
||||||
|
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@WebMvcTest(controllers = TransformerController.class)
|
||||||
|
public abstract class TransformerTest {
|
||||||
|
|
||||||
|
public abstract Transformer getTransformer();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void tryTransformerId() {
|
||||||
|
AssertRegex.assertMatches("flexmark|commonmark", this.getTransformer().getTransformerId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = TransformException.class)
|
||||||
|
public void tryExtractMetadata() throws Exception {
|
||||||
|
this.getTransformer().extractMetadata("does-not-matter", "does-not-matter", "does-not-matter", Collections.emptyMap(), null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user