View Javadoc
1   /*
2    * #%L
3    * jTimer
4    * %%
5    * Copyright (C) 2008 - 2016 CodeLutin
6    * %%
7    * This program is free software: you can redistribute it and/or modify
8    * it under the terms of the GNU General Public License as
9    * published by the Free Software Foundation, either version 3 of the 
10   * License, or (at your option) any later version.
11   * 
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Public License for more details.
16   * 
17   * You should have received a copy of the GNU General Public 
18   * License along with this program.  If not, see
19   * <http://www.gnu.org/licenses/gpl-3.0.html>.
20   * #L%
21   */
22  
23  package org.chorem.jtimer.ui.report;
24  
25  import org.apache.commons.lang3.JavaVersion;
26  import org.apache.commons.lang3.SystemUtils;
27  import org.apache.commons.logging.Log;
28  import org.apache.commons.logging.LogFactory;
29  import org.chorem.jtimer.AbstractJTimerTest;
30  import org.chorem.jtimer.entities.TimerProject;
31  import org.testng.Assert;
32  import org.testng.annotations.Test;
33  
34  import java.text.DateFormat;
35  import java.text.ParseException;
36  import java.util.ArrayList;
37  import java.util.Date;
38  import java.util.List;
39  import java.util.Locale;
40  
41  /**
42   * Test for ReportGenerator class.
43   *
44   * @author chatellier
45   * @version $Revision$
46   *
47   * Last update : $Date$
48   * By : $Author$
49   */
50  public class ReportGeneratorTest extends AbstractJTimerTest {
51  
52      /** Class log */
53      private static Log log = LogFactory.getLog(ReportGeneratorTest.class);
54  
55      protected static DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, Locale.ENGLISH);
56  
57      /**
58       * Test report generation.
59       *
60       * @throws ParseException
61       */
62      @Test
63      public void getReportTextDaily() throws ParseException {
64  
65          /*try {
66              FIXME saver.lock();*/
67  
68          Date d1 = df.parse("January 1, 2008");
69          Date d2 = df.parse("December 31, 2008");
70          List<TimerProject> projects = new ArrayList<>();
71          projects.addAll(testSaver.load());
72          ReportGenerator generator = new ReportGenerator();
73          String content = generator.getReportText(ReportGenerator.Type.BY_DAY_REPORT,
74                  projects, d1, d2, false, false, false, false);
75  
76          if (log.isDebugEnabled()) {
77              log.debug("Daily report = " + content);
78          }
79  
80          Assert.assertNotNull(content);
81          Assert.assertFalse(content.indexOf("IsisFish") > 0);
82          Assert.assertFalse(content.indexOf("jRST") > 0);
83          Assert.assertTrue(content.indexOf("Topia") > 0);
84  
85          // no present task
86          Assert.assertFalse(content.indexOf("Add webservice") > 0);
87          Assert.assertFalse(content.indexOf("Add workspace support") > 0);
88  
89          // present task
90          Assert.assertTrue(content.indexOf("Add service layer") > 0);
91          Assert.assertTrue(content.indexOf("Calendar to date") > 0);
92          Assert.assertTrue(content.indexOf("Tree tests") > 0);
93  
94          // no annotations
95          Assert.assertFalse(content.indexOf("Test task and subtask time") > 0);
96          Assert.assertFalse(content.indexOf("Not easy work") > 0);
97          Assert.assertFalse(content.indexOf("Reports tests") > 0);
98          
99          /*FIXME saver.unlock();
100         } catch (DataLockingException e) {
101         if(log.isErrorEnabled()) {
102             log.error("getProjectFromFileTest error", e);
103             Assert.fail();
104         }
105         }*/
106     }
107 
108     /**
109      * Test report generation with annotation time.
110      *
111      * @throws ParseException
112      */
113     @Test
114     public void getReportTextDailyAnnotationTime() throws ParseException {
115 
116         /*try {
117             FIXME saver.lock();*/
118 
119         Date d1 = df.parse("November 1, 2008");
120         Date d2 = df.parse("March 31, 2009");
121         List<TimerProject> projects = new ArrayList<>();
122         projects.addAll(testSaver.load());
123         ReportGenerator generator = new ReportGenerator();
124         String content = generator.getReportText(ReportGenerator.Type.BY_DAY_REPORT,
125                 projects, d1, d2, false, true, true, false);
126 
127         if (log.isDebugEnabled()) {
128             log.debug("Daily report = " + content);
129         }
130 
131         Assert.assertNotNull(content);
132 
133         // with annotations and time (* is important in test)
134         Assert.assertTrue(content.indexOf("* 2:10 PM : Test task and subtask time") > 0);
135         Assert.assertTrue(content.indexOf("* 12:00 AM : Not easy work") > 0);
136         
137         /*FIXME saver.unlock();
138         } catch (DataLockingException e) {
139         if(log.isErrorEnabled()) {
140             log.error("getProjectFromFileTest error", e);
141             Assert.fail();
142         }
143         }*/
144     }
145 
146     /**
147      * Test report generation.
148      *
149      * @throws ParseException
150      */
151     @Test
152     public void getReportTextWeekly() throws ParseException {
153 
154         /*try {
155             FIXME saver.lock();*/
156 
157         Date d1 = df.parse("November 1, 2008");
158         Date d2 = df.parse("March 31, 2009");
159         List<TimerProject> projects = new ArrayList<>();
160         projects.addAll(testSaver.load());
161         ReportGenerator generator = new ReportGenerator();
162         String content = generator.getReportText(ReportGenerator.Type.BY_WEEK_REPORT,
163                 projects, d1, d2, true, true, false, false);
164 
165         if (log.isDebugEnabled()) {
166             log.debug("Weekly report = " + content);
167         }
168 
169         Assert.assertNotNull(content);
170         Assert.assertTrue(content.indexOf("jTimer") > 0);
171         Assert.assertTrue(content.indexOf("Topia") > 0);
172 
173         // no present task
174         Assert.assertFalse(content.indexOf("Add service layer") > 0);
175 
176         // present task
177         Assert.assertTrue(content.indexOf("Add webservice") > 0);
178         Assert.assertTrue(content.indexOf("Add workspace support") > 0);
179 
180         // with annotations
181         Assert.assertTrue(content.indexOf("* Test task and subtask time") > 0);
182         Assert.assertTrue(content.indexOf("* Not easy work") > 0);
183         
184         /*FIXME saver.unlock();
185         } catch (DataLockingException e) {
186         if(log.isErrorEnabled()) {
187             log.error("getProjectFromFileTest error", e);
188             Assert.fail();
189         }
190         }*/
191     }
192 
193     /**
194      * Test report generation with annotation time.
195      *
196      * @throws ParseException
197      */
198     @Test
199     public void getReportTextMonthlyAnnotationTime() throws ParseException {
200 
201         /*try {
202             FIXME saver.lock();*/
203 
204         Date d1 = df.parse("November 1, 2008");
205         Date d2 = df.parse("March 31, 2009");
206         List<TimerProject> projects = new ArrayList<>();
207         projects.addAll(testSaver.load());
208         ReportGenerator generator = new ReportGenerator();
209         String content = generator.getReportText(ReportGenerator.Type.BY_MONTH_REPORT,
210                 projects, d1, d2, true, true, true, false);
211 
212         if (log.isDebugEnabled()) {
213             log.debug("Monthly report = " + content);
214         }
215 
216         Assert.assertNotNull(content);
217 
218         // no annotations
219         if (SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_9)) {
220             Assert.assertTrue(content.indexOf("* 2/3/09, 2:10 PM : Test task and subtask time") > 0);
221             Assert.assertTrue(content.indexOf("* 12/11/08, 12:00 AM : Not easy work") > 0);
222         } else {
223             Assert.assertTrue(content.indexOf("* 2/3/09 2:10 PM : Test task and subtask time") > 0);
224             Assert.assertTrue(content.indexOf("* 12/11/08 12:00 AM : Not easy work") > 0);
225         }
226         
227         /*FIXME saver.unlock();
228         } catch (DataLockingException e) {
229         if(log.isErrorEnabled()) {
230             log.error("getProjectFromFileTest error", e);
231             Assert.fail();
232         }
233         }*/
234     }
235 
236     /**
237      * Test report generation.
238      * @throws ParseException
239      */
240     @Test
241     public void getReportTextMonthly() throws ParseException {
242 
243         /*try {
244             FIXME saver.lock();*/
245 
246         Date d1 = df.parse("November 1, 2008");
247         Date d2 = df.parse("March 31, 2009");
248         List<TimerProject> projects = new ArrayList<>();
249         projects.addAll(testSaver.load());
250         ReportGenerator generator = new ReportGenerator();
251         String content = generator.getReportText(ReportGenerator.Type.BY_MONTH_REPORT,
252                 projects, d1, d2, true, false, false, false);
253 
254         if (log.isDebugEnabled()) {
255             log.debug("Monthly report = " + content);
256         }
257 
258         Assert.assertNotNull(content);
259         Assert.assertTrue(content.indexOf("Chorem") > 0);
260         Assert.assertTrue(content.indexOf("Topia") > 0);
261 
262         // no present task
263         Assert.assertFalse(content.indexOf("Add service layer") > 0);
264 
265         // present task
266         Assert.assertTrue(content.indexOf("Add webservice") > 0);
267         Assert.assertTrue(content.indexOf("Add workspace support") > 0);
268 
269         // no annotations
270         Assert.assertFalse(content.indexOf("Test task and subtask time") > 0);
271         Assert.assertFalse(content.indexOf("Not easy work") > 0);
272         
273         /*FIXME saver.unlock();
274         } catch (DataLockingException e) {
275         if(log.isErrorEnabled()) {
276             log.error("getProjectFromFileTest error", e);
277             Assert.fail();
278         }
279         }*/
280     }
281 
282     /**
283      * Test report generation.
284      * @throws ParseException
285      */
286     @Test
287     public void getReportTextYearly() throws ParseException {
288 
289         /*try {
290             FIXME saver.lock();*/
291 
292         Date d1 = df.parse("January 1, 2008");
293         Date d2 = df.parse("December 31, 2008");
294         List<TimerProject> projects = new ArrayList<>();
295         projects.addAll(testSaver.load());
296         ReportGenerator generator = new ReportGenerator();
297         String content = generator.getReportText(ReportGenerator.Type.BY_YEAR_REPORT,
298                 projects, d1, d2, false, false, false, false);
299 
300         if (log.isDebugEnabled()) {
301             log.debug("Yearly report = " + content);
302         }
303 
304         Assert.assertNotNull(content);
305         Assert.assertFalse(content.indexOf("Chorem") > 0);
306         Assert.assertTrue(content.indexOf("Topia") > 0);
307 
308         // no present task
309         Assert.assertFalse(content.indexOf("Add webservice") > 0);
310         Assert.assertFalse(content.indexOf("Add workspace support") > 0);
311 
312         // present task
313         Assert.assertTrue(content.indexOf("Add service layer") > 0);
314         Assert.assertTrue(content.indexOf("Calendar to date") > 0);
315 
316         // no annotations
317         Assert.assertFalse(content.indexOf("Test task and subtask time") > 0);
318         Assert.assertFalse(content.indexOf("Not easy work") > 0);
319         
320         /*FIXME saver.unlock();
321         } catch (DataLockingException e) {
322         if(log.isErrorEnabled()) {
323             log.error("getProjectFromFileTest error", e);
324             Assert.fail();
325         }
326         }*/
327     }
328 
329     /**
330      * Test report generation.
331      * @throws ParseException
332      */
333     @Test
334     public void getReportTextByProject() throws ParseException {
335 
336         /*try {
337             FIXME saver.lock();*/
338 
339         Date d1 = df.parse("January 1, 2008");
340         Date d2 = df.parse("December 31, 2008");
341         List<TimerProject> projects = new ArrayList<>();
342         projects.addAll(testSaver.load());
343         ReportGenerator generator = new ReportGenerator();
344         String content = generator.getReportText(ReportGenerator.Type.BY_PROJECT_REPORT,
345                 projects, d1, d2, true, true, false, false);
346 
347         if (log.isDebugEnabled()) {
348             log.debug("Project report = " + content);
349         }
350 
351         Assert.assertNotNull(content);
352         Assert.assertFalse(content.indexOf("Chorem") > 0);
353         Assert.assertTrue(content.indexOf("Topia") > 0);
354 
355         // no present task
356         Assert.assertFalse(content.indexOf("Add webservice") > 0);
357         Assert.assertFalse(content.indexOf("Add workspace support") > 0);
358 
359         // present task
360         Assert.assertTrue(content.indexOf("Add service layer") > 0);
361         Assert.assertTrue(content.indexOf("Calendar to date") > 0);
362 
363         // test annotations
364         Assert.assertFalse(content.indexOf("Test task and subtask time") > 0);
365         Assert.assertTrue(content.indexOf("* Not easy work") > 0);
366         
367         /*FIXME saver.unlock();
368         } catch (DataLockingException e) {
369         if(log.isErrorEnabled()) {
370             log.error("getProjectFromFileTest error", e);
371             Assert.fail();
372         }
373         }*/
374     }
375 }