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 package fr.ifremer.isisfish.datastore;
27
28 import java.io.StringWriter;
29 import java.io.Writer;
30 import java.util.Date;
31 import java.util.HashMap;
32 import java.util.Map;
33
34 import org.junit.Before;
35 import org.junit.Test;
36
37 import fr.ifremer.isisfish.AbstractIsisFishTest;
38 import fr.ifremer.isisfish.IsisFish;
39 import freemarker.template.Configuration;
40 import freemarker.template.Template;
41
42
43
44
45
46
47
48
49
50
51
52
53 public class FormuleStorageTest extends AbstractIsisFishTest {
54
55 protected Configuration freemarkerConfiguration;
56
57 @Before
58 public void setUp() throws Exception {
59 freemarkerConfiguration = getFreemarkerConfiguration();
60 }
61
62 @Test
63 public void testNewFormuleWithCompilation() throws Exception {
64
65 String fileName = "TestFormule1";
66
67 FormuleStorage formuleStorage = FormuleStorage.getFormule("test",
68 fileName);
69
70
71 Template template = freemarkerConfiguration
72 .getTemplate(FormuleStorage.FORMULE_TEMPLATE);
73
74
75 Map<String, Object> root = new HashMap<>();
76 root.put("category", "");
77 root.put("name", fileName);
78 root.put("date", new Date());
79 root.put("author", IsisFish.config.getUserName());
80 root.put("email", IsisFish.config.getUserMail());
81
82
83 Writer out = new StringWriter();
84 template.process(root, out);
85 out.flush();
86 formuleStorage.setContent(out.toString());
87
88
89
90
91
92 }
93
94 }