-#foreach( $email in $emails) + #foreach( $email in $emails) $email #enddiff --git a/src/main/resources/templates/export.vm b/src/main/resources/templates/export.vm index e357750..dae8695 100644 --- a/src/main/resources/templates/export.vm +++ b/src/main/resources/templates/export.vm @@ -1,31 +1,32 @@ #set( $dateFormatter = $action.getDateFormatter())
$bodyWithHtml
$dateFormatter.formatDateTime($date2userName.value) | -$profile.getFullName() | -$profile.getEmail() | -
- | $profile.getFullName() | -$profile.getEmail() | -
$dateFormatter.formatDateTime($date2userName.value) | +$profile.getFullName() | +$profile.getEmail() | +
+ | $profile.getFullName() | +$profile.getEmail() | +
$bodyWithHtml
-$bodyWithHtml
+This is Sparta
\n", markdown.toHTML("This is *Sparta*")); - assertEquals("Link
\n", markdown.toHTML("[Link](http://a.com)")); - assertEquals("\n", markdown.toHTML("![Image](http://url/a.png)")); - assertEquals("<b></b>
\n", markdown.toHTML("")); - assertEquals(readResource("commonmark.html").trim(), markdown.toHTML(readResource("commonmark.md")).trim()); - } - - - private String readResource(String name) throws IOException, URISyntaxException { - return readAllLines(get(getClass().getResource("/"+name).toURI())).stream().collect(joining("\n")); - } - + private Markdown markdown; + + @Before + public void setUp() { + markdown = new Markdown(); + } + + @Test + public void testToHTML() throws Exception { + assertEquals("This is Sparta
\n", markdown.toHTML("This is *Sparta*")); + assertEquals("Link
\n", markdown.toHTML("[Link](http://a.com)")); + assertEquals("\n", markdown.toHTML("![Image](http://url/a.png)")); + assertEquals("<b></b>
\n", markdown.toHTML("")); + assertEquals(readResource("commonmark.html").trim(), markdown.toHTML(readResource("commonmark.md")).trim()); + } + + private String readResource(String name) throws IOException, URISyntaxException { + return String.join("\n", readAllLines(get(getClass().getResource("/" + name).toURI()))); + } } diff --git a/src/test/java/com/baloise/confluence/digitalsignature/MessageFormatTest.java b/src/test/java/com/baloise/confluence/digitalsignature/MessageFormatTest.java index 09a2610..4d2dde1 100644 --- a/src/test/java/com/baloise/confluence/digitalsignature/MessageFormatTest.java +++ b/src/test/java/com/baloise/confluence/digitalsignature/MessageFormatTest.java @@ -1,21 +1,19 @@ package com.baloise.confluence.digitalsignature; -import static org.junit.Assert.*; - import java.text.MessageFormat; import org.junit.Test; -public class MessageFormatTest { - - @Test - public void test() { - String rawTemplate = "Email addresses of users who {0}signed{1} {2}"; - String actual = MessageFormat.format(rawTemplate, "", "", "#123"); - assertEquals("Email addresses of users who signed #123", actual); - rawTemplate = "{2} was {0}signed{1}"; - actual = MessageFormat.format(rawTemplate, "", "", "#123"); - assertEquals("#123 was signed", actual); - } +import static org.junit.Assert.assertEquals; +public class MessageFormatTest { + @Test + public void test() { + String rawTemplate = "Email addresses of users who {0}signed{1} {2}"; + String actual = MessageFormat.format(rawTemplate, "", "", "#123"); + assertEquals("Email addresses of users who signed #123", actual); + rawTemplate = "{2} was {0}signed{1}"; + actual = MessageFormat.format(rawTemplate, "", "", "#123"); + assertEquals("#123 was signed", actual); + } } diff --git a/src/test/java/com/baloise/confluence/digitalsignature/SignatureSerialisationTest.java b/src/test/java/com/baloise/confluence/digitalsignature/SignatureSerialisationTest.java index e5ee2dc..165ce7f 100644 --- a/src/test/java/com/baloise/confluence/digitalsignature/SignatureSerialisationTest.java +++ b/src/test/java/com/baloise/confluence/digitalsignature/SignatureSerialisationTest.java @@ -1,7 +1,6 @@ package com.baloise.confluence.digitalsignature; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import org.junit.Test; import java.io.FileOutputStream; import java.io.IOException; @@ -9,35 +8,34 @@ import java.io.ObjectOutputStream; import java.util.Date; -import org.junit.Test; - -import jdk.nashorn.internal.ir.annotations.Ignore; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; public class SignatureSerialisationTest { + @Test + public void deserialise() throws IOException, ClassNotFoundException { + ObjectInputStream in = new ObjectInputStream(getClass().getResourceAsStream("/signature.ser")); + Signature signature = (Signature) in.readObject(); + in.close(); + assertEquals("signature.a077cdcc5bfcf275fe447ae2c609c1c361331b4e90cb85909582e0d824cbc5b3", signature.getKey()); + assertEquals("[missing1, missing2]", signature.getMissingSignatures().toString()); + assertEquals(1, signature.getSignatures().size()); + assertTrue(signature.getSignatures().containsKey("signed1")); + assertEquals(9999, signature.getSignatures().get("signed1").getTime()); + } - @Test - public void deserialise() throws IOException, ClassNotFoundException { - ObjectInputStream in = new ObjectInputStream(getClass().getResourceAsStream("/signature.ser")); - Signature signature = (Signature) in.readObject(); - in.close(); - assertEquals("signature.a077cdcc5bfcf275fe447ae2c609c1c361331b4e90cb85909582e0d824cbc5b3", signature.getKey()); - assertEquals("[missing1, missing2]", signature.getMissingSignatures().toString()); - assertEquals(1, signature.getSignatures().size()); - assertTrue( signature.getSignatures().containsKey("signed1")); - assertEquals(9999, signature.getSignatures().get("signed1").getTime()); - } - - @Test - @Ignore - public void serialise() throws IOException { - Signature signature = new Signature(123L, "body", "title"); - signature.getNotify().add("notify1"); - signature.getMissingSignatures().add("missing1"); - signature.getMissingSignatures().add("missing2"); - signature.getSignatures().put("signed1", new Date(9999)); - ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("src/test/resources/signature.ser")); - out.writeObject(signature); - out.close(); - } + @Test + public void serialise() throws IOException, ClassNotFoundException { + Signature signature = new Signature(123L, "body", "title"); + signature.getNotify().add("notify1"); + signature.getMissingSignatures().add("missing1"); + signature.getMissingSignatures().add("missing2"); + signature.getSignatures().put("signed1", new Date(9999)); + ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("src/test/resources/signature-test.ser")); + out.writeObject(signature); + out.close(); + ObjectInputStream in = new ObjectInputStream(this.getClass().getResourceAsStream("/signature.ser")); + assertEquals(signature, in.readObject()); + } } diff --git a/src/test/java/com/baloise/confluence/digitalsignature/TemplatesTest.java b/src/test/java/com/baloise/confluence/digitalsignature/TemplatesTest.java index 8bbe1d4..e4930a3 100644 --- a/src/test/java/com/baloise/confluence/digitalsignature/TemplatesTest.java +++ b/src/test/java/com/baloise/confluence/digitalsignature/TemplatesTest.java @@ -1,48 +1,46 @@ package com.baloise.confluence.digitalsignature; -import static org.apache.velocity.app.Velocity.mergeTemplate; +import org.apache.velocity.VelocityContext; +import org.junit.Test; import java.io.BufferedWriter; import java.io.StringWriter; import java.io.Writer; -import org.apache.velocity.VelocityContext; -import org.apache.velocity.exception.MethodInvocationException; -import org.apache.velocity.exception.ParseErrorException; -import org.apache.velocity.exception.ResourceNotFoundException; -import org.junit.Test; +import static org.apache.velocity.app.Velocity.mergeTemplate; +import static org.junit.Assert.assertEquals; public class TemplatesTest { + private static String normalize(String input) { + return input.replaceAll("[\n\r]", "") + .replaceAll(" +", " ") + .replaceAll("> <", "><") + .trim(); + } - @Test - public void test() throws ResourceNotFoundException, ParseErrorException, MethodInvocationException, Exception { - StringWriter sw = new StringWriter(); - //let's buffer Writer for better performace: - Writer writer = new BufferedWriter(sw); - VelocityContext context = new VelocityContext(); - //add your parameters to context - mergeTemplate("src/main/resources/templates/macro.vm", "UTF-8", context, writer); - writer.flush(); - String result = sw.toString(); - System.out.println(result); - } - - @Test - public void test2() throws ResourceNotFoundException, ParseErrorException, MethodInvocationException, Exception { - StringWriter sw = new StringWriter(); - //let's buffer Writer for better performace: - Writer writer = new BufferedWriter(sw); - VelocityContext context = new VelocityContext(); - //add your parameters to context - mergeTemplate("src/main/resources/templates/export.vm", "UTF-8", context, writer); - writer.flush(); - String result = sw.toString(); - System.out.println(result); - } - - @Test - public void foo() { - System.out.println("https://test-confluence.baloisenet.com/atlassian/rest/signature/1.0/".split("rest/")[0]); - } + @Test + public void testMacroVm() throws Exception { + StringWriter sw = new StringWriter(); + //lets use BufferedWriter for better performance: + Writer writer = new BufferedWriter(sw); + VelocityContext context = new VelocityContext(); + //add your parameters to context + mergeTemplate("src/main/resources/templates/macro.vm", "UTF-8", context, writer); + writer.flush(); + String expected = "#requireResource(\"com.baloise.confluence.digital-signature:digital-signature-resources\") $title$bodyWithHtml
$bodyWithHtml