Added a unit test for error handling in MarkdownFromURLMacro
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package ut.com.atlassian.plugins.confluence;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
|
||||
import org.mockito.*;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
@@ -41,6 +43,24 @@ public class MarkdownFromURLUnitTest {
|
||||
String file = new File("src/test/resources/testMarkdown.md").toURI().toURL().toString();
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
String output = markdownMacro.execute(new HashMap(), file, conversionContext);
|
||||
assertTrue(Pattern.matches("[\\S\\s]*<em>Italic</em>[\\S\\s]*", output));
|
||||
assertThat(Pattern.matches("[\\S\\s]*<em>Italic</em>[\\S\\s]*", output), is(true));
|
||||
}
|
||||
@Test
|
||||
public void testErrorHandling() throws MacroExecutionException, MalformedURLException {
|
||||
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);
|
||||
String input1 = new File("src/test/resources/nonexistantfile.md").toURI().toURL().toString();
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
String output1 = markdownMacro.execute(new HashMap(), input1, conversionContext);
|
||||
assertThat(output1, is(not("")));
|
||||
String input2 = "not_a_URL";
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
String output2 = markdownMacro.execute(new HashMap(), input2, conversionContext);
|
||||
assertThat(output2, is(not("")));
|
||||
String input3 = new File("src/test/resources/testPrivateBitbucket.html").toURI().toURL().toString();
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
String output3 = markdownMacro.execute(new HashMap(), input3, conversionContext);
|
||||
assertThat(output3, is(not("")));
|
||||
}
|
||||
}
|
||||
15
src/test/resources/testPrivateBitbucket.html
Normal file
15
src/test/resources/testPrivateBitbucket.html
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>OpenID transaction in progress</title>
|
||||
</head>
|
||||
<body onload="document.forms[0].submit();">
|
||||
<form id="openid_message" action="https://id.atlassian.com/openid/v2/op" method="post" accept-charset="UTF-8" enctype="application/x-www-form-urlencoded"><input name="openid.ns.crowdid" type="hidden" value="https://developer.atlassian.com/display/CROWDDEV/CrowdID+OpenID+extensions#CrowdIDOpenIDextensions-login-page-parameters"/><input name="openid.return_to" type="hidden" value="https://bitbucket.org/socialauth/complete/atlassianid/?janrain_nonce=2018-09-03T16%3A44%3A09ZAMqmtD"/><input name="openid.realm" type="hidden" value="https://bitbucket.org"/><input name="openid.ns" type="hidden" value="http://specs.openid.net/auth/2.0"/><input name="openid.sreg.optional" type="hidden" value="fullname,nickname,email"/><input name="openid.claimed_id" type="hidden" value="http://specs.openid.net/auth/2.0/identifier_select"/><input name="openid.ns.sreg" type="hidden" value="http://openid.net/extensions/sreg/1.1"/><input name="openid.crowdid.application" type="hidden" value="bitbucket"/><input name="openid.assoc_handle" type="hidden" value="8063999"/><input name="openid.mode" type="hidden" value="checkid_setup"/><input name="openid.identity" type="hidden" value="http://specs.openid.net/auth/2.0/identifier_select"/><input type="submit" value="Continue"/></form>
|
||||
<script>
|
||||
var elements = document.forms[0].elements;
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
elements[i].style.display = "none";
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user