Skip to content

Commit 0c6f2ba

Browse files
committed
DocHelperExample converted to JUnit
1 parent f86c89a commit 0c6f2ba

File tree

1 file changed

+75
-0
lines changed
  • code-samples-fj-doc/src/test/java/test/testorg/fugerit/java/codesamplesfjdoc

1 file changed

+75
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package test.testorg.fugerit.java.codesamplesfjdoc;
2+
3+
import lombok.extern.slf4j.Slf4j;
4+
import org.fugerit.java.codesamplesfjdoc.DocHelper;
5+
import org.fugerit.java.codesamplesfjdoc.DocHelperExample;
6+
import org.fugerit.java.doc.base.config.DocConfig;
7+
import org.fugerit.java.doc.base.process.DocProcessContext;
8+
import org.junit.jupiter.api.Test;
9+
10+
import java.io.ByteArrayOutputStream;
11+
import java.io.IOException;
12+
import java.nio.charset.StandardCharsets;
13+
import java.util.Arrays;
14+
import java.util.List;
15+
16+
/**
17+
* This is a basic example of Fugerit Venus Doc usage,
18+
* running this main the program will :
19+
* - creates data to be used in document model
20+
* - renders the 'document.ftl' template
21+
* - print the result in markdown format on the log
22+
*
23+
* For further documentation :
24+
* https://github.com/fugerit-org/fj-doc
25+
*/
26+
@Slf4j
27+
class DocHelperTest {
28+
29+
@Test
30+
void example() throws IOException {
31+
try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) {
32+
// creates the doc helper
33+
DocHelper docHelper = new DocHelper();
34+
// create custom data for the fremarker template 'document.ftl'
35+
List<DocHelperExample.People> listPeople = Arrays.asList( new DocHelperExample.People( "Luthien", "Tinuviel", "Queen" ), new DocHelperExample.People( "Thorin", "Oakshield", "King" ) );
36+
// handler id
37+
String handlerId = DocConfig.TYPE_MD;
38+
// output generation
39+
docHelper.getDocProcessConfig().fullProcess( "document", DocProcessContext.newContext( "listPeople", listPeople ), handlerId, baos );
40+
// print the output
41+
log.info( "html output : \n{}", new String( baos.toByteArray(), StandardCharsets.UTF_8 ) );
42+
}
43+
}
44+
45+
/*
46+
* Class used to wrap data to be rendered in the document template
47+
*/
48+
public static class People {
49+
50+
private String name;
51+
52+
private String surname;
53+
54+
private String title;
55+
56+
public People(String name, String surname, String title) {
57+
this.name = name;
58+
this.surname = surname;
59+
this.title = title;
60+
}
61+
62+
public String getName() {
63+
return name;
64+
}
65+
66+
public String getSurname() {
67+
return surname;
68+
}
69+
70+
public String getTitle() {
71+
return title;
72+
}
73+
}
74+
75+
}

0 commit comments

Comments
 (0)