Added a unit test for markdown rendering functionality
This commit is contained in:
12
pom.xml
12
pom.xml
@@ -79,6 +79,18 @@
|
||||
<version>${atlassian.spring.scanner.version}</version>
|
||||
<scope>provided</scope>
|
||||
</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>
|
||||
<build>
|
||||
<plugins>
|
||||
|
||||
@@ -24,7 +24,6 @@ import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport;
|
||||
import com.atlassian.webresource.api.assembler.PageBuilderService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
|
||||
import com.vladsch.flexmark.ast.Node;
|
||||
import com.vladsch.flexmark.ext.gfm.strikethrough.StrikethroughSubscriptExtension;
|
||||
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.util.options.MutableDataSet;
|
||||
|
||||
|
||||
import java.net.*;
|
||||
import java.io.*;
|
||||
|
||||
|
||||
@@ -46,7 +46,6 @@ public class MarkdownMacro extends BaseMacro implements Macro
|
||||
{
|
||||
|
||||
private final XhtmlContent xhtmlUtils;
|
||||
|
||||
private PageBuilderService pageBuilderService;
|
||||
|
||||
@Autowired
|
||||
@@ -54,12 +53,7 @@ public class MarkdownMacro extends BaseMacro implements Macro
|
||||
this.pageBuilderService = pageBuilderService;
|
||||
this.xhtmlUtils = xhtmlUtils;
|
||||
}
|
||||
|
||||
// public MarkdownMacro(XhtmlContent xhtmlUtils)
|
||||
// {
|
||||
// this.xhtmlUtils = xhtmlUtils;
|
||||
// }
|
||||
|
||||
|
||||
@Override
|
||||
public BodyType getBodyType()
|
||||
{
|
||||
@@ -107,9 +101,8 @@ public class MarkdownMacro extends BaseMacro implements Macro
|
||||
HtmlRenderer renderer = HtmlRenderer.builder(options).build();
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
package com.atlassian.plugins.confluence.markdown;
|
||||
|
||||
public interface MyPluginComponent
|
||||
{
|
||||
String getName();
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user