View Javadoc
1   /*
2    * #%L
3    * IsisFish
4    * 
5    * $Id: SensitivityAnalysisStorageTest.java 4291 2015-06-24 08:04:58Z echatellier $
6    * $HeadURL: https://svn.codelutin.com/isis-fish/tags/isis-fish-4.4.0.2/src/test/java/fr/ifremer/isisfish/datastore/SensitivityAnalysisStorageTest.java $
7    * %%
8    * Copyright (C) 2009 - 2012 Ifremer, CodeLutin, Chatellier Eric
9    * %%
10   * This program is free software: you can redistribute it and/or modify
11   * it under the terms of the GNU General Public License as
12   * published by the Free Software Foundation, either version 3 of the 
13   * License, or (at your option) any later version.
14   * 
15   * This program is distributed in the hope that it will be useful,
16   * but WITHOUT ANY WARRANTY; without even the implied warranty of
17   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18   * GNU General Public License for more details.
19   * 
20   * You should have received a copy of the GNU General Public 
21   * License along with this program.  If not, see
22   * <http://www.gnu.org/licenses/gpl-3.0.html>.
23   * #L%
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.Assert;
35  import org.junit.Before;
36  import org.junit.Test;
37  
38  import fr.ifremer.isisfish.AbstractIsisFishTest;
39  import fr.ifremer.isisfish.IsisFish;
40  import fr.ifremer.isisfish.datastore.CodeSourceStorage.Location;
41  import freemarker.template.Configuration;
42  import freemarker.template.Template;
43  
44  /**
45   * SensitivityStorageTest.
46   * 
47   * Created: 7 août 2006 11:07:57
48   *
49   * @author poussin
50   * @version $Revision: 4291 $
51   *
52   * Last update: $Date: 2015-06-24 10:04:58 +0200 (Wed, 24 Jun 2015) $
53   * by : $Author: echatellier $
54   */
55  public class SensitivityAnalysisStorageTest extends AbstractIsisFishTest {
56  
57      protected Configuration freemarkerConfiguration;
58  
59      @Before
60      public void setUp() throws Exception {
61          freemarkerConfiguration = getFreemarkerConfiguration();
62      }
63  
64      @Test
65      public void testNewSensitivityAnalysisWithCompilation() throws Exception {
66  
67          String fileName = "TestSensitivityAnalysis1";
68  
69          SensitivityAnalysisStorage sensitivityStorage = SensitivityAnalysisStorage
70                  .createSensitivityAnalysis(fileName, Location.OFFICIAL);
71  
72          // get template
73          Template template = freemarkerConfiguration
74                  .getTemplate(SensitivityAnalysisStorage.SENSITIVITY_ANALYSIS_TEMPLATE);
75  
76          // context values
77          Map<String, Object> root = new HashMap<>();
78          root.put("name", fileName);
79          root.put("date", new Date());
80          root.put("author", IsisFish.config.getUserName());
81          root.put("email", IsisFish.config.getUserMail());
82  
83          // process template
84          Writer out = new StringWriter();
85          template.process(root, out);
86          out.flush();
87          sensitivityStorage.setContent(out.toString());
88  
89          // 0 = compile success
90          int compileResult = sensitivityStorage.compile(false, null);
91          Assert.assertEquals(0, compileResult);
92      }
93  
94  }