forked from jbake-org/jbake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GroovyMarkupTemplateEngineRenderingTest.java
83 lines (68 loc) · 3.31 KB
/
GroovyMarkupTemplateEngineRenderingTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package org.jbake.app.template;
import org.apache.commons.io.FileUtils;
import org.jbake.app.Crawler;
import org.jbake.app.DBUtil;
import org.jbake.app.Parser;
import org.jbake.app.Renderer;
import org.jbake.model.DocumentModel;
import org.jbake.model.DocumentTypes;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.File;
import java.nio.charset.Charset;
import java.util.Arrays;
import static org.assertj.core.api.Assertions.assertThat;
public class GroovyMarkupTemplateEngineRenderingTest extends AbstractTemplateEngineRenderingTest {
public GroovyMarkupTemplateEngineRenderingTest() {
super("groovyMarkupTemplates", "tpl");
outputStrings.put("post", Arrays.asList("<h2>Second Post</h2>",
"<p class=\"post-date\">28",
"2013</p>",
"Lorem ipsum dolor sit amet",
"<h5>Published Posts</h5>",
"blog/2012/first-post.html"));
outputStrings.put("page", Arrays.asList("<h4>About</h4>",
"All about stuff!",
"<h5>Published Pages</h5>",
"/projects.html"));
outputStrings.put("index", Arrays.asList("<h4><a href=\"blog/2012/first-post.html\">First Post</a></h4>",
"<h4><a href=\"blog/2013/second-post.html\">Second Post</a></h4>"));
outputStrings.put("feed", Arrays.asList("<description>My corner of the Internet</description>",
"<title>Second Post</title>",
"<title>First Post</title>"));
outputStrings.put("archive", Arrays.asList("<a href=\"blog/2013/second-post.html\">Second Post</a></h4>",
"<a href=\"blog/2012/first-post.html\">First Post</a></h4>"));
outputStrings.put("tags", Arrays.asList("<a href=\"blog/2013/second-post.html\">Second Post</a></h4>",
"<a href=\"blog/2012/first-post.html\">First Post</a></h4>"));
outputStrings.put("sitemap", Arrays.asList("blog/2013/second-post.html",
"blog/2012/first-post.html",
"papers/published-fixture.groovyMarkupTemplates.paper.html"));
outputStrings.put("paper", Arrays.asList("<h2>Published Paper</h2>",
"<p class=\"post-date\">24",
"2014</p>",
"Lorem ipsum dolor sit amet",
"<h5>Published Posts</h5>",
"<li>Published Paper published</li>"));
}
@Test
public void renderCustomTypePaper() throws Exception {
// setup
Crawler crawler = new Crawler(db, config);
crawler.crawl();
Parser parser = new Parser(config);
Renderer renderer = new Renderer(db, config);
String filename = "published-paper.html";
File sampleFile = new File(sourceFolder.getPath() + File.separator + "content" + File.separator + "papers" + File.separator + filename);
DocumentModel content = parser.processFile(sampleFile);
content.setUri("/" + filename);
renderer.render(content);
File outputFile = new File(destinationFolder, filename);
Assert.assertTrue(outputFile.exists());
// verify
String output = FileUtils.readFileToString(outputFile, Charset.defaultCharset());
for (String string : getOutputStrings("paper")) {
assertThat(output).contains(string);
}
}
}