Added a unit test for markdown rendering functionality

This commit is contained in:
unknown
2018-08-22 14:15:25 -06:00
parent 27dcf6d8bf
commit bb8417e57b
5 changed files with 57 additions and 17 deletions

12
pom.xml
View File

@@ -79,6 +79,18 @@
<version>${atlassian.spring.scanner.version}</version> <version>${atlassian.spring.scanner.version}</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.0</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>

View File

@@ -24,7 +24,6 @@ import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport;
import com.atlassian.webresource.api.assembler.PageBuilderService; import com.atlassian.webresource.api.assembler.PageBuilderService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import com.vladsch.flexmark.ast.Node; import com.vladsch.flexmark.ast.Node;
import com.vladsch.flexmark.ext.gfm.strikethrough.StrikethroughSubscriptExtension; import com.vladsch.flexmark.ext.gfm.strikethrough.StrikethroughSubscriptExtension;
import com.vladsch.flexmark.ext.tables.TablesExtension; import com.vladsch.flexmark.ext.tables.TablesExtension;
@@ -41,7 +40,6 @@ import com.vladsch.flexmark.html.HtmlRenderer;
import com.vladsch.flexmark.parser.Parser; import com.vladsch.flexmark.parser.Parser;
import com.vladsch.flexmark.util.options.MutableDataSet; import com.vladsch.flexmark.util.options.MutableDataSet;
import java.net.*; import java.net.*;
import java.io.*; import java.io.*;

View File

@@ -46,7 +46,6 @@ public class MarkdownMacro extends BaseMacro implements Macro
{ {
private final XhtmlContent xhtmlUtils; private final XhtmlContent xhtmlUtils;
private PageBuilderService pageBuilderService; private PageBuilderService pageBuilderService;
@Autowired @Autowired
@@ -55,11 +54,6 @@ public class MarkdownMacro extends BaseMacro implements Macro
this.xhtmlUtils = xhtmlUtils; this.xhtmlUtils = xhtmlUtils;
} }
// public MarkdownMacro(XhtmlContent xhtmlUtils)
// {
// this.xhtmlUtils = xhtmlUtils;
// }
@Override @Override
public BodyType getBodyType() public BodyType getBodyType()
{ {
@@ -107,9 +101,8 @@ public class MarkdownMacro extends BaseMacro implements Macro
HtmlRenderer renderer = HtmlRenderer.builder(options).build(); HtmlRenderer renderer = HtmlRenderer.builder(options).build();
Node document = parser.parse(bodyContent); Node document = parser.parse(bodyContent);
String html = renderer.render(document ) + highlightjs; // "<p>This is <em>Sparta</em></p>\n" String html = renderer.render(document ) + highlightjs;
return html; return html;
} }
@Override @Override

View File

@@ -1,6 +0,0 @@
package com.atlassian.plugins.confluence.markdown;
public interface MyPluginComponent
{
String getName();
}

View File

@@ -0,0 +1,43 @@
package ut.com.atlassian.plugins.confluence;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.assertTrue;
import org.mockito.*;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.HashMap;
import java.util.regex.Pattern;
import com.atlassian.confluence.content.render.xhtml.ConversionContext;
import com.atlassian.confluence.macro.MacroExecutionException;
import com.atlassian.webresource.api.assembler.PageBuilderService;
import com.atlassian.webresource.api.assembler.RequiredResources;
import com.atlassian.webresource.api.assembler.WebResourceAssembler;
import com.atlassian.plugins.confluence.markdown.MarkdownMacro;
@RunWith (MockitoJUnitRunner.class)
public class MarkdownUnitTest {
@Mock
ConversionContext conversionContext;
@Mock
PageBuilderService pageBuilderService;
@Mock
WebResourceAssembler webResourceAssembler;
@Mock
RequiredResources requiredResources;
@InjectMocks
MarkdownMacro markdownMacro;
@Test
public void testMarkdownRendering() throws MacroExecutionException {
Mockito.when(pageBuilderService.assembler()).thenReturn(webResourceAssembler);
Mockito.when(webResourceAssembler.resources()).thenReturn(requiredResources);
Mockito.when(requiredResources.requireWebResource("com.atlassian.plugins.confluence.markdown.confluence-markdown-macro:highlightjs")).thenReturn(requiredResources);
@SuppressWarnings({ "rawtypes", "unchecked" })
String output = markdownMacro.execute(new HashMap(), "*Italic*", conversionContext);
assertTrue(Pattern.matches("<p><em>Italic</em></p>[\\S\\s]*", output));
}
}