1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
43
44
45
46
47
48
49
50 public class ReportGeneratorTest extends AbstractJTimerTest {
51
52
53 private static Log log = LogFactory.getLog(ReportGeneratorTest.class);
54
55 protected static DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, Locale.ENGLISH);
56
57
58
59
60
61
62 @Test
63 public void getReportTextDaily() throws ParseException {
64
65
66
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
86 Assert.assertFalse(content.indexOf("Add webservice") > 0);
87 Assert.assertFalse(content.indexOf("Add workspace support") > 0);
88
89
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
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
100
101
102
103
104
105
106 }
107
108
109
110
111
112
113 @Test
114 public void getReportTextDailyAnnotationTime() throws ParseException {
115
116
117
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
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
138
139
140
141
142
143
144 }
145
146
147
148
149
150
151 @Test
152 public void getReportTextWeekly() throws ParseException {
153
154
155
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
174 Assert.assertFalse(content.indexOf("Add service layer") > 0);
175
176
177 Assert.assertTrue(content.indexOf("Add webservice") > 0);
178 Assert.assertTrue(content.indexOf("Add workspace support") > 0);
179
180
181 Assert.assertTrue(content.indexOf("* Test task and subtask time") > 0);
182 Assert.assertTrue(content.indexOf("* Not easy work") > 0);
183
184
185
186
187
188
189
190
191 }
192
193
194
195
196
197
198 @Test
199 public void getReportTextMonthlyAnnotationTime() throws ParseException {
200
201
202
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
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
228
229
230
231
232
233
234 }
235
236
237
238
239
240 @Test
241 public void getReportTextMonthly() throws ParseException {
242
243
244
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
263 Assert.assertFalse(content.indexOf("Add service layer") > 0);
264
265
266 Assert.assertTrue(content.indexOf("Add webservice") > 0);
267 Assert.assertTrue(content.indexOf("Add workspace support") > 0);
268
269
270 Assert.assertFalse(content.indexOf("Test task and subtask time") > 0);
271 Assert.assertFalse(content.indexOf("Not easy work") > 0);
272
273
274
275
276
277
278
279
280 }
281
282
283
284
285
286 @Test
287 public void getReportTextYearly() throws ParseException {
288
289
290
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
309 Assert.assertFalse(content.indexOf("Add webservice") > 0);
310 Assert.assertFalse(content.indexOf("Add workspace support") > 0);
311
312
313 Assert.assertTrue(content.indexOf("Add service layer") > 0);
314 Assert.assertTrue(content.indexOf("Calendar to date") > 0);
315
316
317 Assert.assertFalse(content.indexOf("Test task and subtask time") > 0);
318 Assert.assertFalse(content.indexOf("Not easy work") > 0);
319
320
321
322
323
324
325
326
327 }
328
329
330
331
332
333 @Test
334 public void getReportTextByProject() throws ParseException {
335
336
337
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
356 Assert.assertFalse(content.indexOf("Add webservice") > 0);
357 Assert.assertFalse(content.indexOf("Add workspace support") > 0);
358
359
360 Assert.assertTrue(content.indexOf("Add service layer") > 0);
361 Assert.assertTrue(content.indexOf("Calendar to date") > 0);
362
363
364 Assert.assertFalse(content.indexOf("Test task and subtask time") > 0);
365 Assert.assertTrue(content.indexOf("* Not easy work") > 0);
366
367
368
369
370
371
372
373
374 }
375 }